package suntest; /** * This source file is part of project littleaccountbook. * This project is under GNU General Public License v2. * This Project is a C/S account book. * Swing is used to create the GUI of this project and Java DB is used to store data in local machine. * Full source code of this project is available at http://littleaccountbook.googlecode.com/svn/trunk/ littleaccountbook-read-only * * @author Moon Zang * */ import java.util.Arrays; import java.util.Collection; import java.util.HashSet; public class InstrumentedHashSet<E> extends HashSet<E> { private int addCount = 0; @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 static void main(String[] args) { InstrumentedHashSet<String> s = new InstrumentedHashSet<String>(); s.addAll(Arrays.asList("Accordion", "Banjo", "Kazoo")); System.out.println(s.addCount); } }