@Test public void testParseDescriptor() throws Exception { int n = 10; int maxnbAttributes = 100; Random rng = RandomUtils.getRandom(); for (int nloop = 0; nloop < n; nloop++) { int nbAttributes = rng.nextInt(maxnbAttributes) + 1; char[] tokens = Utils.randomTokens(rng, nbAttributes); Attribute[] attrs = DescriptorUtils.parseDescriptor(Utils.generateDescriptor(tokens)); assertEquals("attributes size", nbAttributes, attrs.length); for (int attr = 0; attr < nbAttributes; attr++) { switch (tokens[attr]) { case 'I': assertTrue(attrs[attr].isIgnored()); break; case 'N': assertTrue(attrs[attr].isNumerical()); break; case 'C': assertTrue(attrs[attr].isCategorical()); break; case 'L': assertTrue(attrs[attr].isLabel()); break; } } } }
public static Attribute[] parseDescriptor(CharSequence descriptor) throws DescriptorException { List<Attribute> attributes = Lists.newArrayList(); for (String token : SPACE.split(descriptor)) { token = token.toUpperCase(Locale.ENGLISH); if ("I".equals(token)) { attributes.add(Attribute.IGNORED); } else if ("N".equals(token)) { attributes.add(Attribute.NUMERICAL); } else if ("C".equals(token)) { attributes.add(Attribute.CATEGORICAL); } else if ("L".equals(token)) { attributes.add(Attribute.LABEL); } else { throw new DescriptorException("Bad Token : " + token); } } return attributes.toArray(new Attribute[attributes.size()]); }
DescriptorUtils { public static Attribute[] parseDescriptor(CharSequence descriptor) throws DescriptorException { List<Attribute> attributes = Lists.newArrayList(); for (String token : SPACE.split(descriptor)) { token = token.toUpperCase(Locale.ENGLISH); if ("I".equals(token)) { attributes.add(Attribute.IGNORED); } else if ("N".equals(token)) { attributes.add(Attribute.NUMERICAL); } else if ("C".equals(token)) { attributes.add(Attribute.CATEGORICAL); } else if ("L".equals(token)) { attributes.add(Attribute.LABEL); } else { throw new DescriptorException("Bad Token : " + token); } } return attributes.toArray(new Attribute[attributes.size()]); } }
DescriptorUtils { public static Attribute[] parseDescriptor(CharSequence descriptor) throws DescriptorException { List<Attribute> attributes = Lists.newArrayList(); for (String token : SPACE.split(descriptor)) { token = token.toUpperCase(Locale.ENGLISH); if ("I".equals(token)) { attributes.add(Attribute.IGNORED); } else if ("N".equals(token)) { attributes.add(Attribute.NUMERICAL); } else if ("C".equals(token)) { attributes.add(Attribute.CATEGORICAL); } else if ("L".equals(token)) { attributes.add(Attribute.LABEL); } else { throw new DescriptorException("Bad Token : " + token); } } return attributes.toArray(new Attribute[attributes.size()]); } private  DescriptorUtils(); }
DescriptorUtils { public static Attribute[] parseDescriptor(CharSequence descriptor) throws DescriptorException { List<Attribute> attributes = Lists.newArrayList(); for (String token : SPACE.split(descriptor)) { token = token.toUpperCase(Locale.ENGLISH); if ("I".equals(token)) { attributes.add(Attribute.IGNORED); } else if ("N".equals(token)) { attributes.add(Attribute.NUMERICAL); } else if ("C".equals(token)) { attributes.add(Attribute.CATEGORICAL); } else if ("L".equals(token)) { attributes.add(Attribute.LABEL); } else { throw new DescriptorException("Bad Token : " + token); } } return attributes.toArray(new Attribute[attributes.size()]); } private  DescriptorUtils(); static Attribute[] parseDescriptor(CharSequence descriptor); static String generateDescriptor(CharSequence description); static String generateDescriptor(Iterable<String> tokens); }
DescriptorUtils { public static Attribute[] parseDescriptor(CharSequence descriptor) throws DescriptorException { List<Attribute> attributes = Lists.newArrayList(); for (String token : SPACE.split(descriptor)) { token = token.toUpperCase(Locale.ENGLISH); if ("I".equals(token)) { attributes.add(Attribute.IGNORED); } else if ("N".equals(token)) { attributes.add(Attribute.NUMERICAL); } else if ("C".equals(token)) { attributes.add(Attribute.CATEGORICAL); } else if ("L".equals(token)) { attributes.add(Attribute.LABEL); } else { throw new DescriptorException("Bad Token : " + token); } } return attributes.toArray(new Attribute[attributes.size()]); } private  DescriptorUtils(); static Attribute[] parseDescriptor(CharSequence descriptor); static String generateDescriptor(CharSequence description); static String generateDescriptor(Iterable<String> tokens);  }