|
Evaluating Software Design Patterns — the "Gang of Four" patterns implemented in Java 6 |
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectdk.rode.thesis.bridge.SequenceValueRange
@Participant(value="ConcreteImplementor") public class SequenceValueRange
A sequence value range generates unique Integer
values within a given range determined at
construction
time.
A sequence value range is ordered
,
sorted
, and do not contain duplicates
.
Field Summary | |
---|---|
private int |
maximum
The maximum value in this range. |
private int |
minimum
The minimum value in this range. |
private int |
value
The current generated value corresponding to a number of value - minimum . |
Constructor Summary | |
---|---|
|
SequenceValueRange(int minimum)
Constructor, which creates this sequence value range to generate Integer values in the range
[minimum, ..[ , i.e. no fixed size. |
|
SequenceValueRange(int minimum,
int maximum)
Constructor, which creates this sequence value range to generate Integer values in the range
[minimum, maximum] . |
private |
SequenceValueRange(int minimum,
int maximum,
int value)
Constructor, which creates this sequence value range to generate Integer values in the range
[minimum, maximum] . |
Method Summary | |
---|---|
private int |
checkNumber(int number,
boolean fail)
Ensures the the number of a given value generated by this value range is legal. |
SequenceValueRange |
copy()
Performs a deep copy of this generator. |
boolean |
duplicates()
Returns true if this generator will generate duplicate (equivalent) values, false if not. |
boolean |
equals(Object object)
Returns true if object is a SequenceValueRange
instance that uses the same value range as this range, false
if not. |
Integer |
first()
Resets this generator to re-generate its first value, where after values can (again) be generated by SequenceValueGenerator.get() . |
Integer |
get()
Returns a value generated by this generator. |
Integer |
get(int number)
Returns the number 'th value generated by this generator,
which may or may not have been generated yet. |
StringablePolicy<? super SequenceValueGenerator<Integer>> |
getStringablePolicy(StringablePolicy<? super SequenceValueGenerator<Integer>> policy)
Always return a non-null policy: policy is not null: policy is returned. |
Class<Integer> |
getValueType()
Returns the actual type of the values generated by this generator. |
int |
hashCode()
Returns the hash code of this value range. |
int |
number()
Returns the number of the the last value generated by either SequenceValueGenerator.first() , SequenceValueGenerator.get() , or SequenceValueGenerator.get(int) . |
int |
numberOf(Integer value,
int fromNumber)
Returns the number of the generated value supplied as value
using an offset of fromNumber , or Const.EOF if no
such value will ever been generated by this generator. |
boolean |
ordered()
Returns true if the values generated by this generator are ordered, i.e. always delivered in some known order. |
int |
size()
Returns the number of values that can be generated by this generator in total, excluding re-generation of values after a call to SequenceValueGenerator.first() . |
boolean |
sorted()
Returns true if the values generated by this generator are sorted, for example based on numerical value in case of numbers. |
String |
toString()
Returns the string representation of this value range. |
CharSequence |
toString(StringablePolicy<? super SequenceValueGenerator<Integer>> policy)
Returns a char sequence representation of this stringable object using the format determined by policy or the
default policy
in case policy is null. |
Methods inherited from class java.lang.Object |
---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
private final int maximum
Will be Const.INFINITE
if the range has no maximum.
private final int minimum
private int value
value
- minimum
.
Range is: minimum
<= number [<= maximum
, if maximum != INFINITE
]
Constructor Detail |
---|
public SequenceValueRange(int minimum)
Integer
values in the range
[minimum, ..[
, i.e. no fixed size.
minimum
- The minimum value to generate.public SequenceValueRange(int minimum, int maximum)
Integer
values in the range
[minimum, maximum]
.
minimum
- The minimum value to generate.maximum
- The maximum value to generate; must be >= minimum
.
IllegalArgumentException
- If minimum
> maximum
.private SequenceValueRange(int minimum, int maximum, int value)
Integer
values in the range
[minimum, maximum]
.
minimum
- The minimum value to generate.maximum
- The maximum value to generate; must be >= minimum
if not Const.INFINITE
.value
- The current value, offset by minimum
.
IllegalArgumentException
- If minimum
> maximum
,
or if value
is illegal.Method Detail |
---|
private final int checkNumber(int number, boolean fail)
fail
is true, an
illegal argument exception is thrown.
A valid range is minimum
<= number [<= maximum
, if maximum != INFINITE
]
number
- The number to check.fail
- If true, an exception is thrown if number
is illegal, otherwise Const.EOF
is returned.
If legal, a number is always returned.
number
, or EOF
.
IllegalArgumentException
- If fail
is true and if
number
is illegal.public SequenceValueRange copy()
The size
, ordered
,
sorted
, and duplicate
properties are adhered to by the returned clone.
copy
in interface SequenceValueGenerator<Integer>
copy
in interface Copyable<SequenceValueGenerator<Integer>>
public boolean duplicates()
SequenceValueGenerator
The test for duplicates is performed using equals(Object)
.
duplicates
in interface SequenceValueGenerator<Integer>
public boolean equals(Object object)
object
is a SequenceValueRange
instance that uses the same value range as this range, false
if not.
equals
in class Object
object
- The object to test; can be null.
public Integer first()
SequenceValueGenerator
SequenceValueGenerator.get()
.
The number
of generated values is reset when
this method is invoked.
If this generator does not generate ordered
, nor
sorted
values, it is undefined which value is
generated as the first value.
first
in interface SequenceValueGenerator<Integer>
public Integer get()
SequenceValueGenerator
The number of the generated value is one higher than the last
value returned by either SequenceValueGenerator.first()
, SequenceValueGenerator.get()
,
or SequenceValueGenerator.get(int)
.
The number
of generated values is reset
when first()
is invoked.
If this generator generates ordered
or
sorted
values, the generation of values
is consistent even after SequenceValueGenerator.first()
have been invoked.
Otherwise the order is undefined.
get
in interface SequenceValueGenerator<Integer>
SequenceValueGenerator.get(int)
public Integer get(int number)
SequenceValueGenerator
number
'th value generated by this generator,
which may or may not have been generated yet. The next call to
SequenceValueGenerator.get()
from generate and return the number + 1
'th
value.
The number
of generated values is reset
when first()
is invoked.
If this generator generates ordered
or
sorted
values, the generation of values is
consistent even after SequenceValueGenerator.first()
have been invoked. Otherwise
the order is undefined, and this method may generate
different values for the same number each time invoked.
get
in interface SequenceValueGenerator<Integer>
number
- The number in question; cannot be zero or negative.
Is one-, not zero-based!
number
'th value generated by this generator;
never null.SequenceValueGenerator.get()
,
SequenceValueGenerator.numberOf(Object, int)
public StringablePolicy<? super SequenceValueGenerator<Integer>> getStringablePolicy(StringablePolicy<? super SequenceValueGenerator<Integer>> policy)
Stringable
policy
is not null: policy
is returned.
policy
is null: a default, non-null policy is returned.
getStringablePolicy
in interface Stringable<SequenceValueGenerator<Integer>>
policy
- The supplied policy; can be null.
Stringable.toString(StringablePolicy)
public Class<Integer> getValueType()
SequenceValueGenerator
getValueType
in interface SequenceValueGenerator<Integer>
public int hashCode()
hashCode
in class Object
public int number()
SequenceValueGenerator
SequenceValueGenerator.first()
, SequenceValueGenerator.get()
, or SequenceValueGenerator.get(int)
.
The number of generated values is reset when first()
is invoked, i.e. to a number of one.
Notice, that first
and get(int)
alter the
number count of values generated, which will be reflected in
the next invocation of get()
!
Range: 1 (0) < number < SequenceValueGenerator.size()
, if size != INFINITE
.
A number of zero will only occur when no values have been generated yet.
number
in interface SequenceValueGenerator<Integer>
public int numberOf(Integer value, int fromNumber)
SequenceValueGenerator
value
using an offset of fromNumber
, or Const.EOF
if no
such value will ever been generated by this generator.
Unlike SequenceValueGenerator.first()
, SequenceValueGenerator.get()
, and SequenceValueGenerator.get(int)
, this
method will not alter the number of values generated by this
generator.
numberOf
in interface SequenceValueGenerator<Integer>
value
- The value to test; cannot be null.fromNumber
- The number to start from; only relevant if the
values generated contain duplicates
. Is one-, not zero-based! If
larger than SequenceValueGenerator.size()
, this method will
always return EOF
.
value
,
or EOF
if no such value can be generated by
this value generator.SequenceValueGenerator.get(int)
public boolean ordered()
SequenceValueGenerator
ordered
in interface SequenceValueGenerator<Integer>
public int size()
SequenceValueGenerator
SequenceValueGenerator.first()
.
Whether or not the count include duplicates
is sub-class specific. If duplicates
is false, the
size is always equal to the number of unique values generated
by this generator.
size
in interface SequenceValueGenerator<Integer>
Const.INFINITE
if this
generator has no (practical) bounds on the number of
values it can generate.public boolean sorted()
SequenceValueGenerator
sorted
in interface SequenceValueGenerator<Integer>
public String toString()
toString
in class Object
public CharSequence toString(StringablePolicy<? super SequenceValueGenerator<Integer>> policy)
Stringable
policy
or the
default
policy
in case policy
is null.
In Foo
, a typical implementation of this method
could be:
public CharSequence toString(StringablePolicy<? super Foo> policy) { return this.There are two approaches to formatting this stringable object into a char sequence representation:getStringablePolicy
(policy).toString
(this); }
policy
decide the entire format,
as in the Foo
example above; or
policy
to format part of the overall
representation, for example letting this method append
certain text regardless of the policy used.
StringablePolicy.toString(Object)
method, for
example in case multiple stringable objects should be formatted
into an overall representation.
In case an implementation uses the approach from bullet 2), care
must be take to respect the policy hints
so the overall format remains meaningful.
toString
in interface Stringable<SequenceValueGenerator<Integer>>
policy
- The policy to dictate the formatting; can be null, in
which case the result of toString
method
is returned.
StringablePolicy.Type
|
Gunni Rode / rode.dk | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |