blob: 5c404e81cc2cdc79bd8a17bee2b69bc7514c0500 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
|
import java.util.HashMap;
public class CachedFibonacciNumberFactory implements FibonacciNumberFactory {
private final HashMap<Integer, FibonacciNumber> cachedNumbers = new HashMap<>();
@Override
public FibonacciNumber getFibonacciNumber(int num) {
if (!cachedNumbers.containsKey(num)) {
cachedNumbers.put(num, new FibonacciNumber(num));
}
return cachedNumbers.get(num);
}
}
|