学习目的
了解java.text包的包含和作用
学会查看java.text包下类和接口的底层源码实现
掌握java.text包的常用接口和类,以及常用的方法
三、java.text
概念
提供以 与自然语言无关的方式 来处理文本、日期、数字和消息的类与接口。
3.1 接口
接口
名称
备注
3.1.1 AttributedCharacterIterator属性字符迭代器
简述
AttributedCharacterIterator 允许对 文本和相关属性信息 的迭代
作用
常见实现类
底层实现及常用方法
public interface AttributedCharacterIterator extends CharacterIterator {
//静态内部类:定义 用于标识文本属性 的属性键
public static class Attribute implements Serializable {
private String name;
// table of all instances in this class, used by readResolve
private static final Map instanceMap = new HashMap<>(7);
protected Attribute(String name) {
this.name = name;
if (this.getClass() == Attribute.class) {
instanceMap.put(name, this);
}
}
public final boolean equals(Object obj) {
return super.equals(obj);
}
public final int hashCode() {
return super.hashCode();
}
public String toString() {
return getClass().getName() + "(" + name + ")";
}
protected String getName() {
return name;
}
protected Object readResolve() throws InvalidObjectException {
if (this.getClass() != Attribute.class) {
throw new InvalidObjectException("subclass didn't correctly implement readResolve");
}
Attribute instance = instanceMap.get(getName());
if (instance != null) {
return instance;
} else {
throw new InvalidObjectException("unknown attribute name");
}
}
//
public static final Attribute LANGUAGE = new Attribute("language");
public static final Attribute READING = new Attribute("reading");
public static final Attribute INPUT_METHOD_SEGMENT = new Attribute("input_method_segment");
// make sure the serial version doesn't change between compiler versions
private static final long serialVersionUID = -9142742483513960612L;
};
//返回关于 包含当前字符的所有属性的 第一个字符的索引
public int getRunStart();
//返回关于 包含当前字符的给定属性的 第一个字符的索引
public int getRunStart(Attribute attribute);
//返回关于 包含当前字符的给定多个属性的 第一个字符的索引
public int getRunStart(Set extends Attribute> attributes);
//返回关于 包含当前字符的所有属性的 运行之后的第一个字符的索引
public int getRunLimit();
public int getRunLimit(Attribute attribute);
public int getRunLimit(Set extends Attribute> attributes);
//返回 具有定义于当前字符上的多个属性 的映射
public Map getAttributes();
//返回当前字符的命名属性的值
public Object getAttribute(Attribute attribute);
//返回 定义于迭代器文本范围上的所有属性的键集合
public Set getAllAttributeKeys();
};
3.1.2 CharacterIterator字符迭代器
简述
CharacterIterator接口定义了对文本进行双向迭代的协议,迭代器对有界的字符序列进行迭代。
作用
常见实现类
底层实现及常用方法
static final char DONE:当迭代器已到达文本末尾或开始处时返回的常量
3.2 常用类
类名
作用
备注
3.2.1 DateFormat
简述
作用
常见父类或接口
底层实现及常用方法
3.2.2 DecimalFormat
简述
作用
常见父类或接口
底层实现及常用方法
3.2.3 Format
简述
作用
常见父类或接口
底层实现及常用方法
3.2.4 SimpleDateFormat
简述
作用
常见父类或接口
底层实现及常用方法
3.2.5
简述
作用
常见父类或接口
底层实现及常用方法