老司机带你重构Android的v4包的部分源码

版权声明:本文为博主原创文章,未经博主允许不得转载。https://www.jianshu.com/p/a08d754944c4

转载请标明出处:
https://www.jianshu.com/p/a08d754944c4
本文出自 AWeiLoveAndroid的博客


【前言】过年回家忙着干活,忙着给亲戚的孩子发红包,好累,忙里偷闲打开studio看了一下v4包,之前看过几个类,这次是每个类都看了一下,原来Android的v4包的源码也有一些是写的不是那么友好的,还有很多改善空间。

下面就拿其中的android.support.v4.text这个包里面的 TextUtilsCompatTextUtilsCompatJellybeanMr1 这两个类来做一个具体讲解。

本文源码同步发布在github,详情请点击 https://github.com/AweiLoveAndroid/refactor-android-support-v4

一、首先看一下Androidv4包下面的 TextUtilsCompatTextUtilsCompatJellybeanMr1 源码:

(一)TextUtilsCompat 源码:
public final class TextUtilsCompat {private static class TextUtilsCompatImpl {TextUtilsCompatImpl() {}@NonNullpublic String htmlEncode(@NonNull String s) {StringBuilder sb = new StringBuilder();char c;for (int i = 0; i < s.length(); i++) {c = s.charAt(i);switch (c) {case '<':sb.append("&lt;"); //$NON-NLS-1$break;case '>':sb.append("&gt;"); //$NON-NLS-1$break;case '&':sb.append("&amp;"); //$NON-NLS-1$break;case '\''://http://www.w3.org/TR/xhtml1// The named character reference &apos; (the apostrophe, U+0027) was// introduced in XML 1.0 but does not appear in HTML. Authors should// therefore use &#39; instead of &apos; to work as expected in HTML 4// user agents.sb.append("&#39;"); //$NON-NLS-1$break;case '"':sb.append("&quot;"); //$NON-NLS-1$break;default:sb.append(c);}}return sb.toString();}public int getLayoutDirectionFromLocale(@Nullable Locale locale) {if (locale != null && !locale.equals(ROOT)) {final String scriptSubtag = ICUCompat.maximizeAndGetScript(locale);if (scriptSubtag == null) return getLayoutDirectionFromFirstChar(locale);// This is intentionally limited to Arabic and Hebrew scripts, since older// versions of Android platform only considered those scripts to be right-to-left.if (scriptSubtag.equalsIgnoreCase(ARAB_SCRIPT_SUBTAG) ||scriptSubtag.equalsIgnoreCase(HEBR_SCRIPT_SUBTAG)) {return ViewCompat.LAYOUT_DIRECTION_RTL;}}return ViewCompat.LAYOUT_DIRECTION_LTR;}/*** Fallback algorithm to detect the locale direction. Rely on the first char of the* localized locale name. This will not work if the localized locale name is in English* (this is the case for ICU 4.4 and "Urdu" script)** @param locale* @return the layout direction. This may be one of:* {@link ViewCompat#LAYOUT_DIRECTION_LTR} or* {@link ViewCompat#LAYOUT_DIRECTION_RTL}.** Be careful: this code will need to be updated when vertical scripts will be supported*/private static int getLayoutDirectionFromFirstChar(@NonNull Locale locale) {switch(Character.getDirectionality(locale.getDisplayName(locale).charAt(0))) {case Character.DIRECTIONALITY_RIGHT_TO_LEFT:case Character.DIRECTIONALITY_RIGHT_TO_LEFT_ARABIC:return ViewCompat.LAYOUT_DIRECTION_RTL;case Character.DIRECTIONALITY_LEFT_TO_RIGHT:default:return ViewCompat.LAYOUT_DIRECTION_LTR;}}}private static class TextUtilsCompatJellybeanMr1Impl extends TextUtilsCompatImpl {TextUtilsCompatJellybeanMr1Impl() {}@Override@NonNullpublic String htmlEncode(@NonNull String s) {return TextUtilsCompatJellybeanMr1.htmlEncode(s);}@Overridepublic int getLayoutDirectionFromLocale(@Nullable Locale locale) {return TextUtilsCompatJellybeanMr1.getLayoutDirectionFromLocale(locale);}}private static final TextUtilsCompatImpl IMPL;static {final int version = Build.VERSION.SDK_INT;if (version >= 17) { // JellyBean MR1IMPL = new TextUtilsCompatJellybeanMr1Impl();} else {IMPL = new TextUtilsCompatImpl();}}/*** Html-encode the string.* @param s the string to be encoded* @return the encoded string*/@NonNullpublic static String htmlEncode(@NonNull String s) {return IMPL.htmlEncode(s);}/*** Return the layout direction for a given Locale** @param locale the Locale for which we want the layout direction. Can be null.* @return the layout direction. This may be one of:* {@link ViewCompat#LAYOUT_DIRECTION_LTR} or* {@link ViewCompat#LAYOUT_DIRECTION_RTL}.** Be careful: this code will need to be updated when vertical scripts will be supported*/public static int getLayoutDirectionFromLocale(@Nullable Locale locale) {return IMPL.getLayoutDirectionFromLocale(locale);}public static final Locale ROOT = new Locale("", "");static String ARAB_SCRIPT_SUBTAG = "Arab";static String HEBR_SCRIPT_SUBTAG = "Hebr";private TextUtilsCompat() {}
}
(二)TextUtilsCompatJellybeanMr1 源码:
/*** Jellybean MR1 - specific TextUtils API access.*/
@RequiresApi(17)
@TargetApi(17)
class TextUtilsCompatJellybeanMr1 {@NonNullpublic static String htmlEncode(@NonNull String s) {return TextUtils.htmlEncode(s);}public static int getLayoutDirectionFromLocale(@Nullable Locale locale) {return TextUtils.getLayoutDirectionFromLocale(locale);}
}

二、分析一下以上源码的一些需要改进的问题(仅个人理解,如有不同意见,欢迎提出):

通过以上源码来看,看起来确实有点不是很舒服。

(一)排列顺序有点乱,我格式化了一下,如下,看的稍微清楚了一些:
/*** 格式化之后的TextUtilsCompat类*/
public class TextUtilsCompat {private static final TextUtilsCompatImpl IMPL;public static final Locale ROOT = new Locale("", "");static String ARAB_SCRIPT_SUBTAG = "Arab";static String HEBR_SCRIPT_SUBTAG = "Hebr";private TextUtilsCompat() {}static {final int version = Build.VERSION.SDK_INT;if (version >= 17) { // JellyBean MR1IMPL = new TextUtilsCompatJellybeanMr1Impl();} else {IMPL = new TextUtilsCompatImpl();}}/*** Html-encode the string.* @param s the string to be encoded* @return the encoded string*/@NonNullpublic static String htmlEncode(@NonNull String s) {return IMPL.htmlEncode(s);}/*** Return the layout direction for a given Locale** @param locale the Locale for which we want the layout direction. Can be null.* @return the layout direction. This may be one of:* {@link ViewCompat#LAYOUT_DIRECTION_LTR} or* {@link ViewCompat#LAYOUT_DIRECTION_RTL}.** Be careful: this code will need to be updated when vertical scripts will be supported*/public static int getLayoutDirectionFromLocale(@Nullable Locale locale) {return IMPL.getLayoutDirectionFromLocale(locale);}private static class TextUtilsCompatImpl {TextUtilsCompatImpl() {}@NonNullpublic String htmlEncode(@NonNull String s) {StringBuilder sb = new StringBuilder();char c;for (int i = 0; i < s.length(); i++) {c = s.charAt(i);switch (c) {case '<':sb.append("&lt;"); //$NON-NLS-1$break;case '>':sb.append("&gt;"); //$NON-NLS-1$break;case '&':sb.append("&amp;"); //$NON-NLS-1$break;case '\''://http://www.w3.org/TR/xhtml1// The named character reference &apos; (the apostrophe, U+0027) was// introduced in XML 1.0 but does not appear in HTML. Authors should// therefore use &#39; instead of &apos; to work as expected in HTML 4// user agents.sb.append("&#39;"); //$NON-NLS-1$break;case '"':sb.append("&quot;"); //$NON-NLS-1$break;default:sb.append(c);}}return sb.toString();}public int getLayoutDirectionFromLocale(@Nullable Locale locale) {if (locale != null && !locale.equals(ROOT)) {final String scriptSubtag = ICUCompat.maximizeAndGetScript(locale);if (scriptSubtag == null) {return getLayoutDirectionFromFirstChar(locale);}// This is intentionally limited to Arabic and Hebrew scripts, since older// versions of Android platform only considered those scripts to be right-to-left.if (scriptSubtag.equalsIgnoreCase(ARAB_SCRIPT_SUBTAG) ||scriptSubtag.equalsIgnoreCase(HEBR_SCRIPT_SUBTAG)) {return ViewCompat.LAYOUT_DIRECTION_RTL;}}return ViewCompat.LAYOUT_DIRECTION_LTR;}/*** Fallback algorithm to detect the locale direction. Rely on the first char of the* localized locale name. This will not work if the localized locale name is in English* (this is the case for ICU 4.4 and "Urdu" script)** @param locale* @return the layout direction. This may be one of:* {@link ViewCompat#LAYOUT_DIRECTION_LTR} or* {@link ViewCompat#LAYOUT_DIRECTION_RTL}.** Be careful: this code will need to be updated when vertical scripts will be supported*/private static int getLayoutDirectionFromFirstChar(@NonNull Locale locale) {switch(Character.getDirectionality(locale.getDisplayName(locale).charAt(0))) {case Character.DIRECTIONALITY_RIGHT_TO_LEFT:case Character.DIRECTIONALITY_RIGHT_TO_LEFT_ARABIC:return ViewCompat.LAYOUT_DIRECTION_RTL;case Character.DIRECTIONALITY_LEFT_TO_RIGHT:default:return ViewCompat.LAYOUT_DIRECTION_LTR;}}}private static class TextUtilsCompatJellybeanMr1Impl extends TextUtilsCompatImpl {TextUtilsCompatJellybeanMr1Impl() {}@Override@NonNullpublic String htmlEncode(@NonNull String s) {return TextUtilsCompatJellybeanMr1.htmlEncode(s);}@Overridepublic int getLayoutDirectionFromLocale(@Nullable Locale locale) {return TextUtilsCompatJellybeanMr1.getLayoutDirectionFromLocale(locale);}}}
(二)TextUtilsCompat 这个类里面有两个内部类,一个是TextUtilsCompatImpl,一个是TextUtilsCompatJellybeanMr1Impl,TextUtilsCompatJellybeanMr1Impl是继承自TextUtilsCompatImpl的。
(三)从静态代码块看出,api 大于17 使用 new TextUtilsCompatJellybeanMr1Impl(); api小于17 使用TextUtilsCompatImpl。TextUtilsCompat,TextUtilsCompatImpl和TextUtilsCompatJellybeanMr1Impl里面都有 htmlEncode 方法和 getLayoutDirectionFromLocale 方法。

静态代码块里面通过TextUtilsCompatImpl IMPL这个常量来判断,当api大于17用TextUtilsCompatJellybeanMr1Impl,否则用TextUtilsCompatImpl,然后htmlEncode方法调用了对应内部类里面的htmlEncode方法,getLayoutDirectionFromLocale调用了对应内部类里面的getLayoutDirectionFromLocale方法。

(四)TextUtilsCompatImpl和TextUtilsCompatJellybeanMr1Impl里面都有 htmlEncode 方法和 getLayoutDirectionFromLocale 方法,看看它们的区别。

(1)TextUtilsCompatJellybeanMr1Impl这个内部类的方法解析:

  • htmlEncode(@NonNull String s) 方法 返回的是:
TextUtilsCompatJellybeanMr1.htmlEncode(s); ==> 调用了TextUtils.htmlEncode(s);
  • getLayoutDirectionFromLocale(@Nullable Locale locale) 方法返回的是:
TextUtilsCompatJellybeanMr1.getLayoutDirectionFromLocale(locale); ==> 调用了TextUtils.getLayoutDirectionFromLocale(locale);

(2)TextUtilsCompatImpl这个内部类的方法解析:

  • htmlEncode(@NonNull String s) 方法 返回的是:
在这个方法内部写了一遍,跟TextUtils.htmlEncode(s);方法里面的一模一样。
  • getLayoutDirectionFromLocale(@Nullable Locale locale) 方法返回的是:
重新写了一遍,这个方法是真正有所区别的地方。

三、根据我做过项目用到的MVP的开发模式,我把共同的htmlEncode方法和getLayoutDirectionFromLocale方法抽取出一个接口,然后分别用两个实现类去实现接口,然后用TextUtilsCompat这个类去判断调用哪个实现类的方法,这样看起来更直观一些。具体步骤如下:

(一)抽取公共接口ITextUtilsCompat
/*** 抽取公用的接口*/
public interface ITextUtilsCompat {/*** Html-encode the string.* @param s the string to be encoded* @return the encoded string*/public String htmlEncode(@NonNull String s);/*** Return the layout direction for a given Locale** @param locale the Locale for which we want the layout direction. Can be null.* @return the layout direction. This may be one of:* {@link android.support.v4.view.ViewCompat#LAYOUT_DIRECTION_LTR} or* {@link android.support.v4.view.ViewCompat#LAYOUT_DIRECTION_RTL}.** Be careful: this code will need to be updated when vertical scripts will be supported*/public int getLayoutDirectionFromLocale(@Nullable Locale locale);
}
(二)写一个TextUtilsCompatJellybeanMr1实现ITextUtilsCompat 接口,然后把之前TextUtilsCompatJellybeanMr1类里面的复制过来,具体如下:
/*** 兼容Android 17+ 版本* Jellybean MR1 - specific TextUtils API access.*/
@RequiresApi(17)
@TargetApi(17)
class TextUtilsCompatJellybeanMr1 implements ITextUtilsCompat{@Override@NonNullpublic String htmlEncode(@NonNull String s) {return TextUtils.htmlEncode(s);}@Overridepublic int getLayoutDirectionFromLocale(@Nullable Locale locale) {return TextUtils.getLayoutDirectionFromLocale(locale);}
}
(三)写一个类TextUtilsCompatImpl实现ITextUtilsCompat 接口,然后把之前TextUtilsCompat类里面的有关代码复制过来,具体如下:
/*** Android 17以下版本使用这个类*/
class TextUtilsCompatImpl implements ITextUtilsCompat{public static final Locale ROOT = new Locale("", "");static String ARAB_SCRIPT_SUBTAG = "Arab";static String HEBR_SCRIPT_SUBTAG = "Hebr";@Override@NonNullpublic String htmlEncode(@NonNull String s) {StringBuilder sb = new StringBuilder();char c;for (int i = 0; i < s.length(); i++) {c = s.charAt(i);switch (c) {case '<':sb.append("&lt;"); //$NON-NLS-1$break;case '>':sb.append("&gt;"); //$NON-NLS-1$break;case '&':sb.append("&amp;"); //$NON-NLS-1$break;case '\''://http://www.w3.org/TR/xhtml1// The named character reference &apos; (the apostrophe, U+0027) was// introduced in XML 1.0 but does not appear in HTML. Authors should// therefore use &#39; instead of &apos; to work as expected in HTML 4// user agents.sb.append("&#39;"); //$NON-NLS-1$break;case '"':sb.append("&quot;"); //$NON-NLS-1$break;default:sb.append(c);}}return sb.toString();}@Overridepublic int getLayoutDirectionFromLocale(@Nullable Locale locale) {if (locale != null && !locale.equals(ROOT)) {final String scriptSubtag = ICUCompat.maximizeAndGetScript(locale);if (scriptSubtag == null) {return getLayoutDirectionFromFirstChar(locale);}// This is intentionally limited to Arabic and Hebrew scripts, since older// versions of Android platform only considered those scripts to be right-to-left.if (scriptSubtag.equalsIgnoreCase(ARAB_SCRIPT_SUBTAG) ||scriptSubtag.equalsIgnoreCase(HEBR_SCRIPT_SUBTAG)) {return ViewCompat.LAYOUT_DIRECTION_RTL;}}return ViewCompat.LAYOUT_DIRECTION_LTR;}/*** Fallback algorithm to detect the locale direction. Rely on the first char of the* localized locale name. This will not work if the localized locale name is in English* (this is the case for ICU 4.4 and "Urdu" script)** @param locale* @return the layout direction. This may be one of:* {@link android.support.v4.view.ViewCompat#LAYOUT_DIRECTION_LTR} or* {@link android.support.v4.view.ViewCompat#LAYOUT_DIRECTION_RTL}.** Be careful: this code will need to be updated when vertical scripts will be supported*/private static int getLayoutDirectionFromFirstChar(@NonNull Locale locale) {switch(Character.getDirectionality(locale.getDisplayName(locale).charAt(0))) {case Character.DIRECTIONALITY_RIGHT_TO_LEFT:case Character.DIRECTIONALITY_RIGHT_TO_LEFT_ARABIC:return ViewCompat.LAYOUT_DIRECTION_RTL;case Character.DIRECTIONALITY_LEFT_TO_RIGHT:default:return ViewCompat.LAYOUT_DIRECTION_LTR;}}
}
(四)封装TextUtilsCompat给调用者使用,具体如下:
/*** v4包下面的TextUtilsCompat的简单优化* 这里使用的是策略模式,根据不同api版本调用不同的接口实现类* 这样写更好维护。*/
public final class TextUtilsCompat {private static final ITextUtilsCompat IMPL;private TextUtilsCompat() {}static {final int version = Build.VERSION.SDK_INT;// JellyBean MR1 大于等于17if (version >= Build.VERSION_CODES.JELLY_BEAN_MR1) {IMPL = new TextUtilsCompatJellybeanMr1();} else {IMPL = new TextUtilsCompatImpl();}}/*** Html-encode the string.* @param s the string to be encoded* @return the encoded string*/@NonNullpublic static String htmlEncode(@NonNull String s) {return IMPL.htmlEncode(s);}/*** Return the layout direction for a given Locale** @param locale the Locale for which we want the layout direction. Can be null.* @return the layout direction. This may be one of:* {@link android.support.v4.view.ViewCompat#LAYOUT_DIRECTION_LTR} or* {@link android.support.v4.view.ViewCompat#LAYOUT_DIRECTION_RTL}.** Be careful: this code will need to be updated when vertical scripts will be supported*/public static int getLayoutDirectionFromLocale(@Nullable Locale locale) {return IMPL.getLayoutDirectionFromLocale(locale);}}

到此,TextUtilsCompat 这个类就封装完了。看完之后是不是很清爽?其实还有很多类似的类都可以根据类似的方式做一下改进的。源码不是完美的,只要掌握以上示例代码的思想还是很容易的让代码更好理解,更简洁清晰的。

【好消息】我的微信公众号正式开通了,关注一下吧!
关注一下我的公众号吧

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/284098.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

.NET静态代码织入——肉夹馍(Rougamo) 发布1.1.0

肉夹馍是什么肉夹馍(https://github.com/inversionhourglass/Rougamo)通过静态代码织入方式实现AOP的组件。.NET常用的AOP有Castle DynamicProxy、AspectCore等&#xff0c;以上两种AOP组件都是通过运行时生成一个代理类执行AOP代码的&#xff0c;肉夹馍则是在代码编译时直接修…

Msys2 国内源(2017.3.30)

确定可用&#xff01; Server https://mirrors.tuna.tsinghua.edu.cn/msys2/msys/$arch转载于:https://www.cnblogs.com/baud/p/6644887.html

基于 IdentityServer3 实现 OAuth 2.0 授权服务【密码模式(Resource Owner Password Credentials)】...

密码模式&#xff08;Resource Owner Password Credentials Grant&#xff09;中&#xff0c;用户向客户端提供自己的用户名和密码。客户端使用这些信息&#xff0c;向"服务商提供商"索要授权。基于之前的 IdentityServer3 实现 OAuth 2.0 授权服务【客户端模式(Clie…

【GlobalMapper精品教程】035:用CASS自带数据创建高程地形、等高线教程

本文讲述globalmapper用CASS自带数据创建高程地形、等高线教程。 文章目录 1. 坐标生成点2. 点转高程格网3. 生成等高线4. 保存等高线CASS自带等高线数据dgx.dat预览:包含点号、编码、东坐标、北坐标、高程5列,可以不用做任何修改,在Globalmapper中生成点。 1. 坐标生成点 …

SaaS产品的免费试用到底该怎么做

”SaaS产品的免费试用&#xff0c;绝不仅仅只是开放产品试用期这么简单&#xff0c;很多企业并没有重视免费试用模式的搭建和转化路径“ 很多SaaS厂商的产品都会提供免费试用的机会&#xff0c;虽然试用的最终目标是促成用户为产品价值付费&#xff0c;但是很多SaaS厂商在开放系…

【.NET6+WPF】WPF使用prism框架+Unity IOC容器实现MVVM双向绑定和依赖注入

前言&#xff1a;在C/S架构上&#xff0c;WPF无疑已经是“桌面一霸”了。在.NET生态环境中&#xff0c;很多小伙伴还在使用Winform开发C/S架构的桌面应用。但是WPF也有很多年的历史了&#xff0c;并且基于MVVM的开发模式&#xff0c;受到了很多开发者的喜爱。并且随着工业化的进…

sql 中 limit 与 limit,offset连用的区别

① select * from table limit 2,1; #跳过2条取出1条数据&#xff0c;limit后面是从第2条开始读&#xff0c;读取1条信息&#xff0c;即读取第3条数据 ② select * from table limit 2 offset 1; #从第1条&#xff08;不包括&#xff09;数据开始取出2条…

【ArcGIS Pro微课1000例】0022:基于DEM进行流域分析生成流域图

文章目录 一、填洼二、流向分析三、计算流域一、填洼 填洼Fill,在进行水文分析后续操作前,首先要对DEM进行填洼,创建无凹陷点的DEM。 填洼需要使用水文分析工具下的【填洼】。 确定输入与输出即可。 填洼结果: 二、流向分析 在ArcGIS中使用的是八方向流量建模(D8算法),工…

Spring配置文件中bean标签的scope属性

转自&#xff1a;https://fj-sh-chz.iteye.com/blog/1775149 singleton &#xff08;默认属性&#xff09; Spring将Bean放入Spring IOC容器的缓存池中&#xff0c;并将Bean引用返回给调用者&#xff0c;spring IOC继续对这些Bean进行后续的生命管理。BeanFactory只管理一个共…

[转]Druid概述

目录 1.Apache Druid简介 2.Apache Druid架构 2.1 服务器类型 2.1.1 Master Server 2.1.2 Query 2.1.3 Data Server 2.2 外部依赖 2.2.1 Deep Storage 2.2.2 Metadata Storage 2.2.3 Zookeeper 2.3 存储设计 3.在HDP上安装Apache Druid 3.1 准备数据库 3.2 安装…

在 .NET MAUI 中如何更好地自定义控件

点击上方蓝字关注我们&#xff08;本文阅读时间&#xff1a;10分钟)今天&#xff0c;我想谈谈并向您展示在.NET MAUI中完全自定义控件的方法。在查看 .NET MAUI 之前&#xff0c;让我们回到几年前&#xff0c;回到 Xamarin.Forms 时代。那时&#xff0c;我们有很多自定义控件的…

【GlobalMapper精品教程】036:基于DEM的流域计算生成流域图

Globalmapper基于DEM的流域计算生成流域图教程。 文章目录一、加载DEM二、流域分析一、加载DEM 加载配套实验数据。 二、流域分析 GM中的流域分析工具位于分析→生成流域&#xff0c;如下所示&#xff1a; 参数设置如下&#xff1a; 流域计算结果&#xff1a;

html之file标签 --- 图片上传前预览 -- FileReader

记得以前做网站时&#xff0c;曾经需要实现一个图片上传到服务器前&#xff0c;先预览的功能。当时用html的<input type"file"/>标签一直实现不了&#xff0c;最后舍弃了这个标签&#xff0c;使用了其他方式来实现了这个功能。 今天无意发现了一个知识点&#…

Android Studio3.0简介

Android Studio 3.0.0 Android Studio 3.0.0 (2017年10月)是一个主要版本&#xff0c;包括各种新功能和改进 Android插件的Gradle 3.0.0 • 支持Android 8.0 • 支持Java 8库和Java 8语言功能&#xff08;没有Jack编译器&#xff09; • 支持Android测试支持库1.0&#xff08;A…

嵌入式linux面试题解析(二)——C语言部分三

嵌入式linux面试题解析&#xff08;二&#xff09;——C语言部分三1、下面的程序会出现什么结果#include <stdio.h>#include <stdlib.h>#include <string.h>void getmemory(char *p){ p(char *) malloc(100); strcpy(p,”hello world”);}int main( ){…

什么是JavaBean、Bean? 什么是POJO、PO、DTO、VO、BO ? 什么是EJB、EntityBean?

前言&#xff1a; 在Java开发中经常遇到这些概念问题&#xff0c;有的可能理解混淆&#xff0c;有的可能理解不到位&#xff0c;特此花了很多时间理顺了这些概念。不过有些概念实际开发中并没有使用到&#xff0c;可能理解还不够准确&#xff0c;只能靠后续不断纠正了。 1、什么…

【GlobalMapper精品教程】037:构建泰森多边形(Thiessen Polygon)实例精解

泰森多边形是进行快速插值和分析地理实体影响区域的常用工具。例如,用离散点的性质描述多边形区域的性质,用离散点的数据计算泰森多边形区域的数据。泰森多边形可用于定性分析、统计分析和临近分析等。 文章目录 一、泰森多边形的概念二、泰森多边形的特点三、泰森多边形构建…

WPF 实现 Gitee 泡泡菜单「完」

WPF 实现 Gitee 泡泡菜单「完」气泡菜单「完」作者&#xff1a;WPFDevelopersOrg原文链接&#xff1a; https://github.com/WPFDevelopersOrg/WPFDevelopers框架使用大于等于.NET40&#xff1b;Visual Studio 2022;项目使用 MIT 开源许可协议&#xff1b;需要实现泡泡菜单需…

BZOJ 4516: [Sdoi2016]生成魔咒 [后缀自动机]

4516: [Sdoi2016]生成魔咒 题意&#xff1a;询问一个字符串每个前缀有多少不同的子串 做了一下SDOI2016R1D2&#xff0c;题好水啊随便AK 强行开map上SAM 每个状态的贡献就是\(Max(s)-Min(s)1\) 插入的时候维护一下就行了 #include <iostream> #include <cstdio> #i…

Fiddler抓包5-接口测试(Composer)

前言 Fiddler最大的优势在于抓包&#xff0c;我们大部分使用的功能也在抓包的功能上&#xff0c;fiddler做接口测试也是非常方便的。 对应没有接口测试文档的时候&#xff0c;可以直接抓完包后&#xff0c;copy请求参数&#xff0c;修改下就可以了。 一、Composer简介 点开右侧…