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
25 package org.biojava.dasobert.dasregistry;
30 * a comparator to sort DasSources
32 * @author Andreas Prlic
35 public abstract class DasCoordSysComparator implements Comparator
38 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();
64 public static final Comparator BY_CATEGORY = new DasCoordSysComparator(
67 protected Comparable getField(DasCoordinateSystem ds)
69 return ds.getCategory();
73 public static final Comparator BY_ORGANISM = new DasCoordSysComparator(
76 protected Comparable getField(DasCoordinateSystem ds)
78 return ds.getOrganismName();
82 public static final Comparator BY_TAXID = new DasCoordSysComparator(
85 protected Comparable getField(DasCoordinateSystem ds)
87 return ds.getNCBITaxId() + "";
93 COMPS_BY_NAME = new HashMap();
94 COMPS_BY_NAME.put(BY_ID.toString(), BY_ID);
95 COMPS_BY_NAME.put(BY_NAME.toString(), BY_NAME);
96 COMPS_BY_NAME.put(BY_CATEGORY.toString(), BY_CATEGORY);
97 COMPS_BY_NAME.put(BY_ORGANISM.toString(), BY_ORGANISM);
98 COMPS_BY_NAME.put(BY_TAXID.toString(), BY_TAXID);
101 public static Comparator fromString(String name)
103 if (COMPS_BY_NAME.containsKey(name))
105 return (Comparator) COMPS_BY_NAME.get(name);
109 throw new IllegalArgumentException("Can't compare by key " + name);
113 protected abstract Comparable getField(DasCoordinateSystem ds);
115 /** compare two DasCoordSys objects */
116 public int compare(Object a, Object b)
118 DasCoordinateSystem x = (DasCoordinateSystem) a;
119 DasCoordinateSystem y = (DasCoordinateSystem) b;
120 return getField(x).compareTo(getField(y));
123 public String toString()