Remove more duplicate code from models
[policy/models.git] / models-tosca / src / main / java / org / onap / policy / models / tosca / authorative / concepts / ToscaConceptIdentifierOptVersion.java
index c23c04f..62c1ed7 100644 (file)
@@ -2,7 +2,7 @@
  * ============LICENSE_START=======================================================
  * ONAP Policy Models
  * ================================================================================
- * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2019, 2021 AT&T Intellectual Property. All rights reserved.
  * Modifications Copyright (C) 2020-2021 Nordix Foundation.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
 
 package org.onap.policy.models.tosca.authorative.concepts;
 
-import lombok.Data;
+import java.io.Serializable;
+import lombok.EqualsAndHashCode;
 import lombok.NoArgsConstructor;
 import lombok.NonNull;
-import org.apache.commons.lang3.ObjectUtils;
 
 /**
- * Concept identifier with an optional version; only the "name" is required.
+ * Concept identifier with an optional name and version.
  */
-@Data
+@EqualsAndHashCode(callSuper = true)
 @NoArgsConstructor
-public class ToscaConceptIdentifierOptVersion implements Comparable<ToscaConceptIdentifierOptVersion> {
-
-    @NonNull
-    private String name;
-
-    private String version;
+public class ToscaConceptIdentifierOptVersion extends ToscaNameVersion
+                implements Serializable, Comparable<ToscaConceptIdentifierOptVersion> {
+    private static final long serialVersionUID = 8010649773816325786L;
 
     public ToscaConceptIdentifierOptVersion(@NonNull String name, String version) {
-        this.name = name;
-        this.version = version;
+        super(name, version);
     }
 
     public ToscaConceptIdentifierOptVersion(ToscaConceptIdentifierOptVersion source) {
-        this.name = source.name;
-        this.version = source.version;
+        super(source);
     }
 
     public ToscaConceptIdentifierOptVersion(ToscaConceptIdentifier source) {
-        this.name = source.getName();
-        this.version = source.getVersion();
+        super(source.getName(), source.getVersion());
     }
 
     @Override
     public int compareTo(ToscaConceptIdentifierOptVersion other) {
-        if (this == other) {
-            return 0;
-        }
-
-        if (other == null) {
-            return 1;
-        }
-
-        int result = ObjectUtils.compare(getName(), other.getName());
-        if (result != 0) {
-            return result;
-        }
-
-        return ObjectUtils.compare(getVersion(), other.getVersion());
-    }
-
-    @Override
-    public String toString() {
-        return this.name + " " + this.version;
+        return commonCompareTo(other);
     }
 }