@Test public void equalityTest() { UUID sessionId = UUID.randomUUID(); UUID incarnationId = UUID.randomUUID(); String logSegmentName = LogSegmentNameHelper.generateFirstSegmentName(isLogSegmented); Offset offset = new Offset(logSegmentName, 0); Offset otherOffset = new Offset(logSegmentName, 1); MockId key = new MockId(TestUtils.getRandomString(10)); MockId otherKey = new MockId(TestUtils.getRandomString(10)); StoreFindToken initToken = new StoreFindToken(); StoreFindToken otherInitToken = new StoreFindToken(); StoreFindToken indexToken = new StoreFindToken(key, offset, sessionId, incarnationId); StoreFindToken otherIndexToken = new StoreFindToken(key, offset, sessionId, incarnationId); StoreFindToken journalToken = new StoreFindToken(offset, sessionId, incarnationId, false); StoreFindToken otherJournalToken = new StoreFindToken(offset, sessionId, incarnationId, false); StoreFindToken inclusiveJournalToken = new StoreFindToken(offset, sessionId, incarnationId, true); StoreFindToken otherInclusiveJournalToken = new StoreFindToken(offset, sessionId, incarnationId, true); compareTokens(initToken, initToken); compareTokens(initToken, otherInitToken); compareTokens(indexToken, indexToken); compareTokens(indexToken, otherIndexToken); compareTokens(journalToken, journalToken); compareTokens(journalToken, otherJournalToken); compareTokens(inclusiveJournalToken, otherInclusiveJournalToken); UUID newSessionId = getRandomUUID(sessionId); UUID newIncarnationId = getRandomUUID(incarnationId); compareTokens(indexToken, new StoreFindToken(key, offset, newSessionId, incarnationId)); compareTokens(journalToken, new StoreFindToken(offset, newSessionId, incarnationId, false)); compareTokens(indexToken, new StoreFindToken(key, offset, sessionId, newIncarnationId)); compareTokens(journalToken, new StoreFindToken(offset, sessionId, newIncarnationId, false)); List<Pair<StoreFindToken, StoreFindToken>> unequalPairs = new ArrayList<>(); unequalPairs.add(new Pair<>(initToken, indexToken)); unequalPairs.add(new Pair<>(initToken, journalToken)); unequalPairs.add(new Pair<>(initToken, inclusiveJournalToken)); unequalPairs.add(new Pair<>(indexToken, journalToken)); unequalPairs.add(new Pair<>(indexToken, inclusiveJournalToken)); unequalPairs.add(new Pair<>(indexToken, new StoreFindToken(key, otherOffset, sessionId, incarnationId))); unequalPairs.add(new Pair<>(indexToken, new StoreFindToken(otherKey, offset, sessionId, incarnationId))); unequalPairs.add(new Pair<>(journalToken, new StoreFindToken(otherOffset, sessionId, incarnationId, false))); unequalPairs.add(new Pair<>(inclusiveJournalToken, journalToken)); for (Pair<StoreFindToken, StoreFindToken> unequalPair : unequalPairs) { StoreFindToken first = unequalPair.getFirst(); StoreFindToken second = unequalPair.getSecond(); assertFalse("StoreFindTokens [" + first + "] and [" + second + "] should not be equal", unequalPair.getFirst().equals(unequalPair.getSecond())); } }
@Override public boolean equals(Object o) { if (this == o) { return true; } if (o == null || getClass() != o.getClass()) { return false; } StoreFindToken that = (StoreFindToken) o; if (type != that.type) { return false; } if (offset != null ? !offset.equals(that.offset) : that.offset != null) { return false; } if (inclusive != that.inclusive) { return false; } return storeKey != null ? storeKey.equals(that.storeKey) : that.storeKey == null; }
StoreFindToken implements FindToken { @Override public boolean equals(Object o) { if (this == o) { return true; } if (o == null || getClass() != o.getClass()) { return false; } StoreFindToken that = (StoreFindToken) o; if (type != that.type) { return false; } if (offset != null ? !offset.equals(that.offset) : that.offset != null) { return false; } if (inclusive != that.inclusive) { return false; } return storeKey != null ? storeKey.equals(that.storeKey) : that.storeKey == null; } }
StoreFindToken implements FindToken { @Override public boolean equals(Object o) { if (this == o) { return true; } if (o == null || getClass() != o.getClass()) { return false; } StoreFindToken that = (StoreFindToken) o; if (type != that.type) { return false; } if (offset != null ? !offset.equals(that.offset) : that.offset != null) { return false; } if (inclusive != that.inclusive) { return false; } return storeKey != null ? storeKey.equals(that.storeKey) : that.storeKey == null; } StoreFindToken();   StoreFindToken(StoreKey key, Offset indexSegmentStartOffset, UUID sessionId, UUID incarnationId);   StoreFindToken(Offset offset, UUID sessionId, UUID incarnationId, boolean inclusive); private  StoreFindToken(FindTokenType type, Offset offset, StoreKey key, UUID sessionId, UUID incarnationId,
      boolean inclusive, short version); }
StoreFindToken implements FindToken { @Override public boolean equals(Object o) { if (this == o) { return true; } if (o == null || getClass() != o.getClass()) { return false; } StoreFindToken that = (StoreFindToken) o; if (type != that.type) { return false; } if (offset != null ? !offset.equals(that.offset) : that.offset != null) { return false; } if (inclusive != that.inclusive) { return false; } return storeKey != null ? storeKey.equals(that.storeKey) : that.storeKey == null; } StoreFindToken();   StoreFindToken(StoreKey key, Offset indexSegmentStartOffset, UUID sessionId, UUID incarnationId);   StoreFindToken(Offset offset, UUID sessionId, UUID incarnationId, boolean inclusive); private  StoreFindToken(FindTokenType type, Offset offset, StoreKey key, UUID sessionId, UUID incarnationId,
      boolean inclusive, short version); FindTokenType getType(); StoreKey getStoreKey(); Offset getOffset(); @Override short getVersion(); @Override long getBytesRead(); @Override byte[] toBytes(); @Override String toString(); @Override boolean equals(Object o); @Override int hashCode(); }
StoreFindToken implements FindToken { @Override public boolean equals(Object o) { if (this == o) { return true; } if (o == null || getClass() != o.getClass()) { return false; } StoreFindToken that = (StoreFindToken) o; if (type != that.type) { return false; } if (offset != null ? !offset.equals(that.offset) : that.offset != null) { return false; } if (inclusive != that.inclusive) { return false; } return storeKey != null ? storeKey.equals(that.storeKey) : that.storeKey == null; } StoreFindToken();   StoreFindToken(StoreKey key, Offset indexSegmentStartOffset, UUID sessionId, UUID incarnationId);   StoreFindToken(Offset offset, UUID sessionId, UUID incarnationId, boolean inclusive); private  StoreFindToken(FindTokenType type, Offset offset, StoreKey key, UUID sessionId, UUID incarnationId,
      boolean inclusive, short version); FindTokenType getType(); StoreKey getStoreKey(); Offset getOffset(); @Override short getVersion(); @Override long getBytesRead(); @Override byte[] toBytes(); @Override String toString(); @Override boolean equals(Object o); @Override int hashCode();  }