/** * Return a shallow copy of this <code>FastHashMap</code> instance. * The keys and values themselves are not copied. * * @return a clone of this map */ @Override public Object clone() { WeakFastHashMap<K, V> results = null; if (fast) { results = new WeakFastHashMap<K, V>(map); } else { synchronized (map) { results = new WeakFastHashMap<K, V>(map); } } results.setFast(getFast()); return (results); }
/** * Clear any cached property descriptors information for all classes * loaded by any class loaders. This is useful in cases where class * loaders are thrown away to implement class reloading. */ public void clearDescriptors() { descriptorsCache.clear(); mappedDescriptorsCache.clear(); Introspector.flushCaches(); }
public boolean remove(final Object o) { if (fast) { synchronized (WeakFastHashMap.this) { final Map<K, V> temp = cloneMap(map); final boolean r = get(temp).remove(o); map = temp; return r; } } else { synchronized (map) { return get(map).remove(o); } } }
/** Base constructor */ public PropertyUtilsBean() { descriptorsCache = new WeakFastHashMap<Class<?>, BeanIntrospectionData>(); descriptorsCache.setFast(true); mappedDescriptorsCache = new WeakFastHashMap<Class<?>, FastHashMap>(); mappedDescriptorsCache.setFast(true); introspectors = new CopyOnWriteArrayList<BeanIntrospector>(); resetBeanIntrospectors(); }
/** * Obtains the {@code BeanIntrospectionData} object describing the specified bean * class. This object is looked up in the internal cache. If necessary, introspection * is performed now on the affected bean class, and the results object is created. * * @param beanClass the bean class in question * @return the {@code BeanIntrospectionData} object for this class * @throws IllegalArgumentException if the bean class is <b>null</b> */ private BeanIntrospectionData getIntrospectionData(final Class<?> beanClass) { if (beanClass == null) { throw new IllegalArgumentException("No bean class specified"); } // Look up any cached information for this bean class BeanIntrospectionData data = descriptorsCache.get(beanClass); if (data == null) { data = fetchIntrospectionData(beanClass); descriptorsCache.put(beanClass, data); } return data; }
/** * Construct a new map with the same mappings as the specified map. * * @param map the map whose mappings are to be copied */ public WeakFastHashMap(final Map<? extends K, ? extends V> map) { super(); this.map = createMap(map); }
/** * Look up and return any registered {@link Converter} for the specified * destination class; if there is no registered Converter, return * <code>null</code>. * * @param clazz Class for which to return a registered Converter * @return The registered {@link Converter} or <code>null</code> if not found */ public Converter lookup(final Class<?> clazz) { return (converters.get(clazz)); }
/** * Register a custom {@link Converter} for the specified destination * <code>Class</code>, replacing any previously registered Converter. * * @param converter Converter to be registered * @param clazz Destination class for conversions performed by this * Converter */ public void register(final Converter converter, final Class<?> clazz) { converters.put(clazz, converter); } }
/** * Remove any registered {@link Converter} for the specified destination * <code>Class</code>. * * @param clazz Class for which to remove a registered Converter */ public void deregister(final Class<?> clazz) { converters.remove(clazz); }
/** * Set whether fast on a Map * @param map The map * @param fast Whether it should be fast or not. * @since 1.8.0 */ public static void setCacheFast(final Map<?, ?> map, final boolean fast) { if (map instanceof WeakFastHashMap) { ((WeakFastHashMap<?, ?>)map).setFast(fast); } } }
/** * Return whether a Map is fast * @param map The map * @return Whether it is fast or not. * @since 1.8.0 */ public static boolean getCacheFast(final Map<?, ?> map) { if (map instanceof WeakFastHashMap) { return ((WeakFastHashMap<?, ?>) map).getFast(); } else { return false; } }
/** * Create a cache. * @param <K> the key type of the cache * @param <V> the value type of the cache * @return a new cache * @since 1.8.0 */ public static <K, V> Map<K, V> createCache() { return new WeakFastHashMap<K, V>(); }
/** Base constructor */ public PropertyUtilsBean() { descriptorsCache = new WeakFastHashMap<Class<?>, BeanIntrospectionData>(); descriptorsCache.setFast(true); mappedDescriptorsCache = new WeakFastHashMap<Class<?>, FastHashMap>(); mappedDescriptorsCache.setFast(true); introspectors = new CopyOnWriteArrayList<BeanIntrospector>(); resetBeanIntrospectors(); }
/** * Construct a new map with the same mappings as the specified map. * * @param map the map whose mappings are to be copied */ public WeakFastHashMap(final Map<? extends K, ? extends V> map) { super(); this.map = createMap(map); }
/** * Obtains the {@code BeanIntrospectionData} object describing the specified bean * class. This object is looked up in the internal cache. If necessary, introspection * is performed now on the affected bean class, and the results object is created. * * @param beanClass the bean class in question * @return the {@code BeanIntrospectionData} object for this class * @throws IllegalArgumentException if the bean class is <b>null</b> */ private BeanIntrospectionData getIntrospectionData(final Class<?> beanClass) { if (beanClass == null) { throw new IllegalArgumentException("No bean class specified"); } // Look up any cached information for this bean class BeanIntrospectionData data = descriptorsCache.get(beanClass); if (data == null) { data = fetchIntrospectionData(beanClass); descriptorsCache.put(beanClass, data); } return data; }
/** * Look up and return any registered {@link Converter} for the specified * destination class; if there is no registered Converter, return * <code>null</code>. * * @param clazz Class for which to return a registered Converter * @return The registered {@link Converter} or <code>null</code> if not found */ public Converter lookup(final Class<?> clazz) { return (converters.get(clazz)); }
/** * Register a custom {@link Converter} for the specified destination * <code>Class</code>, replacing any previously registered Converter. * * @param converter Converter to be registered * @param clazz Destination class for conversions performed by this * Converter */ public void register(final Converter converter, final Class<?> clazz) { converters.put(clazz, converter); } }
/** * Remove any registered {@link Converter} for the specified destination * <code>Class</code>. * * @param clazz Class for which to remove a registered Converter */ public void deregister(final Class<?> clazz) { converters.remove(clazz); }
/** * Set whether fast on a Map * @param map The map * @param fast Whether it should be fast or not. * @since 1.8.0 */ public static void setCacheFast(final Map<?, ?> map, final boolean fast) { if (map instanceof WeakFastHashMap) { ((WeakFastHashMap<?, ?>)map).setFast(fast); } } }
/** * Return whether a Map is fast * @param map The map * @return Whether it is fast or not. * @since 1.8.0 */ public static boolean getCacheFast(final Map<?, ?> map) { if (map instanceof WeakFastHashMap) { return ((WeakFastHashMap<?, ?>) map).getFast(); } else { return false; } }