From 46a659c983911b87b38b20cd4b28ab9176e4fdb3 Mon Sep 17 00:00:00 2001 From: braxtonhall Date: Sun, 23 Oct 2022 19:13:46 -0700 Subject: Add fib-java --- .../fib-java/src/CachedFibonacciNumberFactory.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 entries/nritschel/fib-java/src/CachedFibonacciNumberFactory.java (limited to 'entries/nritschel/fib-java/src/CachedFibonacciNumberFactory.java') diff --git a/entries/nritschel/fib-java/src/CachedFibonacciNumberFactory.java b/entries/nritschel/fib-java/src/CachedFibonacciNumberFactory.java new file mode 100644 index 0000000..5c404e8 --- /dev/null +++ b/entries/nritschel/fib-java/src/CachedFibonacciNumberFactory.java @@ -0,0 +1,13 @@ +import java.util.HashMap; + +public class CachedFibonacciNumberFactory implements FibonacciNumberFactory { + private final HashMap cachedNumbers = new HashMap<>(); + + @Override + public FibonacciNumber getFibonacciNumber(int num) { + if (!cachedNumbers.containsKey(num)) { + cachedNumbers.put(num, new FibonacciNumber(num)); + } + return cachedNumbers.get(num); + } +} -- cgit v1.2.3-70-g09d2