diff options
Diffstat (limited to 'document/src/main/java/com/yahoo')
9 files changed, 44 insertions, 55 deletions
diff --git a/document/src/main/java/com/yahoo/document/annotation/Annotation.java b/document/src/main/java/com/yahoo/document/annotation/Annotation.java index 3d9300550ff..237ca6db58b 100644 --- a/document/src/main/java/com/yahoo/document/annotation/Annotation.java +++ b/document/src/main/java/com/yahoo/document/annotation/Annotation.java @@ -129,7 +129,7 @@ public class Annotation implements Comparable<Annotation> { } /** - * WARNING! Should only be used by deserializers! Sets the span node that this annotation points to. + * WARNING! Should only be used by deserializers! Sets the span node that this annotation points to. * * @param spanNode the span node that this annotation shall point to. */ @@ -221,10 +221,9 @@ public class Annotation implements Comparable<Annotation> { @Override public String toString() { - String retval = "annotation of type " + type; - retval += ((value == null) ? " (no value)" : " (with value)"); - retval += ((spanNode == null) ? " (no span)" : (" with span "+spanNode)); - return retval; + return type + " annotation " + + ((value == null) ? " (no value)" : " (with value)") + + ((spanNode == null) ? " (no span)" : (" with span "+spanNode)); } diff --git a/document/src/main/java/com/yahoo/document/annotation/AnnotationContainer.java b/document/src/main/java/com/yahoo/document/annotation/AnnotationContainer.java index 6e2b986a478..ac2e6aefa1b 100644 --- a/document/src/main/java/com/yahoo/document/annotation/AnnotationContainer.java +++ b/document/src/main/java/com/yahoo/document/annotation/AnnotationContainer.java @@ -23,11 +23,7 @@ abstract class AnnotationContainer { */ abstract void annotate(Annotation annotation); - /** - * Returns a mutable collection of annotations. - * - * @return a mutable collection of annotations. - */ + /** Returns a mutable collection of the annotations in this. */ abstract Collection<Annotation> annotations(); /** diff --git a/document/src/main/java/com/yahoo/document/annotation/AnnotationType2AnnotationContainer.java b/document/src/main/java/com/yahoo/document/annotation/AnnotationType2AnnotationContainer.java index d8709baa3a1..01b8f990bb4 100644 --- a/document/src/main/java/com/yahoo/document/annotation/AnnotationType2AnnotationContainer.java +++ b/document/src/main/java/com/yahoo/document/annotation/AnnotationType2AnnotationContainer.java @@ -16,6 +16,7 @@ import java.util.NoSuchElementException; */ // TODO: Should this be removed? public class AnnotationType2AnnotationContainer extends IteratingAnnotationContainer { + private final Multimap<AnnotationType, Annotation> annotationType2Annotation = Multimaps.newMultimap(new IdentityHashMap<>(), ArrayList::new); @Override @@ -31,7 +32,6 @@ public class AnnotationType2AnnotationContainer extends IteratingAnnotationConta } @Override - @SuppressWarnings("unchecked") Collection<Annotation> annotations() { return annotationType2Annotation.values(); } @@ -56,12 +56,12 @@ public class AnnotationType2AnnotationContainer extends IteratingAnnotationConta } private class NonRecursiveIterator implements Iterator<Annotation> { + private final IdentityHashMap<SpanNode, SpanNode> nodes; private final Iterator<Annotation> annotationIt; private Annotation next = null; private boolean nextCalled; - @SuppressWarnings("unchecked") public NonRecursiveIterator(IdentityHashMap<SpanNode, SpanNode> nodes) { this.nodes = nodes; this.annotationIt = annotationType2Annotation.values().iterator(); @@ -106,4 +106,5 @@ public class AnnotationType2AnnotationContainer extends IteratingAnnotationConta nextCalled = false; } } + } diff --git a/document/src/main/java/com/yahoo/document/annotation/IteratingAnnotationContainer.java b/document/src/main/java/com/yahoo/document/annotation/IteratingAnnotationContainer.java index 54af80e6e43..c7c3545fc09 100644 --- a/document/src/main/java/com/yahoo/document/annotation/IteratingAnnotationContainer.java +++ b/document/src/main/java/com/yahoo/document/annotation/IteratingAnnotationContainer.java @@ -5,30 +5,29 @@ import java.util.IdentityHashMap; import java.util.Iterator; /** - * @author <a href="mailto:einarmr@yahoo-inc.com">Einar M R Rosenvinge</a> + * @author Einar M R Rosenvinge */ abstract class IteratingAnnotationContainer extends AnnotationContainer { @Override Iterator<Annotation> iterator(SpanNode node) { - IdentityHashMap<SpanNode, SpanNode> nodes = new IdentityHashMap<SpanNode, SpanNode>(); + IdentityHashMap<SpanNode, SpanNode> nodes = new IdentityHashMap<>(); nodes.put(node, node); return iterator(nodes); } @Override Iterator<Annotation> iteratorRecursive(SpanNode node) { - IdentityHashMap<SpanNode, SpanNode> nodes = new IdentityHashMap<SpanNode, SpanNode>(); + IdentityHashMap<SpanNode, SpanNode> nodes = new IdentityHashMap<>(); nodes.put(node, node); - { - Iterator<SpanNode> childrenIt = node.childIteratorRecursive(); - while (childrenIt.hasNext()) { - SpanNode child = childrenIt.next(); - nodes.put(child, child); - } + Iterator<SpanNode> childrenIt = node.childIteratorRecursive(); + while (childrenIt.hasNext()) { + SpanNode child = childrenIt.next(); + nodes.put(child, child); } return iterator(nodes); } abstract Iterator<Annotation> iterator(IdentityHashMap<SpanNode, SpanNode> nodes); + } diff --git a/document/src/main/java/com/yahoo/document/annotation/ListAnnotationContainer.java b/document/src/main/java/com/yahoo/document/annotation/ListAnnotationContainer.java index c2c22558a32..b8d8cd692d8 100644 --- a/document/src/main/java/com/yahoo/document/annotation/ListAnnotationContainer.java +++ b/document/src/main/java/com/yahoo/document/annotation/ListAnnotationContainer.java @@ -13,6 +13,7 @@ import java.util.NoSuchElementException; * @author Einar M R Rosenvinge */ public class ListAnnotationContainer extends IteratingAnnotationContainer { + private final List<Annotation> annotations = new LinkedList<>(); @Override @@ -38,9 +39,8 @@ public class ListAnnotationContainer extends IteratingAnnotationContainer { @Override public boolean equals(Object o) { if (this == o) return true; - if (!(o instanceof ListAnnotationContainer)) return false; - ListAnnotationContainer that = (ListAnnotationContainer) o; - if (!annotations.equals(that.annotations)) return false; + if (!(o instanceof ListAnnotationContainer other)) return false; + if (!annotations.equals(other.annotations)) return false; return true; } @@ -50,8 +50,9 @@ public class ListAnnotationContainer extends IteratingAnnotationContainer { } private class AnnotationIterator implements Iterator<Annotation> { - private IdentityHashMap<SpanNode, SpanNode> nodes; - private PeekableListIterator<Annotation> base; + + private final IdentityHashMap<SpanNode, SpanNode> nodes; + private final PeekableListIterator<Annotation> base; private boolean nextCalled = false; AnnotationIterator(ListIterator<Annotation> baseIt, IdentityHashMap<SpanNode, SpanNode> nodes) { @@ -91,4 +92,5 @@ public class ListAnnotationContainer extends IteratingAnnotationContainer { nextCalled = false; } } + } diff --git a/document/src/main/java/com/yahoo/document/annotation/SpanList.java b/document/src/main/java/com/yahoo/document/annotation/SpanList.java index 9530689c3f1..04bdf5c892e 100644 --- a/document/src/main/java/com/yahoo/document/annotation/SpanList.java +++ b/document/src/main/java/com/yahoo/document/annotation/SpanList.java @@ -11,13 +11,14 @@ import java.util.ListIterator; /** * A node in a Span tree that can have child nodes. * - * @author <a href="mailto:einarmr@yahoo-inc.com">Einar M R Rosenvinge</a> + * @author Einar M R Rosenvinge */ public class SpanList extends SpanNode { + public static final byte ID = 2; private final List<SpanNode> children; - private int cachedFrom = Integer.MIN_VALUE; //triggers calculateFrom() - private int cachedTo = Integer.MIN_VALUE; //triggers calculateTo() + private int cachedFrom = Integer.MIN_VALUE; // triggers calculateFrom() + private int cachedTo = Integer.MIN_VALUE; // triggers calculateTo() /** Creates a new SpanList. */ public SpanList() { @@ -39,7 +40,7 @@ public class SpanList extends SpanNode { * @param other the SpanList to copy. */ public SpanList(SpanList other) { - this.children = new LinkedList<SpanNode>(); + this.children = new LinkedList<>(); for (SpanNode otherNode : other.children) { if (otherNode instanceof Span) { children.add(new Span((Span) otherNode)); @@ -86,15 +87,15 @@ public class SpanList extends SpanNode { /** Create a span, add it to this list and return it */ public Span span(int from, int length) { - Span span=new Span(from,length); + Span span = new Span(from, length); add(span); return span; } void setInvalid() { - //invalidate ourselves: + // invalidate ourselves: super.setInvalid(); - //invalidate all our children: + // invalidate all our children: for (SpanNode node : children()) { node.setInvalid(); } @@ -213,20 +214,12 @@ public class SpanList extends SpanNode { return this; } - /** - * Returns a <strong>modifiable</strong> list of the immediate children of this SpanList. - * - * @return a <strong>modifiable</strong> list of the immediate children of this SpanList. - */ + /** Returns a modifiable list of the immediate children of this SpanList. */ protected List<SpanNode> children() { return children; } - /** - * Returns the number of children this SpanList holds. - * - * @return the number of children this SpanList holds. - */ + /** Returns the number of children this SpanList holds. */ public int numChildren() { return children().size(); } @@ -394,11 +387,9 @@ public class SpanList extends SpanNode { @Override public boolean equals(Object o) { if (this == o) return true; - if (!(o instanceof SpanList)) return false; + if (!(o instanceof SpanList spanList)) return false; if (!super.equals(o)) return false; - SpanList spanList = (SpanList) o; - if (children() != null ? !children().equals(spanList.children()) : spanList.children() != null) return false; return true; @@ -415,4 +406,5 @@ public class SpanList extends SpanNode { public String toString() { return "SpanList with " + children().size() + " children"; } + } diff --git a/document/src/main/java/com/yahoo/document/annotation/SpanNode2AnnotationContainer.java b/document/src/main/java/com/yahoo/document/annotation/SpanNode2AnnotationContainer.java index a66639b3bfd..f563fd0d6cd 100644 --- a/document/src/main/java/com/yahoo/document/annotation/SpanNode2AnnotationContainer.java +++ b/document/src/main/java/com/yahoo/document/annotation/SpanNode2AnnotationContainer.java @@ -18,6 +18,7 @@ import java.util.List; * @author Einar M R Rosenvinge */ class SpanNode2AnnotationContainer extends AnnotationContainer { + private final Multimap<SpanNode, Annotation> spanNode2Annotation = Multimaps.newMultimap(new IdentityHashMap<>(), ArrayList::new); @Override 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 f785cf3b3ec..2faf17ce428 100644 --- a/document/src/main/java/com/yahoo/document/annotation/SpanTree.java +++ b/document/src/main/java/com/yahoo/document/annotation/SpanTree.java @@ -19,6 +19,7 @@ import java.util.Iterator; import java.util.LinkedList; import java.util.List; import java.util.Map; +import java.util.stream.Collectors; /** * A SpanTree holds a root node of a tree of SpanNodes, and a List of Annotations pointing to these nodes @@ -431,7 +432,7 @@ public class SpanTree implements Iterable<Annotation>, SpanNodeParent, Comparabl } /** - * Adds an Annotation to the internal list of annotations for this SpanTree. Use this when + * Adds an Annotation to the internal list of annotations for this SpanTree. Use this when * adding an Annotation that shall annotate a SpanNode. Upon return, Annotation.getSpanNode() * returns the given node. * @@ -446,7 +447,7 @@ public class SpanTree implements Iterable<Annotation>, SpanNodeParent, Comparabl } /** - * Adds an Annotation to the internal list of annotations for this SpanTree. Use this when + * Adds an Annotation to the internal list of annotations for this SpanTree. Use this when * adding an Annotation that shall annotate a SpanNode. Upon return, Annotation.getSpanNode() * returns the given node. This one is unchecked and assumes that the SpanNode is valid and has * already been attached to the Annotation. @@ -538,10 +539,7 @@ 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. - */ + /** Returns an Iterator over all annotations in this tree. Note that the iteration order is non-deterministic. */ public Iterator<Annotation> iterator() { return annotations.annotations().iterator(); } @@ -641,7 +639,9 @@ public class SpanTree implements Iterable<Annotation>, SpanNodeParent, Comparabl @Override public String toString() { - return "SpanTree '" + name + "'"; + return "SpanTree '" + name + "' with root: " + root + + ( annotations.annotations().size() > 5 ? "" : + ", annotations: " + annotations.annotations().stream().map(Annotation::toString).collect(Collectors.joining(", "))); } @Override 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 0b1bbf5d3ca..bb54b41069b 100644 --- a/document/src/main/java/com/yahoo/document/datatypes/Struct.java +++ b/document/src/main/java/com/yahoo/document/datatypes/Struct.java @@ -218,8 +218,7 @@ public class Struct extends StructuredFieldValue { StringBuilder retVal = new StringBuilder(); retVal.append("Struct (").append(getDataType()).append("): "); int [] increasing = getInOrder(); - for (int i = 0; i < increasing.length; i++) { - int id = increasing[i]; + for (int id : increasing) { retVal.append(getDataType().getField(id)).append("=").append(values.get(id)).append(", "); } return retVal.toString(); |