本文整理汇总了Java中java.text.FieldPosition.getField方法的典型用法代码示例。如果您正苦于以下问题:Java FieldPosition.getField方法的具体用法?Java FieldPosition.getField怎么用?Java FieldPosition.getField使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.text.FieldPosition
的用法示例。
在下文中一共展示了FieldPosition.getField方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: formatMeasurePerUnit
import java.text.FieldPosition; //导入方法依赖的package包/类
/**
* Formats a single measure per unit.
*
* An example of such a formatted string is "3.5 meters per second."
*
* @param measure the measure object. In above example, 3.5 meters.
* @param perUnit the per unit. In above example, it is MeasureUnit.SECOND
* @param appendTo formatted string appended here.
* @param pos The field position.
* @return appendTo.
* @stable ICU 55
*/
public StringBuilder formatMeasurePerUnit(
Measure measure,
MeasureUnit perUnit,
StringBuilder appendTo,
FieldPosition pos) {
MeasureUnit resolvedUnit = MeasureUnit.resolveUnitPerUnit(
measure.getUnit(), perUnit);
if (resolvedUnit != null) {
Measure newMeasure = new Measure(measure.getNumber(), resolvedUnit);
return formatMeasure(newMeasure, numberFormat, appendTo, pos);
}
FieldPosition fpos = new FieldPosition(
pos.getFieldAttribute(), pos.getField());
int offset = withPerUnitAndAppend(
formatMeasure(measure, numberFormat, new StringBuilder(), fpos),
perUnit,
appendTo);
if (fpos.getBeginIndex() != 0 || fpos.getEndIndex() != 0) {
pos.setBeginIndex(fpos.getBeginIndex() + offset);
pos.setEndIndex(fpos.getEndIndex() + offset);
}
return appendTo;
}
示例2: exponentialFormat
import java.text.FieldPosition; //导入方法依赖的package包/类
private StringBuffer exponentialFormat(double mantissa, double exponent,
StringBuffer result,
FieldPosition fieldPosition)
{
FieldPosition intfp = new FieldPosition(0);
FieldPosition ruse, euse;
if (fieldPosition.getField() == EXPONENT_FIELD) {
ruse = intfp;
euse = fieldPosition;
}
else {
ruse = fieldPosition;
euse = intfp;
}
dfmt.format(mantissa, result, ruse);
efmt.format(exponent, result, euse);
return result;
}
示例3: selectPlural
import java.text.FieldPosition; //导入方法依赖的package包/类
/**
* Selects the standard plural form for the number/formatter/rules.
*/
public static StandardPlural selectPlural(
Number number, NumberFormat fmt, PluralRules rules,
StringBuffer formattedNumber, FieldPosition pos) {
UFieldPosition fpos = new UFieldPosition(pos.getFieldAttribute(), pos.getField());
fmt.format(number, formattedNumber, fpos);
// TODO: Long, BigDecimal & BigInteger may not fit into doubleValue().
FixedDecimal fd = new FixedDecimal(
number.doubleValue(),
fpos.getCountVisibleFractionDigits(), fpos.getFractionDigits());
String pluralKeyword = rules.select(fd);
pos.setBeginIndex(fpos.getBeginIndex());
pos.setEndIndex(fpos.getEndIndex());
return StandardPlural.orOtherFromString(pluralKeyword);
}
示例4: format
import java.text.FieldPosition; //导入方法依赖的package包/类
/**
* Able to format Collection<? extends Measure>, Measure[], and Measure
* by delegating to formatMeasures.
* If the pos argument identifies a NumberFormat field,
* then its indices are set to the beginning and end of the first such field
* encountered. MeasureFormat itself does not supply any fields.
*
* Calling a
* <code>formatMeasures</code> method is preferred over calling
* this method as they give better performance.
*
* @param obj must be a Collection<? extends Measure>, Measure[], or Measure object.
* @param toAppendTo Formatted string appended here.
* @param pos Identifies a field in the formatted text.
* @see java.text.Format#format(java.lang.Object, java.lang.StringBuffer, java.text.FieldPosition)
*
* @stable ICU53
*/
@Override
public StringBuffer format(Object obj, StringBuffer toAppendTo, FieldPosition pos) {
int prevLength = toAppendTo.length();
FieldPosition fpos =
new FieldPosition(pos.getFieldAttribute(), pos.getField());
if (obj instanceof Collection) {
Collection<?> coll = (Collection<?>) obj;
Measure[] measures = new Measure[coll.size()];
int idx = 0;
for (Object o : coll) {
if (!(o instanceof Measure)) {
throw new IllegalArgumentException(obj.toString());
}
measures[idx++] = (Measure) o;
}
toAppendTo.append(formatMeasures(new StringBuilder(), fpos, measures));
} else if (obj instanceof Measure[]) {
toAppendTo.append(formatMeasures(new StringBuilder(), fpos, (Measure[]) obj));
} else if (obj instanceof Measure){
toAppendTo.append(formatMeasure((Measure) obj, numberFormat, new StringBuilder(), fpos));
} else {
throw new IllegalArgumentException(obj.toString());
}
if (fpos.getBeginIndex() != 0 || fpos.getEndIndex() != 0) {
pos.setBeginIndex(fpos.getBeginIndex() + prevLength);
pos.setEndIndex(fpos.getEndIndex() + prevLength);
}
return toAppendTo;
}
示例5: formatMeasuresSlowTrack
import java.text.FieldPosition; //导入方法依赖的package包/类
private StringBuilder formatMeasuresSlowTrack(
ListFormatter listFormatter,
StringBuilder appendTo,
FieldPosition fieldPosition,
Measure... measures) {
String[] results = new String[measures.length];
// Zero out our field position so that we can tell when we find our field.
FieldPosition fpos = new FieldPosition(
fieldPosition.getFieldAttribute(), fieldPosition.getField());
int fieldPositionFoundIndex = -1;
for (int i = 0; i < measures.length; ++i) {
ImmutableNumberFormat nf = (i == measures.length - 1 ? numberFormat : integerFormat);
if (fieldPositionFoundIndex == -1) {
results[i] = formatMeasure(measures[i], nf, new StringBuilder(), fpos).toString();
if (fpos.getBeginIndex() != 0 || fpos.getEndIndex() != 0) {
fieldPositionFoundIndex = i;
}
} else {
results[i] = formatMeasure(measures[i], nf);
}
}
ListFormatter.FormattedListBuilder builder =
listFormatter.format(Arrays.asList(results), fieldPositionFoundIndex);
// Fix up FieldPosition indexes if our field is found.
if (builder.getOffset() != -1) {
fieldPosition.setBeginIndex(fpos.getBeginIndex() + builder.getOffset() + appendTo.length());
fieldPosition.setEndIndex(fpos.getEndIndex() + builder.getOffset() + appendTo.length());
}
return appendTo.append(builder.toString());
}
示例6: fallbackFormat
import java.text.FieldPosition; //导入方法依赖的package包/类
private final StringBuffer fallbackFormat(Calendar fromCalendar,
Calendar toCalendar,
boolean fromToOnSameDay,
StringBuffer appendTo,
FieldPosition pos) {
String fullPattern = null; // for saving the pattern in fDateFormat
boolean formatDatePlusTimeRange = (fromToOnSameDay && fDatePattern != null && fTimePattern != null);
// the fall back
if (formatDatePlusTimeRange) {
fullPattern = fDateFormat.toPattern(); // save current pattern, restore later
fDateFormat.applyPattern(fTimePattern);
}
FieldPosition otherPos = new FieldPosition(pos.getField());
StringBuffer earlierDate = new StringBuffer(64);
earlierDate = fDateFormat.format(fromCalendar, earlierDate, pos);
StringBuffer laterDate = new StringBuffer(64);
laterDate = fDateFormat.format(toCalendar, laterDate, otherPos);
String fallbackPattern = fInfo.getFallbackIntervalPattern();
adjustPosition(fallbackPattern, earlierDate.toString(), pos, laterDate.toString(), otherPos, pos);
String fallbackRange = SimpleFormatterImpl.formatRawPattern(
fallbackPattern, 2, 2, earlierDate, laterDate);
if (formatDatePlusTimeRange) {
// fallbackRange has just the time range, need to format the date part and combine that
fDateFormat.applyPattern(fDatePattern);
StringBuffer datePortion = new StringBuffer(64);
otherPos.setBeginIndex(0);
otherPos.setEndIndex(0);
datePortion = fDateFormat.format(fromCalendar, datePortion, otherPos);
adjustPosition(fDateTimeFormat, fallbackRange, pos, datePortion.toString(), otherPos, pos);
fallbackRange = SimpleFormatterImpl.formatRawPattern(
fDateTimeFormat, 2, 2, fallbackRange, datePortion);
}
appendTo.append(fallbackRange);
if (formatDatePlusTimeRange) {
// restore full pattern
fDateFormat.applyPattern(fullPattern);
}
return appendTo;
}