FeatureVector implements Iterable<FeatureVector.Entry> { public void add(FeatureVector other) throws InvalidFeatureVectorValueException { for (FeatureVector.Entry entry : other) { this.set(entry.index, this.get(entry.index) + entry.value); } }  void add(FeatureVector other); void multiply(double factor); double l2Norm(); @Override boolean equals(Object o); @Override int hashCode(); abstract void set(int index, double value); abstract double get(int index); abstract Iterator<Entry> iterator(); double innerProduct(FeatureVector other);  }
@Test public void testAdd() throws Throwable { fv1.add(fv2); assertTrue(fv1.equals(fv2)); fv1.add(fv3); assertEquals(fv1.get(0), 0.0, 0.0); assertEquals(fv1.get(1), 5.5, delta); assertEquals(fv1.get(2), 0.0, 0.0); assertEquals(fv1.get(3), 2.5, delta); assertEquals(fv1.get(4), 0.0, 0.0); assertEquals(fv1.get(5), 7.1, delta); assertEquals(fv1.get(6), 13.5, delta); assertEquals(fv1.get(7), 0.0, 0.0); assertEquals(fv1.get(8), 0.0, 0.0); assertEquals(fv1.get(9), 0.0, 0.0); assertEquals(fv1.get(10), 2.3, delta); assertEquals(fv1.get(11), 0.0, 0.0); }