Package net.sf.freecol.common.model
Class FeatureContainer
- java.lang.Object
-
- net.sf.freecol.common.model.FeatureContainer
-
public final class FeatureContainer extends java.lang.ObjectA 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 Summary
Fields Modifier and Type Field Description private java.util.Map<java.lang.String,java.util.Set<Ability>>abilitiesThe abilities in the container.private java.lang.ObjectabilitiesLockLock variables.private static java.util.logging.Loggerloggerprivate java.util.Map<java.lang.String,java.util.Set<Modifier>>modifiersThe modifiers in the container.private java.lang.ObjectmodifiersLock
-
Constructor Summary
Constructors Constructor Description FeatureContainer()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private booleanabilitiesPresent()Have the abilities map been created?booleanaddAbility(Ability ability)Add the given ability to a container.voidaddFeatures(FreeColObject fco)Adds all the features in an object to this object.booleanaddModifier(Modifier modifier)Adds a modifier to a container.static booleanallAbilities(java.util.stream.Stream<Ability> abilities)Is the given set of abilities non-empty and contains no false-valued members?static floatapplyModifiers(float number, Turn turn, java.util.Collection<Modifier> mods)Applies a collection of modifiers to the given float value.static floatapplyModifiers(float number, Turn turn, java.util.stream.Stream<Modifier> mods)Applies a stream of modifiers to the given float value.private static floatapplyModifiersInternal(float number, Turn turn, java.util.Collection<Modifier> mods)Implement applyModifiers.voidclear()Clear this feature container.booleancontainsAbilityKey(java.lang.String key)Checks if this container contains a given ability key.voidcopy(FeatureContainer other)Copy anther feature container.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.protected java.util.Collection<Ability>getAbilityValues()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.protected java.util.Collection<Modifier>getModifierValues()booleanhasAbility(java.lang.String id, FreeColSpecObjectType fcgot, Turn turn)Is the given set of abilities non-empty and contains no false-valued members?private booleanmodifiersPresent()Have the modifiers map been created?voidremoveAbilities(java.lang.String id)Remove all abilities with a given identifier.AbilityremoveAbility(Ability ability)Remove the given ability from a container.voidremoveFeatures(FreeColObject fco)Removes all the features in an object from a container.ModifierremoveModifier(Modifier modifier)Removes a modifier from a container.voidremoveModifiers(java.lang.String id)Removes all modifiers with a given identifier.voidreplaceSource(FreeColSpecObjectType oldSource, FreeColSpecObjectType newSource)Replaces the source field.private voidrequireAbilities()On demand creation of the abilities map.private voidrequireModifiers()On demand creation of the modifiers map.java.lang.StringtoString()
-
-
-
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.
-
-
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 ofAbilitys 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 optionalFreeColSpecObjectTypethe ability applies to.turn- An optional applicableTurn.- 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 optionalFreeColSpecObjectTypethe ability applies to.turn- An optional applicableTurn.- Returns:
- A stream of abilities.
-
addAbility
public boolean addAbility(Ability ability)
Add the given ability to a container.- Parameters:
ability- AnAbilityto add.- Returns:
- True if the
Abilitywas added.
-
removeAbility
public Ability removeAbility(Ability ability)
Remove the given ability from a container.- Parameters:
ability- AnAbilityto 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 optionalFreeColSpecObjectTypethe modifier applies to.turn- An optional applicableTurn.- 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 applicableTurn.mods- TheModifiers 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 applicableTurn.mods- TheModifiers 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 applicableTurn.mods- TheModifiers to apply.- Returns:
- The modified number.
-
addModifier
public boolean addModifier(Modifier modifier)
Adds a modifier to a container.- Parameters:
modifier- TheModifierto add.- Returns:
- True if the modifier was added.
-
removeModifier
public Modifier removeModifier(Modifier modifier)
Removes a modifier from a container.- Parameters:
modifier- TheModifierto 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- TheFreeColObjectto add features from.
-
removeFeatures
public void removeFeatures(FreeColObject fco)
Removes all the features in an object from a container.- Parameters:
fco- TheFreeColObjectto find features to remove in.
-
copy
public void copy(FeatureContainer other)
Copy anther feature container.- Parameters:
other- The otherFeatureContainer.
-
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 sourceFreeColSpecObjectType.newSource- The new sourceFreeColSpecObjectType.
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-