@Override public boolean equals(Object o) { FeatureVector other; try { other = (FeatureVector) o; } catch (ClassCastException e) { return false; } Iterator<Entry> thisIt = this.iterator(); Iterator<Entry> otherIt = other.iterator(); while (thisIt.hasNext() || otherIt.hasNext()) { Entry thisEntry; Entry otherEntry; try { thisEntry = thisIt.next(); otherEntry = otherIt.next(); } catch (NoSuchElementException e) { return false; } if (!thisEntry.equals(otherEntry)) return false; } return true; }