Java Code Examples for java.text.FieldPosition#setEndIndex()
The following examples show how to use
java.text.FieldPosition#setEndIndex() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ProperFractionFormat.java From astor with GNU General Public License v2.0 | 6 votes |
/** * 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; }
Example 2
Source File: Math_101_ComplexFormat_t.java From coming with MIT License | 6 votes |
/** * 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; }
Example 3
Source File: ComplexFormat.java From astor with GNU General Public License v2.0 | 6 votes |
/** * 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; }
Example 4
Source File: Vector3DFormat.java From astor with GNU General Public License v2.0 | 6 votes |
/** * 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; }
Example 5
Source File: ProperBigFractionFormat.java From astor with GNU General Public License v2.0 | 6 votes |
/** * 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; }
Example 6
Source File: ComplexFormat.java From astor with GNU General Public License v2.0 | 6 votes |
/** * 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; }
Example 7
Source File: ProperFractionFormat.java From astor with GNU General Public License v2.0 | 6 votes |
/** * 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; }
Example 8
Source File: RealVectorFormat.java From astor with GNU General Public License v2.0 | 6 votes |
/** * 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; }
Example 9
Source File: RealVectorFormat.java From astor with GNU General Public License v2.0 | 6 votes |
/** * 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; }
Example 10
Source File: Vector3DFormat.java From astor with GNU General Public License v2.0 | 6 votes |
/** * 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; }
Example 11
Source File: ProperFractionFormat.java From astor with GNU General Public License v2.0 | 6 votes |
/** * 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; }
Example 12
Source File: ComplexFormat.java From astor with GNU General Public License v2.0 | 5 votes |
/** * 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; }
Example 13
Source File: FractionFormat.java From cacheonix-core with GNU Lesser General Public License v2.1 | 5 votes |
/** * 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; }
Example 14
Source File: FractionFormat.java From astor with GNU General Public License v2.0 | 5 votes |
/** * 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; }
Example 15
Source File: FractionFormat.java From astor with GNU General Public License v2.0 | 5 votes |
/** * 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; }
Example 16
Source File: MessageFormat.java From j2objc with Apache License 2.0 | 5 votes |
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; }
Example 17
Source File: FractionFormat.java From hipparchus with Apache License 2.0 | 5 votes |
/** * 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; }
Example 18
Source File: BigFractionFormat.java From astor with GNU General Public License v2.0 | 5 votes |
/** * 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; }
Example 19
Source File: FieldPositionTest.java From j2objc with Apache License 2.0 | 5 votes |
/** * @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)); }
Example 20
Source File: FractionFormat.java From astor with GNU General Public License v2.0 | 5 votes |
/** * 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; }