DifferentialProfileComparator implements Comparator<T> { @Override public int compare(T firstProfile, T otherProfile) { boolean allContrastsSelected = nonSelectedQueryContrasts.isEmpty(); if (isSpecific && allContrastsSelected) { int order = Long.compare(firstProfile.getSpecificity(regulation), otherProfile.getSpecificity(regulation)); if (0 == order) { order = compareOnAverageExpressionLevel(firstProfile, otherProfile, selectedQueryContrasts); } if (0 == order) { order = compareOnAveragePValue(firstProfile, otherProfile, selectedQueryContrasts); } if (0 == order) { order = firstProfile.getName().compareTo(otherProfile.getName()); } return order; } if (isSpecific && !allContrastsSelected) { int order = Ordering.natural().compare( getExpressionLevelFoldChange(firstProfile), getExpressionLevelFoldChange(otherProfile)); if (0 == order) { order = compareOnAverageExpressionLevel(firstProfile, otherProfile, selectedQueryContrasts); } if (0 == order) { order = compareOnAveragePValue(firstProfile, otherProfile, selectedQueryContrasts); } if (0 == order) { order = firstProfile.getName().compareTo(otherProfile.getName()); } return order; } if (!isSpecific && allContrastsSelected) { int order = compareOnAverageExpressionLevel(firstProfile, otherProfile, selectedQueryContrasts); if (0 == order) { order = compareOnAveragePValue(firstProfile, otherProfile, selectedQueryContrasts); } if (0 == order) { order = firstProfile.getName().compareTo(otherProfile.getName()); } return order; } int order = compareOnAverageExpressionLevel(firstProfile, otherProfile, selectedQueryContrasts); if (0 == order) { order = compareOnAveragePValue(firstProfile, otherProfile, selectedQueryContrasts); } if (0 == order) { order = firstProfile.getName().compareTo(otherProfile.getName()); } return order; } DifferentialProfileComparator(boolean isSpecific, Collection<Contrast> selectedQueryContrasts,
                                         Collection<Contrast> allQueryContrasts, Regulation regulation); static DifferentialProfileComparator<Prof> create(
            DifferentialProfileStreamOptions options); @Override int compare(T firstProfile, T otherProfile); double getExpressionLevelFoldChange(DifferentialProfile<?, ?> differentialProfile);  }
@Test public void lowSpecificityShouldFollowHigherSpecificity() { subject = new DifferentialProfileComparator<>(true, allContrasts, allContrasts, Regulation.UP); when(profileMock1.getSpecificity(Regulation.UP)).thenReturn(1L); when(profileMock2.getSpecificity(Regulation.UP)).thenReturn(2L); int comparison = subject.compare(profileMock1, profileMock2); assertThat(comparison, lessThan(0)); }