RestrictionImpl implements Restriction { @Override public int hashCode() { if (hashCode == 0) { hashCode = Objects.hashCode(definition, property, PropertyValues.create(property)); } return hashCode; } RestrictionImpl(@NotNull PropertyState property, @NotNull RestrictionDefinition def);  RestrictionImpl(@NotNull PropertyState property, boolean isMandatory); @NotNull @Override RestrictionDefinition getDefinition(); @NotNull @Override PropertyState getProperty(); @Override int hashCode(); @Override boolean equals(Object o);  }
@Test public void testSameHashCode() { assertEquals(restriction.hashCode(), new RestrictionImpl(createProperty(name, value, type), isMandatory).hashCode()); }
@Test public void testNotSameHashCode() { List<Restriction> rs = new ArrayList<>(); rs.add(new RestrictionImpl(PropertyStates.createProperty(name, value, Type.STRING), isMandatory)); rs.add(new RestrictionImpl(PropertyStates.createProperty(name, ImmutableList.of(value), Type.NAMES), isMandatory)); rs.add(new RestrictionImpl(createProperty("otherName", value, type), isMandatory)); rs.add(new RestrictionImpl(createProperty(name, "otherValue", type), isMandatory)); rs.add(new RestrictionImpl(createProperty(name, value, type), !isMandatory)); rs.add(new Restriction() { @NotNull @Override public RestrictionDefinition getDefinition() { return new RestrictionDefinitionImpl(name, type, isMandatory); } @NotNull @Override public PropertyState getProperty() { return createProperty(name, value, type); } }); for (Restriction r : rs) { assertNotEquals(restriction.hashCode(), r.hashCode()); } }