diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2024-04-12 08:30:35 +0200 |
---|---|---|
committer | Henning Baldersheim <balder@yahoo-inc.com> | 2024-04-12 08:39:04 +0200 |
commit | 76a89b62274060452022ddf24a7685ee2f380cb4 (patch) | |
tree | ef924603de22efd026f519ab31fd8f5a6ff60f2f /document | |
parent | 7e7ebf7b527be1f163d497a41898e2252d878fe7 (diff) |
Replace all usages of Arrays.asList with List.of where possible.
Diffstat (limited to 'document')
4 files changed, 17 insertions, 25 deletions
diff --git a/document/src/main/java/com/yahoo/document/annotation/AnnotationTypes.java b/document/src/main/java/com/yahoo/document/annotation/AnnotationTypes.java index 4750e64a784..312f2800e6c 100644 --- a/document/src/main/java/com/yahoo/document/annotation/AnnotationTypes.java +++ b/document/src/main/java/com/yahoo/document/annotation/AnnotationTypes.java @@ -3,7 +3,6 @@ package com.yahoo.document.annotation; import com.yahoo.document.DataType; -import java.util.Arrays; import java.util.List; /** @@ -29,7 +28,7 @@ public final class AnnotationTypes { public static final AnnotationType PROXIMITY_BREAK = new AnnotationType("proximity_break", DataType.DOUBLE, 8); public static final AnnotationType SPECIAL_TOKEN = new AnnotationType("special_token", 9); - public static final List<AnnotationType> ALL_TYPES = Arrays.asList(TERM, TOKEN_TYPE, CANONICAL, NORMALIZED, READING, + public static final List<AnnotationType> ALL_TYPES = List.of(TERM, TOKEN_TYPE, CANONICAL, NORMALIZED, READING, STEM, TRANSFORMED, PROXIMITY_BREAK, SPECIAL_TOKEN); } diff --git a/document/src/main/java/com/yahoo/document/fieldpathupdate/FieldPathUpdate.java b/document/src/main/java/com/yahoo/document/fieldpathupdate/FieldPathUpdate.java index 35d12f32906..42405bb6f06 100644 --- a/document/src/main/java/com/yahoo/document/fieldpathupdate/FieldPathUpdate.java +++ b/document/src/main/java/com/yahoo/document/fieldpathupdate/FieldPathUpdate.java @@ -13,6 +13,7 @@ import com.yahoo.document.select.parser.ParseException; import com.yahoo.document.serialization.DocumentUpdateReader; import com.yahoo.document.serialization.VespaDocumentSerializer6; import java.util.ListIterator; +import java.util.Objects; /** * @author Thomas Gundersen @@ -48,8 +49,8 @@ public abstract class FieldPathUpdate { private DocumentSelector selector; private String originalFieldPath; private String whereClause; - private Type updType; - private DocumentType docType; + private final Type updType; + private final DocumentType docType; public FieldPathUpdate(Type updType, DocumentType docType, String fieldPath, String whereClause) { this.updType = updType; @@ -97,7 +98,7 @@ public abstract class FieldPathUpdate { public void setWhereClause(String whereClause) throws ParseException { this.whereClause = whereClause; selector = null; - if (whereClause != null && !whereClause.equals("")) { + if (whereClause != null && !whereClause.isEmpty()) { selector = new DocumentSelector(whereClause); } } @@ -135,15 +136,11 @@ public abstract class FieldPathUpdate { } public static FieldPathUpdate create(Type type, DocumentType docType, DocumentUpdateReader reader) { - switch (type) { - case ASSIGN: - return new AssignFieldPathUpdate(docType, reader); - case ADD: - return new AddFieldPathUpdate(docType, reader); - case REMOVE: - return new RemoveFieldPathUpdate(docType, reader); - } - throw new IllegalArgumentException("Field path update type '" + type + "' not supported."); + return switch (type) { + case ASSIGN -> new AssignFieldPathUpdate(docType, reader); + case ADD -> new AddFieldPathUpdate(docType, reader); + case REMOVE -> new RemoveFieldPathUpdate(docType, reader); + }; } @Override @@ -153,10 +150,10 @@ public abstract class FieldPathUpdate { FieldPathUpdate that = (FieldPathUpdate) o; - if (docType != null ? !docType.equals(that.docType) : that.docType != null) return false; - if (originalFieldPath != null ? !originalFieldPath.equals(that.originalFieldPath) : that.originalFieldPath != null) + if (!Objects.equals(docType, that.docType)) return false; + if (!Objects.equals(originalFieldPath, that.originalFieldPath)) return false; - if (whereClause != null ? !whereClause.equals(that.whereClause) : that.whereClause != null) return false; + if (!Objects.equals(whereClause, that.whereClause)) return false; return true; } diff --git a/document/src/test/java/com/yahoo/document/json/JsonReaderTestCase.java b/document/src/test/java/com/yahoo/document/json/JsonReaderTestCase.java index aa043a25d78..e72d3720024 100644 --- a/document/src/test/java/com/yahoo/document/json/JsonReaderTestCase.java +++ b/document/src/test/java/com/yahoo/document/json/JsonReaderTestCase.java @@ -20,7 +20,6 @@ import com.yahoo.document.MapDataType; import com.yahoo.document.PositionDataType; import com.yahoo.document.StructDataType; import com.yahoo.document.TensorDataType; -import com.yahoo.document.TestAndSetCondition; import com.yahoo.document.WeightedSetDataType; import com.yahoo.document.datatypes.Array; import com.yahoo.document.datatypes.BoolFieldValue; @@ -32,7 +31,6 @@ import com.yahoo.document.datatypes.StringFieldValue; import com.yahoo.document.datatypes.Struct; import com.yahoo.document.datatypes.TensorFieldValue; import com.yahoo.document.datatypes.WeightedSet; -import com.yahoo.document.fieldpathupdate.FieldPathUpdate; import com.yahoo.document.internal.GeoPosType; import com.yahoo.document.json.readers.DocumentParseInfo; import com.yahoo.document.json.readers.VespaJsonDocumentReader; @@ -64,7 +62,6 @@ import org.junit.Test; import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; -import java.util.ArrayList; import java.util.Arrays; import java.util.Base64; import java.util.Collections; diff --git a/document/src/test/java/com/yahoo/document/select/DocumentSelectorTestCase.java b/document/src/test/java/com/yahoo/document/select/DocumentSelectorTestCase.java index 63255f90919..b09d33a2fe4 100644 --- a/document/src/test/java/com/yahoo/document/select/DocumentSelectorTestCase.java +++ b/document/src/test/java/com/yahoo/document/select/DocumentSelectorTestCase.java @@ -32,7 +32,6 @@ import org.junit.Before; import org.junit.Test; import java.util.ArrayList; -import java.util.Arrays; import java.util.HashSet; import java.util.List; import java.util.Map; @@ -852,10 +851,10 @@ public class DocumentSelectorTestCase { @Test public void testThatSelectionIsConvertedToQueries() throws ParseException { - assertThatQueriesAreCreated("music.expire > now()", Arrays.asList("music"), Arrays.asList("expire:>now(0)")); - assertThatQueriesAreCreated("music.expire > now() - 300", Arrays.asList("music"), Arrays.asList("expire:>now(300)")); - assertThatQueriesAreCreated("music.expire > now() - 300 and video.expire > now() - 3600", Arrays.asList("music", "video"), Arrays.asList("expire:>now(300)", "expire:>now(3600)")); - assertThatQueriesAreCreated("music.expire > now() - 300 or video", Arrays.asList("music"), Arrays.asList("expire:>now(300)")); + assertThatQueriesAreCreated("music.expire > now()", List.of("music"), List.of("expire:>now(0)")); + assertThatQueriesAreCreated("music.expire > now() - 300", List.of("music"), List.of("expire:>now(300)")); + assertThatQueriesAreCreated("music.expire > now() - 300 and video.expire > now() - 3600", List.of("music", "video"), List.of("expire:>now(300)", "expire:>now(3600)")); + assertThatQueriesAreCreated("music.expire > now() - 300 or video", List.of("music"), List.of("expire:>now(300)")); assertVisitWithInvalidNowFails("music.field1 > now() - 300 and music.field2 > now() - 300", "Specifying multiple document types is not allowed"); assertVisitWithInvalidNowFails("music.field1 > now() - 300 and video.field1 > now() and music.field2 > now() - 300", "Specifying multiple document types is not allowed"); assertVisitWithInvalidNowFails("now() > music.field", "Left hand side of comparison must be a document field"); |