当前位置: 首页>>代码示例>>Java>>正文


Java FieldPosition类代码示例

本文整理汇总了Java中java.text.FieldPosition的典型用法代码示例。如果您正苦于以下问题:Java FieldPosition类的具体用法?Java FieldPosition怎么用?Java FieldPosition使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


FieldPosition类属于java.text包,在下文中一共展示了FieldPosition类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: subFormat

import java.text.FieldPosition; //导入依赖的package包/类
/**
 * Formats a single field. This is the version called internally; it
 * adds fieldNum and capitalizationContext parameters.
 *
 * @internal
 * @deprecated This API is ICU internal only.
 */
@Deprecated
protected String subFormat(char ch, int count, int beginOffset,
                           int fieldNum, DisplayContext capitalizationContext,
                           FieldPosition pos,
                           Calendar cal)
{
    StringBuffer buf = new StringBuffer();
    subFormat(buf, ch, count, beginOffset, fieldNum, capitalizationContext, pos, cal);
    return buf.toString();
}
 
开发者ID:abhijitvalluri,项目名称:fitnotifications,代码行数:18,代码来源:SimpleDateFormat.java

示例2: convertDollar2Cent

import java.text.FieldPosition; //导入依赖的package包/类
/**
 * 将字符串"元"转换成"分"
 * @param str
 * @return
 */
public static String convertDollar2Cent(String str) {
    DecimalFormat df = new DecimalFormat("0.00");
    StringBuffer sb = df.format(Double.parseDouble(str),
            new StringBuffer(), new FieldPosition(0));
    int idx = sb.toString().indexOf(".");
    sb.deleteCharAt(idx);
    for (; sb.length() != 1;) {
        if(sb.charAt(0) == '0') {
            sb.deleteCharAt(0);
        } else {
            break;
        }
    }
    return sb.toString();
}
 
开发者ID:ywtnhm,项目名称:pay-xxpay-master,代码行数:21,代码来源:AmountUtil.java

示例3: getLocalePatternInfo

import java.text.FieldPosition; //导入依赖的package包/类
/**
 * Retourne un tableau avec les informations sur le format standard des dates et heures.<br>
 * [0] = séparateur dans une date, exemple: "."<br>
 * [1] = séparateur sous la forme d'une expression regex, exemple: "\."<br>
 * [2] = le format d'une date, exemple: "dd.MM.yy"<br>
 * [3] = séparateur d'un temps, exemple: ":"<br>
 * [4] = séparateur d'un temps sous la forme d'une expression regex, exemple: "\:"<br>
 * [5] = le format d'un temps, exemple: "HH:mm:ss"<br>
 *
 * @return un tableau avec les informations sus-mentionnées
 */
public static String[] getLocalePatternInfo() {
  String info[] = new String[6];
  DateFormat dateFormat = DateFormat.getDateInstance(DateFormat.SHORT, Locale.getDefault());
  FieldPosition yearPosition = new FieldPosition(DateFormat.YEAR_FIELD);

  StringBuffer buffer = new StringBuffer();
  StringBuffer format = dateFormat.format(getNow(), buffer, yearPosition);
  String pattern = new SimpleDateFormat().toPattern();
  String datePattern = pattern.substring(0, format.length());
  String hourPattern = pattern.substring(format.length() + 1);

  // infos sur le format des dates
  int yearIdx = yearPosition.getBeginIndex() - 1;
  info[0] = format.substring(yearIdx, yearIdx + 1);
  info[1] = "\\" + info[0];
  info[2] = datePattern;

  // infos sur le format des heures
  info[3] = hourPattern.substring(2, 3);
  info[4] = "\\" + info[3];
  info[5] = hourPattern + info[3] + "ss";
  return info;
}
 
开发者ID:elgoupil,项目名称:GoupilBot,代码行数:35,代码来源:DateTimeLib.java

示例4: format

import java.text.FieldPosition; //导入依赖的package包/类
/**
 * Formats the pattern with the value and adjusts the FieldPosition.
 */
public static StringBuilder format(String compiledPattern, CharSequence value,
        StringBuilder appendTo, FieldPosition pos) {
    int[] offsets = new int[1];
    SimpleFormatterImpl.formatAndAppend(compiledPattern, appendTo, offsets, value);
    if (pos.getBeginIndex() != 0 || pos.getEndIndex() != 0) {
        if (offsets[0] >= 0) {
            pos.setBeginIndex(pos.getBeginIndex() + offsets[0]);
            pos.setEndIndex(pos.getEndIndex() + offsets[0]);
        } else {
            pos.setBeginIndex(0);
            pos.setEndIndex(0);
        }
    }
    return appendTo;
}
 
开发者ID:abhijitvalluri,项目名称:fitnotifications,代码行数:19,代码来源:QuantityFormatter.java

示例5: subFormat

import java.text.FieldPosition; //导入依赖的package包/类
/**
 * {@inheritDoc}
 * @internal
 * @deprecated This API is ICU internal only.
 */
@Override
@Deprecated
protected void subFormat(StringBuffer buf,
                         char ch, int count, int beginOffset,
                         int fieldNum, DisplayContext capitalizationContext,
                         FieldPosition pos,
                         Calendar cal) {

    // Logic to handle 'G' for chinese calendar is moved into SimpleDateFormat,
    // and obsolete pattern char 'l' is now ignored in SimpleDateFormat, so we
    // just use its implementation
    super.subFormat(buf, ch, count, beginOffset, fieldNum, capitalizationContext, pos, cal);

    // The following is no longer an issue for this subclass...
    // TODO: add code to set FieldPosition for 'G' and 'l' fields. This
    // is a DESIGN FLAW -- subclasses shouldn't have to duplicate the
    // code that handles this at the end of SimpleDateFormat.subFormat.
    // The logic should be moved up into SimpleDateFormat.format.
}
 
开发者ID:abhijitvalluri,项目名称:fitnotifications,代码行数:25,代码来源:ChineseDateFormat.java

示例6: checkLength

import java.text.FieldPosition; //导入依赖的package包/类
/** This method will ensure that the input Number does not exceed the specified limits.
 * @param input The number whose length is to be checked.
 * @param intSize The upper limit on the number of digits allowed before the decimal.
 * @param fracSize The upper limit on the number of digits allowed after the decimal.
 * @return a true if the input Number is within the specified limits.
 */
private boolean checkLength(Number input, Integer intSize, Integer fracSize) {
    if (input != null && (intSize != null || fracSize != null)) {
        double value = Math.abs(input.doubleValue());

        if (intSize != null) {
            double intLimit = Math.pow(10, intSize.intValue());
            if ((long) value >= (long) intLimit)
                return false;
        }

        if (fracSize != null) {
            // @todo: should find a much more efficient way of finding the no. of fractional digits
            StringBuffer buf = new StringBuffer();
            FieldPosition fp = new FieldPosition(NumberFormat.FRACTION_FIELD);
            NumberFormat df = NumberFormat.getNumberInstance();
            df.setGroupingUsed(false);
            df.setMaximumFractionDigits(20); // THIS SHOULD BE SUFFICIENT
            df.format(value, buf, fp);
            String fracString = buf.substring(fp.getBeginIndex(), fp.getEndIndex());
            if (fracString != null && fracString.length() > fracSize.intValue())
                return false;
        }
    }
    return true;
}
 
开发者ID:jaffa-projects,项目名称:jaffa-framework,代码行数:32,代码来源:MaxLengthValidator.java

示例7: formatMeasure

import java.text.FieldPosition; //导入依赖的package包/类
private StringBuilder formatMeasure(
        Measure measure,
        ImmutableNumberFormat nf,
        StringBuilder appendTo,
        FieldPosition fieldPosition) {
    Number n = measure.getNumber();
    MeasureUnit unit = measure.getUnit();
    if (unit instanceof Currency) {
        return appendTo.append(
                currencyFormat.format(
                        new CurrencyAmount(n, (Currency) unit),
                        new StringBuffer(),
                        fieldPosition));

    }
    StringBuffer formattedNumber = new StringBuffer();
    StandardPlural pluralForm = QuantityFormatter.selectPlural(
            n, nf.nf, rules, formattedNumber, fieldPosition);
    String formatter = getPluralFormatter(unit, formatWidth, pluralForm.ordinal());
    return QuantityFormatter.format(formatter, formattedNumber, appendTo, fieldPosition);
}
 
开发者ID:abhijitvalluri,项目名称:fitnotifications,代码行数:22,代码来源:MeasureFormat.java

示例8: formatToCharacterIterator

import java.text.FieldPosition; //导入依赖的package包/类
/**
 * {@inheritDoc}
 *
 * @stable ICU 49
 */
@Override
public AttributedCharacterIterator formatToCharacterIterator(Object obj) {
    StringBuffer toAppendTo = new StringBuffer();
    FieldPosition pos = new FieldPosition(0);
    toAppendTo = format(obj, toAppendTo, pos);

    // supporting only DateFormat.Field.TIME_ZONE
    AttributedString as = new AttributedString(toAppendTo.toString());
    as.addAttribute(DateFormat.Field.TIME_ZONE, DateFormat.Field.TIME_ZONE);

    return as.getIterator();
}
 
开发者ID:abhijitvalluri,项目名称:fitnotifications,代码行数:18,代码来源:TimeZoneFormat.java

示例9: 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;
   }
 
开发者ID:etomica,项目名称:etomica,代码行数:22,代码来源:ScientificFormat.java

示例10: format

import java.text.FieldPosition; //导入依赖的package包/类
@Override
public final StringBuffer format(
  Object obj, 
  StringBuffer toAppendTo,
  FieldPosition fieldPosition)
{
  if (obj instanceof Color)
  {
    return format((Color)obj, toAppendTo, fieldPosition);
  }
  else if (obj instanceof Number)
  {
    return format(new Color(((Number)obj).intValue()),
                  toAppendTo, fieldPosition);
  }
  else 
  {
    throw 
      new IllegalArgumentException(_LOG.getMessage(
        "CANNOT_FORMAT_GIVEN_OBJECT_AS_COLOR"));
  }
}
 
开发者ID:apache,项目名称:myfaces-trinidad,代码行数:23,代码来源:ColorFormat.java

示例11: format

import java.text.FieldPosition; //导入依赖的package包/类
@Override
public StringBuffer format(Object o, StringBuffer stringBuffer, FieldPosition fieldPosition) {
    Address address = (Address) o;
    String result = format;

    result = replace(result, "%p", address.getPostcode());
    result = replace(result, "%c", address.getCountry());
    result = replace(result, "%s", address.getState());
    result = replace(result, "%d", address.getDistrict());
    result = replace(result, "%t", address.getSettlement());
    result = replace(result, "%u", address.getSuburb());
    result = replace(result, "%r", address.getStreet());
    result = replace(result, "%h", address.getHouse());

    result = result.replaceAll("^[, ]*", "");

    return stringBuffer.append(result);
}
 
开发者ID:bamartinezd,项目名称:traccar-service,代码行数:19,代码来源:AddressFormat.java

示例12: format

import java.text.FieldPosition; //导入依赖的package包/类
@Override
public StringBuffer format(Object obj, StringBuffer toAppendTo, FieldPosition pos) {
	if (obj instanceof Double) {
		return toAppendTo.append(convertWithFormat(((Double) obj).longValue(), NO_DECIMAL));
	}
	throw new RuntimeException("Unexpected call.");
}
 
开发者ID:eclipse,项目名称:n4js,代码行数:8,代码来源:SimpleTimeFormat.java

示例13: format

import java.text.FieldPosition; //导入依赖的package包/类
@Override
public @Nullable StringBuffer format(@Nullable Object obj, @Nullable StringBuffer toAppendTo, @Nullable FieldPosition pos) {
    if (obj == null || toAppendTo == null) {
        return new StringBuffer(SWTCHART_EMPTY_LABEL);
    }

    Double doubleObj = (Double) obj;

    /*
     * Return a string buffer with a space in it since SWT does not like to
     * draw empty strings.
     */
    if ((doubleObj % 1 != 0) || !fMap.containsValue((doubleObj.intValue()))) {
        return new StringBuffer(SWTCHART_EMPTY_LABEL);
    }

    for (Entry<String, Integer> entry : fMap.entrySet()) {
        /*
         * FIXME: Find if the elements are the same, based on their double
         * value, because SWTChart uses double values so we do the same
         * check. The loss of precision could lead to false positives.
         */
        if (Double.compare(entry.getValue().doubleValue(), doubleObj.doubleValue()) == 0) {
            if (entry.getKey() == null) {
                return new StringBuffer(UNKNOWN_REPRESENTATION);
            }
            return toAppendTo.append(entry.getKey());
        }
    }
    return new StringBuffer(SWTCHART_EMPTY_LABEL);
}
 
开发者ID:lttng,项目名称:lttng-scope,代码行数:32,代码来源:LamiLabelFormat.java

示例14: format

import java.text.FieldPosition; //导入依赖的package包/类
/**
 * Formats the given date.
 * 
 * @param date  the date.
 * @param toAppendTo  the string buffer.
 * @param fieldPosition  the field position.
 * 
 * @return The formatted date.
 */
public StringBuffer format(Date date, StringBuffer toAppendTo,
                           FieldPosition fieldPosition) {
    this.calendar.setTime(date);
    int month = this.calendar.get(Calendar.MONTH);
    toAppendTo.append(this.months[month]);
    if (this.showYear[month]) {
        toAppendTo.append(this.yearFormatter.format(date));
    }
    return toAppendTo;   
}
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:20,代码来源:MonthDateFormat.java

示例15: 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);
}
 
开发者ID:abhijitvalluri,项目名称:fitnotifications,代码行数:18,代码来源:QuantityFormatter.java


注:本文中的java.text.FieldPosition类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。