From e5852de9c3fcfd5714aa20512014e1524338c844 Mon Sep 17 00:00:00 2001 From: Jon Bratseth Date: Sun, 21 Feb 2021 14:41:50 +0100 Subject: Non-functional changes only --- .../com/yahoo/document/CollectionDataType.java | 7 ++--- .../java/com/yahoo/document/DocumentTypeId.java | 9 +++++-- .../main/java/com/yahoo/document/Generated.java | 2 +- .../document/TemporaryStructuredDataType.java | 3 ++- .../document/annotation/AlternateSpanList.java | 16 +++++------ .../com/yahoo/document/annotation/Annotation.java | 31 +++++++++++----------- .../document/annotation/AnnotationContainer.java | 4 +-- .../document/annotation/AnnotationReference.java | 5 ++-- .../annotation/AnnotationReferenceDataType.java | 12 +++++---- .../yahoo/document/annotation/AnnotationType.java | 31 ++++++++-------------- 10 files changed, 61 insertions(+), 59 deletions(-) (limited to 'document/src/main') diff --git a/document/src/main/java/com/yahoo/document/CollectionDataType.java b/document/src/main/java/com/yahoo/document/CollectionDataType.java index c6420b5e71f..9088f48d827 100644 --- a/document/src/main/java/com/yahoo/document/CollectionDataType.java +++ b/document/src/main/java/com/yahoo/document/CollectionDataType.java @@ -9,9 +9,10 @@ import com.yahoo.vespa.objects.ObjectVisitor; import java.util.List; /** - * @author Einar M R Rosenvinge + * @author Einar M R Rosenvinge */ public abstract class CollectionDataType extends DataType { + // The global class identifier shared with C++. public static int classId = registerClass(Ids.document + 53, CollectionDataType.class); @@ -23,7 +24,7 @@ public abstract class CollectionDataType extends DataType { } @Override - public abstract CollectionFieldValue createFieldValue(); + public abstract CollectionFieldValue createFieldValue(); @Override public CollectionDataType clone() { @@ -56,7 +57,7 @@ public abstract class CollectionDataType extends DataType { if (!(value instanceof CollectionFieldValue)) { return false; } - CollectionFieldValue cfv = (CollectionFieldValue) value; + CollectionFieldValue cfv = (CollectionFieldValue) value; return equals(cfv.getDataType()); } diff --git a/document/src/main/java/com/yahoo/document/DocumentTypeId.java b/document/src/main/java/com/yahoo/document/DocumentTypeId.java index d7ecfb11c31..0b90493f4cd 100644 --- a/document/src/main/java/com/yahoo/document/DocumentTypeId.java +++ b/document/src/main/java/com/yahoo/document/DocumentTypeId.java @@ -4,10 +4,11 @@ package com.yahoo.document; /** * The id of a document type. * - * @author Einar M R Rosenvinge + * @author Einar M R Rosenvinge */ public class DocumentTypeId { - private int id; + + private final int id; public DocumentTypeId(int id) { this.id = id; @@ -17,17 +18,21 @@ public class DocumentTypeId { return id; } + @Override public boolean equals(Object o) { if (!(o instanceof DocumentTypeId)) return false; DocumentTypeId other = (DocumentTypeId) o; return other.id == this.id; } + @Override public int hashCode() { return id; } + @Override public String toString() { return "" + id; } + } diff --git a/document/src/main/java/com/yahoo/document/Generated.java b/document/src/main/java/com/yahoo/document/Generated.java index 6c02bc7ee0a..b58471617fb 100644 --- a/document/src/main/java/com/yahoo/document/Generated.java +++ b/document/src/main/java/com/yahoo/document/Generated.java @@ -9,7 +9,7 @@ import java.lang.annotation.RetentionPolicy; * differs from javax.annotation.Generated in that the retention * policy is Runtime. * - * @author Vegard Havdal + * @author Vegard Havdal */ @Retention(RetentionPolicy.RUNTIME) public @interface Generated { diff --git a/document/src/main/java/com/yahoo/document/TemporaryStructuredDataType.java b/document/src/main/java/com/yahoo/document/TemporaryStructuredDataType.java index 1f99cc7bf0e..0449612da6f 100644 --- a/document/src/main/java/com/yahoo/document/TemporaryStructuredDataType.java +++ b/document/src/main/java/com/yahoo/document/TemporaryStructuredDataType.java @@ -4,7 +4,7 @@ package com.yahoo.document; /** * Internal class, DO NOT USE!! Only public because it must be used from com.yahoo.searchdefinition.parser. * - * @author Einar M R Rosenvinge + * @author Einar M R Rosenvinge */ public class TemporaryStructuredDataType extends StructDataType { @@ -29,4 +29,5 @@ public class TemporaryStructuredDataType extends StructDataType { super.setName(name); setId(createId(getName())); } + } diff --git a/document/src/main/java/com/yahoo/document/annotation/AlternateSpanList.java b/document/src/main/java/com/yahoo/document/annotation/AlternateSpanList.java index bfac5c2c620..54511d6d0b9 100644 --- a/document/src/main/java/com/yahoo/document/annotation/AlternateSpanList.java +++ b/document/src/main/java/com/yahoo/document/annotation/AlternateSpanList.java @@ -14,12 +14,14 @@ import java.util.ListIterator; * A node in a {@link SpanNode} tree that can have a multiple trees of child nodes, each with its own probability. * This class has quite a few convenience methods for accessing the first subtree. * - * @author Einar M R Rosenvinge + * @author Einar M R Rosenvinge * @see com.yahoo.document.annotation.SpanList */ public class AlternateSpanList extends SpanList { + public static final byte ID = 4; - private final List childTrees = new LinkedList(); + + private final List childTrees = new LinkedList<>(); private static final Comparator childComparator = new ProbabilityComparator(); /** Create a new AlternateSpanList instance, having a single subtree with probability 1.0. */ @@ -28,7 +30,7 @@ public class AlternateSpanList extends SpanList { ensureAtLeastOneSubTree(); } - /* + /** * Deep-copies another AlternateSpanList. * * @param otherSpanList the instance to deep-copy. @@ -267,7 +269,6 @@ public class AlternateSpanList extends SpanList { } } - /** * Traverses all immediate children of all subtrees of this AlternateSpanList. * The ListIterator only supports iteration forwards, and the optional operations that are implemented are @@ -334,7 +335,6 @@ public class AlternateSpanList extends SpanList { return children(i).size(); } - /** * Returns a modifiable {@link List} of child nodes of the specified subtree. * @@ -345,7 +345,6 @@ public class AlternateSpanList extends SpanList { return childTrees.get(i).children(); } - @Override void setParent(SpanNodeParent parent) { super.setParent(parent); @@ -436,7 +435,6 @@ public class AlternateSpanList extends SpanList { } } - /** * Sets the subtree at index i. * @@ -597,7 +595,6 @@ public class AlternateSpanList extends SpanList { return "AlternateSpanList, num subtrees=" + getNumSubTrees(); } - private static class ProbabilityComparator implements Comparator { @Override public int compare(Children o1, Children o2) { @@ -606,6 +603,7 @@ public class AlternateSpanList extends SpanList { } private class Children extends SpanList { + private double probability = 1.0; private Children(SpanNodeParent parent) { @@ -630,5 +628,7 @@ public class AlternateSpanList extends SpanList { public void setProbability(double probability) { this.probability = probability; } + } + } 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 4b9452f3400..1aaaa8e1d16 100644 --- a/document/src/main/java/com/yahoo/document/annotation/Annotation.java +++ b/document/src/main/java/com/yahoo/document/annotation/Annotation.java @@ -5,21 +5,21 @@ import com.yahoo.document.DataType; import com.yahoo.document.datatypes.FieldValue; /** - * An Annotation describes some kind of information associated with - * a {@link SpanNode}. + * An Annotation describes some kind of information associated with a {@link SpanNode}. * - * @author Einar M R Rosenvinge * @see com.yahoo.document.annotation.SpanNode * @see com.yahoo.document.annotation.AnnotationType + * @author Einar M R Rosenvinge */ public class Annotation implements Comparable { + private AnnotationType type; private SpanNode spanNode = null; private FieldValue value = null; - /** - * This scratch id is used to avoid using IdentityHashMaps as they are very costly. - */ + + /** This scratch id is used to avoid using IdentityHashMaps as they are very costly. */ private int scratchId = -1; + public void setScratchId(int id) { scratchId = id; } @@ -30,7 +30,7 @@ public class Annotation implements Comparable { /** - * Constructs an Annotation without a type. BEWARE! Should only be used during deserialization. + * Constructs an Annotation without a type. BEWARE! Should only be used during deserialization. */ public Annotation() { } @@ -77,7 +77,7 @@ public class Annotation implements Comparable { } /** - * Sets the type of this annotation. BEWARE! Should only be used during deserialization. + * Sets the type of this annotation. BEWARE! Should only be used during deserialization. * * @param type the type of this annotation */ @@ -96,9 +96,9 @@ public class Annotation implements Comparable { } /** - * Returns true iff. this Annotation is associated with a SpanNode and the SpanNode is valid. + * Returns true iff this Annotation is associated with a SpanNode and the SpanNode is valid. * - * @return true iff. this Annotation is associated with a SpanNode and the SpanNode is valid. + * @return true iff this Annotation is associated with a SpanNode and the SpanNode is valid. * @see com.yahoo.document.annotation.SpanNode#isValid() */ public boolean isSpanNodeValid() { @@ -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. */ @@ -143,14 +143,14 @@ public class Annotation implements Comparable { throw new IllegalStateException("Span node is invalid: " + spanNode); } if (spanNode == DummySpanNode.INSTANCE) { - //internal safeguard - throw new IllegalStateException("BUG!! Annotations should never be attached to DummySpanNode."); + // internal safeguard + throw new IllegalStateException("BUG! Annotations should never be attached to DummySpanNode."); } this.spanNode = spanNode; } /** - * 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. */ @@ -247,7 +247,7 @@ public class Annotation implements Comparable { return comp; } - //types are equal, too, compare values + // types are equal, too, compare values if (value == null) { comp = (annotation.value == null) ? 0 : -1; } else { @@ -256,5 +256,6 @@ public class Annotation implements Comparable { return comp; } + } 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 40651bdc123..e9a81f16f90 100644 --- a/document/src/main/java/com/yahoo/document/annotation/AnnotationContainer.java +++ b/document/src/main/java/com/yahoo/document/annotation/AnnotationContainer.java @@ -5,7 +5,7 @@ import java.util.Collection; import java.util.Iterator; /** - * @author Einar M R Rosenvinge + * @author Einar M R Rosenvinge */ abstract class AnnotationContainer { @@ -46,6 +46,6 @@ abstract class AnnotationContainer { */ abstract Iterator iteratorRecursive(SpanNode node); + // TODO: remember equals and hashcode in subclasses! - //TODO: remember equals and hashcode in subclasses! } diff --git a/document/src/main/java/com/yahoo/document/annotation/AnnotationReference.java b/document/src/main/java/com/yahoo/document/annotation/AnnotationReference.java index be6f4955dcf..66ab895c88b 100644 --- a/document/src/main/java/com/yahoo/document/annotation/AnnotationReference.java +++ b/document/src/main/java/com/yahoo/document/annotation/AnnotationReference.java @@ -12,8 +12,8 @@ import com.yahoo.vespa.objects.Ids; /** * A FieldValue which holds a reference to an annotation of a specified type. * - * @author Einar M R Rosenvinge * @see Annotation#setFieldValue(com.yahoo.document.datatypes.FieldValue) + * @author Einar M R Rosenvinge */ public class AnnotationReference extends FieldValue { @@ -123,7 +123,7 @@ public class AnnotationReference extends FieldValue { @Override public void printXml(XmlStream xml) { - //TODO: Implement AnnotationReference.printXml() + // TODO: Implement AnnotationReference.printXml() } @Override @@ -182,4 +182,5 @@ public class AnnotationReference extends FieldValue { } return comp; } + } diff --git a/document/src/main/java/com/yahoo/document/annotation/AnnotationReferenceDataType.java b/document/src/main/java/com/yahoo/document/annotation/AnnotationReferenceDataType.java index 9adf7397a52..26b8919f4b8 100644 --- a/document/src/main/java/com/yahoo/document/annotation/AnnotationReferenceDataType.java +++ b/document/src/main/java/com/yahoo/document/annotation/AnnotationReferenceDataType.java @@ -7,15 +7,16 @@ import com.yahoo.document.datatypes.FieldValue; /** * A data type describing a field value having a reference to an annotation of a given type. * - * @author Einar M R Rosenvinge + * @author Einar M R Rosenvinge */ public class AnnotationReferenceDataType extends DataType { + private AnnotationType aType; /** * Creates an AnnotationReferenceDataType with a generated id. * - * @param aType the annotation type that AnnotationRefs shall refer to. + * @param aType the annotation type that AnnotationRefs shall refer to */ public AnnotationReferenceDataType(AnnotationType aType) { super("annotationreference<" + ((aType == null) ? "" : aType.getName()) + ">", 0); @@ -25,7 +26,7 @@ public class AnnotationReferenceDataType extends DataType { /** * Creates an AnnotationReferenceDataType with a given id. * - * @param aType the annotation type that AnnotationRefs shall refer to. + * @param aType the annotation type that AnnotationRefs shall refer to * @param id the id to use */ public AnnotationReferenceDataType(AnnotationType aType, int id) { @@ -34,7 +35,7 @@ public class AnnotationReferenceDataType extends DataType { } /** - * Creates an AnnotationReferenceDataType. WARNING! Do not use! + * Creates an AnnotationReferenceDataType. WARNING! Do not use! */ protected AnnotationReferenceDataType() { super("annotationreference<>", 0); @@ -77,11 +78,12 @@ public class AnnotationReferenceDataType extends DataType { } /** - * Sets the annotation type that this AnnotationReferenceDataType points to. WARNING! Do not use. + * Sets the annotation type that this AnnotationReferenceDataType points to. WARNING! Do not use. * @param type the annotation type of this AnnotationReferenceDataType. */ protected void setAnnotationType(AnnotationType type) { this.aType = type; setId(createId()); } + } 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 15e30b1f882..c93c69b08fc 100644 --- a/document/src/main/java/com/yahoo/document/annotation/AnnotationType.java +++ b/document/src/main/java/com/yahoo/document/annotation/AnnotationType.java @@ -16,9 +16,10 @@ import java.util.Collections; * that type are allowed to have a {@link com.yahoo.document.datatypes.FieldValue} of the given * {@link com.yahoo.document.DataType} as an optional payload. * - * @author Einar M R Rosenvinge + * @author Einar M R Rosenvinge */ public class AnnotationType implements Comparable { + private final int id; private final String name; private DataType dataType; @@ -60,7 +61,7 @@ public class AnnotationType implements Comparable { } /** - * Creates a new annotation type, with the specified ID. WARNING! Only to be used by configuration + * Creates a new annotation type, with the specified ID. WARNING! Only to be used by configuration * system, do not use!! * * @param name the name of the new annotation type @@ -71,26 +72,18 @@ public class AnnotationType implements Comparable { this.name = name; } - /** - * Returns the name of this annotation. - * - * @return the name of this annotation. - */ + /** Returns the name of this annotation. */ public String getName() { return name; } - /** - * Returns the data type of this annotation, if any. - * - * @return the data type of this annotation, or null. - */ + /** Returns the data type of this annotation, if any. */ public DataType getDataType() { return dataType; } /** - * Sets the data type of this annotation. WARNING! Only to be used by configuration + * Sets the data type of this annotation. WARNING! Only to be used by configuration * system, do not use!! * * @param dataType the data type of the annotation value @@ -99,11 +92,7 @@ public class AnnotationType implements Comparable { this.dataType = dataType; } - /** - * Returns the ID of this annotation. - * - * @return the ID of this annotation. - */ + /** Returns the ID of this annotation. */ public int getId() { return id; } @@ -121,13 +110,14 @@ public class AnnotationType implements Comparable { } /** - * WARNING! Only to be used by the configuration system and in unit tests. Not to be used in production code. + * WARNING! Only to be used by the configuration system and in unit tests. Not to be used in production code. * * @param type the type to inherit from */ public void inherit(AnnotationType type) { if (superType != null) { - throw new IllegalArgumentException("Already inherits type " + superType + ", multiple inheritance not currently supported."); + throw new IllegalArgumentException("Already inherits type " + superType + + ", multiple inheritance not currently supported."); } superType = type; } @@ -183,4 +173,5 @@ public class AnnotationType implements Comparable { } return 0; } + } -- cgit v1.2.3