Mercurial > hg > blitz_stable
comparison 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 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:3dc0c5604566 |
---|---|
1 package org.dancres.blitz; | |
2 | |
3 import java.util.Set; | |
4 import java.util.HashSet; | |
5 import java.util.ArrayList; | |
6 | |
7 /** | |
8 * A set of UID's that is guarenteed to contain no duplicates and limits it's | |
9 * size to the specified capacity | |
10 */ | |
11 public class UIDSet { | |
12 private Set theFilter = new HashSet(); | |
13 private ArrayList theMembers = new ArrayList(); | |
14 private long theCapacity; | |
15 | |
16 UIDSet(long aMaxSize) { | |
17 theCapacity = aMaxSize; | |
18 } | |
19 | |
20 void add(SpaceEntryUID aUID) { | |
21 synchronized(theFilter) { | |
22 if (isFull()) | |
23 return; | |
24 | |
25 if (! theFilter.contains(aUID)) { | |
26 theFilter.add(aUID); | |
27 theMembers.add(aUID); | |
28 } | |
29 } | |
30 } | |
31 | |
32 boolean isFull() { | |
33 synchronized(theFilter) { | |
34 return (theFilter.size() == theCapacity); | |
35 } | |
36 } | |
37 | |
38 SpaceEntryUID pop() { | |
39 synchronized(theFilter) { | |
40 if (theMembers.size() == 0) | |
41 return null; | |
42 else | |
43 return (SpaceEntryUID) theMembers.remove(theMembers.size() - 1); | |
44 } | |
45 } | |
46 } |