Ejemplo n.º 1
0
 @Override
 public ExampleSet apply(ExampleSet exampleSet) throws OperatorException {
   Attributes attributes = exampleSet.getAttributes();
   Set<Attribute> attributeSubset = attributeSelector.getAttributeSubset(exampleSet, true);
   Iterator<Attribute> r = attributes.allAttributes();
   while (r.hasNext()) {
     Attribute attribute = r.next();
     if (!attributeSubset.contains(attribute)) r.remove();
   }
   return exampleSet;
 }
  private Attribute[] getMatchingAttributes(Attributes attributes, String regex)
      throws OperatorException {
    Pattern pattern = null;
    try {
      pattern = Pattern.compile(regex);
    } catch (PatternSyntaxException e) {
      throw new UserError(this, 206, regex, e.getMessage());
    }
    List<Attribute> attributeList = new LinkedList<Attribute>();
    Iterator<Attribute> iterator = attributes.allAttributes();
    while (iterator.hasNext()) {
      Attribute attribute = iterator.next();
      if (pattern.matcher(attribute.getName()).matches()) {
        attributeList.add(attribute);
      }
    }

    // building array of attributes for faster access.
    Attribute[] attributesArray = new Attribute[attributeList.size()];
    attributesArray = attributeList.toArray(attributesArray);
    return attributesArray;
  }