@Test public void testIfChecksumIsAlwaysTheSame() throws Exception { ChecksumAlgorithm algorithm = factory.getAlgorithm("Adler32"); algorithm.update(data); long oldValue = algorithm.getValue(); for (int i = 0; i < 32; i++) { algorithm.update(data); long newValue = algorithm.getValue(); assertEquals(oldValue, newValue); oldValue = newValue; } }
public ChecksumAlgorithm getAlgorithm(String name) throws NoSuchAlgorithmException { ConcurrentLinkedQueue<ChecksumAlgorithm> cache = pool.get(name); if (cache == null) throw new NoSuchAlgorithmException("algorithm " + name + " not supported"); ChecksumAlgorithm algorithm = cache.poll(); if (algorithm == null) { return algorithms.get(name).clone(); } else { return algorithm; } }
ChecksumFactory { public ChecksumAlgorithm getAlgorithm(String name) throws NoSuchAlgorithmException { ConcurrentLinkedQueue<ChecksumAlgorithm> cache = pool.get(name); if (cache == null) throw new NoSuchAlgorithmException("algorithm " + name + " not supported"); ChecksumAlgorithm algorithm = cache.poll(); if (algorithm == null) { return algorithms.get(name).clone(); } else { return algorithm; } } }
ChecksumFactory { public ChecksumAlgorithm getAlgorithm(String name) throws NoSuchAlgorithmException { ConcurrentLinkedQueue<ChecksumAlgorithm> cache = pool.get(name); if (cache == null) throw new NoSuchAlgorithmException("algorithm " + name + " not supported"); ChecksumAlgorithm algorithm = cache.poll(); if (algorithm == null) { return algorithms.get(name).clone(); } else { return algorithm; } } private  ChecksumFactory(); }
ChecksumFactory { public ChecksumAlgorithm getAlgorithm(String name) throws NoSuchAlgorithmException { ConcurrentLinkedQueue<ChecksumAlgorithm> cache = pool.get(name); if (cache == null) throw new NoSuchAlgorithmException("algorithm " + name + " not supported"); ChecksumAlgorithm algorithm = cache.poll(); if (algorithm == null) { return algorithms.get(name).clone(); } else { return algorithm; } } private  ChecksumFactory(); static ChecksumFactory getInstance(); ChecksumAlgorithm getAlgorithm(String name); void returnAlgorithm(ChecksumAlgorithm algorithm); void addProvider(ChecksumProvider provider); void addAlgorithm(ChecksumAlgorithm algorithm); void removeProvider(ChecksumProvider provider); void removeAlgorithm(String algorithm); }
ChecksumFactory { public ChecksumAlgorithm getAlgorithm(String name) throws NoSuchAlgorithmException { ConcurrentLinkedQueue<ChecksumAlgorithm> cache = pool.get(name); if (cache == null) throw new NoSuchAlgorithmException("algorithm " + name + " not supported"); ChecksumAlgorithm algorithm = cache.poll(); if (algorithm == null) { return algorithms.get(name).clone(); } else { return algorithm; } } private  ChecksumFactory(); static ChecksumFactory getInstance(); ChecksumAlgorithm getAlgorithm(String name); void returnAlgorithm(ChecksumAlgorithm algorithm); void addProvider(ChecksumProvider provider); void addAlgorithm(ChecksumAlgorithm algorithm); void removeProvider(ChecksumProvider provider); void removeAlgorithm(String algorithm);  }