/** * Since {@link cscie97.asn3.ecommerce.product.Country} objects may be added to collections, and * also since the {@link cscie97.asn3.ecommerce.product.IProductAPI} enforces that all country * items be unique, this method provides a way to determine if another {@link * cscie97.asn3.ecommerce.product.Country} item is the same as the current one. Uses the Apache * Commons {@link org.apache.commons.lang3.builder.EqualsBuilder} to determine if the two objects * are indeed equal to each other. * * @param compare the {@link cscie97.asn3.ecommerce.product.Country} item to compare to the * current object to test for equality * @return true if the objects are the same, false otherwise * @see <a * href="http://stackoverflow.com/questions/27581/overriding-equals-and-hashcode-in-java">http://stackoverflow.com/questions/27581/overriding-equals-and-hashcode-in-java</a> * @see <a * href="http://www.java-tutorial.ch/core-java-tutorial/equalsbuilder">http://www.java-tutorial.ch/core-java-tutorial/equalsbuilder</a> * @see <a * href="http://commons.apache.org/proper/commons-lang/javadocs/api-2.6/org/apache/commons/lang/builder/EqualsBuilder.html">http://commons.apache.org/proper/commons-lang/javadocs/api-2.6/org/apache/commons/lang/builder/EqualsBuilder.html</a> */ @Override public boolean equals(Object compare) { if (compare == null) return false; if (!(compare instanceof Country)) return false; if (compare == this) return true; Country rhs = (Country) compare; return new EqualsBuilder() .appendSuper(super.equals(compare)) .append(this.code, rhs.getCode()) .append(this.name, rhs.getName()) .append(this.exportStatus, rhs.getExportStatus()) .isEquals(); }
/** * Checks that all required fields are set, and that all country item property values are valid. * * @param country the item to be validated for correct properties * @return true if all properties are valid, false otherwise */ public static boolean validateCountry(Country country) { return ((country.getCode() != null && country.getCode().length() == 2) && (country.getName() != null && country.getName().length() > 0) && (country.getExportStatus() != null && (country.getExportStatus().equalsIgnoreCase("OPEN") || country.getExportStatus().equalsIgnoreCase("CLOSED")))); }