diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2022-01-08 00:11:04 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-01-08 00:11:04 +0100 |
commit | cb82e84d2cd3ac0f589e199155821aacafa32201 (patch) | |
tree | c4d443391ce48961e108903cd83790cc60feb50f | |
parent | fa8857b5f2e4c6c52620d7e82f3b6f635eee73fe (diff) | |
parent | 4eeb104a64167898b52abc0281dcb73653ed98f9 (diff) |
Merge pull request #20711 from vespa-engine/bratseth/cleanup-100
Cleanup; No functional changes
97 files changed, 343 insertions, 285 deletions
diff --git a/vespajlib/abi-spec.json b/vespajlib/abi-spec.json index 5eeee267cf6..71e6c0f28f4 100644 --- a/vespajlib/abi-spec.json +++ b/vespajlib/abi-spec.json @@ -3026,7 +3026,7 @@ "public void write(char[], int, int)", "public void flush()", "public void close()", - "public final java.io.Writer getWriter()" + "public java.io.Writer getWriter()" ], "fields": [] }, diff --git a/vespajlib/src/main/java/com/yahoo/binaryprefix/BinaryPrefix.java b/vespajlib/src/main/java/com/yahoo/binaryprefix/BinaryPrefix.java index 64121756e5c..cf5183ec9d3 100644 --- a/vespajlib/src/main/java/com/yahoo/binaryprefix/BinaryPrefix.java +++ b/vespajlib/src/main/java/com/yahoo/binaryprefix/BinaryPrefix.java @@ -3,9 +3,11 @@ package com.yahoo.binaryprefix; /** * Represents binary prefixes. + * * @author Tony Vaagenes */ public enum BinaryPrefix { + //represents the binary prefix 2^(k*10) unit(0), kilo(1, 'K'), @@ -42,4 +44,5 @@ public enum BinaryPrefix { } throw new RuntimeException("No such binary prefix: " + c); } + } diff --git a/vespajlib/src/main/java/com/yahoo/binaryprefix/BinaryScaledAmount.java b/vespajlib/src/main/java/com/yahoo/binaryprefix/BinaryScaledAmount.java index ec2886d32bb..fef1f5bac4a 100644 --- a/vespajlib/src/main/java/com/yahoo/binaryprefix/BinaryScaledAmount.java +++ b/vespajlib/src/main/java/com/yahoo/binaryprefix/BinaryScaledAmount.java @@ -11,6 +11,7 @@ package com.yahoo.binaryprefix; * @author Tony Vaagenes */ public final class BinaryScaledAmount { + public final double amount; public final BinaryPrefix binaryPrefix; @@ -53,4 +54,5 @@ public final class BinaryScaledAmount { public int hashCode() { return (int)BinaryPrefix.unit.convertFrom(amount, binaryPrefix); } + } diff --git a/vespajlib/src/main/java/com/yahoo/collections/BobHash.java b/vespajlib/src/main/java/com/yahoo/collections/BobHash.java index cb5e88b3131..d133af2ea84 100644 --- a/vespajlib/src/main/java/com/yahoo/collections/BobHash.java +++ b/vespajlib/src/main/java/com/yahoo/collections/BobHash.java @@ -4,22 +4,18 @@ package com.yahoo.collections; import com.yahoo.text.Utf8; /** - * <p>A Java port of Michael Susag's BobHash in FastLib. This version is + * A Java port of Michael Susag's BobHash in FastLib. This version is * specifically done to be bit compatible with the one in FastLib, as it - * is used in decoding packets from FastServer.</p> + * is used in decoding packets from FastServer. * - * <p>Hash function based on - * <a href="http://burtleburtle.net/bob/hash/index.html"> - * http://burtleburtle.net/bob/hash/index.html</a> + * Hash function based on + * <a href="http://burtleburtle.net/bob/hash/index.html">http://burtleburtle.net/bob/hash/index.html</a> * by Bob Jenkins, 1996. bob_jenkins@burtleburtle.net. You may use this - * code any way you wish, private, educational, or commercial. It's free.</p> - * - * @author Michael Susag - * @author <a href="mailto:steinar@yahoo-inc.com">Steinar Knutsen</a> - * + * code any way you wish, private, educational, or commercial. It's free. * + * @author Michael Susag + * @author Steinar Knutsen */ - public class BobHash { /** diff --git a/vespajlib/src/main/java/com/yahoo/collections/CollectionComparator.java b/vespajlib/src/main/java/com/yahoo/collections/CollectionComparator.java index 5754718b66e..d936bbe41d4 100644 --- a/vespajlib/src/main/java/com/yahoo/collections/CollectionComparator.java +++ b/vespajlib/src/main/java/com/yahoo/collections/CollectionComparator.java @@ -8,7 +8,7 @@ import java.util.Iterator; * Utility class which is useful when implementing <code>Comparable</code> and one needs to * compare Collections of Comparables as instance variables. * - * @author <a href="mailto:einarmr@yahoo-inc.com">Einar M R Rosenvinge</a> + * @author Einar M R Rosenvinge */ public class CollectionComparator { /** @@ -51,4 +51,5 @@ public class CollectionComparator { //we haven't returned yet; contents must be equal: return 0; } + } diff --git a/vespajlib/src/main/java/com/yahoo/collections/CollectionUtil.java b/vespajlib/src/main/java/com/yahoo/collections/CollectionUtil.java index 1154df1db83..58d39e097d8 100644 --- a/vespajlib/src/main/java/com/yahoo/collections/CollectionUtil.java +++ b/vespajlib/src/main/java/com/yahoo/collections/CollectionUtil.java @@ -15,7 +15,6 @@ import java.util.stream.Collectors; * * @author Tony Vaagenes * @author gjoranv - * @since 5.1.8 */ public class CollectionUtil { @@ -100,4 +99,5 @@ public class CollectionUtil { } return Optional.empty(); } + } diff --git a/vespajlib/src/main/java/com/yahoo/collections/Comparables.java b/vespajlib/src/main/java/com/yahoo/collections/Comparables.java index 5952c5ec012..1f97cdd1ee3 100644 --- a/vespajlib/src/main/java/com/yahoo/collections/Comparables.java +++ b/vespajlib/src/main/java/com/yahoo/collections/Comparables.java @@ -8,6 +8,7 @@ package com.yahoo.collections; * @author hakon */ public class Comparables { + /** * Returns the least element, or {@code first} if they are equal according to * {@link Comparable#compareTo(Object) compareTo}. @@ -23,4 +24,5 @@ public class Comparables { public static <T extends Comparable<? super T>> T max(T first, T second) { return first.compareTo(second) <= 0 ? second : first; } + } diff --git a/vespajlib/src/main/java/com/yahoo/collections/FreezableArrayList.java b/vespajlib/src/main/java/com/yahoo/collections/FreezableArrayList.java index 1a765beaa3b..43ba88cf10c 100644 --- a/vespajlib/src/main/java/com/yahoo/collections/FreezableArrayList.java +++ b/vespajlib/src/main/java/com/yahoo/collections/FreezableArrayList.java @@ -10,7 +10,6 @@ import java.util.List; * Freezable lists may optionally allow new items to be added to the end of the list also after freeze. * * @author bratseth - * @since 5.20 */ public class FreezableArrayList<ITEM> extends ListenableArrayList<ITEM> { diff --git a/vespajlib/src/main/java/com/yahoo/collections/Hashlet.java b/vespajlib/src/main/java/com/yahoo/collections/Hashlet.java index ef31c38cc5a..bfd62a4c9fd 100644 --- a/vespajlib/src/main/java/com/yahoo/collections/Hashlet.java +++ b/vespajlib/src/main/java/com/yahoo/collections/Hashlet.java @@ -20,8 +20,8 @@ package com.yahoo.collections; * maximum load factor is 0.7 and drops slightly with increasing * capacity. * - * @author <a href="mailto:havardpe@yahoo-inc.com">Havard Pettersen</a> - **/ + * @author Havard Pettersen + */ public final class Hashlet<K, V> { private static final int[] emptyHash = new int[1]; @@ -223,4 +223,5 @@ public final class Hashlet<K, V> { } return true; } + } diff --git a/vespajlib/src/main/java/com/yahoo/collections/IntArrayComparator.java b/vespajlib/src/main/java/com/yahoo/collections/IntArrayComparator.java index b4122c3a311..59c0ac5758c 100644 --- a/vespajlib/src/main/java/com/yahoo/collections/IntArrayComparator.java +++ b/vespajlib/src/main/java/com/yahoo/collections/IntArrayComparator.java @@ -5,9 +5,10 @@ package com.yahoo.collections; * Utility class which is useful when implementing <code>Comparable</code> and one needs to * compare int arrays as instance variables. * - * @author <a href="mailto:einarmr@yahoo-inc.com">Einar M R Rosenvinge</a> + * @author Einar M R Rosenvinge */ public class IntArrayComparator { + /** * Compare the arguments. Shorter arrays are always considered * smaller than longer arrays. For arrays of equal lengths, the elements @@ -29,7 +30,7 @@ public class IntArrayComparator { return 1; } - //lengths are equal, compare contents + // lengths are equal, compare contents for (int i = 0; i < first.length; i++) { if (first[i] < second[i]) { return -1; @@ -39,7 +40,8 @@ public class IntArrayComparator { //values at index i are equal, continue... } - //we haven't returned yet; contents must be equal: + // we haven't returned yet; contents must be equal: return 0; } + } diff --git a/vespajlib/src/main/java/com/yahoo/collections/ListMap.java b/vespajlib/src/main/java/com/yahoo/collections/ListMap.java index 3f6321cb3d9..809acb69bf5 100644 --- a/vespajlib/src/main/java/com/yahoo/collections/ListMap.java +++ b/vespajlib/src/main/java/com/yahoo/collections/ListMap.java @@ -133,6 +133,7 @@ public class ListMap<K, V> { */ public void freeze() { if (frozen) return; + frozen = true; for (Map.Entry<K,List<V>> entry : map.entrySet()) entry.setValue(ImmutableList.copyOf(entry.getValue())); diff --git a/vespajlib/src/main/java/com/yahoo/collections/ListenableArrayList.java b/vespajlib/src/main/java/com/yahoo/collections/ListenableArrayList.java index 6fbf03925cb..9a807d0fcc7 100644 --- a/vespajlib/src/main/java/com/yahoo/collections/ListenableArrayList.java +++ b/vespajlib/src/main/java/com/yahoo/collections/ListenableArrayList.java @@ -11,7 +11,6 @@ import java.util.List; * * @author bratseth */ -@SuppressWarnings("serial") public class ListenableArrayList<ITEM> extends ArrayList<ITEM> { private List<Runnable> listeners = null; diff --git a/vespajlib/src/main/java/com/yahoo/collections/MD5.java b/vespajlib/src/main/java/com/yahoo/collections/MD5.java index de50b1d7410..bc1a8b29c64 100644 --- a/vespajlib/src/main/java/com/yahoo/collections/MD5.java +++ b/vespajlib/src/main/java/com/yahoo/collections/MD5.java @@ -15,9 +15,10 @@ import java.security.NoSuchAlgorithmException; * <p> * This class is not thread safe. * - * @author <a href="mailto:einarmr@yahoo-inc.com">Einar M R Rosenvinge</a> + * @author Einar M R Rosenvinge */ public class MD5 { + public static final ThreadLocal<MessageDigest> md5 = new MD5Factory(); private static class MD5Factory extends ThreadLocal<MessageDigest> { @@ -27,6 +28,7 @@ public class MD5 { return createMD5(); } } + private static MessageDigest createMD5() { try { return MessageDigest.getInstance("MD5"); @@ -34,7 +36,9 @@ public class MD5 { throw new RuntimeException(e); } } + final private MessageDigest digester; + public MD5() { try { digester = MessageDigest.getInstance("MD5"); @@ -64,4 +68,5 @@ public class MD5 { public byte[] hashFull(String s) { return digester.digest(Utf8.toBytes(s)); } + } diff --git a/vespajlib/src/main/java/com/yahoo/collections/MethodCache.java b/vespajlib/src/main/java/com/yahoo/collections/MethodCache.java index ef64a2e344a..ea8060e203b 100644 --- a/vespajlib/src/main/java/com/yahoo/collections/MethodCache.java +++ b/vespajlib/src/main/java/com/yahoo/collections/MethodCache.java @@ -10,6 +10,7 @@ import java.lang.reflect.Method; * @author baldersheim */ public final class MethodCache { + private final String methodName; private final CopyOnWriteHashMap<String, Method> cache = new CopyOnWriteHashMap<>(); @@ -34,4 +35,5 @@ public final class MethodCache { return null; } } + } diff --git a/vespajlib/src/main/java/com/yahoo/collections/TinyIdentitySet.java b/vespajlib/src/main/java/com/yahoo/collections/TinyIdentitySet.java index 831fddd7de8..f9fe365c4c7 100644 --- a/vespajlib/src/main/java/com/yahoo/collections/TinyIdentitySet.java +++ b/vespajlib/src/main/java/com/yahoo/collections/TinyIdentitySet.java @@ -13,17 +13,12 @@ import java.util.Set; * ArrayList for identity matches. In other words: Performance will only be * acceptable for <i>small</i> sets. * - * <p> * The rationale for this class is the high cost of the object identifier used * in IdentityHashMap, where the key set is often used as an identity set. - * </p> * * @author Steinar Knutsen - * @since 5.1.4 * @see java.util.IdentityHashMap - * - * @param <E> - * the type contained in the Set + * @param <E> the type contained in the Set */ public final class TinyIdentitySet<E> implements Set<E> { private class ArrayIterator<T> implements Iterator<E> { diff --git a/vespajlib/src/main/java/com/yahoo/collections/Tuple2.java b/vespajlib/src/main/java/com/yahoo/collections/Tuple2.java index c95e643a588..4ee02c45efa 100644 --- a/vespajlib/src/main/java/com/yahoo/collections/Tuple2.java +++ b/vespajlib/src/main/java/com/yahoo/collections/Tuple2.java @@ -2,15 +2,13 @@ package com.yahoo.collections; /** - * A representation of a pair of values, typically of different types. + * A pair of values. * - * <p> * This class is to avoid littering a class with thin wrapper objects for * passing around e.g. the state of an operation and the result value. Using * this class may be correct, but it is a symptom that you may want to redesign * your code. (Should you pass mutable objects to the method instead? Create a * new class and do the work inside that class instead? Etc.) - * </p> * * @author Steinar Knutsen */ diff --git a/vespajlib/src/main/java/com/yahoo/compress/CompressionType.java b/vespajlib/src/main/java/com/yahoo/compress/CompressionType.java index 50022256478..dc4132a3f3f 100644 --- a/vespajlib/src/main/java/com/yahoo/compress/CompressionType.java +++ b/vespajlib/src/main/java/com/yahoo/compress/CompressionType.java @@ -14,7 +14,7 @@ public enum CompressionType { LZ4((byte) 6), ZSTD((byte) 7); - private byte code; + private final byte code; CompressionType(byte code) { this.code = code; diff --git a/vespajlib/src/main/java/com/yahoo/concurrent/CachedThreadPoolWithFallback.java b/vespajlib/src/main/java/com/yahoo/concurrent/CachedThreadPoolWithFallback.java index 13d2463cf2c..c693d46975f 100644 --- a/vespajlib/src/main/java/com/yahoo/concurrent/CachedThreadPoolWithFallback.java +++ b/vespajlib/src/main/java/com/yahoo/concurrent/CachedThreadPoolWithFallback.java @@ -13,9 +13,9 @@ import java.util.concurrent.TimeUnit; /** * An executor that will first try a bounded cached thread pool before falling back to an unbounded * single threaded thread pool that will take over dispatching to the primary pool. - * */ public class CachedThreadPoolWithFallback implements AutoCloseable, Executor { + private final ExecutorService primary; private final ExecutorService secondary; diff --git a/vespajlib/src/main/java/com/yahoo/concurrent/DaemonThreadFactory.java b/vespajlib/src/main/java/com/yahoo/concurrent/DaemonThreadFactory.java index 3e84970764a..c1a3ee30b9a 100644 --- a/vespajlib/src/main/java/com/yahoo/concurrent/DaemonThreadFactory.java +++ b/vespajlib/src/main/java/com/yahoo/concurrent/DaemonThreadFactory.java @@ -11,7 +11,8 @@ import java.util.concurrent.ThreadFactory; * @author Einar M R Rosenvinge */ public class DaemonThreadFactory implements ThreadFactory { - private ThreadFactory defaultThreadFactory = Executors.defaultThreadFactory(); + + private final ThreadFactory defaultThreadFactory = Executors.defaultThreadFactory(); private String prefix = null; /** diff --git a/vespajlib/src/main/java/com/yahoo/concurrent/LocalInstance.java b/vespajlib/src/main/java/com/yahoo/concurrent/LocalInstance.java index e52e80963f3..98a509a89c2 100644 --- a/vespajlib/src/main/java/com/yahoo/concurrent/LocalInstance.java +++ b/vespajlib/src/main/java/com/yahoo/concurrent/LocalInstance.java @@ -10,14 +10,12 @@ import com.yahoo.concurrent.ThreadLocalDirectory.Updater; * {@link ThreadLocal} in ThreadLocalDirectory if possible, but has no user * available methods. * - * @param <AGGREGATOR> - * the structure to insert produced data into - * @param <SAMPLE> - * type of produced data to insert from each participating thread - * + * @param <AGGREGATOR> the structure to insert produced data into + * @param <SAMPLE> type of produced data to insert from each participating thread * @author Steinar Knutsen */ public final class LocalInstance<AGGREGATOR, SAMPLE> { + /** * The current generation of data produced from a single thread, where * generation is the period between two subsequent calls to diff --git a/vespajlib/src/main/java/com/yahoo/concurrent/Receiver.java b/vespajlib/src/main/java/com/yahoo/concurrent/Receiver.java index ace822e071f..7f8aa4b8725 100644 --- a/vespajlib/src/main/java/com/yahoo/concurrent/Receiver.java +++ b/vespajlib/src/main/java/com/yahoo/concurrent/Receiver.java @@ -27,7 +27,7 @@ import com.yahoo.collections.Tuple2; * there is no support for recycling it. * </p> * - * @author <a href="mailto:steinar@yahoo-inc.com">Steinar Knutsen</a> + * @author Steinar Knutsen */ public class Receiver<T> { /** diff --git a/vespajlib/src/main/java/com/yahoo/concurrent/ThreadFactoryFactory.java b/vespajlib/src/main/java/com/yahoo/concurrent/ThreadFactoryFactory.java index 10c057421af..1779179efcd 100644 --- a/vespajlib/src/main/java/com/yahoo/concurrent/ThreadFactoryFactory.java +++ b/vespajlib/src/main/java/com/yahoo/concurrent/ThreadFactoryFactory.java @@ -19,6 +19,7 @@ public class ThreadFactoryFactory { } return p.getFactory(false); } + static public synchronized ThreadFactory getDaemonThreadFactory(String name) { PooledFactory p = factory.get(name); if (p == null) { @@ -27,6 +28,7 @@ public class ThreadFactoryFactory { } return p.getFactory(true); } + private static class PooledFactory { private static class Factory implements ThreadFactory { final ThreadGroup group; @@ -65,6 +67,6 @@ public class ThreadFactoryFactory { private final String name; private final AtomicInteger poolId = new AtomicInteger(1); } - static private Map<String, PooledFactory> factory = new HashMap<>(); + static private final Map<String, PooledFactory> factory = new HashMap<>(); } diff --git a/vespajlib/src/main/java/com/yahoo/concurrent/ThreadRobustList.java b/vespajlib/src/main/java/com/yahoo/concurrent/ThreadRobustList.java index 18fec46a888..619e2beb6f4 100644 --- a/vespajlib/src/main/java/com/yahoo/concurrent/ThreadRobustList.java +++ b/vespajlib/src/main/java/com/yahoo/concurrent/ThreadRobustList.java @@ -14,8 +14,7 @@ import java.util.NoSuchElementException; * This is useful for traced information as there may be timed out threads * working on the structure after it is returned upwards for consumption. * - * @since 4.2 - * @author <a href="mailto:steinar@yahoo-inc.com">Steinar Knutsen</a> + * @author Steinar Knutsen * @author bratseth */ public class ThreadRobustList<T> implements Iterable<T> { diff --git a/vespajlib/src/main/java/com/yahoo/concurrent/classlock/ClassLock.java b/vespajlib/src/main/java/com/yahoo/concurrent/classlock/ClassLock.java index fc43fcc3116..d05cb14c64f 100644 --- a/vespajlib/src/main/java/com/yahoo/concurrent/classlock/ClassLock.java +++ b/vespajlib/src/main/java/com/yahoo/concurrent/classlock/ClassLock.java @@ -7,6 +7,7 @@ package com.yahoo.concurrent.classlock; * @author valerijf */ public class ClassLock implements AutoCloseable { + private final Class<?> clazz; private final ClassLocking classLocking; @@ -24,4 +25,5 @@ public class ClassLock implements AutoCloseable { public void close() { classLocking.unlock(clazz, this); } + } diff --git a/vespajlib/src/main/java/com/yahoo/concurrent/classlock/ClassLocking.java b/vespajlib/src/main/java/com/yahoo/concurrent/classlock/ClassLocking.java index f06ef662de5..7c9403965ac 100644 --- a/vespajlib/src/main/java/com/yahoo/concurrent/classlock/ClassLocking.java +++ b/vespajlib/src/main/java/com/yahoo/concurrent/classlock/ClassLocking.java @@ -12,6 +12,7 @@ import java.util.function.BooleanSupplier; * @author valerijf */ public class ClassLocking { + private final Map<String, ClassLock> classLocks = new HashMap<>(); private final Object monitor = new Object(); @@ -71,4 +72,5 @@ public class ClassLocking { monitor.notifyAll(); } } + } diff --git a/vespajlib/src/main/java/com/yahoo/concurrent/classlock/LockInterruptException.java b/vespajlib/src/main/java/com/yahoo/concurrent/classlock/LockInterruptException.java index ea61e87cd80..0e9ece62883 100644 --- a/vespajlib/src/main/java/com/yahoo/concurrent/classlock/LockInterruptException.java +++ b/vespajlib/src/main/java/com/yahoo/concurrent/classlock/LockInterruptException.java @@ -4,6 +4,5 @@ package com.yahoo.concurrent.classlock; /** * @author valerijf */ -@SuppressWarnings("serial") public class LockInterruptException extends RuntimeException { } diff --git a/vespajlib/src/main/java/com/yahoo/data/access/ArrayTraverser.java b/vespajlib/src/main/java/com/yahoo/data/access/ArrayTraverser.java index 9d86e7f02c9..5b22f55273b 100644 --- a/vespajlib/src/main/java/com/yahoo/data/access/ArrayTraverser.java +++ b/vespajlib/src/main/java/com/yahoo/data/access/ArrayTraverser.java @@ -5,12 +5,14 @@ package com.yahoo.data.access; * Callback interface for traversing arrays. * Implement this and call Inspector.traverse() * and you will get one callback for each array entry. - **/ + */ public interface ArrayTraverser { + /** * Callback function to implement. * @param idx array index for the current array entry. * @param inspector accessor for the current array entry's value. - **/ - public void entry(int idx, Inspector inspector); + */ + void entry(int idx, Inspector inspector); + } diff --git a/vespajlib/src/main/java/com/yahoo/data/access/Inspectable.java b/vespajlib/src/main/java/com/yahoo/data/access/Inspectable.java index 362c6e8f69e..9ff173ece45 100644 --- a/vespajlib/src/main/java/com/yahoo/data/access/Inspectable.java +++ b/vespajlib/src/main/java/com/yahoo/data/access/Inspectable.java @@ -5,7 +5,7 @@ package com.yahoo.data.access; * Minimal API to implement for objects containing or exposing * structured, generic, schemaless data. Use this when it's * impractical to implement the Inspector interface directly. - **/ + */ public interface Inspectable { /** Returns an Inspector exposing this object's structured data. */ diff --git a/vespajlib/src/main/java/com/yahoo/data/access/ObjectTraverser.java b/vespajlib/src/main/java/com/yahoo/data/access/ObjectTraverser.java index 45f1d280b34..1d033ebd7b1 100644 --- a/vespajlib/src/main/java/com/yahoo/data/access/ObjectTraverser.java +++ b/vespajlib/src/main/java/com/yahoo/data/access/ObjectTraverser.java @@ -5,12 +5,14 @@ package com.yahoo.data.access; * Callback interface for traversing objects. * Implement this and call Inspector.traverse() * and you will get one callback for each field in an object. - **/ + */ public interface ObjectTraverser { + /** * Callback function to implement. * @param name the name of the current field. * @param inspector accessor for the current field's value. - **/ - public void field(String name, Inspector inspector); + */ + void field(String name, Inspector inspector); + } diff --git a/vespajlib/src/main/java/com/yahoo/data/access/Type.java b/vespajlib/src/main/java/com/yahoo/data/access/Type.java index f0c3f91f386..354568e8808 100644 --- a/vespajlib/src/main/java/com/yahoo/data/access/Type.java +++ b/vespajlib/src/main/java/com/yahoo/data/access/Type.java @@ -13,7 +13,9 @@ package com.yahoo.data.access; * as an array of bytes. * - maps should be represented as an ARRAY of OBJECTs where each * object has the fields "key" and "value". - **/ + */ public enum Type { + EMPTY, BOOL, LONG, DOUBLE, STRING, DATA, ARRAY, OBJECT; + } diff --git a/vespajlib/src/main/java/com/yahoo/data/access/simple/JsonRender.java b/vespajlib/src/main/java/com/yahoo/data/access/simple/JsonRender.java index f2a0a05e6d3..cfc95c4e05f 100644 --- a/vespajlib/src/main/java/com/yahoo/data/access/simple/JsonRender.java +++ b/vespajlib/src/main/java/com/yahoo/data/access/simple/JsonRender.java @@ -32,7 +32,7 @@ public final class JsonRender { private final StringBuilder out; private boolean head = true; - private boolean compact; + private final boolean compact; private int level = 0; public StringEncoder(StringBuilder out, boolean compact) { diff --git a/vespajlib/src/main/java/com/yahoo/data/access/simple/Value.java b/vespajlib/src/main/java/com/yahoo/data/access/simple/Value.java index 182865bd950..2f4c8c59f1d 100644 --- a/vespajlib/src/main/java/com/yahoo/data/access/simple/Value.java +++ b/vespajlib/src/main/java/com/yahoo/data/access/simple/Value.java @@ -1,7 +1,6 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.data.access.simple; - import com.yahoo.data.access.*; import java.util.Collections; import java.util.Map; @@ -10,11 +9,11 @@ import java.util.List; import java.util.ArrayList; import java.nio.charset.StandardCharsets; - public class Value implements Inspector { - private static Value empty = new EmptyValue(); - private static Value invalid = new Value(); - private static byte[] empty_array = new byte[0]; + + private static final Value empty = new EmptyValue(); + private static final Value invalid = new Value(); + private static final byte[] empty_array = new byte[0]; public static Inspector empty() { return empty; } public static Inspector invalid() { return invalid; } public Inspector inspect() { return this; } diff --git a/vespajlib/src/main/java/com/yahoo/data/access/slime/SlimeAdapter.java b/vespajlib/src/main/java/com/yahoo/data/access/slime/SlimeAdapter.java index 3dc7e80fd05..010a015f288 100644 --- a/vespajlib/src/main/java/com/yahoo/data/access/slime/SlimeAdapter.java +++ b/vespajlib/src/main/java/com/yahoo/data/access/slime/SlimeAdapter.java @@ -1,26 +1,37 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.data.access.slime; +import com.yahoo.slime.Type; import java.util.Map; import java.util.AbstractMap; import java.util.List; import java.util.ArrayList; - public final class SlimeAdapter implements com.yahoo.data.access.Inspector { - private com.yahoo.slime.Inspector inspector; + + private final com.yahoo.slime.Inspector inspector; + public SlimeAdapter(com.yahoo.slime.Inspector inspector) { this.inspector = inspector; } - @Override public boolean equals(Object rhs) { + + @Override + public boolean equals(Object rhs) { if (!(rhs instanceof SlimeAdapter)) { return false; } return inspector.equals(((SlimeAdapter)rhs).inspector); } - @Override public int hashCode() { return inspector.hashCode(); } - @Override public String toString() { return inspector.toString(); } + + @Override + public int hashCode() { return inspector.hashCode(); } + + @Override + public String toString() { return inspector.toString(); } + public com.yahoo.data.access.Inspector inspect() { return this; } + public boolean valid() { return inspector.valid(); } + public com.yahoo.data.access.Type type() { switch(inspector.type()) { case NIX: return com.yahoo.data.access.Type.EMPTY; @@ -34,123 +45,143 @@ public final class SlimeAdapter implements com.yahoo.data.access.Inspector { } return com.yahoo.data.access.Type.EMPTY; } - private boolean verify(com.yahoo.slime.Type ok_type_a) { - com.yahoo.slime.Type my_type = inspector.type(); - return (valid() && (my_type == ok_type_a)); + + private boolean verify(Type okTypeA) { + Type myType = inspector.type(); + return (valid() && (myType == okTypeA)); } - private boolean verify(com.yahoo.slime.Type ok_type_a, - com.yahoo.slime.Type ok_type_b) - { - com.yahoo.slime.Type my_type = inspector.type(); - return (valid() && (my_type == ok_type_a || my_type == ok_type_b)); + + private boolean verify(Type okTypeA, Type okTypeB) { + Type myType = inspector.type(); + return (valid() && (myType == okTypeA || myType == okTypeB)); } - private boolean verify(com.yahoo.slime.Type ok_type_a, - com.yahoo.slime.Type ok_type_b, - com.yahoo.slime.Type ok_type_c) - { - com.yahoo.slime.Type my_type = inspector.type(); - return (valid() && (my_type == ok_type_a || my_type == ok_type_b || my_type == ok_type_c)); + + private boolean verify(Type okTypeA, Type okTypeB, Type okTypeC) { + Type myType = inspector.type(); + return (valid() && (myType == okTypeA || myType == okTypeB || myType == okTypeC)); } + public int entryCount() { return inspector.entries(); } + public int fieldCount() { return inspector.fields(); } + public boolean asBool() { - if (!verify(com.yahoo.slime.Type.NIX, com.yahoo.slime.Type.BOOL)) { + if (!verify(Type.NIX, Type.BOOL)) { throw new IllegalStateException("invalid data extraction!"); } return inspector.asBool(); } + public long asLong() { - if (!verify(com.yahoo.slime.Type.NIX, com.yahoo.slime.Type.LONG, com.yahoo.slime.Type.DOUBLE)) { + if (!verify(Type.NIX, Type.LONG, Type.DOUBLE)) { throw new IllegalStateException("invalid data extraction!"); } return inspector.asLong(); } + public double asDouble() { - if (!verify(com.yahoo.slime.Type.NIX, com.yahoo.slime.Type.DOUBLE, com.yahoo.slime.Type.LONG)) { + if (!verify(Type.NIX, Type.DOUBLE, Type.LONG)) { throw new IllegalStateException("invalid data extraction!"); } return inspector.asDouble(); } + public String asString() { - if (!verify(com.yahoo.slime.Type.NIX, com.yahoo.slime.Type.STRING)) { + if (!verify(Type.NIX, Type.STRING)) { throw new IllegalStateException("invalid data extraction!"); } return inspector.asString(); } + public byte[] asUtf8() { - if (!verify(com.yahoo.slime.Type.NIX, com.yahoo.slime.Type.STRING)) { + if (!verify(Type.NIX, Type.STRING)) { throw new IllegalStateException("invalid data extraction!"); } return inspector.asUtf8(); } + public byte[] asData() { - if (!verify(com.yahoo.slime.Type.NIX, com.yahoo.slime.Type.DATA)) { + if (!verify(Type.NIX, Type.DATA)) { throw new IllegalStateException("invalid data extraction!"); } return inspector.asData(); } + public boolean asBool(boolean defaultValue) { - if (!verify(com.yahoo.slime.Type.BOOL)) { + if (!verify(Type.BOOL)) { return defaultValue; } return inspector.asBool(); } + public long asLong(long defaultValue) { - if (!verify(com.yahoo.slime.Type.LONG, com.yahoo.slime.Type.DOUBLE)) { + if (!verify(Type.LONG, Type.DOUBLE)) { return defaultValue; } return inspector.asLong(); } + public double asDouble(double defaultValue) { - if (!verify(com.yahoo.slime.Type.DOUBLE, com.yahoo.slime.Type.LONG)) { + if (!verify(Type.DOUBLE, Type.LONG)) { return defaultValue; } return inspector.asDouble(); } + public String asString(String defaultValue) { - if (!verify(com.yahoo.slime.Type.STRING)) { + if (!verify(Type.STRING)) { return defaultValue; } return inspector.asString(); } + public byte[] asUtf8(byte[] defaultValue) { - if (!verify(com.yahoo.slime.Type.STRING)) { + if (!verify(Type.STRING)) { return defaultValue; } return inspector.asUtf8(); } + public byte[] asData(byte[] defaultValue) { - if (!verify(com.yahoo.slime.Type.DATA)) { + if (!verify(Type.DATA)) { return defaultValue; } return inspector.asData(); } + public void traverse(final com.yahoo.data.access.ArrayTraverser at) { inspector.traverse(new com.yahoo.slime.ArrayTraverser() { public void entry(int idx, com.yahoo.slime.Inspector inspector) { at.entry(idx, new SlimeAdapter(inspector)); } }); } + public void traverse(final com.yahoo.data.access.ObjectTraverser ot) { inspector.traverse(new com.yahoo.slime.ObjectTraverser() { public void field(String name, com.yahoo.slime.Inspector inspector) { ot.field(name, new SlimeAdapter(inspector)); } }); } + public com.yahoo.data.access.Inspector entry(int idx) { return new SlimeAdapter(inspector.entry(idx)); } + public com.yahoo.data.access.Inspector field(String name) { return new SlimeAdapter(inspector.field(name)); } + public Iterable<com.yahoo.data.access.Inspector> entries() { final List<com.yahoo.data.access.Inspector> list = new ArrayList<>(); + inspector.traverse(new com.yahoo.slime.ArrayTraverser() { public void entry(int idx, com.yahoo.slime.Inspector inspector) { list.add(new SlimeAdapter(inspector)); } }); return list; } + public Iterable<Map.Entry<String,com.yahoo.data.access.Inspector>> fields() { final List<Map.Entry<String,com.yahoo.data.access.Inspector>> list = new ArrayList<>(); inspector.traverse(new com.yahoo.slime.ObjectTraverser() { public void field(String name, com.yahoo.slime.Inspector inspector) { - list.add(new AbstractMap.SimpleImmutableEntry<String,com.yahoo.data.access.Inspector>(name, new SlimeAdapter(inspector))); + list.add(new AbstractMap.SimpleImmutableEntry<>(name, new SlimeAdapter(inspector))); } }); return list; } + } diff --git a/vespajlib/src/main/java/com/yahoo/exception/ExceptionUtils.java b/vespajlib/src/main/java/com/yahoo/exception/ExceptionUtils.java index fbd7336f558..8911e5c5d9e 100644 --- a/vespajlib/src/main/java/com/yahoo/exception/ExceptionUtils.java +++ b/vespajlib/src/main/java/com/yahoo/exception/ExceptionUtils.java @@ -37,4 +37,5 @@ public class ExceptionUtils { throw new UncheckedIOException(e); } } + } diff --git a/vespajlib/src/main/java/com/yahoo/geo/BoundingBoxParser.java b/vespajlib/src/main/java/com/yahoo/geo/BoundingBoxParser.java index d686a564d99..7a5e02cf30c 100644 --- a/vespajlib/src/main/java/com/yahoo/geo/BoundingBoxParser.java +++ b/vespajlib/src/main/java/com/yahoo/geo/BoundingBoxParser.java @@ -40,7 +40,7 @@ public class BoundingBoxParser { /** * parse the given string as a bounding box and return a parser object with parsed coordinates in member variables * @throws IllegalArgumentException if the input is malformed in any way - **/ + */ public BoundingBoxParser(String bb) { this.parseString = bb; this.len = bb.length(); diff --git a/vespajlib/src/main/java/com/yahoo/geo/DegreesParser.java b/vespajlib/src/main/java/com/yahoo/geo/DegreesParser.java index 986baf82bd2..187807d9a04 100644 --- a/vespajlib/src/main/java/com/yahoo/geo/DegreesParser.java +++ b/vespajlib/src/main/java/com/yahoo/geo/DegreesParser.java @@ -5,15 +5,13 @@ package com.yahoo.geo; * Utility for parsing geographical coordinates * * @author arnej27959 - **/ + */ public class DegreesParser { - /** - * the parsed latitude (degrees north if positive) - **/ + + /** The parsed latitude (degrees north if positive). */ public double latitude = 0; - /** - * the parsed longitude (degrees east if positive) - **/ + + /** The parsed longitude (degrees east if positive). */ public double longitude = 0; private boolean isDigit(char ch) { @@ -23,8 +21,8 @@ public class DegreesParser { return (ch == 'N' || ch == 'S' || ch == 'E' || ch == 'W'); } - private String parseString = null; - private int len = 0; + private final String parseString; + private final int len; private int pos = 0; private char getNextChar() throws IllegalArgumentException { @@ -65,9 +63,9 @@ public class DegreesParser { * "E10o25.982;N63o25.105" → same <br> * "N63.418417;E10.433033" → same <br> * "63N25.105;10E25.982" → same <br> - * @param latandlong Latitude and longitude separated by semicolon. * - **/ + * @param latandlong Latitude and longitude separated by semicolon. + */ public DegreesParser(String latandlong) throws IllegalArgumentException { this.parseString = latandlong; this.len = parseString.length(); @@ -107,11 +105,7 @@ public class DegreesParser { if (isDigit(ch) || ch == '.') { valid = true; - if (foundDigits) { - throw new IllegalArgumentException("found digits after not consuming previous digits"); - } double divider = 1.0; - foundDot = false; while (isDigit(ch)) { foundDigits = true; accum *= 10; @@ -163,7 +157,6 @@ public class DegreesParser { // if we found some number, assign it into the next unset variable if (foundDigits) { - valid = true; if (degSet) { if (minSet) { if (secSet) { @@ -281,4 +274,5 @@ public class DegreesParser { } // everything parsed OK } + } diff --git a/vespajlib/src/main/java/com/yahoo/geo/DistanceParser.java b/vespajlib/src/main/java/com/yahoo/geo/DistanceParser.java index acb7ed95597..04c2e735055 100644 --- a/vespajlib/src/main/java/com/yahoo/geo/DistanceParser.java +++ b/vespajlib/src/main/java/com/yahoo/geo/DistanceParser.java @@ -1,14 +1,14 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. - package com.yahoo.geo; import com.yahoo.api.annotations.Beta; /** * Utility for parsing a geographical distance with unit. - **/ + */ @Beta public class DistanceParser { + // according to wikipedia: // Earth's equatorial radius = 6378137 meter - not used // meters per mile = 1609.344 diff --git a/vespajlib/src/main/java/com/yahoo/geo/OneDegreeParser.java b/vespajlib/src/main/java/com/yahoo/geo/OneDegreeParser.java index 5b14606bb39..1ad5842173d 100644 --- a/vespajlib/src/main/java/com/yahoo/geo/OneDegreeParser.java +++ b/vespajlib/src/main/java/com/yahoo/geo/OneDegreeParser.java @@ -6,17 +6,14 @@ package com.yahoo.geo; * Utility for parsing one geographical coordinate * * @author arnej27959 - **/ + */ class OneDegreeParser { - /** - * the parsed latitude (degrees north if positive) - **/ + + /** The parsed latitude (degrees north if positive). */ public double latitude = 0; public boolean foundLatitude = false; - /** - * the parsed longitude (degrees east if positive) - **/ + /** The parsed longitude (degrees east if positive). */ public double longitude = 0; public boolean foundLongitude = false; @@ -78,6 +75,7 @@ class OneDegreeParser { * "E10o25.982" and "N63o25.105" → same <br> * "N63.418417" and "E10.433033" → same <br> * "63N25.105" and "10E25.982" → same <br> + * * @param assumeNorthSouth Latitude assumed, otherwise longitude * @param toParse Latitude or longitude string to parse * @@ -130,9 +128,6 @@ class OneDegreeParser { if (isDigit(ch) || ch == '.') { valid = true; - if (foundDigits) { - throw new IllegalArgumentException("found digits after not consuming previous digits when parsing <"+parseString+">"); - } double divider = 1.0; foundDot = false; while (isDigit(ch)) { @@ -279,4 +274,5 @@ class OneDegreeParser { } throw new IllegalArgumentException("found neither latitude nor longitude from: "+parseString); } + } diff --git a/vespajlib/src/main/java/com/yahoo/geo/ParsedDegree.java b/vespajlib/src/main/java/com/yahoo/geo/ParsedDegree.java index 695d78eadfc..d17508206d8 100644 --- a/vespajlib/src/main/java/com/yahoo/geo/ParsedDegree.java +++ b/vespajlib/src/main/java/com/yahoo/geo/ParsedDegree.java @@ -6,13 +6,14 @@ package com.yahoo.geo; * Utility for holding one geographical coordinate * * @author arnej27959 - **/ + */ public class ParsedDegree { + /** * the parsed latitude or longitude * Degrees north or east if positive * Degrees south or west if negative - **/ + */ public final double degrees; // one of these two flag will be true: @@ -46,6 +47,7 @@ public class ParsedDegree { throw new IllegalArgumentException("could not parse: "+toParse); } + @Override public String toString() { if (isLatitude) { return "Latitude: "+degrees+" degrees"; diff --git a/vespajlib/src/main/java/com/yahoo/geo/ZCurve.java b/vespajlib/src/main/java/com/yahoo/geo/ZCurve.java index d53ab72b199..45865cd265d 100644 --- a/vespajlib/src/main/java/com/yahoo/geo/ZCurve.java +++ b/vespajlib/src/main/java/com/yahoo/geo/ZCurve.java @@ -8,6 +8,7 @@ package com.yahoo.geo; * @author gjoranv */ public class ZCurve { + /** * Encode two 32 bit integers by bit-interleaving them into one 64 bit * integer value. The x-direction owns the least significant bit (bit @@ -43,8 +44,8 @@ public class ZCurve { * @return The bit-interleaved long containing x and y. */ public static long encode(int x, int y) { - long xl = (long)x; - long yl = (long)y; + long xl = x; + long yl = y; long rx = ((xl & 0x00000000ffff0000L) << 16) | (xl & 0x000000000000ffffL); long ry = ((yl & 0x00000000ffff0000L) << 16) | (yl & 0x000000000000ffffL); @@ -120,7 +121,7 @@ public class ZCurve { * * @param x x value * @param y y value - * @return The bit-interleaved long containing x and y. + * @return the bit-interleaved long containing x and y */ public static long encode_slow(int x, int y) { long z = 0L; diff --git a/vespajlib/src/main/java/com/yahoo/io/AbstractByteWriter.java b/vespajlib/src/main/java/com/yahoo/io/AbstractByteWriter.java index e97abe4a80a..a7cb6a9508e 100644 --- a/vespajlib/src/main/java/com/yahoo/io/AbstractByteWriter.java +++ b/vespajlib/src/main/java/com/yahoo/io/AbstractByteWriter.java @@ -16,8 +16,7 @@ import java.nio.charset.CharsetEncoder; * @author Steinar Knutsen * @author baldersheim */ -public abstract class AbstractByteWriter extends GenericWriter implements - WritableByteTransmitter { +public abstract class AbstractByteWriter extends GenericWriter implements WritableByteTransmitter { protected final CharsetEncoder encoder; protected final BufferChain buffer; diff --git a/vespajlib/src/main/java/com/yahoo/io/BufferChain.java b/vespajlib/src/main/java/com/yahoo/io/BufferChain.java index c3dec43764b..cee7a3c25dd 100644 --- a/vespajlib/src/main/java/com/yahoo/io/BufferChain.java +++ b/vespajlib/src/main/java/com/yahoo/io/BufferChain.java @@ -18,6 +18,7 @@ import java.util.List; * @author Steinar Knutsen */ public final class BufferChain { + // refer to the revision history of ByteWriter for more information about // the reasons behind the sizing of BUFFERSIZE, WATERMARK and MAXBUFFERS static final int BUFFERSIZE = 4096; diff --git a/vespajlib/src/main/java/com/yahoo/io/ByteWriter.java b/vespajlib/src/main/java/com/yahoo/io/ByteWriter.java index df457990bbe..4bca8ad51f7 100644 --- a/vespajlib/src/main/java/com/yahoo/io/ByteWriter.java +++ b/vespajlib/src/main/java/com/yahoo/io/ByteWriter.java @@ -14,6 +14,7 @@ import java.nio.charset.CharsetEncoder; * @author Steinar Knutsen */ public class ByteWriter extends AbstractByteWriter { + private final OutputStream stream; public ByteWriter(final OutputStream stream, final CharsetEncoder encoder) { diff --git a/vespajlib/src/main/java/com/yahoo/io/FatalErrorHandler.java b/vespajlib/src/main/java/com/yahoo/io/FatalErrorHandler.java index a491d7ee2cb..1aa84b0a15c 100644 --- a/vespajlib/src/main/java/com/yahoo/io/FatalErrorHandler.java +++ b/vespajlib/src/main/java/com/yahoo/io/FatalErrorHandler.java @@ -28,8 +28,8 @@ import java.util.logging.Level; * * @author Steinar Knutsen */ - public class FatalErrorHandler { + protected static final Logger log = Logger.getLogger(FatalErrorHandler.class.getName()); /** @@ -48,4 +48,5 @@ public class FatalErrorHandler { Runtime.getRuntime().halt(1); } } + } diff --git a/vespajlib/src/main/java/com/yahoo/io/GrowableBufferOutputStream.java b/vespajlib/src/main/java/com/yahoo/io/GrowableBufferOutputStream.java index ef598f70175..4b7d2ba4094 100644 --- a/vespajlib/src/main/java/com/yahoo/io/GrowableBufferOutputStream.java +++ b/vespajlib/src/main/java/com/yahoo/io/GrowableBufferOutputStream.java @@ -15,12 +15,12 @@ import java.nio.ByteBuffer; public class GrowableBufferOutputStream extends OutputStream { private ByteBuffer lastBuffer; - private ByteBuffer directBuffer; - private LinkedList<ByteBuffer> bufferList = new LinkedList<>(); - private Stack<ByteBuffer> recycledBuffers = new Stack<>(); + private final ByteBuffer directBuffer; + private final LinkedList<ByteBuffer> bufferList = new LinkedList<>(); + private final Stack<ByteBuffer> recycledBuffers = new Stack<>(); - private int bufferSize; - private int maxBuffers; + private final int bufferSize; + private final int maxBuffers; public GrowableBufferOutputStream(int bufferSize, int maxBuffers) { this.bufferSize = bufferSize; diff --git a/vespajlib/src/main/java/com/yahoo/io/IOUtils.java b/vespajlib/src/main/java/com/yahoo/io/IOUtils.java index 54cdf5c7b40..81e1306b29e 100644 --- a/vespajlib/src/main/java/com/yahoo/io/IOUtils.java +++ b/vespajlib/src/main/java/com/yahoo/io/IOUtils.java @@ -1,7 +1,6 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.io; - import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.ByteArrayOutputStream; @@ -27,7 +26,6 @@ import java.util.List; import java.nio.charset.Charset; import java.nio.ByteBuffer; - /** * Some static io convenience methods. * diff --git a/vespajlib/src/main/java/com/yahoo/io/Utf8ByteWriter.java b/vespajlib/src/main/java/com/yahoo/io/Utf8ByteWriter.java index c4cf25f34a0..30ad4aefd09 100644 --- a/vespajlib/src/main/java/com/yahoo/io/Utf8ByteWriter.java +++ b/vespajlib/src/main/java/com/yahoo/io/Utf8ByteWriter.java @@ -7,11 +7,13 @@ import java.io.IOException; import java.nio.ByteBuffer; public class Utf8ByteWriter extends AbstractByteWriter { + private ByteBuffer myBuf; public Utf8ByteWriter(int initialBuffer) { super(Utf8.getNewEncoder()); myBuf = ByteBuffer.allocate(initialBuffer); } + @Override public void send(ByteBuffer src) throws IOException { if (myBuf.remaining() < src.remaining()) { @@ -36,6 +38,7 @@ public class Utf8ByteWriter extends AbstractByteWriter { /** * Return a buffer ready for read. Must only be called after writer has been closed. + * * @return A flipped ByteBuffer */ public ByteBuffer getBuf() { diff --git a/vespajlib/src/main/java/com/yahoo/protect/ClassValidator.java b/vespajlib/src/main/java/com/yahoo/protect/ClassValidator.java index ed0b1c05d4d..128b564d2eb 100644 --- a/vespajlib/src/main/java/com/yahoo/protect/ClassValidator.java +++ b/vespajlib/src/main/java/com/yahoo/protect/ClassValidator.java @@ -16,7 +16,7 @@ import java.util.List; * is minimal. * </p> * - * @author <a href="mailto:steinar@yahoo-inc.com">Steinar Knutsen</a> + * @author Steinar Knutsen */ public final class ClassValidator { @@ -25,10 +25,8 @@ public final class ClassValidator { * maskedClass is implemented in testClass. Note, this will by definition * blow up on final methods in maskedClass. * - * @param testClass - * class which wraps or masks another class - * @param maskedClass - * class which is masked or wrapped + * @param testClass class which wraps or masks another class + * @param maskedClass class which is masked or wrapped * @return the methods which seem to miss from testClass to be complete */ public static List<Method> unmaskedMethods(Class<?> testClass, @@ -53,8 +51,7 @@ public final class ClassValidator { * Check testClass overrides all protected, public and package private * methods of its immediate super class. See unmaskedMethods(). * - * @param testClass - * the class to check whether completely masks its super class + * @param testClass the class to check whether completely masks its super class * @return the methods missing from testClass to completely override its * immediate super class */ diff --git a/vespajlib/src/main/java/com/yahoo/protect/Process.java b/vespajlib/src/main/java/com/yahoo/protect/Process.java index 1a462f1042e..8caaec88117 100644 --- a/vespajlib/src/main/java/com/yahoo/protect/Process.java +++ b/vespajlib/src/main/java/com/yahoo/protect/Process.java @@ -11,7 +11,6 @@ import java.util.concurrent.atomic.AtomicBoolean; import java.util.logging.Level; import java.util.logging.Logger; - /** * A class for interacting with the global state of the running VM. * diff --git a/vespajlib/src/main/java/com/yahoo/protect/Validator.java b/vespajlib/src/main/java/com/yahoo/protect/Validator.java index 358d75408da..530404cbd52 100644 --- a/vespajlib/src/main/java/com/yahoo/protect/Validator.java +++ b/vespajlib/src/main/java/com/yahoo/protect/Validator.java @@ -1,7 +1,6 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.protect; - /** * Static utility methods for validating input. * diff --git a/vespajlib/src/main/java/com/yahoo/reflection/Casting.java b/vespajlib/src/main/java/com/yahoo/reflection/Casting.java index ea11980b385..7d904543760 100644 --- a/vespajlib/src/main/java/com/yahoo/reflection/Casting.java +++ b/vespajlib/src/main/java/com/yahoo/reflection/Casting.java @@ -5,12 +5,15 @@ import java.util.Optional; /** * Utility methods for doing casting + * * @author Tony Vaagenes */ public class Casting { + /** * Returns the casted instance if it is assignment-compatible with targetClass, * or empty otherwise. + * * @see Class#isInstance(Object) */ public static <T> Optional<T> cast(Class<T> targetClass, Object instance) { @@ -18,4 +21,5 @@ public class Casting { Optional.of(targetClass.cast(instance)): Optional.empty(); } + } diff --git a/vespajlib/src/main/java/com/yahoo/slime/ArrayInserter.java b/vespajlib/src/main/java/com/yahoo/slime/ArrayInserter.java index 993556922d0..e2bb7479574 100644 --- a/vespajlib/src/main/java/com/yahoo/slime/ArrayInserter.java +++ b/vespajlib/src/main/java/com/yahoo/slime/ArrayInserter.java @@ -4,24 +4,26 @@ package com.yahoo.slime; /** * Helper class for inserting values into an ArrayValue. * For justification read Inserter documentation. - **/ + */ public final class ArrayInserter implements Inserter { + private Cursor target; public ArrayInserter(Cursor c) { target = c; } - public final ArrayInserter adjust(Cursor c) { + public ArrayInserter adjust(Cursor c) { target = c; return this; } - public final Cursor insertNIX() { return target.addNix(); } - public final Cursor insertBOOL(boolean value) { return target.addBool(value); } - public final Cursor insertLONG(long value) { return target.addLong(value); } - public final Cursor insertDOUBLE(double value) { return target.addDouble(value); } - public final Cursor insertSTRING(String value) { return target.addString(value); } - public final Cursor insertSTRING(byte[] utf8) { return target.addString(utf8); } - public final Cursor insertDATA(byte[] value) { return target.addData(value); } - public final Cursor insertARRAY() { return target.addArray(); } - public final Cursor insertOBJECT() { return target.addObject(); } + public Cursor insertNIX() { return target.addNix(); } + public Cursor insertBOOL(boolean value) { return target.addBool(value); } + public Cursor insertLONG(long value) { return target.addLong(value); } + public Cursor insertDOUBLE(double value) { return target.addDouble(value); } + public Cursor insertSTRING(String value) { return target.addString(value); } + public Cursor insertSTRING(byte[] utf8) { return target.addString(utf8); } + public Cursor insertDATA(byte[] value) { return target.addData(value); } + public Cursor insertARRAY() { return target.addArray(); } + public Cursor insertOBJECT() { return target.addObject(); } + } diff --git a/vespajlib/src/main/java/com/yahoo/slime/BinaryDecoder.java b/vespajlib/src/main/java/com/yahoo/slime/BinaryDecoder.java index 383fd626a62..b9aa8e5cf22 100644 --- a/vespajlib/src/main/java/com/yahoo/slime/BinaryDecoder.java +++ b/vespajlib/src/main/java/com/yahoo/slime/BinaryDecoder.java @@ -8,6 +8,7 @@ import static com.yahoo.slime.BinaryFormat.decode_type; import static com.yahoo.slime.BinaryFormat.decode_zigzag; final class BinaryDecoder { + BufferedInput in; private final SlimeInserter slimeInserter = new SlimeInserter(null); @@ -160,4 +161,5 @@ final class BinaryDecoder { } } } + } diff --git a/vespajlib/src/main/java/com/yahoo/slime/BinaryEncoder.java b/vespajlib/src/main/java/com/yahoo/slime/BinaryEncoder.java index 0d848e83bab..7da85b5cb63 100644 --- a/vespajlib/src/main/java/com/yahoo/slime/BinaryEncoder.java +++ b/vespajlib/src/main/java/com/yahoo/slime/BinaryEncoder.java @@ -5,9 +5,8 @@ import static com.yahoo.slime.BinaryFormat.encode_double; import static com.yahoo.slime.BinaryFormat.encode_type_and_meta; import static com.yahoo.slime.BinaryFormat.encode_zigzag; -final class BinaryEncoder implements -ArrayTraverser, ObjectSymbolTraverser -{ +final class BinaryEncoder implements ArrayTraverser, ObjectSymbolTraverser { + private final BufferedOutput out; BinaryEncoder() { @@ -143,4 +142,5 @@ ArrayTraverser, ObjectSymbolTraverser encode_cmpr_long(symbol); encodeValue(inspector); } + } diff --git a/vespajlib/src/main/java/com/yahoo/slime/BinaryFormat.java b/vespajlib/src/main/java/com/yahoo/slime/BinaryFormat.java index b397d4c2982..519ab54e25d 100644 --- a/vespajlib/src/main/java/com/yahoo/slime/BinaryFormat.java +++ b/vespajlib/src/main/java/com/yahoo/slime/BinaryFormat.java @@ -6,8 +6,9 @@ import com.yahoo.compress.Compressor; /** * Class for serializing Slime data into binary format, or deserializing * the binary format into a Slime object. - **/ + */ public class BinaryFormat { + static long encode_zigzag(long x) { return ((x << 1) ^ (x >> 63)); // note ASR } @@ -96,4 +97,5 @@ public class BinaryFormat { BinaryDecoder decoder = new BinaryDecoder(); return decoder.decode(data, offset, length); } + } diff --git a/vespajlib/src/main/java/com/yahoo/slime/Injector.java b/vespajlib/src/main/java/com/yahoo/slime/Injector.java index eec5f3999f9..71b5574fcc8 100644 --- a/vespajlib/src/main/java/com/yahoo/slime/Injector.java +++ b/vespajlib/src/main/java/com/yahoo/slime/Injector.java @@ -5,6 +5,7 @@ package com.yahoo.slime; * @author hakonhall */ public class Injector { + /** * Inject a slime sub-structure described by an Inspector into a slime * structure where the insertion point is described by an @@ -17,7 +18,7 @@ public class Injector { * * @param inspector what to inject * @param inserter where to inject - **/ + */ public void inject(Inspector inspector, Inserter inserter) { if (inspector.valid()) { injectValue(inserter, inspector, null); @@ -77,4 +78,5 @@ public class Injector { injectValue(new ObjectInserter(cursor, name), inspector, guard); } } + } diff --git a/vespajlib/src/main/java/com/yahoo/slime/Inserter.java b/vespajlib/src/main/java/com/yahoo/slime/Inserter.java index 7a7e5ba6f84..c36b56c11e2 100644 --- a/vespajlib/src/main/java/com/yahoo/slime/Inserter.java +++ b/vespajlib/src/main/java/com/yahoo/slime/Inserter.java @@ -6,8 +6,9 @@ package com.yahoo.slime; * classes (ArrayValue, ObjectValue, or Slime). May be useful for * deserializers where you can use it to decouple the actual value * decoding from the container where the value should be inserted. - **/ + */ public interface Inserter { + Cursor insertNIX(); Cursor insertBOOL(boolean value); Cursor insertLONG(long value); @@ -17,4 +18,5 @@ public interface Inserter { Cursor insertDATA(byte[] value); Cursor insertARRAY(); Cursor insertOBJECT(); + } diff --git a/vespajlib/src/main/java/com/yahoo/slime/JsonFormat.java b/vespajlib/src/main/java/com/yahoo/slime/JsonFormat.java index e7a96695922..3772aafa044 100644 --- a/vespajlib/src/main/java/com/yahoo/slime/JsonFormat.java +++ b/vespajlib/src/main/java/com/yahoo/slime/JsonFormat.java @@ -14,8 +14,8 @@ import java.io.*; * * @author Ulf Lilleengen */ -public final class JsonFormat implements SlimeFormat -{ +public final class JsonFormat implements SlimeFormat { + private final static byte [] HEX = Utf8.toBytes("0123456789ABCDEF"); private final boolean compact; public JsonFormat(boolean compact) { diff --git a/vespajlib/src/main/java/com/yahoo/slime/ObjectInserter.java b/vespajlib/src/main/java/com/yahoo/slime/ObjectInserter.java index c6becab554e..57c99f4604e 100644 --- a/vespajlib/src/main/java/com/yahoo/slime/ObjectInserter.java +++ b/vespajlib/src/main/java/com/yahoo/slime/ObjectInserter.java @@ -5,6 +5,7 @@ package com.yahoo.slime; * @author hakonhall */ public final class ObjectInserter implements Inserter { + private Cursor target; private String key; diff --git a/vespajlib/src/main/java/com/yahoo/slime/ObjectSymbolInserter.java b/vespajlib/src/main/java/com/yahoo/slime/ObjectSymbolInserter.java index c5c18943926..4935d96d388 100644 --- a/vespajlib/src/main/java/com/yahoo/slime/ObjectSymbolInserter.java +++ b/vespajlib/src/main/java/com/yahoo/slime/ObjectSymbolInserter.java @@ -4,8 +4,9 @@ package com.yahoo.slime; /** * Helper class for inserting values into an ObjectValue. * For justification read Inserter documentation. - **/ + */ public final class ObjectSymbolInserter implements Inserter { + private Cursor target; private int symbol; @@ -14,19 +15,19 @@ public final class ObjectSymbolInserter implements Inserter { symbol = sym; } - public final ObjectSymbolInserter adjust(Cursor c, int sym) { + public ObjectSymbolInserter adjust(Cursor c, int sym) { target = c; symbol = sym; return this; } - public final Cursor insertNIX() { return target.setNix(symbol); } - public final Cursor insertBOOL(boolean value) { return target.setBool(symbol, value); } - public final Cursor insertLONG(long value) { return target.setLong(symbol, value); } - public final Cursor insertDOUBLE(double value) { return target.setDouble(symbol, value); } - public final Cursor insertSTRING(String value) { return target.setString(symbol, value); } - public final Cursor insertSTRING(byte[] utf8) { return target.setString(symbol, utf8); } - public final Cursor insertDATA(byte[] value) { return target.setData(symbol, value); } - public final Cursor insertARRAY() { return target.setArray(symbol); } - public final Cursor insertOBJECT() { return target.setObject(symbol); } + public Cursor insertNIX() { return target.setNix(symbol); } + public Cursor insertBOOL(boolean value) { return target.setBool(symbol, value); } + public Cursor insertLONG(long value) { return target.setLong(symbol, value); } + public Cursor insertDOUBLE(double value) { return target.setDouble(symbol, value); } + public Cursor insertSTRING(String value) { return target.setString(symbol, value); } + public Cursor insertSTRING(byte[] utf8) { return target.setString(symbol, utf8); } + public Cursor insertDATA(byte[] value) { return target.setData(symbol, value); } + public Cursor insertARRAY() { return target.setArray(symbol); } + public Cursor insertOBJECT() { return target.setObject(symbol); } } diff --git a/vespajlib/src/main/java/com/yahoo/slime/ObjectSymbolTraverser.java b/vespajlib/src/main/java/com/yahoo/slime/ObjectSymbolTraverser.java index 90ca9bc70cd..a4946d3ff31 100644 --- a/vespajlib/src/main/java/com/yahoo/slime/ObjectSymbolTraverser.java +++ b/vespajlib/src/main/java/com/yahoo/slime/ObjectSymbolTraverser.java @@ -6,12 +6,14 @@ package com.yahoo.slime; * Implement this and call Inspector.traverse() * and you will get one callback for each field in an object. **/ -public interface ObjectSymbolTraverser -{ +public interface ObjectSymbolTraverser { + /** * Callback function to implement. + * * @param sym symbol id for the current field. * @param inspector accessor for the current field's value. - **/ - public void field(int sym, Inspector inspector); + */ + void field(int sym, Inspector inspector); + } diff --git a/vespajlib/src/main/java/com/yahoo/slime/ObjectTraverser.java b/vespajlib/src/main/java/com/yahoo/slime/ObjectTraverser.java index 6597d3b82f3..d9f9b75dfd1 100644 --- a/vespajlib/src/main/java/com/yahoo/slime/ObjectTraverser.java +++ b/vespajlib/src/main/java/com/yahoo/slime/ObjectTraverser.java @@ -7,6 +7,7 @@ package com.yahoo.slime; * and you will get one callback for each field in an object. */ public interface ObjectTraverser { + /** * Callback function to implement. * diff --git a/vespajlib/src/main/java/com/yahoo/slime/Slime.java b/vespajlib/src/main/java/com/yahoo/slime/Slime.java index c45b48cf743..eba9226c8ef 100644 --- a/vespajlib/src/main/java/com/yahoo/slime/Slime.java +++ b/vespajlib/src/main/java/com/yahoo/slime/Slime.java @@ -7,7 +7,7 @@ package com.yahoo.slime; * ObjectValue data objects). * * @author havardpe - **/ + */ public final class Slime { private final SymbolTable names = new SymbolTable(); diff --git a/vespajlib/src/main/java/com/yahoo/slime/SlimeStream.java b/vespajlib/src/main/java/com/yahoo/slime/SlimeStream.java index 4fea24110f0..0c0229579e7 100644 --- a/vespajlib/src/main/java/com/yahoo/slime/SlimeStream.java +++ b/vespajlib/src/main/java/com/yahoo/slime/SlimeStream.java @@ -11,6 +11,7 @@ import java.util.stream.Stream; * @author ogronnesby */ public final class SlimeStream { + private SlimeStream() {} /** @@ -24,4 +25,5 @@ public final class SlimeStream { .mapToObj(array::entry) .map(mapper); } + } diff --git a/vespajlib/src/main/java/com/yahoo/slime/SymbolTable.java b/vespajlib/src/main/java/com/yahoo/slime/SymbolTable.java index 0e498aa72e7..e86835fc0b7 100644 --- a/vespajlib/src/main/java/com/yahoo/slime/SymbolTable.java +++ b/vespajlib/src/main/java/com/yahoo/slime/SymbolTable.java @@ -5,7 +5,7 @@ package com.yahoo.slime; * A mapping from an arbitrary set of unique strings to a range of * integers. Slime users normally won't need to use this class * directly. - **/ + */ final class SymbolTable { public static final int INVALID = Integer.MAX_VALUE; @@ -95,4 +95,5 @@ final class SymbolTable { } return INVALID; } + } diff --git a/vespajlib/src/main/java/com/yahoo/slime/Type.java b/vespajlib/src/main/java/com/yahoo/slime/Type.java index 7d2b309157e..5407b296b38 100644 --- a/vespajlib/src/main/java/com/yahoo/slime/Type.java +++ b/vespajlib/src/main/java/com/yahoo/slime/Type.java @@ -3,7 +3,7 @@ package com.yahoo.slime; /** * Enumeration of all possibly Slime data types. - **/ + */ public enum Type { NIX(0), diff --git a/vespajlib/src/main/java/com/yahoo/slime/Utf8Codec.java b/vespajlib/src/main/java/com/yahoo/slime/Utf8Codec.java index 73be9620c22..e9f11a90af2 100644 --- a/vespajlib/src/main/java/com/yahoo/slime/Utf8Codec.java +++ b/vespajlib/src/main/java/com/yahoo/slime/Utf8Codec.java @@ -5,12 +5,14 @@ import com.yahoo.text.Utf8; /** * Helper class for conversion between String and UTF-8 representations. - **/ + */ class Utf8Codec { + public static String decode(byte[] data, int pos, int len) { return Utf8.toString(data, pos, len); } public static byte[] encode(String str) { return Utf8.toBytes(str); } + } diff --git a/vespajlib/src/main/java/com/yahoo/slime/Visitor.java b/vespajlib/src/main/java/com/yahoo/slime/Visitor.java index 5372e9cbf6f..0e49d0daf1e 100644 --- a/vespajlib/src/main/java/com/yahoo/slime/Visitor.java +++ b/vespajlib/src/main/java/com/yahoo/slime/Visitor.java @@ -4,19 +4,20 @@ package com.yahoo.slime; /** * Visitor interface used to resolve the underlying type of a value * represented by an Inspector. - **/ + */ public interface Visitor { + /** * Called when the visited Inspector is not valid. - **/ - public void visitInvalid(); - public void visitNix(); - public void visitBool(boolean bit); - public void visitLong(long l); - public void visitDouble(double d); - public void visitString(String str); - public void visitString(byte[] utf8); - public void visitData(byte[] data); - public void visitArray(Inspector arr); - public void visitObject(Inspector obj); + */ + void visitInvalid(); + void visitNix(); + void visitBool(boolean bit); + void visitLong(long l); + void visitDouble(double d); + void visitString(String str); + void visitString(byte[] utf8); + void visitData(byte[] data); + void visitArray(Inspector arr); + void visitObject(Inspector obj); } diff --git a/vespajlib/src/main/java/com/yahoo/system/CommandLineParser.java b/vespajlib/src/main/java/com/yahoo/system/CommandLineParser.java index 0689e634cf4..aedd7047567 100644 --- a/vespajlib/src/main/java/com/yahoo/system/CommandLineParser.java +++ b/vespajlib/src/main/java/com/yahoo/system/CommandLineParser.java @@ -11,23 +11,24 @@ import java.util.*; * progname -binaryswitch foo -unaryswitch argument1 argument2 * * @author vegardh - * */ public class CommandLineParser { - private List<String> inputStrings = new ArrayList<>(); - private Map<String, String> legalUnarySwitches = new HashMap<>(); - private Map<String, String> legalBinarySwitches = new HashMap<>(); - private List<String> unarySwitches = new ArrayList<>(); - private Map<String, String> binarySwitches = new HashMap<>(); - private List<String> arguments = new ArrayList<>(); - private Map<String, String> requiredUnarySwitches = new HashMap<>(); - private Map<String, String> requiredBinarySwitches = new HashMap<>(); + + private static final HashSet<String> helpSwitches = new HashSet<>(); + + private final List<String> inputStrings; + private final Map<String, String> legalUnarySwitches = new HashMap<>(); + private final Map<String, String> legalBinarySwitches = new HashMap<>(); + private final List<String> unarySwitches = new ArrayList<>(); + private final Map<String, String> binarySwitches = new HashMap<>(); + private final List<String> arguments = new ArrayList<>(); + private final Map<String, String> requiredUnarySwitches = new HashMap<>(); + private final Map<String, String> requiredBinarySwitches = new HashMap<>(); private String progname = "progname"; private String argumentExplanation; - private int minArguments=0; - private int maxArguments=Integer.MAX_VALUE; + private int minArguments = 0; + private int maxArguments = Integer.MAX_VALUE; private String helpText; - private static HashSet<String> helpSwitches = new HashSet<>(); private boolean helpSwitchUsed = false; static { @@ -213,4 +214,5 @@ public class CommandLineParser { public boolean helpSwitchUsed() { return helpSwitchUsed; } + } diff --git a/vespajlib/src/main/java/com/yahoo/system/ForceLoad.java b/vespajlib/src/main/java/com/yahoo/system/ForceLoad.java index d627a4324d9..6869fdfaf5c 100644 --- a/vespajlib/src/main/java/com/yahoo/system/ForceLoad.java +++ b/vespajlib/src/main/java/com/yahoo/system/ForceLoad.java @@ -3,21 +3,17 @@ package com.yahoo.system; /** * Utility class used to force the loading of other classes. - **/ + */ public class ForceLoad { /** * Force the loading of the given classes. If any of the named * classes can not be loaded, an error will be thrown. * - * @param packageName the name of the package for which - * we want to forceload classes. - * @param classNames array of names of classes (without package prefix) - * to force load. - **/ - public static void forceLoad(String packageName, String[] classNames, ClassLoader loader) - throws ForceLoadError - { + * @param packageName the name of the package for which we want to forceload classes. + * @param classNames array of names of classes (without package prefix) to force load. + */ + public static void forceLoad(String packageName, String[] classNames, ClassLoader loader) throws ForceLoadError { String fullClassName = ""; try { for (String className : classNames) { @@ -28,4 +24,5 @@ public class ForceLoad { throw new ForceLoadError(fullClassName, e); } } + } diff --git a/vespajlib/src/main/java/com/yahoo/system/ForceLoadError.java b/vespajlib/src/main/java/com/yahoo/system/ForceLoadError.java index b85fb1b303c..02fe11e5f5e 100644 --- a/vespajlib/src/main/java/com/yahoo/system/ForceLoadError.java +++ b/vespajlib/src/main/java/com/yahoo/system/ForceLoadError.java @@ -3,8 +3,7 @@ package com.yahoo.system; /** * Special error to be propagated when force-loading a class fails. - **/ -@SuppressWarnings("serial") + */ public class ForceLoadError extends java.lang.Error { /** @@ -12,8 +11,9 @@ public class ForceLoadError extends java.lang.Error { * * @param className full name of offending class * @param cause what caused the failure - **/ + */ public ForceLoadError(String className, Throwable cause) { super("Force loading class '" + className + "' failed", cause); } + } diff --git a/vespajlib/src/main/java/com/yahoo/system/ProcessExecuter.java b/vespajlib/src/main/java/com/yahoo/system/ProcessExecuter.java index b705cc081a5..91c3e59fbae 100644 --- a/vespajlib/src/main/java/com/yahoo/system/ProcessExecuter.java +++ b/vespajlib/src/main/java/com/yahoo/system/ProcessExecuter.java @@ -27,7 +27,7 @@ public class ProcessExecuter { /** * Executes the given command synchronously without timeout. * - * @return Retcode and stdout/stderr merged + * @return retcode and stdout/stderr merged */ public Pair<Integer, String> exec(String command) throws IOException { StringTokenizer tok = new StringTokenizer(command); diff --git a/vespajlib/src/main/java/com/yahoo/text/AbstractUtf8Array.java b/vespajlib/src/main/java/com/yahoo/text/AbstractUtf8Array.java index 4994479047e..62998621181 100644 --- a/vespajlib/src/main/java/com/yahoo/text/AbstractUtf8Array.java +++ b/vespajlib/src/main/java/com/yahoo/text/AbstractUtf8Array.java @@ -5,45 +5,32 @@ import java.nio.ByteBuffer; /** * @author baldersheim - * @since 5.2 */ public abstract class AbstractUtf8Array implements Comparable<AbstractUtf8Array> { - /** - * This will write the utf8 sequence to the given target. - */ + + /** Writes the utf8 sequence to the given target. */ final public void writeTo(ByteBuffer target) { target.put(getBytes(), getByteOffset(), getByteLength()); } - /** - * This will return the byte at the given position. - */ + /** Returns the byte at the given position. */ public byte getByte(int index) { return getBytes()[getByteOffset() + index]; } - /** - * - * @return Length in bytes of the utf8 sequence. - */ + /** Returns the length in bytes of the utf8 sequence. */ public abstract int getByteLength(); - /** - * Wraps the utf8 sequence in a ByteBuffer - * @return The wrapping buffer. + /** Wraps the utf8 sequence in a ByteBuffer + * + * @return the wrapping buffer */ public ByteBuffer wrap() { return ByteBuffer.wrap(getBytes(), getByteOffset(), getByteLength()); } - /** - * - * @return The backing byte array. - */ + /** Returns the backing byte array. */ protected abstract byte [] getBytes(); public boolean isEmpty() { return getByteLength() == 0; } - /** - * - * @return The offset in the backing array where the utf8 sequence starts. - */ + /** Returns the offset in the backing array where the utf8 sequence starts. */ protected abstract int getByteOffset(); @Override public int hashCode() { @@ -57,6 +44,7 @@ public abstract class AbstractUtf8Array implements Comparable<AbstractUtf8Array> } return h; } + @Override public boolean equals(Object o) { if (o instanceof AbstractUtf8Array) { @@ -68,10 +56,7 @@ public abstract class AbstractUtf8Array implements Comparable<AbstractUtf8Array> return false; } - /** - * Will convert the utf8 sequence to a Java string - * @return The converted Java String - */ + /** Retuerns the utf8 sequence as a Java string. */ @Override public String toString() { return Utf8.toString(getBytes(), getByteOffset(), getByteLength()); diff --git a/vespajlib/src/main/java/com/yahoo/text/Ascii7BitMatcher.java b/vespajlib/src/main/java/com/yahoo/text/Ascii7BitMatcher.java index d796d746f37..85ecbaf140e 100644 --- a/vespajlib/src/main/java/com/yahoo/text/Ascii7BitMatcher.java +++ b/vespajlib/src/main/java/com/yahoo/text/Ascii7BitMatcher.java @@ -7,9 +7,11 @@ import java.util.BitSet; * Fast replacement for regex based validators of simple expressions. * It can take a list of legal characters for the the first character, * and another list for the following. Limited to 7bit ascii. + * * @author baldersheim */ public class Ascii7BitMatcher { + private final BitSet legalFirst; private final BitSet legalRest; private static BitSet createBitSet(String legal) { @@ -48,7 +50,7 @@ public class Ascii7BitMatcher { return true; } static public String charsAndNumbers() { - char [] chars = new char[26*2+10]; + char[] chars = new char[26*2+10]; int i = 0; for (char c = 'A'; c <= 'Z'; c++) { chars[i++] = c; @@ -61,4 +63,5 @@ public class Ascii7BitMatcher { } return new String(chars); } + } diff --git a/vespajlib/src/main/java/com/yahoo/text/CaseInsensitiveIdentifier.java b/vespajlib/src/main/java/com/yahoo/text/CaseInsensitiveIdentifier.java index d0c2a27cdee..d42db0250ec 100644 --- a/vespajlib/src/main/java/com/yahoo/text/CaseInsensitiveIdentifier.java +++ b/vespajlib/src/main/java/com/yahoo/text/CaseInsensitiveIdentifier.java @@ -5,6 +5,7 @@ package com.yahoo.text; * @author baldersheim */ public class CaseInsensitiveIdentifier extends Identifier { + private final Identifier original; public CaseInsensitiveIdentifier(String s) { @@ -18,4 +19,5 @@ public class CaseInsensitiveIdentifier extends Identifier { original = new Identifier(utf8); } public String toString() { return original.toString(); } + } diff --git a/vespajlib/src/main/java/com/yahoo/text/DataTypeIdentifier.java b/vespajlib/src/main/java/com/yahoo/text/DataTypeIdentifier.java index d6d0cbca624..3f64993c343 100644 --- a/vespajlib/src/main/java/com/yahoo/text/DataTypeIdentifier.java +++ b/vespajlib/src/main/java/com/yahoo/text/DataTypeIdentifier.java @@ -5,6 +5,7 @@ package com.yahoo.text; * @author baldersheim */ public class DataTypeIdentifier { + private static final byte [] ARRAY = {'a', 'r', 'r', 'a', 'y'}; private static final byte [] ANNOTATIONREFERENCE = {'a','n','n','o','t','a','t','i','o','n','r','e','f','e','r','e','n','c','e'}; private static final byte [] MAP = { 'm', 'a', 'p'}; diff --git a/vespajlib/src/main/java/com/yahoo/text/ForwardWriter.java b/vespajlib/src/main/java/com/yahoo/text/ForwardWriter.java index 3fb2e37649c..aedf474359b 100644 --- a/vespajlib/src/main/java/com/yahoo/text/ForwardWriter.java +++ b/vespajlib/src/main/java/com/yahoo/text/ForwardWriter.java @@ -4,10 +4,9 @@ package com.yahoo.text; import java.io.IOException; /** - * Wraps another writer and also converting IOException to Exceptions. + * Wraps another writer and converts IOException to RuntimeExceptions. * * @author baldersheim - * @since 5.2 */ public class ForwardWriter extends GenericWriter { diff --git a/vespajlib/src/main/java/com/yahoo/text/GenericWriter.java b/vespajlib/src/main/java/com/yahoo/text/GenericWriter.java index 29f0f2d4fc5..cc867c00ee2 100644 --- a/vespajlib/src/main/java/com/yahoo/text/GenericWriter.java +++ b/vespajlib/src/main/java/com/yahoo/text/GenericWriter.java @@ -9,19 +9,13 @@ import java.io.Writer; * java.io.Writer, but it allows for more overrides for speed. * This introduces additional interfaces in addition to the java.lang.Writer. * The purpose is to allow for optimizations. + * * @author baldersheim - * @since 5.2 */ - public abstract class GenericWriter extends Writer { -/* - public abstract void write(char [] c, int offset, int bytes); - public abstract void flush(); - public abstract void close(); -*/ public GenericWriter write(char c) throws java.io.IOException { - char t[] = new char[1]; + char[] t = new char[1]; t[0] = c; try { write(t, 0, 1); @@ -47,18 +41,22 @@ public abstract class GenericWriter extends Writer { write(String.valueOf(i)); return this; } + public GenericWriter write(byte i) throws java.io.IOException { write(String.valueOf(i)); return this; } + public GenericWriter write(double i) throws java.io.IOException { write(String.valueOf(i)); return this; } + public GenericWriter write(float i) throws java.io.IOException { write(String.valueOf(i)); return this; } + public GenericWriter write(boolean i) throws java.io.IOException { write(String.valueOf(i)); return this; @@ -68,4 +66,5 @@ public abstract class GenericWriter extends Writer { write(v.toString()); return this; } + } diff --git a/vespajlib/src/main/java/com/yahoo/text/HTML.java b/vespajlib/src/main/java/com/yahoo/text/HTML.java index c7295695414..a983df4d970 100644 --- a/vespajlib/src/main/java/com/yahoo/text/HTML.java +++ b/vespajlib/src/main/java/com/yahoo/text/HTML.java @@ -1,17 +1,16 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.text; - import java.util.Map; import java.util.HashMap; - /** * Static HTML escaping stuff * - * @author <a href="mailto:borud@yahoo-inc.com">Bjorn Borud</a> + * @author Bjorn Borud */ public class HTML { + static Object[][] entities = { // {"#39", Integer.valueOf(39)}, // ' - apostrophe {"quot", 34}, // " - double-quote @@ -121,4 +120,5 @@ public class HTML { } return buf.toString(); } + } diff --git a/vespajlib/src/main/java/com/yahoo/text/JSONWriter.java b/vespajlib/src/main/java/com/yahoo/text/JSONWriter.java index bf89d9c4547..30746cf016c 100644 --- a/vespajlib/src/main/java/com/yahoo/text/JSONWriter.java +++ b/vespajlib/src/main/java/com/yahoo/text/JSONWriter.java @@ -16,7 +16,7 @@ import java.util.Deque; public final class JSONWriter { /** A stack maintaining the "needs comma" state at the current level */ - private Deque<Boolean> needsComma=new ArrayDeque<>(); + private final Deque<Boolean> needsComma = new ArrayDeque<>(); private static final char[] DIGITS = new char[] { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' }; diff --git a/vespajlib/src/main/java/com/yahoo/text/JavaWriterWriter.java b/vespajlib/src/main/java/com/yahoo/text/JavaWriterWriter.java index cfbcf7353d3..1edc1c06400 100644 --- a/vespajlib/src/main/java/com/yahoo/text/JavaWriterWriter.java +++ b/vespajlib/src/main/java/com/yahoo/text/JavaWriterWriter.java @@ -8,7 +8,6 @@ import java.io.Writer; * Wraps a simple java.lang.Writer. Of course you loose the possible optimizations. * * @author baldersheim - * @since 5.2 */ public final class JavaWriterWriter extends GenericWriter { @@ -44,6 +43,7 @@ public final class JavaWriterWriter extends GenericWriter { throw new RuntimeException("Caught exception in Java writer.close.", e); } } - public final Writer getWriter() { return out; } + + public Writer getWriter() { return out; } } diff --git a/vespajlib/src/main/java/com/yahoo/text/LowercaseIdentifier.java b/vespajlib/src/main/java/com/yahoo/text/LowercaseIdentifier.java index 0091fed2a67..9b2d57df5eb 100644 --- a/vespajlib/src/main/java/com/yahoo/text/LowercaseIdentifier.java +++ b/vespajlib/src/main/java/com/yahoo/text/LowercaseIdentifier.java @@ -5,6 +5,7 @@ package com.yahoo.text; * @author baldersheim */ public class LowercaseIdentifier extends Identifier { + public LowercaseIdentifier(String s) { this(Utf8.toBytes(s)); } diff --git a/vespajlib/src/main/java/com/yahoo/text/MapParser.java b/vespajlib/src/main/java/com/yahoo/text/MapParser.java index cd0ff19afd1..9b40e3d90ad 100644 --- a/vespajlib/src/main/java/com/yahoo/text/MapParser.java +++ b/vespajlib/src/main/java/com/yahoo/text/MapParser.java @@ -24,7 +24,6 @@ import java.util.Map; * <p>Map parsers are NOT multithread safe, but are cheap to construct.</p> * * @author bratseth - * @since 5.1.15 */ public abstract class MapParser<VALUETYPE> extends SimpleMapParser { diff --git a/vespajlib/src/main/java/com/yahoo/text/PositionedString.java b/vespajlib/src/main/java/com/yahoo/text/PositionedString.java index 9285f8ba8af..aca0b7d1259 100644 --- a/vespajlib/src/main/java/com/yahoo/text/PositionedString.java +++ b/vespajlib/src/main/java/com/yahoo/text/PositionedString.java @@ -6,11 +6,10 @@ package com.yahoo.text; * Useful for writing simple single-pass parsers. * * @author bratseth - * @since 5.1.15 */ public class PositionedString { - private String s; + private final String s; private int p; /** diff --git a/vespajlib/src/main/java/com/yahoo/text/SimpleMapParser.java b/vespajlib/src/main/java/com/yahoo/text/SimpleMapParser.java index 185f2e34ab8..6724ae51a84 100644 --- a/vespajlib/src/main/java/com/yahoo/text/SimpleMapParser.java +++ b/vespajlib/src/main/java/com/yahoo/text/SimpleMapParser.java @@ -24,7 +24,6 @@ package com.yahoo.text; * <p>Map parsers are NOT multithread safe, but are cheap to construct.</p> * * @author bratseth - * @since 5.1.15 */ public abstract class SimpleMapParser { diff --git a/vespajlib/src/main/java/com/yahoo/text/StringUtilities.java b/vespajlib/src/main/java/com/yahoo/text/StringUtilities.java index 0b6d707e0fd..fb90fabb964 100644 --- a/vespajlib/src/main/java/com/yahoo/text/StringUtilities.java +++ b/vespajlib/src/main/java/com/yahoo/text/StringUtilities.java @@ -4,6 +4,7 @@ package com.yahoo.text; import com.google.common.collect.ImmutableSet; import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; import java.util.Collections; import java.util.List; import java.io.ByteArrayOutputStream; @@ -19,14 +20,15 @@ import java.util.Set; // TODO: Text utilities should which are still needed should move to Text. This should be deprecated. public class StringUtilities { - private static Charset UTF8 = Charset.forName("utf8"); + private static final Charset UTF8 = StandardCharsets.UTF_8; private static byte toHex(int val) { return (byte) (val < 10 ? '0' + val : 'a' + (val - 10)); } private static class ReplacementCharacters { - public byte needEscape[] = new byte[256]; - public byte replacement1[] = new byte[256]; - public byte replacement2[] = new byte[256]; + + public byte[] needEscape = new byte[256]; + public byte[] replacement1 = new byte[256]; + public byte[] replacement2 = new byte[256]; public ReplacementCharacters() { for (int i=0; i<256; ++i) { @@ -65,7 +67,7 @@ public class StringUtilities { * @return The escaped string */ public static String escape(String source, char delimiter) { - byte bytes[] = source.getBytes(UTF8); + byte[] bytes = source.getBytes(UTF8); ByteArrayOutputStream result = new ByteArrayOutputStream(); for (byte b : bytes) { int val = b; @@ -90,7 +92,7 @@ public class StringUtilities { } public static String unescape(String source) { - byte bytes[] = source.getBytes(UTF8); + byte[] bytes = source.getBytes(UTF8); ByteArrayOutputStream result = new ByteArrayOutputStream(); for (int i=0; i<bytes.length; ++i) { if (bytes[i] != '\\') { @@ -212,7 +214,7 @@ public class StringUtilities { public static Set<String> split(String s) { if (s == null || s.isEmpty()) return Collections.emptySet(); ImmutableSet.Builder<String> b = new ImmutableSet.Builder<>(); - for (String item : s.split("[\\s\\,]")) + for (String item : s.split("[\\s,]")) if ( ! item.isEmpty()) b.add(item); return b.build(); diff --git a/vespajlib/src/main/java/com/yahoo/text/Utf8.java b/vespajlib/src/main/java/com/yahoo/text/Utf8.java index a71406582fa..91bbb86d3fc 100644 --- a/vespajlib/src/main/java/com/yahoo/text/Utf8.java +++ b/vespajlib/src/main/java/com/yahoo/text/Utf8.java @@ -18,7 +18,6 @@ import java.nio.charset.StandardCharsets; * @author arnej27959 * @author Steinar Knutsen * @author baldersheim - * */ public final class Utf8 { diff --git a/vespajlib/src/main/java/com/yahoo/text/Utf8Array.java b/vespajlib/src/main/java/com/yahoo/text/Utf8Array.java index 75498ecc69c..2d881ea2f62 100644 --- a/vespajlib/src/main/java/com/yahoo/text/Utf8Array.java +++ b/vespajlib/src/main/java/com/yahoo/text/Utf8Array.java @@ -1,18 +1,16 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.text; - import java.nio.ByteBuffer; /** * This is a primitive class that owns an array of utf8 encoded string. * This is a class that has speed as its primary purpose. * If you have a string, consider Utf8String - * If you have a large backing array consider Utf8PartialArray + * If you have a large backing array consider Utf8PartialArray. + * * @author baldersheim - * @since 5.2 */ - public class Utf8Array extends AbstractUtf8Array { protected final byte[] utf8; diff --git a/vespajlib/src/main/java/com/yahoo/text/Utf8PartialArray.java b/vespajlib/src/main/java/com/yahoo/text/Utf8PartialArray.java index 7f76d17ce8e..275335d3c2b 100644 --- a/vespajlib/src/main/java/com/yahoo/text/Utf8PartialArray.java +++ b/vespajlib/src/main/java/com/yahoo/text/Utf8PartialArray.java @@ -3,10 +3,11 @@ package com.yahoo.text; /** * This wraps a window in a backing byte array. Without doing any copying. + * * @author baldersheim - * @since 5.2 */ public class Utf8PartialArray extends Utf8Array { + final int offset; final int length; diff --git a/vespajlib/src/main/java/com/yahoo/text/Utf8String.java b/vespajlib/src/main/java/com/yahoo/text/Utf8String.java index 1530f7effff..b36f2933291 100644 --- a/vespajlib/src/main/java/com/yahoo/text/Utf8String.java +++ b/vespajlib/src/main/java/com/yahoo/text/Utf8String.java @@ -1,18 +1,18 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.text; - /** * String with Utf8 backing. + * * @author baldersheim - * @since 5.2 */ -public final class Utf8String extends Utf8Array implements CharSequence -{ +public final class Utf8String extends Utf8Array implements CharSequence { + private final String s; /** * This will construct a utf8 backing of the given string. + * * @param str The string that will be utf8 encoded */ public Utf8String(String str) { @@ -22,6 +22,7 @@ public final class Utf8String extends Utf8Array implements CharSequence /** * This will create a string based on the utf8 sequence. + * * @param utf8 The backing array */ public Utf8String(AbstractUtf8Array utf8) { diff --git a/vespajlib/src/main/java/com/yahoo/time/TimeBudget.java b/vespajlib/src/main/java/com/yahoo/time/TimeBudget.java index cf69cfb4fcd..b18a0f397f6 100644 --- a/vespajlib/src/main/java/com/yahoo/time/TimeBudget.java +++ b/vespajlib/src/main/java/com/yahoo/time/TimeBudget.java @@ -14,6 +14,7 @@ import java.util.Optional; * @author hakon */ public class TimeBudget { + private final Clock clock; private final Instant start; private final Optional<Duration> timeout; @@ -90,4 +91,5 @@ public class TimeBudget { private static Duration makeNonNegative(Duration duration) { return duration.isNegative() ? Duration.ZERO : duration; } + } diff --git a/vespajlib/src/main/java/com/yahoo/vespa/objects/BufferSerializer.java b/vespajlib/src/main/java/com/yahoo/vespa/objects/BufferSerializer.java index 1bf71f51112..716795049fb 100644 --- a/vespajlib/src/main/java/com/yahoo/vespa/objects/BufferSerializer.java +++ b/vespajlib/src/main/java/com/yahoo/vespa/objects/BufferSerializer.java @@ -11,6 +11,7 @@ import java.nio.ByteOrder; * @author baldersheim */ public class BufferSerializer implements Serializer, Deserializer { + protected GrowableByteBuffer buf; public BufferSerializer(GrowableByteBuffer buf) { this.buf = buf; } diff --git a/vespajlib/src/main/java/com/yahoo/vespa/objects/Deserializer.java b/vespajlib/src/main/java/com/yahoo/vespa/objects/Deserializer.java index d8ee9308146..affc20c73b9 100644 --- a/vespajlib/src/main/java/com/yahoo/vespa/objects/Deserializer.java +++ b/vespajlib/src/main/java/com/yahoo/vespa/objects/Deserializer.java @@ -5,6 +5,7 @@ package com.yahoo.vespa.objects; * @author baldersheim */ public interface Deserializer { + byte getByte(FieldBase field); short getShort(FieldBase field); int getInt(FieldBase field); @@ -13,4 +14,5 @@ public interface Deserializer { double getDouble(FieldBase field); byte [] getBytes(FieldBase field, int length); String getString(FieldBase field); + } diff --git a/vespajlib/src/main/java/com/yahoo/vespa/objects/Identifiable.java b/vespajlib/src/main/java/com/yahoo/vespa/objects/Identifiable.java index 947b312ac3b..5fc6336f628 100644 --- a/vespajlib/src/main/java/com/yahoo/vespa/objects/Identifiable.java +++ b/vespajlib/src/main/java/com/yahoo/vespa/objects/Identifiable.java @@ -27,7 +27,7 @@ public class Identifiable extends Selectable implements Cloneable { * Returns the class identifier of this class. This proxies the {@link #onGetClassId()} method that must be * implemented by every subclass. * - * @return The class identifier. + * @return the class identifier */ public final int getClassId() { return onGetClassId(); diff --git a/vespajlib/src/main/java/com/yahoo/vespa/objects/ObjectOperation.java b/vespajlib/src/main/java/com/yahoo/vespa/objects/ObjectOperation.java index 1eff5c0120b..f78ff98cc0a 100755 --- a/vespajlib/src/main/java/com/yahoo/vespa/objects/ObjectOperation.java +++ b/vespajlib/src/main/java/com/yahoo/vespa/objects/ObjectOperation.java @@ -13,5 +13,6 @@ public interface ObjectOperation { * * @param obj The object to operate on. */ - public void execute(Object obj); + void execute(Object obj); + } diff --git a/vespajlib/src/main/java/com/yahoo/vespa/objects/ObjectPredicate.java b/vespajlib/src/main/java/com/yahoo/vespa/objects/ObjectPredicate.java index a555c7688ae..6da1f6d6d7d 100755 --- a/vespajlib/src/main/java/com/yahoo/vespa/objects/ObjectPredicate.java +++ b/vespajlib/src/main/java/com/yahoo/vespa/objects/ObjectPredicate.java @@ -15,5 +15,6 @@ public interface ObjectPredicate { * @param obj The object to check. * @return True or false. */ - public boolean check(Object obj); + boolean check(Object obj); + } diff --git a/vespajlib/src/main/java/com/yahoo/vespa/objects/Serializer.java b/vespajlib/src/main/java/com/yahoo/vespa/objects/Serializer.java index 4dc27392caa..570ba97f24f 100644 --- a/vespajlib/src/main/java/com/yahoo/vespa/objects/Serializer.java +++ b/vespajlib/src/main/java/com/yahoo/vespa/objects/Serializer.java @@ -7,6 +7,7 @@ import java.nio.ByteBuffer; * @author baldersheim */ public interface Serializer { + Serializer putByte(FieldBase field, byte value); Serializer putShort(FieldBase field, short value); Serializer putInt(FieldBase field, int value); @@ -16,4 +17,5 @@ public interface Serializer { Serializer put(FieldBase field, byte[] value); Serializer put(FieldBase field, ByteBuffer value); Serializer put(FieldBase field, String value); + } |