-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathOneValueCache.java
More file actions
32 lines (27 loc) · 770 Bytes
/
OneValueCache.java
File metadata and controls
32 lines (27 loc) · 770 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
26
27
28
29
30
31
32
package net.jcip.examples;
import java.math.BigInteger;
import java.util.*;
import net.jcip.annotations.*;
/**
* OneValueCache
* <p/>
* Immutable holder for caching a number and its factors
*
* @author Brian Goetz and Tim Peierls
*/
@Immutable
public class OneValueCache {
private final BigInteger lastNumber;
private final BigInteger[] lastFactors;
public OneValueCache(BigInteger i,
BigInteger[] factors) {
lastNumber = i;
lastFactors = Arrays.copyOf(factors, factors.length);
}
public BigInteger[] getFactors(BigInteger i) {
if (lastNumber == null || !lastNumber.equals(i))
return null;
else
return Arrays.copyOf(lastFactors, lastFactors.length);
}
}