summaryrefslogtreecommitdiffstats
path: root/vespajlib
diff options
context:
space:
mode:
authorJon Bratseth <bratseth@yahoo-inc.com>2017-08-30 13:27:07 +0200
committerJon Bratseth <bratseth@yahoo-inc.com>2017-08-30 13:27:07 +0200
commit2b06022f3ebc63bd211961c83307bbf4f4c286cb (patch)
tree7c67c36b494c5dd6cd5598e5749fe9c3d8836e62 /vespajlib
parent6c5dc8f0bdabeec182ee4ebe566080f8a7ff072f (diff)
Nonfunctional changes
Diffstat (limited to 'vespajlib')
-rw-r--r--vespajlib/src/main/java/com/yahoo/data/access/Inspector.java79
-rw-r--r--vespajlib/src/main/java/com/yahoo/slime/Inspector.java61
-rw-r--r--vespajlib/src/main/java/com/yahoo/slime/Slime.java47
3 files changed, 104 insertions, 83 deletions
diff --git a/vespajlib/src/main/java/com/yahoo/data/access/Inspector.java b/vespajlib/src/main/java/com/yahoo/data/access/Inspector.java
index 5bf8016aad3..bb4487e68d6 100644
--- a/vespajlib/src/main/java/com/yahoo/data/access/Inspector.java
+++ b/vespajlib/src/main/java/com/yahoo/data/access/Inspector.java
@@ -12,7 +12,9 @@ import java.util.Map;
* Instrospection methods are available, but you can also use accessors
* with a default value if you expect a certain type and just want your
* default value if some field doesn't exist or was of the wrong type.
- **/
+ *
+ * @author havardpe
+ */
public interface Inspector extends Inspectable {
/**
@@ -20,55 +22,55 @@ public interface Inspector extends Inspectable {
* If you try to access a field or array entry that does not exist,
* you will get an invalid Inspector returned.
*/
- public boolean valid();
+ boolean valid();
/** Get the type of an inspector */
- public Type type();
+ Type type();
/** Get the number of entries in an ARRAY (always returns 0 for non-arrays) */
- public int entryCount();
+ int entryCount();
/** Get the number of fields in an OBJECT (always returns 0 for non-objects) */
- public int fieldCount();
+ int fieldCount();
/** Access the inspector's value if it's a BOOLEAN; otherwise throws exception */
- public boolean asBool();
+ boolean asBool();
/** Access the inspector's value if it's a LONG (or DOUBLE); otherwise throws exception */
- public long asLong();
+ long asLong();
/** Access the inspector's value if it's a DOUBLE (or LONG); otherwise throws exception */
- public double asDouble();
+ double asDouble();
/** Access the inspector's value if it's a STRING; otherwise throws exception */
- public String asString();
+ String asString();
/**
* Access the inspector's value (in utf-8 representation) if it's
* a STRING; otherwise throws exception
- **/
- public byte[] asUtf8();
+ */
+ byte[] asUtf8();
/** Access the inspector's value if it's DATA; otherwise throws exception */
- public byte[] asData();
+ byte[] asData();
/** Get the inspector's value (or the supplied default), never throws */
- public boolean asBool(boolean defaultValue);
+ boolean asBool(boolean defaultValue);
/** Get the inspector's value (or the supplied default), never throws */
- public long asLong(long defaultValue);
+ long asLong(long defaultValue);
/** Get the inspector's value (or the supplied default), never throws */
- public double asDouble(double defaultValue);
+ double asDouble(double defaultValue);
/** Get the inspector's value (or the supplied default), never throws */
- public String asString(String defaultValue);
+ String asString(String defaultValue);
/** Get the inspector's value (or the supplied default), never throws */
- public byte[] asUtf8(byte[] defaultValue);
+ byte[] asUtf8(byte[] defaultValue);
/** Get the inspector's value (or the supplied default), never throws */
- public byte[] asData(byte[] defaultValue);
+ byte[] asData(byte[] defaultValue);
/**
* Traverse an array value, performing callbacks for each entry.
@@ -76,10 +78,11 @@ public interface Inspector extends Inspectable {
* If the current Inspector is connected to an array value,
* perform callbacks to the given traverser for each entry
* contained in the array. Otherwise a no-op.
- * @param at traverser callback object.
- **/
+ *
+ * @param at traverser callback object
+ */
@SuppressWarnings("overloads")
- public void traverse(ArrayTraverser at);
+ void traverse(ArrayTraverser at);
/**
* Traverse an object value, performing callbacks for each field.
@@ -87,10 +90,11 @@ public interface Inspector extends Inspectable {
* If the current Inspector is connected to an object value,
* perform callbacks to the given traverser for each field
* contained in the object. Otherwise a no-op.
- * @param ot traverser callback object.
- **/
+ *
+ * @param ot traverser callback object
+ */
@SuppressWarnings("overloads")
- public void traverse(ObjectTraverser ot);
+ void traverse(ObjectTraverser ot);
/**
* Access an array entry.
@@ -98,10 +102,11 @@ public interface Inspector extends Inspectable {
* If the current Inspector doesn't connect to an array value,
* or the given array index is out of bounds, the returned
* Inspector will be invalid.
- * @param idx array index.
- * @return a new Inspector for the entry value.
- **/
- public Inspector entry(int idx);
+ *
+ * @param idx array index
+ * @return a new Inspector for the entry value
+ */
+ Inspector entry(int idx);
/**
* Access an field in an object.
@@ -109,20 +114,22 @@ public interface Inspector extends Inspectable {
* If the current Inspector doesn't connect to an object value, or
* the object value does not contain a field with the given symbol
* name, the returned Inspector will be invalid.
- * @param name symbol name.
- * @return a new Inspector for the field value.
- **/
- public Inspector field(String name);
+ *
+ * @param name symbol name
+ * @return a new Inspector for the field value
+ */
+ Inspector field(String name);
/**
* Convert an array to an iterable list. Other types will just
* return an empty list.
- **/
- public Iterable<Inspector> entries();
+ */
+ Iterable<Inspector> entries();
/**
* Convert an object to an iterable list of (name, value) pairs.
* Other types will just return an empty list.
- **/
- public Iterable<Map.Entry<String,Inspector>> fields();
+ */
+ Iterable<Map.Entry<String,Inspector>> fields();
+
}
diff --git a/vespajlib/src/main/java/com/yahoo/slime/Inspector.java b/vespajlib/src/main/java/com/yahoo/slime/Inspector.java
index 89e7b3383fc..99489faca47 100644
--- a/vespajlib/src/main/java/com/yahoo/slime/Inspector.java
+++ b/vespajlib/src/main/java/com/yahoo/slime/Inspector.java
@@ -9,59 +9,61 @@ package com.yahoo.slime;
* current Inspector is invalid or the type doesn't match your
* accessor type. If you want to do something exceptional instead
* when the types don't match, you must check using type() first.
- **/
+ *
+ * @author havardpe
+ */
public interface Inspector {
/** check if this inspector is valid */
- public boolean valid();
+ boolean valid();
/** return an enum describing value type */
- public Type type();
+ Type type();
/**
* Check how many entries or fields are contained in the current value.
* Useful for arrays and objects; anything else always returns 0.
* @return number of entries/fields contained.
- **/
- public int children();
+ */
+ int children();
/**
* Check how many entries are contained in the current value.
* Useful for arrays; anything else always returns 0.
* @return number of entries contained.
- **/
- public int entries();
+ */
+ int entries();
/**
* Check how many fields are contained in the current value.
* Useful for objects; anything else always returns 0.
* @return number of fields contained.
- **/
- public int fields();
+ */
+ int fields();
/** the current value (for booleans); default: false */
- public boolean asBool();
+ boolean asBool();
/** the current value (for integers); default: 0 */
- public long asLong();
+ long asLong();
/** the current value (for floating-point values); default: 0.0 */
- public double asDouble();
+ double asDouble();
/** the current value (for string values); default: empty string */
- public String asString();
+ String asString();
/** the current value encoded into UTF-8 (for string values); default: empty array */
- public byte[] asUtf8();
+ byte[] asUtf8();
/** the current value (for data values); default: empty array */
- public byte[] asData();
+ byte[] asData();
/**
* Use the visitor pattern to resolve the underlying type of this value.
* @param v the visitor
- **/
- public void accept(Visitor v);
+ */
+ void accept(Visitor v);
/**
* Traverse an array value, performing callbacks for each entry.
@@ -70,9 +72,9 @@ public interface Inspector {
* perform callbacks to the given traverser for each entry
* contained in the array.
* @param at traverser callback object.
- **/
+ */
@SuppressWarnings("overloads")
- public void traverse(ArrayTraverser at);
+ void traverse(ArrayTraverser at);
/**
* Traverse an object value, performing callbacks for each field.
@@ -81,9 +83,9 @@ public interface Inspector {
* perform callbacks to the given traverser for each field
* contained in the object.
* @param ot traverser callback object.
- **/
+ */
@SuppressWarnings("overloads")
- public void traverse(ObjectSymbolTraverser ot);
+ void traverse(ObjectSymbolTraverser ot);
/**
* Traverse an object value, performing callbacks for each field.
@@ -92,9 +94,9 @@ public interface Inspector {
* perform callbacks to the given traverser for each field
* contained in the object.
* @param ot traverser callback object.
- **/
+ */
@SuppressWarnings("overloads")
- public void traverse(ObjectTraverser ot);
+ void traverse(ObjectTraverser ot);
/**
* Access an array entry.
@@ -104,8 +106,8 @@ public interface Inspector {
* Inspector will be invalid.
* @param idx array index.
* @return a new Inspector for the entry value.
- **/
- public Inspector entry(int idx);
+ */
+ Inspector entry(int idx);
/**
* Access an field in an object by symbol id.
@@ -115,8 +117,8 @@ public interface Inspector {
* id, the returned Inspector will be invalid.
* @param sym symbol id.
* @return a new Inspector for the field value.
- **/
- public Inspector field(int sym);
+ */
+ Inspector field(int sym);
/**
* Access an field in an object by symbol name.
@@ -126,6 +128,7 @@ public interface Inspector {
* name, the returned Inspector will be invalid.
* @param name symbol name.
* @return a new Inspector for the field value.
- **/
- public Inspector field(String name);
+ */
+ Inspector field(String name);
+
}
diff --git a/vespajlib/src/main/java/com/yahoo/slime/Slime.java b/vespajlib/src/main/java/com/yahoo/slime/Slime.java
index b601d0b72ff..84f193caa4d 100644
--- a/vespajlib/src/main/java/com/yahoo/slime/Slime.java
+++ b/vespajlib/src/main/java/com/yahoo/slime/Slime.java
@@ -5,26 +5,29 @@ package com.yahoo.slime;
* Top-level value class that contains one Value data object and a
* symbol table (shared between all directly or indirectly contained
* ObjectValue data objects).
+ *
+ * @author havardpe
**/
-public final class Slime
-{
+public final class Slime {
+
private final SymbolTable names = new SymbolTable();
private Value root = NixValue.instance();
/**
* Construct an empty Slime with an empty top-level value.
- **/
+ */
public Slime() {}
- /** return count of names in the symbol table. */
+ /** Returns a count of names in the symbol table. */
public int symbols() {
return names.symbols();
}
/**
* Return the symbol name associated with an id.
+ *
* @param symbol the id, must be in range [0, symbols()-1]
- **/
+ */
public String inspect(int symbol) {
return names.inspect(symbol);
}
@@ -32,9 +35,10 @@ public final class Slime
/**
* Add a name to the symbol table; if the name is already
* in the symbol table just returns the id it already had.
+ *
* @param name the name to insert
* @return the id now associated with the name
- **/
+ */
public int insert(String name) {
return names.insert(name);
}
@@ -43,7 +47,7 @@ public final class Slime
* Find the id associated with a symbol name; if the
* name was not in the symbol table returns the
* constant Integer.MAX_VALUE instead.
- **/
+ */
public int lookup(String name) {
return names.lookup(name);
}
@@ -53,7 +57,7 @@ public final class Slime
/**
* Create a new empty value and make it the new top-level data object.
- **/
+ */
public Cursor setNix() {
root = NixValue.instance();
return root;
@@ -61,8 +65,9 @@ public final class Slime
/**
* Create a new boolean value and make it the new top-level data object.
+ *
* @param bit the actual boolean value for the new value
- **/
+ */
public Cursor setBool(boolean bit) {
root = BoolValue.instance(bit);
return root;
@@ -70,8 +75,9 @@ public final class Slime
/**
* Create a new double value and make it the new top-level data object.
+ *
* @param l the actual long value for the new value
- **/
+ */
public Cursor setLong(long l) {
root = new LongValue(l);
return root;
@@ -79,8 +85,9 @@ public final class Slime
/**
* Create a new double value and make it the new top-level data object.
+ *
* @param d the actual double value for the new value
- **/
+ */
public Cursor setDouble(double d) {
root = new DoubleValue(d);
return root;
@@ -88,8 +95,9 @@ public final class Slime
/**
* Create a new string value and make it the new top-level data object.
+ *
* @param str the actual string for the new value
- **/
+ */
public Cursor setString(String str) {
root = StringValue.create(str);
return root;
@@ -97,8 +105,9 @@ public final class Slime
/**
* Create a new string value and make it the new top-level data object.
+ *
* @param utf8 the actual string (encoded as UTF-8 data) for the new value
- **/
+ */
public Cursor setString(byte[] utf8) {
root = Utf8Value.create(utf8);
return root;
@@ -106,8 +115,9 @@ public final class Slime
/**
* Create a new data value and make it the new top-level data object.
+ *
* @param data the actual data to be put into the new value.
- **/
+ */
public Cursor setData(byte[] data) {
root = DataValue.create(data);
return root;
@@ -115,7 +125,7 @@ public final class Slime
/**
* Create a new array value and make it the new top-level data object.
- **/
+ */
public Cursor setArray() {
root = new ArrayValue(names);
return root;
@@ -123,7 +133,7 @@ public final class Slime
/**
* Create a new object value and make it the new top-level data object.
- **/
+ */
public Cursor setObject() {
root = new ObjectValue(names);
return root;
@@ -133,7 +143,7 @@ public final class Slime
* Take the current top-level data object and make it a field in a
* new ObjectValue with the given symbol id as field id; the new
* ObjectValue will also become the new top-level data object.
- **/
+ */
public Cursor wrap(int sym) {
root = new ObjectValue(names, sym, root);
return root;
@@ -143,8 +153,9 @@ public final class Slime
* Take the current top-level data object and make it a field in a
* new ObjectValue with the given symbol name as field name; the new
* ObjectValue will also become the new top-level data object.
- **/
+ */
public Cursor wrap(String name) {
return wrap(names.insert(name));
}
+
}