/** * Returns {@code true} if this map contains a mapping for the specified key. * Null keys are considered never present. * * @param key key whose presence in this map is to be tested. * @return {@code true} if this map contains a mapping for the specified key. */ @Override public boolean containsKey(final Object key) { return get(key) != null; }
/** * Returns {@code true} if this map contains a mapping for the specified key. * Null keys are considered never present. * * @param key key whose presence in this map is to be tested. * @return {@code true} if this map contains a mapping for the specified key. */ @Override public boolean containsKey(final Object key) { return get(key) != null; }
/** * Returns the value associated to the given key, or {@code null} if none. * This method can be invoked at anytime (at {@link Units} class initialization time or not). */ static Object get(final Object key) { Object value = HARD_CODED.get(key); // Treated as immutable, no synchronization needed. if (value == null) { value = USER_DEFINED.get(key); // Implies a synchronization lock. } return value; }
/** * Returns the value associated to the given key, or {@code null} if none. * This method can be invoked at anytime (at {@link Units} class initialization time or not). */ static Object get(final Object key) { Object value = HARD_CODED.get(key); // Treated as immutable, no synchronization needed. if (value == null) { value = USER_DEFINED.get(key); // Implies a synchronization lock. } return value; }
/** * 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; }
DefaultLocalName child; synchronized (childs) { final Object existing = childs.get(key); if (existing instanceof DefaultLocalName) { child = (DefaultLocalName) existing;
/** * 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; } }
/** * 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; } }
return DEFAULT_TYPES; DimensionNameType[] shared = POOL.get(types); if (shared == null) {
/** * Creates a coordinate reference system from the given {@literal Proj.4} definition string. * The {@code Proj4} suffix shall have been removed before to invoke this method. * * @param definition the Proj.4 definition. * @param withHeight whether to include a height axis. * * @see Proj4#createCRS(String, int) * @see #createCoordinateReferenceSystem(String) */ final CoordinateReferenceSystem createCRS(final String definition, final boolean withHeight) throws FactoryException { PJ pj = pool.get(definition); if (pj == null) { pj = unique(new PJ(definition)); pool.putIfAbsent(definition, pj); } return createCRS(pj, withHeight); }
/** * Creates a coordinate reference system from the given {@literal Proj.4} definition string. * The {@code Proj4} suffix shall have been removed before to invoke this method. * * @param definition the Proj.4 definition. * @param withHeight whether to include a height axis. * * @see Proj4#createCRS(String, int) * @see #createCoordinateReferenceSystem(String) */ final CoordinateReferenceSystem createCRS(final String definition, final boolean withHeight) throws FactoryException { PJ pj = pool.get(definition); if (pj == null) { pj = unique(new PJ(definition)); pool.putIfAbsent(definition, pj); } return createCRS(pj, withHeight); }
final WeakValueHashMap<String,Object> pool = p.childs; synchronized (pool) { final Object existing = pool.get(key); if (existing instanceof DefaultNameSpace) { if (equalsIgnoreParent((DefaultNameSpace) existing)) {
final WeakValueHashMap<String,Object> pool = p.childs; synchronized (pool) { final Object existing = pool.get(key); if (existing instanceof DefaultNameSpace) { if (equalsIgnoreParent((DefaultNameSpace) existing)) {
/** * 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; }
PositionalAccuracy p = CACHE.get(accuracy); if (p == null) { final DefaultRecord record = new DefaultRecord(TYPE);
PositionalAccuracy p = CACHE.get(accuracy); if (p == null) { final RecordType type = RecordSchemaSIS.REAL;
/** * 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)); } }
/** * 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)); }