Class SlimeAdapter

java.lang.Object
com.yahoo.data.access.slime.SlimeAdapter
All Implemented Interfaces:
Inspectable, Inspector

public final class SlimeAdapter extends Object implements Inspector
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    Access the inspector's value if it's a BOOLEAN; otherwise throws exception
    boolean
    asBool(boolean defaultValue)
    Get the inspector's value (or the supplied default), never throws
    byte[]
    Access the inspector's value if it's DATA; otherwise throws exception
    byte[]
    asData(byte[] defaultValue)
    Get the inspector's value (or the supplied default), never throws
    double
    Access the inspector's value if it's a DOUBLE (or LONG); otherwise throws exception
    double
    asDouble(double defaultValue)
    Get the inspector's value (or the supplied default), never throws
    long
    Access the inspector's value if it's a LONG (or DOUBLE); otherwise throws exception
    long
    asLong(long defaultValue)
    Get the inspector's value (or the supplied default), never throws
    Access the inspector's value if it's a STRING; otherwise throws exception
    asString(String defaultValue)
    Get the inspector's value (or the supplied default), never throws
    byte[]
    Access the inspector's value (in utf-8 representation) if it's a STRING; otherwise throws exception
    byte[]
    asUtf8(byte[] defaultValue)
    Get the inspector's value (or the supplied default), never throws
    Convert an array to an iterable list.
    entry(int idx)
    Access an array entry.
    int
    Get the number of entries in an ARRAY (always returns 0 for non-arrays)
    boolean
     
    field(String name)
    Access an field in an object.
    int
    Get the number of fields in an OBJECT (always returns 0 for non-objects)
    Convert an object to an iterable list of (name, value) pairs.
    int
     
    Returns an Inspector exposing this object's structured data.
     
    void
    Traverse an array value, performing callbacks for each entry.
    void
    Traverse an object value, performing callbacks for each field.
    Get the type of an inspector
    boolean
    Check if the inspector is valid.

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • SlimeAdapter

      public SlimeAdapter(Inspector inspector)
  • Method Details

    • equals

      public boolean equals(Object rhs)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • inspect

      public Inspector inspect()
      Description copied from interface: Inspectable
      Returns an Inspector exposing this object's structured data.
      Specified by:
      inspect in interface Inspectable
    • 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.
      Specified by:
      valid in interface Inspector
    • type

      public Type type()
      Description copied from interface: Inspector
      Get the type of an inspector
      Specified by:
      type in interface Inspector
    • 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 interface Inspector
    • 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 interface Inspector
    • asBool

      public boolean asBool()
      Description copied from interface: Inspector
      Access the inspector's value if it's a BOOLEAN; otherwise throws exception
      Specified by:
      asBool in interface Inspector
    • asLong

      public long asLong()
      Description copied from interface: Inspector
      Access the inspector's value if it's a LONG (or DOUBLE); otherwise throws exception
      Specified by:
      asLong in interface Inspector
    • asDouble

      public double asDouble()
      Description copied from interface: Inspector
      Access the inspector's value if it's a DOUBLE (or LONG); otherwise throws exception
      Specified by:
      asDouble in interface Inspector
    • asString

      public String asString()
      Description copied from interface: Inspector
      Access the inspector's value if it's a STRING; otherwise throws exception
      Specified by:
      asString in interface Inspector
    • 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
      Specified by:
      asUtf8 in interface Inspector
    • asData

      public byte[] asData()
      Description copied from interface: Inspector
      Access the inspector's value if it's DATA; otherwise throws exception
      Specified by:
      asData in interface Inspector
    • asBool

      public boolean asBool(boolean defaultValue)
      Description copied from interface: Inspector
      Get the inspector's value (or the supplied default), never throws
      Specified by:
      asBool in interface Inspector
    • asLong

      public long asLong(long defaultValue)
      Description copied from interface: Inspector
      Get the inspector's value (or the supplied default), never throws
      Specified by:
      asLong in interface Inspector
    • asDouble

      public double asDouble(double defaultValue)
      Description copied from interface: Inspector
      Get the inspector's value (or the supplied default), never throws
      Specified by:
      asDouble in interface Inspector
    • asString

      public String asString(String defaultValue)
      Description copied from interface: Inspector
      Get the inspector's value (or the supplied default), never throws
      Specified by:
      asString in interface Inspector
    • asUtf8

      public byte[] asUtf8(byte[] defaultValue)
      Description copied from interface: Inspector
      Get the inspector's value (or the supplied default), never throws
      Specified by:
      asUtf8 in interface Inspector
    • asData

      public byte[] asData(byte[] defaultValue)
      Description copied from interface: Inspector
      Get the inspector's value (or the supplied default), never throws
      Specified by:
      asData in interface Inspector
    • 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.
      Specified by:
      traverse in interface Inspector
      Parameters:
      at - traverser callback object
    • 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.
      Specified by:
      traverse in interface Inspector
      Parameters:
      ot - traverser callback object
    • 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.
      Specified by:
      entry in interface Inspector
      Parameters:
      idx - array index
      Returns:
      a new Inspector for the entry value
    • field

      public Inspector field(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.
      Specified by:
      field in interface Inspector
      Parameters:
      name - symbol name
      Returns:
      a new Inspector for the field value
    • entries

      public Iterable<Inspector> entries()
      Description copied from interface: Inspector
      Convert an array to an iterable list. Other types will just return an empty list.
      Specified by:
      entries in interface Inspector
    • fields

      public Iterable<Map.Entry<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.
      Specified by:
      fields in interface Inspector