BaseSequenceEntry { public boolean testEquals(@NotNull BasedSequence baseSeq, @NotNull Object o, int[] equalsCall) { equalsCall[0] = 0; if (o == baseSeq || o == baseSeq.getBase()) return true; if (!(o instanceof CharSequence)) return false; CharSequence other = (CharSequence) o; if (other.length() != baseSeq.length()) return false; if (o instanceof IRichSequence<?>) { IRichSequence<?> rich = (BasedSequence) o; equalsCall[0] = 1; if (rich.hashCode() != baseSeq.hashCode()) return false; } else if (o instanceof String) { String string = (String) o; equalsCall[0] = 1; if (string.hashCode() != baseSeq.hashCode()) return false; } Boolean result; equalsCall[0] = 2; result = quickEquals.get(o); if (result != null) return result; if (baseSeq instanceof SubSequence && o instanceof String) { equalsCall[0] = 3; result = baseSeq.getBase().equals(o); } else if (baseSeq instanceof SubSequence && o instanceof SubSequence) { equalsCall[0] = 3; result = baseSeq.getBase().equals(((SubSequence) o).getBase()); } else { equalsCall[0] = 4; result = baseSeq.equals(o); } quickEquals.put(o, result); return result; } BaseSequenceEntry(); boolean testEquals(@NotNull BasedSequence baseSeq, @NotNull Object o, int[] equalsCall); @Override boolean equals(Object o); @Override int hashCode();  }
@Test public void test_basic() { String input1 = "0123456789"; String input2 = "0123456789"; String input3 = "0123456789"; String input4 = "012345678"; String input5 = "1234567890"; BasedSequence sequence1 = BasedSequence.of(input1); BasedSequence sequence2 = BasedSequence.of(input2); BasedSequence sequence3 = BasedSequence.of(input3); BasedSequence sequence4 = BasedSequence.of(input4); BasedSequence sequence5 = BasedSequence.of(input5); BaseSequenceEntry entry = new BaseSequenceEntry(); int[] equalsCall = { 0 }; assertTrue(entry.testEquals(sequence1, input1, equalsCall)); assertEquals(0, equalsCall[0]); assertTrue(entry.testEquals(sequence1, input2, equalsCall)); assertEquals(0, equalsCall[0]); assertTrue(entry.testEquals(sequence1, input3, equalsCall)); assertEquals(0, equalsCall[0]); assertFalse(entry.testEquals(sequence1, input4, equalsCall)); assertEquals(0, equalsCall[0]); assertFalse(entry.testEquals(sequence1, input5, equalsCall)); assertEquals(1, equalsCall[0]); assertTrue(entry.testEquals(sequence1, sequence1, equalsCall)); assertEquals(0, equalsCall[0]); assertTrue(entry.testEquals(sequence1, sequence2, equalsCall)); assertEquals(3, equalsCall[0]); assertTrue(entry.testEquals(sequence1, sequence2, equalsCall)); assertEquals(2, equalsCall[0]); sequence2 = null; System.gc(); sequence2 = BasedSequence.of(input2); assertTrue(entry.testEquals(sequence1, sequence2, equalsCall)); assertEquals(3, equalsCall[0]); assertTrue(entry.testEquals(sequence1, sequence2, equalsCall)); assertEquals(2, equalsCall[0]); assertTrue(entry.testEquals(sequence1, sequence3, equalsCall)); assertEquals(2, equalsCall[0]); assertFalse(entry.testEquals(sequence1, sequence4, equalsCall)); assertEquals(0, equalsCall[0]); assertFalse(entry.testEquals(sequence1, sequence5, equalsCall)); assertEquals(1, equalsCall[0]); }