/** * when you use the lock keep it until release * * @param key * @return */ private ReadWriteLock getLock(final Point key){ ReadWriteLock lock; synchronized(locks){ lock = locks.get(key); if (lock == null) { lock = new ReentrantReadWriteLock(); locks.put(key, lock); } } return lock; }
/** * Creates a new map or return an existing map for the given attribute characteristics. * * <p>This method does not clone the {@code characterizedBy} array. If that array * is a user-provided argument, then cloning that array is caller responsibility.</p> * * @param source the attribute which is characterized by {@code characterizedBy}. * @param characterizedBy characteristics of {@code source}. Should not be empty. * @return a map for this given characteristics. * @throws IllegalArgumentException if two characteristics have the same name. */ static CharacteristicTypeMap create(final DefaultAttributeType<?> source, final DefaultAttributeType<?>[] characterizedBy) { CharacteristicTypeMap map; synchronized (SHARED) { map = SHARED.get(characterizedBy); if (map == null) { map = new CharacteristicTypeMap(source, characterizedBy); SHARED.put(characterizedBy, map); } } return map; }
/** * Creates a new map or return an existing map for the given attribute characteristics. * * <p>This method does not clone the {@code characterizedBy} array. If that array * is a user-provided argument, then cloning that array is caller responsibility.</p> * * @param source the attribute which is characterized by {@code characterizedBy}. * @param characterizedBy characteristics of {@code source}. Should not be empty. * @return a map for this given characteristics. * @throws IllegalArgumentException if two characteristics have the same name. */ static CharacteristicTypeMap create(final DefaultAttributeType<?> source, final DefaultAttributeType<?>[] characterizedBy) { CharacteristicTypeMap map; synchronized (SHARED) { map = SHARED.get(characterizedBy); if (map == null) { map = new CharacteristicTypeMap(source, characterizedBy); SHARED.put(characterizedBy, map); } } return map; }
if (childs.put(key, child) != existing) { throw new AssertionError(); // Paranoiac check.
/** * Returns the logger of the specified name, or {@code null} if the JDK logging framework * should be used. * * @param name the name of the logger. * @return the logger, or {@code null} if the JDK logging framework should be used. */ public Logger getLogger(final String name) { final L target = getImplementation(name); if (target == null) { return null; } synchronized (loggers) { Logger logger = loggers.get(name); if (logger == null || !target.equals(unwrap(logger))) { logger = wrap(name, target); loggers.put(name, logger); } return logger; } }
if (childs.put(key, child) != existing) { throw new AssertionError(); // Paranoiac check.
/** * Returns the logger of the specified name, or {@code null} if the JDK logging framework * should be used. * * @param name the name of the logger. * @return the logger, or {@code null} if the JDK logging framework should be used. */ public Logger getLogger(final String name) { final L target = getImplementation(name); if (target == null) { return null; } synchronized (loggers) { Logger logger = loggers.get(name); if (logger == null || !target.equals(unwrap(logger))) { logger = wrap(name, target); loggers.put(name, logger); } return logger; } }
SHARED.put(locale, map);
if (childs.put(key, child) != existing) { throw new AssertionError(); // Paranoiac check.
if (childs.put(key, child) != existing) { throw new AssertionError(); // Paranoiac check.
SHARED.put(locale, map);
if (pool.put(key, this) != existing) { throw new AssertionError(); // Paranoiac check.
value = Proxy.newProxyInstance(classloader, new Class<?>[] {type, MetadataProxy.class}, new Dispatcher(identifier, this)); pool.put(key, value);
if (pool.put(key, this) != existing) { throw new AssertionError(); // Paranoiac check.
value = Proxy.newProxyInstance(classloader, new Class<?>[] {type, MetadataProxy.class}, new Dispatcher(identifier, this)); pool.put(key, value);
/** * Creates a model for the specified datum and maximum degree and order. * In current version, only {@linkplain DefaultGeodeticDatum#WGS84 WGS84} * and {@linkplain DefaultGeodeticDatum#WGS72 WGS72} datum are supported. * * @param datum The datum for which to create the model. * @param nmax The maximum degree and order. * @return The model. * @throws IllegalArgumentException If {@code nmax} is not greater than zero, * or if the given datum is not a supported one. * @throws FactoryException If an error occurred while loading the data. */ public static EarthGravitationalModel create(final GeodeticDatum datum, final int nmax) throws IllegalArgumentException, FactoryException { EarthGravitationalModel model; final Integer key = hashCode(CRS.equalsApproximatively(CommonCRS.WGS84.datum(), datum), nmax); synchronized (POOL) { model = POOL.get(key); if (model == null) { model = new EarthGravitationalModel(datum, nmax); POOL.put(key, model); } } return model; }
/** * Tests with array keys. */ @Test @DependsOnMethod("testStrongReferences") public void testWithArrayKeys() { final WeakValueHashMap<int[],Integer> weakMap = new WeakValueHashMap<>(int[].class); final int[] k1 = new int[] {2, 5, 3}; final int[] k2 = new int[] {2, 5, 4}; final Integer v1 = 1; final Integer v2 = 2; assertNull ( weakMap.put(k1, v1)); assertSame (v1, weakMap.put(k1, v1)); assertSame (v1, weakMap.put(k1.clone(), v1)); assertNull ( weakMap.put(k2, v2)); assertSame (v2, weakMap.put(k2, v2)); assertSame (v1, weakMap.get(k1)); assertSame (v2, weakMap.get(k2)); }
/** * Tests using identity comparisons. This test uses two {@link Integer} keys having the same value * but being different instances. * * @since 0.4 */ @Test @DependsOnMethod("testStrongReferences") @SuppressWarnings("UnnecessaryBoxing") public void testIdentityComparisons() { final WeakValueHashMap<Integer,Integer> weakMap = new WeakValueHashMap<>(Integer.class, true); final Integer k1 = 10; final Integer k2 = 20; final Integer k3 = new Integer(10); // Really want a new instance. final Integer v1 = 1; final Integer v2 = 2; final Integer v3 = 3; assertEquals(k1, k3); // Necessary condition for the test to be valid. assertNull(weakMap.put(k1, v1)); assertSame(v1, weakMap.put(k1, v1)); assertNull(weakMap.put(k2, v2)); assertSame(v2, weakMap.put(k2, v2)); assertNull(weakMap.put(k3, v3)); assertSame(v3, weakMap.put(k3, v3)); assertSame(v1, weakMap.get(k1)); assertSame(v2, weakMap.get(k2)); assertSame(v3, weakMap.get(k3)); } }