Package com.salesforce.cantor
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 voidadd(String namespace, String set, String entry)Add an entry with weight of 0 to the set in the given namespace.voidadd(String namespace, String set, String entry, long weight)Add an entry with a weight to the set in the given namespace.voidadd(String namespace, String set, Map<String,Long> entries)Add batch of entries/weights to the set in the given namespace.default voiddelete(String namespace, String set)Deletes all entries in the set in the given namespace.voiddelete(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.booleandelete(String namespace, String set, String entry)Deletes an entry from the set in the given namespace.voiddelete(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 maxdefault 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 maxdefault 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 maxCollection<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 Stringfirst(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 ascendingdefault 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 ascendingMap<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.longinc(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 ascendingdefault 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 ascendingMap<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 Stringlast(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 setdefault Map<String,Long>pop(String namespace, String set, int start, int count)Return and atomically remove all entries in the set with start and countMap<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.intsize(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 ascendingdefault 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 ascendingMap<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.Longweight(String namespace, String set, String entry)Returns an entry's weight in the set.-
Methods inherited from interface com.salesforce.cantor.Namespaceable
create, drop
-
-
-
-
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 namespaceset- name of the set to add the entry toentry- the entryweight- 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 namespaceset- name of the set to add the entry toentry- 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 namespaceset- name of the set to add the entry toentries- 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 namespaceset- name of the sorted setmin- the minimum weightmax- the maximum weightstart- start offsetcount- maximum number of entries to returnascending- 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 namespaceset- name of the sorted setstart- start offsetcount- maximum number of entries to returnascending- 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 namespaceset- name of the sorted setstart- start offsetcount- 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 namespaceset- 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 namespaceset- name of the sorted setmin- the minimum weightmax- the maximum weightstart- start offsetcount- maximum number of entries to return; -1 for infiniteascending- 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 namespaceset- 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 namespaceset- name of the sorted setstart- start offsetcount- 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 namespaceset- name of the sorted setmin- the minimum weightmax- 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 namespaceset- 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 namespaceset- 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 namespaceset- 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 namespacesets- name of the sorted sets to do union overmin- the minimum weightmax- the maximum weightstart- start offsetcount- maximum number of entries to return; -1 for infiniteascending- 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 namespacesets- 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 namespacesets- name of the sorted sets to do union overstart- start offsetcount- 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 namespacesets- name of the sorted sets to do intersection overmin- the minimum weightmax- the maximum weightstart- start offsetcount- maximum number of entries to return; -1 for infiniteascending- 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 namespacesets- 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 namespacesets- name of the sorted sets to do intersect overstart- start offsetcount- 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 namespaceset- name of the sorted setmin- the minimum weightmax- the maximum weightstart- start offsetcount- maximum number of entries to return; -1 for infiniteascending- 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 namespaceset- 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 namespaceset- name of the sorted setstart- start offsetcount- 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 namespaceset- 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 namespaceset- 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 namespaceset- 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 namespaceset- 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 namespaceset- name of the sorted setcount- 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
-
-