X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=models-base%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Fpolicy%2Fmodels%2Fbase%2FPfReferenceTimestampKey.java;h=06af688b003eeba20c9f8658f595e2001f4a6e86;hb=fcbf3698fa3e3fbc6ea3364d80d4a3f3a8d37650;hp=47a72e8cd113b85f5df658bfb397cba05b1253f9;hpb=726bec7cd5e1b0f5c45b3ec58bc64e344240e8c9;p=policy%2Fmodels.git diff --git a/models-base/src/main/java/org/onap/policy/models/base/PfReferenceTimestampKey.java b/models-base/src/main/java/org/onap/policy/models/base/PfReferenceTimestampKey.java index 47a72e8cd..06af688b0 100644 --- a/models-base/src/main/java/org/onap/policy/models/base/PfReferenceTimestampKey.java +++ b/models-base/src/main/java/org/onap/policy/models/base/PfReferenceTimestampKey.java @@ -22,12 +22,14 @@ package org.onap.policy.models.base; import java.sql.Timestamp; import java.time.Instant; +import java.util.Collections; +import java.util.List; import javax.persistence.Column; import javax.persistence.Embeddable; +import javax.persistence.Embedded; import lombok.Data; import lombok.EqualsAndHashCode; import lombok.NonNull; -import lombok.ToString; import org.onap.policy.common.parameters.annotations.NotNull; import org.onap.policy.common.utils.validation.Assertions; @@ -36,11 +38,11 @@ import org.onap.policy.common.utils.validation.Assertions; * additional option to have timestamp as a parameter. * */ + @Embeddable @Data -@EqualsAndHashCode(callSuper = true) -@ToString(callSuper = true) -public class PfReferenceTimestampKey extends PfReferenceKey { +@EqualsAndHashCode +public class PfReferenceTimestampKey extends PfKey { private static final long serialVersionUID = 1130918285832617215L; private static final String TIMESTAMP_TOKEN = "timeStamp"; @@ -49,24 +51,27 @@ public class PfReferenceTimestampKey extends PfReferenceKey { @NotNull private Timestamp timeStamp; + @Embedded + @Column + private PfReferenceKey referenceKey; /** * The default constructor creates a null reference timestamp key. */ public PfReferenceTimestampKey() { - super(); + this.referenceKey = new PfReferenceKey(); this.timeStamp = new Timestamp(0); } /** * The Copy Constructor creates a key by copying another key. * - * @param referenceKey + * @param referenceTimestampKey * the reference key to copy from */ - public PfReferenceTimestampKey(final PfReferenceTimestampKey referenceKey) { - super(referenceKey); - this.timeStamp = referenceKey.getTimeStamp(); + public PfReferenceTimestampKey(final PfReferenceTimestampKey referenceTimestampKey) { + this.referenceKey = referenceTimestampKey.getReferenceKey(); + this.timeStamp = referenceTimestampKey.getTimeStamp(); } /** @@ -76,7 +81,7 @@ public class PfReferenceTimestampKey extends PfReferenceKey { * the parent concept key of this reference key */ public PfReferenceTimestampKey(final PfConceptKey pfConceptKey) { - super(pfConceptKey); + this.referenceKey = new PfReferenceKey(pfConceptKey); this.timeStamp = new Timestamp(0); } @@ -91,7 +96,7 @@ public class PfReferenceTimestampKey extends PfReferenceKey { * the time stamp for this reference key */ public PfReferenceTimestampKey(final PfConceptKey pfConceptKey, final String localName, final Instant instant) { - super(pfConceptKey, localName); + this.referenceKey = new PfReferenceKey(pfConceptKey, localName); this.timeStamp = Timestamp.from(instant); } @@ -107,7 +112,7 @@ public class PfReferenceTimestampKey extends PfReferenceKey { */ public PfReferenceTimestampKey(final PfReferenceKey parentReferenceKey, final String localName, final Instant instant) { - super(parentReferenceKey, localName); + this.referenceKey = new PfReferenceKey(parentReferenceKey, localName); this.timeStamp = Timestamp.from(instant); } @@ -126,7 +131,7 @@ public class PfReferenceTimestampKey extends PfReferenceKey { */ public PfReferenceTimestampKey(final PfConceptKey pfConceptKey, final String parentLocalName, final String localName, final Instant instant) { - super(pfConceptKey, parentLocalName, localName); + this.referenceKey = new PfReferenceKey(pfConceptKey, parentLocalName, localName); this.timeStamp = Timestamp.from(instant); } @@ -145,7 +150,7 @@ public class PfReferenceTimestampKey extends PfReferenceKey { */ public PfReferenceTimestampKey(final String parentKeyName, final String parentKeyVersion, final String localName, final Instant instant) { - super(parentKeyName, parentKeyVersion, NULL_KEY_NAME, localName); + this.referenceKey = new PfReferenceKey(parentKeyName, parentKeyVersion, PfKey.NULL_KEY_NAME, localName); this.timeStamp = Timestamp.from(instant); } @@ -166,7 +171,7 @@ public class PfReferenceTimestampKey extends PfReferenceKey { */ public PfReferenceTimestampKey(final String parentKeyName, final String parentKeyVersion, final String parentLocalName, final String localName, final Instant instant) { - super(parentKeyName, parentKeyVersion, parentLocalName, localName); + this.referenceKey = new PfReferenceKey(parentKeyName, parentKeyVersion, parentLocalName, localName); this.timeStamp = Timestamp.from(instant); } @@ -177,7 +182,7 @@ public class PfReferenceTimestampKey extends PfReferenceKey { * @param id the key ID in a format that respects the KEY_ID_REGEXP */ public PfReferenceTimestampKey(final String id) { - super(id.substring(0, id.lastIndexOf(':'))); + this.referenceKey = new PfReferenceKey(id.substring(0, id.lastIndexOf(':'))); this.timeStamp = new Timestamp(Long.parseLong(id.substring(id.lastIndexOf(':') + 1))); } @@ -200,32 +205,99 @@ public class PfReferenceTimestampKey extends PfReferenceKey { setTimeStamp(Timestamp.from(instant)); } - @Override + /** + * Get the key of this reference. + * + * @return the pfReferenceTimestamp key + */ public PfReferenceTimestampKey getKey() { return this; } - @Override + /** + * Get the key as a string. + * @return pfReferenceTimestamp key. + */ public String getId() { - return super.getId() + ':' + getTimeStamp().getTime(); + return getReferenceKey().getId() + ':' + getTimeStamp().getTime(); + } + + + /** + * Check if this key is a newer version than the other key. + * + * @param otherKey the key to check against + * @return true, if this key is newer than the other key + */ + @Override + public boolean isNewerThan(@NonNull PfKey otherKey) { + Assertions.instanceOf(otherKey, PfReferenceTimestampKey.class); + final PfReferenceTimestampKey otherReferenceKey = (PfReferenceTimestampKey) otherKey; + if (!getTimeStamp().equals(otherReferenceKey.timeStamp)) { + return timeStamp.after(otherReferenceKey.timeStamp); + } + return getReferenceKey().isNewerThan(otherReferenceKey.getReferenceKey()); } @Override public boolean isNullKey() { - return super.isNullKey() && getTimeStamp().getTime() == 0; + return getReferenceKey().isNullKey() && getTimeStamp().getTime() == 0; } @Override - public boolean isNewerThan(@NonNull PfKey otherKey) { - Assertions.instanceOf(otherKey, PfReferenceTimestampKey.class); - final PfReferenceTimestampKey otherConceptKey = (PfReferenceTimestampKey) otherKey; + public int getMajorVersion() { + return getReferenceKey().getMajorVersion(); + } - if (this.equals(otherConceptKey)) { - return false; + @Override + public int getMinorVersion() { + return getReferenceKey().getMinorVersion(); + } + + @Override + public int getPatchVersion() { + return getReferenceKey().getPatchVersion(); + } + + + @Override + public int compareTo(@NonNull final PfConcept otherObj) { + if (this == otherObj) { + return 0; + } + if (getClass() != otherObj.getClass()) { + return getClass().getName().compareTo(otherObj.getClass().getName()); } - if (!getTimeStamp().equals(otherConceptKey.timeStamp)) { - return timeStamp.after(otherConceptKey.timeStamp); + int result = getReferenceKey().compareTo(((PfReferenceTimestampKey) otherObj).getReferenceKey()); + if (0 == result) { + return getTimeStamp().compareTo(((PfReferenceTimestampKey) otherObj).timeStamp); } - return super.isNewerThan(otherKey); + return result; + } + + @Override + public List getKeys() { + return Collections.singletonList(getKey()); + } + + @Override + public void clean() { + getReferenceKey().clean(); + } + + @Override + public Compatibility getCompatibility(@NonNull PfKey otherKey) { + return getReferenceKey().getCompatibility(otherKey); + } + + @Override + public boolean isCompatible(@NonNull PfKey otherKey) { + if (!(otherKey instanceof PfReferenceTimestampKey)) { + return false; + } + final PfReferenceTimestampKey otherReferenceKey = (PfReferenceTimestampKey) otherKey; + + return this.getReferenceKey().getParentConceptKey().isCompatible(otherReferenceKey.getReferenceKey() + .getParentConceptKey()); } }