StringList implements Iterable<String> { @Override public int hashCode() { int numBitsRegular = 32 / size(); int numExtra = 32 % size(); int maskExtra = 0xFFFFFFFF >>> (32 - numBitsRegular + 1); int maskRegular = 0xFFFFFFFF >>> 32 - numBitsRegular; int code = 0x000000000; int leftMostBit = 0; for (int wi = 0; wi < size(); wi++) { int word; int mask; int numBits; if (wi < numExtra) { mask = maskExtra; numBits = numBitsRegular + 1; } else { mask = maskRegular; numBits = numBitsRegular; } word = getToken(wi).hashCode() & mask; word <<= 32 - leftMostBit - numBits; leftMostBit += numBits; code |= word; } return code; } StringList(String singleToken);  StringList(String... tokens); String getToken(int index); int size(); Iterator<String> iterator(); boolean compareToIgnoreCase(StringList tokens); @Override boolean equals(Object obj); @Override int hashCode(); @Override String toString();  }
@Test public void testHashCode() { assertEquals(new StringList("a", "b").hashCode(), new StringList("a", "b").hashCode()); }