Lookups.fixed(...) now returns special lookup implementations for the cases that an empty list of object is passed (Lookups.EMPTY) or a single-item is passed (Lookups.singleton()) as an argument
1.1 --- a/openide.util/src/org/openide/util/lookup/Lookups.java Thu Jul 16 17:26:11 2009 -0400
1.2 +++ b/openide.util/src/org/openide/util/lookup/Lookups.java Wed Jul 22 15:06:37 2009 +0200
1.3 @@ -1,7 +1,7 @@
1.4 /*
1.5 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
1.6 *
1.7 - * Copyright 1997-2008 Sun Microsystems, Inc. All rights reserved.
1.8 + * Copyright 1997-2009 Sun Microsystems, Inc. All rights reserved.
1.9 *
1.10 * The contents of this file are subject to the terms of either the GNU
1.11 * General Public License Version 2 only ("GPL") or the Common
1.12 @@ -24,7 +24,7 @@
1.13 * Contributor(s):
1.14 *
1.15 * The Original Software is NetBeans. The Initial Developer of the Original
1.16 - * Software is Sun Microsystems, Inc. Portions Copyright 1997-2008 Sun
1.17 + * Software is Sun Microsystems, Inc. Portions Copyright 1997-2009 Sun
1.18 * Microsystems, Inc. All Rights Reserved.
1.19 *
1.20 * If you wish your version of this file to be governed by only the CDDL
1.21 @@ -92,6 +92,14 @@
1.22 throw new NullPointerException();
1.23 }
1.24
1.25 + if (objectsToLookup.length == 0) {
1.26 + return Lookup.EMPTY;
1.27 + }
1.28 +
1.29 + if (objectsToLookup.length == 1) {
1.30 + return singleton(objectsToLookup[0]);
1.31 + }
1.32 +
1.33 return new SimpleLookup(Arrays.asList(objectsToLookup));
1.34 }
1.35
2.1 --- a/openide.util/test/unit/src/org/openide/util/lookup/SimpleLookupTest.java Thu Jul 16 17:26:11 2009 -0400
2.2 +++ b/openide.util/test/unit/src/org/openide/util/lookup/SimpleLookupTest.java Wed Jul 22 15:06:37 2009 +0200
2.3 @@ -1,7 +1,7 @@
2.4 /*
2.5 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
2.6 *
2.7 - * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
2.8 + * Copyright 1997-2009 Sun Microsystems, Inc. All rights reserved.
2.9 *
2.10 * The contents of this file are subject to the terms of either the GNU
2.11 * General Public License Version 2 only ("GPL") or the Common
2.12 @@ -24,7 +24,7 @@
2.13 * Contributor(s):
2.14 *
2.15 * The Original Software is NetBeans. The Initial Developer of the Original
2.16 - * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
2.17 + * Software is Sun Microsystems, Inc. Portions Copyright 1997-2009 Sun
2.18 * Microsystems, Inc. All Rights Reserved.
2.19 *
2.20 * If you wish your version of this file to be governed by only the CDDL
2.21 @@ -59,6 +59,10 @@
2.22 super(testName);
2.23 }
2.24
2.25 + public void testEmptyLookup() {
2.26 + assertSize("Lookup.EMPTY should be small", 8, Lookup.EMPTY);
2.27 + }
2.28 +
2.29 /**
2.30 * Simple tests testing singleton lookup.
2.31 */
2.32 @@ -77,6 +81,18 @@
2.33 assertNotNull(p2.lookup(java.io.Serializable.class));
2.34 }
2.35
2.36 + public void testEmptyFixed() {
2.37 + Lookup l = Lookups.fixed();
2.38 + assertSize("Lookups.fixed() for empty list of items should be small", 8, l);
2.39 + assertSame(Lookup.EMPTY, l);
2.40 + }
2.41 +
2.42 + public void testSingleItemFixed() {
2.43 + Object o = new Object();
2.44 + Lookup l = Lookups.fixed(o);
2.45 + assertSize("Lookups.fixed(o) for a single item should be small", 24, l);
2.46 + }
2.47 +
2.48 /**
2.49 * Simple tests testing fixed lookup.
2.50 */