1 12 package org.eclipse.ant.internal.ui.dtd.util; 13 14 import java.util.Comparator ; 15 16 20 public class SortedMapFactory { 21 22 private static class IndirectStringComparator implements Comparator { 23 26 public int compare(Object o1, Object o2) { 27 return o1.toString().compareTo(o2.toString()); 28 } 29 } 30 31 private static final IndirectStringComparator fIndirectStringComp = new IndirectStringComparator(); 32 private static final Factory fFactory = new Factory(); 33 34 public static SortedMap getMap(IMapHolder holder, Comparator comp) { 35 SortedMap map = (SortedMap) fFactory.getFree(); 36 if (map == null) 37 map = new SortedMap(); 38 map.setMapHolder(holder); 39 map.setComparator(comp); 40 return map; 41 } 42 43 public static SortedMap getIndirectStringMap(IMapHolder holder) { 44 return getMap(holder, fIndirectStringComp); 45 } 46 47 public static void freeMap(SortedMap map) { 48 map.setComparator(null); 49 map.setMapHolder(null); 50 fFactory.setFree(map); 51 } 52 } | Popular Tags |