1 18 19 package org.apache.jorphan.collections; 20 21 import java.io.Serializable ; 22 import java.util.Collection ; 23 import java.util.Comparator ; 24 import java.util.HashMap ; 25 import java.util.Iterator ; 26 import java.util.Map ; 27 import java.util.TreeMap ; 28 29 32 44 public class SortedHashTree extends HashTree implements Serializable 45 { 46 protected Comparator comparator; 48 49 public SortedHashTree() 50 { 51 data = new TreeMap (); 52 } 53 54 public SortedHashTree(Comparator comper) 55 { 56 comparator = comper; 57 data = new TreeMap (comparator); 58 } 59 60 public SortedHashTree(Object key) 61 { 62 data = new TreeMap (); 63 data.put(key, new SortedHashTree()); 64 } 65 66 public SortedHashTree(Object key,Comparator comper) 67 { 68 comparator = comper; 69 data = new TreeMap (comparator); 70 data.put(key, new SortedHashTree(comparator)); 71 } 72 73 public SortedHashTree(Collection keys) 74 { 75 data = new TreeMap (); 76 Iterator it = keys.iterator(); 77 while (it.hasNext()) 78 { 79 data.put(it.next(), new SortedHashTree()); 80 } 81 } 82 83 public SortedHashTree(Collection keys,Comparator comper) 84 { 85 comparator = comper; 86 data = new TreeMap (comparator); 87 Iterator it = keys.iterator(); 88 while (it.hasNext()) 89 { 90 data.put(it.next(), new SortedHashTree(comparator)); 91 } 92 } 93 94 public SortedHashTree(Object [] keys) 95 { 96 data = new TreeMap (); 97 for (int x = 0; x < keys.length; x++) 98 { 99 data.put(keys[x], new SortedHashTree()); 100 } 101 } 102 103 public SortedHashTree(Object [] keys,Comparator comper) 104 { 105 comparator = comper; 106 data = new TreeMap (comparator); 107 for (int x = 0; x < keys.length; x++) 108 { 109 data.put(keys[x], new SortedHashTree(comparator)); 110 } 111 } 112 113 protected HashTree createNewTree() 114 { 115 if(comparator == null) 116 { 117 return new SortedHashTree(); 118 } 119 else 120 { 121 return new SortedHashTree(comparator); 122 } 123 } 124 125 protected HashTree createNewTree(Object key) 126 { 127 if(comparator == null) 128 { 129 return new SortedHashTree(key); 130 } 131 else 132 { 133 return new SortedHashTree(key,comparator); 134 } 135 } 136 137 protected HashTree createNewTree(Collection values) 138 { 139 if(comparator == null) 140 { 141 return new SortedHashTree(values); 142 } 143 else 144 { 145 return new SortedHashTree(values,comparator); 146 } 147 } 148 149 public Object clone() 150 { 151 HashTree newTree = null; 152 if(comparator == null) 153 { 154 newTree = new SortedHashTree(); 155 } 156 else 157 { 158 newTree = new SortedHashTree(comparator); 159 } 160 newTree.data = (Map ) ((HashMap ) data).clone(); 161 return newTree; 162 } 163 166 public void setComparator(Comparator comparator) { 167 this.comparator = comparator; 168 } 169 } 170 | Popular Tags |