~slub.team/goobi-indexserver/3.x

« back to all changes in this revision

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

  • Committer: Sebastian Meyer
  • Date: 2012-08-03 09:12:40 UTC
  • Revision ID: sebastian.meyer@slub-dresden.de-20120803091240-x6861b0vabq1xror
Remove Lucene and Solr source code and add patches instead
Fix Bug #985487: Auto-suggestion for the search interface

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
 
 * <p/>
11
 
 * http://www.apache.org/licenses/LICENSE-2.0
12
 
 * <p/>
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
 
 * @lucene.internal
22
 
 */ 
23
 
public final class English {
24
 
 
25
 
  private English() {} // no instance
26
 
 
27
 
  public static String longToEnglish(long i) {
28
 
    StringBuilder result = new StringBuilder();
29
 
    longToEnglish(i, result);
30
 
    return result.toString();
31
 
  }
32
 
 
33
 
  public static void longToEnglish(long i, StringBuilder result) {
34
 
    if (i == 0) {
35
 
      result.append("zero");
36
 
      return;
37
 
    }
38
 
    if (i < 0) {
39
 
      result.append("minus ");
40
 
      i = -i;
41
 
    }
42
 
    if (i >= 1000000000000000000l) {        // quadrillion
43
 
      longToEnglish(i / 1000000000000000000l, result);
44
 
      result.append("quintillion, ");
45
 
      i = i % 1000000000000000000l;
46
 
    }
47
 
    if (i >= 1000000000000000l) {        // quadrillion
48
 
      longToEnglish(i / 1000000000000000l, result);
49
 
      result.append("quadrillion, ");
50
 
      i = i % 1000000000000000l;
51
 
    }
52
 
    if (i >= 1000000000000l) {        // trillions
53
 
      longToEnglish(i / 1000000000000l, result);
54
 
      result.append("trillion, ");
55
 
      i = i % 1000000000000l;
56
 
    }
57
 
    if (i >= 1000000000) {        // billions
58
 
      longToEnglish(i / 1000000000, result);
59
 
      result.append("billion, ");
60
 
      i = i % 1000000000;
61
 
    }
62
 
    if (i >= 1000000) {          // millions
63
 
      longToEnglish(i / 1000000, result);
64
 
      result.append("million, ");
65
 
      i = i % 1000000;
66
 
    }
67
 
    if (i >= 1000) {          // thousands
68
 
      longToEnglish(i / 1000, result);
69
 
      result.append("thousand, ");
70
 
      i = i % 1000;
71
 
    }
72
 
    if (i >= 100) {          // hundreds
73
 
      longToEnglish(i / 100, result);
74
 
      result.append("hundred ");
75
 
      i = i % 100;
76
 
    }
77
 
    //we know we are smaller here so we can cast
78
 
    if (i >= 20) {
79
 
      switch (((int) i) / 10) {
80
 
        case 9:
81
 
          result.append("ninety");
82
 
          break;
83
 
        case 8:
84
 
          result.append("eighty");
85
 
          break;
86
 
        case 7:
87
 
          result.append("seventy");
88
 
          break;
89
 
        case 6:
90
 
          result.append("sixty");
91
 
          break;
92
 
        case 5:
93
 
          result.append("fifty");
94
 
          break;
95
 
        case 4:
96
 
          result.append("forty");
97
 
          break;
98
 
        case 3:
99
 
          result.append("thirty");
100
 
          break;
101
 
        case 2:
102
 
          result.append("twenty");
103
 
          break;
104
 
      }
105
 
      i = i % 10;
106
 
      if (i == 0)
107
 
        result.append(" ");
108
 
      else
109
 
        result.append("-");
110
 
    }
111
 
    switch ((int) i) {
112
 
      case 19:
113
 
        result.append("nineteen ");
114
 
        break;
115
 
      case 18:
116
 
        result.append("eighteen ");
117
 
        break;
118
 
      case 17:
119
 
        result.append("seventeen ");
120
 
        break;
121
 
      case 16:
122
 
        result.append("sixteen ");
123
 
        break;
124
 
      case 15:
125
 
        result.append("fifteen ");
126
 
        break;
127
 
      case 14:
128
 
        result.append("fourteen ");
129
 
        break;
130
 
      case 13:
131
 
        result.append("thirteen ");
132
 
        break;
133
 
      case 12:
134
 
        result.append("twelve ");
135
 
        break;
136
 
      case 11:
137
 
        result.append("eleven ");
138
 
        break;
139
 
      case 10:
140
 
        result.append("ten ");
141
 
        break;
142
 
      case 9:
143
 
        result.append("nine ");
144
 
        break;
145
 
      case 8:
146
 
        result.append("eight ");
147
 
        break;
148
 
      case 7:
149
 
        result.append("seven ");
150
 
        break;
151
 
      case 6:
152
 
        result.append("six ");
153
 
        break;
154
 
      case 5:
155
 
        result.append("five ");
156
 
        break;
157
 
      case 4:
158
 
        result.append("four ");
159
 
        break;
160
 
      case 3:
161
 
        result.append("three ");
162
 
        break;
163
 
      case 2:
164
 
        result.append("two ");
165
 
        break;
166
 
      case 1:
167
 
        result.append("one ");
168
 
        break;
169
 
      case 0:
170
 
        result.append("");
171
 
        break;
172
 
    }
173
 
  }
174
 
 
175
 
 
176
 
  public static String intToEnglish(int i) {
177
 
    StringBuilder result = new StringBuilder();
178
 
    longToEnglish(i, result);
179
 
    return result.toString();
180
 
  }
181
 
 
182
 
  public static void intToEnglish(int i, StringBuilder result) {
183
 
    longToEnglish(i, result);
184
 
  }
185
 
 
186
 
  public static void main(String[] args) {
187
 
    System.out.println(longToEnglish(Long.parseLong(args[0])));
188
 
  }
189
 
 
190
 
}