Codota Logo
WeakList
Code IndexAdd Codota to your IDE (free)

How to use
WeakList
in
rocks.inspectit.agent.java.util

Best Java code snippets using rocks.inspectit.agent.java.util.WeakList (Showing top 13 results out of 315)

  • Add the Codota plugin to your IDE and get smart completions
private void myMethod () {
Gson g =
  • Codota Iconnew Gson()
  • Codota IconGsonBuilder gsonBuilder;gsonBuilder.create()
  • Codota Iconnew GsonBuilder().create()
  • Smart code suggestions by Codota
}
origin: inspectIT/inspectIT

/**
 * Calling this method removes all the garbage collected elements in this list which appear to
 * be null now.<br>
 * TODO: call this method periodically!
 */
public void removeAllNullElements() {
  for (int i = size() - 1; i >= 0; i--) {
    if (get(i) == null) {
      remove(i);
    }
  }
}
origin: inspectIT/inspectIT

/**
 * {@inheritDoc}
 */
@Override
public T get(int index) {
  return getHardReference(refs.get(index));
}
origin: inspectIT/inspectIT

/**
 * {@inheritDoc}
 */
@Override
public boolean contains(Object o) {
  for (int i = 0; i < size(); i++) {
    if (o == get(i)) {
      return true;
    }
  }
  return false;
}
origin: inspectIT/inspectIT

@Test
public void oneElement() {
  Object object = new Object();
  weakList.add(object);
  Object returnValue = weakList.get(0);
  assertThat(returnValue, is(notNullValue()));
  assertThat(returnValue, is(object));
}
origin: inspectIT/inspectIT

@Test
public void clearNoGC() {
  Object objectOne = new Object();
  Object objectTwo = new Object();
  Object objectThree = new Object();
  weakList.add(objectOne);
  weakList.add(objectTwo);
  weakList.add(objectThree);
  weakList.clear();
  assertThat(weakList, is(empty()));
}
origin: inspectIT/inspectIT

@Test(expectedExceptions = { IndexOutOfBoundsException.class })
public void outOfBounds() {
  assertThat(weakList.get(5), is(nullValue()));
}
origin: inspectIT/inspectIT

@Test
public void containsNoGC() {
  Object objectOne = new Object();
  Object objectTwo = new Object();
  weakList.add(objectOne);
  weakList.add(objectTwo);
  assertThat(weakList, hasItem(objectTwo));
}
origin: inspectIT/inspectIT

@BeforeMethod
public void initTestClass() {
  weakList = new WeakList<Object>();
}
origin: inspectIT/inspectIT

/**
 * Returns a list of hard references. Skips all weak references but doesn't delete them if there
 * are any. The list returned (especially the indices) aren't the same as the ones from this
 * list.
 *
 * @return An {@link ArrayList} containing all the hard references of this weak list.
 */
public List<T> getHardReferences() {
  List<T> result = new ArrayList<T>();
  for (int i = 0; i < size(); i++) {
    T tmp = get(i);
    if (null != tmp) {
      result.add(tmp);
    }
  }
  return result;
}
origin: inspectIT/inspectIT

@Test
public void clearWithGC() {
  Object objectOne = new Object();
  Object objectTwo = new Object();
  Object objectThree = new Object();
  weakList.add(objectOne);
  weakList.add(objectTwo);
  weakList.add(objectThree);
  System.gc();
  weakList.clear();
  assertThat(weakList, is(empty()));
}
origin: inspectIT/inspectIT

@Test
public void containsWithGC() {
  Object objectOne = new Object();
  Object objectTwo = new Object();
  weakList.add(objectOne);
  weakList.add(objectTwo);
  System.gc();
  assertThat(weakList, hasItem(objectTwo));
}
origin: inspectIT/inspectIT

/**
 * {@inheritDoc}
 */
@Override
public T remove(int index) {
  return getHardReference(refs.remove(index));
}
origin: inspectIT/inspectIT

/**
 * {@inheritDoc}
 */
@Override
public T set(int index, T element) {
  return getHardReference(refs.set(index, new SoftReference<T>(element)));
}
rocks.inspectit.agent.java.utilWeakList

Javadoc

This list is used to store elements as weak references. Especially useful to save a list of ClassLoader objects in a JEE environment. Objects are added and removed as in any other list, but can turn to become null. Calling #removeAllNullElements() is the only way to get rid of the garbage collected elements. #getHardReferences() returns an ArrayList suppressing all the references in this list which are already removed by the garbage collector.

Most used methods

  • get
  • <init>
  • add
  • clear
  • getHardReference
    Returns the hard reference.
  • remove
  • size

Popular in Java

  • Reading from database using SQL prepared statement
  • findViewById (Activity)
  • notifyDataSetChanged (ArrayAdapter)
  • startActivity (Activity)
  • VirtualMachine (com.sun.tools.attach)
    A Java virtual machine. A VirtualMachine represents a Java virtual machine to which this Java vir
  • BufferedReader (java.io)
    Reads text from a character-input stream, buffering characters so as to provide for the efficient re
  • Permission (java.security)
    Abstract class for representing access to a system resource. All permissions have a name (whose inte
  • Annotation (javassist.bytecode.annotation)
    The annotation structure.An instance of this class is returned bygetAnnotations() in AnnotationsAttr
  • Response (javax.ws.rs.core)
    Defines the contract between a returned instance and the runtime when an application needs to provid
  • DateTimeFormat (org.joda.time.format)
    Factory that creates instances of DateTimeFormatter from patterns and styles. Datetime formatting i
Codota Logo
  • Products

    Search for Java codeSearch for JavaScript codeEnterprise
  • IDE Plugins

    IntelliJ IDEAWebStormAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimAtomGoLandRubyMineEmacsJupyter
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogCodota Academy Plugin user guide Terms of usePrivacy policyJava Code IndexJavascript Code Index
Get Codota for your IDE now