java.util.WeakHashMap.containsKey()方法的使用及代码示例

x33g5p2x  于2022-02-02 转载在 其他  
字(8.4k)|赞(0)|评价(0)|浏览(121)

本文整理了Java中java.util.WeakHashMap.containsKey()方法的一些代码示例,展示了WeakHashMap.containsKey()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。WeakHashMap.containsKey()方法的具体详情如下:
包路径:java.util.WeakHashMap
类名称:WeakHashMap
方法名:containsKey

WeakHashMap.containsKey介绍

[英]Returns whether this map contains the specified key.
[中]返回此映射是否包含指定的键。

代码示例

代码示例来源:origin: jfoenixadmin/JFoenix

@Override
public void cache(Node node) {
  if (!cache.containsKey(node)) {
    final CacheMemento cacheMemento = new CacheMemento(node);
    cache.put(node, cacheMemento);
    cacheMemento.cache();
  }
}

代码示例来源:origin: apache/geode

/**
 * Throws LeaseExpiredException if the calling thread's lease on this lock previously expired. The
 * expired lease will no longer be tracked after throwing LeaseExpiredException. Caller must
 * synchronize on this lock token.
 *
 * @throws LeaseExpiredException if calling thread's lease expired
 */
void throwIfCurrentThreadHadExpiredLease() throws LeaseExpiredException {
 if (this.expiredLeases == null) {
  return;
 }
 if (this.expiredLeases.containsKey(Thread.currentThread())) {
  this.expiredLeases.remove(Thread.currentThread());
  throw new LeaseExpiredException(
    "This thread's lease expired for this lock");
 }
}

代码示例来源:origin: androidquery/androidquery

@Override
public final void callback(String url, Bitmap bm, AjaxStatus status) {
  
  ImageView firstView = v.get();
  WeakHashMap<ImageView, BitmapAjaxCallback> ivs = queueMap.remove(url);
  
  //check if view queue already contains first view 
  if(ivs == null || !ivs.containsKey(firstView)){
    checkCb(this, url, firstView, bm, status);
  }
  
  if(ivs != null){
  
    Set<ImageView> set = ivs.keySet();
    
    for(ImageView view: set){
      BitmapAjaxCallback cb = ivs.get(view);
      cb.status = status;                
      checkCb(cb, url, view, bm, status);
    }
  
  }
  
}

代码示例来源:origin: com.sun.xml.bind/jaxb-impl

/**
 * Computes the edit distance between two strings.
 * 
 * <p>
 * The complexity is O(nm) where n=a.length() and m=b.length().
 */
public static int editDistance( String a, String b ) {
  // let's check cache
  AbstractMap.SimpleEntry<String,String> entry = new AbstractMap.SimpleEntry<String, String>(a, b); // using this class to avoid creation of my own which will handle PAIR of values
  Integer result = null;
  if (CACHE.containsKey(entry))
    result = CACHE.get(entry); // looks like we have it
  if (result == null) {
    result = new EditDistance(a, b).calc();
    CACHE.put(entry, result); // cache the result
  }
  return result;
}

代码示例来源:origin: stackoverflow.com

Data someDataObject = new Data("foo");
map.put(someDataObject, someDataObject.value);
System.out.println("map contains someDataObject ? " + map.containsKey(someDataObject));

代码示例来源:origin: alibaba/jvm-sandbox

if (spyNewInstanceForNoneMethodCache.containsKey(spyRetClassInTargetClassLoader)) {
  method = spyNewInstanceForNoneMethodCache.get(spyRetClassInTargetClassLoader);
} else {
if (spyNewInstanceForReturnMethodCache.containsKey(spyRetClassInTargetClassLoader)) {
  method = spyNewInstanceForReturnMethodCache.get(spyRetClassInTargetClassLoader);
} else {
if (spyNewInstanceForThrowsMethodCache.containsKey(spyRetClassInTargetClassLoader)) {
  method = spyNewInstanceForThrowsMethodCache.get(spyRetClassInTargetClassLoader);
} else {

代码示例来源:origin: alibaba/jvm-sandbox

try {
  final Integer nextObjectID;
  if (objectIDMapping.containsKey(object)) {
    nextObjectID = objectIDMapping.get(object);
  } else {

代码示例来源:origin: yahoo/squidb

/**
 * Returns true if the session should yield the connection due to
 * contention over available database connections.
 *
 * @param connection The connection owned by the session.
 * @param connectionFlags The connection request flags.
 * @return True if the session should yield its connection.
 * @throws IllegalStateException if the connection was not acquired
 * from this pool or if it has already been released.
 */
public boolean shouldYieldConnection(SQLiteConnection connection, int connectionFlags) {
  synchronized (mLock) {
    if (!mAcquiredConnections.containsKey(connection)) {
      throw new IllegalStateException("Cannot perform this operation "
          + "because the specified connection was not acquired "
          + "from this pool or has already been released.");
    }
    if (!mIsOpen) {
      return false;
    }
    return isSessionBlockingImportantConnectionWaitersLocked(
        connection.isPrimaryConnection(), connectionFlags);
  }
}

代码示例来源:origin: facebook/litho

private static @Nullable MountContentPool getMountContentPool(
  Context context, ComponentLifecycle lifecycle) {
 if (lifecycle.poolSize() == 0) {
  return null;
 }
 synchronized (sMountContentLock) {
  SparseArray<MountContentPool> poolsArray = sMountContentPoolsByContext.get(context);
  if (poolsArray == null) {
   final Context rootContext = ContextUtils.getRootContext(context);
   if (sDestroyedRootContexts.containsKey(rootContext)) {
    return null;
   }
   ensureActivityCallbacks(context);
   poolsArray = new SparseArray<>();
   sMountContentPoolsByContext.put(context, poolsArray);
  }
  MountContentPool pool = poolsArray.get(lifecycle.getTypeId());
  if (pool == null) {
   pool = lifecycle.onCreateMountContentPool();
   poolsArray.put(lifecycle.getTypeId(), pool);
  }
  return pool;
 }
}

代码示例来源:origin: jfoenixadmin/JFoenix

@Override
public void cache(Pane node) {
  if (!cache.containsKey(node)) {
    SnapshotParameters snapShotparams = new SnapshotParameters();
    snapShotparams.setFill(Color.TRANSPARENT);
    WritableImage temp = node.snapshot(snapShotparams,
      new WritableImage((int) node.getLayoutBounds().getWidth(),
        (int) node.getLayoutBounds().getHeight()));
    ImageView tempImage = new ImageView(temp);
    tempImage.setCache(true);
    tempImage.setCacheHint(CacheHint.SPEED);
    cache.put(node, new ArrayList<>(node.getChildren()));
    node.getChildren().setAll(tempImage);
  }
}

代码示例来源:origin: AppliedEnergistics/Applied-Energistics-2

boolean hasDivided( final GridStorage myStorage )
{
  return this.divided.containsKey( myStorage );
}

代码示例来源:origin: parse-community/Parse-SDK-Android

private static Long getStableId(Lock lock) {
  synchronized (stableIds) {
    if (stableIds.containsKey(lock)) {
      return stableIds.get(lock);
    }
    long id = nextStableId++;
    stableIds.put(lock, id);
    return id;
  }
}

代码示例来源:origin: ogaclejapan/ArcLayout

public float getChildAngleAt(View v) {
 return (childAngleHolder.containsKey(v)) ? childAngleHolder.get(v) : 0f;
}

代码示例来源:origin: jersey/jersey

return getDefaultValidator();
} else {
  if (!validatorCache.containsKey(contextResolver)) {
    final ValidateOnExecutionHandler validateOnExecutionHandler =
        new ValidateOnExecutionHandler(validationConfig, !isValidateOnExecutableOverrideCheckDisabled());

代码示例来源:origin: GeekGhost/Ghost

/**
 * 获取 创建Logger 的时候的实例,提供利用率
 *
 * @param className logger的名称
 * @return
 */
private static org.slf4j.Logger getLoggerInstance(String className) {
  if (loggerHashMap == null)
    loggerHashMap = new WeakHashMap<String, org.slf4j.Logger>();
  if (loggerHashMap.containsKey(className)) {
    return loggerHashMap.get(className);
  } else {
    org.slf4j.Logger logger = LoggerFactory.getLogger(className);
    loggerHashMap.put(className, logger);
    return logger;
  }
}

代码示例来源:origin: Vazkii/Botania

@Override
public TileEntity getClosestCollector(BlockPos pos, World world, int limit) {
  if(manaCollectors.containsKey(world))
    return getClosest(manaCollectors.get(world), pos, world.isRemote, limit);
  return null;
}

代码示例来源:origin: Vazkii/Botania

@Override
public TileEntity getClosestPool(BlockPos pos, World world, int limit) {
  if(manaPools.containsKey(world))
    return getClosest(manaPools.get(world), pos, world.isRemote, limit);
  return null;
}

代码示例来源:origin: ukanth/afwall

@Override
public void registerOnSharedPreferenceChangeListener(OnSharedPreferenceChangeListener listener) {
  if (mListeners.containsKey(listener)) return;
  PreferenceContentObserver observer = new PreferenceContentObserver(listener);
  mListeners.put(listener, observer);
  mContext.getContentResolver().registerContentObserver(mBaseUri, true, observer);
}

代码示例来源:origin: org.glassfish.jaxb/jaxb-runtime

/**
 * Computes the edit distance between two strings.
 * 
 * <p>
 * The complexity is O(nm) where n=a.length() and m=b.length().
 */
public static int editDistance( String a, String b ) {
  // let's check cache
  AbstractMap.SimpleEntry<String,String> entry = new AbstractMap.SimpleEntry<String, String>(a, b); // using this class to avoid creation of my own which will handle PAIR of values
  Integer result = null;
  if (CACHE.containsKey(entry))
    result = CACHE.get(entry); // looks like we have it
  if (result == null) {
    result = new EditDistance(a, b).calc();
    CACHE.put(entry, result); // cache the result
  }
  return result;
}

代码示例来源:origin: apache/accumulo

/**
 * Lookup the RateLimiter associated with the specified name, or create a new one for that name.
 *
 * @param name
 *          key for the rate limiter
 * @param rateProvider
 *          a function which can be called to get what the current rate for the rate limiter
 *          should be.
 */
public RateLimiter create(String name, RateProvider rateProvider) {
 synchronized (activeLimiters) {
  if (activeLimiters.containsKey(name)) {
   return activeLimiters.get(name);
  } else {
   long initialRate;
   initialRate = rateProvider.getDesiredRate();
   SharedRateLimiter limiter = new SharedRateLimiter(name, rateProvider, initialRate);
   activeLimiters.put(name, limiter);
   return limiter;
  }
 }
}

相关文章