org.openide.util.lookup.InstanceContent Maven / Gradle / Ivy
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.openide.util.lookup;
import org.openide.util.lookup.AbstractLookup.Pair;
import java.lang.ref.WeakReference;
import java.util.*;
import java.util.concurrent.Executor;
import org.openide.util.Lookup.Item;
/** A special content implementation that can be passed to AbstractLookup
* and provides methods for registration of instances and lazy instances.
*
* {@link InstanceContent} ic = new {@link InstanceContent#InstanceContent() InstanceContent()};
* {@link Lookup} lookup = new {@link AbstractLookup#AbstractLookup(org.openide.util.lookup.AbstractLookup.Content) AbstractLookup(ic)};
*
* ic.{@link #add(java.lang.Object) add(new Object ())};
* ic.{@link #add(java.lang.Object) add(new Dimension (...))};
*
* {@link java.awt.Dimension Dimension} theDim = lookup.lookup ({@link java.awt.Dimension Dimension}.class);
*
*
* @author Jaroslav Tulach
*
* @since 1.25
*/
public final class InstanceContent extends AbstractLookup.Content {
/**
* Create a new, empty content.
*/
public InstanceContent() {
}
/** Creates a content associated with an executor to handle dispatch
* of changes.
* @param notifyIn the executor to notify changes in
* @since 7.16
*/
public InstanceContent(Executor notifyIn) {
super(notifyIn);
}
/** Adds an instance to the lookup. If inst
already exists
* in the lookup (equality is determined by object's {@link 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.
*
* @param inst instance
*/
public final void add(Object inst) {
addPair(new SimpleItem
© 2015 - 2024 Weber Informatics LLC | Privacy Policy