Last active
September 20, 2015 09:08
-
-
Save lucastanziano/e6274afa22a7bbd64886 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Broken - Inappropriate use of inheritance! | |
public class InstrumentedHashSet<E> extends HashSet<E> { | |
// The number of attempted element insertions | |
private int addCount = 0; | |
public InstrumentedHashSet() { | |
} | |
public InstrumentedHashSet(int initCap, float loadFactor) { | |
super(initCap, loadFactor); | |
} | |
@Override public boolean add(E e) { | |
addCount++; | |
return super.add(e); | |
} | |
@Override public boolean addAll(Collection<? extends E> c) { | |
addCount += c.size(); | |
return super.addAll(c); | |
} | |
public int getAddCount() { | |
return addCount; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment