Class 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 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 new AbstractGoods instance.
        Parameters:
        type - The GoodsType to create.
        amount - The amount of goods to create.
      • AbstractGoods

        public AbstractGoods​(AbstractGoods other)
        Creates a new AbstractGoods instance.
        Parameters:
        other - Another AbstractGoods 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 new GoodsType.
      • 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 - The GoodsType to look for.
        goods - The collection of AbstractGoods 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 - The Player 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 type GoodsType
        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 interface Named
        Returns:
        The name of the Named.
      • getXMLTagName

        public java.lang.String getXMLTagName()
        Get the serialization tag for this object.
        Specified by:
        getXMLTagName in class FreeColObject
        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 class FreeColObject
        Type Parameters:
        T - The FreeColObject 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 class FreeColObject
      • toFullString

        public static java.lang.String toFullString​(GoodsType goodsType,
                                                    int amount)
        Simple string version of the component parts of some goods.
        Parameters:
        goodsType - The GoodsType to use.
        amount - The amount of goods.
        Returns:
        A string version of the goods.