public Map produceBasicFeatureData(FeatureTreeNode feature) {
   Map basicDataMap = new HashMap();
   basicDataMap.put("feature_id", feature.getID());
   basicDataMap.put("feature_name", getFeatureName(feature));
   basicDataMap.put("feature_type", getFeatureType(feature));
   basicDataMap.put("feature_level", feature.getLevel());
   basicDataMap.put("feature_parentid", getFeatureParent(feature));
   basicDataMap.put("feature_decision", "" + feature.getValue());
   basicDataMap.put(
       "feature_decisionType",
       feature.getValue() == -1
           ? ""
           : (String) feature.getProperty("decisionType")); // manual, propagated, auto-completion
   basicDataMap.put(
       "feature_decisionStep",
       feature.getValue() == -1 ? "" : (String) feature.getProperty("decisionStep"));
   basicDataMap.put(
       "feature_previousDecisionStep",
       feature.getValue() == -1
           ? ""
           : "" + (Integer.valueOf((String) feature.getProperty("decisionStep")) - 1));
   basicDataMap.put("feature_has_children", feature.getChildCount() > 0);
   basicDataMap.put("feature_group_min", -1);
   basicDataMap.put("feature_group_max", -1);
   if (feature instanceof FeatureGroup) {
     FeatureGroup group = (FeatureGroup) feature;
     int min = group.getMin();
     int max = group.getMax();
     basicDataMap.put("feature_group_min", min);
     basicDataMap.put("feature_group_max", max == -1 ? group.getChildCount() : max);
   }
   return basicDataMap;
 }
Пример #2
0
  protected FeatureTreeNode createNodes() throws FeatureModelException {

    int countFeatures = 1;
    Vector<FeatureTreeNode> fmNodes = new Vector<FeatureTreeNode>();

    String featureName = "R";
    countFeatures++;

    RootNode root = new RootNode(featureName, featureName);
    fmNodes.add(root);
    FeatureTreeNode parentNode = null;

    while (countFeatures <= numberOfFeatures) {

      parentNode = fmNodes.firstElement();
      fmNodes.removeElement(parentNode);

      int numberOfChildNodesToCreate =
          Math.min(
              numberOfFeatures - countFeatures + 1,
              (Math.abs(new Random().nextInt()) % (childFeaturesOdds - minChildFeature + 1))
                  + minChildFeature);

      // prevents an early end of the recursion when all nodes happen to have no children
      if (numberOfChildNodesToCreate == 0) {
        if (fmNodes.size() == 0) {
          numberOfChildNodesToCreate = 1;
        }
      }

      if (numberOfChildNodesToCreate > 0) {
        for (int i = 0; i < numberOfChildNodesToCreate && countFeatures <= numberOfFeatures; i++) {
          String childFeatureName = parentNode.getID().substring(1) + (i + 1);
          FeatureTreeNode randomNode =
              createRandomNode(
                  childFeatureName, solitaireOdds, groupOdds, minGroupCard, maxGroupCard);
          parentNode.add(randomNode);
          if (randomNode instanceof FeatureGroup) {
            FeatureGroup groupRandomNode = (FeatureGroup) randomNode;
            int countGroupedNodes = groupRandomNode.getChildCount();
            for (int j = 0; j < countGroupedNodes; j++) {
              fmNodes.add((FeatureTreeNode) groupRandomNode.getChildAt(j));
            }
            countFeatures += (countGroupedNodes);
          } else {
            fmNodes.add(randomNode);
            countFeatures++;
          }
        }
      }
    }

    return root;
  }