2 * BioJava development code
4 * This code may be freely distributed and modified under the
5 * terms of the GNU Lesser General Public Licence. This should
6 * be distributed with the code. If you do not have a copy,
9 * http://www.gnu.org/copyleft/lesser.html
11 * Copyright for this code is held jointly by the individual
12 * authors. These should be listed in @author doc comments.
14 * For more information on the BioJava project and its aims,
15 * or to join the biojava-l mailing list, visit the home page
18 * http://www.biojava.org/
20 * Created on 15.04.2004
21 * @author Andreas Prlic
26 package org.biojava.dasobert.dasregistry;
30 /** a comparator to sort DasSources
31 * @author Andreas Prlic
35 public abstract class DasCoordSysComparator
39 private final String name;
40 private static final Map COMPS_BY_NAME;
42 public DasCoordSysComparator(String str)
44 //System.out.println("new dasSourceComparator " + str);
48 public static final Comparator BY_NAME = new DasCoordSysComparator("name")
50 protected Comparable getField(DasCoordinateSystem ds)
56 public static final Comparator BY_ID = new DasCoordSysComparator("id")
58 protected Comparable getField(DasCoordinateSystem ds)
60 return ds.getUniqueId();
63 public static final Comparator BY_CATEGORY = new DasCoordSysComparator(
66 protected Comparable getField(DasCoordinateSystem ds)
68 return ds.getCategory();
71 public static final Comparator BY_ORGANISM = new DasCoordSysComparator(
74 protected Comparable getField(DasCoordinateSystem ds)
76 return ds.getOrganismName();
79 public static final Comparator BY_TAXID = new DasCoordSysComparator("taxid")
81 protected Comparable getField(DasCoordinateSystem ds)
83 return ds.getNCBITaxId() + "";
89 COMPS_BY_NAME = new HashMap();
90 COMPS_BY_NAME.put(BY_ID.toString(), BY_ID);
91 COMPS_BY_NAME.put(BY_NAME.toString(), BY_NAME);
92 COMPS_BY_NAME.put(BY_CATEGORY.toString(), BY_CATEGORY);
93 COMPS_BY_NAME.put(BY_ORGANISM.toString(), BY_ORGANISM);
94 COMPS_BY_NAME.put(BY_TAXID.toString(), BY_TAXID);
97 public static Comparator fromString(String name)
99 if (COMPS_BY_NAME.containsKey(name))
101 return (Comparator) COMPS_BY_NAME.get(name);
105 throw new IllegalArgumentException("Can't compare by key " + name);
109 protected abstract Comparable getField(DasCoordinateSystem ds);
111 /** compare two DasCoordSys objects */
112 public int compare(Object a, Object b)
114 DasCoordinateSystem x = (DasCoordinateSystem) a;
115 DasCoordinateSystem y = (DasCoordinateSystem) b;
116 return getField(x).compareTo(getField(y));
119 public String toString()