java.text.FieldPosition#setEndIndex ( )源码实例Demo

下面列出了java.text.FieldPosition#setEndIndex ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: astor   文件: ProperFractionFormat.java
/**
 * Formats a {@link Fraction} object to produce a string.  The fraction
 * is output in proper format.
 *
 * @param fraction the object to format.
 * @param toAppendTo where the text is to be appended
 * @param pos On input: an alignment field, if desired. On output: the
 *            offsets of the alignment field
 * @return the value passed in as toAppendTo.
 */
@Override
public StringBuffer format(Fraction fraction, StringBuffer toAppendTo,
        FieldPosition pos) {

    pos.setBeginIndex(0);
    pos.setEndIndex(0);

    int num = fraction.getNumerator();
    int den = fraction.getDenominator();
    int whole = num / den;
    num = num % den;

    if (whole != 0) {
        getWholeFormat().format(whole, toAppendTo, pos);
        toAppendTo.append(' ');
        num = Math.abs(num);
    }
    getNumeratorFormat().format(num, toAppendTo, pos);
    toAppendTo.append(" / ");
    getDenominatorFormat().format(den, toAppendTo,
        pos);

    return toAppendTo;
}
 
源代码2 项目: astor   文件: ComplexFormat.java
/**
 * Format the absolute value of the imaginary part.
 *
 * @param absIm Absolute value of the imaginary part of a complex number.
 * @param toAppendTo where the text is to be appended.
 * @param pos On input: an alignment field, if desired. On output: the
 * offsets of the alignment field.
 * @return the value passed in as toAppendTo.
 * @throws MathInternalError if {@code absIm} is not positive.
 */
private StringBuffer formatImaginary(double absIm,
                                     StringBuffer toAppendTo,
                                     FieldPosition pos) {
    if (absIm < 0) {
        throw new MathInternalError();
    }

    pos.setBeginIndex(0);
    pos.setEndIndex(0);

    CompositeFormat.formatDouble(absIm, getImaginaryFormat(), toAppendTo, pos);
    if (toAppendTo.toString().equals("1")) {
        // Remove the character "1" if it is the only one.
        toAppendTo.setLength(0);
    }

    return toAppendTo;
}
 
源代码3 项目: astor   文件: Vector3DFormat.java
/**
 * Formats a {@link Vector3D} object to produce a string.
 * @param vector the object to format.
 * @param toAppendTo where the text is to be appended
 * @param pos On input: an alignment field, if desired. On output: the
 *            offsets of the alignment field
 * @return the value passed in as toAppendTo.
 */
public StringBuffer format(Vector3D vector, StringBuffer toAppendTo,
                           FieldPosition pos) {

    pos.setBeginIndex(0);
    pos.setEndIndex(0);

    // format prefix
    toAppendTo.append(prefix);

    // format components
    formatDouble(vector.getX(), format, toAppendTo, pos);
    toAppendTo.append(separator);
    formatDouble(vector.getY(), format, toAppendTo, pos);
    toAppendTo.append(separator);
    formatDouble(vector.getZ(), format, toAppendTo, pos);

    // format suffix
    toAppendTo.append(suffix);

    return toAppendTo;

}
 
源代码4 项目: astor   文件: ProperBigFractionFormat.java
/**
 * Formats a {@link BigFraction} object to produce a string.  The BigFraction
 * is output in proper format.
 *
 * @param fraction the object to format.
 * @param toAppendTo where the text is to be appended
 * @param pos On input: an alignment field, if desired. On output: the
 *            offsets of the alignment field
 * @return the value passed in as toAppendTo.
 */
@Override
public StringBuffer format(final BigFraction fraction,
                           final StringBuffer toAppendTo, final FieldPosition pos) {

    pos.setBeginIndex(0);
    pos.setEndIndex(0);

    BigInteger num = fraction.getNumerator();
    BigInteger den = fraction.getDenominator();
    BigInteger whole = num.divide(den);
    num = num.remainder(den);

    if (!BigInteger.ZERO.equals(whole)) {
        getWholeFormat().format(whole, toAppendTo, pos);
        toAppendTo.append(' ');
        if (num.compareTo(BigInteger.ZERO) < 0) {
            num = num.negate();
        }
    }
    getNumeratorFormat().format(num, toAppendTo, pos);
    toAppendTo.append(" / ");
    getDenominatorFormat().format(den, toAppendTo, pos);

    return toAppendTo;
}
 
源代码5 项目: astor   文件: ComplexFormat.java
/**
 * Formats a {@link Complex} object to produce a string.
 *
 * @param complex the object to format.
 * @param toAppendTo where the text is to be appended
 * @param pos On input: an alignment field, if desired. On output: the
 *            offsets of the alignment field
 * @return the value passed in as toAppendTo.
 */
public StringBuffer format(Complex complex, StringBuffer toAppendTo,
        FieldPosition pos) {

    pos.setBeginIndex(0);
    pos.setEndIndex(0);

    // format real
    double re = complex.getReal();
    formatDouble(re, getRealFormat(), toAppendTo, pos);

    // format sign and imaginary
    double im = complex.getImaginary();
    if (im < 0.0) {
        toAppendTo.append(" - ");
        formatDouble(-im, getImaginaryFormat(), toAppendTo, pos);
        toAppendTo.append(getImaginaryCharacter());
    } else if (im > 0.0 || Double.isNaN(im)) {
        toAppendTo.append(" + ");
        formatDouble(im, getImaginaryFormat(), toAppendTo, pos);
        toAppendTo.append(getImaginaryCharacter());
    }

    return toAppendTo;
}
 
源代码6 项目: astor   文件: RealVectorFormat.java
/**
 * Formats a {@link RealVector} object to produce a string.
 * @param vector the object to format.
 * @param toAppendTo where the text is to be appended
 * @param pos On input: an alignment field, if desired. On output: the
 *            offsets of the alignment field
 * @return the value passed in as toAppendTo.
 */
public StringBuffer format(RealVector vector, StringBuffer toAppendTo,
                           FieldPosition pos) {

    pos.setBeginIndex(0);
    pos.setEndIndex(0);

    // format prefix
    toAppendTo.append(prefix);

    // format components
    for (int i = 0; i < vector.getDimension(); ++i) {
        if (i > 0) {
            toAppendTo.append(separator);
        }
        CompositeFormat.formatDouble(vector.getEntry(i), format, toAppendTo, pos);
    }

    // format suffix
    toAppendTo.append(suffix);

    return toAppendTo;
}
 
源代码7 项目: astor   文件: RealVectorFormat.java
/**
 * Formats a {@link RealVector} object to produce a string.
 * @param vector the object to format.
 * @param toAppendTo where the text is to be appended
 * @param pos On input: an alignment field, if desired. On output: the
 *            offsets of the alignment field
 * @return the value passed in as toAppendTo.
 */
public StringBuffer format(RealVector vector, StringBuffer toAppendTo,
                           FieldPosition pos) {

    pos.setBeginIndex(0);
    pos.setEndIndex(0);

    // format prefix
    toAppendTo.append(prefix);

    // format components
    for (int i = 0; i < vector.getDimension(); ++i) {
        if (i > 0) {
            toAppendTo.append(separator);
        }
        formatDouble(vector.getEntry(i), format, toAppendTo, pos);
    }

    // format suffix
    toAppendTo.append(suffix);

    return toAppendTo;

}
 
源代码8 项目: astor   文件: ProperFractionFormat.java
/**
 * Formats a {@link Fraction} object to produce a string.  The fraction
 * is output in proper format.
 *
 * @param fraction the object to format.
 * @param toAppendTo where the text is to be appended
 * @param pos On input: an alignment field, if desired. On output: the
 *            offsets of the alignment field
 * @return the value passed in as toAppendTo.
 */
@Override
public StringBuffer format(Fraction fraction, StringBuffer toAppendTo,
        FieldPosition pos) {

    pos.setBeginIndex(0);
    pos.setEndIndex(0);

    int num = fraction.getNumerator();
    int den = fraction.getDenominator();
    int whole = num / den;
    num = num % den;

    if (whole != 0) {
        getWholeFormat().format(whole, toAppendTo, pos);
        toAppendTo.append(' ');
        num = Math.abs(num);
    }
    getNumeratorFormat().format(num, toAppendTo, pos);
    toAppendTo.append(" / ");
    getDenominatorFormat().format(den, toAppendTo,
        pos);

    return toAppendTo;
}
 
源代码9 项目: astor   文件: Vector3DFormat.java
/**
 * Formats a {@link Vector3D} object to produce a string.
 * @param vector the object to format.
 * @param toAppendTo where the text is to be appended
 * @param pos On input: an alignment field, if desired. On output: the
 *            offsets of the alignment field
 * @return the value passed in as toAppendTo.
 */
public StringBuffer format(Vector3D vector, StringBuffer toAppendTo,
                           FieldPosition pos) {

    pos.setBeginIndex(0);
    pos.setEndIndex(0);

    // format prefix
    toAppendTo.append(prefix);

    // format components
    CompositeFormat.formatDouble(vector.getX(), format, toAppendTo, pos);
    toAppendTo.append(separator);
    CompositeFormat.formatDouble(vector.getY(), format, toAppendTo, pos);
    toAppendTo.append(separator);
    CompositeFormat.formatDouble(vector.getZ(), format, toAppendTo, pos);

    // format suffix
    toAppendTo.append(suffix);

    return toAppendTo;
}
 
源代码10 项目: astor   文件: ProperFractionFormat.java
/**
 * Formats a {@link Fraction} object to produce a string.  The fraction
 * is output in proper format.
 *
 * @param fraction the object to format.
 * @param toAppendTo where the text is to be appended
 * @param pos On input: an alignment field, if desired. On output: the
 *            offsets of the alignment field
 * @return the value passed in as toAppendTo.
 */
@Override
public StringBuffer format(Fraction fraction, StringBuffer toAppendTo,
        FieldPosition pos) {

    pos.setBeginIndex(0);
    pos.setEndIndex(0);

    int num = fraction.getNumerator();
    int den = fraction.getDenominator();
    int whole = num / den;
    num = num % den;

    if (whole != 0) {
        getWholeFormat().format(whole, toAppendTo, pos);
        toAppendTo.append(' ');
        num = Math.abs(num);
    }
    getNumeratorFormat().format(num, toAppendTo, pos);
    toAppendTo.append(" / ");
    getDenominatorFormat().format(den, toAppendTo,
        pos);

    return toAppendTo;
}
 
源代码11 项目: coming   文件: Math_101_ComplexFormat_t.java
/**
 * Formats a {@link Complex} object to produce a string.
 *
 * @param complex the object to format.
 * @param toAppendTo where the text is to be appended
 * @param pos On input: an alignment field, if desired. On output: the
 *            offsets of the alignment field
 * @return the value passed in as toAppendTo.
 */
public StringBuffer format(Complex complex, StringBuffer toAppendTo,
        FieldPosition pos) {
    
    pos.setBeginIndex(0);
    pos.setEndIndex(0);

    // format real
    double re = complex.getReal();
    formatDouble(re, getRealFormat(), toAppendTo, pos);
    
    // format sign and imaginary
    double im = complex.getImaginary();
    if (im < 0.0) {
        toAppendTo.append(" - ");
        formatDouble(-im, getImaginaryFormat(), toAppendTo, pos);
        toAppendTo.append(getImaginaryCharacter());
    } else if (im > 0.0 || Double.isNaN(im)) {
        toAppendTo.append(" + ");
        formatDouble(im, getImaginaryFormat(), toAppendTo, pos);
        toAppendTo.append(getImaginaryCharacter());
    }
    
    return toAppendTo;
}
 
源代码12 项目: astor   文件: FractionFormat.java
/**
 * Formats a {@link Fraction} object to produce a string.  The fraction is
 * output in improper format.
 *
 * @param fraction the object to format.
 * @param toAppendTo where the text is to be appended
 * @param pos On input: an alignment field, if desired. On output: the
 *            offsets of the alignment field
 * @return the value passed in as toAppendTo.
 */
public StringBuffer format(final Fraction fraction,
                           final StringBuffer toAppendTo, final FieldPosition pos) {

    pos.setBeginIndex(0);
    pos.setEndIndex(0);

    getNumeratorFormat().format(fraction.getNumerator(), toAppendTo, pos);
    toAppendTo.append(" / ");
    getDenominatorFormat().format(fraction.getDenominator(), toAppendTo,
        pos);

    return toAppendTo;
}
 
源代码13 项目: j2objc   文件: FieldPositionTest.java
/**
 * @tests java.text.FieldPosition#equals(java.lang.Object)
 */
public void test_equalsLjava_lang_Object() {
	// Test for method boolean
	// java.text.FieldPosition.equals(java.lang.Object)
	FieldPosition fpos = new FieldPosition(1);
	FieldPosition fpos1 = new FieldPosition(1);
	assertTrue("Identical objects were not equal!", fpos.equals(fpos1));

	FieldPosition fpos2 = new FieldPosition(2);
	assertTrue("Objects with a different ID should not be equal!", !fpos
			.equals(fpos2));

	fpos.setBeginIndex(1);
	fpos1.setBeginIndex(2);
	assertTrue("Objects with a different beginIndex were still equal!",
			!fpos.equals(fpos1));
	fpos1.setBeginIndex(1);
	fpos1.setEndIndex(2);
	assertTrue("Objects with a different endIndex were still equal!", !fpos
			.equals(fpos1));

	FieldPosition fpos3 = new FieldPosition(DateFormat.Field.ERA, 1);
	assertTrue("Objects with a different attribute should not be equal!",
			!fpos.equals(fpos3));
	FieldPosition fpos4 = new FieldPosition(DateFormat.Field.AM_PM, 1);
	assertTrue("Objects with a different attribute should not be equal!",
			!fpos3.equals(fpos4));
}
 
源代码14 项目: astor   文件: BigFractionFormat.java
/**
 * Formats a {@link BigFraction} object to produce a string.  The BigFraction is
 * output in improper format.
 *
 * @param BigFraction the object to format.
 * @param toAppendTo where the text is to be appended
 * @param pos On input: an alignment field, if desired. On output: the
 *            offsets of the alignment field
 * @return the value passed in as toAppendTo.
 */
public StringBuffer format(final BigFraction BigFraction,
                           final StringBuffer toAppendTo, final FieldPosition pos) {
    
    pos.setBeginIndex(0);
    pos.setEndIndex(0);

    getNumeratorFormat().format(BigFraction.getNumerator(), toAppendTo, pos);
    toAppendTo.append(" / ");
    getDenominatorFormat().format(BigFraction.getDenominator(), toAppendTo, pos);
    
    return toAppendTo;
}
 
源代码15 项目: hipparchus   文件: FractionFormat.java
/**
 * Formats a {@link Fraction} object to produce a string.  The fraction is
 * output in improper format.
 *
 * @param fraction the object to format.
 * @param toAppendTo where the text is to be appended
 * @param pos On input: an alignment field, if desired. On output: the
 * offsets of the alignment field
 * @return the value passed in as toAppendTo.
 */
public StringBuffer format(final Fraction fraction, // NOPMD - PMD false positive, we cannot have @Override here
                           final StringBuffer toAppendTo, final FieldPosition pos) {

    pos.setBeginIndex(0);
    pos.setEndIndex(0);

    getNumeratorFormat().format(fraction.getNumerator(), toAppendTo, pos);
    toAppendTo.append(" / ");
    getDenominatorFormat().format(fraction.getDenominator(), toAppendTo,
        pos);

    return toAppendTo;
}
 
源代码16 项目: j2objc   文件: MessageFormat.java
private FieldPosition updateMetaData(AppendableWrapper dest, int prevLength,
                                     FieldPosition fp, Object argId) {
    if (dest.attributes != null && prevLength < dest.length) {
        dest.attributes.add(new AttributeAndPosition(argId, prevLength, dest.length));
    }
    if (fp != null && Field.ARGUMENT.equals(fp.getFieldAttribute())) {
        fp.setBeginIndex(prevLength);
        fp.setEndIndex(dest.length);
        return null;
    }
    return fp;
}
 
源代码17 项目: astor   文件: FractionFormat.java
/**
 * Formats a {@link Fraction} object to produce a string.  The fraction is
 * output in improper format.
 *
 * @param fraction the object to format.
 * @param toAppendTo where the text is to be appended
 * @param pos On input: an alignment field, if desired. On output: the
 *            offsets of the alignment field
 * @return the value passed in as toAppendTo.
 */
public StringBuffer format(final Fraction fraction,
                           final StringBuffer toAppendTo, final FieldPosition pos) {
    
    pos.setBeginIndex(0);
    pos.setEndIndex(0);

    getNumeratorFormat().format(fraction.getNumerator(), toAppendTo, pos);
    toAppendTo.append(" / ");
    getDenominatorFormat().format(fraction.getDenominator(), toAppendTo,
        pos);
    
    return toAppendTo;
}
 
源代码18 项目: astor   文件: FractionFormat.java
/**
 * Formats a {@link Fraction} object to produce a string.  The fraction is
 * output in improper format.
 *
 * @param fraction the object to format.
 * @param toAppendTo where the text is to be appended
 * @param pos On input: an alignment field, if desired. On output: the
 *            offsets of the alignment field
 * @return the value passed in as toAppendTo.
 */
public StringBuffer format(final Fraction fraction,
                           final StringBuffer toAppendTo, final FieldPosition pos) {

    pos.setBeginIndex(0);
    pos.setEndIndex(0);

    getNumeratorFormat().format(fraction.getNumerator(), toAppendTo, pos);
    toAppendTo.append(" / ");
    getDenominatorFormat().format(fraction.getDenominator(), toAppendTo,
        pos);

    return toAppendTo;
}
 
源代码19 项目: cacheonix-core   文件: FractionFormat.java
/**
 * Formats a {@link Fraction} object to produce a string.  The fraction is
 * output in improper format.
 *
 * @param fraction the object to format.
 * @param toAppendTo where the text is to be appended
 * @param pos On input: an alignment field, if desired. On output: the
 *            offsets of the alignment field
 * @return the value passed in as toAppendTo.
 */
public StringBuffer format(Fraction fraction, StringBuffer toAppendTo,
        FieldPosition pos) {
    
    pos.setBeginIndex(0);
    pos.setEndIndex(0);

    getNumeratorFormat().format(fraction.getNumerator(), toAppendTo, pos);
    toAppendTo.append(" / ");
    getDenominatorFormat().format(fraction.getDenominator(), toAppendTo,
        pos);
    
    return toAppendTo;
}
 
源代码20 项目: astor   文件: ComplexFormat.java
/**
 * Format the absolute value of the imaginary part.
 *
 * @param absIm Absolute value of the imaginary part of a complex number.
 * @param toAppendTo where the text is to be appended.
 * @param pos On input: an alignment field, if desired. On output: the
 * offsets of the alignment field.
 * @return the value passed in as toAppendTo.
 */
private StringBuffer formatImaginary(double absIm,
                                     StringBuffer toAppendTo,
                                     FieldPosition pos) {
    pos.setBeginIndex(0);
    pos.setEndIndex(0);

    CompositeFormat.formatDouble(absIm, getImaginaryFormat(), toAppendTo, pos);
    if (toAppendTo.toString().equals("1")) {
        // Remove the character "1" if it is the only one.
        toAppendTo.setLength(0);
    }

    return toAppendTo;
}