Instances { public static <OUTCOME_TYPE> List<Instance<OUTCOME_TYPE>> toInstances( List<OUTCOME_TYPE> outcomes, List<List<Feature>> featureLists) { int nOutcomes = outcomes.size(); int nFeatureLists = featureLists.size(); if (nOutcomes != nFeatureLists) { String message = "expected the same number of outcomes (%d) as featureLists (%d)"; throw new IllegalArgumentException(String.format(message, nOutcomes, nFeatureLists)); } List<Instance<OUTCOME_TYPE>> instances = new ArrayList<Instance<OUTCOME_TYPE>>(); for (int i = 0; i < nOutcomes; ++i) { instances.add(new Instance<OUTCOME_TYPE>(outcomes.get(i), featureLists.get(i))); } return instances; }  static List<Instance<OUTCOME_TYPE>> toInstances(
      List<OUTCOME_TYPE> outcomes,
      List<List<Feature>> featureLists);  }
@Test public void test() { List<String> outcomes = Arrays.asList("X", "Y", "Z"); List<Feature> features1 = Arrays.asList(new Feature("foo", 42), new Feature("bar", "a")); List<Feature> features2 = Arrays.asList(new Feature("foo", -1), new Feature("bar", "b")); List<Feature> features3 = Arrays.asList(new Feature("foo", 13), new Feature("bar", "c")); List<List<Feature>> featureLists = new ArrayList<List<Feature>>(); featureLists.add(features1); featureLists.add(features2); featureLists.add(features3); List<Instance<String>> expected = new ArrayList<Instance<String>>(); expected.add(new Instance<String>("X", features1)); expected.add(new Instance<String>("Y", features2)); expected.add(new Instance<String>("Z", features3)); List<Instance<String>> actual = Instances.toInstances(outcomes, featureLists); Assert.assertEquals(expected, actual); }