public final class IdSet extends Object implements Iterable<Integer>, Serializable
Many of Brightpearl's GET APIs, and some searches and destructive resources, allow multiple IDs to be fetched or
modified in one request by specifying comma or dot separated ID ranges (e.g. "1-3,6-15,20"). This class
represents a set of ID ranges and includes a toString() method that generates a valid ID set string for
inclusion in URLs.
Internally, an ordered Set implementation is used, so duplicates are automatically filtered and the ID string
is generated in ascending order, therefore period (.) separation, which indicates unordered IDs, is not used.
This client does not place any limit on the size of an ID set, however Brightpearl does have limits that are not always documented. Bear in mind that requesting a large number of non-sequential IDs will produce an excessively long URL, and that any large number of IDs may result in the request being rejected by Brightpearl or returning a very large response. Some GET resources have corresponding OPTIONs resources that provide a list of individual requests to make in order to retrieve a large set of entities. Where no OPTIONs resource is available, consider limiting ID sets to fewer than 100 IDs and test whether Brightpearl accepts these requests.
| Constructor and Description |
|---|
IdSet()
Initialise a new empty ID set.
|
IdSet(Collection<Integer> ids)
Initialise an ID set containing a collection of IDs.
|
IdSet(Integer... ids)
Initialise an ID set containing IDs from an array or varargs argument.
|
| Modifier and Type | Method and Description |
|---|---|
IdSet |
add(Collection<Integer> ids)
Add IDs from a collection.
|
IdSet |
add(Integer... ids)
Add IDs from an array or varargs argument.
|
IdSet |
addRange(int from,
int to)
Add a range of IDs.
|
static IdSet |
all()
Initialise an empty ID set.
|
static IdSet |
any()
Initialise an empty ID set.
|
boolean |
equals(Object o) |
Set<Integer> |
getIds()
Returns the IDs as a
Set. |
int |
getSize()
Returns the number of IDs in the set.
|
int |
hashCode() |
static IdSet |
ids(Collection<Integer> ids)
Initialise an ID set containing a collection of IDs.
|
static IdSet |
ids(Integer... ids)
Initialise an ID set containing IDs from an array or varargs argument.
|
boolean |
isEmpty()
Returns true if this set contains no IDs.
|
Iterator<Integer> |
iterator()
Returns an iterator over the set of IDs.
|
static IdSet |
parse(String str)
Parse the string representation of an ID set.
|
static IdSet |
range(int from,
int to)
Initialise an ID set with a single range of IDs.
|
Set<IdSet> |
split(int batchSize)
Splits this IdSet into batches of the given size.
|
String |
toString()
Creates a string representation of the ID set for inclusion in URLs.
|
public IdSet()
public IdSet(Integer... ids)
ids - Initial set of IDs to add to the ID set.public IdSet(Collection<Integer> ids)
ids - Initial set of IDs to add to the ID set.public static IdSet any()
public static IdSet all()
public static IdSet ids(Integer... ids)
ids - Initial set of IDs to add to the ID set.public static IdSet ids(Collection<Integer> ids)
ids - Initial set of IDs to add to the ID set.public static IdSet range(int from, int to)
from - first ID (inclusive)to - last ID (inclusive)public static IdSet parse(String str)
str - A string ID set.public IdSet add(Integer... ids)
ids - a set of IDs to add to the ID set.public IdSet add(Collection<Integer> ids)
ids - a collection of IDs to add to the ID set.public IdSet addRange(int from, int to)
from - first ID of the range (inclusive)to - last ID of the range (inclusive)public int getSize()
public boolean isEmpty()
public Iterator<Integer> iterator()
Set.iterator() internally. Iteration will be in
ascending order.public Set<IdSet> split(int batchSize)
If this IdSet is empty, the returned set will be empty.
batchSize - Size of batch.Set of IDSets.public String toString()
Copyright © 2014. All Rights Reserved.