Class FeatureContainer


  • public final class FeatureContainer
    extends java.lang.Object
    A container to hold abilities and modifiers for some FreeColObject-subclass. - FreeColSpecObjectType, Europe, Player, Settlement are current implementors. - Building delegates some functionality to its type. - Unit fakes it by constructing a FeatureContainer on the fly. - FreeColObject itself implements a null version.
    • Field Detail

      • logger

        private static final java.util.logging.Logger logger
      • abilitiesLock

        private final java.lang.Object abilitiesLock
        Lock variables.
      • modifiersLock

        private final java.lang.Object modifiersLock
      • abilities

        private java.util.Map<java.lang.String,​java.util.Set<Ability>> abilities
        The abilities in the container.
      • modifiers

        private java.util.Map<java.lang.String,​java.util.Set<Modifier>> modifiers
        The modifiers in the container.
    • Constructor Detail

      • FeatureContainer

        public FeatureContainer()
    • Method Detail

      • abilitiesPresent

        private boolean abilitiesPresent()
        Have the abilities map been created?
        Returns:
        True if the abilities are present.
      • requireAbilities

        private void requireAbilities()
        On demand creation of the abilities map.
      • modifiersPresent

        private boolean modifiersPresent()
        Have the modifiers map been created?
        Returns:
        True if the modifiers are present.
      • requireModifiers

        private void requireModifiers()
        On demand creation of the modifiers map.
      • getAbilityValues

        protected java.util.Collection<Ability> getAbilityValues()
      • getModifierValues

        protected java.util.Collection<Modifier> getModifierValues()
      • allAbilities

        public static boolean allAbilities​(java.util.stream.Stream<Ability> abilities)
        Is the given set of abilities non-empty and contains no false-valued members?
        Parameters:
        abilities - A stream of Abilitys to check.
        Returns:
        True if the abilities are `satisfied'.
      • hasAbility

        public boolean hasAbility​(java.lang.String id,
                                  FreeColSpecObjectType fcgot,
                                  Turn turn)
        Is the given set of abilities non-empty and contains no false-valued members?
        Parameters:
        id - The object identifier.
        fcgot - An optional FreeColSpecObjectType the ability applies to.
        turn - An optional applicable Turn.
        Returns:
        True if the ability is present.
      • containsAbilityKey

        public boolean containsAbilityKey​(java.lang.String key)
        Checks if this container contains a given ability key.
        Parameters:
        key - The key to check.
        Returns:
        True if the key is present.
      • getAbilities

        public java.util.stream.Stream<Ability> getAbilities​(java.lang.String id,
                                                             FreeColSpecObjectType fcgot,
                                                             Turn turn)
        Gets the set of abilities with the given identifier from a container.
        Parameters:
        id - The object identifier (null matches all).
        fcgot - An optional FreeColSpecObjectType the ability applies to.
        turn - An optional applicable Turn.
        Returns:
        A stream of abilities.
      • addAbility

        public boolean addAbility​(Ability ability)
        Add the given ability to a container.
        Parameters:
        ability - An Ability to add.
        Returns:
        True if the Ability was added.
      • removeAbility

        public Ability removeAbility​(Ability ability)
        Remove the given ability from a container.
        Parameters:
        ability - An Ability to remove.
        Returns:
        The ability removed or null on failure.
      • removeAbilities

        public void removeAbilities​(java.lang.String id)
        Remove all abilities with a given identifier.
        Parameters:
        id - The object identifier.
      • getModifiers

        public java.util.stream.Stream<Modifier> getModifiers​(java.lang.String id,
                                                              FreeColSpecObjectType fcgot,
                                                              Turn turn)
        Gets the set of modifiers with the given identifier from this container.
        Parameters:
        id - The object identifier.
        fcgot - An optional FreeColSpecObjectType the modifier applies to.
        turn - An optional applicable Turn.
        Returns:
        A stream of Modifiers.
      • applyModifiers

        public static float applyModifiers​(float number,
                                           Turn turn,
                                           java.util.Collection<Modifier> mods)
        Applies a collection of modifiers to the given float value.
        Parameters:
        number - The number to modify.
        turn - An optional applicable Turn.
        mods - The Modifiers to apply.
        Returns:
        The modified number.
      • applyModifiers

        public static float applyModifiers​(float number,
                                           Turn turn,
                                           java.util.stream.Stream<Modifier> mods)
        Applies a stream of modifiers to the given float value.
        Parameters:
        number - The number to modify.
        turn - An optional applicable Turn.
        mods - The Modifiers to apply.
        Returns:
        The modified number.
      • applyModifiersInternal

        private static float applyModifiersInternal​(float number,
                                                    Turn turn,
                                                    java.util.Collection<Modifier> mods)
        Implement applyModifiers.
        Parameters:
        number - The number to modify.
        turn - An optional applicable Turn.
        mods - The Modifiers to apply.
        Returns:
        The modified number.
      • addModifier

        public boolean addModifier​(Modifier modifier)
        Adds a modifier to a container.
        Parameters:
        modifier - The Modifier to add.
        Returns:
        True if the modifier was added.
      • removeModifier

        public Modifier removeModifier​(Modifier modifier)
        Removes a modifier from a container.
        Parameters:
        modifier - The Modifier to remove.
        Returns:
        The modifier removed.
      • removeModifiers

        public void removeModifiers​(java.lang.String id)
        Removes all modifiers with a given identifier.
        Parameters:
        id - The object identifier.
      • addFeatures

        public void addFeatures​(FreeColObject fco)
        Adds all the features in an object to this object.
        Parameters:
        fco - The FreeColObject to add features from.
      • removeFeatures

        public void removeFeatures​(FreeColObject fco)
        Removes all the features in an object from a container.
        Parameters:
        fco - The FreeColObject to find features to remove in.
      • copy

        public void copy​(FeatureContainer other)
        Copy anther feature container.
        Parameters:
        other - The other FeatureContainer.
      • clear

        public void clear()
        Clear this feature container.
      • replaceSource

        public void replaceSource​(FreeColSpecObjectType oldSource,
                                  FreeColSpecObjectType newSource)
        Replaces the source field. This is necessary because objects may inherit Features from other abstract objects.
        Parameters:
        oldSource - The old source FreeColSpecObjectType.
        newSource - The new source FreeColSpecObjectType.
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object