Package civquest.parser.ruleset

Examples of civquest.parser.ruleset.Field


            if ( sectionName.startsWith("advance_") ) {
                Section section = ruleset.getSection(sectionName);
                String name = section.getField("name").getStringValue();

                String description = null;
                Field helptext = section.getField("helptext");
                if (helptext != null) description = helptext.getStringValue();

                Science science = new Science(name, description,  0); // FIXME: make data for required points
                String req = section.getField("req1").getStringValue();
                if (req != null && !req.equals("None") && !req.equals("Never")) science.addDependency(req);
                req = section.getField("req2").getStringValue();
View Full Code Here


    }

  }

  private boolean getInfoOn(Section section) throws RulesetException {
    Field infoOnField = section.getField("infoOn");
    if (infoOnField == null) {
      throw new MissingFieldException(section, "infoOn",
                      "Happened in Messages.getInfoOn");
    } else if (!infoOnField.isBoolValue()) {
      throw new InvalidFieldValueException(infoOnField, "Bool",
                         "Happ1ened in Messages.getInfoOn");
    } else {
      return infoOnField.getBoolValue();
    }
  }
View Full Code Here

      return infoOnField.getBoolValue();
    }
  }

  private void loadBasicCategories(Section basicCatSection) throws RulesetException {
    Field basicCatField = basicCatSection.getField("basic_categories");
    for (int n = 0; n < basicCatField.getNumberOfValues(); n++) {
      String currCat = basicCatField.getStringValue(n);
      basicCategories.add(currCat);

      if (providingCatMap.containsKey(currCat)) {
        System.err.println("[Messages] ERROR! " + currCat + " is defined "
                   + "multiple times as basic category");
View Full Code Here

    checkIfBasicCompositesDisjunct(section);
    checkIfAllProvidedCategoriesDefined(section);
   
    Iterator<Field> iterator = section.getFieldIterator();
    while (iterator.hasNext()) {
      Field currField = iterator.next();
      Set<String> value = new HashSet<String>();
      value.add(currField.getName());
      providingCatMap.put(currField.getName(), value);
    }   

    // maps composite categories (Strings) to the count of
    // not-yet-processed parents
    Map<String, Integer> parentCounts = getParentCounts(section);

    // all composite categories having zero parents now, being processed
    // in the next iteration
    Set<String> zeroCategories = getNotMentionedCompositeCategories(parentCounts, section);

    while (zeroCategories.size() > 0) {
      // composite categories that still need to be processed remain

      // set of the composite categories where we process the last
      // unprocessed parent within this iteration
      Set<String> newZeroCategories = new HashSet<String>();

      // for each category with zero unprocessed parents, add all its parents
      // plus itself (stored within providingCatMap) to the providingCatMap-entries
      // of all of its children.  Update their parentCount-entries, subtracting one.
      Iterator<String> zeroIterator = zeroCategories.iterator();
      while (zeroIterator.hasNext()) {
        String currCategory = zeroIterator.next();
        Set<String> currCategoryProvides = providingCatMap.get(currCategory);

        Field field = section.getField(currCategory);
        for (int n = 0; n < field.getNumberOfValues(); n++) {
          String currProvCategory = field.getStringValue(n);
          Set<String> currProvSet = providingCatMap.get(currProvCategory);
          currProvSet.addAll(currCategoryProvides);

          if (parentCounts.containsKey(currProvCategory)) {
            // This happens only for composite children.
View Full Code Here

  // expects basicCategories being calculated
  private void checkIfBasicCompositesDisjunct(Section section) {
    Iterator iterator = section.getFieldIterator();
    while (iterator.hasNext()) {
      Field currField = (Field)(iterator.next());
      if (basicCategories.contains(currField.getName())) {
        System.err.println("[Messages] ERROR: " + currField.getName()
                   + " is basic AND composite category!!!");
        System.err.println("[Messages]        CivQuest will abort NOW!!!");
        System.exit(-1);
      }
    }   
View Full Code Here

  // expects basicCategories being calculated
  private void checkIfAllProvidedCategoriesDefined(Section section) {
    Iterator iterator = section.getFieldIterator();
    while (iterator.hasNext()) {
      try {
        Field currField = (Field)(iterator.next());
        for (int n = 0; n < currField.getNumberOfValues(); n++) {
          if (!(basicCategories.contains(currField.getStringValue(n))
              || section.hasField(currField.getStringValue(n)))) {
            System.err.println("[Messages] ERROR! " + currField.getStringValue(n)
                       + " is defined neither as basic nor as composite "
                       + "category!");
            System.err.println("[Messages]        CivQuest will abort NOW!!!");
            System.exit(-1);         
          }
View Full Code Here

  // basic-categories-set needs to be constructed before
  private Map<String, Integer> getParentCounts(Section section) {
    Map<String, Integer> retMap = new HashMap<String, Integer>();
    Iterator<Field> iterator = section.getFieldIterator();
    while (iterator.hasNext()) {
      Field currField = iterator.next();

      for (int n = 0; n < currField.getNumberOfValues(); n++) {
        try {
          String currChild = currField.getStringValue(n);
          if (retMap.containsKey(currChild)) {
            Integer number = retMap.get(currChild);
            retMap.put(currChild, new Integer(number.intValue() + 1));
          } else if (!basicCategories.contains(currChild)) {
            retMap.put(currChild, 1);
View Full Code Here

                               Section section) {
    Set<String> retSet = new HashSet<String>();
   
    Iterator<Field> iterator = section.getFieldIterator();
    while (iterator.hasNext()) {
      Field currField = iterator.next();
      String currCat = currField.getName();
      if (!parentCounts.containsKey(currCat)) {
        retSet.add(currCat);
      }
    }
View Full Code Here

      } else {
       
      }
   
      Section propertiesSection = ruleset.getSection("properties");
      Field verbosityField = propertiesSection.getField("verbosity");
      retDest.setUpVerbosity(verbosityField);

      Section listeningSection = ruleset.getSection("listening");
      Field categoriesField = listeningSection.getField("categories");
      for (int n = 0; n < categoriesField.getNumberOfValues(); n++) {
        retDest.startListeningToCategory(categoriesField.getStringValue(n));
      }
     
      if (selfVerbose) {
        System.out.println("[Messages] Listening to categories "
                   + retDest.getCategories());
View Full Code Here

    return retDest;
  }
 
  // interprets errorDests-field.
  private void setErrorDests(Section settingsSection, Map dests) throws RulesetException {
    Field errorField = settingsSection.getField("errorDests");

    if (errorField == null) {
      throw new MissingFieldException(settingsSection, "errorDests",
                      "Happened within Messages.setErrorDests");
    } else {
      errDests = new Destination[errorField.getNumberOfValues()];
      for (int n = 0; n < errorField.getNumberOfValues(); n++) {
        if (!errorField.isStringValue(n)) {
          throw new InvalidFieldValueException
            (errorField, n, "String", "Happened within Messages.setErrorDests");
        } else {
          if (!dests.containsKey(errorField.getStringValue(n))) {
            System.err.println("[Messages] ERROR! " + errorField.getStringValue(n)
                       + " is not a valid error-destination");
            System.err.println("[Messages]        Happened in setErrorDests");
            System.err.println("[Messages]        CivQuest will abort NOW!");
            System.exit(-1);
          } else {
            errDests[n] = (Destination)(dests.get(errorField.getStringValue(n)));
          }
        }
      }
    }
  }
View Full Code Here

TOP

Related Classes of civquest.parser.ruleset.Field

Copyright © 2018 www.massapicom. 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.