diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2022-11-30 10:04:50 +0100 |
---|---|---|
committer | Henning Baldersheim <balder@yahoo-inc.com> | 2022-11-30 10:04:50 +0100 |
commit | 448231f18ba53edf5c0e7ab4b6732ef69328281c (patch) | |
tree | 289f528fd6adac2a39e636c449c633c26fdb838e /document | |
parent | 711362f17d4bbece0dc2d0833a22063374ae3e04 (diff) |
Reduce the simple usage of guava where java has caught up
Diffstat (limited to 'document')
6 files changed, 25 insertions, 85 deletions
diff --git a/document/src/main/java/com/yahoo/document/DocumentType.java b/document/src/main/java/com/yahoo/document/DocumentType.java index 0f771e4d55a..bec08837a84 100644 --- a/document/src/main/java/com/yahoo/document/DocumentType.java +++ b/document/src/main/java/com/yahoo/document/DocumentType.java @@ -1,7 +1,6 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.document; -import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSet; import com.yahoo.document.datatypes.FieldValue; import com.yahoo.document.fieldset.AllFields; @@ -38,9 +37,9 @@ public class DocumentType extends StructuredDataType { public static final int classId = registerClass(Ids.document + 58, DocumentType.class); private StructDataType contentStructType; private List<DocumentType> inherits = new ArrayList<>(1); - private Map<String, Set<Field>> fieldSets = new HashMap<>(); + private final Map<String, Set<Field>> fieldSets = new HashMap<>(); private final Set<String> importedFieldNames; - private Map<String, StructDataType> declaredStructTypes = new HashMap<>(); + private final Map<String, StructDataType> declaredStructTypes = new HashMap<>(); /** * Creates a new document type and registers it with the document type manager. @@ -101,10 +100,9 @@ public class DocumentType extends StructuredDataType { @Override public boolean isValueCompatible(FieldValue value) { - if (!(value instanceof Document)) { + if (!(value instanceof Document doc)) { return false; } - Document doc = (Document) value; if (doc.getDataType().inherits(this)) { //the value is of this type; or the supertype of the value is of this type, etc.... return true; @@ -330,7 +328,7 @@ public class DocumentType extends StructuredDataType { for (DocumentType type : inherits) { names.add(type.getDataTypeName()); } - return ImmutableList.copyOf(names).listIterator(); + return List.copyOf(names).listIterator(); } /** @@ -433,7 +431,7 @@ public class DocumentType extends StructuredDataType { } collection.addAll(contentStructType.getFields()); - return ImmutableList.copyOf(collection); + return List.copyOf(collection); } private Set<Field> getAllUniqueFields() { @@ -486,8 +484,7 @@ public class DocumentType extends StructuredDataType { } public boolean equals(Object o) { - if (!(o instanceof DocumentType)) return false; - DocumentType other = (DocumentType) o; + if (!(o instanceof DocumentType other)) return false; // Ignore whether one of them have added inheritance to super Document.0 type if (super.equals(o) && contentStructType.equals(other.contentStructType)) { if ((inherits.size() > 1 || other.inherits.size() > 1) || diff --git a/document/src/main/java/com/yahoo/document/StructDataType.java b/document/src/main/java/com/yahoo/document/StructDataType.java index 34967cf6f51..2af34711851 100644 --- a/document/src/main/java/com/yahoo/document/StructDataType.java +++ b/document/src/main/java/com/yahoo/document/StructDataType.java @@ -1,7 +1,6 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.document; -import com.google.common.collect.ImmutableList; import com.yahoo.document.datatypes.FieldValue; import com.yahoo.document.datatypes.Struct; import com.yahoo.vespa.objects.Ids; @@ -9,6 +8,7 @@ import com.yahoo.vespa.objects.Ids; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; +import java.util.List; /** * @author Einar M R Rosenvinge @@ -98,7 +98,7 @@ public class StructDataType extends BaseStructDataType { Collection<Field> fieldsBuilder = new ArrayList<>(); fieldsBuilder.addAll(super.getFields()); fieldsBuilder.addAll(superType.getFields()); - return ImmutableList.copyOf(fieldsBuilder); + return List.copyOf(fieldsBuilder); } public Collection<Field> getFieldsThisTypeOnly() { @@ -117,10 +117,9 @@ public class StructDataType extends BaseStructDataType { @Override public boolean isValueCompatible(FieldValue value) { - if (!(value instanceof Struct)) { + if (!(value instanceof Struct structValue)) { return false; } - Struct structValue = (Struct) value; if (structValue.getDataType().inherits(this)) { //the value is of this type; or the supertype of the value is of this type, etc.... return true; @@ -142,9 +141,9 @@ public class StructDataType extends BaseStructDataType { public Collection<StructDataType> getInheritedTypes() { if (superType == null) { - return ImmutableList.of(); + return List.of(); } - return ImmutableList.of(superType); + return List.of(superType); } public boolean inherits(StructDataType type) { @@ -156,10 +155,9 @@ public class StructDataType extends BaseStructDataType { @Override public boolean equals(Object o) { if (this == o) return true; - if (!(o instanceof StructDataType)) return false; + if (!(o instanceof StructDataType that)) return false; if (!super.equals(o)) return false; - StructDataType that = (StructDataType) o; if (superType != null ? !superType.equals(that.superType) : that.superType != null) return false; return true; } diff --git a/document/src/main/java/com/yahoo/document/annotation/AnnotationType.java b/document/src/main/java/com/yahoo/document/annotation/AnnotationType.java index 4acc9c00384..88e6bd7822a 100644 --- a/document/src/main/java/com/yahoo/document/annotation/AnnotationType.java +++ b/document/src/main/java/com/yahoo/document/annotation/AnnotationType.java @@ -1,12 +1,11 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.document.annotation; -import com.google.common.collect.ImmutableList; import com.yahoo.collections.MD5; import com.yahoo.document.DataType; import java.util.Collection; -import java.util.Collections; +import java.util.List; /** * An AnnotationType describes a certain type of annotations; they are @@ -124,9 +123,9 @@ public class AnnotationType implements Comparable<AnnotationType> { public Collection<AnnotationType> getInheritedTypes() { if (superType == null) { - return ImmutableList.of(); + return List.of(); } - return ImmutableList.of(superType); + return List.of(superType); } public boolean inherits(AnnotationType type) { @@ -138,9 +137,7 @@ public class AnnotationType implements Comparable<AnnotationType> { @Override public boolean equals(Object o) { if (this == o) return true; - if (!(o instanceof AnnotationType)) return false; - - AnnotationType that = (AnnotationType) o; + if (!(o instanceof AnnotationType that)) return false; return name.equals(that.name); } diff --git a/document/src/main/java/com/yahoo/document/annotation/SpanTree.java b/document/src/main/java/com/yahoo/document/annotation/SpanTree.java index b03f587d839..d63616130e2 100644 --- a/document/src/main/java/com/yahoo/document/annotation/SpanTree.java +++ b/document/src/main/java/com/yahoo/document/annotation/SpanTree.java @@ -1,7 +1,6 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.document.annotation; -import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMultiset; import com.yahoo.document.CollectionDataType; import com.yahoo.document.Field; @@ -63,7 +62,6 @@ public class SpanTree implements Iterable<Annotation>, SpanNodeParent, Comparabl setRoot(new SpanList()); } - @SuppressWarnings("unchecked") public SpanTree(SpanTree otherToCopy) { name = otherToCopy.name; setRoot(copySpan(otherToCopy.root)); @@ -250,7 +248,6 @@ public class SpanTree implements Iterable<Annotation>, SpanNodeParent, Comparabl * total number of Annotations, and m is the number of SpanNodes that had been removed from the tree. * The lower bound is Omega(n), if no SpanNodes had been removed from the tree. */ - @SuppressWarnings("unchecked") public void cleanup() { Map<Annotation, Annotation> removedAnnotations = removeAnnotationsThatPointToInvalidSpanNodes(); @@ -269,9 +266,8 @@ public class SpanTree implements Iterable<Annotation>, SpanNodeParent, Comparabl } FieldValue value = a.getFieldValue(); - if (value instanceof AnnotationReference) { + if (value instanceof AnnotationReference ref) { //the annotation "a" has a reference - AnnotationReference ref = (AnnotationReference) value; if (removedAnnotations.get(ref.getReference()) != null) { //this reference refers to a dead annotation ref.setReference(null); @@ -367,7 +363,6 @@ public class SpanTree implements Iterable<Annotation>, SpanNodeParent, Comparabl return false; } - @SuppressWarnings("unchecked") private Map<Annotation, Annotation> removeAnnotationsThatPointToInvalidSpanNodes() { Map<Annotation, Annotation> removedAnnotations = new IdentityHashMap<Annotation, Annotation>(); @@ -412,7 +407,6 @@ public class SpanTree implements Iterable<Annotation>, SpanNodeParent, Comparabl annotations.annotate(annotation); } - @SuppressWarnings("unchecked") private Collection<Annotation> getAnnotations() { return annotations.annotations(); } @@ -548,7 +542,6 @@ public class SpanTree implements Iterable<Annotation>, SpanNodeParent, Comparabl * Returns an Iterator over all annotations in this tree. Note that the iteration order is non-deterministic. * @return an Iterator over all annotations in this tree. */ - @SuppressWarnings("unchecked") public Iterator<Annotation> iterator() { return annotations.annotations().iterator(); } @@ -559,7 +552,6 @@ public class SpanTree implements Iterable<Annotation>, SpanNodeParent, Comparabl * @param node the node to return annotations for. * @return an Iterator over all annotations that annotate the given node. */ - @SuppressWarnings("unchecked") public Iterator<Annotation> iterator(SpanNode node) { return annotations.iterator(node); } @@ -570,7 +562,6 @@ public class SpanTree implements Iterable<Annotation>, SpanNodeParent, Comparabl * @param node the node to recursively return annotations for. * @return a recursive Iterator over all annotations that annotate the given node and its subnodes. */ - @SuppressWarnings("unchecked") public Iterator<Annotation> iteratorRecursive(SpanNode node) { return annotations.iteratorRecursive(node); } @@ -642,10 +633,10 @@ public class SpanTree implements Iterable<Annotation>, SpanNodeParent, Comparabl public Collection<IndexKey> getCurrentIndexes() { if (annotations instanceof AnnotationType2AnnotationContainer) - return ImmutableList.of(IndexKey.ANNOTATION_TYPE); + return List.of(IndexKey.ANNOTATION_TYPE); if (annotations instanceof SpanNode2AnnotationContainer) - return ImmutableList.of(IndexKey.SPAN_NODE); - return ImmutableList.of(); + return List.of(IndexKey.SPAN_NODE); + return List.of(); } @Override @@ -656,9 +647,8 @@ public class SpanTree implements Iterable<Annotation>, SpanNodeParent, Comparabl @Override public boolean equals(Object o) { if (this == o) return true; - if (!(o instanceof SpanTree)) return false; + if (!(o instanceof SpanTree tree)) return false; - SpanTree tree = (SpanTree) o; if (!annotationsEquals(tree)) return false; if (!name.equals(tree.name)) return false; if (!root.equals(tree.root)) return false; @@ -666,7 +656,6 @@ public class SpanTree implements Iterable<Annotation>, SpanNodeParent, Comparabl return true; } - @SuppressWarnings("unchecked") private boolean annotationsEquals(SpanTree tree) { List<Annotation> annotationCollection = new LinkedList<Annotation>(getAnnotations()); List<Annotation> otherAnnotations = new LinkedList<Annotation>(tree.getAnnotations()); diff --git a/document/src/main/java/com/yahoo/document/datatypes/StringFieldValue.java b/document/src/main/java/com/yahoo/document/datatypes/StringFieldValue.java index 51b068b4712..6133c9ca0ad 100644 --- a/document/src/main/java/com/yahoo/document/datatypes/StringFieldValue.java +++ b/document/src/main/java/com/yahoo/document/datatypes/StringFieldValue.java @@ -1,7 +1,6 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.document.datatypes; -import com.google.common.collect.ImmutableList; import com.yahoo.collections.CollectionComparator; import com.yahoo.document.DataType; import com.yahoo.document.Field; @@ -16,6 +15,7 @@ import com.yahoo.vespa.objects.Ids; import java.util.Collection; import java.util.HashMap; +import java.util.List; import java.util.Map; import java.util.Objects; @@ -142,9 +142,9 @@ public class StringFieldValue extends FieldValue { */ public Collection<SpanTree> getSpanTrees() { if (spanTrees == null) { - return ImmutableList.of(); + return List.of(); } - return ImmutableList.copyOf(spanTrees.values()); + return List.copyOf(spanTrees.values()); } /** Returns the map of spantrees. Might be null. */ @@ -236,9 +236,8 @@ public class StringFieldValue extends FieldValue { @Override public boolean equals(Object o) { if (this == o) return true; - if (!(o instanceof StringFieldValue)) return false; + if (!(o instanceof StringFieldValue that)) return false; if (!super.equals(o)) return false; - StringFieldValue that = (StringFieldValue) o; if (!Objects.equals(spanTrees, that.spanTrees)) return false; if (!Objects.equals(value, that.value)) return false; return true; diff --git a/document/src/main/java/com/yahoo/document/json/TokenBuffer.java b/document/src/main/java/com/yahoo/document/json/TokenBuffer.java index e6d2021f90b..58ceeec4f4c 100644 --- a/document/src/main/java/com/yahoo/document/json/TokenBuffer.java +++ b/document/src/main/java/com/yahoo/document/json/TokenBuffer.java @@ -89,10 +89,6 @@ public class TokenBuffer { bufferJsonStruct(first, tokens, JsonToken.START_OBJECT); } - public void bufferArray(JsonToken first, JsonParser tokens) { - bufferJsonStruct(first, tokens, JsonToken.START_ARRAY); - } - private void bufferJsonStruct(JsonToken first, JsonParser tokens, JsonToken firstToken) { int localNesting = 0; JsonToken t = first; @@ -150,42 +146,6 @@ public class TokenBuffer { return nesting; } - public String dumpContents() { - StringBuilder b = new StringBuilder(); - b.append("[nesting: ").append(nesting()).append("\n"); - for (Token t : buffer) { - b.append("(").append(t.token).append(", \"").append(t.name).append("\", \"").append(t.text).append("\")\n"); - } - b.append("]\n"); - return b.toString(); - } - - public void fastForwardToEndObject() { - JsonToken t = currentToken(); - while (t != JsonToken.END_OBJECT) { - t = next(); - } - } - - public TokenBuffer prefetchCurrentElement() { - Deque<Token> copy = new ArrayDeque<>(); - - if (currentToken().isScalarValue()) { - copy.add(buffer.peekFirst()); - } else { - int localNesting = nesting(); - int nestingBarrier = localNesting; - for (Token t : buffer) { - copy.add(t); - localNesting += nestingOffset(t.token); - if (localNesting < nestingBarrier) { - break; - } - } - } - return new TokenBuffer(copy); - } - public Token prefetchScalar(String name) { int localNesting = nesting(); int nestingBarrier = localNesting; |