|
What this is
Other links
The source code/* * Sun Public License Notice * * The contents of this file are subject to the Sun Public License * Version 1.0 (the "License"). You may not use this file except in * compliance with the License. A copy of the License is available at * http://www.sun.com/ * * The Original Code is NetBeans. The Initial Developer of the Original * Code is Sun Microsystems, Inc. Portions Copyright 1997-2003 Sun * Microsystems, Inc. All Rights Reserved. */ package org.openide.util.lookup; import java.util.Collections; import java.util.Arrays; import org.openide.util.Lookup; /** * A convinience class with couple of static factory methods. It is impossible * to create an instance of this class. * * @author David Strupl * @since 2.21 */ public class Lookups { /** Noone should ever create intstances of this class. */ private Lookups() { } /** * Creates a singleton lookup. It means lookup that contains only * one object specified via the supplied parameter. The lookup will * either return the object or null if the supplied template does * not match the class. If the specified argument is null the method * will end with NullPointerException. * @return Fully initialized lookup object ready to use * @throws NullPointerException if the supplied argument is null * @since 2.21 */ public static Lookup singleton(Object objectToLookup) { if (objectToLookup == null) { throw new NullPointerException(); } // performance of the resulting lookup might be further // improved by providing specialized singleton result (and lookup) // instead of using SimpleResult return new SimpleLookup(Collections.singleton(objectToLookup)); } /** * Creates a lookup that contains an array of objects specified via the * parameter. The resulting lookup is fixed in the following sense: it * contains only fixed set of objects passed in by the array parameter. * Its contents never changes so registering listeners on such lookup * does not have any observable effect (the listeners are never called). * * @return Fully initialized lookup object ready to use * @throws NullPointerException if the supplied argument is null * @since 2.21 * */ public static Lookup fixed(Object[] objectsToLookup) { if (objectsToLookup == null) { throw new NullPointerException(); } return new SimpleLookup(Arrays.asList(objectsToLookup)); } /** * Creates a lookup that contains an array of objects specified via the * parameter. The resulting lookup is fixed in the following sense: it * contains only fixed set of objects passed in by the array parameter. * The objects returned from this lookup are converted to real objects * before they are returned by the lookup. * Its contents never changes so registering listeners on such lookup * does not have any observable effect (the listeners are never called). * * @return Fully initialized lookup object ready to use * @throws NullPointerException if the any of the arguments is null * @since 2.21 * */ public static Lookup fixed(Object[] keys, InstanceContent.Convertor convertor) { if (keys == null) { throw new NullPointerException(); } if (convertor == null) { throw new NullPointerException(); } return new SimpleLookup(Arrays.asList(keys), convertor); } /** Creates a lookup that delegates to another one but that one can change * from time to time. The returned lookup checks every time somebody calls * |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.