public class GlobalCredit extends java.lang.Object implements java.io.Serializable, java.lang.Iterable<CreditCard>
The collection encapsulated by this class is an example of dynamic allocation; i.e. it can grow and shrink as needed.
Constructor and Description |
---|
GlobalCredit()
Construct a GCC having the name "NoName".
|
GlobalCredit(java.lang.String name)
Construct a GCC having the passed name.
|
Modifier and Type | Method and Description |
---|---|
boolean |
add(CreditCard card)
Attempt to add the passed credit card to
this GCC. |
CreditCard |
get(java.lang.String number)
Find the card whose number is passed.
|
CreditCard |
getFirst()
Deprecated.
As of version 4.0, replaced with
iterator() The base
invocation of the forward iterator. |
CreditCard |
getNext()
Deprecated.
As of version 4.0, replaced with
iterator() Follow
up invocation of the forward iterator. |
static GlobalCredit |
getRandom()
Create a randomly chosen GCC.
|
static GlobalCredit |
getRandom(boolean same)
Create a randomly chosen GCC.
|
java.util.Iterator<CreditCard> |
iterator()
Determine an Iterator over the credit cards in
this centre. |
CreditCard |
remove(java.lang.String number)
Remove the card whose number is passed from
this GCC. |
int |
size()
Determine the number of credit cards registered with
this
GCC. |
java.lang.String |
toString()
Return a string representation of this GCC.
|
public GlobalCredit(java.lang.String name)
name
- the name (typically city name) of this GCC.public GlobalCredit()
public boolean add(CreditCard card)
this
GCC. If a card
of the same number is already present, no addition is done.card
- a reference to the card to be added.true
if the card was added and false
if
not. The card is not added if a card with the same number has
already been added.java.lang.RuntimeException
- if the passed parameter is null.public CreditCard remove(java.lang.String number)
this
GCC.number
- the number of the card to remove.null
if there is
no card with such a number in the GCC.public CreditCard get(java.lang.String number)
number
- the number of the card to find.null
is returned.public int size()
this
GCC.this
GCC.public java.lang.String toString()
toString
in class java.lang.Object
"Global Credit Company [title]: CARDS=xx"
, where title
is the GCC's name and xx
is the actual number of cards in the collection.public java.util.Iterator<CreditCard> iterator()
this
centre.iterator
in interface java.lang.Iterable<CreditCard>
@Deprecated public CreditCard getFirst()
iterator()
The base
invocation of the forward iterator.null
is returned.@Deprecated public CreditCard getNext()
iterator()
Follow
up invocation of the forward iterator.null
is returned. It is assumed that
getFirst
is first invoked, and if it had a non-null
return, then this method is invoked repeatedly until null is
returned.public static GlobalCredit getRandom()
getRandom(false)
.public static GlobalCredit getRandom(boolean same)
false
parameter. The parameter was added to allow a harness
to pass the same test cases to an app being tested and to an oracle.
This method was added for pedagogical reasons.
same
- a flag that determines if a new GCC is to be generated (when
false
) or if a reference to the last-generated
GCC should be returned (true
). You should
normally set it to false
to get a different GCC
per invocation.same
is
false
) or is the same as the one last generated by
this method. If this method was never invoked before, a random
GCC is returned regardless of the passed parameter.