Data implements Cloneable { public Data subset(Condition condition) { List<Instance> subset = new ArrayList<>(); for (Instance instance : instances) { if (condition.isTrueFor(instance)) { subset.add(instance); } } return new Data(dataset, subset); } Data(Dataset dataset);  Data(Dataset dataset, List<Instance> instances); int size(); boolean isEmpty(); boolean contains(Instance v); Instance get(int index); Data subset(Condition condition); Data bagging(Random rng); Data bagging(Random rng, boolean[] sampled); Data rsplit(Random rng, int subsize); boolean isIdentical(); boolean identicalLabel(); double[] values(int attr); @Override Data clone(); @Override boolean equals(Object obj); @Override int hashCode(); double[] extractLabels(); int majorityLabel(Random rng); void countLabels(int[] counts); Dataset getDataset();  }
@Test public void testSubset() { int n = 10; for (int nloop = 0; nloop < n; nloop++) { int attr = rng.nextInt(classifierData.getDataset().nbAttributes()); double[] values = classifierData.values(attr); double value = values[rng.nextInt(values.length)]; Data eSubset = classifierData.subset(Condition.equals(attr, value)); Data lSubset = classifierData.subset(Condition.lesser(attr, value)); Data gSubset = classifierData.subset(Condition.greaterOrEquals(attr, value)); for (int index = 0; index < DATA_SIZE; index++) { Instance instance = classifierData.get(index); if (instance.get(attr) < value) { assertTrue(lSubset.contains(instance)); assertFalse(eSubset.contains(instance)); assertFalse(gSubset.contains(instance)); } else if (instance.get(attr) == value) { assertFalse(lSubset.contains(instance)); assertTrue(eSubset.contains(instance)); assertTrue(gSubset.contains(instance)); } else { assertFalse(lSubset.contains(instance)); assertFalse(eSubset.contains(instance)); assertTrue(gSubset.contains(instance)); } } attr = rng.nextInt(regressionData.getDataset().nbAttributes()); values = regressionData.values(attr); value = values[rng.nextInt(values.length)]; eSubset = regressionData.subset(Condition.equals(attr, value)); lSubset = regressionData.subset(Condition.lesser(attr, value)); gSubset = regressionData.subset(Condition.greaterOrEquals(attr, value)); for (int index = 0; index < DATA_SIZE; index++) { Instance instance = regressionData.get(index); if (instance.get(attr) < value) { assertTrue(lSubset.contains(instance)); assertFalse(eSubset.contains(instance)); assertFalse(gSubset.contains(instance)); } else if (instance.get(attr) == value) { assertFalse(lSubset.contains(instance)); assertTrue(eSubset.contains(instance)); assertTrue(gSubset.contains(instance)); } else { assertFalse(lSubset.contains(instance)); assertFalse(eSubset.contains(instance)); assertTrue(gSubset.contains(instance)); } } } }