@Test public void compareNestedPages() { assertTrue(compare(Arrays.asList("math", "Path", "To", "Page"), Arrays.asList("math", "Path", "Page")) > 0); assertTrue(compare(Arrays.asList("math", "Path", "Alice"), Arrays.asList("math", "Path", "To", "Bob")) < 0); assertTrue( compare(Arrays.asList("math", "Users", "Alice", "Files"), Arrays.asList("math", "Users", "Alice")) > 0); assertTrue( compare(Arrays.asList("math", "Users", "Alice"), Arrays.asList("math", "Users", "Alice", "Files")) < 0); assertEquals(0, compare(Arrays.asList("math", "Users", "Alice", "Files"), Arrays.asList("math", "Users", "Alice", "Files"))); }
@Override public int compare(DocumentReference alice, DocumentReference bob) { Iterator<EntityReference> aliceIterator = alice.getReversedReferenceChain().iterator(); Iterator<EntityReference> bobIterator = bob.getReversedReferenceChain().iterator(); while (aliceIterator.hasNext() && bobIterator.hasNext()) { int diff = aliceIterator.next().getName().compareTo(bobIterator.next().getName()); if (diff != 0) { return diff; } } if (aliceIterator.hasNext()) { return 1; } else if (bobIterator.hasNext()) { return -1; } String aliceLocale = alice.getLocale() != null ? alice.getLocale().toString() : ""; String bobLocale = bob.getLocale() != null ? bob.getLocale().toString() : ""; return aliceLocale.compareTo(bobLocale); }
DocumentReferenceComparator implements Comparator<DocumentReference> { @Override public int compare(DocumentReference alice, DocumentReference bob) { Iterator<EntityReference> aliceIterator = alice.getReversedReferenceChain().iterator(); Iterator<EntityReference> bobIterator = bob.getReversedReferenceChain().iterator(); while (aliceIterator.hasNext() && bobIterator.hasNext()) { int diff = aliceIterator.next().getName().compareTo(bobIterator.next().getName()); if (diff != 0) { return diff; } } if (aliceIterator.hasNext()) { return 1; } else if (bobIterator.hasNext()) { return -1; } String aliceLocale = alice.getLocale() != null ? alice.getLocale().toString() : ""; String bobLocale = bob.getLocale() != null ? bob.getLocale().toString() : ""; return aliceLocale.compareTo(bobLocale); } }
DocumentReferenceComparator implements Comparator<DocumentReference> { @Override public int compare(DocumentReference alice, DocumentReference bob) { Iterator<EntityReference> aliceIterator = alice.getReversedReferenceChain().iterator(); Iterator<EntityReference> bobIterator = bob.getReversedReferenceChain().iterator(); while (aliceIterator.hasNext() && bobIterator.hasNext()) { int diff = aliceIterator.next().getName().compareTo(bobIterator.next().getName()); if (diff != 0) { return diff; } } if (aliceIterator.hasNext()) { return 1; } else if (bobIterator.hasNext()) { return -1; } String aliceLocale = alice.getLocale() != null ? alice.getLocale().toString() : ""; String bobLocale = bob.getLocale() != null ? bob.getLocale().toString() : ""; return aliceLocale.compareTo(bobLocale); }  }
DocumentReferenceComparator implements Comparator<DocumentReference> { @Override public int compare(DocumentReference alice, DocumentReference bob) { Iterator<EntityReference> aliceIterator = alice.getReversedReferenceChain().iterator(); Iterator<EntityReference> bobIterator = bob.getReversedReferenceChain().iterator(); while (aliceIterator.hasNext() && bobIterator.hasNext()) { int diff = aliceIterator.next().getName().compareTo(bobIterator.next().getName()); if (diff != 0) { return diff; } } if (aliceIterator.hasNext()) { return 1; } else if (bobIterator.hasNext()) { return -1; } String aliceLocale = alice.getLocale() != null ? alice.getLocale().toString() : ""; String bobLocale = bob.getLocale() != null ? bob.getLocale().toString() : ""; return aliceLocale.compareTo(bobLocale); }  @Override int compare(DocumentReference alice, DocumentReference bob); }
DocumentReferenceComparator implements Comparator<DocumentReference> { @Override public int compare(DocumentReference alice, DocumentReference bob) { Iterator<EntityReference> aliceIterator = alice.getReversedReferenceChain().iterator(); Iterator<EntityReference> bobIterator = bob.getReversedReferenceChain().iterator(); while (aliceIterator.hasNext() && bobIterator.hasNext()) { int diff = aliceIterator.next().getName().compareTo(bobIterator.next().getName()); if (diff != 0) { return diff; } } if (aliceIterator.hasNext()) { return 1; } else if (bobIterator.hasNext()) { return -1; } String aliceLocale = alice.getLocale() != null ? alice.getLocale().toString() : ""; String bobLocale = bob.getLocale() != null ? bob.getLocale().toString() : ""; return aliceLocale.compareTo(bobLocale); }  @Override int compare(DocumentReference alice, DocumentReference bob);  }