Class ListIndexProxy<E>

java.lang.Object
com.exonum.binding.core.proxy.AbstractNativeProxy
com.exonum.binding.core.storage.indices.ListIndexProxy<E>
Type Parameters:
E - the type of elements in this list
All Implemented Interfaces:
ListIndex<E>, StorageIndex, Iterable<E>

public final class ListIndexProxy<E>
extends AbstractNativeProxy
implements ListIndex<E>
A list index proxy is a contiguous list of elements. Elements may be added to or removed from the end of the list only.

This list implementation does not permit null elements.

The "destructive" methods of the list, i.e., those that change its contents, are specified to throw UnsupportedOperationException if this list has been created with a read-only database view.

All method arguments are non-null by default.

This class is not thread-safe and and its instances shall not be shared between threads.

When the view goes out of scope, this list is destroyed. Subsequent use of the closed list is prohibited and will result in IllegalStateException.

See Also:
View
  • Method Details

    • newInstance

      public static <E extends com.google.protobuf.MessageLite> ListIndexProxy<E> newInstance​(String name, View view, Class<E> elementType)
      Creates a new ListIndexProxy storing protobuf messages.
      Type Parameters:
      E - the type of elements in this list; must be a protobuf message that has a public static #parseFrom(byte[]) method
      Parameters:
      name - a unique alphanumeric non-empty identifier of this list in the underlying storage: [a-zA-Z0-9_]
      view - a database view. Must be valid. If a view is read-only, "destructive" operations are not permitted.
      elementType - the class of an element-protobuf message
      Throws:
      IllegalStateException - if the view is not valid
      IllegalArgumentException - if the name is empty
    • newInstance

      public static <E> ListIndexProxy<E> newInstance​(String name, View view, Serializer<E> serializer)
      Creates a new ListIndexProxy.
      Type Parameters:
      E - the type of elements in this list
      Parameters:
      name - a unique alphanumeric non-empty identifier of this list in the underlying storage: [a-zA-Z0-9_]
      view - a database view. Must be valid. If a view is read-only, "destructive" operations are not permitted.
      serializer - a serializer of elements
      Throws:
      IllegalStateException - if the view is not valid
      IllegalArgumentException - if the name is empty
      See Also:
      StandardSerializers
    • newInGroupUnsafe

      public static <E> ListIndexProxy<E> newInGroupUnsafe​(String groupName, byte[] listId, View view, Serializer<E> serializer)
      Creates a new list in a collection group with the given name.

      See a caveat on index identifiers.

      Type Parameters:
      E - the type of elements in this list
      Parameters:
      groupName - a name of the collection group
      listId - an identifier of this collection in the group, see the caveats
      view - a database view
      serializer - a serializer of list elements
      Returns:
      a new list proxy
      Throws:
      IllegalStateException - if the view is not valid
      IllegalArgumentException - if the name or index id is empty
      See Also:
      StandardSerializers
    • add

      public final void add​(T e)
      Description copied from interface: ListIndex
      Adds a new element to the end of the list.
      Specified by:
      add in interface ListIndex<T>
      Parameters:
      e - an element to append to the list
    • addAll

      public void addAll​(Collection<? extends T> elements)
      Description copied from interface: ListIndex
      Adds all elements from the specified collection to this list.

      If the collection contains an invalid element, this list is not modified.

      Specified by:
      addAll in interface ListIndex<T>
      Parameters:
      elements - elements to add to this list
    • set

      public final void set​(long index, T e)
      Description copied from interface: ListIndex
      Replaces the element at the given index of the list with the specified element.
      Specified by:
      set in interface ListIndex<T>
      Parameters:
      index - an index of the element to replace
      e - an element to add
    • get

      public final T get​(long index)
      Description copied from interface: ListIndex
      Returns the element at the given index.
      Specified by:
      get in interface ListIndex<T>
      Parameters:
      index - an index of the element to return
      Returns:
      an element at the given index
    • getLast

      public final T getLast()
      Description copied from interface: ListIndex
      Returns the last element of the list.
      Specified by:
      getLast in interface ListIndex<T>
      Returns:
      the last element of the list
    • removeLast

      public T removeLast()
      Description copied from interface: ListIndex
      Removes the last element of the list and returns it.
      Specified by:
      removeLast in interface ListIndex<T>
      Returns:
      the last element of the list.
    • truncate

      public void truncate​(long newSize)
      Description copied from interface: ListIndex
      Truncates the list, reducing its size to newSize.

      If newSize < size(), keeps the first newSize elements, removing the rest. If newSize >= size(), has no effect.

      Specified by:
      truncate in interface ListIndex<T>
      Parameters:
      newSize - the maximum number of elements to keep
    • clear

      public final void clear()
      Description copied from interface: ListIndex
      Clears the list.
      Specified by:
      clear in interface ListIndex<T>
    • isEmpty

      public final boolean isEmpty()
      Description copied from interface: ListIndex
      Returns true if the list is empty, false — otherwise.
      Specified by:
      isEmpty in interface ListIndex<T>
    • size

      public final long size()
      Description copied from interface: ListIndex
      Returns the number of elements in the list.
      Specified by:
      size in interface ListIndex<T>
    • iterator

      public final Iterator<T> iterator()
      Description copied from interface: ListIndex
      Returns an iterator over the elements of the list.
      Specified by:
      iterator in interface Iterable<T>
      Specified by:
      iterator in interface ListIndex<T>
    • stream

      public Stream<T> stream()
      Description copied from interface: ListIndex
      Returns a stream of elements in this list. The returned stream is fail-fast and late-binding. The stream can be used as long as the source list is valid.
      Specified by:
      stream in interface ListIndex<T>
    • getAddress

      public IndexAddress getAddress()
      Description copied from interface: StorageIndex
      Returns the index address: its unique identifier in the database. It consists of the name and, in case this index belongs to an index family, a family identifier.
      Specified by:
      getAddress in interface StorageIndex
    • toString

      public String toString()
      Overrides:
      toString in class Object