Exemplo n.º 1
0
 public int compare(final ProductionRule o1, final ProductionRule o2) {
   if (o1.getResults().size() == 1 && o2.getResults().size() == 1) {
     final NamedAttachable n1 = o1.getResults().keySet().iterator().next();
     final NamedAttachable n2 = o2.getResults().keySet().iterator().next();
     if (n1 instanceof UnitType) {
       final UnitType u1 = (UnitType) n1;
       if (n2 instanceof UnitType) {
         final UnitType u2 = (UnitType) n2;
         return utc.compare(u1, u2);
       } else if (n2 instanceof Resource) {
         // final Resource r2 = (Resource) n2;
         return -1;
       }
       return n1.getName().compareTo(n2.getName());
     } else if (n1 instanceof Resource) {
       final Resource r1 = (Resource) n1;
       if (n2 instanceof UnitType) {
         // final UnitType u2 = (UnitType) n2;
         return 1;
       } else if (n2 instanceof Resource) {
         final Resource r2 = (Resource) n2;
         return r1.getName().compareTo(r2.getName());
       } else return n1.getName().compareTo(n2.getName());
     }
     return n1.getName().compareTo(n2.getName());
   }
   if (o1.getResults().size() > o2.getResults().size()) return -1;
   else if (o1.getResults().size() < o2.getResults().size()) return 1;
   return o1.getName().compareTo(o2.getName());
 }
Exemplo n.º 2
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);
     }
   }
 }