org.openide.util.WeakSet.putIfAbsent()方法的使用及代码示例

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

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

WeakSet.putIfAbsent介绍

[英]Put object in this set if equal one is not yet in set. Returns previous set entry if equal object is already in set.

WeakSet<MyClass> set = new WeakSet<MyClass>(); 
... 
MyClass sharedValue = set.putIfAbsent(new MyClass("abc));

[中]如果集合中还没有相等的对象,则将对象放入该集合。如果集合中已存在相等对象,则返回上一个集合项

WeakSet<MyClass> set = new WeakSet<MyClass>(); 
... 
MyClass sharedValue = set.putIfAbsent(new MyClass("abc));

代码示例

代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-cnd-utils

/**
 * returns shared string instance equal to input text.
 * 
 * @param test - interested shared string 
 * @return the shared instance of text
 * @exception NullPointerException If the <code>text</code> parameter
 *                                 is <code>null</code>.
 */
@Override
public final CharSequence getString(CharSequence text) {
  if (text == null) {
    throw new NullPointerException("null string is illegal to share"); // NOI18N
  }
  CharSequence outText = null;
  synchronized (lock) {
    outText = storage.putIfAbsent(text);
  }
  assert (outText != null);
  assert (outText.equals(text));
  return outText;
}

代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-cnd-apt

/**
 * returns shared string instance equal to input text.
 *
 * @param test - interested shared string
 * @return the shared instance of text
 * @exception NullPointerException If the <code>text</code> parameter
 *                                 is <code>null</code>.
 */
@Override
public APTMacro getMacro(APTMacro macro) {
  if (macro == null) {
    throw new NullPointerException("null string is illegal to share"); // NOI18N
  }
  APTMacro outMacro = null;
  synchronized (lock) {
    outMacro = storage.putIfAbsent(macro);
  }
  assert (outMacro != null);
  assert (outMacro.equals(macro));
  return outMacro;
}

代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-cnd-modelimpl

@SuppressWarnings("unchecked")
private <T> CsmUID<T> getSharedUID(CsmUID<T> uid) {
  return (CsmUID<T>) getDelegate(uid).putIfAbsent(uid);
}

代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-cnd-modelimpl

public final Key getShared(Key key) {
  Key out = getDelegate(key).putIfAbsent(key);
  return out;
}

代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-cnd-apt

/**
 * returns shared string instance equal to input text.
 *
 * @param test - interested shared string
 * @return the shared instance of text
 * @exception NullPointerException If the <code>text</code> parameter
 *                                 is <code>null</code>.
 */
@Override
public Holder getHolder(Holder arr) {
  if (arr == null) {
    throw new NullPointerException("null string is illegal to share"); // NOI18N
  }
  Holder outHolder = null;
  synchronized (lock) {
    outHolder = storage.putIfAbsent(arr);
  }
  assert (outHolder != null);
  assert (outHolder.equals(arr));
  return outHolder;
}

代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-dlight-libs-common

private FileObject getInvalidFileObject(CharSequence path) {
  synchronized (this) {
    if (DLightLibsCommonLogger.isDebugMode() && new File(path.toString()).exists()) {
      DLightLibsCommonLogger.getInstance().log(Level.INFO, "Creating an invalid file object for existing file {0}", path);
    }
    FileObject fo = fileObjects.putIfAbsent(new InvalidFileObject(fileSystem, path));
    return fo;
  }
}

代码示例来源:origin: org.netbeans.api/org-netbeans-modules-java-source-base

/**
 * Factory method for creating {@link ElementHandle}.
 * @param element for which the {@link ElementHandle} should be created. Permitted
 * {@link ElementKind}s
 * are: {@link ElementKind#PACKAGE}, {@link ElementKind#CLASS},
 * {@link ElementKind#INTERFACE}, {@link ElementKind#ENUM}, {@link ElementKind#ANNOTATION_TYPE}, {@link ElementKind#METHOD},
 * {@link ElementKind#CONSTRUCTOR}, {@link ElementKind#INSTANCE_INIT}, {@link ElementKind#STATIC_INIT},
 * {@link ElementKind#FIELD}, and {@link ElementKind#ENUM_CONSTANT}.
 * @return a new {@link ElementHandle}
 * @throws IllegalArgumentException if the element is of an unsupported {@link ElementKind}
 */
public static @NonNull <T extends Element> ElementHandle<T> create (@NonNull final T element) throws IllegalArgumentException {
  ElementHandle<T> eh = createImpl(element);
  return (ElementHandle<T>) NORMALIZATION_CACHE.putIfAbsent(eh);
}

相关文章