Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,12 @@
import java.util.Map;
import java.util.Objects;

import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.apache.commons.lang3.StringUtils;

@NoArgsConstructor
@Getter
@Setter
@EqualsAndHashCode(callSuper = true)
public class IdentifiableArtefactReferenceImpl
extends MaintainableArtefactReference
implements ArtefactReference {
Expand Down Expand Up @@ -76,6 +72,18 @@ public IdentifiableArtefactReferenceImpl(ArtefactReference from) {
this.itemId = Objects.requireNonNull(from.getItemId());
}

public void setItemId(String itemId) {
this.itemId = itemId;
invalidateHashCode();
}

@Override
protected int computeHashCode() {
int result = super.computeHashCode();
result = 31 * result + Objects.hashCode(itemId);
return result;
}

@Override
public boolean isItemReference() {
return StringUtils.isNotEmpty(itemId);
Expand All @@ -92,6 +100,7 @@ public StructureClass getMaintainableStructureClass() {
return parentType();
}

@Override
public String getUrn() {
final String urn = super.getUrn();
if (itemId != null) {
Expand All @@ -100,6 +109,7 @@ public String getUrn() {
return urn;
}

@Override
public ArtefactReference getMaintainableArtefactReference() {
return new MaintainableArtefactReference(
getId(),
Expand All @@ -121,7 +131,18 @@ public IdentifiableArtefactReferenceImpl clone() {

@Override
public String toString() {
String superString = super.toString();
return superString + "." + itemId;
return super.toString() + "." + itemId;
}

@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (!(o instanceof IdentifiableArtefactReferenceImpl that)) {
return false;
}
return super.equals(o)
&& Objects.equals(itemId, that.itemId);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,22 @@
import java.util.Optional;
import java.util.function.Function;

import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;
import org.apache.commons.lang3.StringUtils;

@Data
@Getter
@NoArgsConstructor
@EqualsAndHashCode(callSuper = false)
public class MaintainableArtefactReference implements ArtefactReference {

protected String id;
protected String organisationId;
protected StructureClass structureClass;
protected VersionReference version;

private transient int cachedHashCode;
private transient boolean hashCodeComputed;

public MaintainableArtefactReference(String id, String organisationId, VersionReference version, StructureClass structureClass) {
this.id = id;
this.organisationId = organisationId;
Expand Down Expand Up @@ -96,6 +97,65 @@ public boolean isItemReference() {

@Override
public String toString() {
return (structureClass != null ? structureClass.getSimpleName() : "null") + "=" + organisationId + ":" + id + "(" + getVersionString() + ")";
return (structureClass != null ? structureClass.getSimpleName() : "null")
+ "=" + organisationId + ":" + id + "(" + getVersionString() + ")";
}

public void setId(String id) {
this.id = id;
invalidateHashCode();
}

public void setOrganisationId(String organisationId) {
this.organisationId = organisationId;
invalidateHashCode();
}

public void setStructureClass(StructureClass structureClass) {
this.structureClass = structureClass;
invalidateHashCode();
}

public void setVersion(VersionReference version) {
this.version = version;
invalidateHashCode();
}

protected void invalidateHashCode() {
this.cachedHashCode = 0;
this.hashCodeComputed = false;
}

protected int computeHashCode() {
int result = Objects.hashCode(id);
result = 31 * result + Objects.hashCode(organisationId);
result = 31 * result + Objects.hashCode(structureClass);
result = 31 * result + Objects.hashCode(version);
return result;
}

@Override
public int hashCode() {
if (hashCodeComputed) {
return cachedHashCode;
}

cachedHashCode = computeHashCode();
hashCodeComputed = true;
return cachedHashCode;
}

@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (!(o instanceof MaintainableArtefactReference that)) {
return false;
}
return Objects.equals(id, that.id)
&& Objects.equals(organisationId, that.organisationId)
&& Objects.equals(structureClass, that.structureClass)
&& Objects.equals(version, that.version);
}
}
}
Loading