FeatureVector implements Iterable<FeatureVector.Entry> { public void multiply(double factor) throws InvalidFeatureVectorValueException { for (FeatureVector.Entry entry : this) { this.set(entry.index, this.get(entry.index) * factor); } }  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 testMultiply() throws Throwable { fv1.multiply(3.3); assertTrue(fv1.equals(new ArrayFeatureVector())); fv2.multiply(0.5); assertEquals(0.0, fv2.get(0), 0.0); assertEquals(2.25, fv2.get(1), delta); assertEquals(0.0, fv2.get(2), 0.0); assertEquals(0.0, fv2.get(3), 0.0); assertEquals(0.0, fv2.get(4), 0.0); assertEquals(3.55, fv2.get(5), delta); assertEquals(6.5, fv2.get(6), delta); assertEquals(0.0, fv2.get(7), 0.0); assertEquals(0.0, fv2.get(8), 0.0); assertEquals(0.0, fv2.get(9), 0.0); assertEquals(1.15, fv2.get(10), delta); assertEquals(0.0, fv2.get(11), 0.0); }