List of usage examples for java.util WeakHashMap WeakHashMap
public WeakHashMap(Map<? extends K, ? extends V> m)
From source file:org.eclipse.gemini.blueprint.service.exporter.support.internal.support.PublishingServiceFactory.java
/** * Constructs a new <code>PublishingServiceFactory</code> instance. Since its an internal class, this constructor * accepts a number of parameters to sacrifice readability for thread-safety. * //ww w . j ava 2 s . c om * @param classes * @param target * @param beanFactory * @param targetBeanName * @param createTCCLProxy * @param classLoader * @param aopClassLoader * @param bundleContext */ public PublishingServiceFactory(LazyTargetResolver targetResolver, Class<?>[] classes, boolean createTCCLProxy, ClassLoader classLoader, ClassLoader aopClassLoader, BundleContext bundleContext) { super(); this.targetResolver = targetResolver; this.classes = classes; this.createTCCLProxy = createTCCLProxy; this.classLoader = classLoader; this.aopClassLoader = aopClassLoader; this.bundleContext = bundleContext; proxyCache = (createTCCLProxy ? new WeakHashMap<Object, WeakReference<Object>>(4) : null); }
From source file:com.sunchenbin.store.feilong.core.lang.ArrayUtil.java
/** * array ./*from www . j av a2 s . com*/ * * <code> * <pre> * * Example 1: * if Integer[] array = { 1, 1, 1, 2, 2, 3, 4, 5, 5, 6, 7, 8, 8 }; * * will return * { * "1": [ * 1, * 1, * 1 * ], * "2": [ * 2, * 2 * ], * "3": [3], * "4": [4], * "5": [ * 5, * 5 * ], * "6": [6], * "7": [7], * "8": [ * 8, * 8 * ] * } * } * </pre></code> * * @param <T> * the generic type * @param array * the array * @return the map< t, list< t>> * @since 1.0.8 */ public static <T> Map<T, List<T>> group(T[] array) { if (null == array) { return Collections.emptyMap(); } // ??? HashMap TreeMap Map<T, List<T>> map = new WeakHashMap<T, List<T>>(array.length); for (T t : array) { List<T> valueList = map.get(t); if (null == valueList) { valueList = new ArrayList<T>(); } valueList.add(t); map.put(t, valueList); } return map; }
From source file:WeakHashSet.java
/** * Constructs a new WeakHashSet with the values given passed the the backing store. * * @see java.util.WeakHashMap#WeakHashMap(int) *//*from ww w.j av a 2 s.c o m*/ public WeakHashSet(final int initialCapacity) { backingStore = new WeakHashMap(initialCapacity); }
From source file:org.openmrs.util.HandlerUtil.java
/** * Retrieves a List of all registered components from the Context that are of the passed * handlerType and one or more of the following is true: * <ul>/*w w w. j a v a 2s . c o m*/ * <li>The handlerType is annotated as a {@link Handler} that supports the passed type</li> * <li>The passed type is null - this effectively returns all components of the passed * handlerType</li> * </ul> * The returned handlers are ordered in the list based upon the order property. * * @param handlerType Indicates the type of class to return * @param type Indicates the type that the given handlerType must support (or null for any) * @return a List of all matching Handlers for the given parameters, ordered by Handler#order * @should return a list of all classes that can handle the passed type * @should return classes registered in a module * @should return an empty list if no classes can handle the passed type */ public static <H, T> List<H> getHandlersForType(Class<H> handlerType, Class<T> type) { List<?> list = cachedHandlers.get(new Key(handlerType, type)); if (list != null) { return (List<H>) list; } List<H> handlers = new ArrayList<H>(); // First get all registered components of the passed class log.debug("Getting handlers of type " + handlerType + (type == null ? "" : " for class " + type.getName())); for (H handler : Context.getRegisteredComponents(handlerType)) { Handler handlerAnnotation = handler.getClass().getAnnotation(Handler.class); // Only consider those that have been annotated as Handlers if (handlerAnnotation != null) { // If no type is passed in return all handlers if (type == null) { log.debug("Found handler " + handler.getClass()); handlers.add(handler); } // Otherwise, return all handlers that support the passed type else { for (int i = 0; i < handlerAnnotation.supports().length; i++) { Class<?> clazz = handlerAnnotation.supports()[i]; if (clazz.isAssignableFrom(type)) { log.debug("Found handler: " + handler.getClass()); handlers.add(handler); } } } } } // Return the list of handlers based on the order specified in the Handler annotation Collections.sort(handlers, new Comparator<H>() { public int compare(H o1, H o2) { return getOrderOfHandler(o1.getClass()).compareTo(getOrderOfHandler(o2.getClass())); } }); Map<Key, List<?>> newCachedHandlers = new WeakHashMap<Key, List<?>>(cachedHandlers); newCachedHandlers.put(new Key(handlerType, type), handlers); cachedHandlers = newCachedHandlers; return handlers; }
From source file:WeakHashSet.java
/** * Constructs a new set containing the elements in the specified * collection. The <tt>WeakHashMap</tt> is created with default load factor * (0.75) and an initial capacity sufficient to contain the elements in * the specified collection.//from w w w. ja v a 2 s . c o m * * @param c the collection whose elements are to be placed into this set. * @throws NullPointerException if the specified collection is null. */ public WeakHashSet(Collection c) { map = new WeakHashMap(Math.max((int) (c.size() / .75f) + 1, 16)); addAll(c); }
From source file:WeakHashSet.java
/** * Constructs a new, empty set; the backing <tt>WeakHashMap</tt> instance has * the specified initial capacity and default load factor, which is * <tt>0.75</tt>./*from ww w . ja v a 2 s . com*/ * * @param initialCapacity the initial capacity of the hash table. * @throws IllegalArgumentException if the initial capacity is less * than zero. */ public WeakHashSet(int initialCapacity) { map = new WeakHashMap(initialCapacity); }
From source file:com.discovery.darchrow.lang.ArrayUtil.java
/** * array ./* w w w . j a v a 2s.c om*/ * * <pre> * * Example 1: * if Integer[] array = { 1, 1, 1, 2, 2, 3, 4, 5, 5, 6, 7, 8, 8 }; * * will return * * {@code * { * "1": [ * 1, * 1, * 1 * ], * "2": [ * 2, * 2 * ], * "3": [3], * "4": [4], * "5": [ * 5, * 5 * ], * "6": [6], * "7": [7], * "8": [ * 8, * 8 * ] * } * } * </pre> * * @param <T> * the generic type * @param array * the array * @return the map< t, list< t>> * @since 1.0.8 */ public static <T> Map<T, List<T>> group(T[] array) { if (null == array) { return null; } // ??? HashMap TreeMap Map<T, List<T>> map = new WeakHashMap<T, List<T>>(array.length); for (T t : array) { List<T> valueList = map.get(t); if (null == valueList) { valueList = new ArrayList<T>(); } valueList.add(t); map.put(t, valueList); } return map; }
From source file:com.uimirror.location.DefaultLocation.java
/** * Gets the expanded map that indeed to send to the caller * @return//from w w w. ja v a 2 s. c o m */ public Map<String, Object> getExpandedLoc() { Map<String, Object> rs = new WeakHashMap<String, Object>(5); rs.put(LocationDBFields.ID, getLocationId()); if (StringUtils.hasText(getName())) rs.put(LocationDBFields.NAME, getName()); if (getLocation() != null) rs.put(LocationDBFields.GEOMETRY, getLocation().toGeoCordMap()); if (getCountry() != null) rs.put(LocationDBFields.COUNTRY, getCountry().toMap()); if (getState() != null) rs.put(LocationDBFields.STATE, getState().toMap()); if (getCity() != null) rs.put(LocationDBFields.CITY, getCity().toMap()); if (getLocality() != null) rs.put(LocationDBFields.LOCALITY, getLocality().toMap()); if (getType() != null) rs.put(LocationDBFields.LOCATION_TYPE, getType().getLocType()); if (StringUtils.hasText(getPin())) rs.put(LocationDBFields.PIN, getPin()); return rs; }
From source file:com.uimirror.location.DefaultLocation.java
/** * gets the short Location map//from ww w . ja va 2 s . co m * @return */ public Map<String, Object> getShortLoc() { Map<String, Object> rs = new WeakHashMap<String, Object>(5); rs.put(LocationDBFields.ID, getLocationId()); if (StringUtils.hasText(getName())) rs.put(LocationDBFields.NAME, getName()); if (getLocation() != null) rs.put(LocationDBFields.GEOMETRY, getLocation().toGeoCordMap()); if (getCountryId() != null) rs.put(LocationDBFields.COUNTRY_ID, getCountryId()); if (getStateId() != null) rs.put(LocationDBFields.STATE_ID, getStateId()); if (getCityId() != null) rs.put(LocationDBFields.CITY_ID, getCityId()); if (getLocalityId() != null) rs.put(LocationDBFields.LOCALITY_ID, getLocalityId()); if (getType() != null) rs.put(LocationDBFields.LOCATION_TYPE, getType().getLocType()); if (StringUtils.hasText(getPin())) rs.put(LocationDBFields.PIN, getPin()); return rs; }
From source file:org.compass.gps.device.hibernate.embedded.CompassEventListener.java
private CompassHolder getCompassHolder(Configuration cfg) { WeakHashMap<Configuration, CompassHolder> contextMap = contexts.get(); if (contextMap == null) { contextMap = new WeakHashMap<Configuration, CompassHolder>(2); contexts.set(contextMap);//from w w w .ja v a 2 s. c o m } CompassHolder compassHolder = contextMap.get(cfg); if (compassHolder == null) { compassHolder = initCompassHolder(cfg); if (compassHolder != null) { if (log.isDebugEnabled()) { log.debug("Regsitering new Compass Holder [" + compassHolder + "]"); } contextMap.put(cfg, compassHolder); } } return compassHolder; }