Mercurial > hg > blitz_stable
view src/org/dancres/blitz/UIDSet.java @ 0:3dc0c5604566
Initial checkin of blitz 2.0 fcs - no installer yet.
author | Dan Creswell <dan.creswell@gmail.com> |
---|---|
date | Sat, 21 Mar 2009 11:00:06 +0000 |
parents | |
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); } } }