~ubuntu-branches/ubuntu/trusty/pylucene/trusty

« back to all changes in this revision

Viewing changes to lucene-java-2.3.1/src/test/org/apache/lucene/util/English.java

  • Committer: Package Import Robot
  • Author(s): Dmitry Nezhevenko
  • Date: 2012-04-23 16:43:55 UTC
  • mfrom: (1.1.1)
  • Revision ID: package-import@ubuntu.com-20120423164355-grqtepnwtecdjfk2
Tags: 3.5.0-1
* New maintainer (closes: 670179)
* New upstream release
* Switch to dpkg-source 3.0 (quilt) format
* Switch to machine-readable debian/copyright
* Bump debian/compat to 8, drop debian/pycompat
* Switch from cdbs to dh
* Add watch file
* Build for all supported versions of python2 (closes: 581198, 632240)
* Rename binary package to python-lucene (closes: 581197)
* Add -dbg package

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
package org.apache.lucene.util;
2
 
 
3
 
/**
4
 
 * Licensed to the Apache Software Foundation (ASF) under one or more
5
 
 * contributor license agreements.  See the NOTICE file distributed with
6
 
 * this work for additional information regarding copyright ownership.
7
 
 * The ASF licenses this file to You under the Apache License, Version 2.0
8
 
 * (the "License"); you may not use this file except in compliance with
9
 
 * the License.  You may obtain a copy of the License at
10
 
 *
11
 
 *     http://www.apache.org/licenses/LICENSE-2.0
12
 
 *
13
 
 * Unless required by applicable law or agreed to in writing, software
14
 
 * distributed under the License is distributed on an "AS IS" BASIS,
15
 
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
 
 * See the License for the specific language governing permissions and
17
 
 * limitations under the License.
18
 
 */
19
 
 
20
 
 
21
 
public class English {
22
 
 
23
 
  public static String intToEnglish(int i) {
24
 
    StringBuffer result = new StringBuffer();
25
 
    intToEnglish(i, result);
26
 
    return result.toString();
27
 
  }
28
 
 
29
 
  public static void intToEnglish(int i, StringBuffer result) {
30
 
    if (i == 0) {
31
 
      result.append("zero");
32
 
      return;
33
 
    }
34
 
    if (i < 0) {
35
 
      result.append("minus ");
36
 
      i = -i;
37
 
    }
38
 
    if (i >= 1000000000) {                        // billions
39
 
      intToEnglish(i/1000000000, result);
40
 
      result.append("billion, ");
41
 
      i = i%1000000000;
42
 
    }
43
 
    if (i >= 1000000) {                           // millions
44
 
      intToEnglish(i/1000000, result);
45
 
      result.append("million, ");
46
 
      i = i%1000000;
47
 
    }
48
 
    if (i >= 1000) {                              // thousands
49
 
      intToEnglish(i/1000, result);
50
 
      result.append("thousand, ");
51
 
      i = i%1000;
52
 
    }
53
 
    if (i >= 100) {                               // hundreds
54
 
      intToEnglish(i/100, result);
55
 
      result.append("hundred ");
56
 
      i = i%100;
57
 
    }
58
 
    if (i >= 20) {
59
 
      switch (i/10) {
60
 
      case 9 : result.append("ninety"); break;
61
 
      case 8 : result.append("eighty"); break;
62
 
      case 7 : result.append("seventy"); break;
63
 
      case 6 : result.append("sixty"); break;
64
 
      case 5 : result.append("fifty"); break;
65
 
      case 4 : result.append("forty"); break;
66
 
      case 3 : result.append("thirty"); break;
67
 
      case 2 : result.append("twenty"); break;
68
 
      }
69
 
      i = i%10;
70
 
      if (i == 0)
71
 
        result.append(" ");
72
 
      else 
73
 
        result.append("-");
74
 
    }
75
 
    switch (i) {
76
 
    case 19 : result.append("nineteen "); break;
77
 
    case 18 : result.append("eighteen "); break;
78
 
    case 17 : result.append("seventeen "); break;
79
 
    case 16 : result.append("sixteen "); break;
80
 
    case 15 : result.append("fifteen "); break;
81
 
    case 14 : result.append("fourteen "); break;
82
 
    case 13 : result.append("thirteen "); break;
83
 
    case 12 : result.append("twelve "); break;
84
 
    case 11 : result.append("eleven "); break;
85
 
    case 10 : result.append("ten "); break;
86
 
    case 9 : result.append("nine "); break;
87
 
    case 8 : result.append("eight "); break;
88
 
    case 7 : result.append("seven "); break;
89
 
    case 6 : result.append("six "); break;
90
 
    case 5 : result.append("five "); break;
91
 
    case 4 : result.append("four "); break;
92
 
    case 3 : result.append("three "); break;
93
 
    case 2 : result.append("two "); break;
94
 
    case 1 : result.append("one "); break;
95
 
    case 0 : result.append(""); break;
96
 
    }
97
 
  }
98
 
 
99
 
  public static void main(String[] args) {
100
 
    System.out.println(intToEnglish(Integer.parseInt(args[0])));
101
 
  }
102
 
 
103
 
}