Skip to content

Commit

Permalink
issues/253 - Tidy up for code review.
Browse files Browse the repository at this point in the history
  • Loading branch information
meywood committed Mar 12, 2024
1 parent 4ab2696 commit ec9c16f
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 17 deletions.
22 changes: 18 additions & 4 deletions src/main/java/com/casper/sdk/model/clvalue/CLValueMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,14 @@ protected void setChildTypes(final Map<? extends AbstractCLValue<?, ?>, ? extend
}
}

// This needed to be customized to ensure equality is being checked correctly.
// The java Map equals method tries to get the "other" map entry's value by using "this" key object,
// which then fails to find the object since they are "different" and returns always null.
/**
* This needed to be customized to ensure equality is being checked correctly.
* The java Map equals method tries to get the "other" map entry's value by using "this" key object,
* which then fails to find the object since they are "different" and returns always null.
*
* @param o the object to compare
* @return true if the objects are equal, false otherwise
*/
@Override
public boolean equals(final Object o) {
if (o == this) return true;
Expand Down Expand Up @@ -175,6 +180,15 @@ public int hashCode() {

@Override
public String toString() {
return getValue() != null ? getValue().entrySet().stream().map(entry -> entry.getKey().toString() + "=" + entry.getValue().toString()).collect(Collectors.joining(", ")) : null;
if (getValue() == null) {
return null;
} else {
return getValue()
.entrySet()
.stream()
.map(entry ->
entry.getKey().toString() + "=" + entry.getValue().toString()).collect(Collectors.joining(", ")
);
}
}
}
13 changes: 3 additions & 10 deletions src/main/java/com/casper/sdk/model/clvalue/cltype/CLTypeList.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,8 @@ public void serializeChildTypes(final SerializerBuffer ser) throws NoSuchTypeExc
}

@Override
public void deserializeChildTypes(final DeserializerBuffer deser) throws ValueDeserializationException, NoSuchTypeException, DynamicInstanceException {
final int childTypeTag = deser.readU8();
final CLTypeData childType = CLTypeData.getTypeBySerializationTag((byte) childTypeTag);
final AbstractCLType clChildType = CLTypeData.createCLTypeFromCLTypeName(childType.getClTypeName());

if (clChildType instanceof AbstractCLTypeWithChildren) {
((AbstractCLTypeWithChildren) clChildType).deserializeChildTypes(deser);
}

setListType(clChildType);
public void deserializeChildTypes(final DeserializerBuffer deser)
throws ValueDeserializationException, NoSuchTypeException, DynamicInstanceException {
setListType(deserializeChildType(deser));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ protected List<Object> getChildTypeObjects() {
}

@Override
public void serializeChildTypes(SerializerBuffer ser) throws NoSuchTypeException {
public void serializeChildTypes(final SerializerBuffer ser) throws NoSuchTypeException {

if (getChildTypes().size() >= 2) {
getChildTypes().get(0).serialize(ser);
Expand All @@ -55,6 +55,4 @@ public void deserializeChildTypes(final DeserializerBuffer deser)
getChildTypes().add(deserializeChildType(deser));
getChildTypes().add(deserializeChildType(deser));
}


}

0 comments on commit ec9c16f

Please sign in to comment.