public int compare( Name o1, Name o2 ) { if (o1 == o2) return 0; if (o1 == null) return -1; if (o2 == null) return 1; return o1.compareTo(o2); } };
/** * {@inheritDoc} */ @Override public int compareTo( PropertyValue that ) { if (this == that) return 0; if (this.name.equals(JcrLexicon.PRIMARY_TYPE)) return -1; if (that.name.equals(JcrLexicon.PRIMARY_TYPE)) return 1; return this.name.compareTo(that.name); }
public int compare( Path.Segment o1, Path.Segment o2 ) { if (o1 == o2) return 0; if (o1 == null) return -1; if (o2 == null) return 1; return o1.getName().compareTo(o2.getName()); } };
@Test( expected = NullPointerException.class ) public void shouldNotSupportNullInCompareTo() { name.compareTo(null); }
/** * {@inheritDoc} */ public int compareTo( Property that ) { if (this == that) return 0; int diff = this.getName().compareTo(that.getName()); if (diff != 0) return diff; diff = this.size() - that.size(); if (diff != 0) return diff; Iterator<?> thisIter = iterator(); Iterator<?> thatIter = that.iterator(); while (thisIter.hasNext()) { // && thatIter.hasNext() Object thisValue = thisIter.next(); Object thatValue = thatIter.next(); diff = ValueComparators.OBJECT_COMPARATOR.compare(thisValue, thatValue); if (diff != 0) return diff; } return 0; }
/** * {@inheritDoc} */ public int compareTo( Path.Segment that ) { if (this == that) return 0; int diff = this.getName().compareTo(that.getName()); if (diff != 0) return diff; return this.getIndex() - that.getIndex(); }
@Test public void shouldConsiderSameInstanceEqualToItself() { assertThat(name.equals(name), is(true)); assertThat(name.compareTo(name), is(0)); }
@Test public void shouldConsiderNamesEqualIfTheyHaveTheSameNamespaceUriAndLocalPart() { Name other = new BasicName(name.getNamespaceUri(), name.getLocalName()); assertThat(name.equals(other), is(true)); assertThat(name.compareTo(other), is(0)); }