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 /*@Override
12 public String normalize(String callNumber) throws Exception {
13 String recid=null;
14 String normalisedLCCallNumber=CallNumUtils.getLCShelfkey(callNumber, null);
15 return normalisedLCCallNumber;
16 }*/
17
18 /*public String normalize(String callNumber){
19
20 // LCCallNumber lcCallNumber=LCCallNumber.getInstance();
21 String normalisedCallNumber =null;
22 // =lcCallNumber.normalize(callNumber);
23 *//* CallNumber callNumber1 = BeanLocator.getCallNumberFactory()
24 .getCallNumber(callNumberType.getCode());*//*
25
26 *//*if(callNumber1.equals(CallNumberType.LC.getDescription())) {
27 normalisedCallNumber=normalizedCallNumber(callNumber);
28 }*//*
29
30 return normalisedCallNumber;
31
32 }*/
33 /*public String normalizedCallNumber(String callNumber) {
34 String normalizedCallNumber=null;
35 try{
36 LCCallNumber lcCallNumber=LCCallNumber.getInstance();
37 normalizedCallNumber= lcCallNumber.normalize(callNumber);
38 }catch (Exception e){
39 e.printStackTrace();
40 }
41
42 return normalizedCallNumber;
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 // get digit substrings
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 // add the non-digit chars before, if they exist
81 if (s < ix) {
82 String text = suffix.substring(s, ix);
83 resultBuf.append(text);
84 }
85 if (digitStr != null && digitStr.length() != 0) {
86 // add the normalized digit chars, if they exist
87 resultBuf.append(normalizeFloat(digitStr, 6, 0));
88 s = ix + digitStr.length();
89 }
90
91 }
92 // add any chars after the last digStr
93 resultBuf.append(suffix.substring(s));
94 return resultBuf.toString();
95 }
96 }
97
98 return suffix;
99 }
100 }