Interface Sets

  • All Superinterfaces:
    Namespaceable

    public interface Sets
    extends Namespaceable
    Sets expose functionalities to work with sorted sets of strings. A set contains an ordered list of unique entries and their associated weight in that particular set. Implementations of this interface allow users to add/remove entries to/from sets, access and modify entries and their weights.
    • Method Summary

      All Methods Instance Methods Abstract Methods Default Methods 
      Modifier and Type Method Description
      default void add​(String namespace, String set, String entry)
      Add an entry with weight of 0 to the set in the given namespace.
      void add​(String namespace, String set, String entry, long weight)
      Add an entry with a weight to the set in the given namespace.
      void add​(String namespace, String set, Map<String,​Long> entries)
      Add batch of entries/weights to the set in the given namespace.
      default void delete​(String namespace, String set)
      Deletes all entries in the set in the given namespace.
      void delete​(String namespace, String set, long min, long max)
      Deletes all entries in the set with weights between the given min and max, in the given namespace.
      boolean delete​(String namespace, String set, String entry)
      Deletes an entry from the set in the given namespace.
      void delete​(String namespace, String set, Collection<String> entries)
      Delete batch of objects from set in the given namespace; no-op if an entry is not found.
      default Collection<String> entries​(String namespace, String set)
      Return object entries and weights stored in the set with start and count and weight more than min, less than max
      default Collection<String> entries​(String namespace, String set, int start, int count)
      Return object entries and weights stored in the set with start and count and weight more than min, less than max
      default Collection<String> entries​(String namespace, String set, int start, int count, boolean ascending)
      Return object entries and weights stored in the set with start and count and weight more than min, less than max
      Collection<String> entries​(String namespace, String set, long min, long max, int start, int count, boolean ascending)
      Return entries stored in the set with start and count and weight more than min, less than max.
      default String first​(String namespace, String set)
      Get the first entry in the set ordered ascending by weight.
      default Map<String,​Long> get​(String namespace, String set)
      Return all entries stored in the set, ordered by weight ascending
      default Map<String,​Long> get​(String namespace, String set, int start, int count)
      Return entries stored in the set with start and count, ordered by weight ascending
      Map<String,​Long> get​(String namespace, String set, long min, long max, int start, int count, boolean ascending)
      Return entries and weights stored in the set with start and count and weight more than min, less than max.
      long inc​(String namespace, String set, String entry, long count)
      Atomic operation to increment an entry's weight in the set by the given count and then return the final value.
      default Map<String,​Long> intersect​(String namespace, Collection<String> sets)
      Return intersect of all entries stored in the given sets, ordered by weight ascending
      default Map<String,​Long> intersect​(String namespace, Collection<String> sets, int start, int count)
      Return entries stored in the set with start and count, ordered by weight ascending
      Map<String,​Long> intersect​(String namespace, Collection<String> sets, long min, long max, int start, int count, boolean ascending)
      Return intersection of entries and weights stored in all of the given sets, with start and count and weight more than min, less than max.
      default String last​(String namespace, String set)
      Get the last entry in the set ordered ascending by weight.
      default Map<String,​Long> pop​(String namespace, String set)
      Return and atomically remove all entries in the set
      default Map<String,​Long> pop​(String namespace, String set, int start, int count)
      Return and atomically remove all entries in the set with start and count
      Map<String,​Long> pop​(String namespace, String set, long min, long max, int start, int count, boolean ascending)
      Return and atomically remove entries and weights stored in the set with start and count and weight more than min, less than max.
      Collection<String> sets​(String namespace)
      Returns list of all sets in the given namespace.
      int size​(String namespace, String set)
      Get the number of entries in the set.
      default Map<String,​Long> union​(String namespace, Collection<String> sets)
      Return union of all entries stored in the given sets, ordered by weight ascending
      default Map<String,​Long> union​(String namespace, Collection<String> sets, int start, int count)
      Return entries stored in the set with start and count, ordered by weight ascending
      Map<String,​Long> union​(String namespace, Collection<String> sets, long min, long max, int start, int count, boolean ascending)
      Return union of entries and weights stored in any of the given sets, with start and count and weight more than min, less than max.
      Long weight​(String namespace, String set, String entry)
      Returns an entry's weight in the set.
    • Method Detail

      • add

        void add​(String namespace,
                 String set,
                 String entry,
                 long weight)
          throws IOException
        Add an entry with a weight to the set in the given namespace.
        Parameters:
        namespace - the namespace
        set - name of the set to add the entry to
        entry - the entry
        weight - weight of the entry in the set
        Throws:
        IOException - exception thrown from the underlying storage implementation
      • add

        default void add​(String namespace,
                         String set,
                         String entry)
                  throws IOException
        Add an entry with weight of 0 to the set in the given namespace.
        Parameters:
        namespace - the namespace
        set - name of the set to add the entry to
        entry - the entry
        Throws:
        IOException - exception thrown from the underlying storage implementation
      • add

        void add​(String namespace,
                 String set,
                 Map<String,​Long> entries)
          throws IOException
        Add batch of entries/weights to the set in the given namespace.
        Parameters:
        namespace - the namespace
        set - name of the set to add the entry to
        entries - map of entries to weights
        Throws:
        IOException - exception thrown from the underlying storage implementation
      • entries

        Collection<String> entries​(String namespace,
                                   String set,
                                   long min,
                                   long max,
                                   int start,
                                   int count,
                                   boolean ascending)
                            throws IOException
        Return entries stored in the set with start and count and weight more than min, less than max.
        Parameters:
        namespace - the namespace
        set - name of the sorted set
        min - the minimum weight
        max - the maximum weight
        start - start offset
        count - maximum number of entries to return
        ascending - ordered ascending or descending by weight
        Returns:
        ordered list of entries in the set matching the given criteria
        Throws:
        IOException - exception thrown from the underlying storage implementation
      • entries

        default Collection<String> entries​(String namespace,
                                           String set,
                                           int start,
                                           int count,
                                           boolean ascending)
                                    throws IOException
        Return object entries and weights stored in the set with start and count and weight more than min, less than max
        Parameters:
        namespace - the namespace
        set - name of the sorted set
        start - start offset
        count - maximum number of entries to return
        ascending - ordered ascending or descending by weight
        Returns:
        ordered list of entries in the set matching the given criteria
        Throws:
        IOException - exception thrown from the underlying storage implementation
      • entries

        default Collection<String> entries​(String namespace,
                                           String set,
                                           int start,
                                           int count)
                                    throws IOException
        Return object entries and weights stored in the set with start and count and weight more than min, less than max
        Parameters:
        namespace - the namespace
        set - name of the sorted set
        start - start offset
        count - maximum number of entries to return
        Returns:
        ordered list of entries in the set matching the given criteria
        Throws:
        IOException - exception thrown from the underlying storage implementation
      • entries

        default Collection<String> entries​(String namespace,
                                           String set)
                                    throws IOException
        Return object entries and weights stored in the set with start and count and weight more than min, less than max
        Parameters:
        namespace - the namespace
        set - name of the sorted set
        Returns:
        ordered list of entries in the set matching the given criteria
        Throws:
        IOException - exception thrown from the underlying storage implementation
      • get

        Map<String,​Long> get​(String namespace,
                                   String set,
                                   long min,
                                   long max,
                                   int start,
                                   int count,
                                   boolean ascending)
                            throws IOException
        Return entries and weights stored in the set with start and count and weight more than min, less than max.
        Parameters:
        namespace - the namespace
        set - name of the sorted set
        min - the minimum weight
        max - the maximum weight
        start - start offset
        count - maximum number of entries to return; -1 for infinite
        ascending - ordered ascending or descending by weight
        Returns:
        map of entries to weights, matching the given criteria
        Throws:
        IOException - exception thrown from the underlying storage implementation
      • get

        default Map<String,​Long> get​(String namespace,
                                           String set)
                                    throws IOException
        Return all entries stored in the set, ordered by weight ascending
        Parameters:
        namespace - the namespace
        set - name of the sorted set
        Returns:
        map of all entries to weights in the given set
        Throws:
        IOException - exception thrown from the underlying storage implementation
      • get

        default Map<String,​Long> get​(String namespace,
                                           String set,
                                           int start,
                                           int count)
                                    throws IOException
        Return entries stored in the set with start and count, ordered by weight ascending
        Parameters:
        namespace - the namespace
        set - name of the sorted set
        start - start offset
        count - maximum number of entries to return
        Returns:
        paginated map of entries to weights
        Throws:
        IOException - exception thrown from the underlying storage implementation
      • delete

        void delete​(String namespace,
                    String set,
                    long min,
                    long max)
             throws IOException
        Deletes all entries in the set with weights between the given min and max, in the given namespace.
        Parameters:
        namespace - the namespace
        set - name of the sorted set
        min - the minimum weight
        max - the maximum weight
        Throws:
        IOException - exception thrown from the underlying storage implementation
      • delete

        default void delete​(String namespace,
                            String set)
                     throws IOException
        Deletes all entries in the set in the given namespace.
        Parameters:
        namespace - the namespace
        set - name of the sorted set
        Throws:
        IOException - exception thrown from the underlying storage implementation
      • delete

        boolean delete​(String namespace,
                       String set,
                       String entry)
                throws IOException
        Deletes an entry from the set in the given namespace.
        Parameters:
        namespace - the namespace
        set - name of the sorted set
        Returns:
        true if entry is found and deleted, false otherwise
        Throws:
        IOException - exception thrown from the underlying storage implementation
      • delete

        void delete​(String namespace,
                    String set,
                    Collection<String> entries)
             throws IOException
        Delete batch of objects from set in the given namespace; no-op if an entry is not found.
        Parameters:
        namespace - the namespace
        set - name of the sorted set
        Throws:
        IOException - exception thrown from the underlying storage implementation
      • union

        Map<String,​Long> union​(String namespace,
                                     Collection<String> sets,
                                     long min,
                                     long max,
                                     int start,
                                     int count,
                                     boolean ascending)
                              throws IOException
        Return union of entries and weights stored in any of the given sets, with start and count and weight more than min, less than max.
        Parameters:
        namespace - the namespace
        sets - name of the sorted sets to do union over
        min - the minimum weight
        max - the maximum weight
        start - start offset
        count - maximum number of entries to return; -1 for infinite
        ascending - ordered ascending or descending by weight
        Returns:
        map of entries to weights, matching the given criteria
        Throws:
        IOException - exception thrown from the underlying storage implementation
      • union

        default Map<String,​Long> union​(String namespace,
                                             Collection<String> sets)
                                      throws IOException
        Return union of all entries stored in the given sets, ordered by weight ascending
        Parameters:
        namespace - the namespace
        sets - name of the sorted sets to do union over
        Returns:
        map of all entries to weights in the given set
        Throws:
        IOException - exception thrown from the underlying storage implementation
      • union

        default Map<String,​Long> union​(String namespace,
                                             Collection<String> sets,
                                             int start,
                                             int count)
                                      throws IOException
        Return entries stored in the set with start and count, ordered by weight ascending
        Parameters:
        namespace - the namespace
        sets - name of the sorted sets to do union over
        start - start offset
        count - maximum number of entries to return
        Returns:
        paginated map of entries to weights
        Throws:
        IOException - exception thrown from the underlying storage implementation
      • intersect

        Map<String,​Long> intersect​(String namespace,
                                         Collection<String> sets,
                                         long min,
                                         long max,
                                         int start,
                                         int count,
                                         boolean ascending)
                                  throws IOException
        Return intersection of entries and weights stored in all of the given sets, with start and count and weight more than min, less than max.
        Parameters:
        namespace - the namespace
        sets - name of the sorted sets to do intersection over
        min - the minimum weight
        max - the maximum weight
        start - start offset
        count - maximum number of entries to return; -1 for infinite
        ascending - ordered ascending or descending by weight
        Returns:
        map of entries to weights, matching the given criteria
        Throws:
        IOException - exception thrown from the underlying storage implementation
      • intersect

        default Map<String,​Long> intersect​(String namespace,
                                                 Collection<String> sets)
                                          throws IOException
        Return intersect of all entries stored in the given sets, ordered by weight ascending
        Parameters:
        namespace - the namespace
        sets - name of the sorted sets to do intersect over
        Returns:
        map of all entries to weights in the given set
        Throws:
        IOException - exception thrown from the underlying storage implementation
      • intersect

        default Map<String,​Long> intersect​(String namespace,
                                                 Collection<String> sets,
                                                 int start,
                                                 int count)
                                          throws IOException
        Return entries stored in the set with start and count, ordered by weight ascending
        Parameters:
        namespace - the namespace
        sets - name of the sorted sets to do intersect over
        start - start offset
        count - maximum number of entries to return
        Returns:
        paginated map of entries to weights
        Throws:
        IOException - exception thrown from the underlying storage implementation
      • pop

        Map<String,​Long> pop​(String namespace,
                                   String set,
                                   long min,
                                   long max,
                                   int start,
                                   int count,
                                   boolean ascending)
                            throws IOException
        Return and atomically remove entries and weights stored in the set with start and count and weight more than min, less than max.
        Parameters:
        namespace - the namespace
        set - name of the sorted set
        min - the minimum weight
        max - the maximum weight
        start - start offset
        count - maximum number of entries to return; -1 for infinite
        ascending - ordered ascending or descending by weight
        Returns:
        map of entries to weights, matching the given criteria
        Throws:
        IOException - exception thrown from the underlying storage implementation
      • pop

        default Map<String,​Long> pop​(String namespace,
                                           String set)
                                    throws IOException
        Return and atomically remove all entries in the set
        Parameters:
        namespace - the namespace
        set - name of the sorted set
        Returns:
        map of all entries to weights in the given set
        Throws:
        IOException - exception thrown from the underlying storage implementation
      • pop

        default Map<String,​Long> pop​(String namespace,
                                           String set,
                                           int start,
                                           int count)
                                    throws IOException
        Return and atomically remove all entries in the set with start and count
        Parameters:
        namespace - the namespace
        set - name of the sorted set
        start - start offset
        count - maximum number of entries to return
        Returns:
        paginated map of entries to weights
        Throws:
        IOException - exception thrown from the underlying storage implementation
      • sets

        Collection<String> sets​(String namespace)
                         throws IOException
        Returns list of all sets in the given namespace.
        Parameters:
        namespace - the namespace
        Returns:
        list of all sets in the namespace
        Throws:
        IOException - exception thrown from the underlying storage implementation
      • size

        int size​(String namespace,
                 String set)
          throws IOException
        Get the number of entries in the set.
        Parameters:
        namespace - the namespace
        set - name of the sorted set
        Returns:
        the number of entries in the set in the namespace
        Throws:
        IOException - exception thrown from the underlying storage implementation
      • first

        default String first​(String namespace,
                             String set)
                      throws IOException
        Get the first entry in the set ordered ascending by weight.
        Parameters:
        namespace - the namespace
        set - name of the sorted set
        Returns:
        the first entry in the set in the namespace if found; null otherwise
        Throws:
        IOException - exception thrown from the underlying storage implementation
      • last

        default String last​(String namespace,
                            String set)
                     throws IOException
        Get the last entry in the set ordered ascending by weight.
        Parameters:
        namespace - the namespace
        set - name of the sorted set
        Returns:
        the last entry in the set in the namespace if found; null otherwise
        Throws:
        IOException - exception thrown from the underlying storage implementation
      • weight

        Long weight​(String namespace,
                    String set,
                    String entry)
             throws IOException
        Returns an entry's weight in the set.
        Parameters:
        namespace - the namespace
        set - name of the sorted set
        Returns:
        the weight associated to the set in the entry in the namespace
        Throws:
        IOException - exception thrown from the underlying storage implementation
      • inc

        long inc​(String namespace,
                 String set,
                 String entry,
                 long count)
          throws IOException
        Atomic operation to increment an entry's weight in the set by the given count and then return the final value.
        Parameters:
        namespace - the namespace
        set - name of the sorted set
        count - count to increment the weight by; use negative values to decrement
        Returns:
        final weight of the entry after incrementing
        Throws:
        IOException - exception thrown from the underlying storage implementation