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 intamountThe amount of goods.static java.util.Comparator<AbstractGoods>ascendingAmountComparatorCompare the amount of abstract goods.static java.util.Comparator<AbstractGoods>descendingAmountComparatorA comparator to sort by descending goods amount and then by a predictable goods type order.protected GoodsTypetypeThe 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 newAbstractGoodsinstance.AbstractGoods(GoodsType type, int amount)Creates a newAbstractGoodsinstance.
-
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.booleanequals(java.lang.Object o)intevaluateFor(Player player)Evaluate goods for trade purposes.static StringTemplategetAbstractLabel(java.lang.String key, int amount)Get a label given a key and amount.intgetAmount()Get the goods amount.static intgetCount(GoodsType type, java.util.Collection<? extends AbstractGoods> goods)Convenience lookup of the goods count in a collection of abstract goods given a goods type.StringTemplategetLabel()Get a label for these goods.StringTemplategetLabel(boolean sellable)Get a label for these goods.java.lang.StringgetNameKey()Gets the name of this named object.GoodsTypegetType()Get the goods type.java.lang.StringgetXMLTagName()Get the serialization tag for this object.inthashCode()booleanisFoodType()Is the goods type a food type?booleanisPositive()Is the amount positive?booleanisStorable()Are these goods storable.static java.util.function.Predicate<? super AbstractGoods>matches(GoodsType key)A predicate maker to match by type.voidsetAmount(int newAmount)Set the goods amount.voidsetType(GoodsType newType)Set the goods type.static java.lang.StringtoFullString(GoodsType goodsType, int amount)Simple string version of the component parts of some goods.java.lang.StringtoString()-
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 newAbstractGoodsinstance.- Parameters:
type- TheGoodsTypeto create.amount- The amount of goods to create.
-
AbstractGoods
public AbstractGoods(AbstractGoods other)
Creates a newAbstractGoodsinstance.- Parameters:
other- AnotherAbstractGoodsto 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- TheGoodsTypeto look for.goods- The collection ofAbstractGoodsto 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- ThePlayerto 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:
getNameKeyin interfaceNamed- Returns:
- The name of the
Named.
-
getXMLTagName
public java.lang.String getXMLTagName()
Get the serialization tag for this object.- Specified by:
getXMLTagNamein classFreeColObject- Returns:
- The tag.
-
copyIn
public <T extends FreeColObject> boolean copyIn(T other)
Copy another FreeColObject into this one if it is compatible.- Overrides:
copyInin classFreeColObject- Type Parameters:
T- TheFreeColObjectsubclass 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:
equalsin classFreeColObject
-
hashCode
public int hashCode()
- Overrides:
hashCodein classFreeColObject
-
toString
public java.lang.String toString()
- Overrides:
toStringin classFreeColObject
-
toFullString
public static java.lang.String toFullString(GoodsType goodsType, int amount)
Simple string version of the component parts of some goods.- Parameters:
goodsType- TheGoodsTypeto use.amount- The amount of goods.- Returns:
- A string version of the goods.
-
-