Package com.yahoo.slime
Interface Inspector
- All Known Subinterfaces:
Cursor
- All Known Implementing Classes:
BinaryView
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
Modifier and TypeMethodDescriptionvoidUse the visitor pattern to resolve the underlying type of this value.booleanasBool()the current value (for booleans); default: falsebyte[]asData()the current value (for data values); default: empty arraydoubleasDouble()the current value (for floating-point values); default: 0.0longasLong()the current value (for integers); default: 0asString()the current value (for string values); default: empty stringbyte[]asUtf8()the current value encoded into UTF-8 (for string values); default: empty arrayintchildren()Check how many entries or fields are contained in the current value.intentries()Check how many entries are contained in the current value.entry(int idx) Access an array entry.default booleanTests whether this is equal to Inspector.field(int sym) Access a field in an object by symbol id.Access a field in an object by symbol name.intfields()Check how many fields are contained in the current value.voidInvoke the given consumer with this value if it is validvoidTraverse an array value, performing callbacks for each entry.voidTraverse an object value, performing callbacks for each field.voidTraverse an object value, performing callbacks for each field.type()return an enum describing value typebooleanvalid()check if this inspector is valid
-
Method Details
-
valid
boolean valid()check if this inspector is valid -
ifValid
Invoke the given consumer with this value if it 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
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
Use the visitor pattern to resolve the underlying type of this value.- Parameters:
v- the visitor
-
traverse
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
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
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
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
Access a 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
Access a 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
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.
-