public int compare(Component comp1, Component comp2) { String name1 = getLabel(comp1); String name2 = getLabel(comp2); // same role? alphabetical order CvExperimentalRole role1 = null; CvExperimentalRole role2 = null; if (!comp1.getExperimentalRoles().isEmpty()) { role1 = comp1.getExperimentalRoles().iterator().next(); } if (!comp2.getExperimentalRoles().isEmpty()) { role2 = comp2.getExperimentalRoles().iterator().next(); } if (role1 == null && role2 == null) return name1.compareTo(name2); if (role1 != null && role2 == null) return -1; if (role1 == null) return 1; // the order is: bait -> prey -> other final boolean isBait1 = ComponentUtils.isBait(comp1.getExperimentalRoles()); final boolean isBait2 = ComponentUtils.isBait(comp2.getExperimentalRoles()); final boolean isPrey1 = ComponentUtils.isPrey(comp1.getExperimentalRoles()); final boolean isPrey2 = ComponentUtils.isPrey(comp2.getExperimentalRoles()); if (isBait1 && !isBait2) return -1; if (isBait1 && isBait2) return name1.compareTo(name2); if (isBait2) return 1; if (isPrey1 && !isPrey2) return -1; if (isPrey1 && isPrey2) return name1.compareTo(name2); if (isPrey2) return 1; return name1.compareTo(name2); }
public int compare(Component comp1, Component comp2) { String name1 = getLabel(comp1); String name2 = getLabel(comp2); // same role? alphabetical order CvExperimentalRole role1 = null; CvExperimentalRole role2 = null; if (!comp1.getExperimentalRoles().isEmpty()) { role1 = comp1.getExperimentalRoles().iterator().next(); } if (!comp2.getExperimentalRoles().isEmpty()) { role2 = comp2.getExperimentalRoles().iterator().next(); } if (role1 == null && role2 == null) return name1.compareTo(name2); if (role1 != null && role2 == null) return -1; if (role1 == null) return 1; // the order is: bait -> prey -> other final boolean isBait1 = ComponentUtils.isBait(comp1.getExperimentalRoles()); final boolean isBait2 = ComponentUtils.isBait(comp2.getExperimentalRoles()); final boolean isPrey1 = ComponentUtils.isPrey(comp1.getExperimentalRoles()); final boolean isPrey2 = ComponentUtils.isPrey(comp2.getExperimentalRoles()); if (isBait1 && !isBait2) return -1; if (isBait1 && isBait2) return name1.compareTo(name2); if (isBait2) return 1; if (isPrey1 && !isPrey2) return -1; if (isPrey1 && isPrey2) return name1.compareTo(name2); if (isPrey2) return 1; return name1.compareTo(name2); }