Class AbstractIndex<V extends java.io.Serializable>

  • Type Parameters:
    V - the value's type
    All Implemented Interfaces:
    Index<V>
    Direct Known Subclasses:
    MapsIndex

    public class AbstractIndex<V extends java.io.Serializable>
    extends java.lang.Object
    implements Index<V>
    Abstract base class for Index implementations.
    • Constructor Summary

      Constructors 
      Constructor Description
      AbstractIndex()  
    • Method Summary

      All Methods Instance Methods Concrete 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.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • AbstractIndex

        public AbstractIndex()
    • Method Detail

      • size

        public int size()
        Description copied from interface: Index
        Returns the number of values in this cache.
        Specified by:
        size in interface Index<V extends java.io.Serializable>
        Returns:
        the number of values
      • findPartialName

        @NotNull
        public @NotNull java.util.Collection<V> findPartialName​(@NotNull
                                                                @NotNull java.lang.String name)
        Description copied from interface: Index
        Returns all matching values for a (possibly partial) key name.
        Specified by:
        findPartialName in interface Index<V extends java.io.Serializable>
        Parameters:
        name - the partial name to look up
        Returns:
        the matching values
      • beginUpdate

        public void beginUpdate()
        Description copied from interface: Index
        Starts an update. Updates do not nest. This function and Index.endUpdate() should be called from only a single thread.
        Specified by:
        beginUpdate in interface Index<V extends java.io.Serializable>
      • endUpdate

        public void endUpdate()
        Description copied from interface: Index
        Ends an update. Removes all values from the index that were not added since the last call to Index.beginUpdate(). Must not be called unless a directly preceding call to beginUpdate() was made.
        Specified by:
        endUpdate in interface Index<V extends java.io.Serializable>
      • add

        public void add​(@NotNull
                        V value,
                        long timestamp)
        Description copied from interface: Index
        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.
        Specified by:
        add in interface Index<V extends java.io.Serializable>
        Parameters:
        value - the value to add
        timestamp - a timestamp associated with the value
      • remove

        public void remove​(@NotNull
                           V value)
        Description copied from interface: Index
        Removes a value from the cache. Does nothing if the values does not exist.
        Specified by:
        remove in interface Index<V extends java.io.Serializable>
        Parameters:
        value - the value to remove
      • setPending

        public void setPending​(@NotNull
                               V value)
        Description copied from interface: Index
        Marks a value as pending. The value is added if it does not exist.
        Specified by:
        setPending in interface Index<V extends java.io.Serializable>
        Parameters:
        value - the value to mark pending
      • setName

        public void setName​(@NotNull
                            V value,
                            long timestamp,
                            @NotNull
                            @NotNull java.lang.String name)
        Description copied from interface: Index
        Associates a value with a name. Adds the value if it does not exist.
        Specified by:
        setName in interface Index<V extends java.io.Serializable>
        Parameters:
        value - the value to associate with a name
        timestamp - the value's timestamp
        name - the name associated with the value
      • getName

        @Nullable
        public @Nullable java.lang.String getName​(@NotNull
                                                  V value)
        Description copied from interface: Index
        Returns the name associated with a value.
        Specified by:
        getName in interface Index<V extends java.io.Serializable>
        Parameters:
        value - the value
        Returns:
        the name or null if the value does not exist or has no associated name
      • removePending

        @Nullable
        public V removePending()
        Description copied from interface: Index
        Returns one pending value.
        Specified by:
        removePending in interface Index<V extends java.io.Serializable>
        Returns:
        a pending value or null if no pending values exist
      • hasPending

        public boolean hasPending()
        Description copied from interface: Index
        Returns whether at least one pending value exists.
        Specified by:
        hasPending in interface Index<V extends java.io.Serializable>
        Returns:
        whether at least one pending value exists
      • isModified

        public boolean isModified()
        Description copied from interface: Index
        Returns whether the state was modified since last save.
        Specified by:
        isModified in interface Index<V extends java.io.Serializable>
        Returns:
        whether the state was modified
      • addIndexListener

        public void addIndexListener​(@NotNull
                                     @NotNull IndexListener<V> listener)
        Description copied from interface: Index
        Adds an IndexListener to be notified of changes.
        Specified by:
        addIndexListener in interface Index<V extends java.io.Serializable>
        Parameters:
        listener - the index listener to add
      • removeIndexListener

        public void removeIndexListener​(@NotNull
                                        @NotNull IndexListener<V> listener)
        Description copied from interface: Index
        Removes an IndexListener to be notified of changes.
        Specified by:
        removeIndexListener in interface Index<V extends java.io.Serializable>
        Parameters:
        listener - the index listener to remove
      • save

        public void save​(@NotNull
                         @NotNull java.io.ObjectOutputStream objectOutputStream)
                  throws java.io.IOException
        Description copied from interface: Index
        Saves the state to an ObjectOutputStream. Pending maps are not saved.
        Specified by:
        save in interface Index<V extends java.io.Serializable>
        Parameters:
        objectOutputStream - the object output stream to write to
        Throws:
        java.io.IOException - if an I/O error occurs
      • load

        public void load​(@NotNull
                         @NotNull java.io.ObjectInputStream objectInputStream)
                  throws java.io.IOException
        Description copied from interface: Index
        Restores the state from an ObjectInputStream. The previous state is overwritten.
        Specified by:
        load in interface Index<V extends java.io.Serializable>
        Parameters:
        objectInputStream - the input stream to read from
        Throws:
        java.io.IOException - if an I/O error occurs
        No Inspection:
        unchecked
      • clear

        public void clear()
        Description copied from interface: Index
        Clears all values from the index.
        Specified by:
        clear in interface Index<V extends java.io.Serializable>
      • indexingFinished

        public void indexingFinished()
        Description copied from interface: Index
        Should be called after indexing has finished.
        Specified by:
        indexingFinished in interface Index<V extends java.io.Serializable>