Mercurial > hg > blitz_condensed
view src/org/dancres/blitz/UIDSet.java @ 22:b7e52953b7a6
Add some cache/memory statistics to help spot potential exhaustion and other tuning issues.
author | Dan Creswell <dan.creswell@gmail.com> |
---|---|
date | Fri, 28 Aug 2009 17:23:33 +0100 |
parents | 3dc0c5604566 |
children |
line wrap: on
line source
package org.dancres.blitz; import java.util.Set; import java.util.HashSet; import java.util.ArrayList; /** * A set of UID's that is guarenteed to contain no duplicates and limits it's * size to the specified capacity */ public class UIDSet { private Set theFilter = new HashSet(); private ArrayList theMembers = new ArrayList(); private long theCapacity; UIDSet(long aMaxSize) { theCapacity = aMaxSize; } void add(SpaceEntryUID aUID) { synchronized(theFilter) { if (isFull()) return; if (! theFilter.contains(aUID)) { theFilter.add(aUID); theMembers.add(aUID); } } } boolean isFull() { synchronized(theFilter) { return (theFilter.size() == theCapacity); } } SpaceEntryUID pop() { synchronized(theFilter) { if (theMembers.size() == 0) return null; else return (SpaceEntryUID) theMembers.remove(theMembers.size() - 1); } } }