@Test public void compare() { DocumentReference reference = new DocumentReference("wiki", "Space", "Page"); assertEquals(0, comparator.compare(reference, new DocumentReference(reference))); assertEquals(0, comparator.compare(new DocumentReference(reference, Locale.FRENCH), new DocumentReference(reference, Locale.FRENCH))); assertTrue(comparator.compare(new DocumentReference(reference, Locale.ROOT), new DocumentReference(reference, Locale.GERMAN)) < 0); assertTrue(comparator.compare(new DocumentReference(reference, Locale.ITALIAN), reference) > 0); assertTrue(comparator.compare(reference, new DocumentReference("wiki", "Space", "APage")) > 0); assertTrue(comparator.compare(reference, new DocumentReference("wiki", "XSpace", "APage")) < 0); assertTrue(comparator.compare(reference, new DocumentReference("aWiki", "ASpace", "APage")) > 0); }
@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);  }