Package net.sf.freecol.common.model
Class AbstractGoods
- java.lang.Object
-
- net.sf.freecol.common.model.FreeColObject
-
- net.sf.freecol.common.model.AbstractGoods
-
- All Implemented Interfaces:
java.lang.Comparable<FreeColObject>
,Named
,ObjectWithId
- Direct Known Subclasses:
Goods
public class AbstractGoods extends FreeColObject implements Named
Represents a certain amount of a GoodsType. This does not correspond to actual cargo present in a Location, but is intended to represent things such as the amount of Lumber necessary to build something, or the amount of cargo to load at a certain Location.
-
-
Field Summary
Fields Modifier and Type Field Description protected int
amount
The amount of goods.static java.util.Comparator<AbstractGoods>
ascendingAmountComparator
Compare the amount of abstract goods.static java.util.Comparator<AbstractGoods>
descendingAmountComparator
A comparator to sort by descending goods amount and then by a predictable goods type order.protected GoodsType
type
The type of goods.-
Fields inherited from class net.sf.freecol.common.model.FreeColObject
ARRAY_SIZE_TAG, DEFAULT_CLASS_INDEX, fcoComparator, ID_ATTRIBUTE_TAG, logger, PARTIAL_ATTRIBUTE_TAG, VALUE_TAG
-
-
Constructor Summary
Constructors Constructor Description AbstractGoods()
Empty constructor.AbstractGoods(AbstractGoods other)
Creates a newAbstractGoods
instance.AbstractGoods(GoodsType type, int amount)
Creates a newAbstractGoods
instance.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description <T extends FreeColObject>
booleancopyIn(T other)
Copy another FreeColObject into this one if it is compatible.boolean
equals(java.lang.Object o)
int
evaluateFor(Player player)
Evaluate goods for trade purposes.static StringTemplate
getAbstractLabel(java.lang.String key, int amount)
Get a label given a key and amount.int
getAmount()
Get the goods amount.static int
getCount(GoodsType type, java.util.Collection<? extends AbstractGoods> goods)
Convenience lookup of the goods count in a collection of abstract goods given a goods type.StringTemplate
getLabel()
Get a label for these goods.StringTemplate
getLabel(boolean sellable)
Get a label for these goods.java.lang.String
getNameKey()
Gets the name of this named object.GoodsType
getType()
Get the goods type.java.lang.String
getXMLTagName()
Get the serialization tag for this object.int
hashCode()
boolean
isFoodType()
Is the goods type a food type?boolean
isPositive()
Is the amount positive?boolean
isStorable()
Are these goods storable.static java.util.function.Predicate<? super AbstractGoods>
matches(GoodsType key)
A predicate maker to match by type.void
setAmount(int newAmount)
Set the goods amount.void
setType(GoodsType newType)
Set the goods type.static java.lang.String
toFullString(GoodsType goodsType, int amount)
Simple string version of the component parts of some goods.java.lang.String
toString()
-
Methods inherited from class net.sf.freecol.common.model.FreeColObject
addAbility, addFeatures, addModifier, addPropertyChangeListener, addPropertyChangeListener, apply, apply, applyModifiers, applyModifiers, arrayKey, compareIds, compareTo, containsAbilityKey, containsModifierKey, copy, copy, copy, copy, copyInCast, dumpObject, fireIndexedPropertyChange, fireIndexedPropertyChange, fireIndexedPropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getAbilities, getAbilities, getAbilities, getAbilities, getClassIndex, getDefenceModifiers, getDisplayObject, getFeatureContainer, getFreeColObjectClass, getFreeColObjectClassByName, getGame, getId, getIdNumber, getIdType, getIdTypeByName, getModifiers, getModifiers, getModifiers, getModifiers, getObjectClassIndex, getPropertyChangeListeners, getPropertyChangeListeners, getPropertyChangeSupport, getSortedAbilities, getSortedModifiers, getSpecification, getSuffix, getSuffix, hasAbility, hasAbility, hasAbility, hasListeners, hasModifier, hasModifier, hasModifier, idEquals, invokeMethod, logFreeColObjects, readAttributes, readChild, readChildren, readFromXML, readFromXMLPartial, removeAbilities, removeAbility, removeFeatures, removeModifier, removeModifiers, removePropertyChangeListener, removePropertyChangeListener, save, save, save, save, serialize, serialize, serialize, serialize, setGame, setId, setSpecification, toXML, toXML, toXMLPartial, toXMLPartial, writeAttributes, writeChildren
-
-
-
-
Field Detail
-
ascendingAmountComparator
public static final java.util.Comparator<AbstractGoods> ascendingAmountComparator
Compare the amount of abstract goods.
-
descendingAmountComparator
public static final java.util.Comparator<AbstractGoods> descendingAmountComparator
A comparator to sort by descending goods amount and then by a predictable goods type order.
-
type
protected GoodsType type
The type of goods.
-
amount
protected int amount
The amount of goods.
-
-
Constructor Detail
-
AbstractGoods
public AbstractGoods()
Empty constructor.
-
AbstractGoods
public AbstractGoods(GoodsType type, int amount)
Creates a newAbstractGoods
instance.- Parameters:
type
- TheGoodsType
to create.amount
- The amount of goods to create.
-
AbstractGoods
public AbstractGoods(AbstractGoods other)
Creates a newAbstractGoods
instance.- Parameters:
other
- AnotherAbstractGoods
to copy.
-
-
Method Detail
-
getType
public final GoodsType getType()
Get the goods type.- Returns:
- The
GoodsType
.
-
setType
public final void setType(GoodsType newType)
Set the goods type.- Parameters:
newType
- The newGoodsType
.
-
isFoodType
public final boolean isFoodType()
Is the goods type a food type?- Returns:
- True if this is food.
-
getAmount
public final int getAmount()
Get the goods amount.- Returns:
- The goods amount.
-
setAmount
public final void setAmount(int newAmount)
Set the goods amount.- Parameters:
newAmount
- The new goods amount.
-
isPositive
public final boolean isPositive()
Is the amount positive?- Returns:
- True if the amount is greater than zero.
-
isStorable
public boolean isStorable()
Are these goods storable.- Returns:
- True if the goods are storable.
-
getLabel
public StringTemplate getLabel()
Get a label for these goods.- Returns:
- The label for these goods.
-
getLabel
public StringTemplate getLabel(boolean sellable)
Get a label for these goods.- Parameters:
sellable
- Whether these goods can be sold.- Returns:
- A label for these goods.
-
getAbstractLabel
public static StringTemplate getAbstractLabel(java.lang.String key, int amount)
Get a label given a key and amount. Used for arbitrary objects, such as the missionary's bible.- Parameters:
key
- A key for the goods to display.amount
- The amount of goods.- Returns:
- The goods label.
-
getCount
public static int getCount(GoodsType type, java.util.Collection<? extends AbstractGoods> goods)
Convenience lookup of the goods count in a collection of abstract goods given a goods type.- Parameters:
type
- TheGoodsType
to look for.goods
- The collection ofAbstractGoods
to look in.- Returns:
- The goods count found, or zero if not found.
-
evaluateFor
public int evaluateFor(Player player)
Evaluate goods for trade purposes.- Parameters:
player
- ThePlayer
to evaluate for.- Returns:
- A value for the goods.
-
matches
public static final java.util.function.Predicate<? super AbstractGoods> matches(GoodsType key)
A predicate maker to match by type.- Parameters:
key
- The key of typeGoodsType
- Returns:
- A suitable
Predicate
.
-
getNameKey
public java.lang.String getNameKey()
Gets the name of this named object. Try to avoid using this directly except in i18n-related routines or to implement itself in more complext objects.- Specified by:
getNameKey
in interfaceNamed
- Returns:
- The name of the
Named
.
-
getXMLTagName
public java.lang.String getXMLTagName()
Get the serialization tag for this object.- Specified by:
getXMLTagName
in classFreeColObject
- Returns:
- The tag.
-
copyIn
public <T extends FreeColObject> boolean copyIn(T other)
Copy another FreeColObject into this one if it is compatible.- Overrides:
copyIn
in classFreeColObject
- Type Parameters:
T
- TheFreeColObject
subclass of the object to copy in.- Parameters:
other
- The other object.- Returns:
- True if the copy in is succesful.
-
equals
public boolean equals(java.lang.Object o)
- Overrides:
equals
in classFreeColObject
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classFreeColObject
-
toString
public java.lang.String toString()
- Overrides:
toString
in classFreeColObject
-
toFullString
public static java.lang.String toFullString(GoodsType goodsType, int amount)
Simple string version of the component parts of some goods.- Parameters:
goodsType
- TheGoodsType
to use.amount
- The amount of goods.- Returns:
- A string version of the goods.
-
-