public static String convertNumberToWord(int number) {
    StringBuilder word = new StringBuilder();
    final List<Integer> tokenizedInts = Tokenizer.tokenizeNumber(number);

    for (int index = tokenizedInts.size() - 1; index >= 0; index--) {
      int token = tokenizedInts.get(index);

      // Skip if zero
      if (token == 0) {
        if (tokenizedInts.size() == 1) {
          word.append(NumberParser.parseOnes(token));
        }
        continue;
      }

      // For values 10 - 19
      if ((token == 1) && ((index == 1) || (index == 4) || (index == 7))) {
        int lastDigit = tokenizedInts.get(index - 1);
        String value = NumberParser.parseOnes((token * 10) + lastDigit);
        word.append(value);
        index--;
      } else {
        word.append(NumberParser.parseNumber(token, index));
      }

      addScales(index, word);
    }

    return word.toString();
  }
Пример #2
0
 private Link parseLink(
     final Feed feed, final Entry entry, final String baseURI, final Element eLink) {
   final Link link = new Link();
   String att = getAttributeValue(eLink, "rel");
   if (att != null) {
     link.setRel(att);
   }
   att = getAttributeValue(eLink, "type");
   if (att != null) {
     link.setType(att);
   }
   att = getAttributeValue(eLink, "href");
   if (att != null) {
     link.setHref(att);
     if (isRelativeURI(att)) {
       link.setHrefResolved(resolveURI(baseURI, eLink, att));
     }
   }
   att = getAttributeValue(eLink, "title");
   if (att != null) {
     link.setTitle(att);
   }
   att = getAttributeValue(eLink, "hreflang");
   if (att != null) {
     link.setHreflang(att);
   }
   att = getAttributeValue(eLink, "length");
   if (att != null) {
     final Long val = NumberParser.parseLong(att);
     if (val != null) {
       link.setLength(val.longValue());
     }
   }
   return link;
 }
Пример #3
0
 public DecBase(String csInt, String csDec) {
   long lInt = NumberParser.getAsLong(csInt);
   setLong(lInt);
   m_csDec = csDec;
 }
Пример #4
0
  /** Parses a length value. */
  protected void parseLength() throws ParseException, IOException {
    int mant = 0;
    int mantDig = 0;
    boolean mantPos = true;
    boolean mantRead = false;

    int exp = 0;
    int expDig = 0;
    int expAdj = 0;
    boolean expPos = true;

    int unitState = 0;

    switch (current) {
      case '-':
        mantPos = false;
      case '+':
        current = reader.read();
    }

    m1:
    switch (current) {
      default:
        reportUnexpectedCharacterError(current);
        return;

      case '.':
        break;

      case '0':
        mantRead = true;
        l:
        for (; ; ) {
          current = reader.read();
          switch (current) {
            case '1':
            case '2':
            case '3':
            case '4':
            case '5':
            case '6':
            case '7':
            case '8':
            case '9':
              break l;
            default:
              break m1;
            case '0':
          }
        }

      case '1':
      case '2':
      case '3':
      case '4':
      case '5':
      case '6':
      case '7':
      case '8':
      case '9':
        mantRead = true;
        l:
        for (; ; ) {
          if (mantDig < 9) {
            mantDig++;
            mant = mant * 10 + (current - '0');
          } else {
            expAdj++;
          }
          current = reader.read();
          switch (current) {
            default:
              break l;
            case '0':
            case '1':
            case '2':
            case '3':
            case '4':
            case '5':
            case '6':
            case '7':
            case '8':
            case '9':
          }
        }
    }

    if (current == '.') {
      current = reader.read();
      m2:
      switch (current) {
        default:
        case 'e':
        case 'E':
          if (!mantRead) {
            reportUnexpectedCharacterError(current);
            return;
          }
          break;

        case '0':
          if (mantDig == 0) {
            l:
            for (; ; ) {
              current = reader.read();
              expAdj--;
              switch (current) {
                case '1':
                case '2':
                case '3':
                case '4':
                case '5':
                case '6':
                case '7':
                case '8':
                case '9':
                  break l;
                default:
                  break m2;
                case '0':
              }
            }
          }
        case '1':
        case '2':
        case '3':
        case '4':
        case '5':
        case '6':
        case '7':
        case '8':
        case '9':
          l:
          for (; ; ) {
            if (mantDig < 9) {
              mantDig++;
              mant = mant * 10 + (current - '0');
              expAdj--;
            }
            current = reader.read();
            switch (current) {
              default:
                break l;
              case '0':
              case '1':
              case '2':
              case '3':
              case '4':
              case '5':
              case '6':
              case '7':
              case '8':
              case '9':
            }
          }
      }
    }

    boolean le = false;
    es:
    switch (current) {
      case 'e':
        le = true;
      case 'E':
        current = reader.read();
        switch (current) {
          default:
            reportUnexpectedCharacterError(current);
            return;
          case 'm':
            if (!le) {
              reportUnexpectedCharacterError(current);
              return;
            }
            unitState = 1;
            break es;
          case 'x':
            if (!le) {
              reportUnexpectedCharacterError(current);
              return;
            }
            unitState = 2;
            break es;
          case '-':
            expPos = false;
          case '+':
            current = reader.read();
            switch (current) {
              default:
                reportUnexpectedCharacterError(current);
                return;
              case '0':
              case '1':
              case '2':
              case '3':
              case '4':
              case '5':
              case '6':
              case '7':
              case '8':
              case '9':
            }
          case '0':
          case '1':
          case '2':
          case '3':
          case '4':
          case '5':
          case '6':
          case '7':
          case '8':
          case '9':
        }

        en:
        switch (current) {
          case '0':
            l:
            for (; ; ) {
              current = reader.read();
              switch (current) {
                case '1':
                case '2':
                case '3':
                case '4':
                case '5':
                case '6':
                case '7':
                case '8':
                case '9':
                  break l;
                default:
                  break en;
                case '0':
              }
            }

          case '1':
          case '2':
          case '3':
          case '4':
          case '5':
          case '6':
          case '7':
          case '8':
          case '9':
            l:
            for (; ; ) {
              if (expDig < 3) {
                expDig++;
                exp = exp * 10 + (current - '0');
              }
              current = reader.read();
              switch (current) {
                default:
                  break l;
                case '0':
                case '1':
                case '2':
                case '3':
                case '4':
                case '5':
                case '6':
                case '7':
                case '8':
                case '9':
              }
            }
        }
      default:
    }

    if (!expPos) {
      exp = -exp;
    }
    exp += expAdj;
    if (!mantPos) {
      mant = -mant;
    }

    lengthHandler.lengthValue(NumberParser.buildFloat(mant, exp));

    switch (unitState) {
      case 1:
        lengthHandler.em();
        current = reader.read();
        return;
      case 2:
        lengthHandler.ex();
        current = reader.read();
        return;
    }

    switch (current) {
      case 'e':
        current = reader.read();
        switch (current) {
          case 'm':
            lengthHandler.em();
            current = reader.read();
            break;
          case 'x':
            lengthHandler.ex();
            current = reader.read();
            break;
          default:
            reportUnexpectedCharacterError(current);
        }
        break;

      case 'p':
        current = reader.read();
        switch (current) {
          case 'c':
            lengthHandler.pc();
            current = reader.read();
            break;
          case 't':
            lengthHandler.pt();
            current = reader.read();
            break;
          case 'x':
            lengthHandler.px();
            current = reader.read();
            break;
          default:
            reportUnexpectedCharacterError(current);
        }
        break;

      case 'i':
        current = reader.read();
        if (current != 'n') {
          reportCharacterExpectedError('n', current);
          break;
        }
        lengthHandler.in();
        current = reader.read();
        break;
      case 'c':
        current = reader.read();
        if (current != 'm') {
          reportCharacterExpectedError('m', current);
          break;
        }
        lengthHandler.cm();
        current = reader.read();
        break;
      case 'm':
        current = reader.read();
        if (current != 'm') {
          reportCharacterExpectedError('m', current);
          break;
        }
        lengthHandler.mm();
        current = reader.read();
        break;
      case '%':
        lengthHandler.percentage();
        current = reader.read();
        break;
    }
  }
 public void write(VarBufferPos buffer, String cs) {
   long l = NumberParser.getAsLong(cs);
   writeSignSeparatedLeadingIntComp0AsLong(buffer, l);
 }
 void write(VarBufferPos buffer, char c) {
   int n = NumberParser.getAsUnsignedInt(c);
   writeSignSeparatedLeadingIntComp0AsLong(buffer, n);
 }