org.openide.util.lookup

## Class InstanceContent

- java.lang.Object
- - org.openide.util.lookup.AbstractLookup.Content
  - - org.openide.util.lookup.InstanceContent

- All Implemented Interfaces:
    Serializable

      public final class InstanceContent
      extends AbstractLookup.Content

  A special content implementation that can be passed to AbstractLookup and provides methods for registration of instances and lazy instances.

       InstanceContent ic = new InstanceContent();
       Lookup lookup = new AbstractLookup(ic);

       ic.add(new Object ());
       ic.add(new Dimension (...));

       Dimension theDim = lookup.lookup (Dimension.class);

  Since:
    1.25
  Author:
    Jaroslav Tulach
  See Also:
    Serialized Form

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `static interface` | `InstanceContent.Convertor<T,R>` Convertor postpones an instantiation of an object.

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `InstanceContent()` Create a new, empty content.
    `InstanceContent(Executor notifyIn)` Creates a content associated with an executor to handle dispatch of changes.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `add(Object inst)` Adds an instance to the lookup.
    `<T,R> void` | `add(T inst, InstanceContent.Convertor<T,R> conv)` Adds a convertible instance into the lookup.
    `void` | `remove(Object inst)` Remove instance.
    `<T,R> void` | `remove(T inst, InstanceContent.Convertor<T,R> conv)` Remove instance added with a convertor.
    `<T,R> void` | `set(Collection<T> col, InstanceContent.Convertor<T,R> conv)` Changes all pairs in the lookup to new values.

    - ### Methods inherited from class org.openide.util.lookup.AbstractLookup.Content

      `addPair, removePair, setPairs`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### InstanceContent

          public InstanceContent()

      Create a new, empty content.

    - #### InstanceContent

          public InstanceContent(Executor notifyIn)

      Creates a content associated with an executor to handle dispatch of changes.
      Parameters:
        `notifyIn` - the executor to notify changes in
      Since:
        7.16

  - ### Method Detail

    - #### add

          public final void add(Object inst)

      Adds an instance to the lookup. If `inst` already exists in the lookup (equality is determined by object's `Object.equals(java.lang.Object)` method) then the new instance replaces the old one in the lookup but listener notifications are not delivered in such case.
      Parameters:
        `inst` - instance

    - #### add

          public final <T,R> void add(T inst,
                                      InstanceContent.Convertor<T,R> conv)

      Adds a convertible instance into the lookup. The `inst` argument is just a key, not the actual value to appear in the lookup. The value will be created on demand, later when it is really needed by calling `convertor` methods.

      This method is useful to delay creation of heavy weight objects. Instead just register lightweight key and a convertor.

      To remove registered object from lookup use `remove(java.lang.Object, org.openide.util.lookup.InstanceContent.Convertor)` with the same arguments.

      Parameters:
        `inst` - instance
        `conv` - convertor which postponing an instantiation, if `conv==null` then the instance is registered directly.

    - #### remove

          public final void remove(Object inst)

      Remove instance.
      Parameters:
        `inst` - instance

    - #### remove

          public final <T,R> void remove(T inst,
                                         InstanceContent.Convertor<T,R> conv)

      Remove instance added with a convertor.
      Parameters:
        `inst` - instance
        `conv` - convertor, if `conv==null` it is same like remove(Object)

    - #### set

          public final <T,R> void set(Collection<T> col,
                                      InstanceContent.Convertor<T,R> conv)

      Changes all pairs in the lookup to new values. Converts collection of instances to collection of pairs.
      Parameters:
        `col` - the collection of (Item) objects
        `conv` - the convertor to use or null

Copyright © 2025 API Design. All Rights Reserved.