FontCharacteristics { @Override public int hashCode() { int result = (isItalic ? 1 : 0); result = 31 * result + (isBold ? 1 : 0); result = 31 * result + (int) fontWeight; return result; } FontCharacteristics();  FontCharacteristics(FontCharacteristics other); FontCharacteristics setFontWeight(short fw); FontCharacteristics setFontWeight(String fw); FontCharacteristics setBoldFlag(boolean isBold); FontCharacteristics setItalicFlag(boolean isItalic); FontCharacteristics setMonospaceFlag(boolean isMonospace); FontCharacteristics setFontStyle(String fs); boolean isItalic(); boolean isBold(); boolean isMonospace(); short getFontWeight(); boolean isUndefined(); @Override boolean equals(Object o); @Override int hashCode();  }
@Test public void testHashCode() { FontCharacteristics fontCharacteristics = new FontCharacteristics(); fontCharacteristics.setFontStyle("italic"); fontCharacteristics.setFontWeight((short) 300); FontCharacteristics sameFontCharacteristics = new FontCharacteristics(); sameFontCharacteristics.setFontStyle("italic"); sameFontCharacteristics.setFontWeight((short) 300); Assert.assertEquals(fontCharacteristics.hashCode(), sameFontCharacteristics.hashCode()); FontCharacteristics copyFontCharacteristics = new FontCharacteristics(fontCharacteristics); Assert.assertEquals(fontCharacteristics.hashCode(), copyFontCharacteristics.hashCode()); FontCharacteristics diffFontCharacteristics = new FontCharacteristics(); fontCharacteristics.setBoldFlag(true); fontCharacteristics.setFontWeight((short) 800); Assert.assertNotEquals(fontCharacteristics.hashCode(), diffFontCharacteristics.hashCode()); }