org.openide.util.WeakSet类的使用及代码示例

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

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

WeakSet介绍

[英]This class provides storage functionality with Weak-referenced entries and new method putIfAbsent. Set implementation is backed by a hash table. It also provides method resize for changing capacity of internal hash table (can be used for reducing memory occupied by empty set which previously had big number of objects, but they were GCed) Access to set is not thread safe.
[中]此类提供了具有弱引用项和新方法putIfAbsent的存储功能。Set实现由哈希表支持。它还提供了调整内部哈希表容量的方法(可用于减少以前有大量对象的空集占用的内存,但它们是GCed的)。对集合的访问不是线程安全的。

代码示例

代码示例来源:origin: org.netbeans.api/org-openide-filesystems

private Set<InputStream> iStream() {
  if (iStreams == null) {
    iStreams = new WeakSet<InputStream>();
  }
  return iStreams;
}

代码示例来源:origin: org.netbeans.api/org-openide-util

/** Set whether the action will survive a change in focus.
* If <code>false</code>, then the action will be automatically
* disabled (using {@link #setActionPerformer}) when the window
* focus changes.
*
* @param b <code>true</code> to survive focus changes, <code>false</code> to be sensitive to them
*/
public void setSurviveFocusChange(boolean b) {
  synchronized (notSurviving) {
    if (b) {
      notSurviving.remove(getClass());
      surviving.add(getClass());
    } else {
      notSurviving.add(getClass());
      surviving.remove(getClass());
    }
  }
}

代码示例来源:origin: org.netbeans.api/org-openide-util

@Override
public Object clone() {      
  try {
    WeakSet<E> nws = (WeakSet<E>) super.clone();
    // sharing load factor is ok
    // but we can not share maps, recreate them
    nws.m = new SharedKeyWeakHashMap<E, Boolean>(size(), loadFactor);
    nws.s = nws.m.keySet();
    nws.addAll(this);
    return nws;
  } catch (CloneNotSupportedException e) {
    throw new IllegalStateException("base class doesn't support clone", e); // NOI18N
  }
}

代码示例来源:origin: org.netbeans.api/org-openide-awt

public AbstractButton getToolbarPresenter() {
  if(toolbarItems == null) {
    toolbarItems = new WeakSet<AbstractButton>(4);
  }
  AbstractButton b = new DefaultIconToggleButton();
  toolbarItems.add(b);
  b.setSelected(isPreferencesSelected());
  Actions.connect(b, this);
  return b;
}

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

public final void dispose() {
    for (int i = 0; i < instances.length; i++) {
      if (instances[i].size() > 0) {
        if (CndTraceFlags.TRACE_SLICE_DISTIBUTIONS) {
          Object[] arr = instances[i].toArray();
          System.out.println("Key cache " + instances[i].size()); // NOI18N
          Map<Class, Integer> classes = new HashMap<>();
          for (Object o : arr) {
            if (o != null) {
              Integer num = classes.get(o.getClass());
              if (num != null) {
                num = new Integer(num.intValue() + 1);
              } else {
                num = new Integer(1);
              }
              classes.put(o.getClass(), num);
            }
          }
          for (Map.Entry<Class, Integer> e : classes.entrySet()) {
            System.out.println("   " + e.getValue() + " of " + e.getKey().getName()); // NOI18N
          }
        }
        instances[i].clear();
        instances[i].resize(initialCapacity);
      }
    }
  }
}

代码示例来源:origin: org.netbeans.api/org-openide-util

/** If the name is not empty creates new instance of
 * DelegatingErrorManager. Adds it to createdByMe.
 */
public ErrorManager getInstance(String name) {
  if ((name == null) || ("".equals(name))) { // NOI18N
    return this;
  }
  DelegatingErrorManager dem = new DelegatingErrorManager(name);
  synchronized (this) {
    attachNewDelegates(dem, name);
    createdByMe.add(dem);
  }
  return dem;
}

代码示例来源:origin: org.netbeans.api/org-netbeans-modules-vmd-model

private void fireActiveComponentsChanged (Collection<DesignComponent> activeComponents) {
  this.activeComponents = activeComponents;
  Listener[] Listeners;
  synchronized (listeners) {
    Listeners = listeners.toArray (new Listener[listeners.size ()]);
  }
  for (Listener listener : Listeners) {
    if (listener != null)
      listener.activeComponentsChanged (activeComponents);
  }
}

代码示例来源:origin: org.netbeans.api/org-openide-explorer

private InvRadioButton[] getButtons(int count) {
  InvRadioButton[] result = new InvRadioButton[count];
  Iterator<InvRadioButton> i = buttonCache.iterator();
  int idx = 0;
  while (i.hasNext() && (idx < count)) {
    result[idx] = i.next();
    if (result[idx] != null) {
      result[idx].setEnabled(true);
      result[idx].setSelected(false);
      idx++;
    }
  }
  for (; idx < count; idx++) {
    result[idx] = createButton();
    buttonCache.add(result[idx]);
  }
  return result;
}

代码示例来源:origin: org.netbeans.api/org-openide-util

private void writeObject(ObjectOutputStream stream) throws IOException {
  stream.defaultWriteObject();
  stream.writeObject(toArray());
}

代码示例来源:origin: org.netbeans.api/org-netbeans-modules-vmd-properties

WeakSet<Node> nodesToRemove = nodesToRemoveMap.get(ic);
if (nodesToRemove == null) {
  nodesToRemove = new WeakSet<Node>();
  nodesToRemoveMap.put(ic, nodesToRemove);
nodesToRemove.clear();

代码示例来源:origin: net.sf.squirrel-sql.thirdparty-non-maven/openide-loaders

FileSystem fs = fo.getFileSystem();
synchronized (knownFileSystems) {
  if (! knownFileSystems.contains(fs)) {
    fs.addFileChangeListener (new FSListener());
    knownFileSystems.add(fs);

代码示例来源:origin: net.sf.squirrel-sql.thirdpary-non-maven/openide

/** Returns true if this set contains no elements.
*/
public boolean isEmpty() {
  return ((nullCount == 0) &&
      (size() == 0));
}
/** Returns an iterator over the elements in this set. */

代码示例来源:origin: org.netbeans.api/org-openide-util

/** Test whether the action will survive a change in focus.
* By default, it will not.
* @return <code>true</code> if the enabled state of the action survives focus changes
*/
public boolean getSurviveFocusChange() {
  getProperty(null); // force initialization
  return !notSurviving.contains(getClass());
}

代码示例来源:origin: org.netbeans.api/org-openide-util

/**
 * Constructs a new <tt>WeakSet</tt> with the same mappings as the
 * specified map.  The <tt>WeakSet</tt> is created with the default
 * load factor (0.75) and an initial capacity sufficient to hold the
 * mappings in the specified map.
 *
 * @param   s the map whose mappings are to be placed in this map
 * @throws  NullPointerException if the specified map is null
 */
public WeakSet(Collection<? extends E> s) {
  this(Math.max((int) (s.size() / SharedKeyWeakHashMap.DEFAULT_LOAD_FACTOR) + 1, 16),
      SharedKeyWeakHashMap.DEFAULT_LOAD_FACTOR);
  addAll(s);
}

代码示例来源:origin: senbox-org/snap-desktop

/**
 * Executes the action command.
 *
 * @return {@code Boolean.TRUE} on success, {@code Boolean.FALSE} on failure, or {@code null} on cancellation.
 */
public Boolean execute() {
  Boolean status;
  if (!productSet.isEmpty()) {
    // Case 1: If productSet is not empty, action has been constructed with selected products
    status = closeProducts(productSet);
    productSet.clear();
  } else {
    // Case 2: If productSet is empty, default constructor has been called
    status = closeProducts(getSelectedProducts());
  }
  return status;
}

代码示例来源: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: net.sf.squirrel-sql.thirdparty-non-maven/openide

void setDnDActive (boolean state) {
  isDnDActive = state;
  if (setOfTargets != null && !setOfTargets.isEmpty ()) {
    Iterator it = setOfTargets.iterator();
    while (it.hasNext ()) {
      JScrollPane pane = (JScrollPane)it.next ();
      if (pane.isEnabled ()) {
        if (pane instanceof TreeView) {
          ((TreeView)pane).setDropTarget (state);
        } else if (pane instanceof ListView) {
          ((ListView)pane).setDropTarget (state);
        }
      }
    }
  }
}

代码示例来源:origin: org.netbeans.api/org-netbeans-modules-vmd-io

/**
 * Unregisters an listener.
 * @param listener the listener
 */
public void removeActiveViewListener (Listener listener) {
  synchronized (listeners) {
    listeners.remove (listener);
  }
}

代码示例来源:origin: org.netbeans.api/org-openide-util

/**
 * compact set if it is empty by setting new capacity
 * @param newCapacity new capacity
 * @since 8.11
 */
public void resize(int newCapacity){
  if (isEmpty()) {
    m.resize(newCapacity);
  }
}

代码示例来源:origin: net.sf.squirrel-sql.thirdparty-non-maven/openide

void addFutureDropTarget (JScrollPane view) {
    if (setOfTargets == null)
      setOfTargets = new WeakSet ();
    setOfTargets.add (view);
  }
}

相关文章