1 package com.calipso.reportgenerator.reportcalculator; 2 3 import java.util.*; 4 import java.io.Serializable ; 5 6 9 10 public class SharedString extends SharedData implements Serializable , Comparable , CubeValue { 11 private final String value; 12 static final private HashMap strings = new HashMap(5003, 0.80f); 14 15 public SharedString(String aValue) { 16 value = aValue; 17 strings.put(aValue, this); 18 } 19 20 static public SharedString newFrom(String aValue) { 21 Object string; 22 23 string = strings.get(aValue); 24 if (string == null) { 25 return new SharedString(aValue); 26 } 27 else { 28 return (SharedString) string; 29 } 30 } 31 32 public String value() { 33 return value; 34 } 35 36 public boolean equals(Object o) { 37 final String string; 38 if (this == o) return true; 39 40 if (o instanceof String ) { 41 string = (String ) o; 42 } 43 else { 44 string = ((SharedString) o).value; 45 } 46 if (!value.equals(string)) return false; 47 return true; 48 } 49 50 public int hashCode() { 51 return value.hashCode(); 52 } 53 54 public String toString(){ 55 return value; 56 } 57 58 public int compareTo(Object o) { 59 if ((toString()== null )&&(o.toString()==null)){ 60 return 0; 61 }else if (toString()== null ){ 62 return -1; 63 }else if ((o.toString()==null)){ 64 return 1; 65 }else { 66 return toString().compareTo(o.toString()); 67 } 68 } 69 70 public Object getValue() { 71 return value; 72 } 73 74 } 75 | Popular Tags |