Interface Transformer

All Known Subinterfaces:
Filter
Functional Interface:
This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.

@FunctionalInterface public interface Transformer
Interface which supports filtering and transforming the entries within a View. For pure filtering, consider implementing a Filter instead.
See Also:
  • Method Summary

    Modifier and Type
    Method
    Description
    default byte[]
    inverseTransformKey(byte[] tkey)
    Apply an inverse transformation of the given key, if supported.
    default byte[]
    inverseTransformKeyGt(byte[] tkey)
    Apply an inverse transformation of the given key, strictly greater than the one given.
    default byte[]
    inverseTransformKeyLt(byte[] tkey)
    Apply an inverse transformation of the given key, strictly less than the one given.
    default byte[]
    inverseTransformValue(byte[] tvalue, byte[] key, byte[] tkey)
    Apply an inverse transformation of the given value, if supported.
    default Boolean
    Returns true by default, indicating that the transform methods always require a value instance to be provided.
    default Comparator<byte[]>
    Returns the view comparator, after transformation.
    default Ordering
    Returns the natural ordering of keys, after they have been transformed.
    default byte[]
    Transform or filter out the given key.
    byte[]
    transformValue(byte[] value, byte[] key, byte[] tkey)
    Transform or filter out the given value.
    default byte[]
    transformValue(Cursor cursor, byte[] tkey)
    Transform or filter out the given value.
  • Method Details

    • requireValue

      default Boolean requireValue()
      Returns true by default, indicating that the transform methods always require a value instance to be provided. When false is returned, values aren't loaded unless explicitly requested. Return null to always use a cursor, in which case the transformValue variant which accepts a cursor should be overridden. Otherwise, returning null is equivalent to returning true.
      Returns:
      true if a value must always be passed into the transform methods
    • transformValue

      byte[] transformValue(byte[] value, byte[] key, byte[] tkey) throws IOException
      Transform or filter out the given value. This method is only called when loading a value from a view.
      Parameters:
      value - nullable value to transform
      key - non-null untransformed key associated with the value
      tkey - non-null transformed key associated with the value
      Returns:
      transformed value or null to discard entry
      Throws:
      IOException
    • transformValue

      default byte[] transformValue(Cursor cursor, byte[] tkey) throws IOException
      Transform or filter out the given value. This method is only called when loading from a positioned a cursor. Default implementation always forces the value to be loaded, unless requireValue returns false.
      Parameters:
      cursor - positioned cursor at the untransformed key and value (not null, might be NOT_LOADED)
      tkey - non-null transformed key associated with the value
      Returns:
      transformed value or null to discard entry
      Throws:
      IOException
    • inverseTransformValue

      default byte[] inverseTransformValue(byte[] tvalue, byte[] key, byte[] tkey) throws ViewConstraintException, IOException
      Apply an inverse transformation of the given value, if supported. This method is only called when attempting to store the value into the view. Default implementation always throws a ViewConstraintException.
      Parameters:
      tvalue - nullable value to transform
      key - non-null untransformed key associated with the value
      tkey - non-null transformed key associated with the value
      Returns:
      inverse transformed value, or null to delete the value
      Throws:
      ViewConstraintException - if inverse transformation of given value is not supported
      IOException
    • transformKey

      default byte[] transformKey(Cursor cursor) throws IOException
      Transform or filter out the given key. This method is only called after positioning a cursor. Default implementation returns the same key.
      Parameters:
      cursor - positioned cursor at the untransformed key and value (might be null or NOT_LOADED)
      Returns:
      transformed key or null to discard entry
      Throws:
      IOException
    • inverseTransformKey

      default byte[] inverseTransformKey(byte[] tkey)
      Apply an inverse transformation of the given key, if supported. This method can be called for load and store operations. Default implementation returns the same key.
      Parameters:
      tkey - non-null key
      Returns:
      inverse transformed key or null if inverse transformation of given key is not supported
    • inverseTransformKeyGt

      default byte[] inverseTransformKeyGt(byte[] tkey)
      Apply an inverse transformation of the given key, strictly greater than the one given. This method is only called after the regular inverse transformation has been attempted. Default implementation increments the key by the minimum amount and then calls inverseTransformKey.
      Parameters:
      tkey - non-null key
      Returns:
      inverse transformed key or null if inverse transformation of given key is not supported
    • inverseTransformKeyLt

      default byte[] inverseTransformKeyLt(byte[] tkey)
      Apply an inverse transformation of the given key, strictly less than the one given. This method is only called after the regular inverse transformation has been attempted. Default implementation decrements the key by the minimum amount and then calls inverseTransformKey.
      Parameters:
      tkey - non-null key
      Returns:
      inverse transformed key or null if inverse transformation of given key is not supported
    • transformedOrdering

      default Ordering transformedOrdering(Ordering original)
      Returns the natural ordering of keys, after they have been transformed. Default implementation returns the same ordering.
      Parameters:
      original - natural ordering of view before transformation
    • transformedComparator

      default Comparator<byte[]> transformedComparator(Comparator<byte[]> original)
      Returns the view comparator, after transformation. Default implementation returns the same comparator.
      Parameters:
      original - comparator of view before transformation
      Throws:
      IllegalStateException - if transformed view is unordered