com.pegacat.vcf.data
Class ResourceType

java.lang.Object
  |
  +--com.pegacat.vcf.data.ResourceType
All Implemented Interfaces:
java.lang.Comparable

public class ResourceType
extends java.lang.Object
implements java.lang.Comparable

Stores information about a particular resource type, including the name, and the category i.e. cultural trade etc.

Note that this is a slightly weird class. As resource type information may be revealed from later surveys, after earlier surveys have already used a resource, we use a single object for all instances of a resource, and that object gets shared by all users. This means that if world A uses a resource R, and later world B also uses it, but determintes that R is a lifetype, then A's copy of R gets updated when B updates it's copy of R.

To facilitate this, you can't create new ResourceTypes with 'new', you have to call getResource() which returns a handle to a resource owned by the class. Creation date: (3/06/2001 9:08:02 PM)


Field Summary
static java.lang.String[] ATMOSNAMES
          names of valid atmospheres - used to detect atmospheric resources
static int ATMOSPHERE
           
static int CULTURAL
          constants defining resource types
static int LIFETYPE
           
protected  java.lang.String name
           
static int NORMAL
           
protected static java.util.Map resmap
          Hash of resources by (string) names.
protected  int type
           
static int UNDETERMINED
           
 
Constructor Summary
protected ResourceType(java.lang.String name, int type)
          constructor - note protected, usually construction is a side effect of getResource() calls.
 
Method Summary
 int compareTo(java.lang.Object o)
          Compares this object with the specified object for order.
 boolean equals(java.lang.Object obj)
          Compares two ResourceTypes for equality.
 java.lang.String getName()
           
static ResourceType getResource(java.lang.String name)
          get a resource if it exists, otherwise returns null.
static ResourceType getResource(java.lang.String name, int type)
          get a resource if it exists, otherwise add a resource & return it.
 int getType()
           
 int hashCode()
          Generates a hash code for the receiver.
static boolean isAtmosphere(java.lang.String resname)
          returns true if the specified resource name is an atmosphere type Creation date: (3/06/2001 9:54:49 PM)
static boolean isCultural(java.lang.String resname)
          returns true if the specified resource name is a cultural cargo type Creation date: (3/06/2001 9:54:49 PM)
static boolean isLifetype(java.lang.String resname)
          returns true if the specified resource name is a (numeric) life type Creation date: (3/06/2001 9:54:49 PM)
 void setName(java.lang.String newName)
           
 void setType(int newType)
           
 java.lang.String toString()
          Returns a String that represents the value of this object.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

CULTURAL

public static final int CULTURAL
constants defining resource types

ATMOSPHERE

public static final int ATMOSPHERE

LIFETYPE

public static final int LIFETYPE

NORMAL

public static final int NORMAL

UNDETERMINED

public static final int UNDETERMINED

ATMOSNAMES

public static final java.lang.String[] ATMOSNAMES
names of valid atmospheres - used to detect atmospheric resources

resmap

protected static java.util.Map resmap
Hash of resources by (string) names. all resources are actually stored here, so we can fix undetermined resources when they become determined, without breaking anything.

name

protected java.lang.String name

type

protected int type
Constructor Detail

ResourceType

protected ResourceType(java.lang.String name,
                       int type)
constructor - note protected, usually construction is a side effect of getResource() calls. Creation date: (3/06/2001 9:18:14 PM)
Parameters:
name - java.lang.String
type - int
Method Detail

getResource

public static ResourceType getResource(java.lang.String name)
get a resource if it exists, otherwise returns null.

getResource

public static ResourceType getResource(java.lang.String name,
                                       int type)
get a resource if it exists, otherwise add a resource & return it. This also updates previously undetermined resources if we now have a type.

compareTo

public int compareTo(java.lang.Object o)
Compares this object with the specified object for order. Returns a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.

Sorts resources by type, then by name within type.

Specified by:
compareTo in interface java.lang.Comparable
Returns:
a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.
Throws:
ClassCastException - if the specified object's type prevents it from being compared to this Object.

equals

public boolean equals(java.lang.Object obj)
Compares two ResourceTypes for equality. Returns a boolean that indicates whether this ResourceType is equivalent to the specified ResourceType. This method is used when a ResourceType is stored in a hashtable.
Overrides:
equals in class java.lang.Object
Parameters:
obj - the ResourceType to compare with
Returns:
true if these ResourceTypes are equal; false otherwise.
See Also:
Hashtable

getName

public java.lang.String getName()

getType

public int getType()

hashCode

public int hashCode()
Generates a hash code for the receiver. This method is supported primarily for hash tables, such as those provided in java.util.

Note hash is just on name, not type, as names should be unique

Overrides:
hashCode in class java.lang.Object
Returns:
an integer hash code for the receiver
See Also:
Hashtable

isAtmosphere

public static boolean isAtmosphere(java.lang.String resname)
returns true if the specified resource name is an atmosphere type Creation date: (3/06/2001 9:54:49 PM)

isCultural

public static boolean isCultural(java.lang.String resname)
returns true if the specified resource name is a cultural cargo type Creation date: (3/06/2001 9:54:49 PM)

isLifetype

public static boolean isLifetype(java.lang.String resname)
returns true if the specified resource name is a (numeric) life type Creation date: (3/06/2001 9:54:49 PM)

setName

public void setName(java.lang.String newName)

setType

public void setType(int newType)

toString

public java.lang.String toString()
Returns a String that represents the value of this object.
Overrides:
toString in class java.lang.Object
Returns:
a string representation of the receiver