### Question:
FeatureList extends ArrayList<Feature> { public void validate() throws ApplicationException { HashSet<Feature> uniq = new HashSet<Feature>(); uniq.addAll(this); if (uniq.size() != this.size()) { throw new ApplicationException("the feature list contains duplicates"); } } FeatureList();  FeatureList(int size);  FeatureList(FeatureList featureList, boolean addBias); void validate(); Collection<FeatureList> group(); int indexOf(Feature feature); void addBias(); void removeBias(); boolean hasBias();  }### Answer:
@Test public void test() throws Exception { Feature f1 = new Feature(NetworkType.ATTRIBUTE_VECTOR, 1, 10); Feature f2 = new Feature(NetworkType.SPARSE_MATRIX, 1, 10); FeatureList list = new FeatureList(); list.add(f1); list.add(f2); list.validate(); Collections.sort(list); Iterator<Feature> iter = list.iterator(); assertEquals(NetworkType.SPARSE_MATRIX, iter.next().getType()); assertEquals(NetworkType.ATTRIBUTE_VECTOR, iter.next().getType()); assertFalse(iter.hasNext()); HashSet<Feature> featureSet = new HashSet<Feature>(); featureSet.addAll(list); assertEquals(2, featureSet.size()); featureSet.addAll(list); assertEquals(2, featureSet.size()); }
@Test(expected = ApplicationException.class) public void testDuplicate() throws Exception { Feature f1 = new Feature(NetworkType.ATTRIBUTE_VECTOR, 1, 10); Feature f2 = new Feature(NetworkType.ATTRIBUTE_VECTOR, 1, 10); FeatureList list = new FeatureList(); list.add(f1); list.add(f2); list.validate(); }