OperatingSystemPattern implements Identifiable, OrderedPattern<OperatingSystemPattern>, Serializable { @Override public int compareTo(final OperatingSystemPattern other) { int result = other == null ? -1 : 0; if (result == 0) { result = CompareNullSafe.compareInt(getPosition(), other.getPosition()); if (result == 0) { result = CompareNullSafe.compareInt(getId(), other.getId()); } if (result == 0) { result = getPattern().pattern().compareTo(other.getPattern().pattern()); } if (result == 0) { result = CompareNullSafe.compareInt(getPattern().flags(), other.getPattern().flags()); } } return result; } OperatingSystemPattern(@Nonnegative final int id, @Nonnull final Pattern pattern, @Nonnegative final int position); @Override int compareTo(final OperatingSystemPattern other); @Override boolean equals(final Object obj); @Override int getId(); @Override Pattern getPattern(); @Override int getPosition(); @Override int hashCode(); @Override String toString();  }
@Test public void compareTo_differentPosition() { final OperatingSystemPattern pattern1 = new OperatingSystemPattern(1, Pattern.compile("[0-9]+"), 1); final OperatingSystemPattern pattern2 = new OperatingSystemPattern(1, Pattern.compile("[0-9]+"), 2); assertThat(pattern1.compareTo(pattern2)).isEqualTo(-1); assertThat(pattern2.compareTo(pattern1)).isEqualTo(1); }
@Test public void compareTo_identical() { final OperatingSystemPattern pattern1 = new OperatingSystemPattern(1, Pattern.compile("[0-9]+"), 1); final OperatingSystemPattern pattern2 = new OperatingSystemPattern(1, Pattern.compile("[0-9]+"), 1); assertThat(pattern1.compareTo(pattern2)).isEqualTo(0); }
@Test public void compareTo_null() { final OperatingSystemPattern pattern = new OperatingSystemPattern(1, Pattern.compile("[0-9]+"), 1); assertThat(pattern.compareTo(null)).isEqualTo(-1); }
@Test public void compareTo_same() { final OperatingSystemPattern pattern = new OperatingSystemPattern(1, Pattern.compile("[0-9]+"), 1); assertThat(pattern.compareTo(pattern)).isEqualTo(0); }