diff options
Diffstat (limited to 'openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-api/src/main/java/org/openecomp/sdc/vendorlicense/dao/types/ChoiceOrOther.java')
-rw-r--r-- | openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-api/src/main/java/org/openecomp/sdc/vendorlicense/dao/types/ChoiceOrOther.java | 203 |
1 files changed, 96 insertions, 107 deletions
diff --git a/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-api/src/main/java/org/openecomp/sdc/vendorlicense/dao/types/ChoiceOrOther.java b/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-api/src/main/java/org/openecomp/sdc/vendorlicense/dao/types/ChoiceOrOther.java index 01699355f5..e4d58fad29 100644 --- a/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-api/src/main/java/org/openecomp/sdc/vendorlicense/dao/types/ChoiceOrOther.java +++ b/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-api/src/main/java/org/openecomp/sdc/vendorlicense/dao/types/ChoiceOrOther.java @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.openecomp.sdc.vendorlicense.dao.types; import com.datastax.driver.mapping.annotations.Transient; @@ -24,126 +23,116 @@ import org.openecomp.sdc.common.errors.ErrorCode; @UDT(keyspace = "dox", name = "choice_or_other") public class ChoiceOrOther<E extends Enum<E>> { - private static final String CHOICE_OR_OTHER_INVALID_ENUM_ERR_ID = - "MULTI_CHOICE_OR_OTHER_INVALID_ENUM_ERR_ID"; - private static final String CHOICE_OR_OTHER_INVALID_ENUM_MSG = - "Enum used as part of ChoiceOrOther type must contain the value 'Other'"; - public static final String OTHER_ENUM_VALUE = "Other"; - - @Transient - private E choice; - - @Transient - private String other; - - private String result; - - public ChoiceOrOther() { - // the default constructor is used to instantiate by reflection - } - - /** - * Instantiates a new Choice or other. - * - * @param choice the choice - * @param other the other - */ - public ChoiceOrOther(E choice, String other) { - this.choice = choice; - this.other = other; - result = resolveResult(); - } - - public E getChoice() { - return choice; - } - - public void setChoice(E choice) { - - this.choice = choice; - } - - public String getOther() { - return other; - } - - public void setOther(String other) { - this.other = other; - } - - public String getResult() { - return result; - } + public static final String OTHER_ENUM_VALUE = "Other"; + private static final String CHOICE_OR_OTHER_INVALID_ENUM_ERR_ID = "MULTI_CHOICE_OR_OTHER_INVALID_ENUM_ERR_ID"; + private static final String CHOICE_OR_OTHER_INVALID_ENUM_MSG = "Enum used as part of ChoiceOrOther type must contain the value 'Other'"; + @Transient + private E choice; + @Transient + private String other; + private String result; + + public ChoiceOrOther() { + // the default constructor is used to instantiate by reflection + } - /** - * Sets result. - * - * @param result the result - */ - public void setResult(String result) { - if (choice != null) { - if (result == null) { - this.result = resolveResult(); - } - } else { - this.result = result; + /** + * Instantiates a new Choice or other. + * + * @param choice the choice + * @param other the other + */ + public ChoiceOrOther(E choice, String other) { + this.choice = choice; + this.other = other; + result = resolveResult(); } - } - private String resolveResult() { - return OTHER_ENUM_VALUE.equals(choice.name()) ? other : choice.name(); - } + public E getChoice() { + return choice; + } - /** - * Resolve enum. - * - * @param enumClass the enum class - */ - public void resolveEnum(Class<E> enumClass) { - if (choice != null || result == null) { - return; + public void setChoice(E choice) { + this.choice = choice; } - try { - choice = E.valueOf(enumClass, result); - } catch (IllegalArgumentException exception) { - try { - choice = E.valueOf(enumClass, OTHER_ENUM_VALUE); - } catch (IllegalArgumentException ex) { - throw new CoreException(new ErrorCode.ErrorCodeBuilder() - .withId(CHOICE_OR_OTHER_INVALID_ENUM_ERR_ID) - .withMessage(CHOICE_OR_OTHER_INVALID_ENUM_MSG).build()); - } - other = result; + public String getOther() { + return other; } - } - @Override - public int hashCode() { - int result1 = choice != null ? choice.hashCode() : 0; - result1 = 31 * result1 + (other != null ? other.hashCode() : 0); - result1 = 31 * result1 + (result != null ? result.hashCode() : 0); - return result1; - } + public void setOther(String other) { + this.other = other; + } - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; + public String getResult() { + return result; } - if (obj == null || getClass() != obj.getClass()) { - return false; + + /** + * Sets result. + * + * @param result the result + */ + public void setResult(String result) { + if (choice != null) { + if (result == null) { + this.result = resolveResult(); + } + } else { + this.result = result; + } } - ChoiceOrOther<?> that = (ChoiceOrOther<?>) obj; + private String resolveResult() { + return OTHER_ENUM_VALUE.equals(choice.name()) ? other : choice.name(); + } - if (choice != null ? !choice.equals(that.choice) : that.choice != null) { - return false; + /** + * Resolve enum. + * + * @param enumClass the enum class + */ + public void resolveEnum(Class<E> enumClass) { + if (choice != null || result == null) { + return; + } + try { + choice = E.valueOf(enumClass, result); + } catch (IllegalArgumentException exception) { + try { + choice = E.valueOf(enumClass, OTHER_ENUM_VALUE); + } catch (IllegalArgumentException ex) { + throw new CoreException( + new ErrorCode.ErrorCodeBuilder().withId(CHOICE_OR_OTHER_INVALID_ENUM_ERR_ID).withMessage(CHOICE_OR_OTHER_INVALID_ENUM_MSG) + .build()); + } + other = result; + } } - if (other != null ? !other.equals(that.other) : that.other != null) { - return false; + + @Override + public int hashCode() { + int result1 = choice != null ? choice.hashCode() : 0; + result1 = 31 * result1 + (other != null ? other.hashCode() : 0); + result1 = 31 * result1 + (result != null ? result.hashCode() : 0); + return result1; } - return result != null ? result.equals(that.result) : that.result == null; - } + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null || getClass() != obj.getClass()) { + return false; + } + ChoiceOrOther<?> that = (ChoiceOrOther<?>) obj; + if (choice != null ? !choice.equals(that.choice) : that.choice != null) { + return false; + } + if (other != null ? !other.equals(that.other) : that.other != null) { + return false; + } + return result != null ? result.equals(that.result) : that.result == null; + } } |