255
256 /**
257 * Gets the pattern.
258 *
259 * @return the pattern string
260 */
261 public String toPattern() {
262 StringBuilder result = new StringBuilder();
263 for (int i = 0; i < choiceLimits.length; ++i) {
264 if (i != 0) {
265 result.append('|');
266 }
267 // choose based upon which has less precision
268 // approximate that by choosing the closest one to an integer.
269 // could do better, but it's not worth it.
270 double less = previousDouble(choiceLimits[i]);
271 double tryLessOrEqual = Math.abs(Math.IEEEremainder(choiceLimits[i], 1.0d));
272 double tryLess = Math.abs(Math.IEEEremainder(less, 1.0d));
273
274 if (tryLessOrEqual < tryLess) {
275 result.append(""+choiceLimits[i]);
276 result.append('#');
277 } else {
278 if (choiceLimits[i] == Double.POSITIVE_INFINITY) {
279 result.append("\u221E");
280 } else if (choiceLimits[i] == Double.NEGATIVE_INFINITY) {
281 result.append("-\u221E");
282 } else {
283 result.append(""+less);
284 }
285 result.append('<');
286 }
287 // Append choiceFormats[i], using quotes if there are special characters.
288 // Single quotes themselves must be escaped in either case.
289 String text = choiceFormats[i];
290 boolean needQuote = text.indexOf('<') >= 0
291 || text.indexOf('#') >= 0
292 || text.indexOf('\u2264') >= 0
293 || text.indexOf('|') >= 0;
294 if (needQuote) result.append('\'');
295 if (text.indexOf('\'') < 0) result.append(text);
296 else {
297 for (int j=0; j<text.length(); ++j) {
298 char c = text.charAt(j);
299 result.append(c);
300 if (c == '\'') result.append(c);
301 }
302 }
303 if (needQuote) result.append('\'');
|
255
256 /**
257 * Gets the pattern.
258 *
259 * @return the pattern string
260 */
261 public String toPattern() {
262 StringBuilder result = new StringBuilder();
263 for (int i = 0; i < choiceLimits.length; ++i) {
264 if (i != 0) {
265 result.append('|');
266 }
267 // choose based upon which has less precision
268 // approximate that by choosing the closest one to an integer.
269 // could do better, but it's not worth it.
270 double less = previousDouble(choiceLimits[i]);
271 double tryLessOrEqual = Math.abs(Math.IEEEremainder(choiceLimits[i], 1.0d));
272 double tryLess = Math.abs(Math.IEEEremainder(less, 1.0d));
273
274 if (tryLessOrEqual < tryLess) {
275 result.append(choiceLimits[i]);
276 result.append('#');
277 } else {
278 if (choiceLimits[i] == Double.POSITIVE_INFINITY) {
279 result.append("\u221E");
280 } else if (choiceLimits[i] == Double.NEGATIVE_INFINITY) {
281 result.append("-\u221E");
282 } else {
283 result.append(less);
284 }
285 result.append('<');
286 }
287 // Append choiceFormats[i], using quotes if there are special characters.
288 // Single quotes themselves must be escaped in either case.
289 String text = choiceFormats[i];
290 boolean needQuote = text.indexOf('<') >= 0
291 || text.indexOf('#') >= 0
292 || text.indexOf('\u2264') >= 0
293 || text.indexOf('|') >= 0;
294 if (needQuote) result.append('\'');
295 if (text.indexOf('\'') < 0) result.append(text);
296 else {
297 for (int j=0; j<text.length(); ++j) {
298 char c = text.charAt(j);
299 result.append(c);
300 if (c == '\'') result.append(c);
301 }
302 }
303 if (needQuote) result.append('\'');
|