import jalview.datamodel.features.FeatureSources;
import jalview.util.StringUtils;
+import java.util.Comparator;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
+import java.util.SortedMap;
import java.util.TreeMap;
import java.util.Vector;
+import intervalstore.api.IntervalI;
+
/**
* A class that models a single contiguous feature on a sequence. If flag
* 'contactFeature' is true, the start and end positions are interpreted instead
@Override
public boolean equals(Object o)
{
- return equals(o, false);
+ return (o != null && (o instanceof SequenceFeature)
+ && equalsInterval((SequenceFeature) o));
}
/**
+ * Having determined that this is in fact a SequenceFeature, now check it for
+ * equivalence. Overridden in CrossRef; used by IntervalStore (possibly).
+ */
+ @Override
+ public boolean equalsInterval(IntervalI sf)
+ {
+ return equals((SequenceFeature) sf, false);
+ }
+ /**
* Overloaded method allows the equality test to optionally ignore the
* 'Parent' attribute of a feature. This supports avoiding adding many
* superficially duplicate 'exon' or CDS features to genomic or protein
* @param ignoreParent
* @return
*/
- public boolean equals(Object o, boolean ignoreParent)
+ public boolean equals(SequenceFeature sf, boolean ignoreParent)
{
- if (o == null || !(o instanceof SequenceFeature))
- {
- return false;
- }
-
- SequenceFeature sf = (SequenceFeature) o;
boolean sameScore = Float.isNaN(score) ? Float.isNaN(sf.score)
: score == sf.score;
if (begin != sf.begin || end != sf.end || !sameScore)
{
/*
* expand values in a Map attribute across separate lines
+ * copy to a TreeMap for alphabetical ordering
*/
- Map<?, ?> values = (Map<?, ?>) value;
- for (Entry<?, ?> e : values.entrySet())
+ Map<String, Object> values = (Map<String, Object>) value;
+ SortedMap<String, Object> sm = new TreeMap<>(
+ String.CASE_INSENSITIVE_ORDER);
+ sm.putAll(values);
+ for (Entry<?, ?> e : sm.entrySet())
{
sb.append(String.format(ROW_DATA, key, e.getKey().toString(), e
.getValue().toString()));
{
source = theSource;
}
+
+
+}
+
+class SFSortByEnd implements Comparator<SequenceFeature>
+{
+ @Override
+ public int compare(SequenceFeature a, SequenceFeature b)
+ {
+ return a.getEnd() - b.getEnd();
+ }
+}
+
+class SFSortByBegin implements Comparator<SequenceFeature>
+{
+ @Override
+ public int compare(SequenceFeature a, SequenceFeature b)
+ {
+ return a.getBegin() - b.getBegin();
+ }
}