|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object jaggregate.AbstractCollection<E> jaggregate.Interval<E>
E
- a restriction on the kinds of numbers that can be in the intervalpublic class Interval<E extends Number>
Represents a collection whose elements form an arithmetic progression.
Currently, all the derivatives ofNumber
in JDK 5 that override
equals
for value equality are supported as type
arguments for this class. This excludes the new AtomicInteger
and
AtomicLong
.
This class does nothing to compensate for the inexact representation of primitive
floating-point values; keep this in mind when using intervals of float
or
double
.
Constructor Summary | |
---|---|
Interval(E from,
E to)
Creates an interval representing an arithmetic progression from one number to another, in increments of 1. |
|
Interval(E from,
E to,
E by)
Creates an interval representing an arithmetic progression from one number to another, with the given increment. |
Method Summary | ||
---|---|---|
E |
after(E target)
Answers the object immediately following the first element which is equivalent to the given target in this sequence. |
|
E |
at(int index)
Answers the element at the given position in this sequence. |
|
E |
before(E target)
Answers the object immediately preceding the first element which is equivalent to the given target in this sequence. |
|
|
collect(UnaryFunctor<? super E,? extends R> transformer)
Evaluates the given transformer for each element of this collection, with the element as the parameter, and answers a new collection containing the results of these evaluations. The elements are traversed in the order specified by forEachDo for this collection.
Unless specifically refined, this message is defined to answer an object
conforming to the same protocol as this collection. |
|
ReadOnlySequence<E> |
concat(ReadOnlySequence<? extends E> otherSequence)
Answers a new sequence containing all of this sequence's elements in their original order followed by all of the elements of the given sequence, in their original order. |
|
ReadOnlySequence<E> |
copyRange(int start,
int stop)
Answers a new sequence containing the specified range of elements of this sequence in their original order. |
|
ReadOnlySequence<E> |
copyWith(E newElement)
Answers a new sequence with size one greater than the size of this sequence, containing the elements of this sequence and a given new element placed at the end. |
|
ReadOnlySequence<E> |
copyWithout(E oldElement)
Answers a new sequence with all of the elements of this sequence that are not equivalent to the given element, in their original order. |
|
void |
doWithIndex(BinaryFunctor<? super Integer,? super E,?> operation)
Evaluates the given operation with the index of each element of this sequence, in order, together with the element itself. |
|
|
doWithOthers(ReadOnlySequence<? extends T> otherSequence,
BinaryFunctor<? super E,? super T,?> operation)
For each element of this sequence and the corresponding element of the given sequence, evaluates the given operation with this sequence's element as the first parameter, and the element of the other sequence as the second parameter. |
|
boolean |
equals(Object that)
|
|
int |
findFirst(UnaryCondition<? super E> discriminator)
Answers the index of the first element which causes the given discriminator to answer true when the element is used as a parameter. |
|
int |
findLast(UnaryCondition<? super E> discriminator)
Answers the index of the last element which causes the given discriminator to answer true when the element is used as a parameter. |
|
E |
first()
Answers the element at index 0 in this sequence. |
|
void |
forEachDo(UnaryFunctor<? super E,?> operation)
For each element of this collection, evaluates the given operation with the element as the parameter. |
|
void |
forEachInRangeDo(int start,
int stop,
UnaryFunctor<? super E,?> operation)
For those elements of this sequence between two given positions, inclusive, evaluates the given operation with the element at that index as its argument. |
|
void |
forEachInRangeDoWithIndex(int start,
int stop,
BinaryFunctor<? super Integer,? super E,?> operation)
For those elements of this sequence between two given positions, inclusive, evaluates the given operation with an element of this sequence as the first argument and the element's position (index) as the second. |
|
void |
forEachInReverseDo(UnaryFunctor<? super E,?> operation)
Evaluates the given operation with each element of this sequence in the reverse of this sequence's standard traversal order. |
|
static
|
fromTo(T from,
T to)
Creates an interval representing an arithmetic progression from one number to another, in increments of 1. |
|
static
|
fromToBy(T from,
T to,
T by)
Creates an interval representing an arithmetic progression from one number to another, with the given increment. |
|
int |
hashCode()
|
|
boolean |
includes(E target)
Answers true if an element of this collection is equivalent to the
given one; answers false otherwise. |
|
int |
indexOf(E target)
Answers the index of the first element which is equivalent to the given target}. |
|
int |
indexOf(ReadOnlySequence<? extends E> targetSequence,
int start)
Answers the index of the first element of this sequence which is the start of a subsequence which matches a given target sequence. |
|
E |
last()
Answers the last element of this sequence, the element at the index equal to this sequence's size minus 1. |
|
ReadOnlySequence<E> |
reject(UnaryCondition<? super E> discriminator)
Answers a new collection which contains only the elements in this collection which cause the given discriminator to answer false .
For each element of this collection, discriminator is evaluated with the
element as the parameter. Each element which causes discriminator to
answer false is included in the new collection.
The elements are traversed in the order specified by forEachDo for this collection.
Unless specifically refined, this message is defined to answer an object
conforming to the same protocol as this collection. If both this collection
and the result maintain an ordering of their elements, the elements of the
result will be in the same relative order as the elements of this collection. |
|
ReadOnlySequence<E> |
reverse()
Answers a sequence with the elements of this sequence arranged in reverse order. |
|
ReadOnlySequence<E> |
select(UnaryCondition<? super E> discriminator)
Answers a new collection which contains only the elements in this collection which cause the given discriminator to answer true .
For each element of this collection, discriminator is evaluated with the
element as the parameter. Each element which causes discriminator to
answer true is included in the new collection.
The elements are traversed in order specified by forEachDo for this collection.
Unless specifically refined, this message is defined to answer an object
conforming to the same protocol as this collection. If both this collection
and the result maintain an ordering of their elements, the elements of the
result will be in the same relative order as the elements of this collection. |
|
int |
size()
Answers the number of elements in this collection. |
|
String |
toString()
|
Methods inherited from class jaggregate.AbstractCollection |
---|
allSatisfy, anySatisfy, detect, inject, isEmpty, occurrencesOf, rehash, toArray, toArray, toBag, toIdentityBag, toIdentitySet, toOrderedCollection, toSet, toSortedCollection, toSortedCollection |
Methods inherited from class java.lang.Object |
---|
getClass, notify, notifyAll, wait, wait, wait |
Methods inherited from interface jaggregate.Collection |
---|
allSatisfy, anySatisfy, detect, inject, isEmpty, occurrencesOf, rehash, toArray, toArray, toBag, toIdentityBag, toIdentitySet, toOrderedCollection, toSet, toSortedCollection, toSortedCollection |
Constructor Detail |
---|
public Interval(E from, E to)
from > to
.
from
- the first element in the intervalto
- the last element of the interval
NullPointerException
- if either from
or to
is null
public Interval(E from, E to, E by)
by
can be negative.
Note that to
is not necessarily an element in the interval.
The last element is given by:
( to - from ) / by * by + from
The interval will be empty if from < to
and
by < 0
, or if from > to
and by > 0
.
from
- the first element in the intervalto
- the termination of the intervalby
- the increment to use to compute successive interval values. If this is
null
, it will be treated as 1.
NullPointerException
- if either from
or to
is null
IllegalArgumentException
- if by == 0
Method Detail |
---|
public static <T extends Number> Interval<T> fromTo(T from, T to)
from > to
.
T
- the type of numbers in the intervalfrom
- the first element in the intervalto
- the last element of the interval
NullPointerException
- if either from
or to
is null
public static <T extends Number> Interval<T> fromToBy(T from, T to, T by)
by
can be negative.
Note that to
is not necessarily an element in the interval.
The last element is given by:
( to - from ) / by * by + from
The interval will be empty if from < to
and
by < 0
, or if from > to
and by > 0
.
T
- the type of numbers in the intervalfrom
- the first element in the intervalto
- the termination of the intervalby
- the increment to use to compute successive interval values. If this is
null
, it will be treated as 1.
NullPointerException
- if from
, to
, or by
is
null
IllegalArgumentException
- if by == 0
public <R> ReadOnlySequence<R> collect(UnaryFunctor<? super E,? extends R> transformer)
forEachDo
for this collection.
Unless specifically refined, this message is defined to answer an object
conforming to the same protocol as this collection.
collect
in interface Collection<E extends Number>
collect
in interface ReadOnlySequence<E extends Number>
collect
in class AbstractCollection<E extends Number>
R
- return type of the transformertransformer
- the transformer to evaluate
public ReadOnlySequence<E> reject(UnaryCondition<? super E> discriminator)
false
.
For each element of this collection, discriminator
is evaluated with the
element as the parameter. Each element which causes discriminator
to
answer false
is included in the new collection.
The elements are traversed in the order specified by forEachDo
for this collection.
Unless specifically refined, this message is defined to answer an object
conforming to the same protocol as this collection. If both this collection
and the result maintain an ordering of their elements, the elements of the
result will be in the same relative order as the elements of this collection.
reject
in interface Collection<E extends Number>
reject
in interface ReadOnlySequence<E extends Number>
reject
in class AbstractCollection<E extends Number>
discriminator
- the discriminator to evaluate
public ReadOnlySequence<E> select(UnaryCondition<? super E> discriminator)
true
.
For each element of this collection, discriminator
is evaluated with the
element as the parameter. Each element which causes discriminator
to
answer true
is included in the new collection.
The elements are traversed in order specified by forEachDo
for this collection.
Unless specifically refined, this message is defined to answer an object
conforming to the same protocol as this collection. If both this collection
and the result maintain an ordering of their elements, the elements of the
result will be in the same relative order as the elements of this collection.
select
in interface Collection<E extends Number>
select
in interface ReadOnlySequence<E extends Number>
select
in class AbstractCollection<E extends Number>
discriminator
- the discriminator to evaluate
public ReadOnlySequence<E> concat(ReadOnlySequence<? extends E> otherSequence)
otherSequence
.
Sequences that enforce an ordering on their elements are permitted to refine
this message to reorder the result.
concat
in interface ReadOnlySequence<E extends Number>
otherSequence
- the sequence to concatenate
public E after(E target)
target
is the traversal order defined by forEachDo
for
this sequence.
after
in interface ReadOnlySequence<E extends Number>
target
- the object to lookup
target
public E at(int index)
at
in interface ReadOnlySequence<E extends Number>
index
- the index to lookup
public E before(E target)
before
in interface ReadOnlySequence<E extends Number>
target
- the object to lookup
target
public ReadOnlySequence<E> copyRange(int start, int stop)
start
in this
sequence is at index 0
in the new sequence; the element at
start + 1
is at index 1
, etc. If stop < start
, then the
new sequence is empty. Otherwise, the size of the new sequence is max(0, stop - start)
.
The given indices must be non-negative.
copyRange
in interface ReadOnlySequence<E extends Number>
start
- the beginning indexstop
- the ending index
public ReadOnlySequence<E> copyWith(E newElement)
copyWith
in interface ReadOnlySequence<E extends Number>
newElement
- element to add to the copy
newElement
appendedpublic ReadOnlySequence<E> copyWithout(E oldElement)
copyWithout
in interface ReadOnlySequence<E extends Number>
oldElement
- the element to strip from the copy of this sequence
oldElement
removedpublic int findFirst(UnaryCondition<? super E> discriminator)
true
when the element is used as a parameter. Answers -1
if no such element is found.
The elements are traversed in the order specified by forEachDo
for this sequence.
findFirst
in interface ReadOnlySequence<E extends Number>
discriminator
- the discriminator to evaluate
-1
if there is no matchpublic int findLast(UnaryCondition<? super E> discriminator)
true
when the element is used as a parameter. Answers -1
if no such element is found.
The elements are traversed in the order specified by forEachInReverseDo
for this sequence.
findLast
in interface ReadOnlySequence<E extends Number>
discriminator
- the discriminator to evaluate
-1
if there is no matchpublic void forEachInReverseDo(UnaryFunctor<? super E,?> operation)
forEachDo
. Each element
is visited exactly once.
forEachInReverseDo
in interface ReadOnlySequence<E extends Number>
operation
- the operation to evaluatepublic E first()
0
in this sequence.
first
in interface ReadOnlySequence<E extends Number>
public void forEachInRangeDo(int start, int stop, UnaryFunctor<? super E,?> operation)
forEachInRangeDo
in interface ReadOnlySequence<E extends Number>
start
- beginning indexstop
- ending indexoperation
- the operation to evaluatepublic void forEachInRangeDoWithIndex(int start, int stop, BinaryFunctor<? super Integer,? super E,?> operation)
forEachInRangeDoWithIndex
in interface ReadOnlySequence<E extends Number>
start
- beginning indexstop
- ending indexoperation
- the operation to evaluatepublic int indexOf(E target)
-1
if no such element is found.
The elements are traversed in the order specified by forEachDo
for this sequence.
indexOf
in interface ReadOnlySequence<E extends Number>
target
- element to match
-1
if no matchpublic int indexOf(ReadOnlySequence<? extends E> targetSequence, int start)
start
is checked for
a match with targetSequence
. To match, each element of a subsequence of
this sequence must be equivalent to the corresponding element of\
targetSequence
. Answers the index of the first element which begins a
matching subsequence; no further subsequences are considered.
Answers -1
if no such subsequence is found in this sequence, or if
targetSequence
is empty.
The elements are traversed in the order specified by forEachDo
message for this sequence.
indexOf
in interface ReadOnlySequence<E extends Number>
targetSequence
- sequence to matchstart
- index at which to begin the search
-1
if nonepublic void doWithIndex(BinaryFunctor<? super Integer,? super E,?> operation)
operation
is evaluated with the index of each element of this sequence as
the first argument and the element itself as the second argument. Evaluation is
in indexed order starting at 0
. The first element is at index 0
,
the second at index 1
, etc. The index of the last element is equal to
this sequence's size minus 1.
doWithIndex
in interface ReadOnlySequence<E extends Number>
operation
- the operation to performpublic E last()
last
in interface ReadOnlySequence<E extends Number>
public ReadOnlySequence<E> reverse()
forEachInReverseDo
message,
adding each element of this sequence to the new sequence.
reverse
in interface ReadOnlySequence<E extends Number>
public boolean equals(Object that)
equals
in class Object
public int hashCode()
hashCode
in class Object
public String toString()
toString
in class Object
public <T> void doWithOthers(ReadOnlySequence<? extends T> otherSequence, BinaryFunctor<? super E,? super T,?> operation)
otherSequence
must have the same size.
The elements of this sequence and otherSequence
are traversed in indexed
order starting at 0
. The operation
is evaluated with the
elements at index 0
in the two sequences, then index 1
, etc.
doWithOthers
in interface ReadOnlySequence<E extends Number>
T
- a constraint on the types of elements in the given sequenceotherSequence
- the other elements to use in the evaluationoperation
- the operation to performpublic void forEachDo(UnaryFunctor<? super E,?> operation)
forEachDo
in interface Collection<E extends Number>
forEachDo
in interface ReadOnlySequence<E extends Number>
operation
- the operation to performpublic boolean includes(E target)
true
if an element of this collection is equivalent to the
given one; answers false
otherwise.
includes
in interface Collection<E extends Number>
includes
in class AbstractCollection<E extends Number>
target
- the object to compare against
public int size()
size
in interface Collection<E extends Number>
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |