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 ;
28 import java.util.Comparator ;
29 import java.util.Map ;
30 import java.util.HashMap ;
32 import org.biojava.dasobert.dasregistry.DasCoordinateSystem;
34 /** a comparator to sort DasSources
35 * @author Andreas Prlic
39 public abstract class DasCoordSysComparator
43 private final String name ;
44 private static final Map COMPS_BY_NAME;
47 public DasCoordSysComparator(String str) {
48 //System.out.println("new dasSourceComparator " + str);
52 public static final Comparator BY_NAME = new DasCoordSysComparator("name") {
53 protected Comparable getField(DasCoordinateSystem ds) {
58 public static final Comparator BY_ID = new DasCoordSysComparator("id") {
59 protected Comparable getField(DasCoordinateSystem ds) {
60 return ds.getUniqueId();
63 public static final Comparator BY_CATEGORY = new DasCoordSysComparator("category") {
64 protected Comparable getField(DasCoordinateSystem ds) {
65 return ds.getCategory();
68 public static final Comparator BY_ORGANISM = new DasCoordSysComparator("organism") {
69 protected Comparable getField(DasCoordinateSystem ds) {
70 return ds.getOrganismName();
73 public static final Comparator BY_TAXID = new DasCoordSysComparator("taxid") {
74 protected Comparable getField(DasCoordinateSystem ds) {
75 return ds.getNCBITaxId()+"";
82 COMPS_BY_NAME = new HashMap();
83 COMPS_BY_NAME.put(BY_ID.toString(), BY_ID);
84 COMPS_BY_NAME.put(BY_NAME.toString(), BY_NAME);
85 COMPS_BY_NAME.put(BY_CATEGORY.toString(), BY_CATEGORY);
86 COMPS_BY_NAME.put(BY_ORGANISM.toString(), BY_ORGANISM);
87 COMPS_BY_NAME.put(BY_TAXID.toString(), BY_TAXID);
92 public static Comparator fromString(String name) {
93 if (COMPS_BY_NAME.containsKey(name)) {
94 return (Comparator) COMPS_BY_NAME.get(name);
96 throw new IllegalArgumentException("Can't compare by key " + name);
100 protected abstract Comparable getField(DasCoordinateSystem ds);
102 /** compare two DasCoordSys objects */
103 public int compare( Object a, Object b) {
104 DasCoordinateSystem x = (DasCoordinateSystem) a ;
105 DasCoordinateSystem y = (DasCoordinateSystem) b ;
106 return getField(x).compareTo(getField(y));
109 public String toString() {