本文整理汇总了Java中java.util.WeakHashMap类的典型用法代码示例。如果您正苦于以下问题:Java WeakHashMap类的具体用法?Java WeakHashMap怎么用?Java WeakHashMap使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
WeakHashMap类属于java.util包,在下文中一共展示了WeakHashMap类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: DownloadHandler
import java.util.WeakHashMap; //导入依赖的package包/类
public DownloadHandler(String url,
WeakHashMap<String, Object> params,
IRequest request,
String downDir,
String extension,
String name,
ISuccess success,
IFailure failure,
IError error) {
this.URL = url;
this.PARAMS = params;
this.REQUEST = request;
this.DOWNLOAD_DIR = downDir;
this.EXTENSION = extension;
this.NAME = name;
this.SUCCESS = success;
this.FAILURE = failure;
this.ERROR = error;
}
示例2: ImageViewSetter
import java.util.WeakHashMap; //导入依赖的package包/类
/**
* Creates a new instance.
* @param context
* @param config - may be null, default will be used
*/
public ImageViewSetter(Context context, ImageViewSetterConfiguration config) {
mConfig = (config == null) ? ImageViewSetterConfiguration.getDefault() : config;
mTaskMap = Collections.synchronizedMap(new WeakHashMap<ImageView, String>());
if (mConfig.interruptThreads) {
mThreadMap = Collections.synchronizedMap(new WeakHashMap<ImageView, Thread>());
mThreadLock = new MultiLock<ImageView>();
} else {
mThreadMap = null;
mThreadLock = null;
}
mHandler = new Handler(context.getMainLooper(), new ForegroundHandler());
mCache = mConfig.useCache ?
new BitmapMemoryCache(mConfig.cacheSize) : null;
mDefaultDrawable = mConfig.whileLoading;
}
示例3: initialize
import java.util.WeakHashMap; //导入依赖的package包/类
static void initialize(ProfilerServer inProfilerServer) {
try {
Class classLoaderClass = ClassLoader.class;
Class[] stringArg = new Class[] { String.class };
findLoadedClassMethod = classLoaderClass.getDeclaredMethod("findLoadedClass", stringArg); // NOI18N
findLoadedClassMethod.setAccessible(true); // REQUIRED to suppress
findBootstrapClassMethod = classLoaderClass.getDeclaredMethod("findBootstrapClass", stringArg); // NOI18N
findBootstrapClassMethod.setAccessible(true); // access checks
} catch (Exception ex) {
System.err.println(ENGINE_WARNING+"Cannot use ClassLoader.findLoadedClass() and/or ClassLoader.findBootstrapClass() in ClassLoaderManager"); // NOI18N
if (DEBUG) ex.printStackTrace(System.err);
findLoadedClassMethod = null;
findBootstrapClassMethod = null;
}
// This is done to just initialize some reflection classes, which may otherwise be initialized only when
// this class is used for the first time, and thus may cause endless class load recursion
ClassLoaderManager clm = new ClassLoaderManager(ClassLoader.getSystemClassLoader(), 0);
clm.getLoadedClass("java.lang.String"); // NOI18N
profilerServer = inProfilerServer;
manMap = new WeakHashMap();
manVec = new Vector();
rq = new ReferenceQueue();
}
示例4: ThumbnailLoader
import java.util.WeakHashMap; //导入依赖的package包/类
private ThumbnailLoader(@Nullable Context context, @Nullable String googleApiKey) {
String metaGoogleApiKey = googleApiKey;
if (context != null) {
try {
final ApplicationInfo appInfo = context.getPackageManager().getApplicationInfo(context.getPackageName(), PackageManager.GET_META_DATA);
if (appInfo.metaData != null) {
metaGoogleApiKey = appInfo.metaData.getString("com.codewaves.youtubethumbnailview.ApiKey");
}
}
catch (PackageManager.NameNotFoundException e) {
// Ignore
}
}
final BlockingQueue<Runnable> taskQueue = new LinkedBlockingQueue<>();
executor = new ThreadPoolExecutor(DEFAULT_THREAD_POOL_SIZE, DEFAULT_THREAD_POOL_SIZE, 0L, TimeUnit.MILLISECONDS, taskQueue);
requestMap = new WeakHashMap<>();
defaultInfoDownloader = new ApiVideoInfoDownloader(metaGoogleApiKey);
defaultImageLoader = new SimpleImageLoader();
}
示例5: readObject
import java.util.WeakHashMap; //导入依赖的package包/类
private void readObject(ObjectInputStream s)
throws ClassNotFoundException, IOException
{
fontSearch = new FontKey(null, 0, 0);
fontTable = new Hashtable<>();
search = new SimpleAttributeSet();
attributesPool = Collections.
synchronizedMap(new WeakHashMap<SmallAttributeSet,
WeakReference<SmallAttributeSet>>());
ObjectInputStream.GetField f = s.readFields();
Style newStyles = (Style) f.get("styles", null);
if (newStyles == null) {
throw new InvalidObjectException("Null styles");
}
styles = newStyles;
unusedSets = f.get("unusedSets", 0);
}
示例6: main
import java.util.WeakHashMap; //导入依赖的package包/类
public static void main(String[] strs) {
int size = 100;
Key[] a = new Key[100];
WeakHashMap<Key, Value> weakHashMap = new WeakHashMap<>();
for (int i = 0; i < size; i++) {
Key key = new Key(i+"");
Value value = new Value(i + "");
if (i % 3 == 0) {
a[i] = key;
}
weakHashMap.put(key, value);
}
System.gc();
System.out.println(weakHashMap);
}
示例7: addListener
import java.util.WeakHashMap; //导入依赖的package包/类
/**
* Add a property listener to this object.
*
* @param propertyMap The property listener that is added.
*/
synchronized final void addListener(final String key, final PropertyMap propertyMap) {
if (Context.DEBUG) {
listenersAdded++;
}
if (listeners == null) {
listeners = new WeakHashMap<>();
}
WeakPropertyMapSet set = listeners.get(key);
if (set == null) {
set = new WeakPropertyMapSet();
listeners.put(key, set);
}
if (!set.contains(propertyMap)) {
set.add(propertyMap);
}
}
示例8: testWeakHashMap
import java.util.WeakHashMap; //导入依赖的package包/类
public void testWeakHashMap() {
Map weakMap = new WeakHashMap();
for (int i = 0; i < 10; i++) {
weakMap.put(new Object(), null);
}
GCTests.assertGCed(new WeakReference(new Object()));
Set entries = weakMap.entrySet();
for (Iterator iter = entries.iterator(); iter.hasNext();) {
Map.Entry entry = (Map.Entry) iter.next();
assertNull(entry.getKey());
}
}
示例9: checkAcceptPermission
import java.util.WeakHashMap; //导入依赖的package包/类
/**
* Verify that the given AccessControlContext has permission to
* accept this connection.
*/
void checkAcceptPermission(SecurityManager sm,
AccessControlContext acc)
{
/*
* Note: no need to synchronize on cache-related fields, since this
* method only gets called from the ConnectionHandler's thread.
*/
if (sm != cacheSecurityManager) {
okContext = null;
authCache = new WeakHashMap<AccessControlContext,
Reference<AccessControlContext>>();
cacheSecurityManager = sm;
}
if (acc.equals(okContext) || authCache.containsKey(acc)) {
return;
}
InetAddress addr = socket.getInetAddress();
String host = (addr != null) ? addr.getHostAddress() : "*";
sm.checkAccept(host, socket.getPort());
authCache.put(acc, new SoftReference<AccessControlContext>(acc));
okContext = acc;
}
示例10: Cache
import java.util.WeakHashMap; //导入依赖的package包/类
public Cache(final int capacity, final boolean fair) {
ReentrantReadWriteLock lock = new ReentrantReadWriteLock(fair);
readerLock = lock.readLock();
writerLock = lock.writeLock();
weakCache = new WeakHashMap<KEY, VALUE>(capacity);
hardCache = new LinkedHashMap<KEY, VALUE>(capacity + 1, 1.0f, true) {
private static final long serialVersionUID = 5994447707758047152L;
protected final boolean removeEldestEntry(Map.Entry<KEY, VALUE> entry) {
if (this.size() > capacity) {
weakCache.put(entry.getKey(), entry.getValue());
return true;
}
return false;
};
};
}
示例11: RxBus
import java.util.WeakHashMap; //导入依赖的package包/类
/**
* With this constructor the {@link RxBus} use a {@link PublishSubject} and instantiate it calling the static method {@code PublishSubject.create()}
* @see PublishSubject
*/
public RxBus() {
super((Subject<T, R>) PublishSubject.create());
mSubscriptionsList = new WeakHashMap<>();
}
示例12: JavaScriptModuleRegistry
import java.util.WeakHashMap; //导入依赖的package包/类
public JavaScriptModuleRegistry(List<JavaScriptModuleRegistration> config) {
mModuleInstances = new WeakHashMap<>();
mModuleRegistrations = new HashMap<>();
for (JavaScriptModuleRegistration registration : config) {
mModuleRegistrations.put(registration.getModuleInterface(), registration);
}
}
示例13: Picasso
import java.util.WeakHashMap; //导入依赖的package包/类
Picasso(Context context, Dispatcher dispatcher, Cache cache, Listener listener,
RequestTransformer requestTransformer, List<RequestHandler> extraRequestHandlers, Stats stats,
Bitmap.Config defaultBitmapConfig, boolean indicatorsEnabled, boolean loggingEnabled) {
this.context = context;
this.dispatcher = dispatcher;
this.cache = cache;
this.listener = listener;
this.requestTransformer = requestTransformer;
this.defaultBitmapConfig = defaultBitmapConfig;
int builtInHandlers = 7; // Adjust this as internal handlers are added or removed.
int extraCount = (extraRequestHandlers != null ? extraRequestHandlers.size() : 0);
List<RequestHandler> allRequestHandlers = new ArrayList<>(builtInHandlers + extraCount);
// ResourceRequestHandler needs to be the first in the list to avoid
// forcing other RequestHandlers to perform null checks on request.uri
// to cover the (request.resourceId != 0) case.
allRequestHandlers.add(new ResourceRequestHandler(context));
if (extraRequestHandlers != null) {
allRequestHandlers.addAll(extraRequestHandlers);
}
allRequestHandlers.add(new ContactsPhotoRequestHandler(context));
allRequestHandlers.add(new MediaStoreRequestHandler(context));
allRequestHandlers.add(new ContentStreamRequestHandler(context));
allRequestHandlers.add(new AssetRequestHandler(context));
allRequestHandlers.add(new FileRequestHandler(context));
allRequestHandlers.add(new NetworkRequestHandler(dispatcher.downloader, stats));
requestHandlers = Collections.unmodifiableList(allRequestHandlers);
this.stats = stats;
this.targetToAction = new WeakHashMap<>();
this.targetToDeferredRequestCreator = new WeakHashMap<>();
this.indicatorsEnabled = indicatorsEnabled;
this.loggingEnabled = loggingEnabled;
this.referenceQueue = new ReferenceQueue<>();
this.cleanupThread = new CleanupThread(referenceQueue, HANDLER);
this.cleanupThread.start();
}
示例14: checkConnectPermission
import java.util.WeakHashMap; //导入依赖的package包/类
/**
* Checks if the current caller has sufficient privilege to make
* a connection to the remote endpoint.
* @exception SecurityException if caller is not allowed to use this
* Channel.
*/
private void checkConnectPermission() throws SecurityException {
SecurityManager security = System.getSecurityManager();
if (security == null)
return;
if (security != cacheSecurityManager) {
// The security manager changed: flush the cache
okContext = null;
authcache = new WeakHashMap<AccessControlContext,
Reference<AccessControlContext>>();
cacheSecurityManager = security;
}
AccessControlContext ctx = AccessController.getContext();
// If ctx is the same context as last time, or if it
// appears in the cache, bypass the checkConnect.
if (okContext == null ||
!(okContext.equals(ctx) || authcache.containsKey(ctx)))
{
security.checkConnect(ep.getHost(), ep.getPort());
authcache.put(ctx, new SoftReference<AccessControlContext>(ctx));
// A WeakHashMap is transformed into a SoftHashSet by making
// each value softly refer to its own key (Peter's idea).
}
okContext = ctx;
}
示例15: cachedOverride
import java.util.WeakHashMap; //导入依赖的package包/类
final AttrSet cachedOverride(Object override) {
AttrSet attrSet;
if (overrideCache == null) {
overrideCache = new WeakHashMap<AttrSet,WeakReference<AttrSet>>(4);
attrSet = null;
} else {
WeakReference<AttrSet> ref = (WeakReference<AttrSet>) ((Map<?,?>)overrideCache).get(override);
attrSet = (ref != null) ? ref.get() : null;
}
overrideGets++;
return attrSet;
}