diff options
author | Jon Bratseth <bratseth@gmail.com> | 2021-12-09 11:12:22 +0100 |
---|---|---|
committer | Jon Bratseth <bratseth@gmail.com> | 2021-12-09 11:12:22 +0100 |
commit | ab7844c88fa058bc1db12837cbcaff3ecf4448ca (patch) | |
tree | ecf599581e09be83d99e3874aeba7a428225665c /vespajlib/src/main | |
parent | 608ea1f94f5e5b5dbbbafc388b6a24cfc26de586 (diff) |
No functional changes
Diffstat (limited to 'vespajlib/src/main')
12 files changed, 227 insertions, 160 deletions
diff --git a/vespajlib/src/main/java/com/yahoo/slime/ArrayValue.java b/vespajlib/src/main/java/com/yahoo/slime/ArrayValue.java index 6450982540f..dbd9771afe9 100644 --- a/vespajlib/src/main/java/com/yahoo/slime/ArrayValue.java +++ b/vespajlib/src/main/java/com/yahoo/slime/ArrayValue.java @@ -1,6 +1,9 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.slime; +/** + * @author havardpe + */ final class ArrayValue extends Value { private int capacity = 16; diff --git a/vespajlib/src/main/java/com/yahoo/slime/BoolValue.java b/vespajlib/src/main/java/com/yahoo/slime/BoolValue.java index 00f3adf82a1..5f40050a7df 100644 --- a/vespajlib/src/main/java/com/yahoo/slime/BoolValue.java +++ b/vespajlib/src/main/java/com/yahoo/slime/BoolValue.java @@ -1,13 +1,18 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.slime; +/** + * @author havardpe + */ final class BoolValue extends Value { + private static final BoolValue trueValue = new BoolValue(true); private static final BoolValue falseValue = new BoolValue(false); private final boolean value; private BoolValue(boolean value) { this.value = value; } - final public Type type() { return Type.BOOL; } - final public boolean asBool() { return this.value; } - public final void accept(Visitor v) { v.visitBool(value); } + public Type type() { return Type.BOOL; } + public boolean asBool() { return this.value; } + public void accept(Visitor v) { v.visitBool(value); } public static BoolValue instance(boolean bit) { return (bit ? trueValue : falseValue); } + } diff --git a/vespajlib/src/main/java/com/yahoo/slime/Cursor.java b/vespajlib/src/main/java/com/yahoo/slime/Cursor.java index 2696e923bd5..e6493a2ba4c 100644 --- a/vespajlib/src/main/java/com/yahoo/slime/Cursor.java +++ b/vespajlib/src/main/java/com/yahoo/slime/Cursor.java @@ -16,270 +16,298 @@ package com.yahoo.slime; * not connected to an array value (for add methods), or it's not * connected to an object (for set methods). Also note that you can * only set() a field once; you cannot overwrite the field in any way. - **/ + * + * @author havardpe + */ public interface Cursor extends Inspector { /** - * Access an array entry. + * Accesses an array entry. * * If the current Cursor doesn't connect to an array value, * or the given array index is out of bounds, the returned * Cursor will be invalid. - * @param idx array index. - * @return a new Cursor for the entry value. - **/ + * + * @param idx array index + * @return a new Cursor for the entry value + */ @Override - public Cursor entry(int idx); + Cursor entry(int idx); /** - * Access an field in an object by symbol id. + * Accesses a field in an object by symbol id. * * If the current Cursor doesn't connect to an object value, or * the object value does not contain a field with the given symbol * id, the returned Cursor will be invalid. - * @param sym symbol id. - * @return a new Cursor for the field value. - **/ + * + * @param sym symbol id + * @return a new Cursor for the field value + */ @Override - public Cursor field(int sym); + Cursor field(int sym); /** - * Access an field in an object by symbol name. + * Accesses a field in an object by symbol name. * * If the current Cursor doesn't connect to an object value, or * the object value does not contain a field with the given symbol * name, the returned Cursor will be invalid. - * @param name symbol name. - * @return a new Cursor for the field value. - **/ + * + * @param name symbol name + * @return a new Cursor for the field value + */ @Override - public Cursor field(String name); + Cursor field(String name); /** - * Append an array entry containing a new value of NIX type. + * Appends an array entry containing a new value of NIX type. * Returns an invalid Cursor if unsuccessful. - * @return a valid Cursor referencing the new entry value if successful. - **/ - public Cursor addNix(); + * + * @return a valid Cursor referencing the new entry value if successful + */ + Cursor addNix(); /** - * Append an array entry containing a new value of BOOL type. + * Appends an array entry containing a new value of BOOL type. * Returns an invalid Cursor if unsuccessful. - * @param bit the actual boolean value for initializing a new BoolValue. - * @return a valid Cursor referencing the new entry value if successful. - **/ - public Cursor addBool(boolean bit); + * + * @param bit the actual boolean value for initializing a new BoolValue + * @return a valid Cursor referencing the new entry value if successful + */ + Cursor addBool(boolean bit); - /** add a new entry of LONG type to an array */ - public Cursor addLong(long l); + /** Adds a new entry of LONG type to an array. */ + Cursor addLong(long l); - /** add a new entry of DOUBLE type to an array */ - public Cursor addDouble(double d); + /** Adds a new entry of DOUBLE type to an array. */ + Cursor addDouble(double d); - /** add a new entry of STRING type to an array */ - public Cursor addString(String str); + /** Add a new entry of STRING type to an array. */ + Cursor addString(String str); - /** add a new entry of STRING type to an array */ - public Cursor addString(byte[] utf8); + /** Add a new entry of STRING type to an array. */ + Cursor addString(byte[] utf8); - /** add a new entry of DATA type to an array */ - public Cursor addData(byte[] data); + /** Add a new entry of DATA type to an array. */ + Cursor addData(byte[] data); /** - * Append an array entry containing a new value of ARRAY type. + * Appends an array entry containing a new value of ARRAY type. * Returns a valid Cursor (thay may again be used for adding new * sub-array entries) referencing the new entry value if * successful; otherwise returns an invalid Cursor. - * @return new Cursor for the new entry value - **/ - public Cursor addArray(); + * + * @return a new Cursor for the new entry value + */ + Cursor addArray(); /** - * Append an array entry containing a new value of OBJECT type. + * Appends an array entry containing a new value of OBJECT type. * Returns a valid Cursor (thay may again be used for setting * sub-fields inside the new object) referencing the new entry * value if successful; otherwise returns an invalid Cursor. - * @return new Cursor for the new entry value - **/ - public Cursor addObject(); + * + * @return a new Cursor for the new entry value + */ + Cursor addObject(); /** - * Set a field (identified with a symbol id) to contain a new + * Sets a field (identified with a symbol id) to contain a new * value of NIX type. Returns a valid Cursor referencing the new * field value if successful; otherwise returns an invalid Cursor. + * * @param sym symbol id for the field to be set * @return new Cursor for the new field value - **/ - public Cursor setNix(int sym); + */ + Cursor setNix(int sym); /** - * Set a field (identified with a symbol id) to contain a new + * Sets a field (identified with a symbol id) to contain a new * value of BOOL type. Returns a valid Cursor referencing the new * field value if successful; otherwise returns an invalid Cursor. + * * @param sym symbol id for the field to be set * @param bit the actual boolean value for the new field * @return new Cursor for the new field value - **/ - public Cursor setBool(int sym, boolean bit); + */ + Cursor setBool(int sym, boolean bit); /** - * Set a field (identified with a symbol id) to contain a new + * Sets a field (identified with a symbol id) to contain a new * value of BOOL type. Returns a valid Cursor referencing the new * field value if successful; otherwise returns an invalid Cursor. + * * @param sym symbol id for the field to be set * @param l the actual long value for the new field * @return new Cursor for the new field value - **/ - public Cursor setLong(int sym, long l); + */ + Cursor setLong(int sym, long l); /** - * Set a field (identified with a symbol id) to contain a new + * Sets a field (identified with a symbol id) to contain a new * value of BOOL type. Returns a valid Cursor referencing the new * field value if successful; otherwise returns an invalid Cursor. + * * @param sym symbol id for the field to be set * @param d the actual double value for the new field * @return new Cursor for the new field value - **/ - public Cursor setDouble(int sym, double d); + */ + Cursor setDouble(int sym, double d); /** - * Set a field (identified with a symbol id) to contain a new + * Sets a field (identified with a symbol id) to contain a new * value of BOOL type. Returns a valid Cursor referencing the new * field value if successful; otherwise returns an invalid Cursor. + * * @param sym symbol id for the field to be set * @param str the actual string for the new field - * @return new Cursor for the new field value - **/ - public Cursor setString(int sym, String str); + * @return a new Cursor for the new field value + */ + Cursor setString(int sym, String str); /** - * Set a field (identified with a symbol id) to contain a new + * Sets a field (identified with a symbol id) to contain a new * value of BOOL type. Returns a valid Cursor referencing the new * field value if successful; otherwise returns an invalid Cursor. + * * @param sym symbol id for the field to be set * @param utf8 the actual string (encoded as UTF-8 data) for the new field - * @return new Cursor for the new field value - **/ - public Cursor setString(int sym, byte[] utf8); + * @return a new Cursor for the new field value + */ + Cursor setString(int sym, byte[] utf8); /** - * Set a field (identified with a symbol id) to contain a new + * Sets a field (identified with a symbol id) to contain a new * value of BOOL type. Returns a valid Cursor referencing the new * field value if successful; otherwise returns an invalid Cursor. + * * @param sym symbol id for the field to be set * @param data the actual data to be put into the new field - * @return new Cursor for the new field value - **/ - public Cursor setData(int sym, byte[] data); + * @return a new Cursor for the new field value + */ + Cursor setData(int sym, byte[] data); /** - * Set a field (identified with a symbol id) to contain a new + * Sets a field (identified with a symbol id) to contain a new * value of ARRAY type. Returns a valid Cursor (thay may again be * used for adding new array entries) referencing the new field * value if successful; otherwise returns an invalid Cursor. + * * @param sym symbol id for the field to be set - * @return new Cursor for the new field value - **/ - public Cursor setArray(int sym); + * @return a new Cursor for the new field value + */ + Cursor setArray(int sym); /** - * Set a field (identified with a symbol id) to contain a new + * Sets a field (identified with a symbol id) to contain a new * value of OBJECT type. Returns a valid Cursor (thay may again * be used for setting sub-fields inside the new object) * referencing the new field value if successful; otherwise * returns an invalid Cursor. + * * @param sym symbol id for the field to be set - * @return new Cursor for the new field value - **/ - public Cursor setObject(int sym); + * @return a new Cursor for the new field value + */ + Cursor setObject(int sym); /** - * Set a field (identified with a symbol name) to contain a new + * Sets a field (identified with a symbol name) to contain a new * value of NIX type. Returns a valid Cursor referencing the new * field value if successful; otherwise returns an invalid Cursor. + * * @param name symbol name for the field to be set - * @return new Cursor for the new field value - **/ - public Cursor setNix(String name); + * @return a new Cursor for the new field value + */ + Cursor setNix(String name); /** - * Set a field (identified with a symbol name) to contain a new + * Sets a field (identified with a symbol name) to contain a new * value of BOOL type. Returns a valid Cursor referencing the new * field value if successful; otherwise returns an invalid Cursor. + * * @param name symbol name for the field to be set * @param bit the actual boolean value for the new field - * @return new Cursor for the new field value - **/ - public Cursor setBool(String name, boolean bit); + * @return a new Cursor for the new field value + */ + Cursor setBool(String name, boolean bit); /** - * Set a field (identified with a symbol name) to contain a new + * Sets a field (identified with a symbol name) to contain a new * value of LONG type. Returns a valid Cursor referencing the new * field value if successful; otherwise returns an invalid Cursor. + * * @param name symbol name for the field to be set * @param l the actual long value for the new field - * @return new Cursor for the new field value - **/ - public Cursor setLong(String name, long l); + * @return a new Cursor for the new field value + */ + Cursor setLong(String name, long l); /** - * Set a field (identified with a symbol name) to contain a new + * Sets a field (identified with a symbol name) to contain a new * value of DOUBLE type. Returns a valid Cursor referencing the new * field value if successful; otherwise returns an invalid Cursor. + * * @param name symbol name for the field to be set * @param d the actual double value for the new field - * @return new Cursor for the new field value - **/ - public Cursor setDouble(String name, double d); + * @return a new Cursor for the new field value + */ + Cursor setDouble(String name, double d); /** - * Set a field (identified with a symbol name) to contain a new + * Sets a field (identified with a symbol name) to contain a new * value of STRING type. Returns a valid Cursor referencing the new * field value if successful; otherwise returns an invalid Cursor. + * * @param name symbol name for the field to be set * @param str the actual string for the new field - * @return new Cursor for the new field value - **/ - public Cursor setString(String name, String str); + * @return a new Cursor for the new field value + */ + Cursor setString(String name, String str); /** - * Set a field (identified with a symbol name) to contain a new + * Sets a field (identified with a symbol name) to contain a new * value of STRING type. Returns a valid Cursor referencing the new * field value if successful; otherwise returns an invalid Cursor. + * * @param name symbol name for the field to be set * @param utf8 the actual string (encoded as UTF-8 data) for the new field - * @return new Cursor for the new field value - **/ - public Cursor setString(String name, byte[] utf8); + * @return a new Cursor for the new field value + */ + Cursor setString(String name, byte[] utf8); /** - * Set a field (identified with a symbol name) to contain a new + * Sets a field (identified with a symbol name) to contain a new * value of DATA type. Returns a valid Cursor referencing the new * field value if successful; otherwise returns an invalid Cursor. + * * @param name symbol name for the field to be set * @param data the actual data to be put into the new field - * @return new Cursor for the new field value - **/ - public Cursor setData(String name, byte[] data); + * @return a new Cursor for the new field value + */ + Cursor setData(String name, byte[] data); /** - * Set a field (identified with a symbol name) to contain a new + * Sets a field (identified with a symbol name) to contain a new * value of ARRAY type. Returns a valid Cursor (thay may again be * used for adding new array entries) referencing the new field * value if successful; otherwise returns an invalid Cursor. + * * @param name symbol name for the field to be set - * @return new Cursor for the new field value - **/ - public Cursor setArray(String name); + * @return a new Cursor for the new field value + */ + Cursor setArray(String name); /** - * Set a field (identified with a symbol name) to contain a new + * Sets a field (identified with a symbol name) to contain a new * value of OBJECT type. Returns a valid Cursor (thay may again * be used for setting sub-fields inside the new object) * referencing the new field value if successful; otherwise * returns an invalid Cursor. + * * @param name symbol name for the field to be set - * @return new Cursor for the new field value - **/ - public Cursor setObject(String name); + * @return a new Cursor for the new field value + */ + Cursor setObject(String name); + } diff --git a/vespajlib/src/main/java/com/yahoo/slime/DataValue.java b/vespajlib/src/main/java/com/yahoo/slime/DataValue.java index 5081b3fdbc7..91f20335eb1 100644 --- a/vespajlib/src/main/java/com/yahoo/slime/DataValue.java +++ b/vespajlib/src/main/java/com/yahoo/slime/DataValue.java @@ -1,7 +1,11 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.slime; +/** + * @author havardpe + */ final class DataValue extends Value { + private final byte[] value; private DataValue(byte[] value) { this.value = value; } public static Value create(byte[] value) { @@ -11,7 +15,8 @@ final class DataValue extends Value { return new DataValue(value); } } - public final Type type() { return Type.DATA; } - public final byte[] asData() { return this.value; } - public final void accept(Visitor v) { v.visitData(value); } + public Type type() { return Type.DATA; } + public byte[] asData() { return this.value; } + public void accept(Visitor v) { v.visitData(value); } + } diff --git a/vespajlib/src/main/java/com/yahoo/slime/DoubleValue.java b/vespajlib/src/main/java/com/yahoo/slime/DoubleValue.java index 22b685d5419..23f636f126d 100644 --- a/vespajlib/src/main/java/com/yahoo/slime/DoubleValue.java +++ b/vespajlib/src/main/java/com/yahoo/slime/DoubleValue.java @@ -1,11 +1,16 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.slime; +/** + * @author havardpe + */ final class DoubleValue extends Value { + private final double value; public DoubleValue(double value) { this.value = value; } - public final Type type() { return Type.DOUBLE; } - public final long asLong() { return (long)this.value; } - public final double asDouble() { return this.value; } - public final void accept(Visitor v) { v.visitDouble(value); } + public Type type() { return Type.DOUBLE; } + public long asLong() { return (long)this.value; } + public double asDouble() { return this.value; } + public void accept(Visitor v) { v.visitDouble(value); } + } diff --git a/vespajlib/src/main/java/com/yahoo/slime/JsonDecoder.java b/vespajlib/src/main/java/com/yahoo/slime/JsonDecoder.java index d6818907bf3..788e872f5ce 100644 --- a/vespajlib/src/main/java/com/yahoo/slime/JsonDecoder.java +++ b/vespajlib/src/main/java/com/yahoo/slime/JsonDecoder.java @@ -77,7 +77,7 @@ public class JsonDecoder { @SuppressWarnings("fallthrough") private void decodeNumber(Inserter inserter) { buf.reset(); - boolean likelyFloatingPoint=false; + boolean likelyFloatingPoint = false; for (;;) { switch (c) { case '.': case 'e': case 'E': diff --git a/vespajlib/src/main/java/com/yahoo/slime/LongValue.java b/vespajlib/src/main/java/com/yahoo/slime/LongValue.java index 62752f2b27c..e728e890274 100644 --- a/vespajlib/src/main/java/com/yahoo/slime/LongValue.java +++ b/vespajlib/src/main/java/com/yahoo/slime/LongValue.java @@ -1,11 +1,16 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.slime; +/** + * @author havardpe + */ final class LongValue extends Value { + private final long value; public LongValue(long value) { this.value = value; } - public final Type type() { return Type.LONG; } - public final long asLong() { return this.value; } - public final double asDouble() { return (double)this.value; } - public final void accept(Visitor v) { v.visitLong(value); } + public Type type() { return Type.LONG; } + public long asLong() { return this.value; } + public double asDouble() { return this.value; } + public void accept(Visitor v) { v.visitLong(value); } + } diff --git a/vespajlib/src/main/java/com/yahoo/slime/NixValue.java b/vespajlib/src/main/java/com/yahoo/slime/NixValue.java index b65cd1dabbf..4ae60f26f07 100644 --- a/vespajlib/src/main/java/com/yahoo/slime/NixValue.java +++ b/vespajlib/src/main/java/com/yahoo/slime/NixValue.java @@ -1,12 +1,16 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.slime; +/** + * @author havardpe + */ final class NixValue extends Value { + private static final NixValue invalidNix = new NixValue(); private static final NixValue validNix = new NixValue(); private NixValue() {} - public final Type type() { return Type.NIX; } - public final void accept(Visitor v) { + public Type type() { return Type.NIX; } + public void accept(Visitor v) { if (valid()) { v.visitNix(); } else { @@ -15,4 +19,5 @@ final class NixValue extends Value { } public static NixValue invalid() { return invalidNix; } public static NixValue instance() { return validNix; } + } diff --git a/vespajlib/src/main/java/com/yahoo/slime/ObjectValue.java b/vespajlib/src/main/java/com/yahoo/slime/ObjectValue.java index 33d2e5be4ed..6ba16f8dd6c 100644 --- a/vespajlib/src/main/java/com/yahoo/slime/ObjectValue.java +++ b/vespajlib/src/main/java/com/yahoo/slime/ObjectValue.java @@ -6,7 +6,9 @@ package com.yahoo.slime; * value fields. Fields can be inspected or traversed using the * {@link Inspector} interface, and you can add new fields by using the * various "set" methods in the @ref Cursor interface. - **/ + * + * @author havardpe + */ final class ObjectValue extends Value { private int capacity = 16; @@ -16,7 +18,7 @@ final class ObjectValue extends Value { private int[] hash = new int[capacity + hashSize() + (capacity << 1)]; private final SymbolTable names; - private final void rehash() { + private void rehash() { capacity = (capacity << 1); Value[] v = values; values = new Value[capacity]; @@ -37,7 +39,7 @@ final class ObjectValue extends Value { } } - private final Value put(int sym, Value value) { + private Value put(int sym, Value value) { if (used == capacity) { rehash(); } @@ -59,7 +61,7 @@ final class ObjectValue extends Value { return value; } - private final Value get(int sym) { + private Value get(int sym) { int entry = hash[capacity + (sym % hashSize())]; while (entry != 0) { final int idx = hash[entry]; @@ -77,32 +79,33 @@ final class ObjectValue extends Value { put(sym, value); } - public final Type type() { return Type.OBJECT; } - public final int children() { return used; } - public final int fields() { return used; } + public Type type() { return Type.OBJECT; } + public int children() { return used; } + public int fields() { return used; } - public final Value field(int sym) { return get(sym); } - public final Value field(String name) { return get(names.lookup(name)); } + public Value field(int sym) { return get(sym); } + public Value field(String name) { return get(names.lookup(name)); } - public final void accept(Visitor v) { v.visitObject(this); } + public void accept(Visitor v) { v.visitObject(this); } - public final void traverse(ObjectSymbolTraverser ot) { + public void traverse(ObjectSymbolTraverser ot) { for (int i = 0; i < used; ++i) { ot.field(hash[i], values[i]); } } - public final void traverse(ObjectTraverser ot) { + public void traverse(ObjectTraverser ot) { for (int i = 0; i < used; ++i) { ot.field(names.inspect(hash[i]), values[i]); } } - protected final Cursor setLeaf(int sym, Value value) { return put(sym, value); } - public final Cursor setArray(int sym) { return put(sym, new ArrayValue(names)); } - public final Cursor setObject(int sym) { return put(sym, new ObjectValue(names)); } + protected Cursor setLeaf(int sym, Value value) { return put(sym, value); } + public Cursor setArray(int sym) { return put(sym, new ArrayValue(names)); } + public Cursor setObject(int sym) { return put(sym, new ObjectValue(names)); } + + protected Cursor setLeaf(String name, Value value) { return put(names.insert(name), value); } + public Cursor setArray(String name) { return put(names.insert(name), new ArrayValue(names)); } + public Cursor setObject(String name) { return put(names.insert(name), new ObjectValue(names)); } - protected final Cursor setLeaf(String name, Value value) { return put(names.insert(name), value); } - public final Cursor setArray(String name) { return put(names.insert(name), new ArrayValue(names)); } - public final Cursor setObject(String name) { return put(names.insert(name), new ObjectValue(names)); } } diff --git a/vespajlib/src/main/java/com/yahoo/slime/StringValue.java b/vespajlib/src/main/java/com/yahoo/slime/StringValue.java index fbd4e150f7e..d7a7281ca1d 100644 --- a/vespajlib/src/main/java/com/yahoo/slime/StringValue.java +++ b/vespajlib/src/main/java/com/yahoo/slime/StringValue.java @@ -4,8 +4,11 @@ package com.yahoo.slime; /** * A value holding a String in Java native format. * See also @ref Utf8Value (for lazy decoding). - **/ + * + * @author havardpe + */ final class StringValue extends Value { + private final String value; private byte[] utf8; private StringValue(String value) { this.value = value; } @@ -16,13 +19,14 @@ final class StringValue extends Value { return new StringValue(value); } } - public final Type type() { return Type.STRING; } - public final String asString() { return this.value; } - public final byte[] asUtf8() { + public Type type() { return Type.STRING; } + public String asString() { return this.value; } + public byte[] asUtf8() { if (utf8 == null) { utf8 = Utf8Codec.encode(value); } return utf8; } - public final void accept(Visitor v) { v.visitString(value); } + public void accept(Visitor v) { v.visitString(value); } + } diff --git a/vespajlib/src/main/java/com/yahoo/slime/Utf8Value.java b/vespajlib/src/main/java/com/yahoo/slime/Utf8Value.java index 3ddcf4e4e24..4ea0dcc6a6e 100644 --- a/vespajlib/src/main/java/com/yahoo/slime/Utf8Value.java +++ b/vespajlib/src/main/java/com/yahoo/slime/Utf8Value.java @@ -5,8 +5,11 @@ package com.yahoo.slime; * A value type encapsulating a String in its UTF-8 representation. * Useful for lazy decoding; if the data is just passed through in * UTF-8 it will never be converted at all. - **/ + * + * @author havardpe + */ final class Utf8Value extends Value { + private final byte[] value; private String string; private Utf8Value(byte[] value) { this.value = value; } @@ -17,13 +20,14 @@ final class Utf8Value extends Value { return new Utf8Value(value); } } - public final Type type() { return Type.STRING; } - public final String asString() { + public Type type() { return Type.STRING; } + public String asString() { if (string == null) { string = Utf8Codec.decode(value, 0, value.length); } return string; } - public final byte[] asUtf8() { return value; } - public final void accept(Visitor v) { v.visitString(value); } + public byte[] asUtf8() { return value; } + public void accept(Visitor v) { v.visitString(value); } + } diff --git a/vespajlib/src/main/java/com/yahoo/slime/Value.java b/vespajlib/src/main/java/com/yahoo/slime/Value.java index 181dc033f3f..ffb6ff66260 100644 --- a/vespajlib/src/main/java/com/yahoo/slime/Value.java +++ b/vespajlib/src/main/java/com/yahoo/slime/Value.java @@ -1,16 +1,16 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.slime; - import java.io.ByteArrayOutputStream; import java.util.Arrays; /** * Common implementation for all value types. * All default behavior is here, so specific types only - * need override their actually useful parts. - **/ - + * need override their actually useful parts + * + * @author havardpoe + */ abstract class Value implements Cursor { private static final String emptyString = ""; |