FeatureVector implements Iterable<FeatureVector.Entry> { public double l2Norm() { double l = 0.0; for (FeatureVector.Entry entry : this) { l += entry.value * entry.value; } return Math.sqrt(l); }  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 testl2Norm() { assertEquals(0.0, fv1.l2Norm(), 0.0); assertEquals(15.65087, fv2.l2Norm(), delta); }