@Test public void testCompare() throws Exception { initDb(); try (Transaction tx = beginTx()) { TaxonomicOrder order = new TaxonomicOrder(); List<Node> nodes = Lists.newArrayList( build(Rank.GENUS, "Pinus"), build(Rank.GENUS, "Abies"), build(Rank.FAMILY, "Pinaceae"), build(Rank.SPECIES, "Abies alba", "Abies alba Mill."), build(Rank.KINGDOM, "Plantae"), build(Rank.SUBSPECIES, "Abies alba alpina", "Abies alba subsp. alpina L."), build(Rank.SPECIES, "Abies alba", "Abies alba L."), build(Rank.VARIETY, "Abies alba berlina", "Abies alba var. berlina DC."), build(Rank.SUBSPECIES, "Abies alba caucasia", "Abies alba subsp. caucasia Reich."), build(Rank.UNRANKED, "nonsense"), build(null, "Incertae sedis"), build(Rank.INFRAGENERIC_NAME, "Abieta") ); Collections.sort(nodes, order); Long[] expected = new Long[]{4l,2l,1l,0l,11l,6l,3l,5l,8l,7l,9l,10l}; Long[] sorted = Lists.transform(nodes, new Function<Node, Long>() { @Nullable @Override public Long apply(@Nullable Node n) { return n.getId(); } }).toArray(new Long[]{}); System.out.println(Joiner.on("l,").join(sorted)); assertArrayEquals(expected, sorted); } }
@Override public int compare(Node n1, Node n2) { int r1 = (int) n1.getProperty(NeoProperties.RANK, Integer.MAX_VALUE); int r2 = (int) n2.getProperty(NeoProperties.RANK, Integer.MAX_VALUE); if (r1!=r2) { return r1 - r2; } String c1 = NeoProperties.getCanonicalName(n1); String c2 = NeoProperties.getCanonicalName(n2); int canonicalComparison = c1.compareTo(c2); if (canonicalComparison == 0) { return NeoProperties.getScientificName(n1).compareTo(NeoProperties.getScientificName(n2)); } return canonicalComparison; }
TaxonomicOrder implements Comparator<Node> { @Override public int compare(Node n1, Node n2) { int r1 = (int) n1.getProperty(NeoProperties.RANK, Integer.MAX_VALUE); int r2 = (int) n2.getProperty(NeoProperties.RANK, Integer.MAX_VALUE); if (r1!=r2) { return r1 - r2; } String c1 = NeoProperties.getCanonicalName(n1); String c2 = NeoProperties.getCanonicalName(n2); int canonicalComparison = c1.compareTo(c2); if (canonicalComparison == 0) { return NeoProperties.getScientificName(n1).compareTo(NeoProperties.getScientificName(n2)); } return canonicalComparison; } }
TaxonomicOrder implements Comparator<Node> { @Override public int compare(Node n1, Node n2) { int r1 = (int) n1.getProperty(NeoProperties.RANK, Integer.MAX_VALUE); int r2 = (int) n2.getProperty(NeoProperties.RANK, Integer.MAX_VALUE); if (r1!=r2) { return r1 - r2; } String c1 = NeoProperties.getCanonicalName(n1); String c2 = NeoProperties.getCanonicalName(n2); int canonicalComparison = c1.compareTo(c2); if (canonicalComparison == 0) { return NeoProperties.getScientificName(n1).compareTo(NeoProperties.getScientificName(n2)); } return canonicalComparison; }  }
TaxonomicOrder implements Comparator<Node> { @Override public int compare(Node n1, Node n2) { int r1 = (int) n1.getProperty(NeoProperties.RANK, Integer.MAX_VALUE); int r2 = (int) n2.getProperty(NeoProperties.RANK, Integer.MAX_VALUE); if (r1!=r2) { return r1 - r2; } String c1 = NeoProperties.getCanonicalName(n1); String c2 = NeoProperties.getCanonicalName(n2); int canonicalComparison = c1.compareTo(c2); if (canonicalComparison == 0) { return NeoProperties.getScientificName(n1).compareTo(NeoProperties.getScientificName(n2)); } return canonicalComparison; }  @Override int compare(Node n1, Node n2); }
TaxonomicOrder implements Comparator<Node> { @Override public int compare(Node n1, Node n2) { int r1 = (int) n1.getProperty(NeoProperties.RANK, Integer.MAX_VALUE); int r2 = (int) n2.getProperty(NeoProperties.RANK, Integer.MAX_VALUE); if (r1!=r2) { return r1 - r2; } String c1 = NeoProperties.getCanonicalName(n1); String c2 = NeoProperties.getCanonicalName(n2); int canonicalComparison = c1.compareTo(c2); if (canonicalComparison == 0) { return NeoProperties.getScientificName(n1).compareTo(NeoProperties.getScientificName(n2)); } return canonicalComparison; }  @Override int compare(Node n1, Node n2);  }