@Override public boolean equals(Object other) { BinaryConfiguration castOther; if (other instanceof BinaryConfiguration) { castOther = (BinaryConfiguration) other; return new EqualsBuilder().append(this.getConfigKey(), castOther.getConfigKey()).isEquals(); } else { return false; } }
private boolean isLogoNotEmpty(BinaryConfiguration logoDomObj) { return (logoDomObj != null && logoDomObj.getConfigValue() != null && logoDomObj.getConfigValue().length > 0); }
private void persistLogo(String prefix, ImageLogo logo) { BinaryConfiguration logoDomObj = new BinaryConfiguration(); logoDomObj.setConfigValue(logo.getImageData()); logoDomObj.setConfigKey(prefix + "Logo"); binConfigDAO.persist(logoDomObj); Configuration logoType = new Configuration(prefix + "LogoType", logo.getImageType()); Configuration logoWidth = new Configuration(prefix + "LogoWidth", Integer.toString(logo.getWidth())); Configuration logoHeight = new Configuration(prefix + "LogoHeight", Integer.toString(logo.getHeight())); configDao.persist(logoType); configDao.persist(logoWidth); configDao.persist(logoHeight); }
@Test public void shouldSave() { BinaryConfiguration config = new BinaryConfiguration(); config.setConfigKey("test"); config.setConfigValue(new byte[]{0, 1, 2}); dao.persist(config); BinaryConfiguration configuration = dao.findById("test"); assertNotNull(configuration); } }
@Override public int hashCode() { return new HashCodeBuilder().append(getConfigKey()).toHashCode(); }
private ImageLogo getPersistedLogo(String prefix) { BinaryConfiguration logoDomObj = binConfigDAO.findById(prefix + "Logo"); ImageLogo logo = null; if (isLogoNotEmpty(logoDomObj)) { logo = new ImageLogo(); logo.setImageData(logoDomObj.getConfigValue()); Configuration logoType = configDao.findById(prefix + "LogoType"); logo.setImageType(logoType.getConfigValue()); Configuration logoWidth = configDao.findById(prefix + "LogoWidth"); logo.setWidth(Integer.parseInt(logoWidth.getConfigValue())); Configuration logoHeight = configDao.findById(prefix + "LogoHeight"); logo.setHeight(Integer.parseInt(logoHeight.getConfigValue())); } return logo; }
public int compareTo(BinaryConfiguration object) { return new CompareToBuilder() .append(this.getConfigKey(), object.getConfigKey()).toComparison(); }