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, Thomas Down
35 public abstract class DasSourceComparator
39 private final String name;
40 private static final Map COMPS_BY_NAME;
42 public DasSourceComparator(String str)
44 //System.out.println("new dasSourceComparator " + str);
48 public static final Comparator BY_ID = new DasSourceComparator("id")
50 protected Comparable getField(DasSource ds)
56 public static final Comparator BY_NICKNAME = new DasSourceComparator(
59 protected Comparable getField(DasSource ds)
61 return ds.getNickname();
64 public static final Comparator BY_REGISTER_DATE = new DasSourceComparator(
67 protected Comparable getField(DasSource ds)
69 return ds.getRegisterDate();
72 public static final Comparator BY_LEASE_DATE = new DasSourceComparator(
75 protected Comparable getField(DasSource ds)
77 return ds.getLeaseDate();
80 public static final Comparator BY_URL = new DasSourceComparator("url")
82 protected Comparable getField(DasSource ds)
87 public static final Comparator BY_ADMIN_EMAIL = new DasSourceComparator(
90 protected Comparable getField(DasSource ds)
92 return ds.getAdminemail();
95 public static final Comparator BY_DESCRIPTION = new DasSourceComparator(
98 protected Comparable getField(DasSource ds)
100 return ds.getDescription();
103 public static final Comparator BY_CAPABILITIES = new DasSourceComparator(
106 protected Comparable getField(DasSource ds)
108 String[] caps = ds.getCapabilities();
109 return caps.length == 0 ? "" : caps[0];
112 public static final Comparator BY_COORDINATE_SYSTEM = new DasSourceComparator(
115 protected Comparable getField(DasSource ds)
117 DasCoordinateSystem[] dcss = ds.getCoordinateSystem();
118 return dcss.length == 0 ? "" : dcss[0].toString();
124 COMPS_BY_NAME = new HashMap();
125 COMPS_BY_NAME.put(BY_ID.toString(), BY_ID);
126 COMPS_BY_NAME.put(BY_NICKNAME.toString(), BY_NICKNAME);
127 COMPS_BY_NAME.put(BY_REGISTER_DATE.toString(), BY_REGISTER_DATE);
128 COMPS_BY_NAME.put(BY_LEASE_DATE.toString(), BY_LEASE_DATE);
129 COMPS_BY_NAME.put(BY_URL.toString(), BY_URL);
130 COMPS_BY_NAME.put(BY_ADMIN_EMAIL.toString(), BY_ADMIN_EMAIL);
131 COMPS_BY_NAME.put(BY_DESCRIPTION.toString(), BY_DESCRIPTION);
132 COMPS_BY_NAME.put(BY_CAPABILITIES.toString(), BY_CAPABILITIES);
133 COMPS_BY_NAME.put(BY_COORDINATE_SYSTEM.toString(), BY_COORDINATE_SYSTEM);
136 public static Comparator fromString(String name)
138 if (COMPS_BY_NAME.containsKey(name))
140 return (Comparator) COMPS_BY_NAME.get(name);
144 throw new IllegalArgumentException("Can't compare by key " + name);
148 protected abstract Comparable getField(DasSource ds);
150 /** compare two DasSource objects */
151 public int compare(Object a, Object b)
154 DasSource x = (DasSource) a;
155 DasSource y = (DasSource) b;
156 return getField(x).compareTo(getField(y));
159 public String toString()