1 package org.kuali.ole.utility.callnumber;
2
3 import java.text.DecimalFormat;
4
5 public abstract class AbstractCallNumber implements CallNumber {
6
7 public String getSortableKey(String callNumber) {
8 return null;
9 }
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45 public static String normalizeFloat(String floatStr, int digitsB4, int digitsAfter) {
46 double value = Double.valueOf(floatStr).doubleValue();
47
48 String formatStr = getFormatString(digitsB4) + '.' + getFormatString(digitsAfter);
49
50 DecimalFormat normFormat = new DecimalFormat(formatStr);
51 String norm = normFormat.format(value);
52 if (norm.endsWith("."))
53 norm = norm.substring(0, norm.length() - 1);
54 return norm;
55 }
56
57 private static String getFormatString(int numDigits) {
58 StringBuilder b4 = new StringBuilder();
59 if (numDigits < 0)
60 b4.append("############");
61 else if (numDigits > 0) {
62 for (int i = 0; i < numDigits; i++) {
63 b4.append('0');
64 }
65 }
66 return b4.toString();
67 }
68
69 public static String normalizeSuffix(String suffix) {
70 if (suffix != null && suffix.length() > 0) {
71 StringBuilder resultBuf = new StringBuilder(suffix.length());
72
73 String[] digitStrs = suffix.split("[\\D]+");
74 int len = digitStrs.length;
75 if (digitStrs != null && len != 0) {
76 int s = 0;
77 for (int d = 0; d < len; d++) {
78 String digitStr = digitStrs[d];
79 int ix = suffix.indexOf(digitStr, s);
80
81 if (s < ix) {
82 String text = suffix.substring(s, ix);
83 resultBuf.append(text);
84 }
85 if (digitStr != null && digitStr.length() != 0) {
86
87 resultBuf.append(normalizeFloat(digitStr, 6, 0));
88 s = ix + digitStr.length();
89 }
90
91 }
92
93 resultBuf.append(suffix.substring(s));
94 return resultBuf.toString();
95 }
96 }
97
98 return suffix;
99 }
100 }