CompletionResult
s (ENTITY_REFERENCE_NODEs)
*/
public Enumeration queryEntities(String prefix) {
- QueueEnumeration list = new QueueEnumeration();
+ java.util.LinkedList list = new java.util.LinkedList();
// add well-know build-in entity names
- if ("lt".startsWith(prefix)) list.put(new MyEntityReference("lt"));
- if ("gt".startsWith(prefix)) list.put(new MyEntityReference("gt"));
- if ("apos".startsWith(prefix)) list.put(new MyEntityReference("apos"));
- if ("quot".startsWith(prefix)) list.put(new MyEntityReference("quot"));
- if ("amp".startsWith(prefix)) list.put(new MyEntityReference("amp"));
+ if ("lt".startsWith(prefix)) list.add(new MyEntityReference("lt"));
+ if ("gt".startsWith(prefix)) list.add(new MyEntityReference("gt"));
+ if ("apos".startsWith(prefix)) list.add(new MyEntityReference("apos"));
+ if ("quot".startsWith(prefix)) list.add(new MyEntityReference("quot"));
+ if ("amp".startsWith(prefix)) list.add(new MyEntityReference("amp"));
- return list;
+ return java.util.Collections.enumeration (list);
}
/*
@@ -184,13 +182,13 @@
} else if (ctx.getNodeType() == Node.ELEMENT_NODE) {
ownerElement = (Element) ctx;
}
- if (ownerElement == null) return EmptyEnumeration.EMPTY;
+ if (ownerElement == null) return org.openide.util.Enumerations.EMPTY;
NamedNodeMap existingAttributes = ownerElement.getAttributes();
List possibleAttributes;
String[] typePair = typeOf(ownerElement);
if (typePair == null) {
- return EmptyEnumeration.EMPTY;
+ return org.openide.util.Enumerations.EMPTY;
}
String kind = typePair[0];
String clazz = typePair[1];
@@ -208,7 +206,7 @@
possibleAttributes.add("if");
possibleAttributes.add("unless");
} else if (kind == KIND_SPECIAL && clazz == SPECIAL_DESCRIPTION) {
- return EmptyEnumeration.EMPTY;
+ return org.openide.util.Enumerations.EMPTY;
} else {
// task, type, or data; anyway, we have the defining class
possibleAttributes = new LinkedList();
@@ -232,18 +230,18 @@
String prefix = ctx.getCurrentPrefix();
- QueueEnumeration list = new QueueEnumeration();
+ java.util.LinkedList list = new java.util.LinkedList();
Iterator it = possibleAttributes.iterator();
while ( it.hasNext()) {
String next = (String) it.next();
if (next.startsWith(prefix)) {
if (existingAttributes.getNamedItem(next) == null) {
- list.put(new MyAttr(next));
+ list.add (new MyAttr(next));
}
}
}
- return list;
+ return java.util.Collections.enumeration (list);
}
/**
@@ -258,15 +256,15 @@
public Enumeration queryElements(HintContext ctx) {
Node parent = ((Node)ctx).getParentNode();
- if (parent == null) return EmptyEnumeration.EMPTY;
+ if (parent == null) return org.openide.util.Enumerations.EMPTY;
if (parent.getNodeType() != Node.ELEMENT_NODE) {
- return EmptyEnumeration.EMPTY;
+ return org.openide.util.Enumerations.EMPTY;
}
List elements;
String[] typePair = typeOf((Element)parent);
if (typePair == null) {
- return EmptyEnumeration.EMPTY;
+ return org.openide.util.Enumerations.EMPTY;
}
String kind = typePair[0];
String clazz = typePair[1];
@@ -285,7 +283,7 @@
// targets can have embedded types too, though less common:
elements.addAll(getSortedDefs("type")); // NOI18N
} else if (kind == KIND_SPECIAL && clazz == SPECIAL_DESCRIPTION) {
- return EmptyEnumeration.EMPTY;
+ return org.openide.util.Enumerations.EMPTY;
} else {
// some introspectable class
if (getAntGrammar().isKnown(clazz)) {
@@ -297,16 +295,16 @@
String prefix = ctx.getCurrentPrefix();
- QueueEnumeration list = new QueueEnumeration();
+ java.util.LinkedList list = new java.util.LinkedList ();
Iterator it = elements.iterator();
while ( it.hasNext()) {
String next = (String) it.next();
if (next.startsWith(prefix)) {
- list.put(new MyElement(next));
+ list.add (new MyElement(next));
}
}
- return list;
+ return java.util.Collections.enumeration (list);
}
private static SortedSet/*CompletionResult
s (NOTATION_NODEs)
*/
public Enumeration queryNotations(String prefix) {
- return EmptyEnumeration.EMPTY;
+ return org.openide.util.Enumerations.EMPTY;
}
public Enumeration queryValues(HintContext ctx) {
@@ -332,13 +330,13 @@
} else if (ctx.getNodeType() == Node.ATTRIBUTE_NODE) {
ownerAttr = (Attr)ctx;
} else {
- return EmptyEnumeration.EMPTY;
+ return org.openide.util.Enumerations.EMPTY;
}
Element ownerElement = ownerAttr.getOwnerElement();
String attrName = ownerAttr.getName();
String[] typePair = typeOf(ownerElement);
if (typePair == null) {
- return EmptyEnumeration.EMPTY;
+ return org.openide.util.Enumerations.EMPTY;
}
List/*CompletionResult
s (ENTITY_REFERENCE_NODEs)
*/
public Enumeration queryEntities(String prefix) {
- QueueEnumeration list = new QueueEnumeration();
+ java.util.LinkedList list = new java.util.LinkedList();
// add well-know build-in entity names
- if ("lt".startsWith(prefix)) list.put(new MyEntityReference("lt"));
- if ("gt".startsWith(prefix)) list.put(new MyEntityReference("gt"));
- if ("apos".startsWith(prefix)) list.put(new MyEntityReference("apos"));
- if ("quot".startsWith(prefix)) list.put(new MyEntityReference("quot"));
- if ("amp".startsWith(prefix)) list.put(new MyEntityReference("amp"));
+ if ("lt".startsWith(prefix)) list.add(new MyEntityReference("lt"));
+ if ("gt".startsWith(prefix)) list.add(new MyEntityReference("gt"));
+ if ("apos".startsWith(prefix)) list.add(new MyEntityReference("apos"));
+ if ("quot".startsWith(prefix)) list.add(new MyEntityReference("quot"));
+ if ("amp".startsWith(prefix)) list.add(new MyEntityReference("amp"));
- return list;
+ return java.util.Collections.enumeration (list);
}
/*
@@ -184,13 +182,13 @@
} else if (ctx.getNodeType() == Node.ELEMENT_NODE) {
ownerElement = (Element) ctx;
}
- if (ownerElement == null) return EmptyEnumeration.EMPTY;
+ if (ownerElement == null) return org.openide.util.Enumerations.EMPTY;
NamedNodeMap existingAttributes = ownerElement.getAttributes();
List possibleAttributes;
String[] typePair = typeOf(ownerElement);
if (typePair == null) {
- return EmptyEnumeration.EMPTY;
+ return org.openide.util.Enumerations.EMPTY;
}
String kind = typePair[0];
String clazz = typePair[1];
@@ -208,7 +206,7 @@
possibleAttributes.add("if");
possibleAttributes.add("unless");
} else if (kind == KIND_SPECIAL && clazz == SPECIAL_DESCRIPTION) {
- return EmptyEnumeration.EMPTY;
+ return org.openide.util.Enumerations.EMPTY;
} else {
// task, type, or data; anyway, we have the defining class
possibleAttributes = new LinkedList();
@@ -232,18 +230,18 @@
String prefix = ctx.getCurrentPrefix();
- QueueEnumeration list = new QueueEnumeration();
+ java.util.LinkedList list = new java.util.LinkedList();
Iterator it = possibleAttributes.iterator();
while ( it.hasNext()) {
String next = (String) it.next();
if (next.startsWith(prefix)) {
if (existingAttributes.getNamedItem(next) == null) {
- list.put(new MyAttr(next));
+ list.add (new MyAttr(next));
}
}
}
- return list;
+ return java.util.Collections.enumeration (list);
}
/**
@@ -258,15 +256,15 @@
public Enumeration queryElements(HintContext ctx) {
Node parent = ((Node)ctx).getParentNode();
- if (parent == null) return EmptyEnumeration.EMPTY;
+ if (parent == null) return org.openide.util.Enumerations.EMPTY;
if (parent.getNodeType() != Node.ELEMENT_NODE) {
- return EmptyEnumeration.EMPTY;
+ return org.openide.util.Enumerations.EMPTY;
}
List elements;
String[] typePair = typeOf((Element)parent);
if (typePair == null) {
- return EmptyEnumeration.EMPTY;
+ return org.openide.util.Enumerations.EMPTY;
}
String kind = typePair[0];
String clazz = typePair[1];
@@ -285,7 +283,7 @@
// targets can have embedded types too, though less common:
elements.addAll(getSortedDefs("type")); // NOI18N
} else if (kind == KIND_SPECIAL && clazz == SPECIAL_DESCRIPTION) {
- return EmptyEnumeration.EMPTY;
+ return org.openide.util.Enumerations.EMPTY;
} else {
// some introspectable class
if (getAntGrammar().isKnown(clazz)) {
@@ -297,16 +295,16 @@
String prefix = ctx.getCurrentPrefix();
- QueueEnumeration list = new QueueEnumeration();
+ java.util.LinkedList list = new java.util.LinkedList ();
Iterator it = elements.iterator();
while ( it.hasNext()) {
String next = (String) it.next();
if (next.startsWith(prefix)) {
- list.put(new MyElement(next));
+ list.add (new MyElement(next));
}
}
- return list;
+ return java.util.Collections.enumeration (list);
}
private static SortedSet/*CompletionResult
s (NOTATION_NODEs)
*/
public Enumeration queryNotations(String prefix) {
- return EmptyEnumeration.EMPTY;
+ return org.openide.util.Enumerations.EMPTY;
}
public Enumeration queryValues(HintContext ctx) {
@@ -332,13 +330,13 @@
} else if (ctx.getNodeType() == Node.ATTRIBUTE_NODE) {
ownerAttr = (Attr)ctx;
} else {
- return EmptyEnumeration.EMPTY;
+ return org.openide.util.Enumerations.EMPTY;
}
Element ownerElement = ownerAttr.getOwnerElement();
String attrName = ownerAttr.getName();
String[] typePair = typeOf(ownerElement);
if (typePair == null) {
- return EmptyEnumeration.EMPTY;
+ return org.openide.util.Enumerations.EMPTY;
}
List/*FileSystem
that simplifies the most
* common tasks. Caches information about the filesystem in
@@ -117,10 +116,10 @@
FileObject fo = getAbstractRoot ().find (st);
return fo != null && fo.isFolder() ? fo : null;
} else {
- Enumeration en = new SequenceEnumeration (
- st,
- new SingletonEnumeration (name + '.' + ext)
- );
+ Enumeration en = org.openide.util.Enumerations.concat (
+ st,
+ org.openide.util.Enumerations.singleton (name + '.' + ext)
+ );
// tries to find it (can return null)
return getAbstractRoot ().find (en);
}
@@ -287,45 +286,26 @@
* @return enumeration of currently existing fileobjects.
*/
protected final Enumeration existingFileObjects (FileObject fo) {
- AlterEnumeration en = new AlterEnumeration(existingFileObjectsWeak(fo)) {
- protected Object alter(Object obj) {
- return ((Reference) obj).get();
- }
- };
- FilterEnumeration fen = new FilterEnumeration(en) {
- protected boolean accept(Object obj) {
- return (obj != null && ((FileObject) obj).isValid ());
+ class OnlyValidAndDeep implements org.openide.util.Enumerations.Processor {
+ public Object process (Object obj, Collection toAdd) {
+ if (obj instanceof Reference) {
+ obj = ((Reference) obj).get();
+ }
+ AbstractFileObject file = (AbstractFileObject)obj;
+ if (file != null) {
+ FileObject[] arr = file.subfiles ();
+ // make the array weak
+ for (int i = 0; i < arr.length; i++) {
+ toAdd.add (new WeakReference (arr[i]));
+ }
+ return file.isValid () ? file : null;
+ }
+ return null;
}
- };
- return fen;
- }
-
- /**
- * Return Enumeration of references to FileObjects.
- */
- final Enumeration existingFileObjectsWeak (FileObject fo) {
- QueueEnumeration en = new QueueEnumeration () {
- public void process (Object o) {
- Reference ref = (Reference)o;
- AbstractFileObject file = (AbstractFileObject)ref.get ();
- if (file != null) {
- FileObject[] arr = file.subfiles ();
- Reference[] to = new Reference[arr.length];
-
- // make the array weak
- for (int i = 0; i < arr.length; i++) {
- to[i] = new WeakReference (arr[i]);
- }
-
- // put it into the enumeration
- put (to);
- }
- }
- };
- // weak reference to root
- en.put (new WeakReference (fo));
-
- return en;
+ }
+ return org.openide.util.Enumerations.queue (
+ org.openide.util.Enumerations.singleton (fo), new OnlyValidAndDeep ()
+ );
}
/**
Index: openide/src/org/openide/filesystems/AbstractFolder.java
===================================================================
RCS file: /cvs/openide/src/org/openide/filesystems/AbstractFolder.java,v
retrieving revision 1.76
diff -u -r1.76 AbstractFolder.java
--- openide/src/org/openide/filesystems/AbstractFolder.java 31 May 2004 11:32:40 -0000 1.76
+++ openide/src/org/openide/filesystems/AbstractFolder.java 3 Jun 2004 13:24:39 -0000
@@ -18,11 +18,9 @@
import java.lang.ref.*;
import java.net.URL;
import org.openide.ErrorManager;
+import org.openide.util.Enumerations;
import org.openide.util.NbBundle;
-
-import org.openide.util.enum.*;
-
/** Implementation of the file object that simplyfies common
* tasks with hierarchy of objects for AbstractFileObject and MultiFileObject.
*
@@ -344,16 +342,19 @@
*/
final Enumeration existingSubFiles (boolean rec) {
if (!rec) {
- return new ArrayEnumeration (subfiles ());
+ return Enumerations.array (subfiles ());
} else {
- QueueEnumeration en = new QueueEnumeration () {
- public void process (Object o) {
- AbstractFolder af = (AbstractFolder)o;
- this.put (af.subfiles ());
- }
- };
- en.put (this);
- return en;
+ class P implements org.openide.util.Enumerations.Processor {
+ public Object process(Object o, Collection toAdd) {
+ AbstractFolder af = (AbstractFolder)o;
+ toAdd.addAll (Arrays.asList (af.subfiles ()));
+ return o;
+ }
+ }
+ return Enumerations.queue (
+ Enumerations.singleton (this),
+ new P ()
+ );
}
}
@@ -516,13 +517,11 @@
*/
private final Enumeration listeners () {
if (listeners == null) {
- return EmptyEnumeration.EMPTY;
+ return Enumerations.EMPTY;
} else {
- return new FilterEnumeration (new ArrayEnumeration (listeners.getAllListeners ())) {
- public boolean accept (Object o) {
- return o != null;
- }
- };
+ return Enumerations.removeNulls (
+ Enumerations.array (listeners.getAllListeners ())
+ );
}
}
Index: openide/src/org/openide/filesystems/DefaultAttributes.java
===================================================================
RCS file: /cvs/openide/src/org/openide/filesystems/DefaultAttributes.java,v
retrieving revision 1.74
diff -u -r1.74 DefaultAttributes.java
--- openide/src/org/openide/filesystems/DefaultAttributes.java 31 May 2004 14:54:46 -0000 1.74
+++ openide/src/org/openide/filesystems/DefaultAttributes.java 3 Jun 2004 13:24:40 -0000
@@ -18,7 +18,6 @@
import java.util.*;
import org.openide.util.NbBundle;
-import org.openide.util.enum.EmptyEnumeration;
import org.openide.util.io.NbMarshalledObject;
import org.openide.util.Utilities;
@@ -766,7 +765,7 @@
public Enumeration attrs (String fileName) {
Map m = (Map)get (fileName);
if (m == null) {
- return EmptyEnumeration.EMPTY;
+ return org.openide.util.Enumerations.EMPTY;
} else {
HashSet s = new HashSet (m.keySet ());
return Collections.enumeration (s);
Index: openide/src/org/openide/filesystems/EventControl.java
===================================================================
RCS file: /cvs/openide/src/org/openide/filesystems/EventControl.java,v
retrieving revision 1.11
diff -u -r1.11 EventControl.java
--- openide/src/org/openide/filesystems/EventControl.java 27 Feb 2003 23:40:45 -0000 1.11
+++ openide/src/org/openide/filesystems/EventControl.java 3 Jun 2004 13:24:40 -0000
@@ -14,8 +14,8 @@
package org.openide.filesystems;
import java.io.*;
import java.util.Enumeration;
+import java.util.LinkedList;
-import org.openide.util.enum.QueueEnumeration;
/**
*
* @author rmatous
@@ -36,7 +36,7 @@
private AtomicActionLink currentAtomAction;
/** List of requests */
- private QueueEnumeration requestsQueue;
+ private LinkedList requestsQueue;
/**
* Method that can fire events directly, postpone them, fire them in
@@ -101,7 +101,7 @@
if (priority) priorityRequests++;
if (requests++ == 0) {
- requestsQueue = new QueueEnumeration ();
+ requestsQueue = new LinkedList ();
}
}
@@ -110,7 +110,7 @@
private void exitAtomicAction (boolean priority) {
boolean fireAll = false;
boolean firePriority = false;
- Enumeration reqQueueCopy;
+ LinkedList reqQueueCopy;
synchronized (this) {
currentAtomAction = currentAtomAction.getPreviousLink();
@@ -140,25 +140,25 @@
}
if (firePriority) {
- requestsQueue = new QueueEnumeration ();
- QueueEnumeration newReqQueue = invokeDispatchers (true, reqQueueCopy);
+ requestsQueue = new LinkedList ();
+ LinkedList newReqQueue = invokeDispatchers (true, reqQueueCopy);
synchronized (this) {
- while (requestsQueue != null && requestsQueue.hasMoreElements()) {
- FileSystem.EventDispatcher r = (FileSystem.EventDispatcher)requestsQueue.nextElement();
- newReqQueue.put(r);
+ while (requestsQueue != null && !requestsQueue.isEmpty ()) {
+ FileSystem.EventDispatcher r = (FileSystem.EventDispatcher)requestsQueue.removeFirst ();
+ newReqQueue.add (r);
}
requestsQueue = newReqQueue;
}
}
}
- private QueueEnumeration invokeDispatchers (boolean priority, Enumeration reqQueueCopy) {
- QueueEnumeration newEnum = new QueueEnumeration ();
+ private LinkedList invokeDispatchers (boolean priority, LinkedList reqQueueCopy) {
+ LinkedList newEnum = new LinkedList ();
- while (reqQueueCopy != null && reqQueueCopy.hasMoreElements()) {
- FileSystem.EventDispatcher r = (FileSystem.EventDispatcher)reqQueueCopy.nextElement();
+ while (reqQueueCopy != null && !reqQueueCopy.isEmpty ()) {
+ FileSystem.EventDispatcher r = (FileSystem.EventDispatcher)reqQueueCopy.removeFirst ();
r.dispatch(priority);
- if (priority) newEnum.put (r);
+ if (priority) newEnum.add (r);
}
return newEnum;
}
@@ -173,7 +173,7 @@
if (requestsQueue != null) {
// run later
disp.setAtomicActionLink (currentAtomAction);
- requestsQueue.put (disp);
+ requestsQueue.add (disp);
return true;
}
return false;
Index: openide/src/org/openide/filesystems/FileObject.java
===================================================================
RCS file: /cvs/openide/src/org/openide/filesystems/FileObject.java,v
retrieving revision 1.85
diff -u -r1.85 FileObject.java
--- openide/src/org/openide/filesystems/FileObject.java 7 May 2004 06:00:38 -0000 1.85
+++ openide/src/org/openide/filesystems/FileObject.java 3 Jun 2004 13:24:40 -0000
@@ -18,7 +18,6 @@
import java.util.Enumeration;
import java.util.StringTokenizer;
-import org.openide.util.enum.QueueEnumeration;
import org.openide.util.*;
/** This is the base for all implementations of file objects on a filesystem.
@@ -489,17 +488,20 @@
* @return enumeration of type FileObject
*/
public Enumeration getChildren (final boolean rec) {
- QueueEnumeration en = new QueueEnumeration () {
- /** @param o processes object by adding its children to the queue */
- public void process (Object o) {
- FileObject fo = (FileObject)o;
- if (rec && fo.isFolder ()) {
- put (fo.getChildren ());
- }
- }
- };
- en.put (getChildren ());
- return en;
+ class WithChildren implements org.openide.util.Enumerations.Processor {
+ public Object process (Object obj, java.util.Collection toAdd) {
+ FileObject fo = (FileObject)obj;
+ if (rec && fo.isFolder ()) {
+ toAdd.addAll (java.util.Arrays.asList (fo.getChildren ()));
+ }
+ return fo;
+ }
+ }
+
+ return org.openide.util.Enumerations.queue (
+ org.openide.util.Enumerations.array (getChildren ()),
+ new WithChildren ()
+ );
}
/** Enumerate the subfolders of this folder.
@@ -507,12 +509,9 @@
* @return enumeration of type FileObject
(satisfying {@link #isFolder})
*/
public Enumeration getFolders (boolean rec) {
- return new org.openide.util.enum.FilterEnumeration (getChildren (rec)) {
- /** @return true if the object is of type FileFolder */
- protected boolean accept (Object o) {
- return ((FileObject)o).isFolder ();
- }
- };
+ return org.openide.util.Enumerations.filter (
+ getChildren (rec), new OnlyFolders (true)
+ );
}
/** Enumerate all data files in this folder.
@@ -520,12 +519,9 @@
* @return enumeration of type FileObject
(satisfying {@link #isData})
*/
public Enumeration getData (boolean rec) {
- return new org.openide.util.enum.FilterEnumeration (getChildren (rec)) {
- /** @return true if the object is of type FileFolder */
- protected boolean accept (Object o) {
- return ((FileObject)o).isData ();
- }
- };
+ return org.openide.util.Enumerations.filter (
+ getChildren (rec), new OnlyFolders (false)
+ );
}
/** Retrieve file or folder contained in this folder by name.
@@ -747,11 +743,11 @@
if (this.op == -1) {
this.op = fe.getFile().isFolder() ? FCLSupport.FOLDER_CREATED : FCLSupport.DATA_CREATED;
}
- QueueEnumeration newEnum = new QueueEnumeration();// later lazy
+ java.util.LinkedList newEnum = new java.util.LinkedList ();// later lazy
while (en.hasMoreElements ()) {
FileChangeListener fcl = (FileChangeListener)en.nextElement ();
if (onlyPriority && !isPriorityListener(fcl)) {
- newEnum.put(fcl);
+ newEnum.add (fcl);
continue;
}
@@ -765,7 +761,7 @@
FCLSupport.dispatchEvent(fcl, fe, op);
}
if (onlyPriority)
- this.en = newEnum;
+ this.en = java.util.Collections.enumeration (newEnum);
/** FileEvents are forked in may cases. But FileEvents fired from
* FileSystem and from Repository mustn`t be forked.
@@ -793,5 +789,23 @@
}
}
+
+ /** Filters folders or data files.
+ */
+ private static final class OnlyFolders implements org.openide.util.Enumerations.Processor {
+ private boolean folders;
+
+ public OnlyFolders (boolean folders) {
+ this.folders = folders;
+ }
+ public Object process (Object obj, java.util.Collection coll) {
+ FileObject fo = (FileObject)obj;
+ if (folders) {
+ return fo.isFolder () ? fo : null;
+ } else {
+ return fo.isData () ? fo : null;
+ }
+ }
+ } // end of OnlyFolders
}
Index: openide/src/org/openide/filesystems/FileSystemCapability.java
===================================================================
RCS file: /cvs/openide/src/org/openide/filesystems/FileSystemCapability.java,v
retrieving revision 1.19
diff -u -r1.19 FileSystemCapability.java
--- openide/src/org/openide/filesystems/FileSystemCapability.java 7 Apr 2004 11:59:17 -0000 1.19
+++ openide/src/org/openide/filesystems/FileSystemCapability.java 3 Jun 2004 13:24:40 -0000
@@ -16,8 +16,6 @@
import java.beans.*;
import java.util.*;
-import org.openide.util.enum.FilterEnumeration;
-
/** This class defines the capabilities of a filesystem to
* take part in different operations. Some filesystems are
* not designed to allow compilation on them, some do not want
@@ -84,12 +82,16 @@
* @deprecated Please use the ClassPath API instead.
*/
public Enumeration fileSystems () {
- return new FilterEnumeration (ExternalUtil.getRepository ().fileSystems ()) {
- public boolean accept (Object o) {
- FileSystem fs = (FileSystem)o;
- return fs.getCapability().capableOf(FileSystemCapability.this);
- }
- };
+ class FFS implements org.openide.util.Enumerations.Processor {
+ public Object process (Object obj, Collection ignore) {
+ FileSystem fs = (FileSystem)obj;
+ return fs.getCapability().capableOf(FileSystemCapability.this) ? fs : null;
+ }
+ }
+
+ return org.openide.util.Enumerations.filter (
+ ExternalUtil.getRepository ().fileSystems (), new FFS ()
+ );
}
/** Find a resource in repository, ignoring not capable filesystems.
Index: openide/src/org/openide/filesystems/JarFileSystem.java
===================================================================
RCS file: /cvs/openide/src/org/openide/filesystems/JarFileSystem.java,v
retrieving revision 1.89
diff -u -r1.89 JarFileSystem.java
--- openide/src/org/openide/filesystems/JarFileSystem.java 26 May 2004 12:45:29 -0000 1.89
+++ openide/src/org/openide/filesystems/JarFileSystem.java 3 Jun 2004 13:24:40 -0000
@@ -23,7 +23,6 @@
import org.openide.filesystems.*;
import org.openide.util.*;
-import org.openide.util.enum.*;
/** A virtual filesystem based on a JAR archive.
* For historical reasons many AbstractFileSystem.* methods are implemented
@@ -486,14 +485,17 @@
Attributes attr = getManifest ().getAttributes (name);
if (attr != null) {
- return new AlterEnumeration(Collections.enumeration (attr.keySet ())) {
- public Object alter(Object obj) {
- return obj.toString();
+ class ToString implements org.openide.util.Enumerations.Processor {
+ public Object process (Object obj, Collection ignore) {
+ return obj.toString ();
}
- };
-
+ }
+ return org.openide.util.Enumerations.convert (
+ Collections.enumeration (attr.keySet ()),
+ new ToString ()
+ );
} else {
- return EmptyEnumeration.EMPTY;
+ return org.openide.util.Enumerations.EMPTY;
}
}
Index: openide/src/org/openide/filesystems/MultiFileObject.java
===================================================================
RCS file: /cvs/openide/src/org/openide/filesystems/MultiFileObject.java,v
retrieving revision 1.118
diff -u -r1.118 MultiFileObject.java
--- openide/src/org/openide/filesystems/MultiFileObject.java 29 Mar 2004 16:30:27 -0000 1.118
+++ openide/src/org/openide/filesystems/MultiFileObject.java 3 Jun 2004 13:24:40 -0000
@@ -19,8 +19,6 @@
import java.lang.ref.*;
-import org.openide.util.enum.*;
-
/** Implementation of the file object for multi file system.
*
* @author Jaroslav Tulach,
Index: openide/src/org/openide/filesystems/MultiFileSystem.java
===================================================================
RCS file: /cvs/openide/src/org/openide/filesystems/MultiFileSystem.java,v
retrieving revision 1.44
diff -u -r1.44 MultiFileSystem.java
--- openide/src/org/openide/filesystems/MultiFileSystem.java 16 Mar 2004 15:34:20 -0000 1.44
+++ openide/src/org/openide/filesystems/MultiFileSystem.java 3 Jun 2004 13:24:40 -0000
@@ -17,7 +17,6 @@
import java.util.*;
import org.openide.util.actions.SystemAction;
-import org.openide.util.enum.*;
/** The base for all filesystems that are build above a top of
* other ones. This system expects at most one filesystem it should write
@@ -212,9 +211,9 @@
if (name == null || ext == null) {
en = st;
} else {
- en = new SequenceEnumeration (
+ en = org.openide.util.Enumerations.concat (
st,
- new SingletonEnumeration (name + '.' + ext)
+ org.openide.util.Enumerations.singleton (name + '.' + ext)
);
}
// tries to find it (can return null)
@@ -293,17 +292,19 @@
*/
protected static Enumeration hiddenFiles (FileObject folder, boolean rec) {
Enumeration allFiles = folder.getChildren (rec);
- Enumeration allNull = new AlterEnumeration (allFiles) {
- public Object alter (Object fo) {
- String sf = ((FileObject)fo).getPath();
- if (sf.endsWith (MASK)) {
- return sf.substring (0, sf.length () - MASK.length ());
- } else {
- return null;
- }
- }
- };
- return new FilterEnumeration (allNull);
+
+ class OnlyHidden implements org.openide.util.Enumerations.Processor {
+ public Object process (Object obj, Collection ignore) {
+ String sf = ((FileObject)obj).getPath();
+ if (sf.endsWith (MASK)) {
+ return sf.substring (0, sf.length () - MASK.length ());
+ } else {
+ return null;
+ }
+ }
+ }
+
+ return org.openide.util.Enumerations.filter (allFiles, new OnlyHidden ());
}
//
@@ -471,20 +472,19 @@
* @return enumeration of FileObject
*/
Enumeration delegates (final String name) {
- Enumeration en = new ArrayEnumeration (systems);
-
- Enumeration objsAndNulls = new AlterEnumeration (en) {
- public Object alter (Object o) {
- FileSystem fs = (FileSystem)o;
- if (fs == null) {
- return null;
- } else {
- return findResourceOn (fs, name);
- }
- }
- };
+ Enumeration en = org.openide.util.Enumerations.array (systems);
- return new FilterEnumeration (objsAndNulls);
+ class Resources implements org.openide.util.Enumerations.Processor {
+ public Object process (Object obj, Collection ignore) {
+ FileSystem fs = (FileSystem)obj;
+ if (fs == null) {
+ return null;
+ } else {
+ return findResourceOn (fs, name);
+ }
+ }
+ }
+ return org.openide.util.Enumerations.filter (en, new Resources ());
}
/** Creates a file object that will mask the given file.
Index: openide/src/org/openide/filesystems/XMLFileSystem.java
===================================================================
RCS file: /cvs/openide/src/org/openide/filesystems/XMLFileSystem.java,v
retrieving revision 1.76
diff -u -r1.76 XMLFileSystem.java
--- openide/src/org/openide/filesystems/XMLFileSystem.java 18 May 2004 11:20:28 -0000 1.76
+++ openide/src/org/openide/filesystems/XMLFileSystem.java 3 Jun 2004 13:24:40 -0000
@@ -20,7 +20,6 @@
import java.util.*;
import java.net.*;
-import org.openide.util.enum.EmptyEnumeration;
import org.openide.util.NbBundle;
import org.xml.sax.*;
@@ -746,7 +745,7 @@
FileObjRef ref = (FileObjRef)fs.findReference(name);
if (ref == null && name.length() == 0 && fs.rootRef != null)
ref = fs.rootRef;
- if (ref == null ) return EmptyEnumeration.EMPTY;
+ if (ref == null ) return org.openide.util.Enumerations.EMPTY;
return ref.attributes();
}
@@ -833,7 +832,7 @@
public Enumeration attributes() {
if (foAttrs == null) {
- return EmptyEnumeration.EMPTY;
+ return org.openide.util.Enumerations.EMPTY;
} else {
HashSet s = new HashSet (foAttrs.keySet ());
return Collections.enumeration (s);
Index: openide/src/org/openide/nodes/Children.java
===================================================================
RCS file: /cvs/openide/src/org/openide/nodes/Children.java,v
retrieving revision 1.121
diff -u -r1.121 Children.java
--- openide/src/org/openide/nodes/Children.java 25 Aug 2003 19:24:30 -0000 1.121
+++ openide/src/org/openide/nodes/Children.java 3 Jun 2004 13:24:40 -0000
@@ -19,7 +19,6 @@
import org.openide.util.Mutex;
-import org.openide.util.enum.ArrayEnumeration;
/** Container for array of nodes.
* Can be {@link Node#Node associated} with a node and then
@@ -247,7 +246,7 @@
* @return enumeration of {@link Node}s
*/
public final Enumeration nodes () {
- return new ArrayEnumeration (getNodes ());
+ return org.openide.util.Enumerations.array (getNodes ());
}
/** Find a child node by name.
Index: openide/src/org/openide/nodes/NodeOp.java
===================================================================
RCS file: /cvs/openide/src/org/openide/nodes/NodeOp.java,v
retrieving revision 1.45
diff -u -r1.45 NodeOp.java
--- openide/src/org/openide/nodes/NodeOp.java 7 Jan 2004 13:19:51 -0000 1.45
+++ openide/src/org/openide/nodes/NodeOp.java 3 Jun 2004 13:24:40 -0000
@@ -20,7 +20,6 @@
import javax.swing.JPopupMenu;
import org.openide.ErrorManager;
-import org.openide.util.enum.ArrayEnumeration;
import org.openide.util.Lookup;
/** Utility class for operations on nodes.
@@ -254,7 +253,7 @@
*/
public static Node findPath (Node start, String[] names)
throws NodeNotFoundException {
- return findPath (start, new ArrayEnumeration (names));
+ return findPath (start, org.openide.util.Enumerations.array (names));
}
/** Find the root for a given node.
Index: openide/src/org/openide/util/Enumerations.java
===================================================================
RCS file: openide/src/org/openide/util/Enumerations.java
diff -N openide/src/org/openide/util/Enumerations.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ openide/src/org/openide/util/Enumerations.java 3 Jun 2004 13:24:40 -0000
@@ -0,0 +1,492 @@
+/*
+ * 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-2004 Sun
+ * Microsystems, Inc. All Rights Reserved.
+ */
+package org.openide.util;
+
+import java.util.*;
+import java.util.Enumeration;
+import java.util.Map;
+import java.util.Set;
+
+/** Factory methods for various types of java.util.Enumeration. Allows composition
+ * of existing enumerations, filtering their content and/or modifying them.
+ * All of this is designed to be done in lazy way - e.g. at the latest time
+ * when needed.
+ *
+ * @since JST-PENDING
+ * @author Jaroslav Tulach
+ */
+public final class Enumerations extends Object {
+ /** No instances */
+ private Enumerations () {
+ }
+
+ /** An empty enumeration. Always returns false
when
+ * EMPTY.hasMoreElements()
and throws NoSuchElementException
+ * from the EMPTY.nextElement()
method.
+ */
+ public static final Enumeration EMPTY = Collections.enumeration (Collections.EMPTY_LIST);
+
+ /** Creates enumeration with one element.
+ * @param obj the element to be present in the enumeration.
+ * @return enumeration
+ */
+ public static Enumeration singleton (Object obj) {
+ return Collections.enumeration (Collections.singleton (obj));
+ }
+ /** Concatenates the content of two enumerations into one. Until the
+ * end of en1
is reached its elements are being served.
+ * As soon as the en1
has no more elements, the content
+ * of en2
is being returned.
+ *
+ * @param en1 first enumeration
+ * @param en2 second enumeration
+ * @return enumeration
+ */
+ public static Enumeration concat (Enumeration en1, Enumeration en2) {
+ return new SeqEn (en1, en2);
+ }
+ /** Concatenates the content of many enumerations. The input value
+ * is enumeration of Enumeration elements and the result is composed
+ * all their content. Each of the provided enumeration is fully read
+ * and their content returned before the next enumeration is asked for
+ * their elements.
+ *
+ * @param enumOfEnums Enumeration of Enumeration elements
+ * @return enumeration
+ */
+ public static Enumeration concat (Enumeration enumOfEnums) {
+ return new SeqEn (enumOfEnums);
+ }
+ /** Filters the input enumeration to new one that should contain
+ * each of the provided elements just once. The elements are compared
+ * using their default equals
and hashCode
methods.
+ *
+ * @param en enumeration to filter
+ * @return enumeration without duplicated items
+ */
+ public static Enumeration removeDuplicates (Enumeration en) {
+ class RDupls implements Processor {
+ private Set set = new HashSet ();
+ public Object process (Object o, Collection nothing) {
+ return set.add (o) ? o : null;
+ }
+ }
+ return filter (en, new RDupls ());
+ }
+
+ /** Returns an enumeration that iterates over provided array.
+ * @param arr the array of object
+ * @return enumeration of those objects
+ */
+ public static Enumeration array (Object[] arr) {
+ return Collections.enumeration (Arrays.asList (arr));
+ }
+ /** Removes all null
s from the input enumeration
+ * @param en enumeration that can contain nulls
+ * @return new enumeration without null values
+ */
+ public static Enumeration removeNulls (Enumeration en) {
+ return filter (en, new RNulls());
+ }
+
+ /** For each element of the input enumeration en
asks the
+ * {@link Processor} to provide a replacement. The toAdd
+ * argument of the processor is always null.
+ *
+ * Example to convert any objects into strings: + *
+ * Processor convertToString = new Process () { + * public Object process (Object obj, Collection toAdd) { // toAdd is always null + * return obj.toString (): // converts to string + * } + * }; + * Enumeration strings = Enumerations.convert (elems, convertToString); + *+ * + * @param en enumeration of any objects + * @param processor a callback processor for the elements (its toAdd arguments is always null) + * @return new enumeration where all elements has been processed + */ + public static Enumeration convert (Enumeration en, Processor processor) { + return new AltEn (en, processor); + } + /** Allows to filter out some elements from the input enumeration. Just + * make the + * {@link Processor} return
null
. Please notice the toAdd
+ * argument of the processor is always null
.
+ * + * Example to remove all objects that are not strings: + *
+ * Processor onlyString = new Processor () { + * public Object process (Object obj, Collection alwaysNull) { + * if (obj instanceof String) { + * return obj; + * } else { + * return null; + * } + * } + * }; + * Enumeration strings = Enumerations.filter (elems, onlyString); + *+ * + * @param en enumeration of any objects + * @param filter a callback processor for the elements (its toAdd arguments is always null) + * @return new enumeration which does not include non-processed (returned null from processor) elements + */ + public static Enumeration filter (Enumeration en, Processor filter) { + return new FilEn (en, filter); + } + + /** Support for breadth-first enumerating. Before any element is returned + * for the resulting enumeration it is processed in the {@link Processor} and + * the processor is allowed to modify it and also add additional elements + * at the (current) end of the
queueby calling
toAdd.add
+ * or toAdd.addAll
. No other methods can be called on the
+ * provided toAdd
collection.
+ * + * Example of doing breadth-first walk through a tree: + *
+ * Processor queueSubnodes = new Process () { + * public Object process (Object obj, Collection toAdd) { + * Node n = (Node)obj; + * toAdd.addAll (n.getChildrenList ()); + * return n; + * } + * }; + * Enumeration strings = Enumerations.queue (elems, queueSubnodes); + *+ * + * @param en initial content of the resulting enumeration + * @param filter the processor that is called for each element and can + * add and addAll elements to its toAdd Collection argument + * @return enumeration with the initial and queued content + */ + public static Enumeration queue (Enumeration en, Processor filter) { + QEn q = new QEn (filter); + while (en.hasMoreElements ()) { + q.put (en.nextElement ()); + } + return q; + } + + /** Processor interface that can filter out objects from the enumeration, + * change them or add aditional objects to the end of the current enumeration. + */ + public static interface Processor { + /** @param original the object that is going to be returned from the enumeration right now + * @return a replacement for this object + * @param toAdd can be non-null if one can add new objects at the end of the enumeration + */ + public Object process (Object original, Collection toAdd); + } + + + /** Altering enumeration implementation */ + private static final class AltEn extends Object implements Enumeration { + /** enumeration to filter */ + private Enumeration en; + /** map to alter */ + private Processor process; + + /** + * @param en enumeration to filter + */ + public AltEn (Enumeration en, Processor process) { + this.en = en; + this.process = process; + } + + /** @return true if there is more elements in the enumeration + */ + public boolean hasMoreElements () { + return en.hasMoreElements (); + } + + /** @return next object in the enumeration + * @exception NoSuchElementException can be thrown if there is no next object + * in the enumeration + */ + public Object nextElement () { + return process.process (en.nextElement (), null); + } + } // end of AltEn + + /** Sequence of enumerations */ + private static final class SeqEn extends Object implements Enumeration { + /** enumeration of Enumerations */ + private Enumeration en; + /** current enumeration */ + private Enumeration current; + + /** is {@link #current} up-to-date and has more elements? + * The combination
current == null
and
+ * checked == true means there are no more elements
+ * in this enumeration.
+ */
+ private boolean checked = false;
+
+ /** Constructs new enumeration from already existing. The elements
+ * of en
should be also enumerations. The resulting
+ * enumeration contains elements of such enumerations.
+ *
+ * @param en enumeration of Enumerations that should be sequenced
+ */
+ public SeqEn (Enumeration en) {
+ this.en = en;
+ }
+
+ /** Composes two enumerations into one.
+ * @param first first enumeration
+ * @param second second enumeration
+ */
+ public SeqEn (Enumeration first, Enumeration second) {
+ this (array (new Enumeration[] { first, second }));
+ }
+
+ /** Ensures that current enumeration is set. If there aren't more
+ * elements in the Enumerations, sets the field current
to null.
+ */
+ private void ensureCurrent () {
+ while (current == null || !current.hasMoreElements ()) {
+ if (en.hasMoreElements ()) {
+ current = (Enumeration)en.nextElement ();
+ } else {
+ // no next valid enumeration
+ current = null;
+ return;
+ }
+ }
+ }
+
+ /** @return true if we have more elements */
+ public boolean hasMoreElements () {
+ if( !checked ) {
+ ensureCurrent ();
+ checked = true;
+ }
+ return current != null;
+ }
+
+ /** @return next element
+ * @exception NoSuchElementException if there is no next element
+ */
+ public synchronized Object nextElement () {
+ if( !checked ) {
+ ensureCurrent ();
+ }
+ if( current != null ) {
+ checked = false;
+ return current.nextElement ();
+ } else {
+ checked = true;
+ throw new java.util.NoSuchElementException ();
+ }
+ }
+ } // end of SeqEn
+
+ /** QueueEnumeration
+ */
+ private static class QEn extends Object implements Enumeration {
+ /** item in linked list of Objects */
+ private static final class ListItem {
+ Object object;
+ ListItem next;
+
+ /** @param o the object for this item */
+ ListItem (Object o) {
+ object = o;
+ }
+ }
+ /** next object to be returned */
+ private ListItem next = null;
+ /** last object in the queue */
+ private ListItem last = null;
+ /** processor to use */
+ private Processor processor;
+
+ public QEn (Processor p) {
+ this.processor = p;
+ }
+
+ /** Put adds new object to the end of queue.
+ * @param o the object to add
+ */
+ public synchronized void put (Object o) {
+ if (last != null) {
+ ListItem li = new ListItem (o);
+ last.next = li;
+ last = li;
+ } else {
+ next = last = new ListItem (o);
+ }
+ }
+
+ /** Adds array of objects into the queue.
+ * @param arr array of objects to put into the queue
+ */
+ public synchronized void put (Object[] arr) {
+ for (int i = 0; i < arr.length; i++) {
+ put (arr[i]);
+ }
+ }
+
+ /** Is there any next object?
+ * @return true if there is next object, false otherwise
+ */
+ public boolean hasMoreElements () {
+ return next != null;
+ }
+
+ /** @return next object in enumeration
+ * @exception NoSuchElementException if there is no next object
+ */
+ public synchronized Object nextElement () {
+ if (next == null) {
+ throw new NoSuchElementException ();
+ }
+ Object res = next.object;
+
+ if ((next = next.next) == null) {
+ last = null;
+ };
+ ToAdd toAdd = new ToAdd (this);
+ res = processor.process (res, toAdd);
+ toAdd.finish ();
+ return res;
+ }
+
+ /** Temporary collection that supports only add and addAll operations*/
+ private static final class ToAdd extends Object implements Collection {
+ private QEn q;
+
+ public ToAdd (QEn q) {
+ this.q = q;
+ }
+
+ public void finish () {
+ this.q = null;
+ }
+
+ public boolean add (Object o) {
+ q.put (o);
+ return true;
+ }
+
+ public boolean addAll (Collection c) {
+ q.put (c.toArray ());
+ return true;
+ }
+
+ private String msg () {
+ return "Only add and addAll are implemented"; // NOI18N
+ }
+
+ public void clear () {
+ throw new IllegalStateException (msg ());
+ }
+ public boolean contains (Object o) {
+ throw new IllegalStateException (msg ());
+ }
+ public boolean containsAll (Collection c) {
+ throw new IllegalStateException (msg ());
+ }
+ public boolean isEmpty () {
+ throw new IllegalStateException (msg ());
+ }
+ public Iterator iterator () {
+ throw new IllegalStateException (msg ());
+ }
+ public boolean remove (Object o) {
+ throw new IllegalStateException (msg ());
+ }
+ public boolean removeAll (Collection c) {
+ throw new IllegalStateException (msg ());
+ }
+ public boolean retainAll (Collection c) {
+ throw new IllegalStateException (msg ());
+ }
+ public int size () {
+ throw new IllegalStateException (msg ());
+ }
+ public Object[] toArray () {
+ throw new IllegalStateException (msg ());
+ }
+ public Object[] toArray (Object[] a) {
+ throw new IllegalStateException (msg ());
+ }
+ } // end of ToAdd
+ } // end of QEn
+
+ /** Filtering enumeration */
+ private static final class FilEn extends Object implements Enumeration {
+ /** marker object stating there is no nexte element prepared */
+ private static final Object EMPTY = new Object();
+
+ /** enumeration to filter */
+ private Enumeration en;
+
+ /** element to be returned next time or {@link #EMPTY} if there is
+ * no such element prepared */
+ private Object next = EMPTY;
+
+ /** the set to use as filter */
+ private Processor filter;
+
+ /**
+ * @param en enumeration to filter
+ */
+ public FilEn (Enumeration en, Processor filter) {
+ this.en = en;
+ this.filter = filter;
+ }
+
+ /** @return true if there is more elements in the enumeration
+ */
+ public boolean hasMoreElements () {
+ if (next != EMPTY) {
+ // there is a object already prepared
+ return true;
+ }
+ while (en.hasMoreElements ()) {
+ // read next
+ next = filter.process (en.nextElement (), null);
+ if (next != null) {
+ // if the object is accepted
+ return true;
+ };
+ }
+ next = EMPTY;
+ return false;
+ }
+
+ /** @return next object in the enumeration
+ * @exception NoSuchElementException can be thrown if there is no next object
+ * in the enumeration
+ */
+ public Object nextElement () {
+ if( next == EMPTY && !hasMoreElements() ) {
+ throw new NoSuchElementException ();
+ }
+ Object res = next;
+ next = EMPTY;
+ return res;
+ }
+ } // end of FilEn
+
+ /** Returns true from contains if object is not null */
+ private static class RNulls implements Processor {
+ public Object process (Object original, Collection toAdd) {
+ return original;
+ }
+ } // end of RNulls
+}
Index: openide/src/org/openide/util/NbBundle.java
===================================================================
RCS file: /cvs/openide/src/org/openide/util/NbBundle.java,v
retrieving revision 1.53
diff -u -r1.53 NbBundle.java
--- openide/src/org/openide/util/NbBundle.java 13 Dec 2003 16:01:27 -0000 1.53
+++ openide/src/org/openide/util/NbBundle.java 3 Jun 2004 13:24:40 -0000
@@ -20,7 +20,6 @@
import java.util.jar.Attributes;
import org.openide.ErrorManager;
-import org.openide.util.enum.*;
/** Convenience class permitting easy loading of localized resources of various sorts.
* Extends the functionality of the default Java resource support, and interacts
@@ -561,8 +560,9 @@
return loc;
}
public Enumeration getKeys () {
- return new RemoveDuplicatesEnumeration
- (new SequenceEnumeration (sub1.getKeys (), sub2.getKeys ()));
+ return Enumerations.removeDuplicates (
+ Enumerations.concat (sub1.getKeys (), sub2.getKeys ())
+ );
}
protected Object handleGetObject (String key) throws MissingResourceException {
try {
Index: openide/src/org/openide/util/Queue.java
===================================================================
RCS file: /cvs/openide/src/org/openide/util/Queue.java,v
retrieving revision 1.7
diff -u -r1.7 Queue.java
--- openide/src/org/openide/util/Queue.java 22 Nov 2001 08:57:08 -0000 1.7
+++ openide/src/org/openide/util/Queue.java 3 Jun 2004 13:24:40 -0000
@@ -13,8 +13,6 @@
package org.openide.util;
-import org.openide.util.enum.QueueEnumeration;
-
/** Queue of objects. When there is no object in the queue the process
* is suspended till some arrives.
*
@@ -23,13 +21,13 @@
*/
public class Queue extends Object {
/** Queue enumeration */
- private QueueEnumeration queue = new QueueEnumeration ();
+ private java.util.LinkedList queue = new java.util.LinkedList();
/** Adds new item.
* @param o object to add
*/
public synchronized void put (Object o) {
- queue.put (o);
+ queue.add (o);
notify ();
}
@@ -40,14 +38,15 @@
*/
public synchronized Object get () {
for (;;) {
- try {
- return queue.nextElement ();
- } catch (java.util.NoSuchElementException ex) {
+ if (queue.isEmpty ()) {
try {
wait ();
- } catch (InterruptedException ex2) {
+ } catch (InterruptedException ex) {
}
+ } else {
+ break;
}
}
+ return queue.removeFirst ();
}
}
Index: openide/src/org/openide/util/enum/AlterEnumeration.java
===================================================================
RCS file: /cvs/openide/src/org/openide/util/enum/AlterEnumeration.java,v
retrieving revision 1.8
diff -u -r1.8 AlterEnumeration.java
--- openide/src/org/openide/util/enum/AlterEnumeration.java 3 Dec 2002 14:12:13 -0000 1.8
+++ openide/src/org/openide/util/enum/AlterEnumeration.java 3 Jun 2004 13:24:40 -0000
@@ -15,7 +15,11 @@
import java.util.Enumeration;
-/** Abstract class that takes an enumeration and alter their elements
+/**
+* @deprecated JDK1.5 treats enum as keyword and that is why this class had to be
+ * replaced by {@link org.openide.util.Enumerations#convert}.
+ *
+* Abstract class that takes an enumeration and alter their elements
* to new objects.
* To get this class fully work one must override alter
method.
* Objects in the input and resulting enumeration must not be null
.
Index: openide/src/org/openide/util/enum/ArrayEnumeration.java
===================================================================
RCS file: /cvs/openide/src/org/openide/util/enum/ArrayEnumeration.java,v
retrieving revision 1.7
diff -u -r1.7 ArrayEnumeration.java
--- openide/src/org/openide/util/enum/ArrayEnumeration.java 22 Nov 2001 08:57:09 -0000 1.7
+++ openide/src/org/openide/util/enum/ArrayEnumeration.java 3 Jun 2004 13:24:40 -0000
@@ -16,7 +16,11 @@
import java.util.Enumeration;
import java.util.NoSuchElementException;
-/** The class that presents specifiED (in constructor) array
+/**
+* @deprecated JDK1.5 treats enum as keyword and that is why this class had to be
+* replaced by {@link org.openide.util.Enumerations#array}.
+*
+* The class that presents specifiED (in constructor) array
* as an Enumeration.
*
* @author Ian Formanek
Index: openide/src/org/openide/util/enum/EmptyEnumeration.java
===================================================================
RCS file: /cvs/openide/src/org/openide/util/enum/EmptyEnumeration.java,v
retrieving revision 1.7
diff -u -r1.7 EmptyEnumeration.java
--- openide/src/org/openide/util/enum/EmptyEnumeration.java 22 Nov 2001 08:57:09 -0000 1.7
+++ openide/src/org/openide/util/enum/EmptyEnumeration.java 3 Jun 2004 13:24:40 -0000
@@ -16,7 +16,11 @@
import java.util.Enumeration;
import java.util.NoSuchElementException;
-/** The class that represents empty enumeration.
+/**
+* @deprecated JDK1.5 treats enum as keyword and that is why this class had to be
+* replaced by {@link org.openide.util.Enumerations#EMPTY}.
+*
+* The class that represents empty enumeration.
*
* @author Petr Hamernik
* @version 0.11, May 12, 1998
Index: openide/src/org/openide/util/enum/FilterEnumeration.java
===================================================================
RCS file: /cvs/openide/src/org/openide/util/enum/FilterEnumeration.java,v
retrieving revision 1.9
diff -u -r1.9 FilterEnumeration.java
--- openide/src/org/openide/util/enum/FilterEnumeration.java 31 May 2001 15:08:52 -0000 1.9
+++ openide/src/org/openide/util/enum/FilterEnumeration.java 3 Jun 2004 13:24:40 -0000
@@ -16,7 +16,11 @@
import java.util.Enumeration;
import java.util.NoSuchElementException;
-/** Abstract class that takes an enumeration and filters its elements.
+/**
+* @deprecated JDK1.5 treats enum as keyword and that is why this class had to be
+* replaced by {@link org.openide.util.Enumerations#filter}.
+*
+* Abstract class that takes an enumeration and filters its elements.
* To get this class fully work one must override accept
method.
* Objects in the enumeration must not be null
.
*
Index: openide/src/org/openide/util/enum/QueueEnumeration.java
===================================================================
RCS file: /cvs/openide/src/org/openide/util/enum/QueueEnumeration.java,v
retrieving revision 1.8
diff -u -r1.8 QueueEnumeration.java
--- openide/src/org/openide/util/enum/QueueEnumeration.java 6 Aug 2001 08:23:11 -0000 1.8
+++ openide/src/org/openide/util/enum/QueueEnumeration.java 3 Jun 2004 13:24:40 -0000
@@ -16,7 +16,11 @@
import java.util.Enumeration;
import java.util.NoSuchElementException;
-/** Enumeration that represents a queue. It allows by redefining
+/**
+* @deprecated JDK1.5 treats enum as keyword and that is why this class had to be
+* replaced by {@link org.openide.util.Enumerations#queue}.
+*
+* Enumeration that represents a queue. It allows by redefining
* method process
each outputed object to add other to the end of
* queue of waiting objects by a call to put
.
*
Index: openide/src/org/openide/util/enum/RemoveDuplicatesEnumeration.java
===================================================================
RCS file: /cvs/openide/src/org/openide/util/enum/RemoveDuplicatesEnumeration.java,v
retrieving revision 1.9
diff -u -r1.9 RemoveDuplicatesEnumeration.java
--- openide/src/org/openide/util/enum/RemoveDuplicatesEnumeration.java 31 May 2001 15:08:53 -0000 1.9
+++ openide/src/org/openide/util/enum/RemoveDuplicatesEnumeration.java 3 Jun 2004 13:24:40 -0000
@@ -16,7 +16,10 @@
import java.util.Enumeration;
import java.util.HashSet;
-/** Enumeration that scans through another one and removes duplicates.
+/**
+* @deprecated JDK1.5 treats enum as keyword and that is why this class had to be
+ * replaced by {@link org.openide.util.Enumerations#removeDuplicates}.
+* Enumeration that scans through another one and removes duplicates.
* Two objects are duplicate if one.equals (another)
.
*
* @author Jaroslav Tulach
Index: openide/src/org/openide/util/enum/SequenceEnumeration.java
===================================================================
RCS file: /cvs/openide/src/org/openide/util/enum/SequenceEnumeration.java,v
retrieving revision 1.7
diff -u -r1.7 SequenceEnumeration.java
--- openide/src/org/openide/util/enum/SequenceEnumeration.java 25 May 2001 13:19:02 -0000 1.7
+++ openide/src/org/openide/util/enum/SequenceEnumeration.java 3 Jun 2004 13:24:40 -0000
@@ -15,7 +15,11 @@
import java.util.Enumeration;
-/** Composes more enumerations into one.
+/**
+* @deprecated JDK1.5 treats enum as keyword and that is why this class had to be
+* replaced by {@link org.openide.util.Enumerations#concat}.
+*
+* Composes more enumerations into one.
*
* @author Jaroslav Tulach
* @author Petr Nejedly
Index: openide/src/org/openide/util/enum/SingletonEnumeration.java
===================================================================
RCS file: /cvs/openide/src/org/openide/util/enum/SingletonEnumeration.java,v
retrieving revision 1.7
diff -u -r1.7 SingletonEnumeration.java
--- openide/src/org/openide/util/enum/SingletonEnumeration.java 22 Nov 2001 08:57:09 -0000 1.7
+++ openide/src/org/openide/util/enum/SingletonEnumeration.java 3 Jun 2004 13:24:40 -0000
@@ -16,7 +16,11 @@
import java.util.Enumeration;
import java.util.NoSuchElementException;
-/** The class that encapsulates one object into one element enumeration.
+/**
+* @deprecated JDK1.5 treats enum as keyword and that is why this class had to be
+* replaced by {@link org.openide.util.Enumerations#singleton}.
+*
+* The class that encapsulates one object into one element enumeration.
*
* @author Jaroslav Tulach
* @version 0.10, Apr 10, 1998
Index: openide/src/org/openide/util/lookup/ArrayStorage.java
===================================================================
RCS file: /cvs/openide/src/org/openide/util/lookup/ArrayStorage.java,v
retrieving revision 1.6
diff -u -r1.6 ArrayStorage.java
--- openide/src/org/openide/util/lookup/ArrayStorage.java 10 Nov 2003 09:32:03 -0000 1.6
+++ openide/src/org/openide/util/lookup/ArrayStorage.java 3 Jun 2004 13:24:40 -0000
@@ -19,8 +19,6 @@
import java.util.*;
import org.openide.util.Lookup;
-import org.openide.util.enum.*;
-
/** ArrayStorage of Pairs from AbstractLookup.
* @author Jaroslav Tulach
@@ -207,26 +205,25 @@
* @see #unsorted
*/
public Enumeration lookup (final Class clazz) {
- class CheckEn extends org.openide.util.enum.FilterEnumeration {
- public CheckEn (Enumeration en) {
- super (en);
- }
-
- protected boolean accept (Object o) {
+ class CheckEn implements org.openide.util.Enumerations.Processor {
+ public Object process (Object o, Collection ignore) {
+ boolean ok;
if (o instanceof AbstractLookup.Pair) {
- return clazz == null || ((AbstractLookup.Pair)o).instanceOf(clazz);
+ ok = clazz == null || ((AbstractLookup.Pair)o).instanceOf(clazz);
+ } else {
+ ok = false;
}
- return false;
+ return ok ? o : null;
}
}
if (content instanceof Object[]) {
- Enumeration all = new org.openide.util.enum.ArrayEnumeration (
+ Enumeration all = org.openide.util.Enumerations.array (
(Object[])content
);
- return new CheckEn (all);
+ return org.openide.util.Enumerations.filter (all, new CheckEn ());
} else {
- return org.openide.util.enum.EmptyEnumeration.EMPTY;
+ return org.openide.util.Enumerations.EMPTY;
}
}
Index: openide/src/org/openide/util/lookup/DelegatingStorage.java
===================================================================
RCS file: /cvs/openide/src/org/openide/util/lookup/DelegatingStorage.java,v
retrieving revision 1.5
diff -u -r1.5 DelegatingStorage.java
--- openide/src/org/openide/util/lookup/DelegatingStorage.java 18 Nov 2003 14:51:17 -0000 1.5
+++ openide/src/org/openide/util/lookup/DelegatingStorage.java 3 Jun 2004 13:24:40 -0000
@@ -19,7 +19,6 @@
import java.util.*;
import org.openide.util.Lookup;
-import org.openide.util.enum.*;
/** Storages that can switch between another storages.
Index: openide/src/org/openide/util/lookup/InheritanceTree.java
===================================================================
RCS file: /cvs/openide/src/org/openide/util/lookup/InheritanceTree.java,v
retrieving revision 1.27
diff -u -r1.27 InheritanceTree.java
--- openide/src/org/openide/util/lookup/InheritanceTree.java 24 Mar 2004 15:57:11 -0000 1.27
+++ openide/src/org/openide/util/lookup/InheritanceTree.java 3 Jun 2004 13:24:40 -0000
@@ -21,8 +21,6 @@
import org.openide.util.Lookup;
import org.openide.util.lookup.AbstractLookup.ReferenceIterator;
import org.openide.util.lookup.AbstractLookup.ReferenceToResult;
-import org.openide.util.enum.*;
-
/** A tree to represent classes with inheritance. Description of the
* data structure by Petr Nejedly:
@@ -207,7 +205,7 @@
* pair with smallest index
*/
public static boolean unsorted (Enumeration en) {
- return en instanceof SequenceEnumeration;
+ return en instanceof NeedsSortEnum;
}
/** Prints debug messages.
@@ -435,7 +433,7 @@
}
if (n == null) {
// not for us
- return EmptyEnumeration.EMPTY;
+ return org.openide.util.Enumerations.EMPTY;
} else {
return nodeToEnum(n);
}
@@ -505,39 +503,36 @@
private static Enumeration nodeToEnum(Node n) {
if (n.children == null) {
// create a simple enumeration because we do not have children
- return n.items == null ? EmptyEnumeration.EMPTY : Collections.enumeration (n.items);
+ return n.items == null ? org.openide.util.Enumerations.EMPTY : Collections.enumeration (n.items);
}
// we have found what we need
// now we have to just build the enumeration
- QueueEnumeration en = new QueueEnumeration () {
- protected void process (Object obj) {
+ class DeepAndItems implements org.openide.util.Enumerations.Processor {
+ public Object process (Object obj, Collection toAdd) {
Node n2 = (Node)obj;
if (n2.children != null) {
- Object[] nodes = n2.children.toArray ();
- put (nodes);
+ toAdd.addAll (n2.children);
}
- }
- };
- // initial node is our current one
- en.put (n);
-
- // convert Node into enumeration of Enumerations of Items
- AlterEnumeration alt = new AlterEnumeration (en) {
- protected Object alter (Object obj) {
- Node n2 = (Node)obj;
+
if (n2.items == null || n2.items.isEmpty ()) {
- return EmptyEnumeration.EMPTY;
+ return org.openide.util.Enumerations.EMPTY;
} else {
return Collections.enumeration (n2.items);
}
}
- };
+ }
+
+ Enumeration en = org.openide.util.Enumerations.queue (
+ // initial node is our current one
+ org.openide.util.Enumerations.singleton (n),
+ new DeepAndItems ()
+ );
// create enumeration of Items
- return new SequenceEnumeration (alt);
+ return new NeedsSortEnum (org.openide.util.Enumerations.concat (en));
}
-
+
//
// Methods to work on interfaces
//
@@ -729,7 +724,7 @@
if (items == null && one != null) {
// single item mode
interfaces.put (clazz, one);
- return new SingletonEnumeration (one);
+ return org.openide.util.Enumerations.singleton (one);
} else {
if (items == null) {
items = new ArrayList (2);
@@ -742,7 +737,7 @@
return Collections.enumeration ((Collection)obj);
} else {
// single item mode
- return new SingletonEnumeration (obj);
+ return org.openide.util.Enumerations.singleton (obj);
}
}
}
@@ -988,5 +983,26 @@
}
} // end of R
+
+ /** Just a marker class to be able to do instanceof and find out
+ * that this enumeration is not sorted
+ */
+ private static final class NeedsSortEnum implements Enumeration {
+ private Enumeration en;
+
+ public NeedsSortEnum (Enumeration en) {
+ this.en = en;
+ }
+
+ public boolean hasMoreElements () {
+ return en.hasMoreElements ();
+ }
+
+ public Object nextElement () {
+ return en.nextElement ();
+ }
+
+ } // end of NeedsSortEnum
+
}
Index: openide/test/unit/src/org/openide/util/EnumerationsTest.java
===================================================================
RCS file: openide/test/unit/src/org/openide/util/EnumerationsTest.java
diff -N openide/test/unit/src/org/openide/util/EnumerationsTest.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ openide/test/unit/src/org/openide/util/EnumerationsTest.java 3 Jun 2004 13:24:41 -0000
@@ -0,0 +1,448 @@
+/*
+ * 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;
+
+import java.util.*;
+import java.util.Enumeration;
+import java.util.Map;
+import java.util.Set;
+
+/** This is the base test for new and old enumerations. It contains
+ * factory methods for various kinds of enumerations and set of tests
+ * that use them. Factory methods are overriden in OldEnumerationsTest
+ *
+ * @author Jaroslav Tulach
+ */
+public class EnumerationsTest extends org.netbeans.junit.NbTestCase {
+
+ /** Creates a new instance of EnumerationsTest */
+ public EnumerationsTest (String testName) {
+ super(testName);
+ }
+
+ public static void main(java.lang.String[] args) {
+ junit.textui.TestRunner.run(new org.netbeans.junit.NbTestSuite(EnumerationsTest.class));
+ }
+
+ //
+ // Factory methods
+ //
+
+ protected Enumeration singleton (Object obj) {
+ return Enumerations.singleton (obj);
+ }
+ protected Enumeration concat (Enumeration en1, Enumeration en2) {
+ return Enumerations.concat (en1, en2);
+ }
+ protected Enumeration concat (Enumeration enumOfEnums) {
+ return Enumerations.concat (enumOfEnums);
+ }
+ protected Enumeration removeDuplicates (Enumeration en) {
+ return Enumerations.removeDuplicates (en);
+ }
+ protected Enumeration empty () {
+ return Enumerations.EMPTY;
+ }
+ protected Enumeration array (Object[] arr) {
+ return Enumerations.array (arr);
+ }
+ protected Enumeration convert (Enumeration en, final Map map) {
+ class P implements Enumerations.Processor {
+ public Object process (Object obj, Collection nothing) {
+ return map.get (obj);
+ }
+ }
+
+
+ return Enumerations.convert (en, new P ());
+ }
+ protected Enumeration removeNulls (Enumeration en) {
+ return Enumerations.removeNulls (en);
+ }
+ protected Enumeration filter (Enumeration en, final Set filter) {
+ class P implements Enumerations.Processor {
+ public Object process (Object obj, Collection nothing) {
+ return filter.contains (obj) ? obj : null;
+ }
+ }
+
+ return Enumerations.filter (en, new P ());
+ }
+
+ protected Enumeration filter (Enumeration en, final QueueProcess filter) {
+ class P implements Enumerations.Processor {
+ public Object process (Object obj, Collection nothing) {
+ return filter.process (obj, nothing);
+ }
+ }
+
+ return Enumerations.filter (en, new P ());
+ }
+
+ /**
+ * @param filter the set.contains (...) is called before each object is produced
+ * @return Enumeration
+ */
+ protected Enumeration queue (Collection initContent, final QueueProcess process) {
+ class C implements Enumerations.Processor {
+ public Object process (Object object, Collection toAdd) {
+ return process.process (object, toAdd);
+ }
+ }
+ return Enumerations.queue (
+ Collections.enumeration (initContent),
+ new C ()
+ );
+ }
+
+ /** Processor interface.
+ */
+ public static interface QueueProcess {
+ public Object process (Object object, Collection toAdd);
+ }
+
+ //
+ // The tests
+ //
+
+ public void testEmptyIsEmpty () {
+ Enumeration e = empty ();
+ assertFalse (e.hasMoreElements ());
+ try {
+ e.nextElement ();
+ fail ("No elements");
+ } catch (java.util.NoSuchElementException ex) {
+ // ok
+ }
+ }
+
+ public void testSingleIsSingle () {
+ Enumeration e = singleton (this);
+ assertTrue (e.hasMoreElements ());
+ assertEquals ("Returns me", this, e.nextElement ());
+ assertFalse ("Now it is empty", e.hasMoreElements ());
+ try {
+ e.nextElement ();
+ fail ("No elements");
+ } catch (java.util.NoSuchElementException ex) {
+ // ok
+ }
+ }
+
+ public void testConcatTwoAndArray () {
+ Object[] one = { new Integer (1), new Integer (2), new Integer (3) };
+ Object[] two = { "1", "2", "3" };
+
+ ArrayList list = new ArrayList (Arrays.asList (one));
+ list.addAll (Arrays.asList (two));
+
+ assertEnums (
+ concat (array (one), array (two)),
+ Collections.enumeration (list)
+ );
+ }
+
+ public void testConcatTwoAndArrayAndTakeOnlyStrings () {
+ Object[] one = { new Integer (1), new Integer (2), new Integer (3) };
+ Object[] two = { "1", "2", "3" };
+ Object[] three = { new Long (1) };
+ Object[] four = { "Kuk" };
+
+ ArrayList list = new ArrayList (Arrays.asList (two));
+ list.addAll (Arrays.asList (four));
+
+ Enumeration[] alls = {
+ array (one), array (two), array (three), array (four)
+ };
+
+ assertEnums (
+ filter (concat (array (alls)), new OnlyStrings()),
+ Collections.enumeration (list)
+ );
+ }
+
+ public void testRemoveDuplicates () {
+ Object[] one = { new Integer (1), new Integer (2), new Integer (3) };
+ Object[] two = { "1", "2", "3" };
+ Object[] three = { new Integer (1) };
+ Object[] four = { "2", "3", "4" };
+
+ Enumeration[] alls = {
+ array (one), array (two), array (three), array (four)
+ };
+
+ assertEnums (
+ removeDuplicates (concat (array (alls))),
+ array (new Object[] { new Integer (1), new Integer (2), new Integer (3), "1", "2", "3", "4" })
+ );
+
+ }
+
+ public void testRemoveDuplicatesAndGCWorks () {
+
+ /*** Return { i1, "", "", "", i2 } */
+ class WeakEnum implements Enumeration {
+ public Object i1 = new Integer (1);
+ public Object i2 = new Integer (1);
+
+ private int state;
+
+ public boolean hasMoreElements () {
+ return state < 5;
+ }
+
+ public Object nextElement () {
+ switch (state++) {
+ case 0: return i1;
+ case 1: case 2: case 3: return "";
+ default: return i2;
+ }
+ }
+ }
+
+ WeakEnum weak = new WeakEnum ();
+ Enumeration en = removeDuplicates (weak);
+
+ assertTrue ("Has some elements", en.hasMoreElements ());
+ assertEquals ("And the first one is get", weak.i1, en.nextElement ());
+
+ try {
+ java.lang.ref.WeakReference ref = new java.lang.ref.WeakReference (weak.i1);
+ weak.i1 = null;
+ assertGC ("Try hard to GC the first integer", ref);
+ // does not matter whether it GCs or not
+ } catch (Throwable tw) {
+ // not GCed, but does not matter
+ }
+ assertTrue ("Next object will be string", en.hasMoreElements ());
+ assertEquals ("is empty string", "", en.nextElement ());
+
+ assertFalse ("The second integer is however equal to the original i1 and thus" +
+ " the enum should not be there", en.hasMoreElements ());
+ }
+
+ public void testQueueEnum () {
+ class Pr implements QueueProcess {
+ public Object process (Object o, Collection c) {
+ Integer i = (Integer)o;
+ int plus = i.intValue () + 1;
+ if (plus < 10) {
+ c.add (new Integer (plus));
+ }
+ return i;
+ }
+ }
+ Pr p = new Pr ();
+
+ Enumeration en = queue (
+ Collections.nCopies (1, new Integer (0)), p
+ );
+
+ for (int i = 0; i < 10; i++) {
+ assertTrue ("has next", en.hasMoreElements ());
+ en.nextElement ();
+ }
+
+ assertFalse ("No next element", en.hasMoreElements ());
+ }
+
+ public void testFilteringAlsoDoesConvertions () throws Exception {
+ class Pr implements QueueProcess {
+ public Object process (Object o, Collection ignore) {
+ Integer i = (Integer)o;
+ int plus = i.intValue () + 1;
+ return new Integer (plus);
+ }
+ }
+ Pr p = new Pr ();
+
+ Enumeration onetwo = array (new Object[] { new Integer (1), new Integer (2) });
+ Enumeration twothree = array (new Object[] { new Integer (2), new Integer (3) });
+
+ assertEnums (
+ filter (onetwo, p), twothree
+ );
+ }
+
+
+ private static void assertEnums (Enumeration e1, Enumeration e2) {
+ int indx = 0;
+ while (e1.hasMoreElements () && e2.hasMoreElements ()) {
+ Object i1 = e1.nextElement ();
+ Object i2 = e2.nextElement ();
+ assertEquals (indx++ + "th: ", i1, i2);
+ }
+
+ if (e1.hasMoreElements ()) {
+ fail ("first one contains another element: " + e1.nextElement ());
+ }
+ if (e2.hasMoreElements ()) {
+ fail ("second one contains another element: " + e2.nextElement ());
+ }
+
+ try {
+ e1.nextElement ();
+ fail ("First one should throw exception, but nothing happend");
+ } catch (java.util.NoSuchElementException ex) {
+ // ok
+ }
+
+ try {
+ e2.nextElement ();
+ fail ("Second one should throw exception, but nothing happend");
+ } catch (java.util.NoSuchElementException ex) {
+ // ok
+ }
+ }
+
+ public void testConvertIntegersToStringRemoveNulls () {
+ Object[] garbage = { new Integer (1), "kuk", "hle", new Integer (5) };
+
+ assertEnums (
+ removeNulls (convert (array (garbage), new MapIntegers ())),
+ array (new Object[] { "1", "5" })
+ );
+ }
+
+ /** Filters only strings.
+ */
+ private static final class OnlyStrings implements java.util.Set {
+ public boolean add (Object o) {
+ fail ("Should not be every called");
+ return false;
+ }
+
+ public boolean addAll (Collection c) {
+ fail ("Should not be every called");
+ return false;
+ }
+
+ public void clear () {
+ fail ("Should not be every called");
+ }
+
+ public boolean contains (Object o) {
+ return o instanceof String;
+ }
+
+ public boolean containsAll (Collection c) {
+ fail ("Should not be every called");
+ return false;
+ }
+
+ public boolean isEmpty () {
+ fail ("Should not be every called");
+ return false;
+ }
+
+ public Iterator iterator () {
+ fail ("Should not be every called");
+ return null;
+ }
+
+ public boolean remove (Object o) {
+ fail ("Should not be every called");
+ return false;
+ }
+
+ public boolean removeAll (Collection c) {
+ fail ("Should not be every called");
+ return false;
+ }
+
+ public boolean retainAll (Collection c) {
+ fail ("Should not be every called");
+ return false;
+ }
+
+ public int size () {
+ fail ("Should not be every called");
+ return 1;
+ }
+
+ public Object[] toArray () {
+ fail ("Should not be every called");
+ return null;
+ }
+
+ public Object[] toArray (Object[] a) {
+ fail ("Should not be every called");
+ return null;
+ }
+ }
+
+ /** Filters only strings.
+ */
+ private static final class MapIntegers implements java.util.Map {
+ public boolean containsKey (Object key) {
+ fail ("Should not be every called");
+ return false;
+ }
+
+ public boolean containsValue (Object value) {
+ fail ("Should not be every called");
+ return false;
+ }
+
+ public Set entrySet () {
+ fail ("Should not be every called");
+ return null;
+ }
+
+ public Object get (Object key) {
+ if (key instanceof Integer) {
+ return key.toString ();
+ }
+ return null;
+ }
+
+ public Set keySet () {
+ fail ("Should not be every called");
+ return null;
+ }
+
+ public Object put (Object key, Object value) {
+ fail ("Should not be every called");
+ return null;
+ }
+
+ public void putAll (Map t) {
+ fail ("Should not be every called");
+ }
+
+ public Collection values () {
+ fail ("Should not be every called");
+ return null;
+ }
+
+ public void clear () {
+ fail ("Should not be every called");
+ }
+
+ public boolean isEmpty () {
+ fail ("Should not be every called");
+ return false;
+ }
+
+ public Object remove (Object key) {
+ fail ("Should not be every called");
+ return null;
+ }
+
+ public int size () {
+ fail ("Should not be every called");
+ return 1;
+ }
+
+ }
+}
Index: openide/test/unit/src/org/openide/util/OldEnumerationsTest.java
===================================================================
RCS file: openide/test/unit/src/org/openide/util/OldEnumerationsTest.java
diff -N openide/test/unit/src/org/openide/util/OldEnumerationsTest.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ openide/test/unit/src/org/openide/util/OldEnumerationsTest.java 3 Jun 2004 13:24:41 -0000
@@ -0,0 +1,153 @@
+/*
+ * 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;
+
+import java.util.Collection;
+import org.openide.util.enum.*;
+import org.openide.util.enum.QueueEnumeration;
+
+/** Implement factory methods from EnumerationsTest, shares the same tests
+ * with EnumerationsTest.
+ *
+ * @author Jaroslav Tulach
+ */
+public class OldEnumerationsTest extends EnumerationsTest {
+
+ /** Creates a new instance of EnumerationsTest */
+ public OldEnumerationsTest (String testName) {
+ super(testName);
+ }
+
+ public static void main(java.lang.String[] args) {
+ junit.textui.TestRunner.run(new org.netbeans.junit.NbTestSuite(OldEnumerationsTest.class));
+ }
+
+ protected java.util.Enumeration singleton (Object obj) {
+ return new SingletonEnumeration (obj);
+ }
+
+ protected java.util.Enumeration convert (java.util.Enumeration en, final java.util.Map map) {
+ return new AlterEnumeration (en) {
+ protected Object alter (Object o) {
+ return map.get (o);
+ }
+ };
+ }
+
+ protected java.util.Enumeration removeDuplicates (java.util.Enumeration en) {
+ return new RemoveDuplicatesEnumeration (en);
+ }
+
+ protected java.util.Enumeration removeNulls (java.util.Enumeration en) {
+ return new FilterEnumeration (en);
+ }
+
+ protected java.util.Enumeration concat (java.util.Enumeration en1, java.util.Enumeration en2) {
+ return new SequenceEnumeration (en1, en2);
+ }
+
+ protected java.util.Enumeration array (Object[] arr) {
+ return new ArrayEnumeration (arr);
+ }
+
+ protected java.util.Enumeration filter (java.util.Enumeration en, final java.util.Set filter) {
+ return new FilterEnumeration (en) {
+ protected boolean accept (Object obj) {
+ return filter.contains (obj);
+ }
+ };
+ }
+ protected java.util.Enumeration filter (java.util.Enumeration en, final QueueProcess filter) {
+ en = new AlterEnumeration (en) {
+ public Object alter (Object alter) {
+ return filter.process (alter, null);
+ }
+ };
+
+ return new FilterEnumeration (en);
+ }
+
+ protected java.util.Enumeration concat (java.util.Enumeration enumOfEnums) {
+ return new SequenceEnumeration (enumOfEnums);
+ }
+
+ protected java.util.Enumeration empty () {
+ return new EmptyEnumeration ();
+ }
+
+ protected java.util.Enumeration queue (Collection init, final QueueProcess process) {
+ class QEAdd extends QueueEnumeration implements Collection {
+ protected void process (Object obj) {
+ process.process (obj, this);
+ }
+
+ public boolean add (Object o) {
+ put (o);
+ return true;
+ }
+
+ public boolean addAll (Collection c) {
+ put (c.toArray ());
+ return true;
+ }
+
+ public void clear () {
+ throw new IllegalStateException ("Unsupported");
+ }
+
+ public boolean contains (Object o) {
+ throw new IllegalStateException ("Unsupported");
+ }
+
+ public boolean containsAll (Collection c) {
+ throw new IllegalStateException ("Unsupported");
+ }
+
+ public boolean isEmpty () {
+ throw new IllegalStateException ("Unsupported");
+ }
+
+ public java.util.Iterator iterator () {
+ throw new IllegalStateException ("Unsupported");
+ }
+
+ public boolean remove (Object o) {
+ throw new IllegalStateException ("Unsupported");
+ }
+
+ public boolean removeAll (Collection c) {
+ throw new IllegalStateException ("Unsupported");
+ }
+
+ public boolean retainAll (Collection c) {
+ throw new IllegalStateException ("Unsupported");
+ }
+
+ public int size () {
+ throw new IllegalStateException ("Unsupported");
+ }
+
+ public Object[] toArray () {
+ throw new IllegalStateException ("Unsupported");
+ }
+
+ public Object[] toArray (Object[] a) {
+ throw new IllegalStateException ("Unsupported");
+ }
+ }
+ QEAdd qe = new QEAdd ();
+ qe.put (init.toArray ());
+ return qe;
+ }
+
+}
Index: openide/loaders/src/org/openide/actions/FileSystemAction.java
===================================================================
RCS file: /cvs/openide/loaders/src/org/openide/actions/FileSystemAction.java,v
retrieving revision 1.6
diff -u -r1.6 FileSystemAction.java
--- openide/loaders/src/org/openide/actions/FileSystemAction.java 7 Jan 2004 13:19:48 -0000 1.6
+++ openide/loaders/src/org/openide/actions/FileSystemAction.java 3 Jun 2004 13:24:40 -0000
@@ -33,7 +33,6 @@
import org.openide.nodes.Node;
import org.openide.util.Lookup;
import org.openide.util.NbBundle;
-import org.openide.util.enum.*;
/** Action that presents standard file system-related actions.
@@ -94,10 +93,10 @@
/* At present not allowed to construct actions for selected nodes on more filesystems - its safe behaviour
* If this restriction will be considered as right solution, then code of this method can be simplified
*/
- if (fsSet.size () == 0 || fsSet.size() > 1) return createMenu (EmptyEnumeration.EMPTY, popUp, lookup);
+ if (fsSet.size () == 0 || fsSet.size() > 1) return createMenu (org.openide.util.Enumerations.EMPTY, popUp, lookup);
Iterator entrySetIt = fsSet.entrySet ().iterator();
- QueueEnumeration result = new QueueEnumeration();
+ LinkedList result = new LinkedList ();
while (entrySetIt.hasNext()) {
Map.Entry entry = (Map.Entry)entrySetIt.next();
@@ -121,11 +120,11 @@
}
Set backSet = new OrderedSet();
backSet.addAll(backupList);
- result.put( fs.getActions (backSet) );
+ result.addAll (java.util.Arrays.asList (fs.getActions (backSet)));
}
- return createMenu ( result, popUp, lookup);
+ return createMenu (Collections.enumeration (result), popUp, lookup);
}
return NONE;
}
@@ -136,7 +135,7 @@
* into the menu if enabled and if not duplicated
*/
static JMenuItem[] createMenu (Enumeration en, boolean popUp, Lookup lookup) {
- en = new RemoveDuplicatesEnumeration (en);
+ en = org.openide.util.Enumerations.removeDuplicates (en);
ArrayList items = new ArrayList ();
while (en.hasMoreElements ()) {
@@ -306,7 +305,7 @@
private static final class OrderedSet extends AbstractSet {
/** Queue of collections of elements. */
- private QueueEnumeration queue = new QueueEnumeration();
+ private LinkedList queue = new LinkedList ();
/** Objects stored in this set. */
Object[] objects = null;
@@ -318,20 +317,24 @@
* Adds all of the elements in the specified collection to this collection.
*/
public boolean addAll(Collection coll) {
- queue.put(coll);
+ queue.add (coll);
return true;
}
private Object[] getObjects() {
if (objects == null) {
- AlterEnumeration altered = new AlterEnumeration(queue) {
- public Object alter(Object obj) {
+ class Coll2Enum implements org.openide.util.Enumerations.Processor {
+ public Object process (Object obj, java.util.Collection ignore) {
return Collections.enumeration((Collection) obj);
}
- };
- SequenceEnumeration sequenced = new SequenceEnumeration(altered);
- Enumeration result = new RemoveDuplicatesEnumeration(sequenced);
+ }
+ Enumeration sequenced = org.openide.util.Enumerations.concat (
+ org.openide.util.Enumerations.convert (
+ Collections.enumeration (queue), new Coll2Enum ()
+ )
+ );
+ Enumeration result = org.openide.util.Enumerations.removeDuplicates (sequenced);
ArrayList objectList = new ArrayList();
for (int i = 0; result.hasMoreElements(); i++) {
objectList.add(result.nextElement());
Index: openide/loaders/src/org/openide/loaders/DataFolder.java
===================================================================
RCS file: /cvs/openide/loaders/src/org/openide/loaders/DataFolder.java,v
retrieving revision 1.25
diff -u -r1.25 DataFolder.java
--- openide/loaders/src/org/openide/loaders/DataFolder.java 23 May 2004 03:44:25 -0000 1.25
+++ openide/loaders/src/org/openide/loaders/DataFolder.java 3 Jun 2004 13:24:40 -0000
@@ -35,7 +35,6 @@
import org.openide.util.HelpCtx;
import org.openide.nodes.*;
import org.openide.util.Lookup;
-import org.openide.util.enum.QueueEnumeration;
import org.openide.util.NbBundle;
import org.openide.util.RequestProcessor;
@@ -277,27 +276,22 @@
if (!rec) {
return children();
}
- QueueEnumeration en = new QueueEnumeration () {
- /** @param o processes object by adding its children to the queue */
- public void process (Object o) {
- DataObject dataObj = (DataObject)o;
- if (rec && dataObj instanceof DataFolder) {
- addChildrenToEnum(this, ((DataFolder)dataObj).getChildren());
- }
- }
- };
- addChildrenToEnum(en, getChildren());
- return en;
- }
-
- /** Puts children into QueueEnumeration.
- * @param en the queue enumeration to add children to
- * @param list array of data objects
- */
- static void addChildrenToEnum (QueueEnumeration en, DataObject[] list) {
- for (int i = 0; i < list.length; i++) {
- en.put(list[i]);
+
+ class Processor implements org.openide.util.Enumerations.Processor {
+ /** @param o processes object by adding its children to the queue */
+ public Object process (Object o, Collection toAdd) {
+ DataObject dataObj = (DataObject)o;
+ if (rec && dataObj instanceof DataFolder) {
+ toAdd.addAll (Arrays.asList (((DataFolder)dataObj).getChildren()));
+ }
+ return o;
+ }
}
+ Enumeration en = org.openide.util.Enumerations.queue (
+ org.openide.util.Enumerations.array (getChildren ()),
+ new Processor ()
+ );
+ return en;
}
/** Create node representative for this folder.
Index: openide/loaders/src/org/openide/loaders/DataLoaderPool.java
===================================================================
RCS file: /cvs/openide/loaders/src/org/openide/loaders/DataLoaderPool.java,v
retrieving revision 1.11
diff -u -r1.11 DataLoaderPool.java
--- openide/loaders/src/org/openide/loaders/DataLoaderPool.java 31 May 2004 14:57:53 -0000 1.11
+++ openide/loaders/src/org/openide/loaders/DataLoaderPool.java 3 Jun 2004 13:24:40 -0000
@@ -30,10 +30,7 @@
import org.openide.nodes.Node;
import org.openide.nodes.FilterNode;
import org.openide.modules.ModuleInfo;
-import org.openide.util.enum.ArrayEnumeration;
-import org.openide.util.enum.FilterEnumeration;
-import org.openide.util.enum.SingletonEnumeration;
-import org.openide.util.enum.SequenceEnumeration;
+import org.openide.util.Enumerations;
import org.openide.util.actions.SystemAction;
import org.openide.util.NbBundle;
import org.openide.util.Lookup;
@@ -230,21 +227,21 @@
public final Enumeration allLoaders () {
if (preferredLoader == null) {
// enumeration of systemloaders followed by normal loaders
- return new SequenceEnumeration (
- new ArrayEnumeration ( new Enumeration[] {
- new ArrayEnumeration (getSystemLoaders ()),
+ return Enumerations.concat (
+ Enumerations.array ( new Enumeration[] {
+ Enumerations.array (getSystemLoaders ()),
loaders (),
- new ArrayEnumeration (getDefaultLoaders ())
+ Enumerations.array (getDefaultLoaders ())
} )
);
} else {
// enumeration of preferred loader folowed by systemloaders and normal loaders
- return new SequenceEnumeration (
- new ArrayEnumeration ( new Enumeration[] {
- new SingletonEnumeration (preferredLoader),
- new ArrayEnumeration (getSystemLoaders ()),
+ return Enumerations.concat (
+ Enumerations.array ( new Enumeration[] {
+ Enumerations.singleton (preferredLoader),
+ Enumerations.array (getSystemLoaders ()),
loaders (),
- new ArrayEnumeration (getDefaultLoaders ())
+ Enumerations.array (getDefaultLoaders ())
} )
);
}
@@ -297,14 +294,15 @@
* @return enumeration of {@link DataLoader}s
*/
public final Enumeration producersOf (final Class clazz) {
- return new FilterEnumeration (allLoaders ()) {
- /** Accepts only those loaders that produces superclass of clazz
- */
- public boolean accept (Object o) {
+ class ProducerOf implements Enumerations.Processor {
+ public Object process (Object o, java.util.Collection ignore) {
DataLoader dl = (DataLoader)o;
- return clazz.isAssignableFrom( dl.getRepresentationClass() );
+ return clazz.isAssignableFrom( dl.getRepresentationClass() ) ? o : null;
}
- };
+ }
+
+ // Accepts only those loaders that produces superclass of clazz
+ return Enumerations.filter (allLoaders (), new ProducerOf ());
}
Index: openide/loaders/src/org/openide/loaders/DataObject.java
===================================================================
RCS file: /cvs/openide/loaders/src/org/openide/loaders/DataObject.java,v
retrieving revision 1.17
diff -u -r1.17 DataObject.java
--- openide/loaders/src/org/openide/loaders/DataObject.java 21 Mar 2004 17:15:36 -0000 1.17
+++ openide/loaders/src/org/openide/loaders/DataObject.java 3 Jun 2004 13:24:40 -0000
@@ -31,7 +31,6 @@
import org.openide.filesystems.*;
import org.openide.filesystems.FileSystem; // override java.io.FileSystem
import org.openide.util.*;
-import org.openide.util.enum.*;
import org.openide.nodes.*;
/** Object that represents one or more file objects, with added behavior.
Index: openide/loaders/src/org/openide/loaders/ExtensionList.java
===================================================================
RCS file: /cvs/openide/loaders/src/org/openide/loaders/ExtensionList.java,v
retrieving revision 1.2
diff -u -r1.2 ExtensionList.java
--- openide/loaders/src/org/openide/loaders/ExtensionList.java 2 Apr 2003 09:45:53 -0000 1.2
+++ openide/loaders/src/org/openide/loaders/ExtensionList.java 3 Jun 2004 13:24:40 -0000
@@ -197,7 +197,7 @@
*/
private static Enumeration en (Collection c) {
if (c == null) {
- return org.openide.util.enum.EmptyEnumeration.EMPTY;
+ return org.openide.util.Enumerations.EMPTY;
} else {
return Collections.enumeration(c);
}
Index: openide/loaders/src/org/openide/loaders/FolderOrder.java
===================================================================
RCS file: /cvs/openide/loaders/src/org/openide/loaders/FolderOrder.java,v
retrieving revision 1.3
diff -u -r1.3 FolderOrder.java
--- openide/loaders/src/org/openide/loaders/FolderOrder.java 5 Nov 2003 12:21:46 -0000 1.3
+++ openide/loaders/src/org/openide/loaders/FolderOrder.java 3 Jun 2004 13:24:40 -0000
@@ -20,7 +20,6 @@
import java.util.*;
import org.openide.filesystems.*;
-import org.openide.util.enum.*;
import org.openide.loaders.DataFolder.SortMode;
@@ -94,7 +93,9 @@
order = new HashMap (arr.length * 4 / 3 + 1);
// each object only once
- Enumeration en = new RemoveDuplicatesEnumeration (new ArrayEnumeration (arr));
+ Enumeration en = org.openide.util.Enumerations.removeDuplicates (
+ org.openide.util.Enumerations.array (arr)
+ );
int i = 0;
while (en.hasMoreElements ()) {
Index: openide/loaders/src/org/openide/loaders/InstanceDataObject.java
===================================================================
RCS file: /cvs/openide/loaders/src/org/openide/loaders/InstanceDataObject.java,v
retrieving revision 1.11
diff -u -r1.11 InstanceDataObject.java
--- openide/loaders/src/org/openide/loaders/InstanceDataObject.java 5 May 2004 12:22:32 -0000 1.11
+++ openide/loaders/src/org/openide/loaders/InstanceDataObject.java 3 Jun 2004 13:24:40 -0000
@@ -1602,7 +1602,7 @@
}
public java.util.Enumeration getAttributes() {
- return fo == null? org.openide.util.enum.EmptyEnumeration.EMPTY: fo.getAttributes();
+ return fo == null? org.openide.util.Enumerations.EMPTY: fo.getAttributes();
}
public FileObject[] getChildren() {
Index: openide/masterfs/src/org/netbeans/modules/masterfs/Cache.java
===================================================================
RCS file: /cvs/openide/masterfs/src/org/netbeans/modules/masterfs/Cache.java,v
retrieving revision 1.2
diff -u -r1.2 Cache.java
--- openide/masterfs/src/org/netbeans/modules/masterfs/Cache.java 9 Apr 2004 14:04:59 -0000 1.2
+++ openide/masterfs/src/org/netbeans/modules/masterfs/Cache.java 3 Jun 2004 13:24:40 -0000
@@ -14,7 +14,6 @@
package org.netbeans.modules.masterfs;
import org.openide.filesystems.FileObject;
-import org.openide.util.enum.ArrayEnumeration;
import java.lang.ref.Reference;
import java.lang.ref.SoftReference;
@@ -124,7 +123,7 @@
}
final Object[] array = new Object[arrayList.size()];
arrayList.toArray(array);
- return new ArrayEnumeration(array);
+ return org.openide.util.Enumerations.array (array);
}
void clear() {
Index: openide/masterfs/src/org/netbeans/modules/masterfs/InvalidDummy.java
===================================================================
RCS file: /cvs/openide/masterfs/src/org/netbeans/modules/masterfs/InvalidDummy.java,v
retrieving revision 1.4
diff -u -r1.4 InvalidDummy.java
--- openide/masterfs/src/org/netbeans/modules/masterfs/InvalidDummy.java 28 Apr 2004 13:41:46 -0000 1.4
+++ openide/masterfs/src/org/netbeans/modules/masterfs/InvalidDummy.java 3 Jun 2004 13:24:40 -0000
@@ -14,7 +14,6 @@
package org.netbeans.modules.masterfs;
import org.openide.filesystems.*;
-import org.openide.util.enum.EmptyEnumeration;
import java.io.FileNotFoundException;
import java.io.IOException;
@@ -78,7 +77,7 @@
}
public Enumeration getAttributes() {
- return EmptyEnumeration.EMPTY;
+ return org.openide.util.Enumerations.EMPTY;
}
public void addFileChangeListener(FileChangeListener fcl) {
Index: openide/masterfs/src/org/netbeans/modules/masterfs/MasterFileObject.java
===================================================================
RCS file: /cvs/openide/masterfs/src/org/netbeans/modules/masterfs/MasterFileObject.java,v
retrieving revision 1.21
diff -u -r1.21 MasterFileObject.java
--- openide/masterfs/src/org/netbeans/modules/masterfs/MasterFileObject.java 24 May 2004 15:34:51 -0000 1.21
+++ openide/masterfs/src/org/netbeans/modules/masterfs/MasterFileObject.java 3 Jun 2004 13:24:41 -0000
@@ -18,9 +18,6 @@
import org.openide.ErrorManager;
import org.openide.filesystems.*;
-import org.openide.util.enum.ArrayEnumeration;
-import org.openide.util.enum.FilterEnumeration;
-import org.openide.util.enum.QueueEnumeration;
import org.openide.util.Utilities;
import javax.swing.event.EventListenerList;
@@ -268,39 +265,53 @@
* Implements FileObject.transformChildren(boolean rec)
*/
public Enumeration getChildren(boolean rec) {
+ Enumeration my = org.openide.util.Enumerations.array (this.getChildren());
+
if (rec == false)
- return new ArrayEnumeration(this.getChildren());
+ return my;
- QueueEnumeration en = getChildsEnum();
- en.put(this.getChildren());
- return en;
+ return org.openide.util.Enumerations.queue (
+ my, getChildsEnum ()
+ );
}
/**
* Implements FileObject.getFolders(boolean rec)
*/
public Enumeration getFolders(boolean rec) {
- return new FilterEnumeration(getChildren(rec)) {
- protected boolean accept(final Object o) {
- final FileObject fo = (FileObject) o;
- return fo.isFolder();
- }
- };
+ return org.openide.util.Enumerations.filter (
+ getChildren (rec), new AcceptFolders (true)
+ );
}
-
/**
* Implements FileObject.getData(boolean rec)
*/
public Enumeration getData(boolean rec) {
- return new FilterEnumeration(getChildren(rec)) {
- protected boolean accept(final Object o) {
- final FileObject fo = (FileObject) o;
- return fo.isData();
- }
- };
+ return org.openide.util.Enumerations.filter (
+ getChildren (rec), new AcceptFolders (false)
+ );
}
+ /** Selector from folders and data files.
+ */
+ private final class AcceptFolders implements org.openide.util.Enumerations.Processor {
+ private boolean folders;
+
+ public AcceptFolders (boolean folders) {
+ this.folders = folders;
+ }
+
+ public Object process (Object o, Collection nothing) {
+ final FileObject fo = (FileObject) o;
+ if (folders) {
+ return fo.isFolder() ? fo : null;
+ } else {
+ return fo.isData() ? fo : null;
+ }
+ }
+ } // end of AcceptFolders
+
/**
* Implements abstract FileObject.getFileSystem()
*/
@@ -525,34 +536,43 @@
}
- private QueueEnumeration getChildsEnum() {
- QueueEnumeration en = new QueueEnumeration() {
- public void process(final Object o) {
+ private org.openide.util.Enumerations.Processor getChildsEnum() {
+ return new org.openide.util.Enumerations.Processor () {
+ public Object process(final Object o, Collection toAdd) {
final FileObject fo = (FileObject) o;
if (fo != null)
- put(fo.getChildren());
+ toAdd.addAll (Arrays.asList (fo.getChildren()));
+ return fo;
}
};
- return en;
}
private Enumeration getEnumOfListeners() {
- QueueEnumeration qE = new QueueEnumeration();
Object[] fcls;
synchronized (this) {
- if (listeners == null) return qE;
+ if (listeners == null) {
+ return org.openide.util.Enumerations.EMPTY;
+ }
fcls = listeners.getListenerList();
}
- if (fcls == null || fcls.length == 0) return qE;
- qE.put(fcls);
+ if (fcls == null || fcls.length == 0) {
+ return org.openide.util.Enumerations.EMPTY;
+ }
- return new FilterEnumeration(qE) {
- protected boolean accept(final Object o) {
- return (o instanceof FileChangeListener) ? true : false;
+ class OnlyListeners implements org.openide.util.Enumerations.Processor {
+ public Object process(final Object o, Collection toAdd) {
+ if (o instanceof FileChangeListener) {
+ return o;
+ }
+ return null;
}
- };
+ }
+
+ return org.openide.util.Enumerations.filter (
+ org.openide.util.Enumerations.array (fcls), new OnlyListeners ()
+ );
}
FileSystem getDelegateFileSystem() {
Index: openide/masterfs/src/org/netbeans/modules/masterfs/MountTable.java
===================================================================
RCS file: /cvs/openide/masterfs/src/org/netbeans/modules/masterfs/MountTable.java,v
retrieving revision 1.10
diff -u -r1.10 MountTable.java
--- openide/masterfs/src/org/netbeans/modules/masterfs/MountTable.java 13 May 2004 16:02:44 -0000 1.10
+++ openide/masterfs/src/org/netbeans/modules/masterfs/MountTable.java 3 Jun 2004 13:24:41 -0000
@@ -15,8 +15,6 @@
import org.netbeans.modules.masterfs.providers.MountSupport;
import org.openide.filesystems.*;
-import org.openide.util.enum.FilterEnumeration;
-import org.openide.util.enum.QueueEnumeration;
import java.io.File;
import java.io.IOException;
@@ -136,7 +134,7 @@
* @return enumeration of mounted filesystems
*/
Enumeration geAllFileSystems() {
- final QueueEnumeration qE = new QueueEnumeration();
+ final ArrayList qE = new ArrayList ();
final Collection values = res2fsMap.values();
//SyncSection.getDefault().enterExclusiveSection();
SyncSection.getDefault().enterSection();
@@ -145,14 +143,14 @@
for (Iterator it = values.iterator(); it.hasNext();) {
FileSystem fs = (FileSystem) it.next();
if (fs != null)
- qE.put(fs);
+ qE.add (fs);
}
}
} finally {
//SyncSection.getDefault().finishExclusiveSection();
SyncSection.getDefault().finishSection();
}
- return qE;
+ return Collections.enumeration (qE);
}
/**
@@ -248,33 +246,41 @@
}
private Enumeration getMountEnumeration(final String mountPointPath) {
- return new FilterEnumeration(Cache.getDefault().getAll()) {
- protected boolean accept(final Object o) {
+ class Mnt implements org.openide.util.Enumerations.Processor {
+ public Object process (Object o, Collection ignore) {
final MasterFileObject hfo = (MasterFileObject) o;
String normalizedMountPoint = ResourcePath.getNormalizedPath(mountPointPath);
String normalizedResourcePath = hfo.getResource().getNormalizedPath();
if (normalizedResourcePath.startsWith(normalizedMountPoint) && hfo.isValid()) {
- return true;
+ return o;
}
- return false;
+ return null;
}
- };
+ }
+ return org.openide.util.Enumerations.filter (
+ Cache.getDefault().getAll(),
+ new Mnt ()
+ );
}
private static Enumeration getUnMountEnumeration(final FileSystem fs2Umount) {
- return new FilterEnumeration(Cache.getDefault().getAll()) {
- protected boolean accept(final Object o) {
+ class UnMnt implements org.openide.util.Enumerations.Processor {
+ public Object process (Object o, Collection ignore) {
final MasterFileObject hfo = (MasterFileObject) o;
if (hfo != null && hfo.isValid()) {
FileSystem delgFs = hfo.getDelegateFileSystem();
if (delgFs == fs2Umount)
- return true;
+ return o;
}
- return false;
+ return null;
}
- };
+ }
+ return org.openide.util.Enumerations.filter (
+ Cache.getDefault().getAll(),
+ new UnMnt ()
+ );
}
FileSystem getMountedFileSystem(String resName) {
Index: openide/test/unit/src/org/openide/util/EnumerationsTest.java
===================================================================
RCS file: openide/test/unit/src/org/openide/util/EnumerationsTest.java
diff -N openide/test/unit/src/org/openide/util/EnumerationsTest.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ openide/test/unit/src/org/openide/util/EnumerationsTest.java 3 Jun 2004 13:24:41 -0000
@@ -0,0 +1,448 @@
+/*
+ * 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;
+
+import java.util.*;
+import java.util.Enumeration;
+import java.util.Map;
+import java.util.Set;
+
+/** This is the base test for new and old enumerations. It contains
+ * factory methods for various kinds of enumerations and set of tests
+ * that use them. Factory methods are overriden in OldEnumerationsTest
+ *
+ * @author Jaroslav Tulach
+ */
+public class EnumerationsTest extends org.netbeans.junit.NbTestCase {
+
+ /** Creates a new instance of EnumerationsTest */
+ public EnumerationsTest (String testName) {
+ super(testName);
+ }
+
+ public static void main(java.lang.String[] args) {
+ junit.textui.TestRunner.run(new org.netbeans.junit.NbTestSuite(EnumerationsTest.class));
+ }
+
+ //
+ // Factory methods
+ //
+
+ protected Enumeration singleton (Object obj) {
+ return Enumerations.singleton (obj);
+ }
+ protected Enumeration concat (Enumeration en1, Enumeration en2) {
+ return Enumerations.concat (en1, en2);
+ }
+ protected Enumeration concat (Enumeration enumOfEnums) {
+ return Enumerations.concat (enumOfEnums);
+ }
+ protected Enumeration removeDuplicates (Enumeration en) {
+ return Enumerations.removeDuplicates (en);
+ }
+ protected Enumeration empty () {
+ return Enumerations.EMPTY;
+ }
+ protected Enumeration array (Object[] arr) {
+ return Enumerations.array (arr);
+ }
+ protected Enumeration convert (Enumeration en, final Map map) {
+ class P implements Enumerations.Processor {
+ public Object process (Object obj, Collection nothing) {
+ return map.get (obj);
+ }
+ }
+
+
+ return Enumerations.convert (en, new P ());
+ }
+ protected Enumeration removeNulls (Enumeration en) {
+ return Enumerations.removeNulls (en);
+ }
+ protected Enumeration filter (Enumeration en, final Set filter) {
+ class P implements Enumerations.Processor {
+ public Object process (Object obj, Collection nothing) {
+ return filter.contains (obj) ? obj : null;
+ }
+ }
+
+ return Enumerations.filter (en, new P ());
+ }
+
+ protected Enumeration filter (Enumeration en, final QueueProcess filter) {
+ class P implements Enumerations.Processor {
+ public Object process (Object obj, Collection nothing) {
+ return filter.process (obj, nothing);
+ }
+ }
+
+ return Enumerations.filter (en, new P ());
+ }
+
+ /**
+ * @param filter the set.contains (...) is called before each object is produced
+ * @return Enumeration
+ */
+ protected Enumeration queue (Collection initContent, final QueueProcess process) {
+ class C implements Enumerations.Processor {
+ public Object process (Object object, Collection toAdd) {
+ return process.process (object, toAdd);
+ }
+ }
+ return Enumerations.queue (
+ Collections.enumeration (initContent),
+ new C ()
+ );
+ }
+
+ /** Processor interface.
+ */
+ public static interface QueueProcess {
+ public Object process (Object object, Collection toAdd);
+ }
+
+ //
+ // The tests
+ //
+
+ public void testEmptyIsEmpty () {
+ Enumeration e = empty ();
+ assertFalse (e.hasMoreElements ());
+ try {
+ e.nextElement ();
+ fail ("No elements");
+ } catch (java.util.NoSuchElementException ex) {
+ // ok
+ }
+ }
+
+ public void testSingleIsSingle () {
+ Enumeration e = singleton (this);
+ assertTrue (e.hasMoreElements ());
+ assertEquals ("Returns me", this, e.nextElement ());
+ assertFalse ("Now it is empty", e.hasMoreElements ());
+ try {
+ e.nextElement ();
+ fail ("No elements");
+ } catch (java.util.NoSuchElementException ex) {
+ // ok
+ }
+ }
+
+ public void testConcatTwoAndArray () {
+ Object[] one = { new Integer (1), new Integer (2), new Integer (3) };
+ Object[] two = { "1", "2", "3" };
+
+ ArrayList list = new ArrayList (Arrays.asList (one));
+ list.addAll (Arrays.asList (two));
+
+ assertEnums (
+ concat (array (one), array (two)),
+ Collections.enumeration (list)
+ );
+ }
+
+ public void testConcatTwoAndArrayAndTakeOnlyStrings () {
+ Object[] one = { new Integer (1), new Integer (2), new Integer (3) };
+ Object[] two = { "1", "2", "3" };
+ Object[] three = { new Long (1) };
+ Object[] four = { "Kuk" };
+
+ ArrayList list = new ArrayList (Arrays.asList (two));
+ list.addAll (Arrays.asList (four));
+
+ Enumeration[] alls = {
+ array (one), array (two), array (three), array (four)
+ };
+
+ assertEnums (
+ filter (concat (array (alls)), new OnlyStrings()),
+ Collections.enumeration (list)
+ );
+ }
+
+ public void testRemoveDuplicates () {
+ Object[] one = { new Integer (1), new Integer (2), new Integer (3) };
+ Object[] two = { "1", "2", "3" };
+ Object[] three = { new Integer (1) };
+ Object[] four = { "2", "3", "4" };
+
+ Enumeration[] alls = {
+ array (one), array (two), array (three), array (four)
+ };
+
+ assertEnums (
+ removeDuplicates (concat (array (alls))),
+ array (new Object[] { new Integer (1), new Integer (2), new Integer (3), "1", "2", "3", "4" })
+ );
+
+ }
+
+ public void testRemoveDuplicatesAndGCWorks () {
+
+ /*** Return { i1, "", "", "", i2 } */
+ class WeakEnum implements Enumeration {
+ public Object i1 = new Integer (1);
+ public Object i2 = new Integer (1);
+
+ private int state;
+
+ public boolean hasMoreElements () {
+ return state < 5;
+ }
+
+ public Object nextElement () {
+ switch (state++) {
+ case 0: return i1;
+ case 1: case 2: case 3: return "";
+ default: return i2;
+ }
+ }
+ }
+
+ WeakEnum weak = new WeakEnum ();
+ Enumeration en = removeDuplicates (weak);
+
+ assertTrue ("Has some elements", en.hasMoreElements ());
+ assertEquals ("And the first one is get", weak.i1, en.nextElement ());
+
+ try {
+ java.lang.ref.WeakReference ref = new java.lang.ref.WeakReference (weak.i1);
+ weak.i1 = null;
+ assertGC ("Try hard to GC the first integer", ref);
+ // does not matter whether it GCs or not
+ } catch (Throwable tw) {
+ // not GCed, but does not matter
+ }
+ assertTrue ("Next object will be string", en.hasMoreElements ());
+ assertEquals ("is empty string", "", en.nextElement ());
+
+ assertFalse ("The second integer is however equal to the original i1 and thus" +
+ " the enum should not be there", en.hasMoreElements ());
+ }
+
+ public void testQueueEnum () {
+ class Pr implements QueueProcess {
+ public Object process (Object o, Collection c) {
+ Integer i = (Integer)o;
+ int plus = i.intValue () + 1;
+ if (plus < 10) {
+ c.add (new Integer (plus));
+ }
+ return i;
+ }
+ }
+ Pr p = new Pr ();
+
+ Enumeration en = queue (
+ Collections.nCopies (1, new Integer (0)), p
+ );
+
+ for (int i = 0; i < 10; i++) {
+ assertTrue ("has next", en.hasMoreElements ());
+ en.nextElement ();
+ }
+
+ assertFalse ("No next element", en.hasMoreElements ());
+ }
+
+ public void testFilteringAlsoDoesConvertions () throws Exception {
+ class Pr implements QueueProcess {
+ public Object process (Object o, Collection ignore) {
+ Integer i = (Integer)o;
+ int plus = i.intValue () + 1;
+ return new Integer (plus);
+ }
+ }
+ Pr p = new Pr ();
+
+ Enumeration onetwo = array (new Object[] { new Integer (1), new Integer (2) });
+ Enumeration twothree = array (new Object[] { new Integer (2), new Integer (3) });
+
+ assertEnums (
+ filter (onetwo, p), twothree
+ );
+ }
+
+
+ private static void assertEnums (Enumeration e1, Enumeration e2) {
+ int indx = 0;
+ while (e1.hasMoreElements () && e2.hasMoreElements ()) {
+ Object i1 = e1.nextElement ();
+ Object i2 = e2.nextElement ();
+ assertEquals (indx++ + "th: ", i1, i2);
+ }
+
+ if (e1.hasMoreElements ()) {
+ fail ("first one contains another element: " + e1.nextElement ());
+ }
+ if (e2.hasMoreElements ()) {
+ fail ("second one contains another element: " + e2.nextElement ());
+ }
+
+ try {
+ e1.nextElement ();
+ fail ("First one should throw exception, but nothing happend");
+ } catch (java.util.NoSuchElementException ex) {
+ // ok
+ }
+
+ try {
+ e2.nextElement ();
+ fail ("Second one should throw exception, but nothing happend");
+ } catch (java.util.NoSuchElementException ex) {
+ // ok
+ }
+ }
+
+ public void testConvertIntegersToStringRemoveNulls () {
+ Object[] garbage = { new Integer (1), "kuk", "hle", new Integer (5) };
+
+ assertEnums (
+ removeNulls (convert (array (garbage), new MapIntegers ())),
+ array (new Object[] { "1", "5" })
+ );
+ }
+
+ /** Filters only strings.
+ */
+ private static final class OnlyStrings implements java.util.Set {
+ public boolean add (Object o) {
+ fail ("Should not be every called");
+ return false;
+ }
+
+ public boolean addAll (Collection c) {
+ fail ("Should not be every called");
+ return false;
+ }
+
+ public void clear () {
+ fail ("Should not be every called");
+ }
+
+ public boolean contains (Object o) {
+ return o instanceof String;
+ }
+
+ public boolean containsAll (Collection c) {
+ fail ("Should not be every called");
+ return false;
+ }
+
+ public boolean isEmpty () {
+ fail ("Should not be every called");
+ return false;
+ }
+
+ public Iterator iterator () {
+ fail ("Should not be every called");
+ return null;
+ }
+
+ public boolean remove (Object o) {
+ fail ("Should not be every called");
+ return false;
+ }
+
+ public boolean removeAll (Collection c) {
+ fail ("Should not be every called");
+ return false;
+ }
+
+ public boolean retainAll (Collection c) {
+ fail ("Should not be every called");
+ return false;
+ }
+
+ public int size () {
+ fail ("Should not be every called");
+ return 1;
+ }
+
+ public Object[] toArray () {
+ fail ("Should not be every called");
+ return null;
+ }
+
+ public Object[] toArray (Object[] a) {
+ fail ("Should not be every called");
+ return null;
+ }
+ }
+
+ /** Filters only strings.
+ */
+ private static final class MapIntegers implements java.util.Map {
+ public boolean containsKey (Object key) {
+ fail ("Should not be every called");
+ return false;
+ }
+
+ public boolean containsValue (Object value) {
+ fail ("Should not be every called");
+ return false;
+ }
+
+ public Set entrySet () {
+ fail ("Should not be every called");
+ return null;
+ }
+
+ public Object get (Object key) {
+ if (key instanceof Integer) {
+ return key.toString ();
+ }
+ return null;
+ }
+
+ public Set keySet () {
+ fail ("Should not be every called");
+ return null;
+ }
+
+ public Object put (Object key, Object value) {
+ fail ("Should not be every called");
+ return null;
+ }
+
+ public void putAll (Map t) {
+ fail ("Should not be every called");
+ }
+
+ public Collection values () {
+ fail ("Should not be every called");
+ return null;
+ }
+
+ public void clear () {
+ fail ("Should not be every called");
+ }
+
+ public boolean isEmpty () {
+ fail ("Should not be every called");
+ return false;
+ }
+
+ public Object remove (Object key) {
+ fail ("Should not be every called");
+ return null;
+ }
+
+ public int size () {
+ fail ("Should not be every called");
+ return 1;
+ }
+
+ }
+}
Index: openide/test/unit/src/org/openide/util/OldEnumerationsTest.java
===================================================================
RCS file: openide/test/unit/src/org/openide/util/OldEnumerationsTest.java
diff -N openide/test/unit/src/org/openide/util/OldEnumerationsTest.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ openide/test/unit/src/org/openide/util/OldEnumerationsTest.java 3 Jun 2004 13:24:41 -0000
@@ -0,0 +1,153 @@
+/*
+ * 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;
+
+import java.util.Collection;
+import org.openide.util.enum.*;
+import org.openide.util.enum.QueueEnumeration;
+
+/** Implement factory methods from EnumerationsTest, shares the same tests
+ * with EnumerationsTest.
+ *
+ * @author Jaroslav Tulach
+ */
+public class OldEnumerationsTest extends EnumerationsTest {
+
+ /** Creates a new instance of EnumerationsTest */
+ public OldEnumerationsTest (String testName) {
+ super(testName);
+ }
+
+ public static void main(java.lang.String[] args) {
+ junit.textui.TestRunner.run(new org.netbeans.junit.NbTestSuite(OldEnumerationsTest.class));
+ }
+
+ protected java.util.Enumeration singleton (Object obj) {
+ return new SingletonEnumeration (obj);
+ }
+
+ protected java.util.Enumeration convert (java.util.Enumeration en, final java.util.Map map) {
+ return new AlterEnumeration (en) {
+ protected Object alter (Object o) {
+ return map.get (o);
+ }
+ };
+ }
+
+ protected java.util.Enumeration removeDuplicates (java.util.Enumeration en) {
+ return new RemoveDuplicatesEnumeration (en);
+ }
+
+ protected java.util.Enumeration removeNulls (java.util.Enumeration en) {
+ return new FilterEnumeration (en);
+ }
+
+ protected java.util.Enumeration concat (java.util.Enumeration en1, java.util.Enumeration en2) {
+ return new SequenceEnumeration (en1, en2);
+ }
+
+ protected java.util.Enumeration array (Object[] arr) {
+ return new ArrayEnumeration (arr);
+ }
+
+ protected java.util.Enumeration filter (java.util.Enumeration en, final java.util.Set filter) {
+ return new FilterEnumeration (en) {
+ protected boolean accept (Object obj) {
+ return filter.contains (obj);
+ }
+ };
+ }
+ protected java.util.Enumeration filter (java.util.Enumeration en, final QueueProcess filter) {
+ en = new AlterEnumeration (en) {
+ public Object alter (Object alter) {
+ return filter.process (alter, null);
+ }
+ };
+
+ return new FilterEnumeration (en);
+ }
+
+ protected java.util.Enumeration concat (java.util.Enumeration enumOfEnums) {
+ return new SequenceEnumeration (enumOfEnums);
+ }
+
+ protected java.util.Enumeration empty () {
+ return new EmptyEnumeration ();
+ }
+
+ protected java.util.Enumeration queue (Collection init, final QueueProcess process) {
+ class QEAdd extends QueueEnumeration implements Collection {
+ protected void process (Object obj) {
+ process.process (obj, this);
+ }
+
+ public boolean add (Object o) {
+ put (o);
+ return true;
+ }
+
+ public boolean addAll (Collection c) {
+ put (c.toArray ());
+ return true;
+ }
+
+ public void clear () {
+ throw new IllegalStateException ("Unsupported");
+ }
+
+ public boolean contains (Object o) {
+ throw new IllegalStateException ("Unsupported");
+ }
+
+ public boolean containsAll (Collection c) {
+ throw new IllegalStateException ("Unsupported");
+ }
+
+ public boolean isEmpty () {
+ throw new IllegalStateException ("Unsupported");
+ }
+
+ public java.util.Iterator iterator () {
+ throw new IllegalStateException ("Unsupported");
+ }
+
+ public boolean remove (Object o) {
+ throw new IllegalStateException ("Unsupported");
+ }
+
+ public boolean removeAll (Collection c) {
+ throw new IllegalStateException ("Unsupported");
+ }
+
+ public boolean retainAll (Collection c) {
+ throw new IllegalStateException ("Unsupported");
+ }
+
+ public int size () {
+ throw new IllegalStateException ("Unsupported");
+ }
+
+ public Object[] toArray () {
+ throw new IllegalStateException ("Unsupported");
+ }
+
+ public Object[] toArray (Object[] a) {
+ throw new IllegalStateException ("Unsupported");
+ }
+ }
+ QEAdd qe = new QEAdd ();
+ qe.put (init.toArray ());
+ return qe;
+ }
+
+}
Index: properties/src/org/netbeans/modules/properties/PresentableFileEntry.java
===================================================================
RCS file: /cvs/properties/src/org/netbeans/modules/properties/PresentableFileEntry.java,v
retrieving revision 1.16
diff -u -r1.16 PresentableFileEntry.java
--- properties/src/org/netbeans/modules/properties/PresentableFileEntry.java 14 Nov 2003 14:12:28 -0000 1.16
+++ properties/src/org/netbeans/modules/properties/PresentableFileEntry.java 3 Jun 2004 13:24:41 -0000
@@ -47,7 +47,6 @@
import org.openide.filesystems.FileObject;
import org.openide.filesystems.FileSystem;
import org.openide.util.*;
-import org.openide.util.enum.*;
import org.openide.util.actions.SystemAction;
import org.openide.util.actions.Presenter;
import org.openide.nodes.*;
Index: vcscore/src/org/netbeans/modules/vcscore/actions/VSRevisionAction.java
===================================================================
RCS file: /cvs/vcscore/src/org/netbeans/modules/vcscore/actions/VSRevisionAction.java,v
retrieving revision 1.6
diff -u -r1.6 VSRevisionAction.java
--- vcscore/src/org/netbeans/modules/vcscore/actions/VSRevisionAction.java 18 May 2004 14:39:32 -0000 1.6
+++ vcscore/src/org/netbeans/modules/vcscore/actions/VSRevisionAction.java 3 Jun 2004 13:24:41 -0000
@@ -25,7 +25,6 @@
import org.openide.filesystems.FileStateInvalidException;
import org.openide.nodes.*;
import org.openide.util.actions.*;
-import org.openide.util.enum.*;
import org.openide.util.HelpCtx;
import org.openide.util.NbBundle;
import org.openide.windows.TopComponent.Registry;
@@ -112,10 +111,10 @@
/* At present not allowed to construct actions for selected nodes on more filesystems - its safe behaviour
* If this restriction will be considered as right solution, then code of this method can be simplified
*/
- if (rListMap.size() == 0 || rListMap.size() > 1) return createMenu(EmptyEnumeration.EMPTY, popUp);
+ if (rListMap.size() == 0 || rListMap.size() > 1) return createMenu(org.openide.util.Enumerations.EMPTY, popUp);
Iterator entrySetIt = rListMap.entrySet().iterator();
- QueueEnumeration result = new QueueEnumeration();
+ LinkedList result = new LinkedList ();
while (entrySetIt.hasNext()) {
Map.Entry entry = (Map.Entry)entrySetIt.next();
@@ -123,12 +122,12 @@
Set itemSet = (Set) entry.getValue();
try {
VersioningFileSystem vs = (VersioningFileSystem) list.getFileObject().getFileSystem();
- result.put(vs.getRevisionActions(list.getFileObject(), itemSet));
+ result.addAll (Arrays.asList (vs.getRevisionActions(list.getFileObject(), itemSet)));
} catch (FileStateInvalidException exc) {
continue;
}
}
- return createMenu(result, popUp);
+ return createMenu(Collections.enumeration (result), popUp);
}
return NONE;
}
@@ -139,7 +138,7 @@
* into the menu if enabled and if not duplicated
*/
private static JMenuItem[] createMenu (Enumeration en, boolean popUp) {
- en = new RemoveDuplicatesEnumeration (en);
+ en = org.openide.util.Enumerations.removeDuplicates (en);
ArrayList items = new ArrayList ();
while (en.hasMoreElements ()) {
Index: vcscore/src/org/netbeans/modules/vcscore/actions/VcsAllCommandsAction.java
===================================================================
RCS file: /cvs/vcscore/src/org/netbeans/modules/vcscore/actions/VcsAllCommandsAction.java,v
retrieving revision 1.5
diff -u -r1.5 VcsAllCommandsAction.java
--- vcscore/src/org/netbeans/modules/vcscore/actions/VcsAllCommandsAction.java 24 May 2004 08:27:56 -0000 1.5
+++ vcscore/src/org/netbeans/modules/vcscore/actions/VcsAllCommandsAction.java 3 Jun 2004 13:24:41 -0000
@@ -53,7 +53,6 @@
import org.openide.util.actions.SystemAction;
import org.openide.util.actions.CallableSystemAction;
import org.openide.util.actions.Presenter;
-import org.openide.util.enum.*;
import org.openide.windows.TopComponent.Registry;
import org.openide.windows.WindowManager;
Index: vcscore/src/org/netbeans/modules/vcscore/actions/VcsCommandsAction.java
===================================================================
RCS file: /cvs/vcscore/src/org/netbeans/modules/vcscore/actions/VcsCommandsAction.java,v
retrieving revision 1.10
diff -u -r1.10 VcsCommandsAction.java
--- vcscore/src/org/netbeans/modules/vcscore/actions/VcsCommandsAction.java 12 Nov 2003 17:34:31 -0000 1.10
+++ vcscore/src/org/netbeans/modules/vcscore/actions/VcsCommandsAction.java 3 Jun 2004 13:24:41 -0000
@@ -36,7 +36,6 @@
import org.openide.util.actions.SystemAction;
import org.openide.util.actions.CallableSystemAction;
import org.openide.util.actions.Presenter;
-import org.openide.util.enum.*;
import org.openide.windows.TopComponent.Registry;
import org.openide.windows.WindowManager;
@@ -89,7 +88,7 @@
* If this restriction will be considered as right solution, then code of this method can be simplified
*/
if (fsSet.size () == 0 || fsSet.size() > 1) {
- List cmdMenu = createMenu (EmptyEnumeration.EMPTY, popUp);
+ List cmdMenu = createMenu (org.openide.util.Enumerations.EMPTY, popUp);
JMenuItem[] menuArray = new JMenuItem [cmdMenu.size ()];
cmdMenu.toArray (menuArray);
return menuArray;
@@ -104,12 +103,18 @@
HashSet foSet = (HashSet)entry.getValue();
if (foSet != null) {
- if (result == null) result = new SequenceEnumeration (new ArrayEnumeration (fs.getActions (foSet)),EmptyEnumeration.EMPTY);
- else result = new SequenceEnumeration (result,new ArrayEnumeration (fs.getActions (foSet)));
+ if (result == null) {
+ result = org.openide.util.Enumerations.array (fs.getActions (foSet));
+ } else {
+ result = org.openide.util.Enumerations.concat (
+ result,
+ org.openide.util.Enumerations.array (fs.getActions (foSet))
+ );
+ }
}
}
- List cmdMenu = createMenu ((result != null) ? result : EmptyEnumeration.EMPTY, popUp);
+ List cmdMenu = createMenu ((result != null) ? result : org.openide.util.Enumerations.EMPTY, popUp);
JMenuItem customize = new JMenuItem();
org.openide.awt.Actions.setMenuText (customize, org.openide.util.NbBundle.getBundle(VcsCommandsAction.class).getString("CTL_VcsFSCustomizer"), true);
customize.setIcon(CallableSystemAction.get(VcsCommandsAction.class).getIcon());
@@ -187,7 +192,7 @@
* into the menu if enabled and if not duplicated
*/
private static List createMenu (Enumeration en, boolean popUp) {
- en = new RemoveDuplicatesEnumeration (en);
+ en = org.openide.util.Enumerations.removeDuplicates (en);
ArrayList items = new ArrayList ();
while (en.hasMoreElements ()) {
Index: vcscore/src/org/netbeans/modules/vcscore/util/OrderedSet.java
===================================================================
RCS file: /cvs/vcscore/src/org/netbeans/modules/vcscore/util/OrderedSet.java,v
retrieving revision 1.1
diff -u -r1.1 OrderedSet.java
--- vcscore/src/org/netbeans/modules/vcscore/util/OrderedSet.java 19 Jul 2001 10:19:20 -0000 1.1
+++ vcscore/src/org/netbeans/modules/vcscore/util/OrderedSet.java 3 Jun 2004 13:24:41 -0000
@@ -20,11 +20,6 @@
import java.util.Enumeration;
import java.util.Iterator;
-import org.openide.util.enum.AlterEnumeration;
-import org.openide.util.enum.QueueEnumeration;
-import org.openide.util.enum.RemoveDuplicatesEnumeration;
-import org.openide.util.enum.SequenceEnumeration;
-
/**
*
* @author Martin Entlicher
@@ -35,7 +30,7 @@
public final class OrderedSet extends AbstractSet {
/** Queue of collections of elements. */
- private QueueEnumeration queue = new QueueEnumeration();
+ private java.util.LinkedList queue = new java.util.LinkedList ();
/** Objects stored in this set. */
Object[] objects = null;
@@ -44,7 +39,7 @@
}
public boolean add(Object obj) {
- queue.put(Collections.singleton(obj));
+ queue.add (Collections.singleton(obj));
return true;
}
@@ -52,20 +47,24 @@
* Adds all of the elements in the specified collection to this collection.
*/
public boolean addAll(Collection coll) {
- queue.put(coll);
+ queue.add (coll);
return true;
}
private Object[] getObjects() {
if (objects == null) {
- AlterEnumeration altered = new AlterEnumeration(queue) {
- public Object alter(Object obj) {
+ class Col2Enum implements org.openide.util.Enumerations.Processor {
+ public Object process (Object obj, Collection toAdd) {
return Collections.enumeration((Collection) obj);
}
- };
- SequenceEnumeration sequenced = new SequenceEnumeration(altered);
- Enumeration result = new RemoveDuplicatesEnumeration(sequenced);
+ }
+
+ Enumeration altered = org.openide.util.Enumerations.convert (
+ Collections.enumeration (queue), new Col2Enum ()
+ );
+ Enumeration sequenced = org.openide.util.Enumerations.concat (altered);
+ Enumeration result = org.openide.util.Enumerations.removeDuplicates (sequenced);
ArrayList objectList = new ArrayList();
for (int i = 0; result.hasMoreElements(); i++) {
objectList.add(result.nextElement());
Index: vcscore/src/org/netbeans/modules/vcscore/util/virtuals/VcsRefreshRequest.java
===================================================================
RCS file: /cvs/vcscore/src/org/netbeans/modules/vcscore/util/virtuals/VcsRefreshRequest.java,v
retrieving revision 1.6
diff -u -r1.6 VcsRefreshRequest.java
--- vcscore/src/org/netbeans/modules/vcscore/util/virtuals/VcsRefreshRequest.java 27 Feb 2003 23:43:21 -0000 1.6
+++ vcscore/src/org/netbeans/modules/vcscore/util/virtuals/VcsRefreshRequest.java 3 Jun 2004 13:24:41 -0000
@@ -23,9 +23,6 @@
import org.openide.ErrorManager;
import org.openide.util.RequestProcessor;
-import org.openide.util.enum.SequenceEnumeration;
-import org.openide.util.enum.SingletonEnumeration;
-import org.openide.util.enum.QueueEnumeration;
/** Request for parsing of an filesystem. Can be stoped.
* Copied from openide by Milos Kleint.. :) because the class is final and I need to rewrite it..
Index: vcscore/src/org/netbeans/modules/vcscore/versioning/VersioningFileSystem.java
===================================================================
RCS file: /cvs/vcscore/src/org/netbeans/modules/vcscore/versioning/VersioningFileSystem.java,v
retrieving revision 1.25
diff -u -r1.25 VersioningFileSystem.java
--- vcscore/src/org/netbeans/modules/vcscore/versioning/VersioningFileSystem.java 16 Mar 2004 15:37:34 -0000 1.25
+++ vcscore/src/org/netbeans/modules/vcscore/versioning/VersioningFileSystem.java 3 Jun 2004 13:24:41 -0000
@@ -453,7 +453,7 @@
public java.util.Enumeration attributes(String name) {
HashMap attrs = (HashMap) files.get(name);
if (attrs == null) {
- return new org.openide.util.enum.EmptyEnumeration();
+ return org.openide.util.Enumerations.EMPTY;
} else {
return Collections.enumeration(attrs.keySet());
}
Index: vcsgeneric/src/org/netbeans/modules/vcs/profiles/commands/RecursiveFolderCommand.java
===================================================================
RCS file: /cvs/vcsgeneric/src/org/netbeans/modules/vcs/profiles/commands/RecursiveFolderCommand.java,v
retrieving revision 1.12
diff -u -r1.12 RecursiveFolderCommand.java
--- vcsgeneric/src/org/netbeans/modules/vcs/profiles/commands/RecursiveFolderCommand.java 27 May 2004 14:05:27 -0000 1.12
+++ vcsgeneric/src/org/netbeans/modules/vcs/profiles/commands/RecursiveFolderCommand.java 3 Jun 2004 13:24:41 -0000
@@ -17,7 +17,6 @@
import java.util.*;
import org.openide.filesystems.FileObject;
-//import org.openide.util.enum.AlterEnumeration;
import org.netbeans.modules.vcscore.Variables;
import org.netbeans.modules.vcscore.VcsFileSystem;
Index: web/core/src/org/netbeans/modules/web/core/jsploader/JspDataObject.java
===================================================================
RCS file: /cvs/web/core/src/org/netbeans/modules/web/core/jsploader/JspDataObject.java,v
retrieving revision 1.51
diff -u -r1.51 JspDataObject.java
--- web/core/src/org/netbeans/modules/web/core/jsploader/JspDataObject.java 22 May 2004 00:43:34 -0000 1.51
+++ web/core/src/org/netbeans/modules/web/core/jsploader/JspDataObject.java 3 Jun 2004 13:24:41 -0000
@@ -16,7 +16,6 @@
import java.util.Iterator;
import java.util.Collection;
import java.util.Vector;
-import java.util.Enumeration;
import java.util.HashMap;
import java.util.Date;
import java.util.Locale;
@@ -38,7 +37,6 @@
import org.openide.windows.*;
import org.openide.text.*;
import org.openide.util.*;
-import org.openide.util.enum.*;
import org.openide.util.actions.*;
import org.openide.nodes.Node;
import org.openide.nodes.CookieSet;
Index: web/core/src/org/netbeans/modules/web/dd/DDGrammarQueryManager.java
===================================================================
RCS file: /cvs/web/core/src/org/netbeans/modules/web/dd/DDGrammarQueryManager.java,v
retrieving revision 1.2
diff -u -r1.2 DDGrammarQueryManager.java
--- web/core/src/org/netbeans/modules/web/dd/DDGrammarQueryManager.java 20 Apr 2004 12:01:50 -0000 1.2
+++ web/core/src/org/netbeans/modules/web/dd/DDGrammarQueryManager.java 3 Jun 2004 13:24:41 -0000
@@ -13,7 +13,6 @@
package org.netbeans.modules.web.dd;
import java.util.Enumeration;
-import org.openide.util.enum.SingletonEnumeration;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.xml.sax.*;
@@ -42,7 +41,7 @@
if (WEB_APP_TAG.equals(tag)) { // NOI18N
String xmlns = element.getAttribute(XMLNS_ATTR);
if (xmlns!=null && DDCatalog.J2EE_NS.equals(xmlns)) //NOI18N
- return new SingletonEnumeration(next);
+ return org.openide.util.Enumerations.singleton (next);
}
}
}
Index: web/core/src/org/netbeans/modules/web/taglib/TaglibGrammarQueryManager.java
===================================================================
RCS file: /cvs/web/core/src/org/netbeans/modules/web/taglib/TaglibGrammarQueryManager.java,v
retrieving revision 1.1
diff -u -r1.1 TaglibGrammarQueryManager.java
--- web/core/src/org/netbeans/modules/web/taglib/TaglibGrammarQueryManager.java 20 Apr 2004 12:01:52 -0000 1.1
+++ web/core/src/org/netbeans/modules/web/taglib/TaglibGrammarQueryManager.java 3 Jun 2004 13:24:41 -0000
@@ -13,7 +13,6 @@
package org.netbeans.modules.web.taglib;
import java.util.Enumeration;
-import org.openide.util.enum.SingletonEnumeration;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.xml.sax.*;
@@ -42,7 +41,7 @@
if (TAGLIB_TAG.equals(tag)) { // NOI18N
String xmlns = element.getAttribute(XMLNS_ATTR);
if (xmlns!=null && TaglibCatalog.J2EE_NS.equals(xmlns)) //NOI18N
- return new SingletonEnumeration(next);
+ return org.openide.util.Enumerations.singleton (next);
}
}
}
Index: web/taglibed/src/org/netbeans/modules/web/taglibed/control/DataFolderSelectionPanel.java
===================================================================
RCS file: /cvs/web/taglibed/src/org/netbeans/modules/web/taglibed/control/DataFolderSelectionPanel.java,v
retrieving revision 1.6
diff -u -r1.6 DataFolderSelectionPanel.java
--- web/taglibed/src/org/netbeans/modules/web/taglibed/control/DataFolderSelectionPanel.java 27 Feb 2003 23:45:10 -0000 1.6
+++ web/taglibed/src/org/netbeans/modules/web/taglibed/control/DataFolderSelectionPanel.java 3 Jun 2004 13:24:41 -0000
@@ -41,7 +41,6 @@
import org.openide.filesystems.*;
import org.openide.util.HelpCtx;
import org.openide.util.Utilities;
-import org.openide.util.enum.*;
import org.openide.util.NbBundle;
import org.netbeans.api.java.classpath.ClassPath;
@@ -482,9 +481,9 @@
system = new WeakReference (fs);
- Enumeration en = new SequenceEnumeration (
- new SingletonEnumeration (fs.getSystemName()),
- st
+ Enumeration en = org.openide.util.Enumerations.concat (
+ org.openide.util.Enumerations.singleton (fs.getSystemName()),
+ st
);
n = NodeOp.findPath (rootNode, en);
Index: xml/core/src/org/netbeans/modules/xml/api/model/GrammarQueryManager.java
===================================================================
RCS file: /cvs/xml/core/src/org/netbeans/modules/xml/api/model/GrammarQueryManager.java,v
retrieving revision 1.3
diff -u -r1.3 GrammarQueryManager.java
--- xml/core/src/org/netbeans/modules/xml/api/model/GrammarQueryManager.java 1 Aug 2002 07:22:19 -0000 1.3
+++ xml/core/src/org/netbeans/modules/xml/api/model/GrammarQueryManager.java 3 Jun 2004 13:24:41 -0000
@@ -30,7 +30,6 @@
import org.openide.loaders.DataObjectNotFoundException;
import org.openide.loaders.FolderLookup;
import org.openide.util.Lookup;
-import org.openide.util.enum.ArrayEnumeration;
import org.xml.sax.InputSource;
/**
@@ -150,15 +149,17 @@
Iterator it = getRegistrations();
transaction.set(null);
ArrayList list = new ArrayList(5);
- Enumeration enum = ctx.getDocumentChildren();
- while (enum.hasMoreElements()) {
- list.add(enum.nextElement());
+ {
+ Enumeration en = ctx.getDocumentChildren();
+ while (en.hasMoreElements()) {
+ list.add(en.nextElement());
+ }
}
Object[] array = list.toArray();
while (it.hasNext()) {
GrammarQueryManager next = (GrammarQueryManager) it.next();
GrammarEnvironment env = new GrammarEnvironment(
- new ArrayEnumeration(array),
+ org.openide.util.Enumerations.array (array),
ctx.getInputSource(),
ctx.getFileObject()
);
Index: xml/core/src/org/netbeans/modules/xml/core/lib/StreamFileObject.java
===================================================================
RCS file: /cvs/xml/core/src/org/netbeans/modules/xml/core/lib/StreamFileObject.java,v
retrieving revision 1.2
diff -u -r1.2 StreamFileObject.java
--- xml/core/src/org/netbeans/modules/xml/core/lib/StreamFileObject.java 12 Mar 2002 14:38:51 -0000 1.2
+++ xml/core/src/org/netbeans/modules/xml/core/lib/StreamFileObject.java 3 Jun 2004 13:24:41 -0000
@@ -17,7 +17,6 @@
import org.openide.filesystems.*;
import org.openide.filesystems.FileSystem;
-import org.openide.util.enum.*;
/**
* This file object represents an InputStream.
@@ -118,7 +117,7 @@
}
public java.util.Enumeration getAttributes() {
- return new EmptyEnumeration();
+ return org.openide.util.Enumerations.EMPTY;
}
public java.lang.String getName() {
Index: xml/core/src/org/netbeans/modules/xml/dtd/grammar/ContentModel.java
===================================================================
RCS file: /cvs/xml/core/src/org/netbeans/modules/xml/dtd/grammar/ContentModel.java,v
retrieving revision 1.9
diff -u -r1.9 ContentModel.java
--- xml/core/src/org/netbeans/modules/xml/dtd/grammar/ContentModel.java 30 Oct 2003 17:25:51 -0000 1.9
+++ xml/core/src/org/netbeans/modules/xml/dtd/grammar/ContentModel.java 3 Jun 2004 13:24:41 -0000
@@ -14,7 +14,6 @@
package org.netbeans.modules.xml.dtd.grammar;
import java.util.*;
-import org.openide.util.enum.*;
/**
* Implementation of queriable DTD content models. It is a hungry
@@ -209,9 +208,9 @@
protected Enumeration possibilities() {
if (terminated() == false) {
- return new SingletonEnumeration(name);
+ return org.openide.util.Enumerations.singleton (name);
} else {
- return EmptyEnumeration.EMPTY;
+ return org.openide.util.Enumerations.EMPTY;
}
}
@@ -311,15 +310,15 @@
protected Enumeration possibilities() {
if (terminated() == false) {
- Enumeration en = EmptyEnumeration.EMPTY;
+ Enumeration en = org.openide.util.Enumerations.EMPTY;
for ( int i = current; iCompletionResult
s (ENTITY_REFERENCE_NODEs)
*/
public Enumeration queryEntities(String prefix) {
- if (entities == null) return EmptyEnumeration.EMPTY;
+ if (entities == null) return org.openide.util.Enumerations.EMPTY;
- QueueEnumeration list = new QueueEnumeration();
+ LinkedList list = new LinkedList();
Iterator it = entities.iterator();
while ( it.hasNext()) {
String next = (String) it.next();
if (next.startsWith(prefix)) {
- list.put(new MyEntityReference(next));
+ list.add (new MyEntityReference(next));
}
}
// add well-know build-in entity names
- if ("lt".startsWith(prefix)) list.put(new MyEntityReference("lt"));
- if ("gt".startsWith(prefix)) list.put(new MyEntityReference("gt"));
- if ("apos".startsWith(prefix)) list.put(new MyEntityReference("apos"));
- if ("quot".startsWith(prefix)) list.put(new MyEntityReference("quot"));
- if ("amp".startsWith(prefix)) list.put(new MyEntityReference("amp"));
+ if ("lt".startsWith(prefix)) list.add(new MyEntityReference("lt"));
+ if ("gt".startsWith(prefix)) list.add(new MyEntityReference("gt"));
+ if ("apos".startsWith(prefix)) list.add(new MyEntityReference("apos"));
+ if ("quot".startsWith(prefix)) list.add(new MyEntityReference("quot"));
+ if ("amp".startsWith(prefix)) list.add(new MyEntityReference("amp"));
- return list;
+ return java.util.Collections.enumeration (list);
}
/**
@@ -95,7 +94,7 @@
* Every list member represents one possibility.
*/
public Enumeration queryAttributes(HintContext ctx) {
- if (attrDecls == null) return EmptyEnumeration.EMPTY;
+ if (attrDecls == null) return org.openide.util.Enumerations.EMPTY;
Element el = null;
// Support two versions of GrammarQuery contract
@@ -104,27 +103,27 @@
} else if (ctx.getNodeType() == Node.ELEMENT_NODE) {
el = (Element) ctx;
}
- if (el == null) return EmptyEnumeration.EMPTY;
+ if (el == null) return org.openide.util.Enumerations.EMPTY;
NamedNodeMap existingAttributes = el.getAttributes();
Set possibleAttributes = (Set) attrDecls.get(el.getTagName());
- if (possibleAttributes == null) return EmptyEnumeration.EMPTY;
+ if (possibleAttributes == null) return org.openide.util.Enumerations.EMPTY;
String prefix = ctx.getCurrentPrefix();
- QueueEnumeration list = new QueueEnumeration();
+ LinkedList list = new LinkedList ();
Iterator it = possibleAttributes.iterator();
while ( it.hasNext()) {
String next = (String) it.next();
if (next.startsWith(prefix)) {
if (existingAttributes.getNamedItem(next) == null) {
- list.put(new MyAttr(next));
+ list.add (new MyAttr(next));
}
}
}
- return list;
+ return Collections.enumeration (list);
}
/**
@@ -137,14 +136,14 @@
* Every list member represents one possibility.
*/
public Enumeration queryElements(HintContext ctx) {
- if (elementDecls == null) return EmptyEnumeration.EMPTY;;
+ if (elementDecls == null) return org.openide.util.Enumerations.EMPTY;;
Node node = ((Node)ctx).getParentNode();
Set elements = null;
if (node instanceof Element) {
Element el = (Element) node;
- if (el == null) return EmptyEnumeration.EMPTY;;
+ if (el == null) return org.openide.util.Enumerations.EMPTY;;
// lazilly parse content model
Object model = null;
@@ -162,7 +161,7 @@
}
if (model instanceof ContentModel) {
Enumeration en = ((ContentModel)model).whatCanFollow(new PreviousEnumeration(el, ctx));
- if (en == null) return EmptyEnumeration.EMPTY;
+ if (en == null) return org.openide.util.Enumerations.EMPTY;
String prefix = ctx.getCurrentPrefix();
elements = new TreeSet();
while (en.hasMoreElements()) {
@@ -179,22 +178,22 @@
} else if (node instanceof Document) {
elements = elementDecls.keySet(); //??? should be one from DOCTYPE if exist
} else {
- return EmptyEnumeration.EMPTY;
+ return org.openide.util.Enumerations.EMPTY;
}
- if (elements == null) return EmptyEnumeration.EMPTY;;
+ if (elements == null) return org.openide.util.Enumerations.EMPTY;;
String prefix = ctx.getCurrentPrefix();
- QueueEnumeration list = new QueueEnumeration();
+ LinkedList list = new LinkedList ();
Iterator it = elements.iterator();
while ( it.hasNext()) {
String next = (String) it.next();
if (next.startsWith(prefix)) {
- list.put(new MyElement(next));
+ list.add(new MyElement(next));
}
}
- return list;
+ return Collections.enumeration (list);
}
/**
@@ -202,18 +201,18 @@
* @return list of CompletionResult
s (NOTATION_NODEs)
*/
public Enumeration queryNotations(String prefix) {
- if (notations == null) return EmptyEnumeration.EMPTY;;
+ if (notations == null) return org.openide.util.Enumerations.EMPTY;;
- QueueEnumeration list = new QueueEnumeration();
+ LinkedList list = new LinkedList ();
Iterator it = notations.iterator();
while ( it.hasNext()) {
String next = (String) it.next();
if (next.startsWith(prefix)) {
- list.put(new MyNotation(next));
+ list.add (new MyNotation(next));
}
}
- return list;
+ return Collections.enumeration (list);
}
/**
@@ -226,30 +225,30 @@
* Every list member represents one possibility.
*/
public Enumeration queryValues(HintContext ctx) {
- if (attrEnumerations.isEmpty()) return EmptyEnumeration.EMPTY;
+ if (attrEnumerations.isEmpty()) return org.openide.util.Enumerations.EMPTY;
if (ctx.getNodeType() == Node.ATTRIBUTE_NODE) {
String attributeName = ctx.getNodeName();
Element element = ((Attr)ctx).getOwnerElement();
- if (element == null) return EmptyEnumeration.EMPTY;
+ if (element == null) return org.openide.util.Enumerations.EMPTY;
String elementName = element.getNodeName();
String key = elementName + " " + attributeName;
List values = (List) attrEnumerations.get(key);
- if (values == null) return EmptyEnumeration.EMPTY;
+ if (values == null) return org.openide.util.Enumerations.EMPTY;
String prefix = ctx.getCurrentPrefix();
- QueueEnumeration en = new QueueEnumeration();
+ LinkedList en = new LinkedList ();
Iterator it = values.iterator();
while (it.hasNext()) {
String next = (String) it.next();
if (next.startsWith(prefix)) {
- en.put(new MyText(next));
+ en.add(new MyText(next));
}
}
- return en;
+ return Collections.enumeration (en);
}
- return EmptyEnumeration.EMPTY;
+ return org.openide.util.Enumerations.EMPTY;
}
// return defaults for attribute values (DTD does not declare content defaults)
Index: xml/core/src/org/netbeans/modules/xml/dtd/grammar/DTDGrammarQueryProvider.java
===================================================================
RCS file: /cvs/xml/core/src/org/netbeans/modules/xml/dtd/grammar/DTDGrammarQueryProvider.java,v
retrieving revision 1.1
diff -u -r1.1 DTDGrammarQueryProvider.java
--- xml/core/src/org/netbeans/modules/xml/dtd/grammar/DTDGrammarQueryProvider.java 23 Jul 2002 11:26:54 -0000 1.1
+++ xml/core/src/org/netbeans/modules/xml/dtd/grammar/DTDGrammarQueryProvider.java 3 Jun 2004 13:24:41 -0000
@@ -16,7 +16,6 @@
import java.beans.FeatureDescriptor;
import java.util.Enumeration;
import org.netbeans.modules.xml.api.model.*;
-import org.openide.util.enum.SingletonEnumeration;
import org.w3c.dom.Node;
import org.xml.sax.InputSource;
@@ -32,7 +31,7 @@
while (en.hasMoreElements()) {
Node next = (Node) en.nextElement();
if (next.getNodeType() == next.DOCUMENT_TYPE_NODE) {
- return new SingletonEnumeration(next);
+ return org.openide.util.Enumerations.singleton (next);
}
}
return null;
Index: xml/core/src/org/netbeans/modules/xml/spi/model/EmptyQuery.java
===================================================================
RCS file: /cvs/xml/core/src/org/netbeans/modules/xml/spi/model/EmptyQuery.java,v
retrieving revision 1.3
diff -u -r1.3 EmptyQuery.java
--- xml/core/src/org/netbeans/modules/xml/spi/model/EmptyQuery.java 21 Nov 2002 20:54:50 -0000 1.3
+++ xml/core/src/org/netbeans/modules/xml/spi/model/EmptyQuery.java 3 Jun 2004 13:24:41 -0000
@@ -17,8 +17,6 @@
import org.w3c.dom.*;
-import org.openide.util.enum.EmptyEnumeration;
-
import org.netbeans.modules.xml.api.model.*;
/**
@@ -36,23 +34,23 @@
// inherit JavaDoc from interface description
public Enumeration queryEntities(String prefix) {
- return EmptyEnumeration.EMPTY;
+ return org.openide.util.Enumerations.EMPTY;
}
public Enumeration queryAttributes(HintContext ctx) {
- return EmptyEnumeration.EMPTY;
+ return org.openide.util.Enumerations.EMPTY;
}
public Enumeration queryElements(HintContext ctx) {
- return EmptyEnumeration.EMPTY;
+ return org.openide.util.Enumerations.EMPTY;
}
public Enumeration queryNotations(String prefix) {
- return EmptyEnumeration.EMPTY;
+ return org.openide.util.Enumerations.EMPTY;
}
public Enumeration queryValues(HintContext ctx) {
- return EmptyEnumeration.EMPTY;
+ return org.openide.util.Enumerations.EMPTY;
}
public boolean isAllowed(Enumeration en) {
Index: xml/core/test/unit/src/org/netbeans/modules/xml/api/model/GrammarQueryManagerTest.java
===================================================================
RCS file: /cvs/xml/core/test/unit/src/org/netbeans/modules/xml/api/model/GrammarQueryManagerTest.java,v
retrieving revision 1.1
diff -u -r1.1 GrammarQueryManagerTest.java
--- xml/core/test/unit/src/org/netbeans/modules/xml/api/model/GrammarQueryManagerTest.java 24 Jul 2002 21:37:13 -0000 1.1
+++ xml/core/test/unit/src/org/netbeans/modules/xml/api/model/GrammarQueryManagerTest.java 3 Jun 2004 13:24:41 -0000
@@ -37,8 +37,6 @@
import org.openide.loaders.DataObjectNotFoundException;
import org.openide.loaders.FolderLookup;
import org.openide.util.Lookup;
-import org.openide.util.enum.ArrayEnumeration;
-import org.openide.util.enum.EmptyEnumeration;
import org.xml.sax.InputSource;
/**
@@ -98,7 +96,7 @@
// test
GrammarQueryManager manager = GrammarQueryManager.getDefault();
- GrammarEnvironment env = new GrammarEnvironment(EmptyEnumeration.EMPTY, new InputSource(), null);
+ GrammarEnvironment env = new GrammarEnvironment(org.openide.util.Enumerations.EMPTY, new InputSource(), null);
Enumeration trigger = manager.enabled(env);
assertTrue("No grammar found!", trigger!=null);
} finally {
Index: xml/core/test/unit/src/org/netbeans/modules/xml/dtd/grammar/ContentModelTest.java
===================================================================
RCS file: /cvs/xml/core/test/unit/src/org/netbeans/modules/xml/dtd/grammar/ContentModelTest.java,v
retrieving revision 1.6
diff -u -r1.6 ContentModelTest.java
--- xml/core/test/unit/src/org/netbeans/modules/xml/dtd/grammar/ContentModelTest.java 30 Oct 2003 17:25:52 -0000 1.6
+++ xml/core/test/unit/src/org/netbeans/modules/xml/dtd/grammar/ContentModelTest.java 3 Jun 2004 13:24:41 -0000
@@ -17,7 +17,6 @@
import org.netbeans.junit.*;
import java.util.*;
import java.util.StringTokenizer;
-import org.openide.util.enum.*;
/**
*
Index: xml/core/test/unit/src/org/netbeans/modules/xml/api/model/GrammarQueryManagerTest.java
===================================================================
RCS file: /cvs/xml/core/test/unit/src/org/netbeans/modules/xml/api/model/GrammarQueryManagerTest.java,v
retrieving revision 1.1
diff -u -r1.1 GrammarQueryManagerTest.java
--- xml/core/test/unit/src/org/netbeans/modules/xml/api/model/GrammarQueryManagerTest.java 24 Jul 2002 21:37:13 -0000 1.1
+++ xml/core/test/unit/src/org/netbeans/modules/xml/api/model/GrammarQueryManagerTest.java 3 Jun 2004 13:24:41 -0000
@@ -37,8 +37,6 @@
import org.openide.loaders.DataObjectNotFoundException;
import org.openide.loaders.FolderLookup;
import org.openide.util.Lookup;
-import org.openide.util.enum.ArrayEnumeration;
-import org.openide.util.enum.EmptyEnumeration;
import org.xml.sax.InputSource;
/**
@@ -98,7 +96,7 @@
// test
GrammarQueryManager manager = GrammarQueryManager.getDefault();
- GrammarEnvironment env = new GrammarEnvironment(EmptyEnumeration.EMPTY, new InputSource(), null);
+ GrammarEnvironment env = new GrammarEnvironment(org.openide.util.Enumerations.EMPTY, new InputSource(), null);
Enumeration trigger = manager.enabled(env);
assertTrue("No grammar found!", trigger!=null);
} finally {
Index: xml/core/test/unit/src/org/netbeans/modules/xml/dtd/grammar/ContentModelTest.java
===================================================================
RCS file: /cvs/xml/core/test/unit/src/org/netbeans/modules/xml/dtd/grammar/ContentModelTest.java,v
retrieving revision 1.6
diff -u -r1.6 ContentModelTest.java
--- xml/core/test/unit/src/org/netbeans/modules/xml/dtd/grammar/ContentModelTest.java 30 Oct 2003 17:25:52 -0000 1.6
+++ xml/core/test/unit/src/org/netbeans/modules/xml/dtd/grammar/ContentModelTest.java 3 Jun 2004 13:24:41 -0000
@@ -17,7 +17,6 @@
import org.netbeans.junit.*;
import java.util.*;
import java.util.StringTokenizer;
-import org.openide.util.enum.*;
/**
*
Index: xml/schema/src/org/netbeans/modules/xml/xsd/XSDGrammarQueryProvider.java
===================================================================
RCS file: /cvs/xml/schema/src/org/netbeans/modules/xml/xsd/XSDGrammarQueryProvider.java,v
retrieving revision 1.2
diff -u -r1.2 XSDGrammarQueryProvider.java
--- xml/schema/src/org/netbeans/modules/xml/xsd/XSDGrammarQueryProvider.java 30 Apr 2004 11:42:08 -0000 1.2
+++ xml/schema/src/org/netbeans/modules/xml/xsd/XSDGrammarQueryProvider.java 3 Jun 2004 13:24:42 -0000
@@ -22,7 +22,6 @@
import org.openide.ErrorManager;
import org.openide.filesystems.FileObject;
-import org.openide.util.enum.SingletonEnumeration;
import org.netbeans.modules.xml.api.model.*;
import org.netbeans.api.xml.services.UserCatalog;
@@ -48,7 +47,7 @@
if (ret != null) {
// remember this schema
schemas.put(ctx.getFileObject(), ret);
- return new SingletonEnumeration(ret.getTarget());
+ return org.openide.util.Enumerations.singleton (ret.getTarget());
}
return null;
Index: xml/tax/src/org/netbeans/modules/xml/tax/parser/ParserLoader.java
===================================================================
RCS file: /cvs/xml/tax/src/org/netbeans/modules/xml/tax/parser/ParserLoader.java,v
retrieving revision 1.4
diff -u -r1.4 ParserLoader.java
--- xml/tax/src/org/netbeans/modules/xml/tax/parser/ParserLoader.java 25 Jun 2003 12:53:38 -0000 1.4
+++ xml/tax/src/org/netbeans/modules/xml/tax/parser/ParserLoader.java 3 Jun 2004 13:24:42 -0000
@@ -176,7 +176,7 @@
Enumeration en1 = super.findResources(name);
Enumeration en2 = parentLoader.getResources(name);
- return new org.openide.util.enum.SequenceEnumeration(en1, en2);
+ return org.openide.util.Enumerations.concat (en1, en2);
}
/**
Index: xml/text-edit/src/org/netbeans/modules/xml/text/completion/GrammarManager.java
===================================================================
RCS file: /cvs/xml/text-edit/src/org/netbeans/modules/xml/text/completion/GrammarManager.java,v
retrieving revision 1.6
diff -u -r1.6 GrammarManager.java
--- xml/text-edit/src/org/netbeans/modules/xml/text/completion/GrammarManager.java 27 Feb 2003 23:46:06 -0000 1.6
+++ xml/text-edit/src/org/netbeans/modules/xml/text/completion/GrammarManager.java 3 Jun 2004 13:24:42 -0000
@@ -17,6 +17,9 @@
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.List;
+import java.util.LinkedList;
+import java.util.Collections;
+
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import javax.swing.text.BadLocationException;
@@ -36,7 +39,6 @@
import org.openide.text.NbDocument;
import org.openide.util.RequestProcessor;
import org.openide.util.Task;
-import org.openide.util.enum.QueueEnumeration;
import org.w3c.dom.Node;
import org.xml.sax.InputSource;
import org.openide.awt.StatusDisplayer;
@@ -189,13 +191,13 @@
try {
- QueueEnumeration ctx = new QueueEnumeration();
+ LinkedList ctx = new LinkedList ();
SyntaxElement first = syntax.getElementChain(1);
while (true) {
if (first == null) break;
if (first instanceof SyntaxNode) {
SyntaxNode node = (SyntaxNode) first;
- ctx.put(node);
+ ctx.add (node);
if (node.ELEMENT_NODE == node.getNodeType()) {
break;
}
@@ -210,7 +212,7 @@
DataObject dobj = (DataObject) obj;
fileObject = dobj.getPrimaryFile();
}
- GrammarEnvironment env = new GrammarEnvironment(ctx, inputSource, fileObject);
+ GrammarEnvironment env = new GrammarEnvironment(Collections.enumeration (ctx), inputSource, fileObject);
// lookup for grammar
Index: xml/text-edit/test/unit/src/org/netbeans/modules/xml/text/completion/UnitTestQuery.java
===================================================================
RCS file: /cvs/xml/text-edit/test/unit/src/org/netbeans/modules/xml/text/completion/UnitTestQuery.java,v
retrieving revision 1.4
diff -u -r1.4 UnitTestQuery.java
--- xml/text-edit/test/unit/src/org/netbeans/modules/xml/text/completion/UnitTestQuery.java 1 Jul 2002 17:34:32 -0000 1.4
+++ xml/text-edit/test/unit/src/org/netbeans/modules/xml/text/completion/UnitTestQuery.java 3 Jun 2004 13:24:42 -0000
@@ -22,7 +22,6 @@
import java.util.Enumeration;
import junit.framework.*;
-import org.openide.util.enum.EmptyEnumeration;
/**
* Just remember completion request and return empty results.
@@ -50,7 +49,7 @@
op = "R";
ctx = "'" + prefix + "'";
fillTrace();
- return EmptyEnumeration.EMPTY;
+ return org.openide.util.Enumerations.EMPTY;
}
/**
Index: xml/text-edit/test/unit/src/org/netbeans/modules/xml/text/completion/UnitTestQuery.java
===================================================================
RCS file: /cvs/xml/text-edit/test/unit/src/org/netbeans/modules/xml/text/completion/UnitTestQuery.java,v
retrieving revision 1.4
diff -u -r1.4 UnitTestQuery.java
--- xml/text-edit/test/unit/src/org/netbeans/modules/xml/text/completion/UnitTestQuery.java 1 Jul 2002 17:34:32 -0000 1.4
+++ xml/text-edit/test/unit/src/org/netbeans/modules/xml/text/completion/UnitTestQuery.java 3 Jun 2004 13:24:42 -0000
@@ -22,7 +22,6 @@
import java.util.Enumeration;
import junit.framework.*;
-import org.openide.util.enum.EmptyEnumeration;
/**
* Just remember completion request and return empty results.
@@ -50,7 +49,7 @@
op = "R";
ctx = "'" + prefix + "'";
fillTrace();
- return EmptyEnumeration.EMPTY;
+ return org.openide.util.Enumerations.EMPTY;
}
/**
Index: xml/tree-edit/src/org/netbeans/modules/xml/tree/completion/GrammarManager.java
===================================================================
RCS file: /cvs/xml/tree-edit/src/org/netbeans/modules/xml/tree/completion/GrammarManager.java,v
retrieving revision 1.5
diff -u -r1.5 GrammarManager.java
--- xml/tree-edit/src/org/netbeans/modules/xml/tree/completion/GrammarManager.java 27 Feb 2003 23:46:16 -0000 1.5
+++ xml/tree-edit/src/org/netbeans/modules/xml/tree/completion/GrammarManager.java 3 Jun 2004 13:24:42 -0000
@@ -34,7 +34,6 @@
import org.openide.loaders.DataObject;
import org.openide.util.RequestProcessor;
import org.openide.util.Task;
-import org.openide.util.enum.QueueEnumeration;
import org.w3c.dom.Node;
import org.xml.sax.InputSource;
import org.openide.awt.StatusDisplayer;
@@ -197,13 +196,13 @@
Iterator treeObjectIter = docRoot.getChildNodes().iterator();
- QueueEnumeration ctx = new QueueEnumeration();
+ LinkedList ctx = new LinkedList ();
while( treeObjectIter.hasNext() )
{
TreeObject child = (TreeObject)treeObjectIter.next();
try {
- ctx.put( Wrapper.wrap(child) );
+ ctx.add ( Wrapper.wrap(child) );
}
catch( RuntimeException ex ) {
System.err.println("Could not wrap TAX object: "
@@ -211,7 +210,7 @@
}
}
- GrammarEnvironment env = new GrammarEnvironment(ctx, inputSource, fObj);
+ GrammarEnvironment env = new GrammarEnvironment(Collections.enumeration (ctx), inputSource, fObj);
if( gqm.enabled(env) != null )
{
Index: xml/xsl/src/org/netbeans/modules/xsl/grammar/XSLGrammarQuery.java
===================================================================
RCS file: /cvs/xml/xsl/src/org/netbeans/modules/xsl/grammar/XSLGrammarQuery.java,v
retrieving revision 1.36
diff -u -r1.36 XSLGrammarQuery.java
--- xml/xsl/src/org/netbeans/modules/xsl/grammar/XSLGrammarQuery.java 28 Feb 2003 01:22:19 -0000 1.36
+++ xml/xsl/src/org/netbeans/modules/xsl/grammar/XSLGrammarQuery.java 3 Jun 2004 13:24:42 -0000
@@ -20,7 +20,6 @@
import org.netbeans.api.xml.services.UserCatalog;
import org.netbeans.modules.xml.api.model.*;
-import org.openide.util.enum.*;
import org.netbeans.modules.xml.dtd.grammar.*;
import org.netbeans.modules.xml.spi.dom.*;
import org.netbeans.modules.xml.api.cookies.ScenarioCookie;
@@ -432,7 +431,7 @@
if (node instanceof Element) {
Element el = (Element) node;
updateProperties(el);
- if (prefixList.size() == 0) return EmptyEnumeration.EMPTY;
+ if (prefixList.size() == 0) return org.openide.util.Enumerations.EMPTY;
String firstXslPrefixWithColon = prefixList.get(0) + ":"; // NOI18N
Set elements;
@@ -477,10 +476,10 @@
} else if (node instanceof Document) {
//??? it should be probably only root element name
- if (prefixList.size() == 0) return EmptyEnumeration.EMPTY;
+ if (prefixList.size() == 0) return org.openide.util.Enumerations.EMPTY;
addXslElementsToEnum(list, getElementDecls().keySet(), prefixList.get(0) + ":", prefix); // NOI18N
} else {
- return EmptyEnumeration.EMPTY;
+ return org.openide.util.Enumerations.EMPTY;
}
return list;
@@ -494,7 +493,7 @@
} else if (ctx.getNodeType() == Node.ELEMENT_NODE) {
el = (Element) ctx;
}
- if (el == null) return EmptyEnumeration.EMPTY;
+ if (el == null) return org.openide.util.Enumerations.EMPTY;
String elTagName = el.getTagName();
NamedNodeMap existingAttributes = el.getAttributes();
@@ -524,7 +523,7 @@
}
}
}
- if (possibleAttributes == null) return EmptyEnumeration.EMPTY;
+ if (possibleAttributes == null) return org.openide.util.Enumerations.EMPTY;
String prefix = ctx.getCurrentPrefix();
@@ -556,7 +555,7 @@
public Enumeration queryValues(HintContext ctx) {
if (ctx.getNodeType() == Node.ATTRIBUTE_NODE) {
updateProperties(((Attr)ctx).getOwnerElement());
- if (prefixList.size() == 0) return EmptyEnumeration.EMPTY;
+ if (prefixList.size() == 0) return org.openide.util.Enumerations.EMPTY;
String xslNamespacePrefix = prefixList.get(0) + ":"; // NOI18N
String prefix = ctx.getCurrentPrefix();
@@ -577,7 +576,7 @@
if ("output".equals(key)) { // NOI18N
if ("doctype-public".equals(attr.getName())) { // NOI18N
UserCatalog catalog = UserCatalog.getDefault();
- if (catalog == null) return EmptyEnumeration.EMPTY;
+ if (catalog == null) return org.openide.util.Enumerations.EMPTY;
QueueEnumeration en = new QueueEnumeration();
Iterator it = catalog.getPublicIDs();
while (it.hasNext()) {
@@ -712,7 +711,7 @@
}
}
- return EmptyEnumeration.EMPTY;
+ return org.openide.util.Enumerations.EMPTY;
}
public GrammarResult queryDefault(HintContext ctx) {
@@ -740,7 +739,7 @@
}
public Enumeration queryNotations(String prefix) {
- return EmptyEnumeration.EMPTY;
+ return org.openide.util.Enumerations.EMPTY;
}
public java.awt.Component getCustomizer(HintContext ctx) {
@@ -1124,4 +1123,23 @@
}
}
+ private static class QueueEnumeration implements Enumeration {
+ private java.util.LinkedList list = new LinkedList ();
+
+ public boolean hasMoreElements () {
+ return !list.isEmpty ();
+ }
+
+ public Object nextElement () {
+ return list.removeFirst ();
+ }
+
+ public void put (Object[] arr) {
+ list.addAll (Arrays.asList (arr));
+ }
+ public void put (Object o) {
+ list.add (o);
+ }
+
+ } // end of QueueEnumeration
}
Index: xml/xsl/src/org/netbeans/modules/xsl/grammar/XSLGrammarQueryProvider.java
===================================================================
RCS file: /cvs/xml/xsl/src/org/netbeans/modules/xsl/grammar/XSLGrammarQueryProvider.java,v
retrieving revision 1.10
diff -u -r1.10 XSLGrammarQueryProvider.java
--- xml/xsl/src/org/netbeans/modules/xsl/grammar/XSLGrammarQueryProvider.java 16 Mar 2004 15:37:52 -0000 1.10
+++ xml/xsl/src/org/netbeans/modules/xsl/grammar/XSLGrammarQueryProvider.java 3 Jun 2004 13:24:42 -0000
@@ -18,16 +18,12 @@
import org.netbeans.modules.xml.api.model.GrammarQuery;
import org.netbeans.modules.xml.api.model.GrammarQueryManager;
import org.openide.filesystems.FileObject;
-import org.openide.util.enum.EmptyEnumeration;
-import org.openide.util.enum.SingletonEnumeration;
import org.w3c.dom.DocumentType;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.xml.sax.InputSource;
import org.openide.filesystems.FileObject;
-import org.openide.util.enum.EmptyEnumeration;
-import org.openide.util.enum.SingletonEnumeration;
import org.netbeans.modules.xsl.XSLDataObject;
import org.openide.loaders.DataObject;
@@ -66,7 +62,7 @@
if ("transformation".equals(tag) || "stylesheet".equals(tag)) { // NOI18N
String ns = element.getAttribute("xmlns"); // NOI18N
if (NAMESPACE.equals(ns)) {
- return new SingletonEnumeration(next);
+ return org.openide.util.Enumerations.singleton (next);
}
}
} else {
@@ -75,7 +71,7 @@
if ("transformation".equals(local) || "stylesheet".equals(local)) { // NOI18N
String ns = element.getAttribute("xmlns:" + prefix); // NOI18N
if (NAMESPACE.equals(ns)) {
- return new SingletonEnumeration(next);
+ return org.openide.util.Enumerations.singleton (next);
}
}
}
@@ -89,7 +85,7 @@
// almost forever, until client uses its own invalidation
// rules based e.g. on new node detection at root level
// or MIME type listening
- return EmptyEnumeration.EMPTY;
+ return org.openide.util.Enumerations.EMPTY;
}
}