public void setFeatureSet(FeatureSet fs) {

    // Move any attributes that were required by the previous feature set.
    Map<String, Object> attr_storage = null;
    if (this.feature_set != null) {
      attr_storage = new HashMap<String, Object>();
      for (String f : feature_set.getRequiredFeatures()) {
        attr_storage.put(f, getAttribute(f));
      }
      attr_storage.put(feature_set.getClassAttribute(), getAttribute(feature_set.getClassAttribute()));
    }
    this.feature_set = fs;

    // Allocate enough space for all of the required features and the class attribute
    fs_attributes = new Object[fs.getRequiredFeatures().size() + 1];

    if (attr_storage != null) {
      // Insert any of the previous required features back into the attribute storage.
      for (String f : attr_storage.keySet()) {
        setAttribute(f, attr_storage.get(f));
      }
    }

    // Move any previously non-required attributes to required storage.
    checkMapUsage();
    Set<String> to_move = new HashSet<String>();
    for (String f : this.attributes.keySet()) {
      if (feature_set.getRequiredFeatures().contains(f)) {
        to_move.add(f);
      }
    }

    for (String f : to_move) {
      Object value = getAttribute(f);
      removeAttribute(f);
      setAttribute(f, value);
    }

  }