### Question:
NetworkMemCache { public void compact() { for (String key: softCache.keySet()) { SoftReference<Matrix> ref = softCache.get(key); if (ref == null) { softCache.remove(key); } else if (ref.get() == null) { softCache.remove(key); } } } NetworkMemCache(); static NetworkMemCache instance(); Matrix get(int organismId, int networkId); Matrix get(String namespace, int organismId, int networkId); void put(int organismId, int networkId, Matrix network); void put(String namespace, int organismId, int networkId, Matrix network); void clear(); void compact(); static final String CORE; }### Answer:
@Test public void testCompact() { System.out.println("compact"); int organismId = 1; int networkId = 3; NetworkMemCache instance = NetworkMemCache.instance(); instance.clear(); Matrix expResult = null; Matrix result = instance.get(organismId, networkId); assertEquals(expResult, result); Matrix m = new DenseMatrix(5, 5); instance.put(organismId, networkId ,m); result = instance.get(organismId, networkId); assertEquals(m, result); instance.compact(); result = instance.get(organismId, networkId); }