Examples of PhysicalAmount


Examples of civquest.util.misc.PhysicalAmount

      }

      while (resources.contains(resName)
           && unsatisfiedConsumerExists(resName)) {

        PhysicalAmount remainingAmount
          = resources.getAmount(resName).clone();
        boolean anythingDistributed = topPolicy
          .distributeAmongChildren(resName, remainingAmount,
                       resources);
View Full Code Here

Examples of civquest.util.misc.PhysicalAmount

      } else {
        boolean anythingDistributed = false;
        for (ChildInfo child : children.values()) {
          ResourceSet neededRes = child.neededRes;
          if (neededRes.contains(resName)) {
            PhysicalAmount needed = neededRes.getAmount(resName);
            double fraction = child.getWeight(resName) / weightSum;
            PhysicalAmount limit = amount.mult(fraction);
            PhysicalAmount forChild
              = PhysicalAmount.min(needed, limit);
            if (forChild.getAmount() > 0) {
              anythingDistributed |= child.distribute(resName,
                                  forChild,
                                  resources);
            }
          }
View Full Code Here

Examples of civquest.util.misc.PhysicalAmount

   */
  public ResourceSet addToThis(String name, PhysicalAmount newAmount)
    throws PhysicalUnitTransformException {

    if (newAmount != null) {
      PhysicalAmount oldAmount = getAmount(name);
      if (oldAmount != null) {
        // We must actually calculate the sum
        resources.put(name, oldAmount.add(newAmount));
      } else {
        resources.put(name, newAmount);
      }
    }
    return this;
View Full Code Here

Examples of civquest.util.misc.PhysicalAmount

  public ResourceSet addToThis(ResourceSet other)
    throws PhysicalUnitTransformException {
    Iterator<String> names = other.getResourceIterator();
    while (names.hasNext()) {
      String name = names.next();
      PhysicalAmount otherAmount = other.getAmount(name);
      addToThis(name, otherAmount);
    }

    return this;
  }
View Full Code Here

Examples of civquest.util.misc.PhysicalAmount

    ResourceSet retSet = new ResourceSet();
   
    Iterator<String> names = this.getResourceIterator();
    while (names.hasNext()) {
      String name = names.next();
      PhysicalAmount amount = this.getAmount(name).mult(factor);
      retSet.addToThis(name, amount);
    }
    return retSet;
  }
View Full Code Here

Examples of civquest.util.misc.PhysicalAmount

    return resources.isEmpty();
  }

  public static boolean isSmaller(ResourceSet set1, ResourceSet set2,
                  String resourceName) {
    PhysicalAmount amount1 = set1.getAmount(resourceName);
    PhysicalAmount amount2 = set2.getAmount(resourceName);
    return PhysicalAmount.isSmaller(amount1, amount2);
  }
View Full Code Here

Examples of civquest.util.misc.PhysicalAmount

    Iterator<civquest.parser.ruleset.Field> fieldIterator = section.getFieldIterator();
    while (fieldIterator.hasNext()) {
      civquest.parser.ruleset.Field field = fieldIterator.next();
      String resourceName = field.getName();
      String amountString = field.getStringValue();
      PhysicalAmount amount = getAmount(amountString);
     
      if (!(mapConfig.resourceExists(resourceName))) {
        throw new ConfigurationException(resourceName + " is not a valid "
                         + "resource name!");
      } else {
        ResourceDefinition resourceDef = mapConfig.getResourceDefinition(resourceName);
        PhysicalAmount.PhysicalUnit standardUnit = resourceDef.getStandardUnit();
       
        if ((!amount.getUnit().canTransform(standardUnit))) {
          String msg = "Can't transform unit " + amount.getUnit() +
            " into standard unit for resource " + resourceName +
            ", which is " + standardUnit;
          throw new ConfigurationException(msg);
        } else {
          resourceSet.addToThis(resourceName, amount);
View Full Code Here

Examples of civquest.util.misc.PhysicalAmount

      if (unit == null) {
        // could not identify unit
        throw new RulesetException(errMsg);
      }
      return new PhysicalAmount(amount, unit);
    }
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.