diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2024-01-16 22:41:58 +0100 |
---|---|---|
committer | Henning Baldersheim <balder@yahoo-inc.com> | 2024-01-16 22:41:58 +0100 |
commit | 8315d2128bccfc2a5ff574afcc768d48e1b81c0e (patch) | |
tree | e14cfac37ff8f9f376476f3d38768e7410713dc7 /document | |
parent | b1c7443922468278a52a6ff3b45dc4f02104b49b (diff) |
Minor code health
Diffstat (limited to 'document')
3 files changed, 12 insertions, 20 deletions
diff --git a/document/src/main/java/com/yahoo/document/StructDataType.java b/document/src/main/java/com/yahoo/document/StructDataType.java index 5a236d0742d..4538e8e08a7 100644 --- a/document/src/main/java/com/yahoo/document/StructDataType.java +++ b/document/src/main/java/com/yahoo/document/StructDataType.java @@ -9,6 +9,7 @@ import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.List; +import java.util.Objects; /** * @author Einar M R Rosenvinge @@ -120,11 +121,8 @@ public class StructDataType extends BaseStructDataType { if (!(value instanceof Struct structValue)) { return false; } - if (structValue.getDataType().inherits(this)) { - //the value is of this type; or the supertype of the value is of this type, etc.... - return true; - } - return false; + //the value is of this type; or the supertype of the value is of this type, etc.... + return structValue.getDataType().inherits(this); } public void inherit(StructDataType type) { @@ -148,8 +146,7 @@ public class StructDataType extends BaseStructDataType { public boolean inherits(StructDataType type) { if (equals(type)) return true; - if (superType != null && superType.inherits(type)) return true; - return false; + return superType != null && superType.inherits(type); } @Override @@ -158,8 +155,7 @@ public class StructDataType extends BaseStructDataType { if (!(o instanceof StructDataType that)) return false; if (!super.equals(o)) return false; - if (superType != null ? !superType.equals(that.superType) : that.superType != null) return false; - return true; + return Objects.equals(superType, that.superType); } @Override diff --git a/document/src/main/java/com/yahoo/document/datatypes/MapFieldValue.java b/document/src/main/java/com/yahoo/document/datatypes/MapFieldValue.java index 0c6e765f2ad..a8dedd37df5 100644 --- a/document/src/main/java/com/yahoo/document/datatypes/MapFieldValue.java +++ b/document/src/main/java/com/yahoo/document/datatypes/MapFieldValue.java @@ -50,9 +50,8 @@ public class MapFieldValue<K extends FieldValue, V extends FieldValue> extends C return; } - if (o instanceof MapFieldValue) { + if (o instanceof MapFieldValue a) { if (o == this) return; - MapFieldValue a = (MapFieldValue) o; values.clear(); putAll(a); } else if (o instanceof Map) { @@ -80,8 +79,7 @@ public class MapFieldValue<K extends FieldValue, V extends FieldValue> extends C * @return true if o is an instance of WeightedSet and the two encapsulated Maps are equal, false otherwise */ public boolean equals(Object o) { - if (!(o instanceof MapFieldValue)) return false; - MapFieldValue m = (MapFieldValue) o; + if (!(o instanceof MapFieldValue m)) return false; if (size() != m.size()) return false; if ( ! super.equals(m)) return false; return entrySet().equals(m.entrySet()); @@ -313,9 +311,9 @@ public class MapFieldValue<K extends FieldValue, V extends FieldValue> extends C */ class MapWrapper implements Map<K,V> { - private Map<Object,Object> map; // Not field values, basic objects - private DataType keyTypeVespa = getDataType().getKeyType(); - private DataType valTypeVespa = getDataType().getValueType(); + private final Map<Object,Object> map; // Not field values, basic objects + private final DataType keyTypeVespa = getDataType().getKeyType(); + private final DataType valTypeVespa = getDataType().getValueType(); public MapWrapper(Map map) { this.map=map; } diff --git a/document/src/main/java/com/yahoo/document/datatypes/Struct.java b/document/src/main/java/com/yahoo/document/datatypes/Struct.java index badcf99b16a..f89a0946347 100644 --- a/document/src/main/java/com/yahoo/document/datatypes/Struct.java +++ b/document/src/main/java/com/yahoo/document/datatypes/Struct.java @@ -134,10 +134,8 @@ public class Struct extends StructuredFieldValue { throw new IllegalArgumentException("Incompatible data types. Got " + value.getDataType() + ", expected " + myField.getDataType()); } - if (myField.getId() - != field.getId()) { - throw new IllegalArgumentException( - "Inconsistent field: " + field); + if (myField.getId() != field.getId()) { + throw new IllegalArgumentException("Inconsistent field: " + field); } int index = values.getIndexOfKey(field.getId()); |