public class FieldPosition extends Object
FieldPosition是由Format及其子类使用的简单类,用于标识格式化输出中的字段。
可以通过两种方式识别字段:
_FIELD 。 的常量在的不同子类中定义的Format 。 Format.Field常数,见ERA_FIELD及其朋友在DateFormat为例。 FieldPosition使用两个索引来跟踪格式化输出中的字段的位置:字段的第一个字符的索引和字段的最后一个字符的索引。
各种Format类中的format方法的一个版本需要一个FieldPosition对象作为参数。 您可以使用此format方法执行部分格式化或获取有关格式化输出的信息(例如字段的位置)。
如果您对格式化字符串中所有属性的位置感兴趣,请使用Format方法formatToCharacterIterator 。
Format
| Constructor and Description |
|---|
FieldPosition(Format.Field attribute)
为给定的字段常量创建一个FieldPosition对象。
|
FieldPosition(Format.Field attribute, int fieldID)
为给定字段创建一个
FieldPosition对象。
|
FieldPosition(int field)
为给定字段创建一个FieldPosition对象。
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
equals(Object obj)
覆盖等于
|
int |
getBeginIndex()
检索请求字段中第一个字符的索引。
|
int |
getEndIndex()
检索请求字段中最后一个字符后的字符索引。
|
int |
getField()
检索字段标识符。
|
Format.Field |
getFieldAttribute()
从
Field子类之一返回字段标识符作为属性常量。
|
int |
hashCode()
返回此FieldPosition的哈希码。
|
void |
setBeginIndex(int bi)
设置开始索引。
|
void |
setEndIndex(int ei)
设置结束索引。
|
String |
toString()
返回此FieldPosition的字符串表示形式。
|
public FieldPosition(int field)
field - 字段标识符
NumberFormat.INTEGER_FIELD ,
NumberFormat.FRACTION_FIELD ,
DateFormat.YEAR_FIELD ,
DateFormat.MONTH_FIELD
public FieldPosition(Format.Field attribute)
Format子类中定义的Format标识。
这相当于调用new FieldPosition(attribute, -1) 。
attribute - Format.Field常数标识字段
public FieldPosition(Format.Field attribute, int fieldID)
FieldPosition对象。
该字段由Field子类之一的Field常量以及由Format子类定义的整数字段ID标识。
Format知道Field应该优先于attribute ,如果attribute不为null,则忽略fieldID 。
但是,较旧的Format子类可能不知道Field并依赖于fieldID 。
如果该字段没有相应的整数常数, fieldID应为-1。
attribute - Format.Field常量标识字段
fieldID - 标识字段的整数常量
public Format.Field getFieldAttribute()
Field子类之一返回字段标识符作为属性常量。
如果字段仅由整数字段ID指定,则可能返回null。
public int getField()
public int getBeginIndex()
public int getEndIndex()
public void setBeginIndex(int bi)
bi - 开始索引
public void setEndIndex(int ei)
ei - 最终索引
public boolean equals(Object obj)
equals在
Object
obj - 与之比较的参考对象。
true如果该对象与obj参数相同;
false否则。
Object.hashCode() , HashMap
public int hashCode()
hashCode在
Object
Object.equals(java.lang.Object) ,
System.identityHashCode(java.lang.Object)
Submit a bug or feature
For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
Copyright © 1993, 2014, Oracle and/or its affiliates. All rights reserved.