Package java.text

Examples of java.text.FieldPosition$Delegate


                    && Character.isDigit(formatting.charAt(2))) {

                numberFormat.setMaximumFractionDigits(Integer.parseInt(formatting.charAt(2) + ""));

                numberFormat.format(number, outputTo, new FieldPosition(0));

                return 3;

            }

            numberFormat.format(number, outputTo, new FieldPosition(0));

            return 1;

        } else if ((0 < formatting.length()) && (formatting.charAt(0) == '.')) {

            if ((1 < formatting.length())

                    && Character.isDigit(formatting.charAt(1))) {

                numberFormat.setMaximumFractionDigits(Integer.parseInt(formatting.charAt(1) + ""));

                numberFormat.format(number, outputTo, new FieldPosition(0));

                return 2;

            }

        }

        numberFormat.format(number, outputTo, new FieldPosition(0));

        return 1;

    }
View Full Code Here


                && Character.isDigit(formatting.charAt(0))) {
            numberFormat.setMinimumIntegerDigits(Integer.parseInt(formatting.charAt(0) + ""));
            if ((2 < formatting.length()) && (formatting.charAt(1) == '.')
                    && Character.isDigit(formatting.charAt(2))) {
                numberFormat.setMaximumFractionDigits(Integer.parseInt(formatting.charAt(2) + ""));
                numberFormat.format(number, outputTo, new FieldPosition(0));
                return 3;
            }
            numberFormat.format(number, outputTo, new FieldPosition(0));
            return 1;
        } else if ((0 < formatting.length()) && (formatting.charAt(0) == '.')) {
            if ((1 < formatting.length())
                    && Character.isDigit(formatting.charAt(1))) {
                numberFormat.setMaximumFractionDigits(Integer.parseInt(formatting.charAt(1) + ""));
                numberFormat.format(number, outputTo, new FieldPosition(0));
                return 2;
            }
        }
        numberFormat.format(number, outputTo, new FieldPosition(0));
        return 1;
    }
View Full Code Here

                    buf.append( ancientDate );
                else
                    DateTool.formatOldCookie
                        (new Date( System.currentTimeMillis() +
                                   maxAge *1000L), buf,
                         new FieldPosition(0));

            } else {
                buf.append ("; Max-Age=");
                buf.append (maxAge);
            }
View Full Code Here

    }
  }
  public String getNumberAsString(Object o){
    if (enableLocalized){
      return formatNumber.format(o, new StringBuffer(),
                    new FieldPosition(0)).toString();
    }
    else {
      return o.toString();
    }
  }
View Full Code Here

        // may be exchanged while we are trying to use it
        MessageFormat myFormat = format;
        synchronized (myFormat) {
            myFormat.format(new Object[] { new Date(), marker,
                Thread.currentThread().getName(), name, level.toString(), msg,
                fqcn }, buffer, new FieldPosition(0));
        }
    }
View Full Code Here

                    buf.append( ancientDate );
                else
                    DateTool.formatOldCookie
                        (new Date( System.currentTimeMillis() +
                                   maxAge *1000L), buf,
                         new FieldPosition(0));

            } else {
                buf.append ("; Max-Age=");
                buf.append (maxAge);
            }
View Full Code Here

    assertEquals("O", boolFormat3.format(falseValue));
  }


  public void testFormatThrowsException() {
    FieldPosition pos = new FieldPosition(0);
    StringBuffer sb = new StringBuffer();
   
    try {
      boolFormat.format(Integer.valueOf(7));
      fail();
    } catch (IllegalArgumentException e) {
      // Expected.
    }
   
    boolFormat.format(null);
    assertTrue(0 == pos.getBeginIndex());
    assertTrue(0 == pos.getEndIndex());
   
    try {
      // StringBuffer is null.
      boolFormat.format(trueValue, null, pos);
      fail();
    } catch (NullPointerException e) {
      assertTrue(0 == pos.getBeginIndex());
      assertTrue(0 == pos.getEndIndex());
    }
    try {
      // FieldPosition is null.
      boolFormat.format(trueValue, sb, null);
      fail();
    } catch (NullPointerException e) {
      // OK.
    }
    pos = new FieldPosition(0);
    sb = new StringBuffer();
    // Object is null.
    boolFormat.format(null, sb, pos);
    assertTrue(0 == pos.getBeginIndex());
    assertTrue(0 == pos.getEndIndex());
    assertTrue(0 == sb.length());
   
    pos = new FieldPosition(0);
    try {
      // Object is not instance of Boolean.
      boolFormat.format(new Object(), new StringBuffer(), pos);
      fail();
    } catch (IllegalArgumentException e) {
      assertTrue(0 == pos.getBeginIndex());
      assertTrue(0 == pos.getEndIndex());
      assertTrue(0 == sb.length());
    }
  }
View Full Code Here

  }

  public void testFieldPosition() {

    // Boolean trueValue.
    FieldPosition pos = new FieldPosition(0);
    StringBuffer sb = new StringBuffer();
    boolFormat.format(trueValue, sb, pos);
    assertTrue(0 == pos.getBeginIndex());
    assertTrue(("true".length() - 1) == pos.getEndIndex());

    // Boolean falseValue.
    pos = new FieldPosition(0);
    sb = new StringBuffer();
    boolFormat.format(falseValue, sb, pos);
    assertTrue(0 == pos.getBeginIndex());
    assertTrue(("false".length() - 1) == pos.getEndIndex());
  }
View Full Code Here

        textFormat.format("abcdefghijklmnop!@#$%^&*()"));
  }

  public void testFormatThrowsException() {
    textFormat = new TextFormat();
    fieldPos = new FieldPosition(0);
    sb = new StringBuffer();
    try {
      // StringBuffer null.
      textFormat.format("String", null, fieldPos);
      fail();
    } catch (NullPointerException e) {
      assertTrue(0 == fieldPos.getBeginIndex());
      assertTrue(0 == fieldPos.getEndIndex());
    }
    fieldPos = new FieldPosition(0);
    try {
      // FieldPosition is null.
      textFormat.format("String", sb, null);
      fail();
    } catch (NullPointerException e) {
      // OK.
    }
    fieldPos = new FieldPosition(0);
    sb = new StringBuffer();
    try {
      // Object is null.
      textFormat.format(null, sb, fieldPos);
      fail();
    } catch (IllegalArgumentException e) {
      assertTrue(0 == sb.length());
      assertTrue(0 == fieldPos.getBeginIndex());
      assertTrue(0 == fieldPos.getEndIndex());
    }
    fieldPos = new FieldPosition(0);
    sb = new StringBuffer();
    try {
      // Object is not instance of String
      textFormat.format(new Object(), sb, fieldPos);
      fail();
View Full Code Here

  }

  public void testFormatFieldPosition() {
    // Regular TextValue.
    textFormat = new TextFormat();
    fieldPos = new FieldPosition(0);
    sb = new StringBuffer();
    textFormat.format("Another String", sb, fieldPos);
    assertTrue(0 == fieldPos.getBeginIndex());
    assertTrue(("Another String".length() - 1) == fieldPos.getEndIndex());
    // Empty TextValue.
    fieldPos = new FieldPosition(0);
    sb = new StringBuffer();
    textFormat.format("", sb, fieldPos);
    assertTrue(0 == fieldPos.getBeginIndex());
    assertTrue(0 == fieldPos.getEndIndex());
  }
View Full Code Here

TOP

Related Classes of java.text.FieldPosition$Delegate

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.