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

« back to all changes in this revision

Viewing changes to lucene/contrib/benchmark/src/java/org/apache/lucene/benchmark/byTask/utils/Format.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.benchmark.byTask.utils;
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
 
import java.text.NumberFormat;
21
 
 
22
 
/**
23
 
 * Formatting utilities (for reports).
24
 
 */
25
 
public class Format {
26
 
 
27
 
  private static NumberFormat numFormat [] = { 
28
 
    NumberFormat.getInstance(), 
29
 
    NumberFormat.getInstance(),
30
 
    NumberFormat.getInstance(),
31
 
  };
32
 
  private static final String padd = "                                                 ";
33
 
  
34
 
  static {
35
 
    numFormat[0].setMaximumFractionDigits(0);
36
 
    numFormat[0].setMinimumFractionDigits(0);
37
 
    numFormat[1].setMaximumFractionDigits(1);
38
 
    numFormat[1].setMinimumFractionDigits(1);
39
 
    numFormat[2].setMaximumFractionDigits(2);
40
 
    numFormat[2].setMinimumFractionDigits(2);
41
 
  }
42
 
 
43
 
  /**
44
 
   * Padd a number from left.
45
 
   * @param numFracDigits number of digits in fraction part - must be 0 or 1 or 2.
46
 
   * @param f number to be formatted.
47
 
   * @param col column name (used for deciding on length).
48
 
   * @return formatted string.
49
 
   */
50
 
  public static String format(int numFracDigits, float f, String col) {
51
 
    String res = padd + numFormat[numFracDigits].format(f);
52
 
    return res.substring(res.length() - col.length());
53
 
  }
54
 
 
55
 
  public static String format(int numFracDigits, double f, String col) {
56
 
    String res = padd + numFormat[numFracDigits].format(f);
57
 
    return res.substring(res.length() - col.length());
58
 
  }
59
 
 
60
 
  /**
61
 
   * Pad a number from right.
62
 
   * @param numFracDigits number of digits in fraction part - must be 0 or 1 or 2.
63
 
   * @param f number to be formatted.
64
 
   * @param col column name (used for deciding on length).
65
 
   * @return formatted string.
66
 
   */
67
 
  public static String formatPaddRight(int numFracDigits, float f, String col) {
68
 
    String res = numFormat[numFracDigits].format(f) + padd;
69
 
    return res.substring(0, col.length());
70
 
  }
71
 
 
72
 
  public static String formatPaddRight(int numFracDigits, double f, String col) {
73
 
    String res = numFormat[numFracDigits].format(f) + padd;
74
 
    return res.substring(0, col.length());
75
 
  }
76
 
 
77
 
  /**
78
 
   * Pad a number from left.
79
 
   * @param n number to be formatted.
80
 
   * @param col column name (used for deciding on length).
81
 
   * @return formatted string.
82
 
   */
83
 
  public static String format(int n, String col) {
84
 
    String res = padd + n;
85
 
    return res.substring(res.length() - col.length());
86
 
  }
87
 
 
88
 
  /**
89
 
   * Pad a string from right.
90
 
   * @param s string to be formatted.
91
 
   * @param col column name (used for deciding on length).
92
 
   * @return formatted string.
93
 
   */
94
 
  public static String format(String s, String col) {
95
 
    String s1 = (s + padd);
96
 
    return s1.substring(0, Math.min(col.length(), s1.length()));
97
 
  }
98
 
 
99
 
  /**
100
 
   * Pad a string from left.
101
 
   * @param s string to be formatted.
102
 
   * @param col column name (used for deciding on length).
103
 
   * @return formatted string.
104
 
   */
105
 
  public static String formatPaddLeft(String s, String col) {
106
 
    String res = padd + s;
107
 
    return res.substring(res.length() - col.length());
108
 
  }
109
 
 
110
 
}