Пример #1
0
 /**
  * The equals method will only return true if both the keys and values match exactly. If a has
  * entries that b doesn't have or vice versa, then a and b are not equal.
  */
 @Override
 @SuppressWarnings("unchecked")
 public boolean equals(final Object o) {
   if (this == o) return true;
   if (o == null || !(o instanceof IntegerMap)) return false;
   final IntegerMap<T> map = (IntegerMap<T>) o;
   if (!map.keySet().equals(this.keySet())) return false;
   if (!map.m_values.equals(this.m_values)) return false;
   for (final T key : map.keySet()) {
     if (!(this.getInt(key) == map.getInt(key))) return false;
   }
   return true;
 }
Пример #2
0
 /**
  * @param units a HashMap in the form RepairRule -> number of units assumes that each repair rule
  *     has 1 result, which is simply the number of units
  */
 public void setUnitsFromRepairRuleMap(
     final HashMap<Unit, IntegerMap<RepairRule>> units,
     final PlayerID player,
     final GameData data) {
   removeAll();
   final Set<Unit> entries = units.keySet();
   for (final Unit unit : entries) {
     final IntegerMap<RepairRule> rules = units.get(unit);
     final TreeSet<RepairRule> repairRules = new TreeSet<RepairRule>(repairRuleComparator);
     repairRules.addAll(rules.keySet());
     for (final RepairRule repairRule : repairRules) {
       final int quantity = rules.getInt(repairRule);
       if (games.strategy.triplea.Properties.getDamageFromBombingDoneToUnitsInsteadOfTerritories(
           data)) {
         // check to see if the repair rule matches the damaged unit
         if (unit.getType().equals((repairRule.getResults().keySet().iterator().next())))
           addUnits(
               player,
               data,
               quantity,
               unit.getType(),
               Matches.UnitHasTakenSomeBombingUnitDamage.match(unit),
               Matches.UnitIsDisabled.match(unit));
       }
     }
   }
 }
Пример #3
0
 /**
  * This will make a new IntegerMap. The Objects will be linked, but the integers mapped to them
  * will not be linked.
  *
  * @param integerMap
  */
 public IntegerMap(final IntegerMap<T> integerMap) {
   /* this will also work:
   m_values = new HashMap<T,Integer>(integerMap.m_values);
    */
   m_values = new HashMap<T, Integer>(integerMap.size());
   for (final T t : integerMap.keySet()) {
     m_values.put(t, integerMap.getInt(t));
   }
 }
Пример #4
0
 /**
  * @param units a HashMap in the form ProductionRule -> number of units assumes that each
  *     production rule has 1 result, which is simple the number of units
  */
 public void setUnitsFromProductionRuleMap(
     final IntegerMap<ProductionRule> units, final PlayerID player, final GameData data) {
   removeAll();
   final TreeSet<ProductionRule> productionRules =
       new TreeSet<ProductionRule>(productionRuleComparator);
   productionRules.addAll(units.keySet());
   for (final ProductionRule productionRule : productionRules) {
     final int quantity = units.getInt(productionRule);
     for (final NamedAttachable resourceOrUnit : productionRule.getResults().keySet()) {
       addUnits(
           player,
           data,
           quantity * productionRule.getResults().getInt(resourceOrUnit),
           resourceOrUnit,
           false,
           false);
     }
   }
 }
Пример #5
0
 /** Add map * multiple */
 public void addMultiple(final IntegerMap<T> map, final int multiple) {
   for (final T key : map.keySet()) {
     add(key, map.getInt(key) * multiple);
   }
 }
Пример #6
0
 /**
  * By >= we mean that each of our entries is greater than or equal to each entry in the other map.
  * We do not take into account entries that are in our map but not in the second map. <br>
  * It is possible that for two maps a and b a.greaterThanOrEqualTo(b) is false, and
  * b.greaterThanOrEqualTo(a) is false, and that a and b are not equal.
  */
 public boolean greaterThanOrEqualTo(final IntegerMap<T> map) {
   for (final T key : map.keySet()) {
     if (!(this.getInt(key) >= map.getInt(key))) return false;
   }
   return true;
 }
Пример #7
0
 public void subtract(final IntegerMap<T> map) {
   for (final T key : map.keySet()) {
     add(key, -map.getInt(key));
   }
 }
Пример #8
0
 public void add(final IntegerMap<T> map) {
   for (final T key : map.keySet()) {
     add(key, map.getInt(key));
   }
 }