T
- element type of the incoming setpublic class Combinations<T> extends java.lang.Object implements java.lang.Iterable<Indexable<T>>
Combinations returned will be ordered when considering the index into the incoming elements:
"ABCD"
will return
"AB"
"AC"
"BC"
"AD"
"BD"
"CD"
Combinations.OfRange
is the most basic and takes care of combinations of consecutive indices.
Indeed all other combinations classes are based on createRangeIterator(int, int)
which is used without overhead only by OfRange
.
Combinations.OfInt
handle combinations of arbitrary int
values.Combinations.OfLong
handles combinations of arbitrary long
values.Combinations.OfShort
handles combinatons of arbitrary short
values.Combinations.OfByte
handles combinations of arbitrary byte
values.Combinations.OfDouble
handles combinations of arbitrary double
values.Combinations.OfFloat
handles combintaions of arbitrary float
values.Combinations.OfChar
handles combinations of arbitrary char
values.Combinations.OfString
handles combinations of the characters of a java.lang.CharSequence
.Combinations.OfBoolean
handles combintaions of arbitrary byte
values.Modifier and Type | Class and Description |
---|---|
static class |
Combinations.OfBoolean
Combinations of boolean values.
|
static class |
Combinations.OfByte
Combinations of byte values.
|
static class |
Combinations.OfChar
Combinations of char values.
|
static class |
Combinations.OfDouble
Combinations of double values.
|
static class |
Combinations.OfFloat
Combinations of float values.
|
static class |
Combinations.OfInt
The combinations of integer values.
|
static class |
Combinations.OfLong
Combinations of long values.
|
static class |
Combinations.OfRange
The combinations of an index range.
|
static class |
Combinations.OfShort
Combinations of short values.
|
static class |
Combinations.OfString
The combinations of the characters of a string, as strings.
|
Constructor and Description |
---|
Combinations(int k,
java.util.Collection<T> set)
Constructor.
|
Combinations(int k,
Countable<T> set)
Constructor.
|
Combinations(int k,
Indexable<T> elements)
Constructor.
|
Combinations(int k,
java.util.List<T> list)
Constructor.
|
Combinations(int k,
T... elems)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
(package private) static void |
checkBinomial(int n,
int k)
Check the parameters of a "n choice k" for sanity.
|
static java.math.BigInteger |
count(int n,
int k)
Get the number of combinations for n choose k.
|
static java.util.Iterator<IntIndexable> |
createRangeIterator(int n,
int k)
Create an iterator which iterates of the subsets of size
k
from the set {0, 1, 2, ..., n-1} . |
java.util.Iterator<Indexable<T>> |
iterator() |
static void |
main(java.lang.String[] args) |
public Combinations(int k, @NotNull Indexable<T> elements)
k
- number of elements to choose, has to be non-negative
and not more the size of the elements
setelements
- set from which elements are chosenpublic Combinations(int k, @NotNull java.util.List<T> list)
k
- number of elements to choose, has to be non-negative
and not more the size of the list
list
- list from which elements will be cosenpublic Combinations(int k, @NotNull Countable<T> set)
k
- number of elements to choose, has to be non-negative
and not more the size of the set
set
- set from which elements will be chosenpublic Combinations(int k, @NotNull java.util.Collection<T> set)
k
- number of elements to choose, has to be non-negative
and not more the size of the set
set
- set from which elements will be chosen@NotNull public static java.util.Iterator<IntIndexable> createRangeIterator(int n, int k)
k
from the set {0, 1, 2, ..., n-1}
.
As the latter can be used as indices this iterator can be used as a base for chosing from any set.
n
- number of elements in the set from which is chosenk
- number of elements in the chosen sub setsstatic void checkBinomial(int n, int k)
n
- n, size of the set from which is chosenk
- k, number of chosen elementsjava.lang.IllegalArgumentException
- if parameters are invalid@NotNull public static java.math.BigInteger count(int n, int k)
n
- n, size of the set from which is chosenk
- k, number of chosen elementsjava.lang.IllegalArgumentException
- if parameters are invalidpublic static void main(java.lang.String[] args)