summaryrefslogtreecommitdiffstats
path: root/document/src/main/java
diff options
context:
space:
mode:
Diffstat (limited to 'document/src/main/java')
-rw-r--r--document/src/main/java/com/yahoo/document/BucketDistribution.java4
-rw-r--r--document/src/main/java/com/yahoo/document/DocumentId.java27
-rw-r--r--document/src/main/java/com/yahoo/document/GlobalId.java8
3 files changed, 16 insertions, 23 deletions
diff --git a/document/src/main/java/com/yahoo/document/BucketDistribution.java b/document/src/main/java/com/yahoo/document/BucketDistribution.java
index abacd4fdc2f..e963f57e22b 100644
--- a/document/src/main/java/com/yahoo/document/BucketDistribution.java
+++ b/document/src/main/java/com/yahoo/document/BucketDistribution.java
@@ -1,8 +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.yahoo.document.BucketId;
-
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
@@ -14,7 +12,7 @@ import java.util.logging.Logger;
public class BucketDistribution {
// A logger object to enable proper logging.
- private static Logger log = Logger.getLogger(BucketDistribution.class.getName());
+ private static final Logger log = Logger.getLogger(BucketDistribution.class.getName());
// A map from bucket id to column index.
private int[] bucketToColumn;
diff --git a/document/src/main/java/com/yahoo/document/DocumentId.java b/document/src/main/java/com/yahoo/document/DocumentId.java
index 8c35eaa0329..3512c5cb7b7 100644
--- a/document/src/main/java/com/yahoo/document/DocumentId.java
+++ b/document/src/main/java/com/yahoo/document/DocumentId.java
@@ -11,6 +11,7 @@ import com.yahoo.vespa.objects.Identifiable;
import com.yahoo.vespa.objects.Serializer;
import java.io.Serializable;
+import java.util.Objects;
/**
* The id of a document
@@ -18,11 +19,9 @@ import java.io.Serializable;
public class DocumentId extends Identifiable implements Serializable {
private IdString id;
- private GlobalId globalId;
+ private GlobalId globalId = null;
- /**
- * Constructor used for deserialization.
- */
+ /** Constructor used for deserialization. */
public DocumentId(Deserializer buf) {
deserialize(buf);
}
@@ -33,21 +32,14 @@ public class DocumentId extends Identifiable implements Serializable {
* The document id string can only contain text characters.
*/
public DocumentId(String id) {
- if (id == null) {
- throw new IllegalArgumentException("Cannot create DocumentId from null id.");
- }
- if (id.length() > IdString.MAX_LENGTH) {
- throw new IllegalArgumentException("The document id(" + id.length() + ") is too long(" + IdString.MAX_LENGTH + "). " +
- "However if you have already fed a document earlier on and want to remove it, you can do so by " +
- "calling new DocumentId(IdString.createIdStringLessStrict()) that will bypass this restriction.");
- }
- this.id = IdString.createIdString(id);
- globalId = null;
+ this.id = IdString.createIdString(Objects.requireNonNull(id));
+ if (id.length() > IdString.MAX_LENGTH)
+ throw new IllegalArgumentException("Document id of length " + id.length() +
+ " is longer than the max " + IdString.MAX_LENGTH);
}
public DocumentId(IdString id) {
this.id = id;
- globalId = null;
}
/**
@@ -86,14 +78,17 @@ public class DocumentId extends Identifiable implements Serializable {
return id.toString().compareTo(cmp.id.toString());
}
+ @Override
public boolean equals(Object o) {
return o instanceof DocumentId && id.equals(((DocumentId)o).id);
}
+ @Override
public int hashCode() {
return id.hashCode();
}
+ @Override
public String toString() {
return id.toString();
}
@@ -107,7 +102,6 @@ public class DocumentId extends Identifiable implements Serializable {
}
}
-
public void onDeserialize(Deserializer data) throws DeserializationException {
if (data instanceof DocumentReader) {
id = ((DocumentReader)data).readDocumentId().getScheme();
@@ -123,4 +117,5 @@ public class DocumentId extends Identifiable implements Serializable {
public String getDocType() {
return id.getDocType();
}
+
}
diff --git a/document/src/main/java/com/yahoo/document/GlobalId.java b/document/src/main/java/com/yahoo/document/GlobalId.java
index 9e90b59171c..b9d454dd007 100644
--- a/document/src/main/java/com/yahoo/document/GlobalId.java
+++ b/document/src/main/java/com/yahoo/document/GlobalId.java
@@ -40,10 +40,10 @@ public class GlobalId implements Comparable {
/**
* Constructs a new global id from a document id string.
*
- * @param id The document id to derive from.
+ * @param id the document id to derive from
*/
public GlobalId(IdString id) {
- byte [] raw = MD5.md5.get().digest(id.toUtf8().wrap().array());
+ byte[] raw = MD5.md5.get().digest(id.toUtf8().wrap().array());
long location = id.getLocation();
this.raw = new byte [LENGTH];
for (int i = 0; i < 4; ++i) {
@@ -57,7 +57,7 @@ public class GlobalId implements Comparable {
/**
* Constructs a global id by deserializing content from the given byte buffer.
*
- * @param buf The buffer to deserialize from.
+ * @param buf the buffer to deserialize from
*/
public GlobalId(Deserializer buf) {
raw = buf.getBytes(null, LENGTH);
@@ -66,7 +66,7 @@ public class GlobalId implements Comparable {
/**
* Serializes the content of this global id into the given byte buffer.
*
- * @param buf The buffer to serialize to.
+ * @param buf the buffer to serialize to
*/
public void serialize(Serializer buf) {
buf.put(null, raw);