-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathBetterVector.java
More file actions
25 lines (21 loc) · 575 Bytes
/
BetterVector.java
File metadata and controls
25 lines (21 loc) · 575 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
package net.jcip.examples;
import java.util.*;
import net.jcip.annotations.*;
/**
* BetterVector
* <p/>
* Extending Vector to have a put-if-absent method
*
* @author Brian Goetz and Tim Peierls
*/
@ThreadSafe
public class BetterVector <E> extends Vector<E> {
// When extending a serializable class, you should redefine serialVersionUID
static final long serialVersionUID = -3963416950630760754L;
public synchronized boolean putIfAbsent(E x) {
boolean absent = !contains(x);
if (absent)
add(x);
return absent;
}
}