org.openide.util.lookup

## Class AbstractLookup

- java.lang.Object
- - org.openide.util.Lookup
  - - org.openide.util.lookup.AbstractLookup

- All Implemented Interfaces:
    Serializable

      public class AbstractLookup
      extends Lookup
      implements Serializable

  Implementation of the lookup from OpenAPIs that is based on the introduction of Item. This class should provide the default way of how to store (Class, Object) pairs in the lookups. It offers protected methods for subclasses to register the pairs.

  Serializable since 3.27.

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

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `static class` | `AbstractLookup.Content` A class that can be used by the creator of the `AbstractLookup` to control its content (a kind of Privileged API giving creator of the lookup more rights than subsequent users of the lookup).
    `static class` | `AbstractLookup.Pair<T>` Extension to the default lookup item that offers additional information for the data structures use in AbstractLookup

    - ### Nested classes/interfaces inherited from class org.openide.util.Lookup

      `Lookup.Item<T>, Lookup.Provider, Lookup.Result<T>, Lookup.Template<T>`

  - ### Field Summary

    - ### Fields inherited from class org.openide.util.Lookup

      `EMPTY`

  - ### Constructor Summary

    Constructors
    Modifier | Constructor and Description
    --- | ---
    `protected` | `AbstractLookup()` Default constructor for subclasses that do not need to provide a content
    `` | `AbstractLookup(AbstractLookup.Content content)` Constructor to create this lookup and associate it with given Content.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `protected void` | `addPair(AbstractLookup.Pair<?> pair)` The method to add instance to the lookup with.
    `protected void` | `addPair(AbstractLookup.Pair<?> pair, Executor notifyIn)` The method to add instance to the lookup with.
    `protected void` | `beforeLookup(Lookup.Template<?> template)` Notifies subclasses that a query is about to be processed.
    `protected void` | `initialize()` Method for subclasses to initialize them selves.
    `<T> T` | `lookup(Class<T> clazz)` Look up an object matching a given interface.
    `<T> Lookup.Result<T>` | `lookup(Lookup.Template<T> template)` The general lookup method.
    `<T> Lookup.Item<T>` | `lookupItem(Lookup.Template<T> template)` Look up the first item matching a given template.
    `protected void` | `removePair(AbstractLookup.Pair<?> pair)` Remove instance.
    `protected void` | `removePair(AbstractLookup.Pair<?> pair, Executor notifyIn)` Remove instance.
    `protected void` | `setPairs(Collection<? extends AbstractLookup.Pair> collection)` Changes all pairs in the lookup to new values.
    `protected void` | `setPairs(Collection<? extends AbstractLookup.Pair> collection, Executor notifyIn)` Changes all pairs in the lookup to new values, notifies listeners using provided executor.
    `String` | `toString()` Returns a string representation of the object.

    - ### Methods inherited from class org.openide.util.Lookup

      `getDefault, lookupAll, lookupResult`

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

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

- - ### Constructor Detail

    - #### AbstractLookup

          public AbstractLookup(AbstractLookup.Content content)

      Constructor to create this lookup and associate it with given Content. The content than allows the creator to invoke protected methods which are not accessible for any other user of the lookup.
      Parameters:
        `content` - the content to assciate with
      Since:
        1.25

    - #### AbstractLookup

          protected AbstractLookup()

      Default constructor for subclasses that do not need to provide a content

  - ### Method Detail

    - #### toString

          public String toString()

      Description copied from class: `Object`
      Returns a string representation of the object. In general, the `toString` method returns a string that "textually represents" this object. The result should be a concise but informative representation that is easy for a person to read. It is recommended that all subclasses override this method.

      The `toString` method for class `Object` returns a string consisting of the name of the class of which the object is an instance, the at-sign character ``@`', and the unsigned hexadecimal representation of the hash code of the object. In other words, this method returns a string equal to the value of:

      >      getClass().getName() + '@' + Integer.toHexString(hashCode())

      Overrides:
        `toString` in class `Object`
      Returns:
        a string representation of the object.

    - #### initialize

          protected void initialize()

      Method for subclasses to initialize them selves.

    - #### beforeLookup

          protected void beforeLookup(Lookup.Template<?> template)

      Notifies subclasses that a query is about to be processed.
      Parameters:
        `template` - the template

    - #### addPair

          protected final void addPair(AbstractLookup.Pair<?> pair)

      The method to add instance to the lookup with.
      Parameters:
        `pair` - class/instance pair

    - #### addPair

          protected final void addPair(AbstractLookup.Pair<?> pair,
                                       Executor notifyIn)

      The method to add instance to the lookup with.
      Parameters:
        `pair` - class/instance pair
        `notifyIn` - the executor that will handle the notification of events
      Since:
        7.16

    - #### removePair

          protected final void removePair(AbstractLookup.Pair<?> pair)

      Remove instance.
      Parameters:
        `pair` - class/instance pair

    - #### removePair

          protected final void removePair(AbstractLookup.Pair<?> pair,
                                          Executor notifyIn)

      Remove instance.
      Parameters:
        `pair` - class/instance pair
        `notifyIn` - the executor that will handle the notification of events
      Since:
        7.16

    - #### setPairs

          protected final void setPairs(Collection<? extends AbstractLookup.Pair> collection)

      Changes all pairs in the lookup to new values.
      Parameters:
        `collection` - the collection of (Pair) objects

    - #### setPairs

          protected final void setPairs(Collection<? extends AbstractLookup.Pair> collection,
                                        Executor notifyIn)

      Changes all pairs in the lookup to new values, notifies listeners using provided executor.
      Parameters:
        `collection` - the collection of (Pair) objects
        `notifyIn` - the executor that will handle the notification of events
      Since:
        7.16

    - #### lookup

          public final <T> T lookup(Class<T> clazz)

      Description copied from class: `Lookup`
      Look up an object matching a given interface. This is the simplest method to use. If more than one object matches, the first will be returned. The template class may be a class or interface; the instance is guaranteed to be assignable to it.
      Specified by:
        `lookup` in class `Lookup`
      Parameters:
        `clazz` - class of the object we are searching for
      Returns:
        an object implementing the given class or `null` if no such implementation is found

    - #### lookupItem

          public final <T> Lookup.Item<T> lookupItem(Lookup.Template<T> template)

      Description copied from class: `Lookup`
      Look up the first item matching a given template. Includes not only the instance but other associated information.
      Overrides:
        `lookupItem` in class `Lookup`
      Parameters:
        `template` - the template to check
      Returns:
        a matching item or `null`

    - #### lookup

          public final <T> Lookup.Result<T> lookup(Lookup.Template<T> template)

      Description copied from class: `Lookup`
      The general lookup method. Callers can get list of all instances and classes that match the given `template`, request more info about them in form of `Lookup.Item` and attach a listener to this be notified about changes. The general interface does not specify whether subsequent calls with the same template produce new instance of the `Lookup.Result` or return shared instance. The prefered behaviour however is to return shared one.
      Specified by:
        `lookup` in class `Lookup`
      Parameters:
        `template` - a template describing the services to look for
      Returns:
        an object containing the results

Copyright © 2025 API Design. All Rights Reserved.