A
- the element type@ValueType public final class Single<A> extends Object implements Tuple.Ops1<A>, Serializable
Tuple.Ops1<A>, Tuple.Ops2<A,B>, Tuple.Ops3<A,B,C>, Tuple.Ops4<A,B,C,D>, Tuple.Ops5<A,B,C,D,E>
Modifier and Type | Method and Description |
---|---|
<T> Pair<A,T> |
add(T t)
Adds a new item to this tuple.
|
List<A> |
asList()
Returns a view of this tuple as a list.
|
boolean |
contains(Object o)
Determines if this tuple contains the specified object.
|
static <T> List<Single<T>> |
enclose(Collection<? extends T> coll)
Encloses a collection of values into a collection of units.
|
boolean |
equals(Object o)
Compares this tuple with the specified object.
|
static <T> List<T> |
extract(Collection<Single<T>> units)
Extracts values from a collection of units into a collection of values.
|
A |
getFirst()
Retrieves the first item in the tuple.
|
int |
hashCode()
Returns the hash code value for this tuple.
|
<T> Pair<T,A> |
insertFirst(T t)
Adds an item into the first position of this tuple.
|
<T> Pair<A,T> |
insertSecond(T t)
Inserts an item into the second position of this tuple.
|
boolean |
isEmpty()
Determines whether the tuple has any items.
|
Iterator<Object> |
iterator() |
static <T> Single<T> |
of(T t)
Creates a new single element tuple.
|
Empty |
removeFirst()
Removes the first item from the tuple.
|
<T> Single<T> |
setFirst(T t)
Sets the first item in the tuple.
|
int |
size()
Returns the number of items in the tuple.
|
boolean |
test(Predicate<? super A> predicate)
Tests the contained value using the specified predicate.
|
Object[] |
toArray()
Returns an array of the items in this tuple.
|
<T> T[] |
toArray(T[] a)
Returns an array of the items in this tuple.
|
String |
toString() |
<B> B |
transform(Function<? super A,? extends B> function)
Transforms the contained value and returns the results.
|
<T> Single<T> |
transformAll(Function<Object,? extends T> function)
Transforms every item in this tuple by applying the specified function to each one.
|
<T> Single<T> |
transformFirst(Function<? super A,? extends T> function)
Transforms the first item in the tuple using the specified function.
|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
forEach, spliterator
public static <T> List<T> extract(Collection<Single<T>> units)
units
- a collection of unitspublic static <T> List<Single<T>> enclose(Collection<? extends T> coll)
coll
- a collection of valuespublic static <T> Single<T> of(T t)
t
- the sole elementpublic List<A> asList()
Since this tuple has exactly one element and we know its type, we can return a precise type
instead of returning List<?>
.
public boolean contains(Object o)
Tuple
e1
is equal to an
object e2
if (e1==null ? e2==null : e1.equals(e2))
.)public int size()
Tuple
public boolean isEmpty()
Tuple
public A getFirst()
Tuple.Ops1
getFirst
in interface Tuple.Ops1<A>
public Object[] toArray()
Tuple
public <T> Single<T> setFirst(T t)
Tuple.Ops1
setFirst
in interface Tuple.Ops1<A>
t
- the new itempublic Empty removeFirst()
Tuple.Ops1
removeFirst
in interface Tuple.Ops1<A>
public <T> Pair<A,T> add(T t)
Tuple
add
in interface Tuple
add
in interface Tuple.Ops1<A>
t
- the item to addpublic <T> Pair<T,A> insertFirst(T t)
Tuple
insertFirst
in interface Tuple
insertFirst
in interface Tuple.Ops1<A>
t
- the item to insertpublic <T> Pair<A,T> insertSecond(T t)
Tuple.Ops1
If this tuple has only one item then this is the same as calling Tuple.Ops1.add(Object)
.
Otherwise, this will insert an item after the first item but before the second.
insertSecond
in interface Tuple.Ops1<A>
t
- the new itempublic <T> Single<T> transformAll(Function<Object,? extends T> function)
Tuple
transformAll
in interface Tuple
transformAll
in interface Tuple.Ops1<A>
function
- the function to applypublic <T> Single<T> transformFirst(Function<? super A,? extends T> function)
Tuple.Ops1
transformFirst
in interface Tuple.Ops1<A>
function
- the function to applypublic <B> B transform(Function<? super A,? extends B> function)
function
- the functionpublic boolean test(Predicate<? super A> predicate)
predicate
- the predicatepublic <T> T[] toArray(T[] a)
Tuple
If this tuple fits in the specified array with room to spare (i.e., the array has more
elements than this tuple), the element in the array immediately following the last element of
the tuple is set to null
. (This is useful in determining the length of this tuple
only if the caller knows that this tuple does not contain any null
elements.)
toArray
in interface Tuple
a
- an array with the desired runtime typeCollection.toArray(Object[])
public boolean equals(Object o)
Tuple
Tuple
and has the same items as this tuple in the same order, then this tuple is equal to the
specified object. (Two elements e1
and e2
are equal if
(e1==null ? e2==null : e1.equals(e2))
.)public int hashCode()
Tuple
Arrays.hashCode(tuple.toArray())
. This is effectively the same as
List.hashCode()
for a list with the same items and in the same order as this tuple.