|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectsoc.game.SOCResourceSet
public class SOCResourceSet
This represents a collection of clay, ore, sheep, wheat, and wood resources. Unknown resources are also tracked here. Although it's possible to store negative amounts of resources, it's discouraged.
SOCResourceConstants,
SOCPlayingPiece.getResourcesToBuild(int),
Serialized Form| Field Summary | |
|---|---|
static SOCResourceSet |
EMPTY_SET
Resource set with zero of each resource type |
private int[] |
resources
the number of each resource type. |
| Constructor Summary | |
|---|---|
SOCResourceSet()
Make an empty resource set |
|
SOCResourceSet(int[] rset)
Make a resource set from an array |
|
SOCResourceSet(int cl,
int or,
int sh,
int wh,
int wo,
int uk)
Make a resource set with stuff in it |
|
| Method Summary | |
|---|---|
void |
add(int amt,
int rtype)
add an amount to a resource |
void |
add(SOCResourceSet rs)
add an entire resource set's amounts into this set. |
void |
clear()
set the number of resources to zero |
boolean |
contains(int rtype)
Does the set contain any resources of this type? |
boolean |
contains(SOCResourceSet sub)
|
void |
convertToUnknown()
Convert all these resources to type SOCResourceConstants.UNKNOWN. |
SOCResourceSet |
copy()
Make a copy of this resource set. |
boolean |
equals(java.lang.Object anObject)
|
int |
getAmount(int rtype)
How many resources of this type are contained in the set? |
int |
getKnownTotal()
Get the total amount of resources of known types: SOCResourceConstants.CLAY to SOCResourceConstants.WOOD,
excluding SOCResourceConstants.UNKNOWN or SOCResourceConstants.GOLD_LOCAL. |
int |
getKnownTypesCount()
Get the number of known resource types contained in this set: SOCResourceConstants.CLAY to SOCResourceConstants.WOOD,
excluding SOCResourceConstants.UNKNOWN or SOCResourceConstants.GOLD_LOCAL. |
int |
getTotal()
Get the total number of resources in this set, including unknown types. |
static boolean |
gte(SOCResourceSet a,
SOCResourceSet b)
Are set A's resources each greater than or equal to set B's? |
int |
hashCode()
|
static boolean |
lte(SOCResourceSet a,
SOCResourceSet b)
Are set A's resources each less than or equal to set B's? |
void |
setAmount(int amt,
int rtype)
Set the amount of a resource. |
void |
setAmounts(SOCResourceSet set)
copy a resource set into this one. |
void |
subtract(int amt,
int rtype)
subtract an amount from a resource. |
void |
subtract(SOCResourceSet rs)
subtract an entire resource set. |
java.lang.String |
toFriendlyString()
Human-readable form of the set, with format "5 clay,1 ore,3 wood". |
boolean |
toFriendlyString(java.lang.StringBuffer sb)
Human-readable form of the set, with format "5 clay, 1 ore, 3 wood". |
java.lang.String |
toShortString()
Human-readable form of the set, with format "Resources: 5 1 0 0 3 0". |
java.lang.String |
toString()
Human-readable form of the set, with format "clay=5|ore=1|sheep=0|wheat=0|wood=3|unknown=0" |
| Methods inherited from class java.lang.Object |
|---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
public static final SOCResourceSet EMPTY_SET
private int[] resources
SOCResourceConstants.CLAY,
2 == SOCResourceConstants.ORE,
...
5 = SOCResourceConstants.WHEAT,
6 = SOCResourceConstants.UNKNOWN.
| Constructor Detail |
|---|
public SOCResourceSet()
public SOCResourceSet(int cl,
int or,
int sh,
int wh,
int wo,
int uk)
cl - number of clay resourcesor - number of ore resourcessh - number of sheep resourceswh - number of wheat resourceswo - number of wood resourcesuk - number of unknown resourcespublic SOCResourceSet(int[] rset)
rset - resource set, of length 5 or 6 (clay, ore, sheep, wheat, wood, unknown).
If length is 5, unknown == 0.| Method Detail |
|---|
public void clear()
public boolean contains(int rtype)
rtype - the type of resource, like SOCResourceConstants.CLAY
getAmount(int),
contains(SOCResourceSet)public int getAmount(int rtype)
rtype - the type of resource, like SOCResourceConstants.CLAY
contains(int)public int getTotal()
getKnownTotal(),
getKnownTypesCount()public int getKnownTypesCount()
SOCResourceConstants.CLAY to SOCResourceConstants.WOOD,
excluding SOCResourceConstants.UNKNOWN or SOCResourceConstants.GOLD_LOCAL.
An empty set returns 0, a set containing only wheat returns 1,
that same set after adding wood and sheep returns 3, etc.
public int getKnownTotal()
SOCResourceConstants.CLAY to SOCResourceConstants.WOOD,
excluding SOCResourceConstants.UNKNOWN or SOCResourceConstants.GOLD_LOCAL.
public void setAmount(int amt,
int rtype)
add(SOCResourceSet),
subtract(SOCResourceSet) or setAmounts(SOCResourceSet).
rtype - the type of resource, like SOCResourceConstants.CLAYamt - the amount
public void add(int amt,
int rtype)
rtype - the type of resource, like SOCResourceConstants.CLAYamt - the amount; if below 0 (thus subtracting resources),
the subtraction occurs and no special action is taken.
subtract(int, int) takes special action in some cases.
public void subtract(int amt,
int rtype)
SOCResourceConstants.UNKNOWN resources.
As a result, UNKNOWN may be less than zero afterwards.
rtype - the type of resource, like SOCResourceConstants.CLAYamt - the amount; unlike in add(int, int), any amount that
takes the resource below 0 is treated specially.public void add(SOCResourceSet rs)
rs - the resource setpublic void subtract(SOCResourceSet rs)
rs - the resource setpublic void convertToUnknown()
SOCResourceConstants.UNKNOWN.
Information on amount of wood, wheat, etc is no longer available.
Equivalent to:
int numTotal = resSet.getTotal();
resSet.clear();
resSet.setAmount (SOCResourceConstants.UNKNOWN, numTotal);
public static boolean gte(SOCResourceSet a,
SOCResourceSet b)
a - set A, cannot be nullb - set B, can be null for an empty resource set
public static boolean lte(SOCResourceSet a,
SOCResourceSet b)
a - set A, cannot be nullb - set B, cannot be null
public java.lang.String toString()
toString in class java.lang.ObjecttoShortString(),
toFriendlyString()public java.lang.String toShortString()
toFriendlyString()public java.lang.String toFriendlyString()
toShortString()public boolean toFriendlyString(java.lang.StringBuffer sb)
sb - Append into this buffer.
toFriendlyString()public boolean contains(SOCResourceSet sub)
sub - the sub set, can be null for an empty resource subset
contains(int)public boolean equals(java.lang.Object anObject)
equals in class java.lang.ObjectanObject - the object in question
public int hashCode()
hashCode in class java.lang.Objectpublic SOCResourceSet copy()
setAmounts(SOCResourceSet).
public void setAmounts(SOCResourceSet set)
set - the set to copy from
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||