Package com.yahoo.data.access.simple
Class Value
- java.lang.Object
-
- com.yahoo.data.access.simple.Value
-
- All Implemented Interfaces:
Inspectable
,Inspector
- Direct Known Subclasses:
Value.ArrayValue
,Value.BoolValue
,Value.DataValue
,Value.DoubleValue
,Value.EmptyValue
,Value.LongValue
,Value.ObjectValue
,Value.StringValue
public class Value extends java.lang.Object implements Inspector
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
Value.ArrayValue
static class
Value.BoolValue
static class
Value.DataValue
static class
Value.DoubleValue
static class
Value.EmptyValue
static class
Value.LongValue
static class
Value.ObjectValue
static class
Value.StringValue
-
Constructor Summary
Constructors Constructor Description Value()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
asBool()
Access the inspector's value if it's a BOOLEAN; otherwise throws exceptionboolean
asBool(boolean defaultValue)
Get the inspector's value (or the supplied default), never throwsbyte[]
asData()
Access the inspector's value if it's DATA; otherwise throws exceptionbyte[]
asData(byte[] defaultValue)
Get the inspector's value (or the supplied default), never throwsdouble
asDouble()
Access the inspector's value if it's a DOUBLE (or LONG); otherwise throws exceptiondouble
asDouble(double defaultValue)
Get the inspector's value (or the supplied default), never throwslong
asLong()
Access the inspector's value if it's a LONG (or DOUBLE); otherwise throws exceptionlong
asLong(long defaultValue)
Get the inspector's value (or the supplied default), never throwsjava.lang.String
asString()
Access the inspector's value if it's a STRING; otherwise throws exceptionjava.lang.String
asString(java.lang.String defaultValue)
Get the inspector's value (or the supplied default), never throwsbyte[]
asUtf8()
Access the inspector's value (in utf-8 representation) if it's a STRING; otherwise throws exceptionbyte[]
asUtf8(byte[] defaultValue)
Get the inspector's value (or the supplied default), never throwsstatic Inspector
empty()
java.lang.Iterable<Inspector>
entries()
Convert an array to an iterable list.Inspector
entry(int idx)
Access an array entry.int
entryCount()
Get the number of entries in an ARRAY (always returns 0 for non-arrays)Inspector
field(java.lang.String name)
Access an field in an object.int
fieldCount()
Get the number of fields in an OBJECT (always returns 0 for non-objects)java.lang.Iterable<java.util.Map.Entry<java.lang.String,Inspector>>
fields()
Convert an object to an iterable list of (name, value) pairs.Inspector
inspect()
Returns an Inspector exposing this object's structured data.static Inspector
invalid()
java.lang.String
toJson()
java.lang.String
toString()
void
traverse(ArrayTraverser at)
Traverse an array value, performing callbacks for each entry.void
traverse(ObjectTraverser ot)
Traverse an object value, performing callbacks for each field.Type
type()
Get the type of an inspectorboolean
valid()
Check if the inspector is valid.java.lang.StringBuilder
writeJson(java.lang.StringBuilder target)
-
-
-
Method Detail
-
empty
public static Inspector empty()
-
invalid
public static Inspector invalid()
-
inspect
public Inspector inspect()
Description copied from interface:Inspectable
Returns an Inspector exposing this object's structured data.- Specified by:
inspect
in interfaceInspectable
-
valid
public boolean valid()
Description copied from interface:Inspector
Check if the inspector is valid. If you try to access a field or array entry that does not exist, you will get an invalid Inspector returned.
-
entryCount
public int entryCount()
Description copied from interface:Inspector
Get the number of entries in an ARRAY (always returns 0 for non-arrays)- Specified by:
entryCount
in interfaceInspector
-
fieldCount
public int fieldCount()
Description copied from interface:Inspector
Get the number of fields in an OBJECT (always returns 0 for non-objects)- Specified by:
fieldCount
in interfaceInspector
-
asBool
public boolean asBool()
Description copied from interface:Inspector
Access the inspector's value if it's a BOOLEAN; otherwise throws exception
-
asLong
public long asLong()
Description copied from interface:Inspector
Access the inspector's value if it's a LONG (or DOUBLE); otherwise throws exception
-
asDouble
public double asDouble()
Description copied from interface:Inspector
Access the inspector's value if it's a DOUBLE (or LONG); otherwise throws exception
-
asString
public java.lang.String asString()
Description copied from interface:Inspector
Access the inspector's value if it's a STRING; otherwise throws exception
-
asUtf8
public byte[] asUtf8()
Description copied from interface:Inspector
Access the inspector's value (in utf-8 representation) if it's a STRING; otherwise throws exception
-
asData
public byte[] asData()
Description copied from interface:Inspector
Access the inspector's value if it's DATA; otherwise throws exception
-
asBool
public boolean asBool(boolean defaultValue)
Description copied from interface:Inspector
Get the inspector's value (or the supplied default), never throws
-
asLong
public long asLong(long defaultValue)
Description copied from interface:Inspector
Get the inspector's value (or the supplied default), never throws
-
asDouble
public double asDouble(double defaultValue)
Description copied from interface:Inspector
Get the inspector's value (or the supplied default), never throws
-
asString
public java.lang.String asString(java.lang.String defaultValue)
Description copied from interface:Inspector
Get the inspector's value (or the supplied default), never throws
-
asUtf8
public byte[] asUtf8(byte[] defaultValue)
Description copied from interface:Inspector
Get the inspector's value (or the supplied default), never throws
-
asData
public byte[] asData(byte[] defaultValue)
Description copied from interface:Inspector
Get the inspector's value (or the supplied default), never throws
-
traverse
public void traverse(ArrayTraverser at)
Description copied from interface:Inspector
Traverse an array value, performing callbacks for each entry. 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.
-
traverse
public void traverse(ObjectTraverser ot)
Description copied from interface:Inspector
Traverse an object value, performing callbacks for each field. 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.
-
entry
public Inspector entry(int idx)
Description copied from interface:Inspector
Access an array entry. 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.
-
field
public Inspector field(java.lang.String name)
Description copied from interface:Inspector
Access an field in an object. 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.
-
entries
public java.lang.Iterable<Inspector> entries()
Description copied from interface:Inspector
Convert an array to an iterable list. Other types will just return an empty list.
-
fields
public java.lang.Iterable<java.util.Map.Entry<java.lang.String,Inspector>> fields()
Description copied from interface:Inspector
Convert an object to an iterable list of (name, value) pairs. Other types will just return an empty list.
-
writeJson
public java.lang.StringBuilder writeJson(java.lang.StringBuilder target)
-
toJson
public java.lang.String toJson()
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-