ComparableEntitySpan implements Comparable<ComparableEntitySpan> { @Override public int compareTo(ComparableEntitySpan s) { if (s.getBegin() > this.getBegin()) { return -1; } else if (s.getBegin() < this.getBegin()) { return 1; } else if (s.getEnd() > this.getEnd()) { return -1; } else if (s.getEnd() < this.getEnd()) { return 1; } else if (this.getValue() == null && s.getValue() == null) { return 0; } else if (this.getValue() != null && s.getValue() == null) { return 1; } else if (this.getValue() == null && s.getValue() != null) { return -1; } else { return this.getValue().compareTo(s.getValue()); } } ComparableEntitySpan(Entity entity, int begin, int end); int getBegin(); int getEnd(); Class<?> getClazz(); Entity getEntity(); String getValue(); @Override int hashCode(); @Override boolean equals(Object obj); @Override String toString(); @Override int compareTo(ComparableEntitySpan s);  }
@Test public void testCompare() throws UIMAException { final JCas jCas = JCasSingleton.getJCasInstance(); final Entity e = new Entity(jCas); final Entity e2 = new Entity(jCas); ComparableEntitySpan span = new ComparableEntitySpan(e, 5, 10); assertEquals(-1, span.compareTo(new ComparableEntitySpan(e2, 11, 15))); assertEquals(1, span.compareTo(new ComparableEntitySpan(e2, 0, 4))); assertEquals(-1, span.compareTo(new ComparableEntitySpan(e2, 5, 15))); assertEquals(1, span.compareTo(new ComparableEntitySpan(e2, 5, 7))); assertEquals(0, span.compareTo(new ComparableEntitySpan(e2, 5, 10))); e.setValue("Hello"); assertEquals(1, span.compareTo(new ComparableEntitySpan(e2, 5, 10))); e.setValue(null); e2.setValue("Hello"); assertEquals(-1, span.compareTo(new ComparableEntitySpan(e2, 5, 10))); e.setValue("Howdy"); assertEquals("Howdy".compareTo("Hello"), span.compareTo(new ComparableEntitySpan(e2, 5, 10))); }