From ef5be496bc4857c5923f566251dd527873b248bf Mon Sep 17 00:00:00 2001 From: Harald Musum Date: Mon, 13 Nov 2023 21:34:45 +0100 Subject: Revert "Bratseth/casing take 2" --- .../com/yahoo/document/annotation/Annotation.java | 9 +++--- .../document/annotation/AnnotationContainer.java | 6 +++- .../AnnotationType2AnnotationContainer.java | 5 ++-- .../annotation/IteratingAnnotationContainer.java | 17 ++++++------ .../annotation/ListAnnotationContainer.java | 12 ++++---- .../com/yahoo/document/annotation/SpanList.java | 32 ++++++++++++++-------- .../annotation/SpanNode2AnnotationContainer.java | 1 - .../com/yahoo/document/annotation/SpanTree.java | 14 +++++----- .../java/com/yahoo/document/datatypes/Struct.java | 3 +- 9 files changed, 55 insertions(+), 44 deletions(-) (limited to 'document') 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 237ca6db58b..3d9300550ff 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 { } /** - * 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,9 +221,10 @@ public class Annotation implements Comparable { @Override public String toString() { - return type + " annotation " + - ((value == null) ? " (no value)" : " (with value)") + - ((spanNode == null) ? " (no span)" : (" with span "+spanNode)); + String retval = "annotation of type " + type; + retval += ((value == null) ? " (no value)" : " (with value)"); + retval += ((spanNode == null) ? " (no span)" : (" with span "+spanNode)); + return retval; } 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 ac2e6aefa1b..6e2b986a478 100644 --- a/document/src/main/java/com/yahoo/document/annotation/AnnotationContainer.java +++ b/document/src/main/java/com/yahoo/document/annotation/AnnotationContainer.java @@ -23,7 +23,11 @@ abstract class AnnotationContainer { */ abstract void annotate(Annotation annotation); - /** Returns a mutable collection of the annotations in this. */ + /** + * Returns a mutable collection of annotations. + * + * @return a mutable collection of annotations. + */ abstract Collection 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 01b8f990bb4..d8709baa3a1 100644 --- a/document/src/main/java/com/yahoo/document/annotation/AnnotationType2AnnotationContainer.java +++ b/document/src/main/java/com/yahoo/document/annotation/AnnotationType2AnnotationContainer.java @@ -16,7 +16,6 @@ import java.util.NoSuchElementException; */ // TODO: Should this be removed? public class AnnotationType2AnnotationContainer extends IteratingAnnotationContainer { - private final Multimap annotationType2Annotation = Multimaps.newMultimap(new IdentityHashMap<>(), ArrayList::new); @Override @@ -32,6 +31,7 @@ public class AnnotationType2AnnotationContainer extends IteratingAnnotationConta } @Override + @SuppressWarnings("unchecked") Collection annotations() { return annotationType2Annotation.values(); } @@ -56,12 +56,12 @@ public class AnnotationType2AnnotationContainer extends IteratingAnnotationConta } private class NonRecursiveIterator implements Iterator { - private final IdentityHashMap nodes; private final Iterator annotationIt; private Annotation next = null; private boolean nextCalled; + @SuppressWarnings("unchecked") public NonRecursiveIterator(IdentityHashMap nodes) { this.nodes = nodes; this.annotationIt = annotationType2Annotation.values().iterator(); @@ -106,5 +106,4 @@ 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 c7c3545fc09..54af80e6e43 100644 --- a/document/src/main/java/com/yahoo/document/annotation/IteratingAnnotationContainer.java +++ b/document/src/main/java/com/yahoo/document/annotation/IteratingAnnotationContainer.java @@ -5,29 +5,30 @@ import java.util.IdentityHashMap; import java.util.Iterator; /** - * @author Einar M R Rosenvinge + * @author Einar M R Rosenvinge */ abstract class IteratingAnnotationContainer extends AnnotationContainer { @Override Iterator iterator(SpanNode node) { - IdentityHashMap nodes = new IdentityHashMap<>(); + IdentityHashMap nodes = new IdentityHashMap(); nodes.put(node, node); return iterator(nodes); } @Override Iterator iteratorRecursive(SpanNode node) { - IdentityHashMap nodes = new IdentityHashMap<>(); + IdentityHashMap nodes = new IdentityHashMap(); nodes.put(node, node); - Iterator childrenIt = node.childIteratorRecursive(); - while (childrenIt.hasNext()) { - SpanNode child = childrenIt.next(); - nodes.put(child, child); + { + Iterator childrenIt = node.childIteratorRecursive(); + while (childrenIt.hasNext()) { + SpanNode child = childrenIt.next(); + nodes.put(child, child); + } } return iterator(nodes); } abstract Iterator iterator(IdentityHashMap 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 b8d8cd692d8..c2c22558a32 100644 --- a/document/src/main/java/com/yahoo/document/annotation/ListAnnotationContainer.java +++ b/document/src/main/java/com/yahoo/document/annotation/ListAnnotationContainer.java @@ -13,7 +13,6 @@ import java.util.NoSuchElementException; * @author Einar M R Rosenvinge */ public class ListAnnotationContainer extends IteratingAnnotationContainer { - private final List annotations = new LinkedList<>(); @Override @@ -39,8 +38,9 @@ public class ListAnnotationContainer extends IteratingAnnotationContainer { @Override public boolean equals(Object o) { if (this == o) return true; - if (!(o instanceof ListAnnotationContainer other)) return false; - if (!annotations.equals(other.annotations)) return false; + if (!(o instanceof ListAnnotationContainer)) return false; + ListAnnotationContainer that = (ListAnnotationContainer) o; + if (!annotations.equals(that.annotations)) return false; return true; } @@ -50,9 +50,8 @@ public class ListAnnotationContainer extends IteratingAnnotationContainer { } private class AnnotationIterator implements Iterator { - - private final IdentityHashMap nodes; - private final PeekableListIterator base; + private IdentityHashMap nodes; + private PeekableListIterator base; private boolean nextCalled = false; AnnotationIterator(ListIterator baseIt, IdentityHashMap nodes) { @@ -92,5 +91,4 @@ 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 04bdf5c892e..9530689c3f1 100644 --- a/document/src/main/java/com/yahoo/document/annotation/SpanList.java +++ b/document/src/main/java/com/yahoo/document/annotation/SpanList.java @@ -11,14 +11,13 @@ import java.util.ListIterator; /** * A node in a Span tree that can have child nodes. * - * @author Einar M R Rosenvinge + * @author Einar M R Rosenvinge */ public class SpanList extends SpanNode { - public static final byte ID = 2; private final List 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() { @@ -40,7 +39,7 @@ public class SpanList extends SpanNode { * @param other the SpanList to copy. */ public SpanList(SpanList other) { - this.children = new LinkedList<>(); + this.children = new LinkedList(); for (SpanNode otherNode : other.children) { if (otherNode instanceof Span) { children.add(new Span((Span) otherNode)); @@ -87,15 +86,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(); } @@ -214,12 +213,20 @@ public class SpanList extends SpanNode { return this; } - /** Returns a modifiable list of the immediate children of this SpanList. */ + /** + * Returns a modifiable list of the immediate children of this SpanList. + * + * @return a modifiable list of the immediate children of this SpanList. + */ protected List children() { return children; } - /** Returns the number of children this SpanList holds. */ + /** + * Returns the number of children this SpanList holds. + * + * @return the number of children this SpanList holds. + */ public int numChildren() { return children().size(); } @@ -387,9 +394,11 @@ public class SpanList extends SpanNode { @Override public boolean equals(Object o) { if (this == o) return true; - if (!(o instanceof SpanList spanList)) return false; + if (!(o instanceof 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; @@ -406,5 +415,4 @@ 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 f563fd0d6cd..a66639b3bfd 100644 --- a/document/src/main/java/com/yahoo/document/annotation/SpanNode2AnnotationContainer.java +++ b/document/src/main/java/com/yahoo/document/annotation/SpanNode2AnnotationContainer.java @@ -18,7 +18,6 @@ import java.util.List; * @author Einar M R Rosenvinge */ class SpanNode2AnnotationContainer extends AnnotationContainer { - private final Multimap 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 2faf17ce428..f785cf3b3ec 100644 --- a/document/src/main/java/com/yahoo/document/annotation/SpanTree.java +++ b/document/src/main/java/com/yahoo/document/annotation/SpanTree.java @@ -19,7 +19,6 @@ 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 @@ -432,7 +431,7 @@ public class SpanTree implements Iterable, 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. * @@ -447,7 +446,7 @@ public class SpanTree implements Iterable, 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. @@ -539,7 +538,10 @@ public class SpanTree implements Iterable, SpanNodeParent, Comparabl } } - /** Returns an Iterator over all annotations in this tree. Note that the iteration order is non-deterministic. */ + /** + * 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. + */ public Iterator iterator() { return annotations.annotations().iterator(); } @@ -639,9 +641,7 @@ public class SpanTree implements Iterable, SpanNodeParent, Comparabl @Override public String toString() { - return "SpanTree '" + name + "' with root: " + root + - ( annotations.annotations().size() > 5 ? "" : - ", annotations: " + annotations.annotations().stream().map(Annotation::toString).collect(Collectors.joining(", "))); + return "SpanTree '" + name + "'"; } @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 bb54b41069b..0b1bbf5d3ca 100644 --- a/document/src/main/java/com/yahoo/document/datatypes/Struct.java +++ b/document/src/main/java/com/yahoo/document/datatypes/Struct.java @@ -218,7 +218,8 @@ public class Struct extends StructuredFieldValue { StringBuilder retVal = new StringBuilder(); retVal.append("Struct (").append(getDataType()).append("): "); int [] increasing = getInOrder(); - for (int id : increasing) { + for (int i = 0; i < increasing.length; i++) { + int id = increasing[i]; retVal.append(getDataType().getField(id)).append("=").append(values.get(id)).append(", "); } return retVal.toString(); -- cgit v1.2.3