StringType implements PrimitiveType, State, Command { @Override public boolean equals(@Nullable Object obj) { if (this == obj) { return true; } if (obj == null) { return false; } if (obj instanceof String) { return obj.equals(value); } if (getClass() != obj.getClass()) { return false; } StringType other = (StringType) obj; return Objects.equals(this.value, other.value); } StringType();  StringType(@Nullable String value); @Override String toString(); @Override String toFullString(); static StringType valueOf(@Nullable String value); @Override String format(String pattern); @Override int hashCode(); @Override boolean equals(@Nullable Object obj); static final StringType EMPTY; }
@Test @SuppressWarnings("unlikely-arg-type") public void testEquals() { StringType empty = new StringType(""); StringType expected1 = new StringType("expected1"); StringType expected2 = new StringType("expected2"); assertEquals(empty.hashCode(), StringType.EMPTY.hashCode()); assertEquals(empty.hashCode(), new StringType("").hashCode()); assertEquals(empty.hashCode(), new StringType().hashCode()); assertEquals(empty.hashCode(), new StringType(null).hashCode()); assertEquals(expected1.hashCode(), new StringType("expected1").hashCode()); assertEquals(expected2.hashCode(), new StringType("expected2").hashCode()); assertNotEquals(expected1.hashCode(), new StringType("expected2").hashCode()); assertEquals(empty, StringType.EMPTY); assertEquals(empty, new StringType("")); assertEquals(empty, new StringType()); assertEquals(empty, new StringType(null)); assertEquals(expected1, new StringType("expected1")); assertEquals(expected2, new StringType("expected2")); assertFalse(expected1.equals(new StringType("expected2"))); assertFalse(expected2.equals(new StringType("expected1"))); assertFalse(expected1.equals(StringType.EMPTY)); assertFalse(expected2.equals(StringType.EMPTY)); assertTrue(expected1.equals("expected1")); assertFalse(expected1.equals("expected2")); assertTrue(new StringType(null).equals(new StringType(null))); assertTrue(new StringType("").equals(new StringType(null))); assertTrue(new StringType(null).equals(new StringType(""))); }