import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class Primes {
    private Map<Integer,List<Integer>> known = new HashMap<>();
    private int current = 2;

    public int next() {
        while (known.containsKey(current)) {
            for (Integer prime : known.get(current)) {
                known.compute(current + prime,
                        (k, v) -> {
                            if (v == null) {
                                List<Integer> primeList = new ArrayList<>();
                                primeList.add(prime);
                                return primeList;
                            } else {
                                v.add(prime);
                                return v;
                            }
                        });
            }
            current++;
        }
        List<Integer> thisPrimes = new ArrayList<>();
        thisPrimes.add(current);
        known.put(current * current, thisPrimes);
        return current++;
    }

    public static void main(String[] args) {
        Primes primes = new Primes();
        System.out.println(primes.next());
        System.out.println(primes.next());
        System.out.println(primes.next());
        System.out.println(primes.next());
        System.out.println(primes.next());
        System.out.println(primes.next());
        System.out.println(primes.next());
    }
}

@@ -135,28 +135,22 @@
 Map%3C
-Integer,List%3CInteger
+Long,List%3CLong
 %3E%3E k
@@ -185,19 +185,20 @@
 private 
-int
+long
  current
@@ -215,19 +215,20 @@
  public 
-int
+long
  next() 
@@ -291,23 +291,20 @@
    for (
-Integer
+Long
  prime :
@@ -346,29 +346,54 @@
     
-known.compute
+List%3CLong%3E primes = known.getOrDefault
 (current
  + p
@@ -392,156 +392,15 @@
 rent
- + 
++
 prime,
-%0A                        (k, v) -%3E %7B%0A                            if (v == null) %7B%0A                                List%3CInteger%3E primeList =
  new
@@ -405,32 +405,33 @@
 ew ArrayList%3C%3E()
+)
 ;%0A              
@@ -436,33 +436,14 @@
     
-  
-              
 prime
-List
+s
 .add
@@ -471,122 +471,39 @@
     
- 
-               return primeList;%0A                            %7D else %7B%0A                                v.add(
+known.put(current+prime, 
 prime
+s
 );%0A 
@@ -509,32 +509,26 @@
             
-        
+%7D%0A
             
@@ -531,257 +531,139 @@
     
-return v;%0A                            %7D%0A                        %7D);%0A            %7D%0A            current++;%0A        %7D%0A        List%3CInteger%3E thisPrimes = new ArrayList%3C%3E();%0A        thisPrimes.add(current);%0A        known.put(current * current, thisPrimes
+known.remove(current);%0A            current++;%0A        %7D%0A        known.put(current * current, new ArrayList%3CLong%3E()%7B%7Badd(current);%7D%7D
 );%0A 

update prime generator