Interface Index<V>

  • Type Parameters:
    V - the value's type
    All Known Implementing Classes:
    AbstractIndex, MapsIndex

    public interface Index<V>
    An index of values. Values are associated with a timestamp and zero or one name. The timestamp is used to mark values as pending whenever they have changed. Pending values may be retrieved for re-indexing.

    Values may be looked up by partial names.

    All methods are synchronized: concurrent access from multiple threads is supported.

    • Method Summary

      All Methods Instance Methods Abstract Methods 
      Modifier and Type Method Description
      void add​(V value, long timestamp)
      Adds a value to the cache.
      void addIndexListener​(@NotNull IndexListener<V> listener)
      Adds an IndexListener to be notified of changes.
      void beginUpdate()
      Starts an update.
      void clear()
      Clears all values from the index.
      void endUpdate()
      Ends an update.
      @NotNull java.util.Collection<V> findPartialName​(@NotNull java.lang.String name)
      Returns all matching values for a (possibly partial) key name.
      @Nullable java.lang.String getName​(V value)
      Returns the name associated with a value.
      boolean hasPending()
      Returns whether at least one pending value exists.
      void indexingFinished()
      Should be called after indexing has finished.
      boolean isModified()
      Returns whether the state was modified since last save.
      void load​(@NotNull java.io.ObjectInputStream objectInputStream)
      Restores the state from an ObjectInputStream.
      void remove​(V value)
      Removes a value from the cache.
      void removeIndexListener​(@NotNull IndexListener<V> listener)
      Removes an IndexListener to be notified of changes.
      V removePending()
      Returns one pending value.
      void save​(@NotNull java.io.ObjectOutputStream objectOutputStream)
      Saves the state to an ObjectOutputStream.
      void setName​(V value, long timestamp, @NotNull java.lang.String name)
      Associates a value with a name.
      void setPending​(V value)
      Marks a value as pending.
      int size()
      Returns the number of values in this cache.
    • Method Detail

      • size

        int size()
        Returns the number of values in this cache.
        Returns:
        the number of values
      • findPartialName

        @NotNull
        @NotNull java.util.Collection<V> findPartialName​(@NotNull
                                                         @NotNull java.lang.String name)
        Returns all matching values for a (possibly partial) key name.
        Parameters:
        name - the partial name to look up
        Returns:
        the matching values
      • beginUpdate

        void beginUpdate()
        Starts an update. Updates do not nest. This function and endUpdate() should be called from only a single thread.
      • endUpdate

        void endUpdate()
        Ends an update. Removes all values from the index that were not added since the last call to beginUpdate(). Must not be called unless a directly preceding call to beginUpdate() was made.
      • add

        void add​(@NotNull
                 V value,
                 long timestamp)
        Adds a value to the cache. Newly added values and existing values for which the new timestamp does not match the old timestamp are marked as pending.
        Parameters:
        value - the value to add
        timestamp - a timestamp associated with the value
      • remove

        void remove​(@NotNull
                    V value)
        Removes a value from the cache. Does nothing if the values does not exist.
        Parameters:
        value - the value to remove
      • setPending

        void setPending​(@NotNull
                        V value)
        Marks a value as pending. The value is added if it does not exist.
        Parameters:
        value - the value to mark pending
      • setName

        void setName​(@NotNull
                     V value,
                     long timestamp,
                     @NotNull
                     @NotNull java.lang.String name)
        Associates a value with a name. Adds the value if it does not exist.
        Parameters:
        value - the value to associate with a name
        timestamp - the value's timestamp
        name - the name associated with the value
      • getName

        @Nullable
        @Nullable java.lang.String getName​(@NotNull
                                           V value)
        Returns the name associated with a value.
        Parameters:
        value - the value
        Returns:
        the name or null if the value does not exist or has no associated name
      • removePending

        @Nullable
        V removePending()
        Returns one pending value.
        Returns:
        a pending value or null if no pending values exist
      • hasPending

        boolean hasPending()
        Returns whether at least one pending value exists.
        Returns:
        whether at least one pending value exists
      • isModified

        boolean isModified()
        Returns whether the state was modified since last save.
        Returns:
        whether the state was modified
      • addIndexListener

        void addIndexListener​(@NotNull
                              @NotNull IndexListener<V> listener)
        Adds an IndexListener to be notified of changes.
        Parameters:
        listener - the index listener to add
      • removeIndexListener

        void removeIndexListener​(@NotNull
                                 @NotNull IndexListener<V> listener)
        Removes an IndexListener to be notified of changes.
        Parameters:
        listener - the index listener to remove
      • save

        void save​(@NotNull
                  @NotNull java.io.ObjectOutputStream objectOutputStream)
           throws java.io.IOException
        Saves the state to an ObjectOutputStream. Pending maps are not saved.
        Parameters:
        objectOutputStream - the object output stream to write to
        Throws:
        java.io.IOException - if an I/O error occurs
      • load

        void load​(@NotNull
                  @NotNull java.io.ObjectInputStream objectInputStream)
           throws java.io.IOException
        Restores the state from an ObjectInputStream. The previous state is overwritten.
        Parameters:
        objectInputStream - the input stream to read from
        Throws:
        java.io.IOException - if an I/O error occurs
      • clear

        void clear()
        Clears all values from the index.
      • indexingFinished

        void indexingFinished()
        Should be called after indexing has finished.