static void assertDecimalFormatSymbolsRIFrance(DecimalFormatSymbols dfs) {
   // Values based on Java 1.5 RI DecimalFormatSymbols for Locale.FRANCE
   /*
    * currency = [EUR]
    * currencySymbol = [€][U+20ac]
    * decimalSeparator = [,][U+002c]
    * digit = [#][U+0023]
    * groupingSeparator = [ ][U+00a0]
    * infinity = [∞][U+221e]
    * internationalCurrencySymbol = [EUR]
    * minusSign = [-][U+002d]
    * monetaryDecimalSeparator = [,][U+002c]
    * naN = [�][U+fffd]
    * patternSeparator = [;][U+003b]
    * perMill = [‰][U+2030]
    * percent = [%][U+0025]
    * zeroDigit = [0][U+0030]
    */
   assertEquals("EUR", dfs.getCurrency().getCurrencyCode());
   assertEquals("\u20AC", dfs.getCurrencySymbol());
   assertEquals(',', dfs.getDecimalSeparator());
   assertEquals('#', dfs.getDigit());
   assertEquals('\u00a0', dfs.getGroupingSeparator());
   assertEquals("\u221e", dfs.getInfinity());
   assertEquals("EUR", dfs.getInternationalCurrencySymbol());
   assertEquals('-', dfs.getMinusSign());
   assertEquals(',', dfs.getMonetaryDecimalSeparator());
   // RI's default NaN is U+FFFD, Harmony's is based on ICU
   assertEquals("\uFFFD", dfs.getNaN());
   assertEquals('\u003b', dfs.getPatternSeparator());
   assertEquals('\u2030', dfs.getPerMill());
   assertEquals('%', dfs.getPercent());
   assertEquals('0', dfs.getZeroDigit());
 }
Exemple #2
0
  public void toggleSign() {
    DecimalFormatSymbols symbols = ((DecimalFormat) formatter).getDecimalFormatSymbols();
    char minus = symbols.getMinusSign();
    String exp = symbols.getExponentSeparator();
    String text = getText().toString();

    int expPos = text.lastIndexOf(exp);
    if (expPos == -1) {
      if (text.charAt(0) == minus) {
        text = text.substring(1);
      } else {
        text = minus + text;
      }

    } else { // Exponent entered
      try {
        if (text.charAt(expPos + exp.length()) == minus) {
          text = text.substring(0, expPos) + exp + text.substring(expPos + exp.length() + 1);
        } else {
          text = text.substring(0, expPos) + exp + minus + text.substring(expPos + exp.length());
        }
      } catch (StringIndexOutOfBoundsException e) {
        text = text + minus;
      }
    }

    setText(text);
  }
Exemple #3
0
 public static VerifyListener getNumberVerifyListener(Locale locale) {
   DecimalFormatSymbols symbols = DecimalFormatSymbols.getInstance(locale);
   final char[] allowedChars =
       new char[] {
         symbols.getDecimalSeparator(),
         symbols.getGroupingSeparator(),
         symbols.getMinusSign(),
         symbols.getZeroDigit(),
         symbols.getMonetaryDecimalSeparator(),
         '+'
       };
   final String exponentSeparator = symbols.getExponentSeparator();
   return new VerifyListener() {
     @Override
     public void verifyText(VerifyEvent e) {
       for (int i = 0; i < e.text.length(); i++) {
         char ch = e.text.charAt(i);
         if (!Character.isDigit(ch)
             && !ArrayUtils.contains(allowedChars, ch)
             && exponentSeparator.indexOf(ch) == -1) {
           e.doit = false;
           return;
         }
       }
       e.doit = true;
     }
   };
 }
Exemple #4
0
  private static void describeDecimalFormatSymbols(StringBuilder result, DecimalFormatSymbols dfs) {
    result.append("Currency Symbol: " + unicodeString(dfs.getCurrencySymbol()) + "\n");
    result.append(
        "International Currency Symbol: "
            + unicodeString(dfs.getInternationalCurrencySymbol())
            + "\n");
    result.append("<p>");

    result.append("Digit: " + unicodeString(dfs.getDigit()) + "\n");
    result.append("Pattern Separator: " + unicodeString(dfs.getPatternSeparator()) + "\n");
    result.append("<p>");

    result.append("Decimal Separator: " + unicodeString(dfs.getDecimalSeparator()) + "\n");
    result.append(
        "Monetary Decimal Separator: " + unicodeString(dfs.getMonetaryDecimalSeparator()) + "\n");
    // 1.6: result.append("Exponent Separator: " + dfs.getExponentSeparator() + "\n");
    result.append("Grouping Separator: " + unicodeString(dfs.getGroupingSeparator()) + "\n");

    result.append("Infinity: " + unicodeString(dfs.getInfinity()) + "\n");
    result.append("Minus Sign: " + unicodeString(dfs.getMinusSign()) + "\n");
    result.append("NaN: " + unicodeString(dfs.getNaN()) + "\n");
    result.append("Percent: " + unicodeString(dfs.getPercent()) + "\n");
    result.append("Per Mille: " + unicodeString(dfs.getPerMill()) + "\n");
    result.append("Zero Digit: " + unicodeString(dfs.getZeroDigit()) + "\n");
    StringBuilder digits = new StringBuilder();
    for (int i = 0; i <= 9; ++i) {
      digits.append((char) (dfs.getZeroDigit() + i));
    }
    result.append("Digits: " + digits.toString() + "\n");
    result.append("<p>");
    result.append("<p>");
  }
 /** @tests java.text.DecimalFormatSymbols#setMinusSign(char) */
 @TestTargetNew(
     level = TestLevel.COMPLETE,
     notes = "",
     method = "setMinusSign",
     args = {char.class})
 public void test_setMinusSignC() {
   dfs.setMinusSign('&');
   assertEquals("Returned incorrect MinusSign symbol", '&', dfs.getMinusSign());
 }
Exemple #6
0
 /**
  * Constructor
  *
  * @param displayType
  * @param format
  * @param tc
  * @param title
  */
 public MDocNumber(int displayType, DecimalFormat format, JTextComponent tc, String title) {
   super();
   if (format == null || tc == null || title == null)
     throw new IllegalArgumentException("Invalid argument");
   //
   m_displayType = displayType;
   m_format = format;
   m_tc = tc;
   m_title = title;
   //
   DecimalFormatSymbols sym = m_format.getDecimalFormatSymbols();
   m_decimalSeparator = sym.getDecimalSeparator();
   m_groupingSeparator = sym.getGroupingSeparator();
   m_minusSign = sym.getMinusSign();
   //	log.finest("Decimal=" + m_decimalSeparator + "(" + (int)m_decimalSeparator
   //		+ ") - Group=" + m_groupingSeparator + "(" + (int)m_groupingSeparator +")");
 } //	MDocNumber
  public boolean isStringNumeric(String str) {
    DecimalFormatSymbols currentLocaleSymbols = DecimalFormatSymbols.getInstance();
    char localeMinusSign = currentLocaleSymbols.getMinusSign();

    if (!Character.isDigit(str.charAt(0)) && str.charAt(0) != localeMinusSign) return false;

    boolean isDecimalSeparatorFound = false;
    char localeDecimalSeparator = currentLocaleSymbols.getDecimalSeparator();

    for (char c : str.substring(1).toCharArray()) {
      if (!Character.isDigit(c)) {
        if (c == localeDecimalSeparator && !isDecimalSeparatorFound) {
          isDecimalSeparatorFound = true;
          continue;
        }
        return false;
      }
    }

    return true;
  }
  private static DateTimeFormatSymbols createInfo(Locale locale) {
    DecimalFormatSymbols oldSymbols = DecimalFormatSymbols.getInstance(locale);
    DateTimeFormatter.checkNotNull(oldSymbols, "Symbols to convert must not be null");
    char zeroDigit = oldSymbols.getZeroDigit();
    char positiveSign = '+';
    char negativeSign = oldSymbols.getMinusSign();
    char decimalSeparator = oldSymbols.getDecimalSeparator();

    Calendar cal = Calendar.getInstance(locale);
    int calFDoW = cal.getFirstDayOfWeek();
    DayOfWeek firstDayOfWeek = (calFDoW == 1 ? DayOfWeek.SUNDAY : DayOfWeek.of(calFDoW - 1));
    int minDaysInFirstWeek = cal.getMinimalDaysInFirstWeek();

    return new DateTimeFormatSymbols(
        locale,
        zeroDigit,
        positiveSign,
        negativeSign,
        decimalSeparator,
        firstDayOfWeek,
        minDaysInFirstWeek);
  }