Package com.yahoo.slime
Interface Inspector
-
- All Known Subinterfaces:
Cursor
public interface Inspector
Interface for read-only access to any value or object that is part of a Slime. You can access meta-data such as validity and actual type. You can always convert to any basic type by calling the various "as" accessor methods; these return a default value if the 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
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description void
accept(Visitor v)
Use the visitor pattern to resolve the underlying type of this value.boolean
asBool()
the current value (for booleans); default: falsebyte[]
asData()
the current value (for data values); default: empty arraydouble
asDouble()
the current value (for floating-point values); default: 0.0long
asLong()
the current value (for integers); default: 0java.lang.String
asString()
the current value (for string values); default: empty stringbyte[]
asUtf8()
the current value encoded into UTF-8 (for string values); default: empty arrayint
children()
Check how many entries or fields are contained in the current value.int
entries()
Check how many entries are contained in the current value.Inspector
entry(int idx)
Access an array entry.boolean
equalTo(Inspector that)
Tests whether this is equal to Inspector.Inspector
field(int sym)
Access an field in an object by symbol id.Inspector
field(java.lang.String name)
Access an field in an object by symbol name.int
fields()
Check how many fields are contained in the current value.void
traverse(ArrayTraverser at)
Traverse an array value, performing callbacks for each entry.void
traverse(ObjectSymbolTraverser ot)
Traverse an object value, performing callbacks for each field.void
traverse(ObjectTraverser ot)
Traverse an object value, performing callbacks for each field.Type
type()
return an enum describing value typeboolean
valid()
check if this inspector is valid
-
-
-
Method Detail
-
valid
boolean valid()
check if this inspector is valid
-
type
Type type()
return an enum describing value type
-
children
int children()
Check how many entries or fields are contained in the current value. Useful for arrays and objects; anything else always returns 0.- Returns:
- number of entries/fields contained.
-
entries
int entries()
Check how many entries are contained in the current value. Useful for arrays; anything else always returns 0.- Returns:
- number of entries contained.
-
fields
int fields()
Check how many fields are contained in the current value. Useful for objects; anything else always returns 0.- Returns:
- number of fields contained.
-
asBool
boolean asBool()
the current value (for booleans); default: false
-
asLong
long asLong()
the current value (for integers); default: 0
-
asDouble
double asDouble()
the current value (for floating-point values); default: 0.0
-
asString
java.lang.String asString()
the current value (for string values); default: empty string
-
asUtf8
byte[] asUtf8()
the current value encoded into UTF-8 (for string values); default: empty array
-
asData
byte[] asData()
the current value (for data values); default: empty array
-
accept
void accept(Visitor v)
Use the visitor pattern to resolve the underlying type of this value.- Parameters:
v
- the visitor
-
traverse
void traverse(ArrayTraverser at)
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.- Parameters:
at
- traverser callback object.
-
traverse
void traverse(ObjectSymbolTraverser ot)
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.- Parameters:
ot
- traverser callback object.
-
traverse
void traverse(ObjectTraverser ot)
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.- Parameters:
ot
- traverser callback object.
-
entry
Inspector entry(int idx)
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.- Parameters:
idx
- array index.- Returns:
- a new Inspector for the entry value.
-
field
Inspector field(int sym)
Access an field in an object by symbol id. If the current Inspector doesn't connect to an object value, or the object value does not contain a field with the given symbol id, the returned Inspector will be invalid.- Parameters:
sym
- symbol id.- Returns:
- a new Inspector for the field value.
-
field
Inspector field(java.lang.String name)
Access an field in an object by symbol name. 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.- Parameters:
name
- symbol name.- Returns:
- a new Inspector for the field value.
-
equalTo
boolean equalTo(Inspector that)
Tests whether this is equal to Inspector. Since equality of two Inspectors is subtle,Object.equals(Object)
is not used.- Parameters:
that
- inspector.- Returns:
- true if they are equal.
-
-