001/*
002 *                    BioJava development code
003 *
004 * This code may be freely distributed and modified under the
005 * terms of the GNU Lesser General Public Licence.  This should
006 * be distributed with the code.  If you do not have a copy,
007 * see:
008 *
009 *      http://www.gnu.org/copyleft/lesser.html
010 *
011 * Copyright for this code is held jointly by the individual
012 * authors.  These should be listed in @author doc comments.
013 *
014 * For more information on the BioJava project and its aims,
015 * or to join the biojava-l mailing list, visit the home page
016 * at:
017 *
018 *      http://www.biojava.org/
019 *
020 */
021
022package org.biojava.bio.seq.io;
023
024import java.util.Comparator;
025
026import org.biojava.bio.seq.Feature;
027
028/**
029 * <code>GenEmblFeatureComparator</code> compares
030 * <code>Feature</code>s by the minimum base position of their
031 * <code>Location</code>, but places <code>Feature</code>s with
032 * type "source" first.
033 * @deprecated Use org.biojavax.bio.seq.io framework instead
034 * @author Keith James
035 * @since 1.2
036 */
037public final class GenEmblFeatureComparator implements Comparator
038{
039    public static final Comparator INSTANCE = new GenEmblFeatureComparator();
040
041    private GenEmblFeatureComparator() { }
042
043    public int compare(Object o1, Object o2)
044    {
045        Feature f1 = (Feature) o1;
046        Feature f2 = (Feature) o2;
047
048        boolean source1 = f1.getType().equals("source") ? true : false;
049        boolean source2 = f2.getType().equals("source") ? true : false;
050
051        // We don't subtract one coordinate from another as one or
052        // both may be set to Integer.MAX_VALUE/Integer.MIN_VALUE
053        // and the result could wrap around. Convert to Long if
054        // necessary.
055        if (! source1 && source2)
056        {
057            return 1;
058        }
059        else if (source1 && ! source2)
060        {
061            return -1;
062        }
063        else if (f1.getLocation().getMin() > f2.getLocation().getMin())
064            return 1;
065        else if (f1.getLocation().getMin() < f2.getLocation().getMin())
066            return -1;
067        else
068            return 0;
069    }
070}