LocalUniqueIDGeneratorFactory { public synchronized static IDGenerator generatorFor(int generatorId, int clusterId, Clock clock, Mode mode) { assertParameterWithinBounds("generatorId", 0, Blueprint.MAX_GENERATOR_ID, generatorId); assertParameterWithinBounds("clusterId", 0, Blueprint.MAX_CLUSTER_ID, clusterId); String generatorAndCluster = String.format("%d_%d", generatorId, clusterId); if (!instances.containsKey(generatorAndCluster)) { GeneratorIdentityHolder identityHolder = LocalGeneratorIdentity.with(clusterId, generatorId); instances.putIfAbsent(generatorAndCluster, new BaseUniqueIDGenerator(identityHolder, clock, mode)); } return instances.get(generatorAndCluster); }  synchronized static IDGenerator generatorFor(int generatorId, int clusterId, Clock clock, Mode mode); synchronized static IDGenerator generatorFor(int generatorId, int clusterId, Mode mode);  }
@Test(expected = IllegalArgumentException.class) public void outOfBoundsGeneratorIDTest() { LocalUniqueIDGeneratorFactory.generatorFor(256, 0, Mode.SPREAD); }
@Test(expected = IllegalArgumentException.class) public void outOfBoundsClusterIDTest() { LocalUniqueIDGeneratorFactory.generatorFor(0, 16, Mode.SPREAD); }
@Test(expected = IllegalArgumentException.class) public void outOfBoundsGeneratorIDNegativeTest() { LocalUniqueIDGeneratorFactory.generatorFor(-1, 0, Mode.SPREAD); }
@Test(expected = IllegalArgumentException.class) public void outOfBoundsClusterIDNegativeTest() { LocalUniqueIDGeneratorFactory.generatorFor(0, -1, Mode.SPREAD); }