KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ant > internal > ui > dtd > util > SortedMapFactory


1 /*******************************************************************************
2  * Copyright (c) 2002, 2006 Object Factory Inc.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * Object Factory Inc. - Initial implementation
10  * IBM Corporation - fix for Bug 110636
11  *******************************************************************************/

12 package org.eclipse.ant.internal.ui.dtd.util;
13
14 import java.util.Comparator JavaDoc;
15
16 /**
17  * Can be inherited or used statically.
18  * @author Bob Foster
19  */

20 public class SortedMapFactory {
21
22     private static class IndirectStringComparator implements Comparator JavaDoc {
23         /**
24          * @see java.util.Comparator#compare(Object, Object)
25          */

26         public int compare(Object JavaDoc o1, Object JavaDoc 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 JavaDoc 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