This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

View | Details | Raw Unified | Return to bug 41166
Collapse All | Expand All

(-)ant/grammar/src/org/netbeans/modules/ant/grammar/AntGrammar.java (-31 / +29 lines)
Lines 21-28 Link Here
21
21
22
import org.w3c.dom.*;
22
import org.w3c.dom.*;
23
23
24
import org.openide.util.enum.*;
25
26
import org.netbeans.modules.xml.api.model.*;
24
import org.netbeans.modules.xml.api.model.*;
27
import org.netbeans.modules.xml.spi.dom.*;
25
import org.netbeans.modules.xml.spi.dom.*;
28
26
Lines 39-55 Link Here
39
     * @return list of <code>CompletionResult</code>s (ENTITY_REFERENCE_NODEs)
37
     * @return list of <code>CompletionResult</code>s (ENTITY_REFERENCE_NODEs)
40
     */
38
     */
41
    public Enumeration queryEntities(String prefix) {
39
    public Enumeration queryEntities(String prefix) {
42
        QueueEnumeration list = new QueueEnumeration();
40
        java.util.LinkedList list = new java.util.LinkedList();
43
        
41
        
44
        // add well-know build-in entity names
42
        // add well-know build-in entity names
45
        
43
        
46
        if ("lt".startsWith(prefix)) list.put(new MyEntityReference("lt"));
44
        if ("lt".startsWith(prefix)) list.add(new MyEntityReference("lt"));
47
        if ("gt".startsWith(prefix)) list.put(new MyEntityReference("gt"));
45
        if ("gt".startsWith(prefix)) list.add(new MyEntityReference("gt"));
48
        if ("apos".startsWith(prefix)) list.put(new MyEntityReference("apos"));
46
        if ("apos".startsWith(prefix)) list.add(new MyEntityReference("apos"));
49
        if ("quot".startsWith(prefix)) list.put(new MyEntityReference("quot"));
47
        if ("quot".startsWith(prefix)) list.add(new MyEntityReference("quot"));
50
        if ("amp".startsWith(prefix)) list.put(new MyEntityReference("amp"));
48
        if ("amp".startsWith(prefix)) list.add(new MyEntityReference("amp"));
51
        
49
        
52
        return list;
50
        return java.util.Collections.enumeration (list);
53
    }
51
    }
54
52
55
    /*
53
    /*
Lines 184-196 Link Here
184
        } else if (ctx.getNodeType() == Node.ELEMENT_NODE) {
182
        } else if (ctx.getNodeType() == Node.ELEMENT_NODE) {
185
            ownerElement = (Element) ctx;
183
            ownerElement = (Element) ctx;
186
        }
184
        }
187
        if (ownerElement == null) return EmptyEnumeration.EMPTY;
185
        if (ownerElement == null) return org.openide.util.Enumerations.EMPTY;
188
        
186
        
189
        NamedNodeMap existingAttributes = ownerElement.getAttributes();        
187
        NamedNodeMap existingAttributes = ownerElement.getAttributes();        
190
        List possibleAttributes;
188
        List possibleAttributes;
191
        String[] typePair = typeOf(ownerElement);
189
        String[] typePair = typeOf(ownerElement);
192
        if (typePair == null) {
190
        if (typePair == null) {
193
            return EmptyEnumeration.EMPTY;
191
            return org.openide.util.Enumerations.EMPTY;
194
        }
192
        }
195
        String kind = typePair[0];
193
        String kind = typePair[0];
196
        String clazz = typePair[1];
194
        String clazz = typePair[1];
Lines 208-214 Link Here
208
            possibleAttributes.add("if");
206
            possibleAttributes.add("if");
209
            possibleAttributes.add("unless");
207
            possibleAttributes.add("unless");
210
        } else if (kind == KIND_SPECIAL && clazz == SPECIAL_DESCRIPTION) {
208
        } else if (kind == KIND_SPECIAL && clazz == SPECIAL_DESCRIPTION) {
211
            return EmptyEnumeration.EMPTY;
209
            return org.openide.util.Enumerations.EMPTY;
212
        } else {
210
        } else {
213
            // task, type, or data; anyway, we have the defining class
211
            // task, type, or data; anyway, we have the defining class
214
            possibleAttributes = new LinkedList();
212
            possibleAttributes = new LinkedList();
Lines 232-249 Link Here
232
        
230
        
233
        String prefix = ctx.getCurrentPrefix();
231
        String prefix = ctx.getCurrentPrefix();
234
        
232
        
235
        QueueEnumeration list = new QueueEnumeration();
233
        java.util.LinkedList list = new java.util.LinkedList();
236
        Iterator it = possibleAttributes.iterator();
234
        Iterator it = possibleAttributes.iterator();
237
        while ( it.hasNext()) {
235
        while ( it.hasNext()) {
238
            String next = (String) it.next();
236
            String next = (String) it.next();
239
            if (next.startsWith(prefix)) {
237
            if (next.startsWith(prefix)) {
240
                if (existingAttributes.getNamedItem(next) == null) {
238
                if (existingAttributes.getNamedItem(next) == null) {
241
                    list.put(new MyAttr(next));
239
                    list.add (new MyAttr(next));
242
                }
240
                }
243
            }
241
            }
244
        }
242
        }
245
        
243
        
246
        return list;
244
        return java.util.Collections.enumeration (list);
247
    }
245
    }
248
    
246
    
249
    /**
247
    /**
Lines 258-272 Link Here
258
    public Enumeration queryElements(HintContext ctx) {
256
    public Enumeration queryElements(HintContext ctx) {
259
        
257
        
260
        Node parent = ((Node)ctx).getParentNode();
258
        Node parent = ((Node)ctx).getParentNode();
261
        if (parent == null) return EmptyEnumeration.EMPTY;
259
        if (parent == null) return org.openide.util.Enumerations.EMPTY;
262
        if (parent.getNodeType() != Node.ELEMENT_NODE) {
260
        if (parent.getNodeType() != Node.ELEMENT_NODE) {
263
            return EmptyEnumeration.EMPTY;
261
            return org.openide.util.Enumerations.EMPTY;
264
        }
262
        }
265
        
263
        
266
        List elements;
264
        List elements;
267
        String[] typePair = typeOf((Element)parent);
265
        String[] typePair = typeOf((Element)parent);
268
        if (typePair == null) {
266
        if (typePair == null) {
269
            return EmptyEnumeration.EMPTY;
267
            return org.openide.util.Enumerations.EMPTY;
270
        }
268
        }
271
        String kind = typePair[0];
269
        String kind = typePair[0];
272
        String clazz = typePair[1];
270
        String clazz = typePair[1];
Lines 285-291 Link Here
285
            // targets can have embedded types too, though less common:
283
            // targets can have embedded types too, though less common:
286
            elements.addAll(getSortedDefs("type")); // NOI18N
284
            elements.addAll(getSortedDefs("type")); // NOI18N
287
        } else if (kind == KIND_SPECIAL && clazz == SPECIAL_DESCRIPTION) {
285
        } else if (kind == KIND_SPECIAL && clazz == SPECIAL_DESCRIPTION) {
288
            return EmptyEnumeration.EMPTY;
286
            return org.openide.util.Enumerations.EMPTY;
289
        } else {
287
        } else {
290
            // some introspectable class
288
            // some introspectable class
291
            if (getAntGrammar().isKnown(clazz)) {
289
            if (getAntGrammar().isKnown(clazz)) {
Lines 297-312 Link Here
297
                
295
                
298
        String prefix = ctx.getCurrentPrefix();
296
        String prefix = ctx.getCurrentPrefix();
299
        
297
        
300
        QueueEnumeration list = new QueueEnumeration();
298
        java.util.LinkedList list = new java.util.LinkedList ();
301
        Iterator it = elements.iterator();
299
        Iterator it = elements.iterator();
302
        while ( it.hasNext()) {
300
        while ( it.hasNext()) {
303
            String next = (String) it.next();
301
            String next = (String) it.next();
304
            if (next.startsWith(prefix)) {
302
            if (next.startsWith(prefix)) {
305
                list.put(new MyElement(next));
303
                list.add (new MyElement(next));
306
            }
304
            }
307
        }
305
        }
308
        
306
        
309
        return list;                        
307
        return java.util.Collections.enumeration (list);                        
310
    }
308
    }
311
    
309
    
312
    private static SortedSet/*<String>*/ getSortedDefs(String kind) {
310
    private static SortedSet/*<String>*/ getSortedDefs(String kind) {
Lines 320-326 Link Here
320
     * @return list of <code>CompletionResult</code>s (NOTATION_NODEs)
318
     * @return list of <code>CompletionResult</code>s (NOTATION_NODEs)
321
     */
319
     */
322
    public Enumeration queryNotations(String prefix) {
320
    public Enumeration queryNotations(String prefix) {
323
        return EmptyEnumeration.EMPTY;
321
        return org.openide.util.Enumerations.EMPTY;
324
    }
322
    }
325
    
323
    
326
    public Enumeration queryValues(HintContext ctx) {
324
    public Enumeration queryValues(HintContext ctx) {
Lines 332-344 Link Here
332
        } else if (ctx.getNodeType() == Node.ATTRIBUTE_NODE) {
330
        } else if (ctx.getNodeType() == Node.ATTRIBUTE_NODE) {
333
            ownerAttr = (Attr)ctx;
331
            ownerAttr = (Attr)ctx;
334
        } else {
332
        } else {
335
            return EmptyEnumeration.EMPTY;
333
            return org.openide.util.Enumerations.EMPTY;
336
        }
334
        }
337
        Element ownerElement = ownerAttr.getOwnerElement();
335
        Element ownerElement = ownerAttr.getOwnerElement();
338
        String attrName = ownerAttr.getName();
336
        String attrName = ownerAttr.getName();
339
        String[] typePair = typeOf(ownerElement);
337
        String[] typePair = typeOf(ownerElement);
340
        if (typePair == null) {
338
        if (typePair == null) {
341
            return EmptyEnumeration.EMPTY;
339
            return org.openide.util.Enumerations.EMPTY;
342
        }
340
        }
343
        List/*<String>*/ choices = new ArrayList();
341
        List/*<String>*/ choices = new ArrayList();
344
        
342
        
Lines 394-408 Link Here
394
        
392
        
395
        // Create the completion:
393
        // Create the completion:
396
        String prefix = ctx.getCurrentPrefix();
394
        String prefix = ctx.getCurrentPrefix();
397
        QueueEnumeration list = new QueueEnumeration();
395
        LinkedList list = new LinkedList ();
398
        Iterator it = choices.iterator();
396
        Iterator it = choices.iterator();
399
        while (it.hasNext()) {
397
        while (it.hasNext()) {
400
            String next = (String)it.next();
398
            String next = (String)it.next();
401
            if (next.startsWith(prefix)) {
399
            if (next.startsWith(prefix)) {
402
                list.put(new MyText(next));
400
                list.add (new MyText(next));
403
            }
401
            }
404
        }
402
        }
405
        return list;
403
        return Collections.enumeration (list);
406
    }
404
    }
407
    
405
    
408
    /**
406
    /**
Lines 446-452 Link Here
446
        // completion on text works differently from attrs:
444
        // completion on text works differently from attrs:
447
        // the context should not be returned (#38342)
445
        // the context should not be returned (#38342)
448
        boolean shortHeader = ctx.getNodeType() == Node.TEXT_NODE;
446
        boolean shortHeader = ctx.getNodeType() == Node.TEXT_NODE;
449
        QueueEnumeration list = new QueueEnumeration();
447
        LinkedList list = new LinkedList ();
450
        for (int i = 0; i < props.length; i++) {
448
        for (int i = 0; i < props.length; i++) {
451
            if (props[i].startsWith(propPrefix)) {
449
            if (props[i].startsWith(propPrefix)) {
452
                String text = header + props[i] + '}';;
450
                String text = header + props[i] + '}';;
Lines 454-463 Link Here
454
                    assert text.startsWith(content) : "text=" + text + " content=" + content;
452
                    assert text.startsWith(content) : "text=" + text + " content=" + content;
455
                    text = text.substring(content.length());
453
                    text = text.substring(content.length());
456
                }
454
                }
457
                list.put(new MyText(text));
455
                list.add (new MyText(text));
458
            }
456
            }
459
        }
457
        }
460
        return list;
458
        return Collections.enumeration (list);
461
    }
459
    }
462
    
460
    
463
    /**
461
    /**
(-)ant/grammar/src/org/netbeans/modules/ant/grammar/AntGrammarQueryProvider.java (-2 / +1 lines)
Lines 16-22 Link Here
16
import java.beans.FeatureDescriptor;
16
import java.beans.FeatureDescriptor;
17
import java.util.Enumeration;
17
import java.util.Enumeration;
18
import org.netbeans.modules.xml.api.model.*;
18
import org.netbeans.modules.xml.api.model.*;
19
import org.openide.util.enum.SingletonEnumeration;
20
import org.w3c.dom.Node;
19
import org.w3c.dom.Node;
21
import org.w3c.dom.Element;
20
import org.w3c.dom.Element;
22
import org.xml.sax.InputSource;
21
import org.xml.sax.InputSource;
Lines 37-43 Link Here
37
                // XXX should also check for any root <project> in NS "antlib:org.apache.tools.ant"
36
                // XXX should also check for any root <project> in NS "antlib:org.apache.tools.ant"
38
                // (but no NS support in HintContext impl anyway: #38340)
37
                // (but no NS support in HintContext impl anyway: #38340)
39
                if ("project".equals(root.getNodeName()) && root.getAttributeNode("default") != null) { // NOI18N
38
                if ("project".equals(root.getNodeName()) && root.getAttributeNode("default") != null) { // NOI18N
40
                    return new SingletonEnumeration(next);
39
                    return org.openide.util.Enumerations.singleton (next);
41
                }
40
                }
42
            }
41
            }
43
        }
42
        }
(-)ant/src/org/apache/tools/ant/module/bridge/AuxClassLoader.java (-2 / +7 lines)
Lines 16-22 Link Here
16
import java.io.IOException;
16
import java.io.IOException;
17
import java.net.URL;
17
import java.net.URL;
18
import java.util.Enumeration;
18
import java.util.Enumeration;
19
import org.openide.util.enum.*;
19
import org.openide.util.Enumerations;
20
20
21
/**
21
/**
22
 * Loads classes in the following order:
22
 * Loads classes in the following order:
Lines 54-60 Link Here
54
    }
54
    }
55
    
55
    
56
    public Enumeration findResources(String name) throws IOException {
56
    public Enumeration findResources(String name) throws IOException {
57
        return new RemoveDuplicatesEnumeration(new SequenceEnumeration(nbLoader.getResources(name), super.findResources(name)));
57
        return Enumerations.removeDuplicates (
58
            Enumerations.concat (
59
                nbLoader.getResources(name), 
60
                super.findResources(name)
61
            )
62
        );
58
    }
63
    }
59
    
64
    
60
    // XXX should maybe do something with packages... but oh well, it is rather hard.
65
    // XXX should maybe do something with packages... but oh well, it is rather hard.
(-)ant/src/org/apache/tools/ant/module/bridge/DummyBridgeImpl.java (-3 / +3 lines)
Lines 19-25 Link Here
19
import org.openide.ErrorManager;
19
import org.openide.ErrorManager;
20
import org.openide.filesystems.FileObject;
20
import org.openide.filesystems.FileObject;
21
import org.openide.util.NbBundle;
21
import org.openide.util.NbBundle;
22
import org.openide.util.enum.EmptyEnumeration;
22
import org.openide.util.Enumerations;
23
23
24
/**
24
/**
25
 * Used when the real Ant class loader cannot be initialized for some reason.
25
 * Used when the real Ant class loader cannot be initialized for some reason.
Lines 51-57 Link Here
51
    }
51
    }
52
    
52
    
53
    public Enumeration getAttributes() {
53
    public Enumeration getAttributes() {
54
        return EmptyEnumeration.EMPTY;
54
        return Enumerations.EMPTY;
55
    }
55
    }
56
    
56
    
57
    public Class getElementType(String name) {
57
    public Class getElementType(String name) {
Lines 59-65 Link Here
59
    }
59
    }
60
    
60
    
61
    public Enumeration getNestedElements() {
61
    public Enumeration getNestedElements() {
62
        return EmptyEnumeration.EMPTY;
62
        return Enumerations.EMPTY;
63
    }
63
    }
64
    
64
    
65
    public boolean supportsCharacters() {
65
    public boolean supportsCharacters() {
(-)ant/grammar/src/org/netbeans/modules/ant/grammar/AntGrammar.java (-31 / +29 lines)
Lines 21-28 Link Here
21
21
22
import org.w3c.dom.*;
22
import org.w3c.dom.*;
23
23
24
import org.openide.util.enum.*;
25
26
import org.netbeans.modules.xml.api.model.*;
24
import org.netbeans.modules.xml.api.model.*;
27
import org.netbeans.modules.xml.spi.dom.*;
25
import org.netbeans.modules.xml.spi.dom.*;
28
26
Lines 39-55 Link Here
39
     * @return list of <code>CompletionResult</code>s (ENTITY_REFERENCE_NODEs)
37
     * @return list of <code>CompletionResult</code>s (ENTITY_REFERENCE_NODEs)
40
     */
38
     */
41
    public Enumeration queryEntities(String prefix) {
39
    public Enumeration queryEntities(String prefix) {
42
        QueueEnumeration list = new QueueEnumeration();
40
        java.util.LinkedList list = new java.util.LinkedList();
43
        
41
        
44
        // add well-know build-in entity names
42
        // add well-know build-in entity names
45
        
43
        
46
        if ("lt".startsWith(prefix)) list.put(new MyEntityReference("lt"));
44
        if ("lt".startsWith(prefix)) list.add(new MyEntityReference("lt"));
47
        if ("gt".startsWith(prefix)) list.put(new MyEntityReference("gt"));
45
        if ("gt".startsWith(prefix)) list.add(new MyEntityReference("gt"));
48
        if ("apos".startsWith(prefix)) list.put(new MyEntityReference("apos"));
46
        if ("apos".startsWith(prefix)) list.add(new MyEntityReference("apos"));
49
        if ("quot".startsWith(prefix)) list.put(new MyEntityReference("quot"));
47
        if ("quot".startsWith(prefix)) list.add(new MyEntityReference("quot"));
50
        if ("amp".startsWith(prefix)) list.put(new MyEntityReference("amp"));
48
        if ("amp".startsWith(prefix)) list.add(new MyEntityReference("amp"));
51
        
49
        
52
        return list;
50
        return java.util.Collections.enumeration (list);
53
    }
51
    }
54
52
55
    /*
53
    /*
Lines 184-196 Link Here
184
        } else if (ctx.getNodeType() == Node.ELEMENT_NODE) {
182
        } else if (ctx.getNodeType() == Node.ELEMENT_NODE) {
185
            ownerElement = (Element) ctx;
183
            ownerElement = (Element) ctx;
186
        }
184
        }
187
        if (ownerElement == null) return EmptyEnumeration.EMPTY;
185
        if (ownerElement == null) return org.openide.util.Enumerations.EMPTY;
188
        
186
        
189
        NamedNodeMap existingAttributes = ownerElement.getAttributes();        
187
        NamedNodeMap existingAttributes = ownerElement.getAttributes();        
190
        List possibleAttributes;
188
        List possibleAttributes;
191
        String[] typePair = typeOf(ownerElement);
189
        String[] typePair = typeOf(ownerElement);
192
        if (typePair == null) {
190
        if (typePair == null) {
193
            return EmptyEnumeration.EMPTY;
191
            return org.openide.util.Enumerations.EMPTY;
194
        }
192
        }
195
        String kind = typePair[0];
193
        String kind = typePair[0];
196
        String clazz = typePair[1];
194
        String clazz = typePair[1];
Lines 208-214 Link Here
208
            possibleAttributes.add("if");
206
            possibleAttributes.add("if");
209
            possibleAttributes.add("unless");
207
            possibleAttributes.add("unless");
210
        } else if (kind == KIND_SPECIAL && clazz == SPECIAL_DESCRIPTION) {
208
        } else if (kind == KIND_SPECIAL && clazz == SPECIAL_DESCRIPTION) {
211
            return EmptyEnumeration.EMPTY;
209
            return org.openide.util.Enumerations.EMPTY;
212
        } else {
210
        } else {
213
            // task, type, or data; anyway, we have the defining class
211
            // task, type, or data; anyway, we have the defining class
214
            possibleAttributes = new LinkedList();
212
            possibleAttributes = new LinkedList();
Lines 232-249 Link Here
232
        
230
        
233
        String prefix = ctx.getCurrentPrefix();
231
        String prefix = ctx.getCurrentPrefix();
234
        
232
        
235
        QueueEnumeration list = new QueueEnumeration();
233
        java.util.LinkedList list = new java.util.LinkedList();
236
        Iterator it = possibleAttributes.iterator();
234
        Iterator it = possibleAttributes.iterator();
237
        while ( it.hasNext()) {
235
        while ( it.hasNext()) {
238
            String next = (String) it.next();
236
            String next = (String) it.next();
239
            if (next.startsWith(prefix)) {
237
            if (next.startsWith(prefix)) {
240
                if (existingAttributes.getNamedItem(next) == null) {
238
                if (existingAttributes.getNamedItem(next) == null) {
241
                    list.put(new MyAttr(next));
239
                    list.add (new MyAttr(next));
242
                }
240
                }
243
            }
241
            }
244
        }
242
        }
245
        
243
        
246
        return list;
244
        return java.util.Collections.enumeration (list);
247
    }
245
    }
248
    
246
    
249
    /**
247
    /**
Lines 258-272 Link Here
258
    public Enumeration queryElements(HintContext ctx) {
256
    public Enumeration queryElements(HintContext ctx) {
259
        
257
        
260
        Node parent = ((Node)ctx).getParentNode();
258
        Node parent = ((Node)ctx).getParentNode();
261
        if (parent == null) return EmptyEnumeration.EMPTY;
259
        if (parent == null) return org.openide.util.Enumerations.EMPTY;
262
        if (parent.getNodeType() != Node.ELEMENT_NODE) {
260
        if (parent.getNodeType() != Node.ELEMENT_NODE) {
263
            return EmptyEnumeration.EMPTY;
261
            return org.openide.util.Enumerations.EMPTY;
264
        }
262
        }
265
        
263
        
266
        List elements;
264
        List elements;
267
        String[] typePair = typeOf((Element)parent);
265
        String[] typePair = typeOf((Element)parent);
268
        if (typePair == null) {
266
        if (typePair == null) {
269
            return EmptyEnumeration.EMPTY;
267
            return org.openide.util.Enumerations.EMPTY;
270
        }
268
        }
271
        String kind = typePair[0];
269
        String kind = typePair[0];
272
        String clazz = typePair[1];
270
        String clazz = typePair[1];
Lines 285-291 Link Here
285
            // targets can have embedded types too, though less common:
283
            // targets can have embedded types too, though less common:
286
            elements.addAll(getSortedDefs("type")); // NOI18N
284
            elements.addAll(getSortedDefs("type")); // NOI18N
287
        } else if (kind == KIND_SPECIAL && clazz == SPECIAL_DESCRIPTION) {
285
        } else if (kind == KIND_SPECIAL && clazz == SPECIAL_DESCRIPTION) {
288
            return EmptyEnumeration.EMPTY;
286
            return org.openide.util.Enumerations.EMPTY;
289
        } else {
287
        } else {
290
            // some introspectable class
288
            // some introspectable class
291
            if (getAntGrammar().isKnown(clazz)) {
289
            if (getAntGrammar().isKnown(clazz)) {
Lines 297-312 Link Here
297
                
295
                
298
        String prefix = ctx.getCurrentPrefix();
296
        String prefix = ctx.getCurrentPrefix();
299
        
297
        
300
        QueueEnumeration list = new QueueEnumeration();
298
        java.util.LinkedList list = new java.util.LinkedList ();
301
        Iterator it = elements.iterator();
299
        Iterator it = elements.iterator();
302
        while ( it.hasNext()) {
300
        while ( it.hasNext()) {
303
            String next = (String) it.next();
301
            String next = (String) it.next();
304
            if (next.startsWith(prefix)) {
302
            if (next.startsWith(prefix)) {
305
                list.put(new MyElement(next));
303
                list.add (new MyElement(next));
306
            }
304
            }
307
        }
305
        }
308
        
306
        
309
        return list;                        
307
        return java.util.Collections.enumeration (list);                        
310
    }
308
    }
311
    
309
    
312
    private static SortedSet/*<String>*/ getSortedDefs(String kind) {
310
    private static SortedSet/*<String>*/ getSortedDefs(String kind) {
Lines 320-326 Link Here
320
     * @return list of <code>CompletionResult</code>s (NOTATION_NODEs)
318
     * @return list of <code>CompletionResult</code>s (NOTATION_NODEs)
321
     */
319
     */
322
    public Enumeration queryNotations(String prefix) {
320
    public Enumeration queryNotations(String prefix) {
323
        return EmptyEnumeration.EMPTY;
321
        return org.openide.util.Enumerations.EMPTY;
324
    }
322
    }
325
    
323
    
326
    public Enumeration queryValues(HintContext ctx) {
324
    public Enumeration queryValues(HintContext ctx) {
Lines 332-344 Link Here
332
        } else if (ctx.getNodeType() == Node.ATTRIBUTE_NODE) {
330
        } else if (ctx.getNodeType() == Node.ATTRIBUTE_NODE) {
333
            ownerAttr = (Attr)ctx;
331
            ownerAttr = (Attr)ctx;
334
        } else {
332
        } else {
335
            return EmptyEnumeration.EMPTY;
333
            return org.openide.util.Enumerations.EMPTY;
336
        }
334
        }
337
        Element ownerElement = ownerAttr.getOwnerElement();
335
        Element ownerElement = ownerAttr.getOwnerElement();
338
        String attrName = ownerAttr.getName();
336
        String attrName = ownerAttr.getName();
339
        String[] typePair = typeOf(ownerElement);
337
        String[] typePair = typeOf(ownerElement);
340
        if (typePair == null) {
338
        if (typePair == null) {
341
            return EmptyEnumeration.EMPTY;
339
            return org.openide.util.Enumerations.EMPTY;
342
        }
340
        }
343
        List/*<String>*/ choices = new ArrayList();
341
        List/*<String>*/ choices = new ArrayList();
344
        
342
        
Lines 394-408 Link Here
394
        
392
        
395
        // Create the completion:
393
        // Create the completion:
396
        String prefix = ctx.getCurrentPrefix();
394
        String prefix = ctx.getCurrentPrefix();
397
        QueueEnumeration list = new QueueEnumeration();
395
        LinkedList list = new LinkedList ();
398
        Iterator it = choices.iterator();
396
        Iterator it = choices.iterator();
399
        while (it.hasNext()) {
397
        while (it.hasNext()) {
400
            String next = (String)it.next();
398
            String next = (String)it.next();
401
            if (next.startsWith(prefix)) {
399
            if (next.startsWith(prefix)) {
402
                list.put(new MyText(next));
400
                list.add (new MyText(next));
403
            }
401
            }
404
        }
402
        }
405
        return list;
403
        return Collections.enumeration (list);
406
    }
404
    }
407
    
405
    
408
    /**
406
    /**
Lines 446-452 Link Here
446
        // completion on text works differently from attrs:
444
        // completion on text works differently from attrs:
447
        // the context should not be returned (#38342)
445
        // the context should not be returned (#38342)
448
        boolean shortHeader = ctx.getNodeType() == Node.TEXT_NODE;
446
        boolean shortHeader = ctx.getNodeType() == Node.TEXT_NODE;
449
        QueueEnumeration list = new QueueEnumeration();
447
        LinkedList list = new LinkedList ();
450
        for (int i = 0; i < props.length; i++) {
448
        for (int i = 0; i < props.length; i++) {
451
            if (props[i].startsWith(propPrefix)) {
449
            if (props[i].startsWith(propPrefix)) {
452
                String text = header + props[i] + '}';;
450
                String text = header + props[i] + '}';;
Lines 454-463 Link Here
454
                    assert text.startsWith(content) : "text=" + text + " content=" + content;
452
                    assert text.startsWith(content) : "text=" + text + " content=" + content;
455
                    text = text.substring(content.length());
453
                    text = text.substring(content.length());
456
                }
454
                }
457
                list.put(new MyText(text));
455
                list.add (new MyText(text));
458
            }
456
            }
459
        }
457
        }
460
        return list;
458
        return Collections.enumeration (list);
461
    }
459
    }
462
    
460
    
463
    /**
461
    /**
(-)ant/grammar/src/org/netbeans/modules/ant/grammar/AntGrammarQueryProvider.java (-2 / +1 lines)
Lines 16-22 Link Here
16
import java.beans.FeatureDescriptor;
16
import java.beans.FeatureDescriptor;
17
import java.util.Enumeration;
17
import java.util.Enumeration;
18
import org.netbeans.modules.xml.api.model.*;
18
import org.netbeans.modules.xml.api.model.*;
19
import org.openide.util.enum.SingletonEnumeration;
20
import org.w3c.dom.Node;
19
import org.w3c.dom.Node;
21
import org.w3c.dom.Element;
20
import org.w3c.dom.Element;
22
import org.xml.sax.InputSource;
21
import org.xml.sax.InputSource;
Lines 37-43 Link Here
37
                // XXX should also check for any root <project> in NS "antlib:org.apache.tools.ant"
36
                // XXX should also check for any root <project> in NS "antlib:org.apache.tools.ant"
38
                // (but no NS support in HintContext impl anyway: #38340)
37
                // (but no NS support in HintContext impl anyway: #38340)
39
                if ("project".equals(root.getNodeName()) && root.getAttributeNode("default") != null) { // NOI18N
38
                if ("project".equals(root.getNodeName()) && root.getAttributeNode("default") != null) { // NOI18N
40
                    return new SingletonEnumeration(next);
39
                    return org.openide.util.Enumerations.singleton (next);
41
                }
40
                }
42
            }
41
            }
43
        }
42
        }
(-)apisupport/src/org/netbeans/modules/apisupport/layers/WritableXMLFileSystem.java (-2 / +2 lines)
Lines 27-33 Link Here
27
import org.openide.filesystems.*;
27
import org.openide.filesystems.*;
28
import org.openide.filesystems.FileSystem;
28
import org.openide.filesystems.FileSystem;
29
import org.openide.util.*;
29
import org.openide.util.*;
30
import org.openide.util.enum.EmptyEnumeration;
30
import org.openide.util.Enumerations;
31
import org.openide.util.io.*;
31
import org.openide.util.io.*;
32
32
33
import org.w3c.dom.*;
33
import org.w3c.dom.*;
Lines 551-557 Link Here
551
    
551
    
552
    public Enumeration attributes (String name) {
552
    public Enumeration attributes (String name) {
553
        Element el = findElement (name);
553
        Element el = findElement (name);
554
        if (el == null) return EmptyEnumeration.EMPTY;
554
        if (el == null) return Enumerations.EMPTY;
555
        NodeList nl = el.getChildNodes ();
555
        NodeList nl = el.getChildNodes ();
556
        ArrayList l = new ArrayList (10); // List<String>
556
        ArrayList l = new ArrayList (10); // List<String>
557
        for (int i = 0; i < nl.getLength (); i++) {
557
        for (int i = 0; i < nl.getLength (); i++) {
(-)core/ide/src/org/netbeans/core/upgrade/CopyUtil.java (-1 / +1 lines)
Lines 734-740 Link Here
734
        public void deleteAttributes (String name) {
734
        public void deleteAttributes (String name) {
735
        }
735
        }
736
        public Enumeration attributes (String name) {
736
        public Enumeration attributes (String name) {
737
            return org.openide.util.enum.EmptyEnumeration.EMPTY;
737
            return org.openide.util.Enumerations.EMPTY;
738
        }
738
        }
739
        public void renameAttributes (String oldName, String newName) {
739
        public void renameAttributes (String oldName, String newName) {
740
        }
740
        }
(-)core/src/org/netbeans/beaninfo/editors/DataFolderPanel.java (-5 / +4 lines)
Lines 36-42 Link Here
36
import org.openide.explorer.propertysheet.editors.EnhancedCustomPropertyEditor;
36
import org.openide.explorer.propertysheet.editors.EnhancedCustomPropertyEditor;
37
import org.openide.filesystems.*;
37
import org.openide.filesystems.*;
38
import org.openide.util.HelpCtx;
38
import org.openide.util.HelpCtx;
39
import org.openide.util.enum.*;
40
import org.openide.windows.TopComponent;
39
import org.openide.windows.TopComponent;
41
40
42
/**
41
/**
Lines 493-502 Link Here
493
492
494
                system = new WeakReference (fs);
493
                system = new WeakReference (fs);
495
494
496
                Enumeration en = new SequenceEnumeration (
495
                Enumeration en = org.openide.util.Enumerations.concat (
497
                                     new SingletonEnumeration (fs.getSystemName()),
496
                    org.openide.util.Enumerations.singleton (fs.getSystemName()),
498
                                     st
497
                    st
499
                                 );
498
                );
500
499
501
                n = NodeOp.findPath (rootNode, en);
500
                n = NodeOp.findPath (rootNode, en);
502
                exact = true;
501
                exact = true;
(-)core/src/org/netbeans/beaninfo/editors/ExtensionListEditor.java (-2 / +1 lines)
Lines 21-27 Link Here
21
import org.openide.explorer.propertysheet.PropertyEnv;
21
import org.openide.explorer.propertysheet.PropertyEnv;
22
22
23
import org.openide.loaders.ExtensionList;
23
import org.openide.loaders.ExtensionList;
24
import org.openide.util.enum.ArrayEnumeration;
25
import org.openide.util.NbBundle;
24
import org.openide.util.NbBundle;
26
import org.openide.nodes.Node;
25
import org.openide.nodes.Node;
27
26
Lines 247-253 Link Here
247
     * @param value the new value of the property
246
     * @param value the new value of the property
248
     */
247
     */
249
    public void setStringArray(String[] nue) {
248
    public void setStringArray(String[] nue) {
250
        setAs (new ArrayEnumeration (nue));
249
        setAs (org.openide.util.Enumerations.array (nue));
251
    }
250
    }
252
251
253
    
252
    
(-)core/src/org/netbeans/core/LoaderPoolNode.java (-2 / +1 lines)
Lines 29-35 Link Here
29
import org.openide.actions.*;
29
import org.openide.actions.*;
30
import org.openide.nodes.*;
30
import org.openide.nodes.*;
31
import org.openide.util.actions.SystemAction;
31
import org.openide.util.actions.SystemAction;
32
import org.openide.util.enum.ArrayEnumeration;
33
import org.openide.util.*;
32
import org.openide.util.*;
34
import org.openide.util.io.*;
33
import org.openide.util.io.*;
35
import org.openide.modules.ModuleInfo;
34
import org.openide.modules.ModuleInfo;
Lines 803-809 Link Here
803
                    arr = loadersArray = loaders.toArray ();
802
                    arr = loadersArray = loaders.toArray ();
804
                }
803
                }
805
            }
804
            }
806
            return new ArrayEnumeration (arr);
805
            return org.openide.util.Enumerations.array (arr);
807
        }
806
        }
808
807
809
        /** Listener to property changes.
808
        /** Listener to property changes.
(-)core/src/org/netbeans/core/NotifyException.java (-1 lines)
Lines 26-32 Link Here
26
26
27
import org.openide.windows.*;
27
import org.openide.windows.*;
28
import org.openide.*;
28
import org.openide.*;
29
import org.openide.util.enum.*;
30
import org.openide.util.NbBundle;
29
import org.openide.util.NbBundle;
31
30
32
/**
31
/**
(-)core/src/org/netbeans/core/Services.java (-1 / +1 lines)
Lines 275-281 Link Here
275
    *    given class
275
    *    given class
276
    */
276
    */
277
    public Enumeration services (Class clazz) {
277
    public Enumeration services (Class clazz) {
278
        if (clazz == null) new org.openide.util.enum.EmptyEnumeration();
278
        if (clazz == null) return org.openide.util.Enumerations.EMPTY;
279
        Collection res = Lookup.getDefault().lookup(new Lookup.Template(clazz)).allInstances();
279
        Collection res = Lookup.getDefault().lookup(new Lookup.Template(clazz)).allInstances();
280
        return Collections.enumeration(res);
280
        return Collections.enumeration(res);
281
    }
281
    }
(-)core/src/org/netbeans/core/projects/FixedFileSystem.java (-3 / +2 lines)
Lines 20-26 Link Here
20
20
21
import org.openide.filesystems.*;
21
import org.openide.filesystems.*;
22
import org.openide.util.Lookup;
22
import org.openide.util.Lookup;
23
import org.openide.util.enum.EmptyEnumeration;
24
23
25
/** Read-only, fixed-structure filesystem.
24
/** Read-only, fixed-structure filesystem.
26
 * Derived from the ManifestFileSystem of yore (sandwich branch).
25
 * Derived from the ManifestFileSystem of yore (sandwich branch).
Lines 475-483 Link Here
475
        return Collections.enumeration (orderAttributes);*/
474
        return Collections.enumeration (orderAttributes);*/
476
        
475
        
477
        Instance inst = (Instance) instances.get (name);
476
        Instance inst = (Instance) instances.get (name);
478
        if (inst == null) return EmptyEnumeration.EMPTY;
477
        if (inst == null) return org.openide.util.Enumerations.EMPTY;
479
        Map m = inst.attributes;
478
        Map m = inst.attributes;
480
        if (m == null) return EmptyEnumeration.EMPTY;
479
        if (m == null) return org.openide.util.Enumerations.EMPTY;
481
        return Collections.enumeration(m.keySet());
480
        return Collections.enumeration(m.keySet());
482
481
483
//        return EmptyEnumeration.EMPTY;
482
//        return EmptyEnumeration.EMPTY;
(-)core/src/org/netbeans/core/projects/cache/BinaryFS.java (-2 / +1 lines)
Lines 24-30 Link Here
24
import org.openide.util.Lookup;
24
import org.openide.util.Lookup;
25
import org.openide.util.SharedClassObject;
25
import org.openide.util.SharedClassObject;
26
import org.openide.util.actions.SystemAction;
26
import org.openide.util.actions.SystemAction;
27
import org.openide.util.enum.EmptyEnumeration;
28
import org.openide.util.io.NbObjectInputStream;
27
import org.openide.util.io.NbObjectInputStream;
29
28
30
/**
29
/**
Lines 430-436 Link Here
430
        /** Get all file attribute names for this file. */
429
        /** Get all file attribute names for this file. */
431
        public Enumeration getAttributes() {
430
        public Enumeration getAttributes() {
432
            initialize();
431
            initialize();
433
            if (attrs == null) return EmptyEnumeration.EMPTY;
432
            if (attrs == null) return org.openide.util.Enumerations.EMPTY;
434
            return Collections.enumeration(attrs.keySet());
433
            return Collections.enumeration(attrs.keySet());
435
        }
434
        }
436
        
435
        
(-)core/src/org/netbeans/core/ui/ProductInformationPanel.java (-3 / +3 lines)
Lines 488-498 Link Here
488
        if (nbdirs != null) {
488
        if (nbdirs != null) {
489
            more = new java.util.StringTokenizer (nbdirs, File.pathSeparator);
489
            more = new java.util.StringTokenizer (nbdirs, File.pathSeparator);
490
        } else {
490
        } else {
491
            more = org.openide.util.enum.EmptyEnumeration.EMPTY;
491
            more = org.openide.util.Enumerations.EMPTY;
492
        }
492
        }
493
            
493
            
494
        java.util.Enumeration all = new org.openide.util.enum.SequenceEnumeration (
494
        java.util.Enumeration all = org.openide.util.Enumerations.concat (
495
            new org.openide.util.enum.SingletonEnumeration (nbhome), more
495
            org.openide.util.Enumerations.singleton (nbhome), more
496
        );
496
        );
497
        
497
        
498
        java.util.HashSet files = new java.util.HashSet ();
498
        java.util.HashSet files = new java.util.HashSet ();
(-)core/ide/src/org/netbeans/core/upgrade/CopyUtil.java (-1 / +1 lines)
Lines 734-740 Link Here
734
        public void deleteAttributes (String name) {
734
        public void deleteAttributes (String name) {
735
        }
735
        }
736
        public Enumeration attributes (String name) {
736
        public Enumeration attributes (String name) {
737
            return org.openide.util.enum.EmptyEnumeration.EMPTY;
737
            return org.openide.util.Enumerations.EMPTY;
738
        }
738
        }
739
        public void renameAttributes (String oldName, String newName) {
739
        public void renameAttributes (String oldName, String newName) {
740
        }
740
        }
(-)editor/src/org/netbeans/modules/editor/java/JCExtension.java (-1 lines)
Lines 59-65 Link Here
59
import org.openide.filesystems.FileSystem;
59
import org.openide.filesystems.FileSystem;
60
import org.openide.src.JavaDoc;
60
import org.openide.src.JavaDoc;
61
import org.openide.src.JavaDocTag;
61
import org.openide.src.JavaDocTag;
62
import org.openide.util.enum.QueueEnumeration;
63
62
64
/**
63
/**
65
* Extended Java Completion support
64
* Extended Java Completion support
(-)editor/src/org/netbeans/modules/editor/java/JCUpdater.java (-8 / +7 lines)
Lines 33-39 Link Here
33
import org.openide.cookies.SourceCookie;
33
import org.openide.cookies.SourceCookie;
34
import org.openide.filesystems.FileObject;
34
import org.openide.filesystems.FileObject;
35
import org.openide.util.NbBundle;
35
import org.openide.util.NbBundle;
36
import org.openide.util.enum.QueueEnumeration;
37
import org.netbeans.editor.ext.java.JCClassProvider2;
36
import org.netbeans.editor.ext.java.JCClassProvider2;
38
import org.netbeans.editor.ext.java.JCFinder;
37
import org.netbeans.editor.ext.java.JCFinder;
39
import org.netbeans.editor.ext.java.JCPackage;
38
import org.netbeans.editor.ext.java.JCPackage;
Lines 168-174 Link Here
168
     * @return false when process was either interrupted or cancelled by user in UI
167
     * @return false when process was either interrupted or cancelled by user in UI
169
     */
168
     */
170
    private boolean processDataObject(DataObject d) {
169
    private boolean processDataObject(DataObject d) {
171
        QueueEnumeration qe = new QueueEnumeration();
170
        java.util.LinkedList qe = new java.util.LinkedList();
172
        
171
        
173
        // Fill in queue. Two types of objects are acceptable: 
172
        // Fill in queue. Two types of objects are acceptable: 
174
        // - DataFolders containing at least one object with SourceCookie
173
        // - DataFolders containing at least one object with SourceCookie
Lines 188-194 Link Here
188
                cnt = 1;
187
                cnt = 1;
189
                // Updating has been invoked on Java source object.
188
                // Updating has been invoked on Java source object.
190
                // This happens mainly during automatic parsing of modified sources
189
                // This happens mainly during automatic parsing of modified sources
191
                qe.put(sc);
190
                qe.add(sc);
192
            }
191
            }
193
        }
192
        }
194
        
193
        
Lines 212-218 Link Here
212
        return result;
211
        return result;
213
    }
212
    }
214
213
215
    private boolean inspectFolder(DataFolder df, QueueEnumeration qe) {
214
    private boolean inspectFolder(DataFolder df, java.util.LinkedList qe) {
216
        DataObject[] children = df.getChildren();
215
        DataObject[] children = df.getChildren();
217
        children = (DataObject[])children.clone();
216
        children = (DataObject[])children.clone();
218
        
217
        
Lines 239-245 Link Here
239
        // we used to take into the consideration only valid folders (which contains JAVA sources... ),
238
        // we used to take into the consideration only valid folders (which contains JAVA sources... ),
240
        // but for performance reasons this was changed and now all folders are
239
        // but for performance reasons this was changed and now all folders are
241
        // put into queue.
240
        // put into queue.
242
        qe.put(df);
241
        qe.add (df);
243
        doneCnt++;
242
        doneCnt++;
244
        
243
        
245
        return true;
244
        return true;
Lines 404-410 Link Here
404
    }
403
    }
405
404
406
    /** Update memory and Code Completion Database after save document event */
405
    /** Update memory and Code Completion Database after save document event */
407
    private boolean updateProvider(final QueueEnumeration qe, final int classCnt) {
406
    private boolean updateProvider(final java.util.LinkedList qe, final int classCnt) {
408
        Map lookupCacheBkg = new HashMap(89);
407
        Map lookupCacheBkg = new HashMap(89);
409
        
408
        
410
        JCClassProvider prov = element.getProvider();
409
        JCClassProvider prov = element.getProvider();
Lines 418-425 Link Here
418
        }
417
        }
419
        
418
        
420
        doneCnt = 0;
419
        doneCnt = 0;
421
        while (qe.hasMoreElements()) {
420
        while (!qe.isEmpty ()) {
422
            Object ob = qe.nextElement();
421
            Object ob = qe.removeFirst ();
423
            if (ob instanceof DataFolder) {
422
            if (ob instanceof DataFolder) {
424
                DataObject[] children = ((DataFolder)(ob)).getChildren();
423
                DataObject[] children = ((DataFolder)(ob)).getChildren();
425
                doneCnt++;
424
                doneCnt++;
(-)httpserver/httpserver4/src/org/netbeans/modules/httpserver/NbBaseServlet.java (-15 / +13 lines)
Lines 29-38 Link Here
29
import javax.servlet.http.*;
29
import javax.servlet.http.*;
30
30
31
import org.openide.util.NbBundle;
31
import org.openide.util.NbBundle;
32
import org.openide.util.enum.AlterEnumeration;
33
import org.openide.util.enum.EmptyEnumeration;
34
import org.openide.util.enum.RemoveDuplicatesEnumeration;
35
import org.openide.util.enum.SequenceEnumeration;
36
import org.openide.TopManager;
32
import org.openide.TopManager;
37
import org.openide.filesystems.FileObject;
33
import org.openide.filesystems.FileObject;
38
import org.openide.filesystems.FileUtil;
34
import org.openide.filesystems.FileUtil;
Lines 299-317 Link Here
299
        Enumeration en = TopManager.getDefault ().getRepository ().getFileSystems ();
295
        Enumeration en = TopManager.getDefault ().getRepository ().getFileSystems ();
300
        // only not hidden filesystems containing the folder are counted
296
        // only not hidden filesystems containing the folder are counted
301
        // creates enumeration of enumerations of FileObjects
297
        // creates enumeration of enumerations of FileObjects
302
        en = new AlterEnumeration (en) {
298
        class EEFO implements org.openide.util.Enumerations.Processor {
303
                 public Object alter (Object o) {
299
            public Object process (Object obj, Collection coll) {
304
                     FileSystem fs = (FileSystem)o;
300
                 FileSystem fs = (FileSystem)o;
305
                     if (fs.isHidden ()) return EmptyEnumeration.EMPTY;
301
                 if (fs.isHidden ()) return org.openide.util.Enumerations.EMPTY;
306
302
307
                     FileObject fo = fs.findResource (name);
303
                 FileObject fo = fs.findResource (name);
308
                     if (fo == null || !fo.isFolder ()) return EmptyEnumeration.EMPTY;
304
                 if (fo == null || !fo.isFolder ()) return org.openide.util.Enumerations.EMPTY;
309
                     return fo.getChildren (false);
305
                 return fo.getChildren (false);
310
                 }
306
            }
311
             };
307
        }
312
308
313
        // composes enumerations into one
309
        // composes enumerations into one
314
        return new SequenceEnumeration (en);
310
        return org.openide.util.Enumerations.concat (
311
            org.openide.util.Enumerations.convert (en, new EEFO ())
312
        );
315
    }
313
    }
316
314
317
    /** Copy Stream in to Stream until EOF or exception
315
    /** Copy Stream in to Stream until EOF or exception
(-)httpserver/src/org/netbeans/modules/httpserver/NbBaseServlet.java (-3 lines)
Lines 28-36 Link Here
28
import javax.servlet.http.*;
28
import javax.servlet.http.*;
29
29
30
import org.openide.util.NbBundle;
30
import org.openide.util.NbBundle;
31
import org.openide.util.enum.AlterEnumeration;
32
import org.openide.util.enum.EmptyEnumeration;
33
import org.openide.util.enum.SequenceEnumeration;
34
import org.openide.ErrorManager;
31
import org.openide.ErrorManager;
35
import org.openide.filesystems.FileObject;
32
import org.openide.filesystems.FileObject;
36
import org.openide.filesystems.FileUtil;
33
import org.openide.filesystems.FileUtil;
(-)httpserver/httpserver4/src/org/netbeans/modules/httpserver/NbBaseServlet.java (-15 / +13 lines)
Lines 29-38 Link Here
29
import javax.servlet.http.*;
29
import javax.servlet.http.*;
30
30
31
import org.openide.util.NbBundle;
31
import org.openide.util.NbBundle;
32
import org.openide.util.enum.AlterEnumeration;
33
import org.openide.util.enum.EmptyEnumeration;
34
import org.openide.util.enum.RemoveDuplicatesEnumeration;
35
import org.openide.util.enum.SequenceEnumeration;
36
import org.openide.TopManager;
32
import org.openide.TopManager;
37
import org.openide.filesystems.FileObject;
33
import org.openide.filesystems.FileObject;
38
import org.openide.filesystems.FileUtil;
34
import org.openide.filesystems.FileUtil;
Lines 299-317 Link Here
299
        Enumeration en = TopManager.getDefault ().getRepository ().getFileSystems ();
295
        Enumeration en = TopManager.getDefault ().getRepository ().getFileSystems ();
300
        // only not hidden filesystems containing the folder are counted
296
        // only not hidden filesystems containing the folder are counted
301
        // creates enumeration of enumerations of FileObjects
297
        // creates enumeration of enumerations of FileObjects
302
        en = new AlterEnumeration (en) {
298
        class EEFO implements org.openide.util.Enumerations.Processor {
303
                 public Object alter (Object o) {
299
            public Object process (Object obj, Collection coll) {
304
                     FileSystem fs = (FileSystem)o;
300
                 FileSystem fs = (FileSystem)o;
305
                     if (fs.isHidden ()) return EmptyEnumeration.EMPTY;
301
                 if (fs.isHidden ()) return org.openide.util.Enumerations.EMPTY;
306
302
307
                     FileObject fo = fs.findResource (name);
303
                 FileObject fo = fs.findResource (name);
308
                     if (fo == null || !fo.isFolder ()) return EmptyEnumeration.EMPTY;
304
                 if (fo == null || !fo.isFolder ()) return org.openide.util.Enumerations.EMPTY;
309
                     return fo.getChildren (false);
305
                 return fo.getChildren (false);
310
                 }
306
            }
311
             };
307
        }
312
308
313
        // composes enumerations into one
309
        // composes enumerations into one
314
        return new SequenceEnumeration (en);
310
        return org.openide.util.Enumerations.concat (
311
            org.openide.util.Enumerations.convert (en, new EEFO ())
312
        );
315
    }
313
    }
316
314
317
    /** Copy Stream in to Stream until EOF or exception
315
    /** Copy Stream in to Stream until EOF or exception
(-)jarpackager/src/org/netbeans/modules/jarpackager/JarContent.java (-1 lines)
Lines 29-35 Link Here
29
import org.openide.loaders.DataObjectNotFoundException;
29
import org.openide.loaders.DataObjectNotFoundException;
30
import org.openide.loaders.DataFolder;
30
import org.openide.loaders.DataFolder;
31
import org.openide.nodes.Node;
31
import org.openide.nodes.Node;
32
import org.openide.util.enum.RemoveDuplicatesEnumeration;
33
import org.openide.util.NbBundle;
32
import org.openide.util.NbBundle;
34
import org.openide.ErrorManager;
33
import org.openide.ErrorManager;
35
34
(-)jarpackager/src/org/netbeans/modules/jarpackager/JarCreator.java (-4 / +3 lines)
Lines 29-35 Link Here
29
import org.openide.cookies.InstanceCookie;
29
import org.openide.cookies.InstanceCookie;
30
import org.openide.cookies.InstanceCookie.Of;
30
import org.openide.cookies.InstanceCookie.Of;
31
import org.openide.loaders.MultiDataObject;
31
import org.openide.loaders.MultiDataObject;
32
import org.openide.util.enum.RemoveDuplicatesEnumeration;
33
import org.openide.execution.NbClassPath;
32
import org.openide.execution.NbClassPath;
34
import org.openide.util.NbBundle;
33
import org.openide.util.NbBundle;
35
import org.openide.ErrorManager;
34
import org.openide.ErrorManager;
Lines 849-857 Link Here
849
      }
848
      }
850
      if (dobj != null && dobj instanceof DataFolder) {
849
      if (dobj != null && dobj instanceof DataFolder) {
851
        DataFolder folder = (DataFolder)dobj;
850
        DataFolder folder = (DataFolder)dobj;
852
        java.util.Enumeration enum = folder.children();
851
        java.util.Enumeration enx = folder.children();
853
        while (enum.hasMoreElements()) {
852
        while (enx.hasMoreElements()) {
854
          Object obj = enum.nextElement();
853
          Object obj = enx.nextElement();
855
          if (obj instanceof InstanceDataObject) {
854
          if (obj instanceof InstanceDataObject) {
856
            InstanceDataObject ido = (InstanceDataObject)obj;
855
            InstanceDataObject ido = (InstanceDataObject)obj;
857
            if (ido.isValid()) {
856
            if (ido.isValid()) {
(-)openide/loaders/src/org/openide/actions/FileSystemAction.java (-13 / +16 lines)
Lines 33-39 Link Here
33
import org.openide.nodes.Node;
33
import org.openide.nodes.Node;
34
import org.openide.util.Lookup;
34
import org.openide.util.Lookup;
35
import org.openide.util.NbBundle;
35
import org.openide.util.NbBundle;
36
import org.openide.util.enum.*;
37
36
38
37
39
/** Action that presents standard file system-related actions.
38
/** Action that presents standard file system-related actions.
Lines 94-103 Link Here
94
            /* At present not allowed to construct actions for selected nodes on more filesystems - its safe behaviour
93
            /* At present not allowed to construct actions for selected nodes on more filesystems - its safe behaviour
95
             * If this restriction will be considered as right solution, then code of this method can be simplified
94
             * If this restriction will be considered as right solution, then code of this method can be simplified
96
             */
95
             */
97
            if (fsSet.size () == 0 || fsSet.size() > 1) return createMenu (EmptyEnumeration.EMPTY, popUp, lookup);
96
            if (fsSet.size () == 0 || fsSet.size() > 1) return createMenu (org.openide.util.Enumerations.EMPTY, popUp, lookup);
98
            
97
            
99
            Iterator entrySetIt = fsSet.entrySet ().iterator();
98
            Iterator entrySetIt = fsSet.entrySet ().iterator();
100
            QueueEnumeration result = new QueueEnumeration();
99
            LinkedList result = new LinkedList ();
101
100
102
            while (entrySetIt.hasNext()) {
101
            while (entrySetIt.hasNext()) {
103
                Map.Entry entry = (Map.Entry)entrySetIt.next();
102
                Map.Entry entry = (Map.Entry)entrySetIt.next();
Lines 121-131 Link Here
121
                }
120
                }
122
                Set backSet = new OrderedSet();
121
                Set backSet = new OrderedSet();
123
                backSet.addAll(backupList);
122
                backSet.addAll(backupList);
124
                result.put( fs.getActions (backSet) );
123
                result.addAll (java.util.Arrays.asList (fs.getActions (backSet)));
125
            }
124
            }
126
            
125
            
127
            
126
            
128
            return createMenu ( result, popUp, lookup);
127
            return createMenu (Collections.enumeration (result), popUp, lookup);
129
        }
128
        }
130
        return NONE;
129
        return NONE;
131
    }
130
    }
Lines 136-142 Link Here
136
    *   into the menu if enabled and if not duplicated
135
    *   into the menu if enabled and if not duplicated
137
    */
136
    */
138
    static JMenuItem[] createMenu (Enumeration en, boolean popUp, Lookup lookup) {
137
    static JMenuItem[] createMenu (Enumeration en, boolean popUp, Lookup lookup) {
139
        en = new RemoveDuplicatesEnumeration (en);
138
        en = org.openide.util.Enumerations.removeDuplicates (en);
140
139
141
        ArrayList items = new ArrayList ();
140
        ArrayList items = new ArrayList ();
142
        while (en.hasMoreElements ()) {
141
        while (en.hasMoreElements ()) {
Lines 306-312 Link Here
306
    private static final class OrderedSet extends AbstractSet {
305
    private static final class OrderedSet extends AbstractSet {
307
        
306
        
308
        /** Queue of collections of elements. */
307
        /** Queue of collections of elements. */
309
        private QueueEnumeration queue = new QueueEnumeration();
308
        private LinkedList queue = new LinkedList ();
310
        /** Objects stored in this set. */
309
        /** Objects stored in this set. */
311
        Object[] objects = null;
310
        Object[] objects = null;
312
        
311
        
Lines 318-337 Link Here
318
         * Adds all of the elements in the specified collection to this collection.
317
         * Adds all of the elements in the specified collection to this collection.
319
         */
318
         */
320
        public boolean addAll(Collection coll) {
319
        public boolean addAll(Collection coll) {
321
            queue.put(coll);
320
            queue.add (coll);
322
            return true;
321
            return true;
323
        }
322
        }
324
        
323
        
325
        
324
        
326
        private Object[] getObjects() {
325
        private Object[] getObjects() {
327
            if (objects == null) {
326
            if (objects == null) {
328
                AlterEnumeration altered = new AlterEnumeration(queue) {
327
                class Coll2Enum implements org.openide.util.Enumerations.Processor {
329
                    public Object alter(Object obj) {
328
                    public Object process (Object obj, java.util.Collection ignore) {
330
                        return Collections.enumeration((Collection) obj);
329
                        return Collections.enumeration((Collection) obj);
331
                    }
330
                    }
332
                };
331
                }
333
                SequenceEnumeration sequenced = new SequenceEnumeration(altered);
332
                Enumeration sequenced = org.openide.util.Enumerations.concat (
334
                Enumeration result = new RemoveDuplicatesEnumeration(sequenced);
333
                    org.openide.util.Enumerations.convert (
334
                        Collections.enumeration (queue), new Coll2Enum ()
335
                    )
336
                );
337
                Enumeration result = org.openide.util.Enumerations.removeDuplicates (sequenced);
335
                ArrayList objectList = new ArrayList();
338
                ArrayList objectList = new ArrayList();
336
                for (int i = 0; result.hasMoreElements(); i++) {
339
                for (int i = 0; result.hasMoreElements(); i++) {
337
                    objectList.add(result.nextElement());
340
                    objectList.add(result.nextElement());
(-)openide/loaders/src/org/openide/loaders/DataFolder.java (-21 / +15 lines)
Lines 35-41 Link Here
35
import org.openide.util.HelpCtx;
35
import org.openide.util.HelpCtx;
36
import org.openide.nodes.*;
36
import org.openide.nodes.*;
37
import org.openide.util.Lookup;
37
import org.openide.util.Lookup;
38
import org.openide.util.enum.QueueEnumeration;
39
import org.openide.util.NbBundle;
38
import org.openide.util.NbBundle;
40
import org.openide.util.RequestProcessor;
39
import org.openide.util.RequestProcessor;
41
40
Lines 277-303 Link Here
277
        if (!rec) {
276
        if (!rec) {
278
            return children();
277
            return children();
279
        }
278
        }
280
        QueueEnumeration en = new QueueEnumeration () {
279
        
281
                                  /** @param o processes object by adding its children to the queue */
280
        class Processor implements org.openide.util.Enumerations.Processor {
282
                                  public void process (Object o) {
281
            /** @param o processes object by adding its children to the queue */
283
                                      DataObject dataObj = (DataObject)o;
282
            public Object process (Object o, Collection toAdd) {
284
                                      if (rec && dataObj instanceof DataFolder) {
283
                DataObject dataObj = (DataObject)o;
285
                                          addChildrenToEnum(this, ((DataFolder)dataObj).getChildren());
284
                if (rec && dataObj instanceof DataFolder) {
286
                                      }
285
                    toAdd.addAll (Arrays.asList (((DataFolder)dataObj).getChildren()));
287
                                  }
286
                }
288
                              };
287
                return o;
289
        addChildrenToEnum(en, getChildren());
288
            }
290
        return en;
291
    }
292
293
    /** Puts children into QueueEnumeration.
294
    * @param en the queue enumeration to add children to
295
    * @param list array of data objects
296
    */
297
    static void addChildrenToEnum (QueueEnumeration en, DataObject[] list) {
298
        for (int i = 0; i < list.length; i++) {
299
            en.put(list[i]);
300
        }
289
        }
290
        Enumeration en = org.openide.util.Enumerations.queue (
291
            org.openide.util.Enumerations.array (getChildren ()),
292
            new Processor ()
293
        );
294
        return en;
301
    }
295
    }
302
296
303
    /** Create node representative for this folder.
297
    /** Create node representative for this folder.
(-)openide/loaders/src/org/openide/loaders/DataLoaderPool.java (-19 / +17 lines)
Lines 30-39 Link Here
30
import org.openide.nodes.Node;
30
import org.openide.nodes.Node;
31
import org.openide.nodes.FilterNode;
31
import org.openide.nodes.FilterNode;
32
import org.openide.modules.ModuleInfo;
32
import org.openide.modules.ModuleInfo;
33
import org.openide.util.enum.ArrayEnumeration;
33
import org.openide.util.Enumerations;
34
import org.openide.util.enum.FilterEnumeration;
35
import org.openide.util.enum.SingletonEnumeration;
36
import org.openide.util.enum.SequenceEnumeration;
37
import org.openide.util.actions.SystemAction;
34
import org.openide.util.actions.SystemAction;
38
import org.openide.util.NbBundle;
35
import org.openide.util.NbBundle;
39
import org.openide.util.Lookup;
36
import org.openide.util.Lookup;
Lines 230-250 Link Here
230
    public final Enumeration allLoaders () {
227
    public final Enumeration allLoaders () {
231
	if (preferredLoader == null) {
228
	if (preferredLoader == null) {
232
            // enumeration of systemloaders followed by normal loaders
229
            // enumeration of systemloaders followed by normal loaders
233
	    return new SequenceEnumeration (
230
	    return Enumerations.concat (
234
		new ArrayEnumeration ( new Enumeration[] {
231
		Enumerations.array ( new Enumeration[] {
235
    		    new ArrayEnumeration (getSystemLoaders ()),
232
    		    Enumerations.array (getSystemLoaders ()),
236
    		    loaders (),
233
    		    loaders (),
237
    		    new ArrayEnumeration (getDefaultLoaders ())
234
    		    Enumerations.array (getDefaultLoaders ())
238
		} )
235
		} )
239
	    );
236
	    );
240
	} else {
237
	} else {
241
            // enumeration of preferred loader folowed by systemloaders and normal loaders
238
            // enumeration of preferred loader folowed by systemloaders and normal loaders
242
	    return new SequenceEnumeration (
239
	    return Enumerations.concat (
243
		new ArrayEnumeration ( new Enumeration[] {
240
		Enumerations.array ( new Enumeration[] {
244
        	    new SingletonEnumeration (preferredLoader),
241
        	    Enumerations.singleton (preferredLoader),
245
    		    new ArrayEnumeration (getSystemLoaders ()),
242
    		    Enumerations.array (getSystemLoaders ()),
246
    		    loaders (),
243
    		    loaders (),
247
    		    new ArrayEnumeration (getDefaultLoaders ())
244
    		    Enumerations.array (getDefaultLoaders ())
248
		} )
245
		} )
249
	    );
246
	    );
250
	}
247
	}
Lines 297-310 Link Here
297
     * @return enumeration of {@link DataLoader}s
294
     * @return enumeration of {@link DataLoader}s
298
     */
295
     */
299
    public final Enumeration producersOf (final Class clazz) {
296
    public final Enumeration producersOf (final Class clazz) {
300
        return new FilterEnumeration (allLoaders ()) {
297
        class ProducerOf implements Enumerations.Processor {
301
                   /** Accepts only those loaders that produces superclass of clazz
298
            public Object process (Object o, java.util.Collection ignore) {
302
                    */
303
            public boolean accept (Object o) {
304
                DataLoader dl = (DataLoader)o;
299
                DataLoader dl = (DataLoader)o;
305
                return clazz.isAssignableFrom( dl.getRepresentationClass() );
300
                return clazz.isAssignableFrom( dl.getRepresentationClass() ) ? o : null;
306
            }
301
            }
307
        };
302
        }
303
        
304
        // Accepts only those loaders that produces superclass of clazz
305
        return Enumerations.filter (allLoaders (), new ProducerOf ());
308
    }
306
    }
309
    
307
    
310
    
308
    
(-)openide/loaders/src/org/openide/loaders/DataObject.java (-1 lines)
Lines 31-37 Link Here
31
import org.openide.filesystems.*;
31
import org.openide.filesystems.*;
32
import org.openide.filesystems.FileSystem; // override java.io.FileSystem
32
import org.openide.filesystems.FileSystem; // override java.io.FileSystem
33
import org.openide.util.*;
33
import org.openide.util.*;
34
import org.openide.util.enum.*;
35
import org.openide.nodes.*;
34
import org.openide.nodes.*;
36
35
37
/** Object that represents one or more file objects, with added behavior.
36
/** Object that represents one or more file objects, with added behavior.
(-)openide/loaders/src/org/openide/loaders/ExtensionList.java (-1 / +1 lines)
Lines 197-203 Link Here
197
     */
197
     */
198
    private static Enumeration en (Collection c) {
198
    private static Enumeration en (Collection c) {
199
        if (c == null) {
199
        if (c == null) {
200
            return org.openide.util.enum.EmptyEnumeration.EMPTY;
200
            return org.openide.util.Enumerations.EMPTY;
201
        } else {
201
        } else {
202
            return Collections.enumeration(c);
202
            return Collections.enumeration(c);
203
        }
203
        }
(-)openide/loaders/src/org/openide/loaders/FolderOrder.java (-2 / +3 lines)
Lines 20-26 Link Here
20
import java.util.*;
20
import java.util.*;
21
21
22
import org.openide.filesystems.*;
22
import org.openide.filesystems.*;
23
import org.openide.util.enum.*;
24
import org.openide.loaders.DataFolder.SortMode;
23
import org.openide.loaders.DataFolder.SortMode;
25
24
26
25
Lines 94-100 Link Here
94
            order = new HashMap (arr.length * 4 / 3 + 1);
93
            order = new HashMap (arr.length * 4 / 3 + 1);
95
94
96
            // each object only once
95
            // each object only once
97
            Enumeration en = new RemoveDuplicatesEnumeration (new ArrayEnumeration (arr));
96
            Enumeration en = org.openide.util.Enumerations.removeDuplicates (
97
                org.openide.util.Enumerations.array (arr)
98
            );
98
99
99
            int i = 0;
100
            int i = 0;
100
            while (en.hasMoreElements ()) {
101
            while (en.hasMoreElements ()) {
(-)openide/loaders/src/org/openide/loaders/InstanceDataObject.java (-1 / +1 lines)
Lines 1602-1608 Link Here
1602
        }
1602
        }
1603
1603
1604
        public java.util.Enumeration getAttributes() {
1604
        public java.util.Enumeration getAttributes() {
1605
            return fo == null? org.openide.util.enum.EmptyEnumeration.EMPTY: fo.getAttributes();
1605
            return fo == null? org.openide.util.Enumerations.EMPTY: fo.getAttributes();
1606
        }
1606
        }
1607
1607
1608
        public FileObject[] getChildren() {
1608
        public FileObject[] getChildren() {
(-)openide/masterfs/src/org/netbeans/modules/masterfs/Cache.java (-2 / +1 lines)
Lines 14-20 Link Here
14
package org.netbeans.modules.masterfs;
14
package org.netbeans.modules.masterfs;
15
15
16
import org.openide.filesystems.FileObject;
16
import org.openide.filesystems.FileObject;
17
import org.openide.util.enum.ArrayEnumeration;
18
17
19
import java.lang.ref.Reference;
18
import java.lang.ref.Reference;
20
import java.lang.ref.SoftReference;
19
import java.lang.ref.SoftReference;
Lines 124-130 Link Here
124
        }
123
        }
125
        final Object[] array = new Object[arrayList.size()];
124
        final Object[] array = new Object[arrayList.size()];
126
        arrayList.toArray(array);
125
        arrayList.toArray(array);
127
        return new ArrayEnumeration(array);
126
        return org.openide.util.Enumerations.array (array);
128
    }
127
    }
129
128
130
    void clear() {
129
    void clear() {
(-)openide/masterfs/src/org/netbeans/modules/masterfs/InvalidDummy.java (-2 / +1 lines)
Lines 14-20 Link Here
14
package org.netbeans.modules.masterfs;
14
package org.netbeans.modules.masterfs;
15
15
16
import org.openide.filesystems.*;
16
import org.openide.filesystems.*;
17
import org.openide.util.enum.EmptyEnumeration;
18
17
19
import java.io.FileNotFoundException;
18
import java.io.FileNotFoundException;
20
import java.io.IOException;
19
import java.io.IOException;
Lines 78-84 Link Here
78
    }
77
    }
79
78
80
    public Enumeration getAttributes() {
79
    public Enumeration getAttributes() {
81
        return EmptyEnumeration.EMPTY;
80
        return org.openide.util.Enumerations.EMPTY;
82
    }
81
    }
83
82
84
    public void addFileChangeListener(FileChangeListener fcl) {
83
    public void addFileChangeListener(FileChangeListener fcl) {
(-)openide/masterfs/src/org/netbeans/modules/masterfs/MasterFileObject.java (-33 / +53 lines)
Lines 18-26 Link Here
18
18
19
import org.openide.ErrorManager;
19
import org.openide.ErrorManager;
20
import org.openide.filesystems.*;
20
import org.openide.filesystems.*;
21
import org.openide.util.enum.ArrayEnumeration;
22
import org.openide.util.enum.FilterEnumeration;
23
import org.openide.util.enum.QueueEnumeration;
24
import org.openide.util.Utilities;
21
import org.openide.util.Utilities;
25
22
26
import javax.swing.event.EventListenerList;
23
import javax.swing.event.EventListenerList;
Lines 268-306 Link Here
268
     * Implements FileObject.transformChildren(boolean rec)
265
     * Implements FileObject.transformChildren(boolean rec)
269
     */
266
     */
270
    public Enumeration getChildren(boolean rec) {
267
    public Enumeration getChildren(boolean rec) {
268
        Enumeration my = org.openide.util.Enumerations.array (this.getChildren());
269
        
271
        if (rec == false)
270
        if (rec == false)
272
            return new ArrayEnumeration(this.getChildren());
271
            return my;
273
272
274
        QueueEnumeration en = getChildsEnum();
273
        return org.openide.util.Enumerations.queue (
275
        en.put(this.getChildren());
274
            my, getChildsEnum ()
276
        return en;
275
        );
277
    }
276
    }
278
277
279
    /**
278
    /**
280
     * Implements FileObject.getFolders(boolean rec)
279
     * Implements FileObject.getFolders(boolean rec)
281
     */
280
     */
282
    public Enumeration getFolders(boolean rec) {
281
    public Enumeration getFolders(boolean rec) {
283
        return new FilterEnumeration(getChildren(rec)) {
282
        return org.openide.util.Enumerations.filter (
284
            protected boolean accept(final Object o) {
283
            getChildren (rec), new AcceptFolders (true)
285
                final FileObject fo = (FileObject) o;
284
        );
286
                return fo.isFolder();
287
            }
288
        };
289
    }
285
    }
290
286
291
292
    /**
287
    /**
293
     * Implements FileObject.getData(boolean rec)
288
     * Implements FileObject.getData(boolean rec)
294
     */
289
     */
295
    public Enumeration getData(boolean rec) {
290
    public Enumeration getData(boolean rec) {
296
        return new FilterEnumeration(getChildren(rec)) {
291
        return org.openide.util.Enumerations.filter (
297
            protected boolean accept(final Object o) {
292
            getChildren (rec), new AcceptFolders (false)
298
                final FileObject fo = (FileObject) o;
293
        );
299
                return fo.isData();
300
            }
301
        };
302
    }
294
    }
303
295
296
    /** Selector from folders and data files.
297
     */
298
    private final class AcceptFolders implements org.openide.util.Enumerations.Processor {
299
        private boolean folders;
300
        
301
        public AcceptFolders (boolean folders) {
302
            this.folders = folders;
303
        }
304
        
305
        public Object process (Object o, Collection nothing) {
306
            final FileObject fo = (FileObject) o;
307
            if (folders) {
308
                return fo.isFolder() ? fo : null;
309
            } else {
310
                return fo.isData() ? fo : null;
311
            }
312
        }
313
    } // end of AcceptFolders
314
304
    /**
315
    /**
305
     * Implements abstract FileObject.getFileSystem()
316
     * Implements abstract FileObject.getFileSystem()
306
     */
317
     */
Lines 525-558 Link Here
525
    }
536
    }
526
537
527
538
528
    private QueueEnumeration getChildsEnum() {
539
    private org.openide.util.Enumerations.Processor getChildsEnum() {
529
        QueueEnumeration en = new QueueEnumeration() {
540
        return new org.openide.util.Enumerations.Processor  () {
530
            public void process(final Object o) {
541
            public Object process(final Object o, Collection toAdd) {
531
                final FileObject fo = (FileObject) o;
542
                final FileObject fo = (FileObject) o;
532
                if (fo != null)
543
                if (fo != null)
533
                    put(fo.getChildren());
544
                    toAdd.addAll (Arrays.asList (fo.getChildren()));
545
                return fo;
534
            }
546
            }
535
        };
547
        };
536
        return en;
537
    }
548
    }
538
549
539
550
540
    private Enumeration getEnumOfListeners() {
551
    private Enumeration getEnumOfListeners() {
541
        QueueEnumeration qE = new QueueEnumeration();
542
        Object[] fcls;
552
        Object[] fcls;
543
        synchronized (this) {
553
        synchronized (this) {
544
            if (listeners == null) return qE;
554
            if (listeners == null) {
555
                return org.openide.util.Enumerations.EMPTY;
556
            }
545
            fcls = listeners.getListenerList();
557
            fcls = listeners.getListenerList();
546
        }
558
        }
547
559
548
        if (fcls == null || fcls.length == 0) return qE;
560
        if (fcls == null || fcls.length == 0) {
549
        qE.put(fcls);
561
            return org.openide.util.Enumerations.EMPTY;
562
        }
550
563
551
        return new FilterEnumeration(qE) {
564
        class OnlyListeners implements org.openide.util.Enumerations.Processor {
552
            protected boolean accept(final Object o) {
565
            public Object process(final Object o, Collection toAdd) {
553
                return (o instanceof FileChangeListener) ? true : false;
566
                if (o instanceof FileChangeListener) {
567
                    return o;
568
                }
569
                return null;
554
            }
570
            }
555
        };
571
        }
572
        
573
        return org.openide.util.Enumerations.filter (
574
            org.openide.util.Enumerations.array (fcls), new OnlyListeners ()
575
        );
556
    }
576
    }
557
577
558
    FileSystem getDelegateFileSystem() {
578
    FileSystem getDelegateFileSystem() {
(-)openide/masterfs/src/org/netbeans/modules/masterfs/MountTable.java (-15 / +21 lines)
Lines 15-22 Link Here
15
15
16
import org.netbeans.modules.masterfs.providers.MountSupport;
16
import org.netbeans.modules.masterfs.providers.MountSupport;
17
import org.openide.filesystems.*;
17
import org.openide.filesystems.*;
18
import org.openide.util.enum.FilterEnumeration;
19
import org.openide.util.enum.QueueEnumeration;
20
18
21
import java.io.File;
19
import java.io.File;
22
import java.io.IOException;
20
import java.io.IOException;
Lines 136-142 Link Here
136
     * @return enumeration of mounted filesystems
134
     * @return enumeration of mounted filesystems
137
     */
135
     */
138
    Enumeration geAllFileSystems() {
136
    Enumeration geAllFileSystems() {
139
        final QueueEnumeration qE = new QueueEnumeration();
137
        final ArrayList qE = new ArrayList ();
140
        final Collection values = res2fsMap.values();
138
        final Collection values = res2fsMap.values();
141
        //SyncSection.getDefault().enterExclusiveSection();
139
        //SyncSection.getDefault().enterExclusiveSection();
142
        SyncSection.getDefault().enterSection();
140
        SyncSection.getDefault().enterSection();
Lines 145-158 Link Here
145
                for (Iterator it = values.iterator(); it.hasNext();) {
143
                for (Iterator it = values.iterator(); it.hasNext();) {
146
                    FileSystem fs = (FileSystem) it.next();
144
                    FileSystem fs = (FileSystem) it.next();
147
                    if (fs != null)
145
                    if (fs != null)
148
                        qE.put(fs);
146
                        qE.add (fs);
149
                }
147
                }
150
            }
148
            }
151
        } finally {
149
        } finally {
152
            //SyncSection.getDefault().finishExclusiveSection();
150
            //SyncSection.getDefault().finishExclusiveSection();
153
            SyncSection.getDefault().finishSection();
151
            SyncSection.getDefault().finishSection();
154
        }
152
        }
155
        return qE;
153
        return Collections.enumeration (qE);
156
    }
154
    }
157
155
158
    /**
156
    /**
Lines 248-280 Link Here
248
    }
246
    }
249
247
250
    private Enumeration getMountEnumeration(final String mountPointPath) {
248
    private Enumeration getMountEnumeration(final String mountPointPath) {
251
        return new FilterEnumeration(Cache.getDefault().getAll()) {
249
        class Mnt implements org.openide.util.Enumerations.Processor {
252
            protected boolean accept(final Object o) {
250
            public Object process (Object o, Collection ignore) {
253
                final MasterFileObject hfo = (MasterFileObject) o;
251
                final MasterFileObject hfo = (MasterFileObject) o;
254
                String normalizedMountPoint = ResourcePath.getNormalizedPath(mountPointPath);                
252
                String normalizedMountPoint = ResourcePath.getNormalizedPath(mountPointPath);                
255
                String normalizedResourcePath = hfo.getResource().getNormalizedPath();
253
                String normalizedResourcePath = hfo.getResource().getNormalizedPath();
256
                
254
                
257
                if (normalizedResourcePath.startsWith(normalizedMountPoint) && hfo.isValid()) {
255
                if (normalizedResourcePath.startsWith(normalizedMountPoint) && hfo.isValid()) {
258
                    return true;
256
                    return o;
259
                }
257
                }
260
                return false;
258
                return null;
261
            }
259
            }
262
        };
260
        }
261
        return org.openide.util.Enumerations.filter (
262
            Cache.getDefault().getAll(), 
263
            new Mnt ()
264
        );
263
    }
265
    }
264
266
265
    private static Enumeration getUnMountEnumeration(final FileSystem fs2Umount) {
267
    private static Enumeration getUnMountEnumeration(final FileSystem fs2Umount) {
266
        return new FilterEnumeration(Cache.getDefault().getAll()) {
268
        class UnMnt implements org.openide.util.Enumerations.Processor {
267
            protected boolean accept(final Object o) {
269
            public Object process (Object o, Collection ignore) {
268
                final MasterFileObject hfo = (MasterFileObject) o;
270
                final MasterFileObject hfo = (MasterFileObject) o;
269
                if (hfo != null && hfo.isValid()) {
271
                if (hfo != null && hfo.isValid()) {
270
                    FileSystem delgFs = hfo.getDelegateFileSystem();
272
                    FileSystem delgFs = hfo.getDelegateFileSystem();
271
                    if (delgFs == fs2Umount)
273
                    if (delgFs == fs2Umount)
272
                        return true;
274
                        return o;
273
275
274
                }
276
                }
275
                return false;
277
                return null;
276
            }
278
            }
277
        };
279
        }
280
        return org.openide.util.Enumerations.filter (
281
            Cache.getDefault().getAll(), 
282
            new UnMnt ()
283
        );
278
    }
284
    }
279
285
280
    FileSystem getMountedFileSystem(String resName) {
286
    FileSystem getMountedFileSystem(String resName) {
(-)openide/src/org/openide/ServiceType.java (-5 / +7 lines)
Lines 191-201 Link Here
191
        * @return an enumeration of all matching {@link ServiceType}s
191
        * @return an enumeration of all matching {@link ServiceType}s
192
        */
192
        */
193
        public Enumeration services (final Class clazz) {
193
        public Enumeration services (final Class clazz) {
194
            return new org.openide.util.enum.FilterEnumeration (services ()) {
194
            class IsInstance implements org.openide.util.Enumerations.Processor {
195
                       public boolean accept (Object o) {
195
                public Object process (Object obj, java.util.Collection ignore) {
196
                           return clazz.isInstance (o);
196
                    return clazz.isInstance (obj) ? obj : null;
197
                       }
197
                }
198
                   };
198
            }
199
            
200
            return org.openide.util.Enumerations.filter (services (), new IsInstance ());
199
        }
201
        }
200
202
201
        /** Getter for list of all service types.
203
        /** Getter for list of all service types.
(-)openide/src/org/openide/awt/UndoRedo.java (-7 / +20 lines)
Lines 13-22 Link Here
13
13
14
package org.openide.awt;
14
package org.openide.awt;
15
15
16
import java.util.LinkedList;
16
import javax.swing.event.*;
17
import javax.swing.event.*;
17
import javax.swing.undo.*;
18
import javax.swing.undo.*;
18
19
19
import org.openide.util.enum.*;
20
import org.openide.util.RequestProcessor;
20
import org.openide.util.RequestProcessor;
21
import org.openide.util.Task;
21
import org.openide.util.Task;
22
22
Lines 89-95 Link Here
89
        private final EventListenerList list = new EventListenerList ();
89
        private final EventListenerList list = new EventListenerList ();
90
        
90
        
91
        /** vector of Edits to run */
91
        /** vector of Edits to run */
92
        private QueueEnumeration runus = new QueueEnumeration (); // for fix of #8692
92
        private LinkedList runus = new LinkedList (); // for fix of #8692
93
        
93
        
94
        /** task that clears the queue */
94
        /** task that clears the queue */
95
        private Task task = Task.EMPTY; // for fix of #8692
95
        private Task task = Task.EMPTY; // for fix of #8692
Lines 120-132 Link Here
120
             * in #8692 between undoredo and document that fires
120
             * in #8692 between undoredo and document that fires
121
             * the undoable edit should be avoided this way.
121
             * the undoable edit should be avoided this way.
122
             */
122
             */
123
            runus.put (ue);
123
            synchronized (runus) {
124
                runus.add (ue);
125
            }
124
            updateTask();
126
            updateTask();
125
        }
127
        }
126
128
127
        /** Discard all the existing edits from the undomanager. */
129
        /** Discard all the existing edits from the undomanager. */
128
        public void discardAllEdits() {
130
        public void discardAllEdits() {
129
            runus.put ((Object)null);
131
            synchronized (runus) {
132
                runus.add (null);
133
            }
130
            updateTask();
134
            updateTask();
131
        }
135
        }
132
136
Lines 134-140 Link Here
134
            /* First it must be checked that there are
138
            /* First it must be checked that there are
135
             * undoable edits waiting to be added to undoredo.
139
             * undoable edits waiting to be added to undoredo.
136
             */
140
             */
137
            if (runus.hasMoreElements()) {
141
            boolean empty;
142
            synchronized (runus) {
143
                empty = runus.isEmpty ();
144
            }
145
            if (!empty) {
138
                task.waitFinished ();
146
                task.waitFinished ();
139
            }
147
            }
140
148
Lines 159-166 Link Here
159
            //Use internal not default RequestProcessor to solve deadlock #10826
167
            //Use internal not default RequestProcessor to solve deadlock #10826
160
            task = internalRequestProcessor.post (new Runnable () {
168
            task = internalRequestProcessor.post (new Runnable () {
161
                public void run () {
169
                public void run () {
162
                    while (runus.hasMoreElements ()) {
170
                    for (;;) {
163
			UndoableEditEvent ue = (UndoableEditEvent)runus.nextElement ();
171
			UndoableEditEvent ue;
172
                        synchronized (runus) {
173
                            if (runus.isEmpty ()) break;
174
                            ue = (UndoableEditEvent)runus.removeFirst ();
175
                        }
176
                        
164
			if (ue == null) {
177
			if (ue == null) {
165
                	    superDiscardAllEdits();
178
                	    superDiscardAllEdits();
166
			} else {
179
			} else {
(-)openide/src/org/openide/explorer/view/VisualizerNode.java (-6 / +5 lines)
Lines 28-34 Link Here
28
import org.openide.nodes.*;
28
import org.openide.nodes.*;
29
import org.openide.util.Mutex;
29
import org.openide.util.Mutex;
30
import org.openide.util.Utilities;
30
import org.openide.util.Utilities;
31
import org.openide.util.enum.QueueEnumeration;
32
31
33
/** Visual representation of one node. Holds necessary information about nodes
32
/** Visual representation of one node. Holds necessary information about nodes
34
* like icon, name, description and also list of its children. 
33
* like icon, name, description and also list of its children. 
Lines 490-496 Link Here
490
        /** queue of all requests (Runnable) that should be processed
489
        /** queue of all requests (Runnable) that should be processed
491
         * AWT-Event queue.
490
         * AWT-Event queue.
492
         */
491
         */
493
        private QueueEnumeration queue = null;
492
        private LinkedList queue = null;
494
493
495
        /** Runs the runnable in event thread.
494
        /** Runs the runnable in event thread.
496
         * @param run what should run
495
         * @param run what should run
Lines 501-510 Link Here
501
            synchronized (this) {
500
            synchronized (this) {
502
                // access to queue variable is synchronized
501
                // access to queue variable is synchronized
503
                if (queue == null) {
502
                if (queue == null) {
504
                    queue = new QueueEnumeration ();
503
                    queue = new LinkedList ();
505
                    isNew = true;
504
                    isNew = true;
506
                }
505
                }
507
                queue.put (run);
506
                queue.add (run);
508
            }
507
            }
509
            
508
            
510
            if (isNew) {
509
            if (isNew) {
Lines 518-527 Link Here
518
        /** Processes the queue.
517
        /** Processes the queue.
519
         */ 
518
         */ 
520
        public void run () {
519
        public void run () {
521
            QueueEnumeration en;
520
            Enumeration en;
522
            synchronized (this) {
521
            synchronized (this) {
523
                // access to queue variable is synchronized
522
                // access to queue variable is synchronized
524
                en = queue;
523
                en = Collections.enumeration (queue);
525
                queue = null;
524
                queue = null;
526
            }
525
            }
527
  
526
  
(-)openide/src/org/openide/filesystems/AbstractFileObject.java (-3 / +2 lines)
Lines 16-23 Link Here
16
import java.io.*;
16
import java.io.*;
17
import java.util.*;
17
import java.util.*;
18
import java.lang.ref.*;
18
import java.lang.ref.*;
19
19
import org.openide.util.Enumerations;
20
import org.openide.util.enum.*;
21
20
22
/** Implementation of the file object for abstract file system.
21
/** Implementation of the file object for abstract file system.
23
*
22
*
Lines 990-996 Link Here
990
        * @return enumeration of keys (as strings)
989
        * @return enumeration of keys (as strings)
991
        */
990
        */
992
        public Enumeration getAttributes() {
991
        public Enumeration getAttributes() {
993
            return EmptyEnumeration.EMPTY;
992
            return Enumerations.EMPTY;
994
        }
993
        }
995
994
996
995
(-)openide/src/org/openide/filesystems/AbstractFileSystem.java (-43 / +23 lines)
Lines 23-29 Link Here
23
23
24
import org.openide.util.actions.SystemAction;
24
import org.openide.util.actions.SystemAction;
25
import org.openide.util.SharedClassObject;
25
import org.openide.util.SharedClassObject;
26
import org.openide.util.enum.*;
27
26
28
/** Implementation of <code>FileSystem</code> that simplifies the most
27
/** Implementation of <code>FileSystem</code> that simplifies the most
29
* common tasks. Caches information about the filesystem in
28
* common tasks. Caches information about the filesystem in
Lines 117-126 Link Here
117
            FileObject fo = getAbstractRoot ().find (st);
116
            FileObject fo = getAbstractRoot ().find (st);
118
            return fo != null && fo.isFolder() ? fo : null;
117
            return fo != null && fo.isFolder() ? fo : null;
119
        } else {
118
        } else {
120
            Enumeration en = new SequenceEnumeration (
119
            Enumeration en = org.openide.util.Enumerations.concat (
121
                     st,
120
                st,
122
                     new SingletonEnumeration (name + '.' + ext)
121
                org.openide.util.Enumerations.singleton (name + '.' + ext)
123
                 );
122
            );
124
            // tries to find it (can return null)
123
            // tries to find it (can return null)
125
            return getAbstractRoot ().find (en);
124
            return getAbstractRoot ().find (en);
126
        }
125
        }
Lines 287-331 Link Here
287
     * @return enumeration of currently existing fileobjects.
286
     * @return enumeration of currently existing fileobjects.
288
     */
287
     */
289
    protected final Enumeration existingFileObjects (FileObject fo) {
288
    protected final Enumeration existingFileObjects (FileObject fo) {
290
        AlterEnumeration en = new AlterEnumeration(existingFileObjectsWeak(fo)) {
289
        class OnlyValidAndDeep implements org.openide.util.Enumerations.Processor {
291
            protected Object alter(Object obj) {
290
            public Object process (Object obj, Collection toAdd) {
292
                return ((Reference) obj).get();
291
                if (obj instanceof Reference) {
293
            }
292
                    obj = ((Reference) obj).get();
294
        };
293
                }
295
        FilterEnumeration fen = new FilterEnumeration(en) {
294
                AbstractFileObject file = (AbstractFileObject)obj;
296
            protected boolean accept(Object obj) {
295
                if (file != null) {
297
                return (obj != null && ((FileObject) obj).isValid ());
296
                    FileObject[] arr = file.subfiles ();
297
                    // make the array weak
298
                    for (int i = 0; i < arr.length; i++) {
299
                        toAdd.add (new WeakReference (arr[i]));
300
                    }
301
                    return file.isValid () ? file : null;
302
                }
303
                return null;
298
            }
304
            }
299
        };
305
        }
300
        return fen;
306
        return org.openide.util.Enumerations.queue (
301
    }
307
            org.openide.util.Enumerations.singleton (fo), new OnlyValidAndDeep ()
302
    
308
        );
303
    /**
304
     * Return Enumeration of references to FileObjects.
305
     */
306
    final Enumeration existingFileObjectsWeak (FileObject fo) {
307
        QueueEnumeration en = new QueueEnumeration () {
308
                                  public void process (Object o) {
309
                                      Reference ref = (Reference)o;
310
                                      AbstractFileObject file = (AbstractFileObject)ref.get ();
311
                                      if (file != null) {
312
                                          FileObject[] arr = file.subfiles ();
313
                                          Reference[] to = new Reference[arr.length];
314
315
                                          // make the array weak
316
                                          for (int i = 0; i < arr.length; i++) {
317
                                              to[i] = new WeakReference (arr[i]);
318
                                          }
319
320
                                          // put it into the enumeration
321
                                          put (to);
322
                                      }
323
                                  }
324
                              };
325
        // weak reference to root
326
        en.put (new WeakReference (fo));
327
        
328
        return en;
329
    }
309
    }
330
310
331
    /**
311
    /**
(-)openide/src/org/openide/filesystems/AbstractFolder.java (-18 / +17 lines)
Lines 18-28 Link Here
18
import java.lang.ref.*;
18
import java.lang.ref.*;
19
import java.net.URL;
19
import java.net.URL;
20
import org.openide.ErrorManager;
20
import org.openide.ErrorManager;
21
import org.openide.util.Enumerations;
21
import org.openide.util.NbBundle;
22
import org.openide.util.NbBundle;
22
23
23
24
import org.openide.util.enum.*;
25
26
/** Implementation of the file object that simplyfies common
24
/** Implementation of the file object that simplyfies common
27
* tasks with hierarchy of objects for AbstractFileObject and MultiFileObject.
25
* tasks with hierarchy of objects for AbstractFileObject and MultiFileObject.
28
*
26
*
Lines 344-359 Link Here
344
    */
342
    */
345
    final Enumeration existingSubFiles (boolean rec) {
343
    final Enumeration existingSubFiles (boolean rec) {
346
        if (!rec) {
344
        if (!rec) {
347
            return new ArrayEnumeration (subfiles ());
345
            return Enumerations.array (subfiles ());
348
        } else {
346
        } else {
349
            QueueEnumeration en = new QueueEnumeration () {
347
            class P implements org.openide.util.Enumerations.Processor {
350
                                      public void process (Object o) {
348
                public Object process(Object o, Collection toAdd) {
351
                                          AbstractFolder af = (AbstractFolder)o;
349
                   AbstractFolder af = (AbstractFolder)o;
352
                                          this.put (af.subfiles ());
350
                   toAdd.addAll (Arrays.asList (af.subfiles ()));
353
                                      }
351
                   return o;
354
                                  };
352
               }
355
            en.put (this);
353
            }
356
            return en;
354
            return Enumerations.queue (
355
                Enumerations.singleton (this),
356
                new P ()
357
            );
357
        }
358
        }
358
    }
359
    }
359
    
360
    
Lines 516-528 Link Here
516
    */
517
    */
517
    private final Enumeration listeners () {
518
    private final Enumeration listeners () {
518
        if (listeners == null) {
519
        if (listeners == null) {
519
            return EmptyEnumeration.EMPTY;
520
            return Enumerations.EMPTY;
520
        } else {
521
        } else {
521
            return new FilterEnumeration (new ArrayEnumeration (listeners.getAllListeners ())) {
522
            return Enumerations.removeNulls (
522
                       public boolean accept (Object o) {
523
                Enumerations.array (listeners.getAllListeners ())
523
                           return o != null;
524
            );
524
                       }
525
                   };
526
        }
525
        }
527
    }
526
    }
528
527
(-)openide/src/org/openide/filesystems/DefaultAttributes.java (-2 / +1 lines)
Lines 18-24 Link Here
18
import java.util.*;
18
import java.util.*;
19
19
20
import org.openide.util.NbBundle;
20
import org.openide.util.NbBundle;
21
import org.openide.util.enum.EmptyEnumeration;
22
import org.openide.util.io.NbMarshalledObject;
21
import org.openide.util.io.NbMarshalledObject;
23
import org.openide.util.Utilities;
22
import org.openide.util.Utilities;
24
23
Lines 766-772 Link Here
766
        public Enumeration attrs (String fileName) {
765
        public Enumeration attrs (String fileName) {
767
            Map m = (Map)get (fileName);
766
            Map m = (Map)get (fileName);
768
            if (m == null) {
767
            if (m == null) {
769
                return EmptyEnumeration.EMPTY;
768
                return org.openide.util.Enumerations.EMPTY;
770
            } else {
769
            } else {
771
                HashSet s = new HashSet (m.keySet ());
770
                HashSet s = new HashSet (m.keySet ());
772
                return Collections.enumeration (s);
771
                return Collections.enumeration (s);
(-)openide/src/org/openide/filesystems/EventControl.java (-15 / +15 lines)
Lines 14-21 Link Here
14
package org.openide.filesystems;
14
package org.openide.filesystems;
15
import java.io.*;
15
import java.io.*;
16
import java.util.Enumeration;
16
import java.util.Enumeration;
17
import java.util.LinkedList;
17
18
18
import org.openide.util.enum.QueueEnumeration;
19
/**
19
/**
20
 *
20
 *
21
 * @author  rmatous
21
 * @author  rmatous
Lines 36-42 Link Here
36
    private AtomicActionLink currentAtomAction;
36
    private AtomicActionLink currentAtomAction;
37
    
37
    
38
    /** List of requests */
38
    /** List of requests */
39
    private QueueEnumeration requestsQueue;
39
    private LinkedList requestsQueue;
40
     
40
     
41
    /**
41
    /**
42
     * Method that can fire events directly, postpone them, fire them in 
42
     * Method that can fire events directly, postpone them, fire them in 
Lines 101-107 Link Here
101
                                                                     
101
                                                                     
102
        if (priority) priorityRequests++;
102
        if (priority) priorityRequests++;
103
        if (requests++ == 0) {
103
        if (requests++ == 0) {
104
            requestsQueue = new QueueEnumeration ();
104
            requestsQueue = new LinkedList ();
105
        }
105
        }
106
    }
106
    }
107
107
Lines 110-116 Link Here
110
    private  void exitAtomicAction (boolean priority) {        
110
    private  void exitAtomicAction (boolean priority) {        
111
        boolean fireAll = false;
111
        boolean fireAll = false;
112
        boolean firePriority = false;        
112
        boolean firePriority = false;        
113
        Enumeration reqQueueCopy;        
113
        LinkedList reqQueueCopy;        
114
        
114
        
115
        synchronized (this) {            
115
        synchronized (this) {            
116
            currentAtomAction = currentAtomAction.getPreviousLink();                
116
            currentAtomAction = currentAtomAction.getPreviousLink();                
Lines 140-164 Link Here
140
        }
140
        }
141
        
141
        
142
        if (firePriority) {
142
        if (firePriority) {
143
            requestsQueue = new QueueEnumeration ();
143
            requestsQueue = new LinkedList ();
144
            QueueEnumeration newReqQueue = invokeDispatchers (true, reqQueueCopy);
144
            LinkedList newReqQueue = invokeDispatchers (true, reqQueueCopy);
145
            synchronized (this) {
145
            synchronized (this) {
146
                while (requestsQueue != null && requestsQueue.hasMoreElements()) {
146
                while (requestsQueue != null && !requestsQueue.isEmpty ()) {
147
                    FileSystem.EventDispatcher r = (FileSystem.EventDispatcher)requestsQueue.nextElement();                
147
                    FileSystem.EventDispatcher r = (FileSystem.EventDispatcher)requestsQueue.removeFirst ();                
148
                    newReqQueue.put(r);
148
                    newReqQueue.add (r);
149
                }                 
149
                }                 
150
                requestsQueue = newReqQueue;
150
                requestsQueue = newReqQueue;
151
            }
151
            }
152
        }
152
        }
153
    }
153
    }
154
    
154
    
155
    private QueueEnumeration invokeDispatchers (boolean priority, Enumeration reqQueueCopy) {
155
    private LinkedList invokeDispatchers (boolean priority, LinkedList reqQueueCopy) {
156
        QueueEnumeration newEnum  = new QueueEnumeration ();
156
        LinkedList newEnum  = new LinkedList ();
157
        
157
        
158
        while (reqQueueCopy != null && reqQueueCopy.hasMoreElements()) {
158
        while (reqQueueCopy != null && !reqQueueCopy.isEmpty ()) {
159
            FileSystem.EventDispatcher r = (FileSystem.EventDispatcher)reqQueueCopy.nextElement();                
159
            FileSystem.EventDispatcher r = (FileSystem.EventDispatcher)reqQueueCopy.removeFirst ();                
160
            r.dispatch(priority);
160
            r.dispatch(priority);
161
            if (priority) newEnum.put (r);
161
            if (priority) newEnum.add (r);
162
        }            
162
        }            
163
        return newEnum;
163
        return newEnum;
164
    }
164
    }
Lines 173-179 Link Here
173
        if (requestsQueue != null) {
173
        if (requestsQueue != null) {
174
            // run later
174
            // run later
175
            disp.setAtomicActionLink (currentAtomAction);
175
            disp.setAtomicActionLink (currentAtomAction);
176
            requestsQueue.put (disp);
176
            requestsQueue.add (disp);
177
            return true;
177
            return true;
178
        }        
178
        }        
179
        return false;
179
        return false;
(-)openide/src/org/openide/filesystems/FileObject.java (-27 / +41 lines)
Lines 18-24 Link Here
18
import java.util.Enumeration;
18
import java.util.Enumeration;
19
import java.util.StringTokenizer;
19
import java.util.StringTokenizer;
20
20
21
import org.openide.util.enum.QueueEnumeration;
22
import org.openide.util.*;
21
import org.openide.util.*;
23
22
24
/** This is the base for all implementations of file objects on a filesystem.
23
/** This is the base for all implementations of file objects on a filesystem.
Lines 489-505 Link Here
489
    * @return enumeration of type <code>FileObject</code>
488
    * @return enumeration of type <code>FileObject</code>
490
    */
489
    */
491
    public Enumeration getChildren (final boolean rec) {
490
    public Enumeration getChildren (final boolean rec) {
492
        QueueEnumeration en = new QueueEnumeration () {
491
        class WithChildren implements org.openide.util.Enumerations.Processor {
493
                                  /** @param o processes object by adding its children to the queue */
492
            public Object process (Object obj, java.util.Collection toAdd) {
494
                                  public void process (Object o) {
493
                FileObject fo = (FileObject)obj;
495
                                      FileObject fo = (FileObject)o;
494
                if (rec && fo.isFolder ()) {
496
                                      if (rec && fo.isFolder ()) {
495
                    toAdd.addAll (java.util.Arrays.asList (fo.getChildren ()));
497
                                          put (fo.getChildren ());
496
                }
498
                                      }
497
                return fo;
499
                                  }
498
            }
500
                              };
499
        }
501
        en.put (getChildren ());
500
        
502
        return en;
501
        return org.openide.util.Enumerations.queue (
502
            org.openide.util.Enumerations.array (getChildren ()), 
503
            new WithChildren ()
504
        );
503
    }
505
    }
504
506
505
    /** Enumerate the subfolders of this folder.
507
    /** Enumerate the subfolders of this folder.
Lines 507-518 Link Here
507
    * @return enumeration of type <code>FileObject</code> (satisfying {@link #isFolder})
509
    * @return enumeration of type <code>FileObject</code> (satisfying {@link #isFolder})
508
    */
510
    */
509
    public Enumeration getFolders (boolean rec) {
511
    public Enumeration getFolders (boolean rec) {
510
        return new org.openide.util.enum.FilterEnumeration (getChildren (rec)) {
512
        return org.openide.util.Enumerations.filter (
511
                   /** @return true if the object is of type FileFolder */
513
            getChildren (rec), new OnlyFolders (true)
512
                   protected boolean accept (Object o) {
514
        );
513
                       return ((FileObject)o).isFolder ();
514
                   }
515
               };
516
    }
515
    }
517
516
518
    /** Enumerate all data files in this folder.
517
    /** Enumerate all data files in this folder.
Lines 520-531 Link Here
520
    * @return enumeration of type <code>FileObject</code> (satisfying {@link #isData})
519
    * @return enumeration of type <code>FileObject</code> (satisfying {@link #isData})
521
    */
520
    */
522
    public Enumeration getData (boolean rec) {
521
    public Enumeration getData (boolean rec) {
523
        return new org.openide.util.enum.FilterEnumeration (getChildren (rec)) {
522
        return org.openide.util.Enumerations.filter (
524
                   /** @return true if the object is of type FileFolder */
523
            getChildren (rec), new OnlyFolders (false)
525
                   protected boolean accept (Object o) {
524
        );
526
                       return ((FileObject)o).isData ();
527
                   }
528
               };
529
    }
525
    }
530
526
531
    /** Retrieve file or folder contained in this folder by name.
527
    /** Retrieve file or folder contained in this folder by name.
Lines 747-757 Link Here
747
            if (this.op == -1) {
743
            if (this.op == -1) {
748
                this.op = fe.getFile().isFolder() ? FCLSupport.FOLDER_CREATED : FCLSupport.DATA_CREATED;                
744
                this.op = fe.getFile().isFolder() ? FCLSupport.FOLDER_CREATED : FCLSupport.DATA_CREATED;                
749
            }
745
            }
750
            QueueEnumeration newEnum = new QueueEnumeration();// later lazy                
746
            java.util.LinkedList newEnum = new java.util.LinkedList ();// later lazy                
751
	    while (en.hasMoreElements ()) {
747
	    while (en.hasMoreElements ()) {
752
                FileChangeListener fcl = (FileChangeListener)en.nextElement ();
748
                FileChangeListener fcl = (FileChangeListener)en.nextElement ();
753
                if (onlyPriority && !isPriorityListener(fcl)) {                                                
749
                if (onlyPriority && !isPriorityListener(fcl)) {                                                
754
                    newEnum.put(fcl);
750
                    newEnum.add (fcl);
755
                    continue;                        
751
                    continue;                        
756
                }                     
752
                }                     
757
                    
753
                    
Lines 765-771 Link Here
765
                FCLSupport.dispatchEvent(fcl, fe, op);
761
                FCLSupport.dispatchEvent(fcl, fe, op);
766
	    }
762
	    }
767
             if (onlyPriority) 
763
             if (onlyPriority) 
768
                 this.en = newEnum;
764
                 this.en = java.util.Collections.enumeration (newEnum);
769
            
765
            
770
            /** FileEvents are forked in may cases. But FileEvents fired from 
766
            /** FileEvents are forked in may cases. But FileEvents fired from 
771
             * FileSystem and from Repository mustn`t be forked.
767
             * FileSystem and from Repository mustn`t be forked.
Lines 793-797 Link Here
793
        }
789
        }
794
        
790
        
795
    }
791
    }
792
793
    /** Filters folders or data files.
794
     */
795
    private static final class OnlyFolders implements org.openide.util.Enumerations.Processor {
796
        private boolean folders;
797
        
798
        public OnlyFolders (boolean folders) {
799
            this.folders = folders;
800
        }
796
        
801
        
802
        public Object process (Object obj, java.util.Collection coll) {
803
            FileObject fo = (FileObject)obj;
804
            if (folders) {
805
                return fo.isFolder () ? fo : null;
806
            } else {
807
                return fo.isData () ? fo : null;
808
            }
809
        }
810
    } // end of OnlyFolders
797
}
811
}
(-)openide/src/org/openide/filesystems/FileSystemCapability.java (-8 / +10 lines)
Lines 16-23 Link Here
16
import java.beans.*;
16
import java.beans.*;
17
import java.util.*;
17
import java.util.*;
18
18
19
import org.openide.util.enum.FilterEnumeration;
20
21
/** This class defines the capabilities of a filesystem to
19
/** This class defines the capabilities of a filesystem to
22
* take part in different operations. Some filesystems are
20
* take part in different operations. Some filesystems are
23
* not designed to allow compilation on them, some do not want
21
* not designed to allow compilation on them, some do not want
Lines 84-95 Link Here
84
    * @deprecated Please use the <a href="@JAVA/API@/org/netbeans/api/java/classpath/api.html">ClassPath API</a> instead.
82
    * @deprecated Please use the <a href="@JAVA/API@/org/netbeans/api/java/classpath/api.html">ClassPath API</a> instead.
85
    */
83
    */
86
    public Enumeration fileSystems () {
84
    public Enumeration fileSystems () {
87
        return new FilterEnumeration (ExternalUtil.getRepository ().fileSystems ()) {
85
        class FFS implements org.openide.util.Enumerations.Processor {
88
                   public boolean accept (Object o) {
86
            public Object process (Object obj, Collection ignore) {
89
                       FileSystem fs = (FileSystem)o;
87
                FileSystem fs = (FileSystem)obj;
90
                       return fs.getCapability().capableOf(FileSystemCapability.this);
88
                return fs.getCapability().capableOf(FileSystemCapability.this) ? fs : null;
91
                   }
89
            }
92
               };
90
        }
91
        
92
        return org.openide.util.Enumerations.filter (
93
            ExternalUtil.getRepository ().fileSystems (), new FFS ()
94
        );
93
    }
95
    }
94
96
95
    /** Find a resource in repository, ignoring not capable filesystems.
97
    /** Find a resource in repository, ignoring not capable filesystems.
(-)openide/src/org/openide/filesystems/JarFileSystem.java (-7 / +9 lines)
Lines 23-29 Link Here
23
import org.openide.filesystems.*;
23
import org.openide.filesystems.*;
24
24
25
import  org.openide.util.*;
25
import  org.openide.util.*;
26
import  org.openide.util.enum.*;
27
26
28
/** A virtual filesystem based on a JAR archive.
27
/** A virtual filesystem based on a JAR archive.
29
* <p>For historical reasons many AbstractFileSystem.* methods are implemented
28
* <p>For historical reasons many AbstractFileSystem.* methods are implemented
Lines 486-499 Link Here
486
        Attributes attr = getManifest ().getAttributes (name);
485
        Attributes attr = getManifest ().getAttributes (name);
487
        
486
        
488
        if (attr != null) {
487
        if (attr != null) {
489
            return  new AlterEnumeration(Collections.enumeration (attr.keySet ())) {
488
            class ToString implements org.openide.util.Enumerations.Processor {
490
                public Object alter(Object obj) {
489
                public Object process (Object obj, Collection ignore) {
491
                    return obj.toString();
490
                    return obj.toString ();
492
                }
491
                }
493
            };
492
            }
494
            
493
            return org.openide.util.Enumerations.convert (
494
                Collections.enumeration (attr.keySet ()),
495
                new ToString ()
496
            );
495
        } else {
497
        } else {
496
            return EmptyEnumeration.EMPTY;
498
            return org.openide.util.Enumerations.EMPTY;
497
        }
499
        }
498
    }
500
    }
499
501
(-)openide/src/org/openide/filesystems/MultiFileObject.java (-2 lines)
Lines 19-26 Link Here
19
import java.lang.ref.*;
19
import java.lang.ref.*;
20
20
21
21
22
import org.openide.util.enum.*;
23
24
/** Implementation of the file object for multi file system.
22
/** Implementation of the file object for multi file system.
25
*
23
*
26
* @author Jaroslav Tulach, 
24
* @author Jaroslav Tulach, 
(-)openide/src/org/openide/filesystems/MultiFileSystem.java (-27 / +27 lines)
Lines 17-23 Link Here
17
import java.util.*;
17
import java.util.*;
18
18
19
import org.openide.util.actions.SystemAction;
19
import org.openide.util.actions.SystemAction;
20
import org.openide.util.enum.*;
21
20
22
/** The base for all filesystems that are build above a top of
21
/** The base for all filesystems that are build above a top of
23
* other ones. This system expects at most one filesystem it should write
22
* other ones. This system expects at most one filesystem it should write
Lines 212-220 Link Here
212
        if (name == null || ext == null) {
211
        if (name == null || ext == null) {
213
            en = st;
212
            en = st;
214
        } else {
213
        } else {
215
            en = new SequenceEnumeration (
214
            en = org.openide.util.Enumerations.concat (
216
                     st,
215
                     st,
217
                     new SingletonEnumeration (name + '.' + ext)
216
                     org.openide.util.Enumerations.singleton (name + '.' + ext)
218
                 );
217
                 );
219
        }
218
        }
220
        // tries to find it (can return null)
219
        // tries to find it (can return null)
Lines 293-309 Link Here
293
    */
292
    */
294
    protected static Enumeration hiddenFiles (FileObject folder, boolean rec) {
293
    protected static Enumeration hiddenFiles (FileObject folder, boolean rec) {
295
        Enumeration allFiles = folder.getChildren (rec);
294
        Enumeration allFiles = folder.getChildren (rec);
296
        Enumeration allNull = new AlterEnumeration (allFiles) {
295
        
297
                                  public Object alter (Object fo) {
296
        class OnlyHidden implements org.openide.util.Enumerations.Processor {
298
                                      String sf = ((FileObject)fo).getPath();
297
            public Object process (Object obj, Collection ignore) {
299
                                      if (sf.endsWith (MASK)) {
298
                String sf = ((FileObject)obj).getPath();
300
                                          return sf.substring (0, sf.length () - MASK.length ());
299
                if (sf.endsWith (MASK)) {
301
                                      } else {
300
                    return sf.substring (0, sf.length () - MASK.length ());
302
                                          return null;
301
                } else {
303
                                      }
302
                    return null;
304
                                  }
303
                }
305
                              };
304
            }
306
        return new FilterEnumeration (allNull);
305
        }
306
        
307
        return org.openide.util.Enumerations.filter (allFiles, new OnlyHidden ());
307
    }
308
    }
308
309
309
    //
310
    //
Lines 471-490 Link Here
471
    * @return enumeration of FileObject
472
    * @return enumeration of FileObject
472
    */
473
    */
473
    Enumeration delegates (final String name) {
474
    Enumeration delegates (final String name) {
474
        Enumeration en = new ArrayEnumeration (systems);
475
        Enumeration en = org.openide.util.Enumerations.array (systems);
475
476
        Enumeration objsAndNulls = new AlterEnumeration (en) {
477
                                       public Object alter (Object o) {
478
                                           FileSystem fs = (FileSystem)o;
479
                                           if (fs == null) {
480
                                               return null;
481
                                           } else {
482
                                               return findResourceOn (fs, name);
483
                                           }
484
                                       }
485
                                   };
486
476
487
        return new FilterEnumeration (objsAndNulls);
477
        class Resources implements org.openide.util.Enumerations.Processor {
478
            public Object process (Object obj, Collection ignore) {
479
                FileSystem fs = (FileSystem)obj;
480
                if (fs == null) {
481
                    return null;
482
                } else {
483
                    return findResourceOn (fs, name);
484
                }
485
            }
486
        }
487
        return org.openide.util.Enumerations.filter (en, new Resources ());
488
    }
488
    }
489
489
490
    /** Creates a file object that will mask the given file.
490
    /** Creates a file object that will mask the given file.
(-)openide/src/org/openide/filesystems/XMLFileSystem.java (-3 / +2 lines)
Lines 20-26 Link Here
20
import java.util.*;
20
import java.util.*;
21
import java.net.*;
21
import java.net.*;
22
22
23
import org.openide.util.enum.EmptyEnumeration;
24
import org.openide.util.NbBundle;
23
import org.openide.util.NbBundle;
25
24
26
import org.xml.sax.*;
25
import org.xml.sax.*;
Lines 746-752 Link Here
746
            FileObjRef ref = (FileObjRef)fs.findReference(name);            
745
            FileObjRef ref = (FileObjRef)fs.findReference(name);            
747
            if (ref == null  && name.length() == 0 && fs.rootRef != null)  
746
            if (ref == null  && name.length() == 0 && fs.rootRef != null)  
748
                ref = fs.rootRef;            
747
                ref = fs.rootRef;            
749
            if (ref == null  )  return EmptyEnumeration.EMPTY;
748
            if (ref == null  )  return org.openide.util.Enumerations.EMPTY;
750
            return ref.attributes();
749
            return ref.attributes();
751
        }
750
        }
752
        
751
        
Lines 833-839 Link Here
833
         
832
         
834
        public Enumeration attributes() {            
833
        public Enumeration attributes() {            
835
            if (foAttrs == null) {
834
            if (foAttrs == null) {
836
                return EmptyEnumeration.EMPTY;
835
                return org.openide.util.Enumerations.EMPTY;
837
            } else {
836
            } else {
838
                HashSet s = new HashSet (foAttrs.keySet ());
837
                HashSet s = new HashSet (foAttrs.keySet ());
839
                return Collections.enumeration (s);
838
                return Collections.enumeration (s);
(-)openide/src/org/openide/nodes/Children.java (-2 / +1 lines)
Lines 19-25 Link Here
19
19
20
20
21
import org.openide.util.Mutex;
21
import org.openide.util.Mutex;
22
import org.openide.util.enum.ArrayEnumeration;
23
22
24
/** Container for array of nodes.
23
/** Container for array of nodes.
25
* Can be {@link Node#Node associated} with a node and then
24
* Can be {@link Node#Node associated} with a node and then
Lines 247-253 Link Here
247
    * @return enumeration of {@link Node}s
246
    * @return enumeration of {@link Node}s
248
    */
247
    */
249
    public final Enumeration nodes () {
248
    public final Enumeration nodes () {
250
        return new ArrayEnumeration (getNodes ());
249
        return org.openide.util.Enumerations.array (getNodes ());
251
    }
250
    }
252
251
253
    /** Find a child node by name.
252
    /** Find a child node by name.
(-)openide/src/org/openide/nodes/NodeOp.java (-2 / +1 lines)
Lines 20-26 Link Here
20
import javax.swing.JPopupMenu;
20
import javax.swing.JPopupMenu;
21
21
22
import org.openide.ErrorManager;
22
import org.openide.ErrorManager;
23
import org.openide.util.enum.ArrayEnumeration;
24
import org.openide.util.Lookup;
23
import org.openide.util.Lookup;
25
24
26
/** Utility class for operations on nodes.
25
/** Utility class for operations on nodes.
Lines 254-260 Link Here
254
    */
253
    */
255
    public static Node findPath (Node start, String[] names)
254
    public static Node findPath (Node start, String[] names)
256
    throws NodeNotFoundException {
255
    throws NodeNotFoundException {
257
        return findPath (start, new ArrayEnumeration (names));
256
        return findPath (start, org.openide.util.Enumerations.array (names));
258
    }
257
    }
259
    
258
    
260
    /** Find the root for a given node.
259
    /** Find the root for a given node.
(-)openide/src/org/openide/util/Enumerations.java (+492 lines)
Added Link Here
1
/*
2
 *                 Sun Public License Notice
3
 * 
4
 * The contents of this file are subject to the Sun Public License
5
 * Version 1.0 (the "License"). You may not use this file except in
6
 * compliance with the License. A copy of the License is available at
7
 * http://www.sun.com/
8
 * 
9
 * The Original Code is NetBeans. The Initial Developer of the Original
10
 * Code is Sun Microsystems, Inc. Portions Copyright 1997-2004 Sun
11
 * Microsystems, Inc. All Rights Reserved.
12
 */
13
package org.openide.util;
14
15
import java.util.*;
16
import java.util.Enumeration;
17
import java.util.Map;
18
import java.util.Set;
19
20
/** Factory methods for various types of java.util.Enumeration. Allows composition
21
 * of existing enumerations, filtering their content and/or modifying them. 
22
 * All of this is designed to be done in lazy way - e.g. at the latest time 
23
 * when needed.
24
 *
25
 * @since JST-PENDING
26
 * @author Jaroslav Tulach
27
 */
28
public final class Enumerations extends Object {
29
    /** No instances */
30
    private Enumerations () {
31
    }
32
33
    /** An empty enumeration. Always returns <code>false</code> when
34
     * <code>EMPTY.hasMoreElements()</code> and throws <code>NoSuchElementException</code>
35
     * from the <code>EMPTY.nextElement()</code> method.
36
     */
37
    public static final Enumeration EMPTY = Collections.enumeration (Collections.EMPTY_LIST);
38
39
    /** Creates enumeration with one element.
40
     * @param obj the element to be present in the enumeration.
41
     * @return enumeration
42
     */
43
    public static Enumeration singleton (Object obj) {
44
        return Collections.enumeration (Collections.singleton (obj));
45
    }
46
    /** Concatenates the content of two enumerations into one. Until the 
47
     * end of <code>en1</code> is reached its elements are being served. 
48
     * As soon as the <code>en1</code> has no more elements, the content
49
     * of <code>en2</code> is being returned.
50
     *
51
     * @param en1 first enumeration
52
     * @param en2 second enumeration
53
     * @return enumeration
54
     */
55
    public static Enumeration concat (Enumeration en1, Enumeration en2) {
56
        return new SeqEn (en1, en2);
57
    }
58
    /** Concatenates the content of many enumerations. The input value
59
     * is enumeration of Enumeration elements and the result is composed 
60
     * all their content. Each of the provided enumeration is fully read
61
     * and their content returned before the next enumeration is asked for 
62
     * their elements.
63
     *
64
     * @param enumOfEnums Enumeration of Enumeration elements
65
     * @return enumeration 
66
     */
67
    public static Enumeration concat (Enumeration enumOfEnums) {
68
        return new SeqEn (enumOfEnums);
69
    }
70
    /** Filters the input enumeration to new one that should contain
71
     * each of the provided elements just once. The elements are compared
72
     * using their default <code>equals</code> and <code>hashCode</code> methods.
73
     *
74
     * @param en enumeration to filter
75
     * @return enumeration without duplicated items
76
     */
77
    public static Enumeration removeDuplicates (Enumeration en) {
78
        class RDupls implements Processor {
79
            private Set set = new HashSet ();
80
            public Object process (Object o, Collection nothing) {
81
                return set.add (o) ? o : null;
82
            }
83
        }
84
        return filter (en, new RDupls ());
85
    }
86
87
    /** Returns an enumeration that iterates over provided array.
88
     * @param arr the array of object
89
     * @return enumeration of those objects
90
     */
91
    public static Enumeration array (Object[] arr) {
92
        return Collections.enumeration (Arrays.asList (arr));
93
    }
94
    /** Removes all <code>null</code>s from the input enumeration
95
     * @param en enumeration that can contain nulls
96
     * @return new enumeration without null values
97
     */
98
    public static Enumeration removeNulls (Enumeration en) {
99
        return filter (en, new RNulls());
100
    }
101
    
102
    /** For each element of the input enumeration <code>en</code> asks the 
103
     * {@link Processor} to provide a replacement. The <code>toAdd</code> 
104
     * argument of the processor is always null.
105
     * <p>
106
     * Example to convert any objects into strings:
107
     * <pre>
108
     * Processor convertToString = new Process () {
109
     *     public Object process (Object obj, Collection toAdd) { // toAdd is always null
110
     *        return obj.toString (): // converts to string
111
     *     }
112
     * };
113
     * Enumeration strings = Enumerations.convert (elems, convertToString);
114
     * </pre> 
115
     *
116
     * @param en enumeration of any objects
117
     * @param processor a callback processor for the elements (its toAdd arguments is always null)
118
     * @return new enumeration where all elements has been processed
119
     */
120
    public static Enumeration convert (Enumeration en, Processor processor) {
121
        return new AltEn (en, processor);
122
    }
123
    /** Allows to filter out some elements from the input enumeration. Just 
124
     * make the 
125
     * {@link Processor} return <code>null</code>. Please notice the <code>toAdd</code>
126
     * argument of the processor is always <code>null</code>.
127
     * <p>
128
     * Example to remove all objects that are not strings:
129
     * <pre>
130
     * Processor onlyString = new Processor () {
131
     *     public Object process (Object obj, Collection alwaysNull) { 
132
     *        if (obj instanceof String) {
133
     *            return obj;
134
     *        } else {
135
     *            return null;
136
     *        }
137
     *     }
138
     * };
139
     * Enumeration strings = Enumerations.filter (elems, onlyString);
140
     * </pre> 
141
     *
142
     * @param en enumeration of any objects
143
     * @param filter a callback processor for the elements (its toAdd arguments is always null)
144
     * @return new enumeration which does not include non-processed (returned null from processor) elements
145
     */
146
    public static Enumeration filter (Enumeration en, Processor filter) {
147
        return new FilEn (en, filter);
148
    }
149
    
150
    /** Support for breadth-first enumerating. Before any element is returned
151
     * for the resulting enumeration it is processed in the {@link Processor} and 
152
     * the processor is allowed to modify it and also add additional elements
153
     * at the (current) end of the <q>queue</q> by calling <code>toAdd.add</code>
154
     * or <code>toAdd.addAll</code>. No other methods can be called on the 
155
     * provided <code>toAdd</code> collection.
156
     * <p>
157
     * Example of doing breadth-first walk through a tree:
158
     * <pre>
159
     * Processor queueSubnodes = new Process () {
160
     *     public Object process (Object obj, Collection toAdd) { 
161
     *        Node n = (Node)obj;
162
     *        toAdd.addAll (n.getChildrenList ());
163
     *        return n;
164
     *     }
165
     * };
166
     * Enumeration strings = Enumerations.queue (elems, queueSubnodes);
167
     * </pre>
168
     * 
169
     * @param en initial content of the resulting enumeration
170
     * @param filter the processor that is called for each element and can 
171
     *        add and addAll elements to its toAdd Collection argument
172
     * @return enumeration with the initial and queued content
173
     */
174
    public static Enumeration queue (Enumeration en, Processor filter) {
175
        QEn q = new QEn (filter);
176
        while (en.hasMoreElements ()) {
177
            q.put (en.nextElement ());
178
        }
179
        return q;
180
    }
181
    
182
    /** Processor interface that can filter out objects from the enumeration,
183
     * change them or add aditional objects to the end of the current enumeration.
184
     */
185
    public static interface Processor {
186
        /** @param original the object that is going to be returned from the enumeration right now
187
         * @return a replacement for this object
188
         * @param toAdd can be non-null if one can add new objects at the end of the enumeration
189
         */
190
        public Object process (Object original, Collection toAdd);
191
    }
192
    
193
194
    /** Altering enumeration implementation */
195
    private static final class AltEn extends Object implements Enumeration {
196
        /** enumeration to filter */
197
        private Enumeration en;
198
        /** map to alter */
199
        private Processor process;
200
201
        /**
202
        * @param en enumeration to filter
203
        */
204
        public AltEn (Enumeration en, Processor process) {
205
            this.en = en;
206
            this.process = process;
207
        }
208
209
        /** @return true if there is more elements in the enumeration
210
        */
211
        public boolean hasMoreElements () {
212
            return en.hasMoreElements ();
213
        }
214
215
        /** @return next object in the enumeration
216
        * @exception NoSuchElementException can be thrown if there is no next object
217
        *   in the enumeration
218
        */
219
        public Object nextElement () {
220
            return process.process (en.nextElement (), null);
221
        }
222
    } // end of AltEn
223
224
    /** Sequence of enumerations */
225
    private static final class SeqEn extends Object implements Enumeration {
226
        /** enumeration of Enumerations */
227
        private Enumeration en;
228
        /** current enumeration */
229
        private Enumeration current;
230
231
        /** is {@link #current} up-to-date and has more elements?
232
        * The combination <CODE>current == null</CODE> and
233
        * <CODE>checked == true means there are no more elements
234
        * in this enumeration.
235
        */
236
        private boolean checked = false;
237
238
        /** Constructs new enumeration from already existing. The elements
239
        * of <CODE>en</CODE> should be also enumerations. The resulting
240
        * enumeration contains elements of such enumerations.
241
        *
242
        * @param en enumeration of Enumerations that should be sequenced
243
        */
244
        public SeqEn (Enumeration en) {
245
            this.en = en;
246
        }
247
248
        /** Composes two enumerations into one.
249
        * @param first first enumeration
250
        * @param second second enumeration
251
        */
252
        public SeqEn (Enumeration first, Enumeration second) {
253
            this (array (new Enumeration[] { first, second }));
254
        }
255
256
        /** Ensures that current enumeration is set. If there aren't more
257
        * elements in the Enumerations, sets the field <CODE>current</CODE> to null.
258
        */
259
        private void ensureCurrent () {
260
            while (current == null || !current.hasMoreElements ()) {
261
                if (en.hasMoreElements ()) {
262
                    current = (Enumeration)en.nextElement ();
263
                } else {
264
                    // no next valid enumeration
265
                    current = null;
266
                    return;
267
                }
268
            }
269
        }
270
271
        /** @return true if we have more elements */
272
        public boolean hasMoreElements () {
273
            if( !checked ) {
274
                ensureCurrent ();
275
                checked = true;
276
            }
277
            return current != null;
278
        }
279
280
        /** @return next element
281
        * @exception NoSuchElementException if there is no next element
282
        */
283
        public synchronized Object nextElement () {
284
            if( !checked ) {
285
                ensureCurrent ();
286
            }
287
            if( current != null ) {
288
                checked = false;
289
                return current.nextElement ();
290
            } else {
291
                checked = true;
292
                throw new java.util.NoSuchElementException ();
293
            }
294
        }
295
    } // end of SeqEn
296
    
297
    /** QueueEnumeration
298
     */
299
    private static class QEn extends Object implements Enumeration {
300
        /** item in linked list of Objects */
301
        private static final class ListItem {
302
            Object object;
303
            ListItem next;
304
305
            /** @param o the object for this item */
306
            ListItem (Object o) {
307
                object = o;
308
            }
309
        }
310
        /** next object to be returned */
311
        private ListItem next = null;
312
        /** last object in the queue */
313
        private ListItem last = null;
314
        /** processor to use */
315
        private Processor processor;
316
317
        public QEn (Processor p) {
318
            this.processor = p;
319
        }
320
        
321
        /** Put adds new object to the end of queue.
322
        * @param o the object to add
323
        */
324
        public synchronized void put (Object o) {
325
            if (last != null) {
326
                ListItem li = new ListItem (o);
327
                last.next = li;
328
                last = li;
329
            } else {
330
                next = last = new ListItem (o);
331
            }
332
        }
333
334
        /** Adds array of objects into the queue.
335
        * @param arr array of objects to put into the queue
336
        */
337
        public synchronized void put (Object[] arr) {
338
            for (int i = 0; i < arr.length; i++) {
339
                put (arr[i]);
340
            }
341
        }
342
343
        /** Is there any next object?
344
        * @return true if there is next object, false otherwise
345
        */
346
        public boolean hasMoreElements () {
347
            return next != null;
348
        }
349
350
        /** @return next object in enumeration
351
        * @exception NoSuchElementException if there is no next object
352
        */
353
        public synchronized Object nextElement () {
354
            if (next == null) {
355
                throw new NoSuchElementException ();
356
            }
357
            Object res = next.object;
358
359
            if ((next = next.next) == null) {
360
                last = null;
361
            };
362
            ToAdd toAdd = new ToAdd (this);
363
            res = processor.process (res, toAdd);
364
            toAdd.finish ();
365
            return res;
366
        }
367
368
        /** Temporary collection that supports only add and addAll operations*/
369
        private static final class ToAdd extends Object implements Collection {
370
            private QEn q;
371
            
372
            public ToAdd (QEn q) {
373
                this.q = q;
374
            }
375
            
376
            public void finish () {
377
                this.q = null;
378
            }
379
            
380
            public boolean add (Object o) {
381
                q.put (o);
382
                return true;
383
            }
384
            
385
            public boolean addAll (Collection c) {
386
                q.put (c.toArray ());
387
                return true;
388
            }
389
            
390
            private String msg () {
391
                return "Only add and addAll are implemented"; // NOI18N
392
            }
393
            
394
            public void clear () {
395
                throw new IllegalStateException (msg ());
396
            }
397
            public boolean contains (Object o) {
398
                throw new IllegalStateException (msg ());
399
            }
400
            public boolean containsAll (Collection c) {
401
                throw new IllegalStateException (msg ());
402
            }
403
            public boolean isEmpty () {
404
                throw new IllegalStateException (msg ());
405
            }
406
            public Iterator iterator () {
407
                throw new IllegalStateException (msg ());
408
            }
409
            public boolean remove (Object o) {
410
                throw new IllegalStateException (msg ());
411
            }
412
            public boolean removeAll (Collection c) {
413
                throw new IllegalStateException (msg ());
414
            }
415
            public boolean retainAll (Collection c) {
416
                throw new IllegalStateException (msg ());
417
            }
418
            public int size () {
419
                throw new IllegalStateException (msg ());
420
            }
421
            public Object[] toArray () {
422
                throw new IllegalStateException (msg ());
423
            }
424
            public Object[] toArray (Object[] a) {
425
                throw new IllegalStateException (msg ());
426
            }
427
        } // end of ToAdd
428
    } // end of QEn
429
    
430
    /** Filtering enumeration */
431
    private static final class FilEn extends Object implements Enumeration {
432
        /** marker object stating there is no nexte element prepared */
433
        private static final Object EMPTY = new Object();
434
435
        /** enumeration to filter */
436
        private Enumeration en;
437
438
        /** element to be returned next time or {@link #EMPTY} if there is
439
        * no such element prepared */
440
        private Object next = EMPTY;
441
        
442
        /** the set to use as filter */
443
        private Processor filter;
444
        
445
        /**
446
        * @param en enumeration to filter
447
        */
448
        public FilEn (Enumeration en, Processor filter) {
449
            this.en = en;
450
            this.filter = filter;
451
        }
452
453
        /** @return true if there is more elements in the enumeration
454
        */
455
        public boolean hasMoreElements () {
456
            if (next != EMPTY) {
457
                // there is a object already prepared
458
                return true;
459
            }
460
            while (en.hasMoreElements ()) {
461
                // read next
462
                next = filter.process (en.nextElement (), null);
463
                if (next != null) {
464
                    // if the object is accepted
465
                    return true;
466
                };
467
            }
468
            next = EMPTY;
469
            return false;
470
        }
471
472
        /** @return next object in the enumeration
473
        * @exception NoSuchElementException can be thrown if there is no next object
474
        *   in the enumeration
475
        */
476
        public Object nextElement () {
477
            if( next == EMPTY && !hasMoreElements() ) {
478
                throw new NoSuchElementException ();
479
            }
480
            Object res = next;
481
            next = EMPTY;
482
            return res;
483
        }
484
    } // end of FilEn
485
    
486
    /** Returns true from contains if object is not null */
487
    private static class RNulls implements Processor  {
488
        public Object process (Object original, Collection toAdd) {
489
            return original;
490
        }
491
    } // end of RNulls
492
}
(-)openide/src/org/openide/util/NbBundle.java (-3 / +3 lines)
Lines 20-26 Link Here
20
import java.util.jar.Attributes;
20
import java.util.jar.Attributes;
21
21
22
import org.openide.ErrorManager;
22
import org.openide.ErrorManager;
23
import org.openide.util.enum.*;
24
23
25
/** Convenience class permitting easy loading of localized resources of various sorts.
24
/** Convenience class permitting easy loading of localized resources of various sorts.
26
* Extends the functionality of the default Java resource support, and interacts
25
* Extends the functionality of the default Java resource support, and interacts
Lines 561-568 Link Here
561
            return loc;
560
            return loc;
562
        }
561
        }
563
        public Enumeration getKeys () {
562
        public Enumeration getKeys () {
564
            return new RemoveDuplicatesEnumeration
563
            return Enumerations.removeDuplicates (
565
                (new SequenceEnumeration (sub1.getKeys (), sub2.getKeys ()));
564
                Enumerations.concat (sub1.getKeys (), sub2.getKeys ())
565
            );
566
        }
566
        }
567
        protected Object handleGetObject (String key) throws MissingResourceException {
567
        protected Object handleGetObject (String key) throws MissingResourceException {
568
            try {
568
            try {
(-)openide/src/org/openide/util/Queue.java (-8 / +7 lines)
Lines 13-20 Link Here
13
13
14
package org.openide.util;
14
package org.openide.util;
15
15
16
import org.openide.util.enum.QueueEnumeration;
17
18
/** Queue of objects. When there is no object in the queue the process
16
/** Queue of objects. When there is no object in the queue the process
19
* is suspended till some arrives.
17
* is suspended till some arrives.
20
*
18
*
Lines 23-35 Link Here
23
*/
21
*/
24
public class Queue extends Object {
22
public class Queue extends Object {
25
    /** Queue enumeration */
23
    /** Queue enumeration */
26
    private QueueEnumeration queue = new QueueEnumeration ();
24
    private java.util.LinkedList queue = new java.util.LinkedList();
27
25
28
    /** Adds new item.
26
    /** Adds new item.
29
    * @param o object to add
27
    * @param o object to add
30
    */
28
    */
31
    public synchronized void put (Object o) {
29
    public synchronized void put (Object o) {
32
        queue.put (o);
30
        queue.add (o);
33
        notify ();
31
        notify ();
34
    }
32
    }
35
33
Lines 40-53 Link Here
40
    */
38
    */
41
    public synchronized Object get () {
39
    public synchronized Object get () {
42
        for (;;) {
40
        for (;;) {
43
            try {
41
            if (queue.isEmpty ()) {
44
                return queue.nextElement ();
45
            } catch (java.util.NoSuchElementException ex) {
46
                try {
42
                try {
47
                    wait ();
43
                    wait ();
48
                } catch (InterruptedException ex2) {
44
                } catch (InterruptedException ex) {
49
                }
45
                }
46
            } else {
47
                break;
50
            }
48
            }
51
        }
49
        }
50
        return queue.removeFirst ();
52
    }
51
    }
53
}
52
}
(-)openide/src/org/openide/util/enum/AlterEnumeration.java (-1 / +5 lines)
Lines 15-21 Link Here
15
15
16
import java.util.Enumeration;
16
import java.util.Enumeration;
17
17
18
/** Abstract class that takes an enumeration and alter their elements
18
/**
19
* @deprecated JDK1.5 treats enum as keyword and that is why this class had to be 
20
 *  replaced by {@link org.openide.util.Enumerations#convert}.
21
 *
22
* Abstract class that takes an enumeration and alter their elements
19
* to new objects.
23
* to new objects.
20
* To get this class fully work one must override <CODE>alter</CODE> method.
24
* To get this class fully work one must override <CODE>alter</CODE> method.
21
* Objects in the input and resulting enumeration must not be <CODE>null</CODE>.
25
* Objects in the input and resulting enumeration must not be <CODE>null</CODE>.
(-)openide/src/org/openide/util/enum/ArrayEnumeration.java (-1 / +5 lines)
Lines 16-22 Link Here
16
import java.util.Enumeration;
16
import java.util.Enumeration;
17
import java.util.NoSuchElementException;
17
import java.util.NoSuchElementException;
18
18
19
/** The class that presents specifiED (in constructor) array
19
/** 
20
* @deprecated JDK1.5 treats enum as keyword and that is why this class had to be 
21
*  replaced by {@link org.openide.util.Enumerations#array}.
22
*
23
* The class that presents specifiED (in constructor) array
20
* as an Enumeration.
24
* as an Enumeration.
21
*
25
*
22
* @author   Ian Formanek
26
* @author   Ian Formanek
(-)openide/src/org/openide/util/enum/EmptyEnumeration.java (-1 / +5 lines)
Lines 16-22 Link Here
16
import java.util.Enumeration;
16
import java.util.Enumeration;
17
import java.util.NoSuchElementException;
17
import java.util.NoSuchElementException;
18
18
19
/** The class that represents empty enumeration.
19
/** 
20
* @deprecated JDK1.5 treats enum as keyword and that is why this class had to be 
21
*  replaced by {@link org.openide.util.Enumerations#EMPTY}.
22
*
23
* The class that represents empty enumeration.
20
*
24
*
21
* @author  Petr Hamernik
25
* @author  Petr Hamernik
22
* @version  0.11, May 12, 1998
26
* @version  0.11, May 12, 1998
(-)openide/src/org/openide/util/enum/FilterEnumeration.java (-1 / +5 lines)
Lines 16-22 Link Here
16
import java.util.Enumeration;
16
import java.util.Enumeration;
17
import java.util.NoSuchElementException;
17
import java.util.NoSuchElementException;
18
18
19
/** Abstract class that takes an enumeration and filters its elements.
19
/** 
20
* @deprecated JDK1.5 treats enum as keyword and that is why this class had to be 
21
*  replaced by {@link org.openide.util.Enumerations#filter}.
22
*  
23
* Abstract class that takes an enumeration and filters its elements.
20
* To get this class fully work one must override <CODE>accept</CODE> method.
24
* To get this class fully work one must override <CODE>accept</CODE> method.
21
* Objects in the enumeration must not be <CODE>null</CODE>.
25
* Objects in the enumeration must not be <CODE>null</CODE>.
22
*
26
*
(-)openide/src/org/openide/util/enum/QueueEnumeration.java (-1 / +5 lines)
Lines 16-22 Link Here
16
import java.util.Enumeration;
16
import java.util.Enumeration;
17
import java.util.NoSuchElementException;
17
import java.util.NoSuchElementException;
18
18
19
/** Enumeration that represents a queue. It allows by redefining
19
/** 
20
* @deprecated JDK1.5 treats enum as keyword and that is why this class had to be 
21
*  replaced by {@link org.openide.util.Enumerations#queue}.
22
*
23
* Enumeration that represents a queue. It allows by redefining
20
* method <CODE>process</CODE> each outputed object to add other to the end of
24
* method <CODE>process</CODE> each outputed object to add other to the end of
21
* queue of waiting objects by a call to <CODE>put</CODE>.
25
* queue of waiting objects by a call to <CODE>put</CODE>.
22
*
26
*
(-)openide/src/org/openide/util/enum/RemoveDuplicatesEnumeration.java (-1 / +4 lines)
Lines 16-22 Link Here
16
import java.util.Enumeration;
16
import java.util.Enumeration;
17
import java.util.HashSet;
17
import java.util.HashSet;
18
18
19
/** Enumeration that scans through another one and removes duplicates.
19
/** 
20
* @deprecated JDK1.5 treats enum as keyword and that is why this class had to be 
21
 *  replaced by {@link org.openide.util.Enumerations#removeDuplicates}.
22
* Enumeration that scans through another one and removes duplicates.
20
* Two objects are duplicate if <CODE>one.equals (another)</CODE>.
23
* Two objects are duplicate if <CODE>one.equals (another)</CODE>.
21
*
24
*
22
* @author Jaroslav Tulach
25
* @author Jaroslav Tulach
(-)openide/src/org/openide/util/enum/SequenceEnumeration.java (-1 / +5 lines)
Lines 15-21 Link Here
15
15
16
import java.util.Enumeration;
16
import java.util.Enumeration;
17
17
18
/** Composes more enumerations into one.
18
/** 
19
* @deprecated JDK1.5 treats enum as keyword and that is why this class had to be 
20
*  replaced by {@link org.openide.util.Enumerations#concat}.
21
*
22
* Composes more enumerations into one.
19
*
23
*
20
* @author Jaroslav Tulach
24
* @author Jaroslav Tulach
21
* @author Petr Nejedly
25
* @author Petr Nejedly
(-)openide/src/org/openide/util/enum/SingletonEnumeration.java (-1 / +5 lines)
Lines 16-22 Link Here
16
import java.util.Enumeration;
16
import java.util.Enumeration;
17
import java.util.NoSuchElementException;
17
import java.util.NoSuchElementException;
18
18
19
/** The class that encapsulates one object into one element enumeration.
19
/** 
20
* @deprecated JDK1.5 treats enum as keyword and that is why this class had to be 
21
*  replaced by {@link org.openide.util.Enumerations#singleton}.
22
*
23
* The class that encapsulates one object into one element enumeration.
20
*
24
*
21
* @author   Jaroslav Tulach
25
* @author   Jaroslav Tulach
22
* @version  0.10, Apr 10, 1998
26
* @version  0.10, Apr 10, 1998
(-)openide/src/org/openide/util/lookup/ArrayStorage.java (-13 / +10 lines)
Lines 19-26 Link Here
19
import java.util.*;
19
import java.util.*;
20
20
21
import org.openide.util.Lookup;
21
import org.openide.util.Lookup;
22
import org.openide.util.enum.*;
23
24
22
25
/** ArrayStorage of Pairs from AbstractLookup.
23
/** ArrayStorage of Pairs from AbstractLookup.
26
 * @author  Jaroslav Tulach
24
 * @author  Jaroslav Tulach
Lines 207-232 Link Here
207
    * @see #unsorted
205
    * @see #unsorted
208
    */
206
    */
209
    public Enumeration lookup (final Class clazz) {
207
    public Enumeration lookup (final Class clazz) {
210
        class CheckEn extends org.openide.util.enum.FilterEnumeration {
208
        class CheckEn implements org.openide.util.Enumerations.Processor {
211
            public CheckEn (Enumeration en) {
209
            public Object process (Object o, Collection ignore) {
212
                super (en);
210
                boolean ok;
213
            }
214
            
215
            protected boolean accept (Object o) {
216
                if (o instanceof AbstractLookup.Pair) {
211
                if (o instanceof AbstractLookup.Pair) {
217
                    return clazz == null || ((AbstractLookup.Pair)o).instanceOf(clazz);
212
                    ok = clazz == null || ((AbstractLookup.Pair)o).instanceOf(clazz);
213
                } else {
214
                    ok = false;
218
                }
215
                }
219
                return false;
216
                return ok ? o : null;
220
            }
217
            }
221
        }
218
        }
222
        
219
        
223
        if (content instanceof Object[]) {
220
        if (content instanceof Object[]) {
224
            Enumeration all = new org.openide.util.enum.ArrayEnumeration (
221
            Enumeration all = org.openide.util.Enumerations.array (
225
                (Object[])content
222
                (Object[])content
226
            );
223
            );
227
            return new CheckEn (all);
224
            return org.openide.util.Enumerations.filter (all, new CheckEn ());
228
        } else {
225
        } else {
229
            return org.openide.util.enum.EmptyEnumeration.EMPTY;
226
            return org.openide.util.Enumerations.EMPTY;
230
        }
227
        }
231
    }
228
    }
232
229
(-)openide/src/org/openide/util/lookup/DelegatingStorage.java (-1 lines)
Lines 19-25 Link Here
19
import java.util.*;
19
import java.util.*;
20
20
21
import org.openide.util.Lookup;
21
import org.openide.util.Lookup;
22
import org.openide.util.enum.*;
23
22
24
23
25
/** Storages that can switch between another storages.
24
/** Storages that can switch between another storages.
(-)openide/src/org/openide/util/lookup/InheritanceTree.java (-24 / +40 lines)
Lines 21-28 Link Here
21
import org.openide.util.Lookup;
21
import org.openide.util.Lookup;
22
import org.openide.util.lookup.AbstractLookup.ReferenceIterator;
22
import org.openide.util.lookup.AbstractLookup.ReferenceIterator;
23
import org.openide.util.lookup.AbstractLookup.ReferenceToResult;
23
import org.openide.util.lookup.AbstractLookup.ReferenceToResult;
24
import org.openide.util.enum.*;
25
26
24
27
/** A tree to represent classes with inheritance. Description of the
25
/** A tree to represent classes with inheritance. Description of the
28
 * data structure by Petr Nejedly:
26
 * data structure by Petr Nejedly:
Lines 207-213 Link Here
207
     *   pair with smallest index
205
     *   pair with smallest index
208
     */
206
     */
209
    public static boolean unsorted (Enumeration en) {
207
    public static boolean unsorted (Enumeration en) {
210
        return en instanceof SequenceEnumeration;
208
        return en instanceof NeedsSortEnum;
211
    }
209
    }
212
    
210
    
213
    /** Prints debug messages.
211
    /** Prints debug messages.
Lines 435-441 Link Here
435
        }
433
        }
436
        if (n == null) {
434
        if (n == null) {
437
            // not for us
435
            // not for us
438
            return EmptyEnumeration.EMPTY;
436
            return org.openide.util.Enumerations.EMPTY;
439
        } else {
437
        } else {
440
            return nodeToEnum(n);
438
            return nodeToEnum(n);
441
        }
439
        }
Lines 505-543 Link Here
505
    private static Enumeration nodeToEnum(Node n) {
503
    private static Enumeration nodeToEnum(Node n) {
506
        if (n.children == null) {
504
        if (n.children == null) {
507
            // create a simple enumeration because we do not have children
505
            // create a simple enumeration because we do not have children
508
            return n.items == null ? EmptyEnumeration.EMPTY : Collections.enumeration (n.items);
506
            return n.items == null ? org.openide.util.Enumerations.EMPTY : Collections.enumeration (n.items);
509
        }
507
        }
510
        
508
        
511
        // we have found what we need
509
        // we have found what we need
512
        // now we have to just build the enumeration
510
        // now we have to just build the enumeration
513
        QueueEnumeration en = new QueueEnumeration () {
511
        class DeepAndItems implements org.openide.util.Enumerations.Processor {
514
            protected void process (Object obj) {
512
            public Object process (Object obj, Collection toAdd) {
515
                Node n2 = (Node)obj;
513
                Node n2 = (Node)obj;
516
                if (n2.children != null) {
514
                if (n2.children != null) {
517
                    Object[] nodes = n2.children.toArray ();
515
                    toAdd.addAll (n2.children);
518
                    put (nodes);
519
                }
516
                }
520
            }
517
                
521
        };
522
        // initial node is our current one
523
        en.put (n);
524
525
        // convert Node into enumeration of Enumerations of Items
526
        AlterEnumeration alt = new AlterEnumeration (en) {
527
            protected Object alter (Object obj) {
528
                Node n2 = (Node)obj;
529
                if (n2.items == null || n2.items.isEmpty ()) {
518
                if (n2.items == null || n2.items.isEmpty ()) {
530
                    return EmptyEnumeration.EMPTY;
519
                    return org.openide.util.Enumerations.EMPTY;
531
                } else {
520
                } else {
532
                    return Collections.enumeration (n2.items);
521
                    return Collections.enumeration (n2.items);
533
                }
522
                }
534
            }
523
            }
535
        };
524
        }
525
526
        Enumeration en = org.openide.util.Enumerations.queue (
527
            // initial node is our current one
528
            org.openide.util.Enumerations.singleton (n),
529
            new DeepAndItems ()
530
        );
536
531
537
        // create enumeration of Items
532
        // create enumeration of Items
538
        return new SequenceEnumeration (alt);
533
        return new NeedsSortEnum (org.openide.util.Enumerations.concat (en));
539
    }
534
    }
540
535
    
541
    //
536
    //
542
    // Methods to work on interfaces
537
    // Methods to work on interfaces
543
    // 
538
    // 
Lines 729-735 Link Here
729
            if (items == null && one != null) {
724
            if (items == null && one != null) {
730
                // single item mode
725
                // single item mode
731
                interfaces.put (clazz, one);
726
                interfaces.put (clazz, one);
732
                return new SingletonEnumeration (one);
727
                return org.openide.util.Enumerations.singleton (one);
733
            } else {
728
            } else {
734
                if (items == null) {
729
                if (items == null) {
735
                    items = new ArrayList (2);
730
                    items = new ArrayList (2);
Lines 742-748 Link Here
742
                return Collections.enumeration ((Collection)obj);
737
                return Collections.enumeration ((Collection)obj);
743
            } else {
738
            } else {
744
                // single item mode
739
                // single item mode
745
                return new SingletonEnumeration (obj);
740
                return org.openide.util.Enumerations.singleton (obj);
746
            }
741
            }
747
        }
742
        }
748
    }
743
    }
Lines 988-992 Link Here
988
        }
983
        }
989
            
984
            
990
    } // end of R
985
    } // end of R
986
987
    /** Just a marker class to be able to do instanceof and find out
988
     * that this enumeration is not sorted
989
     */
990
    private static final class NeedsSortEnum implements Enumeration {
991
        private Enumeration en;
992
        
993
        public NeedsSortEnum (Enumeration en) {
994
            this.en = en;
995
        }
996
        
997
        public boolean hasMoreElements () {
998
            return en.hasMoreElements ();
999
        }
1000
        
1001
        public Object nextElement () {
1002
            return en.nextElement ();
1003
        }
1004
        
1005
    } // end of NeedsSortEnum
1006
991
    
1007
    
992
}
1008
}
(-)openide/test/unit/src/org/openide/util/EnumerationsTest.java (+448 lines)
Added Link Here
1
/*
2
 *                 Sun Public License Notice
3
 * 
4
 * The contents of this file are subject to the Sun Public License
5
 * Version 1.0 (the "License"). You may not use this file except in
6
 * compliance with the License. A copy of the License is available at
7
 * http://www.sun.com/
8
 * 
9
 * The Original Code is NetBeans. The Initial Developer of the Original
10
 * Code is Sun Microsystems, Inc. Portions Copyright 1997-2003 Sun
11
 * Microsystems, Inc. All Rights Reserved.
12
 */
13
package org.openide.util;
14
15
import java.util.*;
16
import java.util.Enumeration;
17
import java.util.Map;
18
import java.util.Set;
19
20
/** This is the base test for new and old enumerations. It contains 
21
 * factory methods for various kinds of enumerations and set of tests
22
 * that use them. Factory methods are overriden in OldEnumerationsTest
23
 *
24
 * @author Jaroslav Tulach
25
 */
26
public class EnumerationsTest extends org.netbeans.junit.NbTestCase {
27
    
28
    /** Creates a new instance of EnumerationsTest */
29
    public EnumerationsTest (String testName) {
30
        super(testName);
31
    }
32
33
    public static void main(java.lang.String[] args) {
34
        junit.textui.TestRunner.run(new org.netbeans.junit.NbTestSuite(EnumerationsTest.class));
35
    }
36
37
    //
38
    // Factory methods
39
    //
40
    
41
    protected Enumeration singleton (Object obj) {
42
        return Enumerations.singleton (obj);
43
    }
44
    protected Enumeration concat (Enumeration en1, Enumeration en2) {
45
        return Enumerations.concat (en1, en2);
46
    }
47
    protected Enumeration concat (Enumeration enumOfEnums) {
48
        return Enumerations.concat (enumOfEnums);
49
    }
50
    protected Enumeration removeDuplicates (Enumeration en) {
51
        return Enumerations.removeDuplicates (en);
52
    }
53
    protected Enumeration empty () {
54
        return Enumerations.EMPTY;
55
    }
56
    protected Enumeration array (Object[] arr) {
57
        return Enumerations.array (arr);
58
    }
59
    protected Enumeration convert (Enumeration en, final Map map) {
60
        class P implements Enumerations.Processor {
61
            public Object process (Object obj, Collection nothing) {
62
                return map.get (obj);
63
            }
64
        }
65
        
66
        
67
        return Enumerations.convert (en, new P ());
68
    }
69
    protected Enumeration removeNulls (Enumeration en) {
70
        return Enumerations.removeNulls (en);
71
    }
72
    protected Enumeration filter (Enumeration en, final Set filter) {
73
        class P implements Enumerations.Processor {
74
            public Object process (Object obj, Collection nothing) {
75
                return filter.contains (obj) ? obj : null;
76
            }
77
        }
78
        
79
        return Enumerations.filter (en, new P ());
80
    }
81
    
82
    protected Enumeration filter (Enumeration en, final QueueProcess filter) {
83
        class P implements Enumerations.Processor {
84
            public Object process (Object obj, Collection nothing) {
85
                return filter.process (obj, nothing);
86
            }
87
        }
88
        
89
        return Enumerations.filter (en, new P ());
90
    }
91
    
92
    /**
93
     * @param filter the set.contains (...) is called before each object is produced
94
     * @return Enumeration
95
     */
96
    protected Enumeration queue (Collection initContent, final QueueProcess process) {
97
        class C implements Enumerations.Processor {
98
            public Object process (Object object, Collection toAdd) {
99
                return process.process (object, toAdd);
100
            }
101
        }
102
        return Enumerations.queue (
103
            Collections.enumeration (initContent), 
104
            new C ()
105
        );
106
    }
107
    
108
    /** Processor interface.
109
     */
110
    public static interface QueueProcess {
111
        public Object process (Object object, Collection toAdd);
112
    }
113
114
    //
115
    // The tests
116
    // 
117
    
118
    public void testEmptyIsEmpty () {
119
        Enumeration e = empty ();
120
        assertFalse (e.hasMoreElements ());
121
        try {
122
            e.nextElement ();
123
            fail ("No elements");
124
        } catch (java.util.NoSuchElementException ex) {
125
            // ok
126
        }
127
    }
128
    
129
    public void testSingleIsSingle () {
130
        Enumeration e = singleton (this);
131
        assertTrue (e.hasMoreElements ());
132
        assertEquals ("Returns me", this, e.nextElement ());
133
        assertFalse ("Now it is empty", e.hasMoreElements ());
134
        try {
135
            e.nextElement ();
136
            fail ("No elements");
137
        } catch (java.util.NoSuchElementException ex) {
138
            // ok
139
        }
140
    }
141
142
    public void testConcatTwoAndArray () {
143
        Object[] one = { new Integer (1), new Integer (2), new Integer (3) };
144
        Object[] two = { "1", "2", "3" };
145
        
146
        ArrayList list = new ArrayList (Arrays.asList (one));
147
        list.addAll (Arrays.asList (two));
148
        
149
        assertEnums (
150
            concat (array (one), array (two)),
151
            Collections.enumeration (list)
152
        );
153
    }
154
    
155
    public void testConcatTwoAndArrayAndTakeOnlyStrings () {
156
        Object[] one = { new Integer (1), new Integer (2), new Integer (3) };
157
        Object[] two = { "1", "2", "3" };
158
        Object[] three = { new Long (1) };
159
        Object[] four = { "Kuk" };
160
        
161
        ArrayList list = new ArrayList (Arrays.asList (two));
162
        list.addAll (Arrays.asList (four));
163
        
164
        Enumeration[] alls = {
165
            array (one), array (two), array (three), array (four)
166
        };
167
        
168
        assertEnums (
169
            filter (concat (array (alls)), new OnlyStrings()),
170
            Collections.enumeration (list)
171
        );
172
    }
173
    
174
    public void testRemoveDuplicates () {
175
        Object[] one = { new Integer (1), new Integer (2), new Integer (3) };
176
        Object[] two = { "1", "2", "3" };
177
        Object[] three = { new Integer (1) };
178
        Object[] four = { "2", "3", "4" };
179
        
180
        Enumeration[] alls = {
181
            array (one), array (two), array (three), array (four)
182
        };
183
        
184
        assertEnums (
185
            removeDuplicates (concat (array (alls))),
186
            array (new Object[] { new Integer (1), new Integer (2), new Integer (3), "1", "2", "3", "4" })
187
        );
188
        
189
    }
190
191
    public void testRemoveDuplicatesAndGCWorks () {
192
        
193
        /*** Return { i1, "", "", "", i2 } */
194
        class WeakEnum implements Enumeration {
195
            public Object i1 = new Integer (1);
196
            public Object i2 = new Integer (1);
197
            
198
            private int state;
199
            
200
            public boolean hasMoreElements () {
201
                return state < 5;
202
            }
203
            
204
            public Object nextElement () {
205
                switch (state++) {
206
                    case 0: return i1;    
207
                    case 1: case 2: case 3: return "";
208
                    default: return i2;
209
                }
210
            }
211
        }
212
        
213
        WeakEnum weak = new WeakEnum ();
214
        Enumeration en = removeDuplicates (weak);
215
        
216
        assertTrue ("Has some elements", en.hasMoreElements ());
217
        assertEquals ("And the first one is get", weak.i1, en.nextElement ());
218
        
219
        try {
220
            java.lang.ref.WeakReference ref = new java.lang.ref.WeakReference (weak.i1);
221
            weak.i1 = null;
222
            assertGC ("Try hard to GC the first integer", ref);
223
            // does not matter whether it GCs or not
224
        } catch (Throwable tw) {
225
            // not GCed, but does not matter
226
        }
227
        assertTrue ("Next object will be string", en.hasMoreElements ());
228
        assertEquals ("is empty string", "", en.nextElement ());
229
        
230
        assertFalse ("The second integer is however equal to the original i1 and thus" +
231
        " the enum should not be there", en.hasMoreElements ());
232
    }
233
    
234
    public void testQueueEnum () {
235
        class Pr implements QueueProcess {
236
            public Object process (Object o, Collection c) {
237
                Integer i = (Integer)o;
238
                int plus = i.intValue () + 1;
239
                if (plus < 10) {
240
                    c.add (new Integer (plus));
241
                }
242
                return i;
243
            }
244
        }
245
        Pr p = new Pr ();
246
        
247
        Enumeration en = queue (
248
            Collections.nCopies (1, new Integer (0)), p
249
        );
250
        
251
        for (int i = 0; i < 10; i++) {
252
            assertTrue ("has next", en.hasMoreElements ());
253
            en.nextElement ();
254
        }
255
        
256
        assertFalse ("No next element", en.hasMoreElements ());
257
    }
258
    
259
    public void testFilteringAlsoDoesConvertions () throws Exception {
260
        class Pr implements QueueProcess {
261
            public Object process (Object o, Collection ignore) {
262
                Integer i = (Integer)o;
263
                int plus = i.intValue () + 1;
264
                return new Integer (plus);
265
            }
266
        }
267
        Pr p = new Pr ();
268
        
269
        Enumeration onetwo = array (new Object[] { new Integer (1), new Integer (2) });
270
        Enumeration twothree = array (new Object[] { new Integer (2), new Integer (3) });
271
        
272
        assertEnums (
273
            filter (onetwo, p), twothree
274
        );
275
    }
276
    
277
    
278
    private static void assertEnums (Enumeration e1, Enumeration e2) {
279
        int indx = 0;
280
        while (e1.hasMoreElements () && e2.hasMoreElements ()) {
281
            Object i1 = e1.nextElement ();
282
            Object i2 = e2.nextElement ();
283
            assertEquals (indx++ + "th: ", i1, i2);
284
        }
285
        
286
        if (e1.hasMoreElements ()) {
287
            fail ("first one contains another element: " + e1.nextElement ());
288
        }
289
        if (e2.hasMoreElements ()) {
290
            fail ("second one contains another element: " + e2.nextElement ());
291
        }
292
        
293
        try {
294
            e1.nextElement ();
295
            fail ("First one should throw exception, but nothing happend");
296
        } catch (java.util.NoSuchElementException ex) {
297
            // ok
298
        }
299
        
300
        try {
301
            e2.nextElement ();
302
            fail ("Second one should throw exception, but nothing happend");
303
        } catch (java.util.NoSuchElementException ex) {
304
            // ok
305
        }
306
    }
307
    
308
    public void testConvertIntegersToStringRemoveNulls () {
309
        Object[] garbage = { new Integer (1), "kuk", "hle", new Integer (5) };
310
        
311
        assertEnums (
312
            removeNulls (convert (array (garbage), new MapIntegers ())), 
313
            array (new Object[] { "1", "5" })
314
        );
315
    }
316
    
317
    /** Filters only strings.
318
     */
319
    private static final class OnlyStrings implements java.util.Set {
320
        public boolean add (Object o) {
321
            fail ("Should not be every called");
322
            return false;
323
        }
324
        
325
        public boolean addAll (Collection c) {
326
            fail ("Should not be every called");
327
            return false;
328
        }
329
        
330
        public void clear () {
331
            fail ("Should not be every called");
332
        }
333
        
334
        public boolean contains (Object o) {
335
            return o instanceof String;
336
        }
337
        
338
        public boolean containsAll (Collection c) {
339
            fail ("Should not be every called");
340
            return false;
341
        }
342
        
343
        public boolean isEmpty () {
344
            fail ("Should not be every called");
345
            return false;
346
        }
347
        
348
        public Iterator iterator () {
349
            fail ("Should not be every called");
350
            return null;
351
        }
352
        
353
        public boolean remove (Object o) {
354
            fail ("Should not be every called");
355
            return false;
356
        }
357
        
358
        public boolean removeAll (Collection c) {
359
            fail ("Should not be every called");
360
            return false;
361
        }
362
        
363
        public boolean retainAll (Collection c) {
364
            fail ("Should not be every called");
365
            return false;
366
        }
367
        
368
        public int size () {
369
            fail ("Should not be every called");
370
            return 1;
371
        }
372
        
373
        public Object[] toArray () {
374
            fail ("Should not be every called");
375
            return null;
376
        }
377
        
378
        public Object[] toArray (Object[] a) {
379
            fail ("Should not be every called");
380
            return null;
381
        }
382
    }
383
    
384
    /** Filters only strings.
385
     */
386
    private static final class MapIntegers implements java.util.Map {
387
        public boolean containsKey (Object key) {
388
            fail ("Should not be every called");
389
            return false;
390
        }
391
        
392
        public boolean containsValue (Object value) {
393
            fail ("Should not be every called");
394
            return false;
395
        }
396
        
397
        public Set entrySet () {
398
            fail ("Should not be every called");
399
            return null;
400
        }
401
        
402
        public Object get (Object key) {
403
            if (key instanceof Integer) {
404
                return key.toString ();
405
            }
406
            return null;
407
        }
408
        
409
        public Set keySet () {
410
            fail ("Should not be every called");
411
            return null;
412
        }
413
        
414
        public Object put (Object key, Object value) {
415
            fail ("Should not be every called");
416
            return null;
417
        }
418
        
419
        public void putAll (Map t) {
420
            fail ("Should not be every called");
421
        }
422
        
423
        public Collection values () {
424
            fail ("Should not be every called");
425
            return null;
426
        }
427
        
428
        public void clear () {
429
            fail ("Should not be every called");
430
        }
431
        
432
        public boolean isEmpty () {
433
            fail ("Should not be every called");
434
            return false;
435
        }
436
        
437
        public Object remove (Object key) {
438
            fail ("Should not be every called");
439
            return null;
440
        }
441
        
442
        public int size () {
443
            fail ("Should not be every called");
444
            return 1;
445
        }
446
        
447
    }
448
}
(-)openide/test/unit/src/org/openide/util/OldEnumerationsTest.java (+153 lines)
Added Link Here
1
/*
2
 *                 Sun Public License Notice
3
 * 
4
 * The contents of this file are subject to the Sun Public License
5
 * Version 1.0 (the "License"). You may not use this file except in
6
 * compliance with the License. A copy of the License is available at
7
 * http://www.sun.com/
8
 * 
9
 * The Original Code is NetBeans. The Initial Developer of the Original
10
 * Code is Sun Microsystems, Inc. Portions Copyright 1997-2003 Sun
11
 * Microsystems, Inc. All Rights Reserved.
12
 */
13
package org.openide.util;
14
15
import java.util.Collection;
16
import org.openide.util.enum.*;
17
import org.openide.util.enum.QueueEnumeration;
18
19
/** Implement factory methods from EnumerationsTest, shares the same tests
20
 * with EnumerationsTest.
21
 *
22
 * @author Jaroslav Tulach
23
 */
24
public class OldEnumerationsTest extends EnumerationsTest {
25
    
26
    /** Creates a new instance of EnumerationsTest */
27
    public OldEnumerationsTest (String testName) {
28
        super(testName);
29
    }
30
31
    public static void main(java.lang.String[] args) {
32
        junit.textui.TestRunner.run(new org.netbeans.junit.NbTestSuite(OldEnumerationsTest.class));
33
    }
34
35
    protected java.util.Enumeration singleton (Object obj) {
36
        return new SingletonEnumeration (obj);
37
    }    
38
    
39
    protected java.util.Enumeration convert (java.util.Enumeration en, final java.util.Map map) {
40
        return new AlterEnumeration (en) {
41
            protected Object alter (Object o) {
42
                return map.get (o);
43
            }
44
        };
45
    }    
46
47
    protected java.util.Enumeration removeDuplicates (java.util.Enumeration en) {
48
        return new RemoveDuplicatesEnumeration (en);
49
    }
50
    
51
    protected java.util.Enumeration removeNulls (java.util.Enumeration en) {
52
        return new FilterEnumeration (en);
53
    }
54
    
55
    protected java.util.Enumeration concat (java.util.Enumeration en1, java.util.Enumeration en2) {
56
        return new SequenceEnumeration (en1, en2);
57
    }
58
    
59
    protected java.util.Enumeration array (Object[] arr) {
60
        return new ArrayEnumeration (arr);
61
    }
62
    
63
    protected java.util.Enumeration filter (java.util.Enumeration en, final java.util.Set filter) {
64
        return new FilterEnumeration (en) {
65
            protected boolean accept (Object obj) {
66
                return filter.contains (obj);
67
            }
68
        };
69
    }
70
    protected java.util.Enumeration filter (java.util.Enumeration en, final QueueProcess filter) {
71
        en = new AlterEnumeration (en) {
72
            public Object alter (Object alter) {
73
                return filter.process (alter, null);
74
            }
75
        };
76
        
77
        return new FilterEnumeration (en);
78
    }
79
    
80
    protected java.util.Enumeration concat (java.util.Enumeration enumOfEnums) {
81
        return new SequenceEnumeration (enumOfEnums);
82
    }
83
    
84
    protected java.util.Enumeration empty () {
85
        return new EmptyEnumeration ();
86
    }
87
    
88
    protected java.util.Enumeration queue (Collection init, final QueueProcess process) {
89
        class QEAdd extends QueueEnumeration implements Collection {
90
            protected void process (Object obj) {
91
                process.process (obj, this);
92
            }
93
            
94
            public boolean add (Object o) {
95
                put (o);
96
                return true;
97
            }
98
            
99
            public boolean addAll (Collection c) {
100
                put (c.toArray ());
101
                return true;
102
            }
103
            
104
            public void clear () {
105
                throw new IllegalStateException ("Unsupported");
106
            }
107
            
108
            public boolean contains (Object o) {
109
                throw new IllegalStateException ("Unsupported");
110
            }
111
            
112
            public boolean containsAll (Collection c) {
113
                throw new IllegalStateException ("Unsupported");
114
            }
115
            
116
            public boolean isEmpty () {
117
                throw new IllegalStateException ("Unsupported");
118
            }
119
            
120
            public java.util.Iterator iterator () {
121
                throw new IllegalStateException ("Unsupported");
122
            }
123
            
124
            public boolean remove (Object o) {
125
                throw new IllegalStateException ("Unsupported");
126
            }
127
            
128
            public boolean removeAll (Collection c) {
129
                throw new IllegalStateException ("Unsupported");
130
            }
131
            
132
            public boolean retainAll (Collection c) {
133
                throw new IllegalStateException ("Unsupported");
134
            }
135
            
136
            public int size () {
137
                throw new IllegalStateException ("Unsupported");
138
            }
139
            
140
            public Object[] toArray () {
141
                throw new IllegalStateException ("Unsupported");
142
            }
143
            
144
            public Object[] toArray (Object[] a) {
145
                throw new IllegalStateException ("Unsupported");
146
            }
147
        }
148
        QEAdd qe = new QEAdd ();
149
        qe.put (init.toArray ());
150
        return qe;
151
    }
152
    
153
}
(-)openide/loaders/src/org/openide/actions/FileSystemAction.java (-13 / +16 lines)
Lines 33-39 Link Here
33
import org.openide.nodes.Node;
33
import org.openide.nodes.Node;
34
import org.openide.util.Lookup;
34
import org.openide.util.Lookup;
35
import org.openide.util.NbBundle;
35
import org.openide.util.NbBundle;
36
import org.openide.util.enum.*;
37
36
38
37
39
/** Action that presents standard file system-related actions.
38
/** Action that presents standard file system-related actions.
Lines 94-103 Link Here
94
            /* At present not allowed to construct actions for selected nodes on more filesystems - its safe behaviour
93
            /* At present not allowed to construct actions for selected nodes on more filesystems - its safe behaviour
95
             * If this restriction will be considered as right solution, then code of this method can be simplified
94
             * If this restriction will be considered as right solution, then code of this method can be simplified
96
             */
95
             */
97
            if (fsSet.size () == 0 || fsSet.size() > 1) return createMenu (EmptyEnumeration.EMPTY, popUp, lookup);
96
            if (fsSet.size () == 0 || fsSet.size() > 1) return createMenu (org.openide.util.Enumerations.EMPTY, popUp, lookup);
98
            
97
            
99
            Iterator entrySetIt = fsSet.entrySet ().iterator();
98
            Iterator entrySetIt = fsSet.entrySet ().iterator();
100
            QueueEnumeration result = new QueueEnumeration();
99
            LinkedList result = new LinkedList ();
101
100
102
            while (entrySetIt.hasNext()) {
101
            while (entrySetIt.hasNext()) {
103
                Map.Entry entry = (Map.Entry)entrySetIt.next();
102
                Map.Entry entry = (Map.Entry)entrySetIt.next();
Lines 121-131 Link Here
121
                }
120
                }
122
                Set backSet = new OrderedSet();
121
                Set backSet = new OrderedSet();
123
                backSet.addAll(backupList);
122
                backSet.addAll(backupList);
124
                result.put( fs.getActions (backSet) );
123
                result.addAll (java.util.Arrays.asList (fs.getActions (backSet)));
125
            }
124
            }
126
            
125
            
127
            
126
            
128
            return createMenu ( result, popUp, lookup);
127
            return createMenu (Collections.enumeration (result), popUp, lookup);
129
        }
128
        }
130
        return NONE;
129
        return NONE;
131
    }
130
    }
Lines 136-142 Link Here
136
    *   into the menu if enabled and if not duplicated
135
    *   into the menu if enabled and if not duplicated
137
    */
136
    */
138
    static JMenuItem[] createMenu (Enumeration en, boolean popUp, Lookup lookup) {
137
    static JMenuItem[] createMenu (Enumeration en, boolean popUp, Lookup lookup) {
139
        en = new RemoveDuplicatesEnumeration (en);
138
        en = org.openide.util.Enumerations.removeDuplicates (en);
140
139
141
        ArrayList items = new ArrayList ();
140
        ArrayList items = new ArrayList ();
142
        while (en.hasMoreElements ()) {
141
        while (en.hasMoreElements ()) {
Lines 306-312 Link Here
306
    private static final class OrderedSet extends AbstractSet {
305
    private static final class OrderedSet extends AbstractSet {
307
        
306
        
308
        /** Queue of collections of elements. */
307
        /** Queue of collections of elements. */
309
        private QueueEnumeration queue = new QueueEnumeration();
308
        private LinkedList queue = new LinkedList ();
310
        /** Objects stored in this set. */
309
        /** Objects stored in this set. */
311
        Object[] objects = null;
310
        Object[] objects = null;
312
        
311
        
Lines 318-337 Link Here
318
         * Adds all of the elements in the specified collection to this collection.
317
         * Adds all of the elements in the specified collection to this collection.
319
         */
318
         */
320
        public boolean addAll(Collection coll) {
319
        public boolean addAll(Collection coll) {
321
            queue.put(coll);
320
            queue.add (coll);
322
            return true;
321
            return true;
323
        }
322
        }
324
        
323
        
325
        
324
        
326
        private Object[] getObjects() {
325
        private Object[] getObjects() {
327
            if (objects == null) {
326
            if (objects == null) {
328
                AlterEnumeration altered = new AlterEnumeration(queue) {
327
                class Coll2Enum implements org.openide.util.Enumerations.Processor {
329
                    public Object alter(Object obj) {
328
                    public Object process (Object obj, java.util.Collection ignore) {
330
                        return Collections.enumeration((Collection) obj);
329
                        return Collections.enumeration((Collection) obj);
331
                    }
330
                    }
332
                };
331
                }
333
                SequenceEnumeration sequenced = new SequenceEnumeration(altered);
332
                Enumeration sequenced = org.openide.util.Enumerations.concat (
334
                Enumeration result = new RemoveDuplicatesEnumeration(sequenced);
333
                    org.openide.util.Enumerations.convert (
334
                        Collections.enumeration (queue), new Coll2Enum ()
335
                    )
336
                );
337
                Enumeration result = org.openide.util.Enumerations.removeDuplicates (sequenced);
335
                ArrayList objectList = new ArrayList();
338
                ArrayList objectList = new ArrayList();
336
                for (int i = 0; result.hasMoreElements(); i++) {
339
                for (int i = 0; result.hasMoreElements(); i++) {
337
                    objectList.add(result.nextElement());
340
                    objectList.add(result.nextElement());
(-)openide/loaders/src/org/openide/loaders/DataFolder.java (-21 / +15 lines)
Lines 35-41 Link Here
35
import org.openide.util.HelpCtx;
35
import org.openide.util.HelpCtx;
36
import org.openide.nodes.*;
36
import org.openide.nodes.*;
37
import org.openide.util.Lookup;
37
import org.openide.util.Lookup;
38
import org.openide.util.enum.QueueEnumeration;
39
import org.openide.util.NbBundle;
38
import org.openide.util.NbBundle;
40
import org.openide.util.RequestProcessor;
39
import org.openide.util.RequestProcessor;
41
40
Lines 277-303 Link Here
277
        if (!rec) {
276
        if (!rec) {
278
            return children();
277
            return children();
279
        }
278
        }
280
        QueueEnumeration en = new QueueEnumeration () {
279
        
281
                                  /** @param o processes object by adding its children to the queue */
280
        class Processor implements org.openide.util.Enumerations.Processor {
282
                                  public void process (Object o) {
281
            /** @param o processes object by adding its children to the queue */
283
                                      DataObject dataObj = (DataObject)o;
282
            public Object process (Object o, Collection toAdd) {
284
                                      if (rec && dataObj instanceof DataFolder) {
283
                DataObject dataObj = (DataObject)o;
285
                                          addChildrenToEnum(this, ((DataFolder)dataObj).getChildren());
284
                if (rec && dataObj instanceof DataFolder) {
286
                                      }
285
                    toAdd.addAll (Arrays.asList (((DataFolder)dataObj).getChildren()));
287
                                  }
286
                }
288
                              };
287
                return o;
289
        addChildrenToEnum(en, getChildren());
288
            }
290
        return en;
291
    }
292
293
    /** Puts children into QueueEnumeration.
294
    * @param en the queue enumeration to add children to
295
    * @param list array of data objects
296
    */
297
    static void addChildrenToEnum (QueueEnumeration en, DataObject[] list) {
298
        for (int i = 0; i < list.length; i++) {
299
            en.put(list[i]);
300
        }
289
        }
290
        Enumeration en = org.openide.util.Enumerations.queue (
291
            org.openide.util.Enumerations.array (getChildren ()),
292
            new Processor ()
293
        );
294
        return en;
301
    }
295
    }
302
296
303
    /** Create node representative for this folder.
297
    /** Create node representative for this folder.
(-)openide/loaders/src/org/openide/loaders/DataLoaderPool.java (-19 / +17 lines)
Lines 30-39 Link Here
30
import org.openide.nodes.Node;
30
import org.openide.nodes.Node;
31
import org.openide.nodes.FilterNode;
31
import org.openide.nodes.FilterNode;
32
import org.openide.modules.ModuleInfo;
32
import org.openide.modules.ModuleInfo;
33
import org.openide.util.enum.ArrayEnumeration;
33
import org.openide.util.Enumerations;
34
import org.openide.util.enum.FilterEnumeration;
35
import org.openide.util.enum.SingletonEnumeration;
36
import org.openide.util.enum.SequenceEnumeration;
37
import org.openide.util.actions.SystemAction;
34
import org.openide.util.actions.SystemAction;
38
import org.openide.util.NbBundle;
35
import org.openide.util.NbBundle;
39
import org.openide.util.Lookup;
36
import org.openide.util.Lookup;
Lines 230-250 Link Here
230
    public final Enumeration allLoaders () {
227
    public final Enumeration allLoaders () {
231
	if (preferredLoader == null) {
228
	if (preferredLoader == null) {
232
            // enumeration of systemloaders followed by normal loaders
229
            // enumeration of systemloaders followed by normal loaders
233
	    return new SequenceEnumeration (
230
	    return Enumerations.concat (
234
		new ArrayEnumeration ( new Enumeration[] {
231
		Enumerations.array ( new Enumeration[] {
235
    		    new ArrayEnumeration (getSystemLoaders ()),
232
    		    Enumerations.array (getSystemLoaders ()),
236
    		    loaders (),
233
    		    loaders (),
237
    		    new ArrayEnumeration (getDefaultLoaders ())
234
    		    Enumerations.array (getDefaultLoaders ())
238
		} )
235
		} )
239
	    );
236
	    );
240
	} else {
237
	} else {
241
            // enumeration of preferred loader folowed by systemloaders and normal loaders
238
            // enumeration of preferred loader folowed by systemloaders and normal loaders
242
	    return new SequenceEnumeration (
239
	    return Enumerations.concat (
243
		new ArrayEnumeration ( new Enumeration[] {
240
		Enumerations.array ( new Enumeration[] {
244
        	    new SingletonEnumeration (preferredLoader),
241
        	    Enumerations.singleton (preferredLoader),
245
    		    new ArrayEnumeration (getSystemLoaders ()),
242
    		    Enumerations.array (getSystemLoaders ()),
246
    		    loaders (),
243
    		    loaders (),
247
    		    new ArrayEnumeration (getDefaultLoaders ())
244
    		    Enumerations.array (getDefaultLoaders ())
248
		} )
245
		} )
249
	    );
246
	    );
250
	}
247
	}
Lines 297-310 Link Here
297
     * @return enumeration of {@link DataLoader}s
294
     * @return enumeration of {@link DataLoader}s
298
     */
295
     */
299
    public final Enumeration producersOf (final Class clazz) {
296
    public final Enumeration producersOf (final Class clazz) {
300
        return new FilterEnumeration (allLoaders ()) {
297
        class ProducerOf implements Enumerations.Processor {
301
                   /** Accepts only those loaders that produces superclass of clazz
298
            public Object process (Object o, java.util.Collection ignore) {
302
                    */
303
            public boolean accept (Object o) {
304
                DataLoader dl = (DataLoader)o;
299
                DataLoader dl = (DataLoader)o;
305
                return clazz.isAssignableFrom( dl.getRepresentationClass() );
300
                return clazz.isAssignableFrom( dl.getRepresentationClass() ) ? o : null;
306
            }
301
            }
307
        };
302
        }
303
        
304
        // Accepts only those loaders that produces superclass of clazz
305
        return Enumerations.filter (allLoaders (), new ProducerOf ());
308
    }
306
    }
309
    
307
    
310
    
308
    
(-)openide/loaders/src/org/openide/loaders/DataObject.java (-1 lines)
Lines 31-37 Link Here
31
import org.openide.filesystems.*;
31
import org.openide.filesystems.*;
32
import org.openide.filesystems.FileSystem; // override java.io.FileSystem
32
import org.openide.filesystems.FileSystem; // override java.io.FileSystem
33
import org.openide.util.*;
33
import org.openide.util.*;
34
import org.openide.util.enum.*;
35
import org.openide.nodes.*;
34
import org.openide.nodes.*;
36
35
37
/** Object that represents one or more file objects, with added behavior.
36
/** Object that represents one or more file objects, with added behavior.
(-)openide/loaders/src/org/openide/loaders/ExtensionList.java (-1 / +1 lines)
Lines 197-203 Link Here
197
     */
197
     */
198
    private static Enumeration en (Collection c) {
198
    private static Enumeration en (Collection c) {
199
        if (c == null) {
199
        if (c == null) {
200
            return org.openide.util.enum.EmptyEnumeration.EMPTY;
200
            return org.openide.util.Enumerations.EMPTY;
201
        } else {
201
        } else {
202
            return Collections.enumeration(c);
202
            return Collections.enumeration(c);
203
        }
203
        }
(-)openide/loaders/src/org/openide/loaders/FolderOrder.java (-2 / +3 lines)
Lines 20-26 Link Here
20
import java.util.*;
20
import java.util.*;
21
21
22
import org.openide.filesystems.*;
22
import org.openide.filesystems.*;
23
import org.openide.util.enum.*;
24
import org.openide.loaders.DataFolder.SortMode;
23
import org.openide.loaders.DataFolder.SortMode;
25
24
26
25
Lines 94-100 Link Here
94
            order = new HashMap (arr.length * 4 / 3 + 1);
93
            order = new HashMap (arr.length * 4 / 3 + 1);
95
94
96
            // each object only once
95
            // each object only once
97
            Enumeration en = new RemoveDuplicatesEnumeration (new ArrayEnumeration (arr));
96
            Enumeration en = org.openide.util.Enumerations.removeDuplicates (
97
                org.openide.util.Enumerations.array (arr)
98
            );
98
99
99
            int i = 0;
100
            int i = 0;
100
            while (en.hasMoreElements ()) {
101
            while (en.hasMoreElements ()) {
(-)openide/loaders/src/org/openide/loaders/InstanceDataObject.java (-1 / +1 lines)
Lines 1602-1608 Link Here
1602
        }
1602
        }
1603
1603
1604
        public java.util.Enumeration getAttributes() {
1604
        public java.util.Enumeration getAttributes() {
1605
            return fo == null? org.openide.util.enum.EmptyEnumeration.EMPTY: fo.getAttributes();
1605
            return fo == null? org.openide.util.Enumerations.EMPTY: fo.getAttributes();
1606
        }
1606
        }
1607
1607
1608
        public FileObject[] getChildren() {
1608
        public FileObject[] getChildren() {
(-)openide/masterfs/src/org/netbeans/modules/masterfs/Cache.java (-2 / +1 lines)
Lines 14-20 Link Here
14
package org.netbeans.modules.masterfs;
14
package org.netbeans.modules.masterfs;
15
15
16
import org.openide.filesystems.FileObject;
16
import org.openide.filesystems.FileObject;
17
import org.openide.util.enum.ArrayEnumeration;
18
17
19
import java.lang.ref.Reference;
18
import java.lang.ref.Reference;
20
import java.lang.ref.SoftReference;
19
import java.lang.ref.SoftReference;
Lines 124-130 Link Here
124
        }
123
        }
125
        final Object[] array = new Object[arrayList.size()];
124
        final Object[] array = new Object[arrayList.size()];
126
        arrayList.toArray(array);
125
        arrayList.toArray(array);
127
        return new ArrayEnumeration(array);
126
        return org.openide.util.Enumerations.array (array);
128
    }
127
    }
129
128
130
    void clear() {
129
    void clear() {
(-)openide/masterfs/src/org/netbeans/modules/masterfs/InvalidDummy.java (-2 / +1 lines)
Lines 14-20 Link Here
14
package org.netbeans.modules.masterfs;
14
package org.netbeans.modules.masterfs;
15
15
16
import org.openide.filesystems.*;
16
import org.openide.filesystems.*;
17
import org.openide.util.enum.EmptyEnumeration;
18
17
19
import java.io.FileNotFoundException;
18
import java.io.FileNotFoundException;
20
import java.io.IOException;
19
import java.io.IOException;
Lines 78-84 Link Here
78
    }
77
    }
79
78
80
    public Enumeration getAttributes() {
79
    public Enumeration getAttributes() {
81
        return EmptyEnumeration.EMPTY;
80
        return org.openide.util.Enumerations.EMPTY;
82
    }
81
    }
83
82
84
    public void addFileChangeListener(FileChangeListener fcl) {
83
    public void addFileChangeListener(FileChangeListener fcl) {
(-)openide/masterfs/src/org/netbeans/modules/masterfs/MasterFileObject.java (-33 / +53 lines)
Lines 18-26 Link Here
18
18
19
import org.openide.ErrorManager;
19
import org.openide.ErrorManager;
20
import org.openide.filesystems.*;
20
import org.openide.filesystems.*;
21
import org.openide.util.enum.ArrayEnumeration;
22
import org.openide.util.enum.FilterEnumeration;
23
import org.openide.util.enum.QueueEnumeration;
24
import org.openide.util.Utilities;
21
import org.openide.util.Utilities;
25
22
26
import javax.swing.event.EventListenerList;
23
import javax.swing.event.EventListenerList;
Lines 268-306 Link Here
268
     * Implements FileObject.transformChildren(boolean rec)
265
     * Implements FileObject.transformChildren(boolean rec)
269
     */
266
     */
270
    public Enumeration getChildren(boolean rec) {
267
    public Enumeration getChildren(boolean rec) {
268
        Enumeration my = org.openide.util.Enumerations.array (this.getChildren());
269
        
271
        if (rec == false)
270
        if (rec == false)
272
            return new ArrayEnumeration(this.getChildren());
271
            return my;
273
272
274
        QueueEnumeration en = getChildsEnum();
273
        return org.openide.util.Enumerations.queue (
275
        en.put(this.getChildren());
274
            my, getChildsEnum ()
276
        return en;
275
        );
277
    }
276
    }
278
277
279
    /**
278
    /**
280
     * Implements FileObject.getFolders(boolean rec)
279
     * Implements FileObject.getFolders(boolean rec)
281
     */
280
     */
282
    public Enumeration getFolders(boolean rec) {
281
    public Enumeration getFolders(boolean rec) {
283
        return new FilterEnumeration(getChildren(rec)) {
282
        return org.openide.util.Enumerations.filter (
284
            protected boolean accept(final Object o) {
283
            getChildren (rec), new AcceptFolders (true)
285
                final FileObject fo = (FileObject) o;
284
        );
286
                return fo.isFolder();
287
            }
288
        };
289
    }
285
    }
290
286
291
292
    /**
287
    /**
293
     * Implements FileObject.getData(boolean rec)
288
     * Implements FileObject.getData(boolean rec)
294
     */
289
     */
295
    public Enumeration getData(boolean rec) {
290
    public Enumeration getData(boolean rec) {
296
        return new FilterEnumeration(getChildren(rec)) {
291
        return org.openide.util.Enumerations.filter (
297
            protected boolean accept(final Object o) {
292
            getChildren (rec), new AcceptFolders (false)
298
                final FileObject fo = (FileObject) o;
293
        );
299
                return fo.isData();
300
            }
301
        };
302
    }
294
    }
303
295
296
    /** Selector from folders and data files.
297
     */
298
    private final class AcceptFolders implements org.openide.util.Enumerations.Processor {
299
        private boolean folders;
300
        
301
        public AcceptFolders (boolean folders) {
302
            this.folders = folders;
303
        }
304
        
305
        public Object process (Object o, Collection nothing) {
306
            final FileObject fo = (FileObject) o;
307
            if (folders) {
308
                return fo.isFolder() ? fo : null;
309
            } else {
310
                return fo.isData() ? fo : null;
311
            }
312
        }
313
    } // end of AcceptFolders
314
304
    /**
315
    /**
305
     * Implements abstract FileObject.getFileSystem()
316
     * Implements abstract FileObject.getFileSystem()
306
     */
317
     */
Lines 525-558 Link Here
525
    }
536
    }
526
537
527
538
528
    private QueueEnumeration getChildsEnum() {
539
    private org.openide.util.Enumerations.Processor getChildsEnum() {
529
        QueueEnumeration en = new QueueEnumeration() {
540
        return new org.openide.util.Enumerations.Processor  () {
530
            public void process(final Object o) {
541
            public Object process(final Object o, Collection toAdd) {
531
                final FileObject fo = (FileObject) o;
542
                final FileObject fo = (FileObject) o;
532
                if (fo != null)
543
                if (fo != null)
533
                    put(fo.getChildren());
544
                    toAdd.addAll (Arrays.asList (fo.getChildren()));
545
                return fo;
534
            }
546
            }
535
        };
547
        };
536
        return en;
537
    }
548
    }
538
549
539
550
540
    private Enumeration getEnumOfListeners() {
551
    private Enumeration getEnumOfListeners() {
541
        QueueEnumeration qE = new QueueEnumeration();
542
        Object[] fcls;
552
        Object[] fcls;
543
        synchronized (this) {
553
        synchronized (this) {
544
            if (listeners == null) return qE;
554
            if (listeners == null) {
555
                return org.openide.util.Enumerations.EMPTY;
556
            }
545
            fcls = listeners.getListenerList();
557
            fcls = listeners.getListenerList();
546
        }
558
        }
547
559
548
        if (fcls == null || fcls.length == 0) return qE;
560
        if (fcls == null || fcls.length == 0) {
549
        qE.put(fcls);
561
            return org.openide.util.Enumerations.EMPTY;
562
        }
550
563
551
        return new FilterEnumeration(qE) {
564
        class OnlyListeners implements org.openide.util.Enumerations.Processor {
552
            protected boolean accept(final Object o) {
565
            public Object process(final Object o, Collection toAdd) {
553
                return (o instanceof FileChangeListener) ? true : false;
566
                if (o instanceof FileChangeListener) {
567
                    return o;
568
                }
569
                return null;
554
            }
570
            }
555
        };
571
        }
572
        
573
        return org.openide.util.Enumerations.filter (
574
            org.openide.util.Enumerations.array (fcls), new OnlyListeners ()
575
        );
556
    }
576
    }
557
577
558
    FileSystem getDelegateFileSystem() {
578
    FileSystem getDelegateFileSystem() {
(-)openide/masterfs/src/org/netbeans/modules/masterfs/MountTable.java (-15 / +21 lines)
Lines 15-22 Link Here
15
15
16
import org.netbeans.modules.masterfs.providers.MountSupport;
16
import org.netbeans.modules.masterfs.providers.MountSupport;
17
import org.openide.filesystems.*;
17
import org.openide.filesystems.*;
18
import org.openide.util.enum.FilterEnumeration;
19
import org.openide.util.enum.QueueEnumeration;
20
18
21
import java.io.File;
19
import java.io.File;
22
import java.io.IOException;
20
import java.io.IOException;
Lines 136-142 Link Here
136
     * @return enumeration of mounted filesystems
134
     * @return enumeration of mounted filesystems
137
     */
135
     */
138
    Enumeration geAllFileSystems() {
136
    Enumeration geAllFileSystems() {
139
        final QueueEnumeration qE = new QueueEnumeration();
137
        final ArrayList qE = new ArrayList ();
140
        final Collection values = res2fsMap.values();
138
        final Collection values = res2fsMap.values();
141
        //SyncSection.getDefault().enterExclusiveSection();
139
        //SyncSection.getDefault().enterExclusiveSection();
142
        SyncSection.getDefault().enterSection();
140
        SyncSection.getDefault().enterSection();
Lines 145-158 Link Here
145
                for (Iterator it = values.iterator(); it.hasNext();) {
143
                for (Iterator it = values.iterator(); it.hasNext();) {
146
                    FileSystem fs = (FileSystem) it.next();
144
                    FileSystem fs = (FileSystem) it.next();
147
                    if (fs != null)
145
                    if (fs != null)
148
                        qE.put(fs);
146
                        qE.add (fs);
149
                }
147
                }
150
            }
148
            }
151
        } finally {
149
        } finally {
152
            //SyncSection.getDefault().finishExclusiveSection();
150
            //SyncSection.getDefault().finishExclusiveSection();
153
            SyncSection.getDefault().finishSection();
151
            SyncSection.getDefault().finishSection();
154
        }
152
        }
155
        return qE;
153
        return Collections.enumeration (qE);
156
    }
154
    }
157
155
158
    /**
156
    /**
Lines 248-280 Link Here
248
    }
246
    }
249
247
250
    private Enumeration getMountEnumeration(final String mountPointPath) {
248
    private Enumeration getMountEnumeration(final String mountPointPath) {
251
        return new FilterEnumeration(Cache.getDefault().getAll()) {
249
        class Mnt implements org.openide.util.Enumerations.Processor {
252
            protected boolean accept(final Object o) {
250
            public Object process (Object o, Collection ignore) {
253
                final MasterFileObject hfo = (MasterFileObject) o;
251
                final MasterFileObject hfo = (MasterFileObject) o;
254
                String normalizedMountPoint = ResourcePath.getNormalizedPath(mountPointPath);                
252
                String normalizedMountPoint = ResourcePath.getNormalizedPath(mountPointPath);                
255
                String normalizedResourcePath = hfo.getResource().getNormalizedPath();
253
                String normalizedResourcePath = hfo.getResource().getNormalizedPath();
256
                
254
                
257
                if (normalizedResourcePath.startsWith(normalizedMountPoint) && hfo.isValid()) {
255
                if (normalizedResourcePath.startsWith(normalizedMountPoint) && hfo.isValid()) {
258
                    return true;
256
                    return o;
259
                }
257
                }
260
                return false;
258
                return null;
261
            }
259
            }
262
        };
260
        }
261
        return org.openide.util.Enumerations.filter (
262
            Cache.getDefault().getAll(), 
263
            new Mnt ()
264
        );
263
    }
265
    }
264
266
265
    private static Enumeration getUnMountEnumeration(final FileSystem fs2Umount) {
267
    private static Enumeration getUnMountEnumeration(final FileSystem fs2Umount) {
266
        return new FilterEnumeration(Cache.getDefault().getAll()) {
268
        class UnMnt implements org.openide.util.Enumerations.Processor {
267
            protected boolean accept(final Object o) {
269
            public Object process (Object o, Collection ignore) {
268
                final MasterFileObject hfo = (MasterFileObject) o;
270
                final MasterFileObject hfo = (MasterFileObject) o;
269
                if (hfo != null && hfo.isValid()) {
271
                if (hfo != null && hfo.isValid()) {
270
                    FileSystem delgFs = hfo.getDelegateFileSystem();
272
                    FileSystem delgFs = hfo.getDelegateFileSystem();
271
                    if (delgFs == fs2Umount)
273
                    if (delgFs == fs2Umount)
272
                        return true;
274
                        return o;
273
275
274
                }
276
                }
275
                return false;
277
                return null;
276
            }
278
            }
277
        };
279
        }
280
        return org.openide.util.Enumerations.filter (
281
            Cache.getDefault().getAll(), 
282
            new UnMnt ()
283
        );
278
    }
284
    }
279
285
280
    FileSystem getMountedFileSystem(String resName) {
286
    FileSystem getMountedFileSystem(String resName) {
(-)openide/test/unit/src/org/openide/util/EnumerationsTest.java (+448 lines)
Added Link Here
1
/*
2
 *                 Sun Public License Notice
3
 * 
4
 * The contents of this file are subject to the Sun Public License
5
 * Version 1.0 (the "License"). You may not use this file except in
6
 * compliance with the License. A copy of the License is available at
7
 * http://www.sun.com/
8
 * 
9
 * The Original Code is NetBeans. The Initial Developer of the Original
10
 * Code is Sun Microsystems, Inc. Portions Copyright 1997-2003 Sun
11
 * Microsystems, Inc. All Rights Reserved.
12
 */
13
package org.openide.util;
14
15
import java.util.*;
16
import java.util.Enumeration;
17
import java.util.Map;
18
import java.util.Set;
19
20
/** This is the base test for new and old enumerations. It contains 
21
 * factory methods for various kinds of enumerations and set of tests
22
 * that use them. Factory methods are overriden in OldEnumerationsTest
23
 *
24
 * @author Jaroslav Tulach
25
 */
26
public class EnumerationsTest extends org.netbeans.junit.NbTestCase {
27
    
28
    /** Creates a new instance of EnumerationsTest */
29
    public EnumerationsTest (String testName) {
30
        super(testName);
31
    }
32
33
    public static void main(java.lang.String[] args) {
34
        junit.textui.TestRunner.run(new org.netbeans.junit.NbTestSuite(EnumerationsTest.class));
35
    }
36
37
    //
38
    // Factory methods
39
    //
40
    
41
    protected Enumeration singleton (Object obj) {
42
        return Enumerations.singleton (obj);
43
    }
44
    protected Enumeration concat (Enumeration en1, Enumeration en2) {
45
        return Enumerations.concat (en1, en2);
46
    }
47
    protected Enumeration concat (Enumeration enumOfEnums) {
48
        return Enumerations.concat (enumOfEnums);
49
    }
50
    protected Enumeration removeDuplicates (Enumeration en) {
51
        return Enumerations.removeDuplicates (en);
52
    }
53
    protected Enumeration empty () {
54
        return Enumerations.EMPTY;
55
    }
56
    protected Enumeration array (Object[] arr) {
57
        return Enumerations.array (arr);
58
    }
59
    protected Enumeration convert (Enumeration en, final Map map) {
60
        class P implements Enumerations.Processor {
61
            public Object process (Object obj, Collection nothing) {
62
                return map.get (obj);
63
            }
64
        }
65
        
66
        
67
        return Enumerations.convert (en, new P ());
68
    }
69
    protected Enumeration removeNulls (Enumeration en) {
70
        return Enumerations.removeNulls (en);
71
    }
72
    protected Enumeration filter (Enumeration en, final Set filter) {
73
        class P implements Enumerations.Processor {
74
            public Object process (Object obj, Collection nothing) {
75
                return filter.contains (obj) ? obj : null;
76
            }
77
        }
78
        
79
        return Enumerations.filter (en, new P ());
80
    }
81
    
82
    protected Enumeration filter (Enumeration en, final QueueProcess filter) {
83
        class P implements Enumerations.Processor {
84
            public Object process (Object obj, Collection nothing) {
85
                return filter.process (obj, nothing);
86
            }
87
        }
88
        
89
        return Enumerations.filter (en, new P ());
90
    }
91
    
92
    /**
93
     * @param filter the set.contains (...) is called before each object is produced
94
     * @return Enumeration
95
     */
96
    protected Enumeration queue (Collection initContent, final QueueProcess process) {
97
        class C implements Enumerations.Processor {
98
            public Object process (Object object, Collection toAdd) {
99
                return process.process (object, toAdd);
100
            }
101
        }
102
        return Enumerations.queue (
103
            Collections.enumeration (initContent), 
104
            new C ()
105
        );
106
    }
107
    
108
    /** Processor interface.
109
     */
110
    public static interface QueueProcess {
111
        public Object process (Object object, Collection toAdd);
112
    }
113
114
    //
115
    // The tests
116
    // 
117
    
118
    public void testEmptyIsEmpty () {
119
        Enumeration e = empty ();
120
        assertFalse (e.hasMoreElements ());
121
        try {
122
            e.nextElement ();
123
            fail ("No elements");
124
        } catch (java.util.NoSuchElementException ex) {
125
            // ok
126
        }
127
    }
128
    
129
    public void testSingleIsSingle () {
130
        Enumeration e = singleton (this);
131
        assertTrue (e.hasMoreElements ());
132
        assertEquals ("Returns me", this, e.nextElement ());
133
        assertFalse ("Now it is empty", e.hasMoreElements ());
134
        try {
135
            e.nextElement ();
136
            fail ("No elements");
137
        } catch (java.util.NoSuchElementException ex) {
138
            // ok
139
        }
140
    }
141
142
    public void testConcatTwoAndArray () {
143
        Object[] one = { new Integer (1), new Integer (2), new Integer (3) };
144
        Object[] two = { "1", "2", "3" };
145
        
146
        ArrayList list = new ArrayList (Arrays.asList (one));
147
        list.addAll (Arrays.asList (two));
148
        
149
        assertEnums (
150
            concat (array (one), array (two)),
151
            Collections.enumeration (list)
152
        );
153
    }
154
    
155
    public void testConcatTwoAndArrayAndTakeOnlyStrings () {
156
        Object[] one = { new Integer (1), new Integer (2), new Integer (3) };
157
        Object[] two = { "1", "2", "3" };
158
        Object[] three = { new Long (1) };
159
        Object[] four = { "Kuk" };
160
        
161
        ArrayList list = new ArrayList (Arrays.asList (two));
162
        list.addAll (Arrays.asList (four));
163
        
164
        Enumeration[] alls = {
165
            array (one), array (two), array (three), array (four)
166
        };
167
        
168
        assertEnums (
169
            filter (concat (array (alls)), new OnlyStrings()),
170
            Collections.enumeration (list)
171
        );
172
    }
173
    
174
    public void testRemoveDuplicates () {
175
        Object[] one = { new Integer (1), new Integer (2), new Integer (3) };
176
        Object[] two = { "1", "2", "3" };
177
        Object[] three = { new Integer (1) };
178
        Object[] four = { "2", "3", "4" };
179
        
180
        Enumeration[] alls = {
181
            array (one), array (two), array (three), array (four)
182
        };
183
        
184
        assertEnums (
185
            removeDuplicates (concat (array (alls))),
186
            array (new Object[] { new Integer (1), new Integer (2), new Integer (3), "1", "2", "3", "4" })
187
        );
188
        
189
    }
190
191
    public void testRemoveDuplicatesAndGCWorks () {
192
        
193
        /*** Return { i1, "", "", "", i2 } */
194
        class WeakEnum implements Enumeration {
195
            public Object i1 = new Integer (1);
196
            public Object i2 = new Integer (1);
197
            
198
            private int state;
199
            
200
            public boolean hasMoreElements () {
201
                return state < 5;
202
            }
203
            
204
            public Object nextElement () {
205
                switch (state++) {
206
                    case 0: return i1;    
207
                    case 1: case 2: case 3: return "";
208
                    default: return i2;
209
                }
210
            }
211
        }
212
        
213
        WeakEnum weak = new WeakEnum ();
214
        Enumeration en = removeDuplicates (weak);
215
        
216
        assertTrue ("Has some elements", en.hasMoreElements ());
217
        assertEquals ("And the first one is get", weak.i1, en.nextElement ());
218
        
219
        try {
220
            java.lang.ref.WeakReference ref = new java.lang.ref.WeakReference (weak.i1);
221
            weak.i1 = null;
222
            assertGC ("Try hard to GC the first integer", ref);
223
            // does not matter whether it GCs or not
224
        } catch (Throwable tw) {
225
            // not GCed, but does not matter
226
        }
227
        assertTrue ("Next object will be string", en.hasMoreElements ());
228
        assertEquals ("is empty string", "", en.nextElement ());
229
        
230
        assertFalse ("The second integer is however equal to the original i1 and thus" +
231
        " the enum should not be there", en.hasMoreElements ());
232
    }
233
    
234
    public void testQueueEnum () {
235
        class Pr implements QueueProcess {
236
            public Object process (Object o, Collection c) {
237
                Integer i = (Integer)o;
238
                int plus = i.intValue () + 1;
239
                if (plus < 10) {
240
                    c.add (new Integer (plus));
241
                }
242
                return i;
243
            }
244
        }
245
        Pr p = new Pr ();
246
        
247
        Enumeration en = queue (
248
            Collections.nCopies (1, new Integer (0)), p
249
        );
250
        
251
        for (int i = 0; i < 10; i++) {
252
            assertTrue ("has next", en.hasMoreElements ());
253
            en.nextElement ();
254
        }
255
        
256
        assertFalse ("No next element", en.hasMoreElements ());
257
    }
258
    
259
    public void testFilteringAlsoDoesConvertions () throws Exception {
260
        class Pr implements QueueProcess {
261
            public Object process (Object o, Collection ignore) {
262
                Integer i = (Integer)o;
263
                int plus = i.intValue () + 1;
264
                return new Integer (plus);
265
            }
266
        }
267
        Pr p = new Pr ();
268
        
269
        Enumeration onetwo = array (new Object[] { new Integer (1), new Integer (2) });
270
        Enumeration twothree = array (new Object[] { new Integer (2), new Integer (3) });
271
        
272
        assertEnums (
273
            filter (onetwo, p), twothree
274
        );
275
    }
276
    
277
    
278
    private static void assertEnums (Enumeration e1, Enumeration e2) {
279
        int indx = 0;
280
        while (e1.hasMoreElements () && e2.hasMoreElements ()) {
281
            Object i1 = e1.nextElement ();
282
            Object i2 = e2.nextElement ();
283
            assertEquals (indx++ + "th: ", i1, i2);
284
        }
285
        
286
        if (e1.hasMoreElements ()) {
287
            fail ("first one contains another element: " + e1.nextElement ());
288
        }
289
        if (e2.hasMoreElements ()) {
290
            fail ("second one contains another element: " + e2.nextElement ());
291
        }
292
        
293
        try {
294
            e1.nextElement ();
295
            fail ("First one should throw exception, but nothing happend");
296
        } catch (java.util.NoSuchElementException ex) {
297
            // ok
298
        }
299
        
300
        try {
301
            e2.nextElement ();
302
            fail ("Second one should throw exception, but nothing happend");
303
        } catch (java.util.NoSuchElementException ex) {
304
            // ok
305
        }
306
    }
307
    
308
    public void testConvertIntegersToStringRemoveNulls () {
309
        Object[] garbage = { new Integer (1), "kuk", "hle", new Integer (5) };
310
        
311
        assertEnums (
312
            removeNulls (convert (array (garbage), new MapIntegers ())), 
313
            array (new Object[] { "1", "5" })
314
        );
315
    }
316
    
317
    /** Filters only strings.
318
     */
319
    private static final class OnlyStrings implements java.util.Set {
320
        public boolean add (Object o) {
321
            fail ("Should not be every called");
322
            return false;
323
        }
324
        
325
        public boolean addAll (Collection c) {
326
            fail ("Should not be every called");
327
            return false;
328
        }
329
        
330
        public void clear () {
331
            fail ("Should not be every called");
332
        }
333
        
334
        public boolean contains (Object o) {
335
            return o instanceof String;
336
        }
337
        
338
        public boolean containsAll (Collection c) {
339
            fail ("Should not be every called");
340
            return false;
341
        }
342
        
343
        public boolean isEmpty () {
344
            fail ("Should not be every called");
345
            return false;
346
        }
347
        
348
        public Iterator iterator () {
349
            fail ("Should not be every called");
350
            return null;
351
        }
352
        
353
        public boolean remove (Object o) {
354
            fail ("Should not be every called");
355
            return false;
356
        }
357
        
358
        public boolean removeAll (Collection c) {
359
            fail ("Should not be every called");
360
            return false;
361
        }
362
        
363
        public boolean retainAll (Collection c) {
364
            fail ("Should not be every called");
365
            return false;
366
        }
367
        
368
        public int size () {
369
            fail ("Should not be every called");
370
            return 1;
371
        }
372
        
373
        public Object[] toArray () {
374
            fail ("Should not be every called");
375
            return null;
376
        }
377
        
378
        public Object[] toArray (Object[] a) {
379
            fail ("Should not be every called");
380
            return null;
381
        }
382
    }
383
    
384
    /** Filters only strings.
385
     */
386
    private static final class MapIntegers implements java.util.Map {
387
        public boolean containsKey (Object key) {
388
            fail ("Should not be every called");
389
            return false;
390
        }
391
        
392
        public boolean containsValue (Object value) {
393
            fail ("Should not be every called");
394
            return false;
395
        }
396
        
397
        public Set entrySet () {
398
            fail ("Should not be every called");
399
            return null;
400
        }
401
        
402
        public Object get (Object key) {
403
            if (key instanceof Integer) {
404
                return key.toString ();
405
            }
406
            return null;
407
        }
408
        
409
        public Set keySet () {
410
            fail ("Should not be every called");
411
            return null;
412
        }
413
        
414
        public Object put (Object key, Object value) {
415
            fail ("Should not be every called");
416
            return null;
417
        }
418
        
419
        public void putAll (Map t) {
420
            fail ("Should not be every called");
421
        }
422
        
423
        public Collection values () {
424
            fail ("Should not be every called");
425
            return null;
426
        }
427
        
428
        public void clear () {
429
            fail ("Should not be every called");
430
        }
431
        
432
        public boolean isEmpty () {
433
            fail ("Should not be every called");
434
            return false;
435
        }
436
        
437
        public Object remove (Object key) {
438
            fail ("Should not be every called");
439
            return null;
440
        }
441
        
442
        public int size () {
443
            fail ("Should not be every called");
444
            return 1;
445
        }
446
        
447
    }
448
}
(-)openide/test/unit/src/org/openide/util/OldEnumerationsTest.java (+153 lines)
Added Link Here
1
/*
2
 *                 Sun Public License Notice
3
 * 
4
 * The contents of this file are subject to the Sun Public License
5
 * Version 1.0 (the "License"). You may not use this file except in
6
 * compliance with the License. A copy of the License is available at
7
 * http://www.sun.com/
8
 * 
9
 * The Original Code is NetBeans. The Initial Developer of the Original
10
 * Code is Sun Microsystems, Inc. Portions Copyright 1997-2003 Sun
11
 * Microsystems, Inc. All Rights Reserved.
12
 */
13
package org.openide.util;
14
15
import java.util.Collection;
16
import org.openide.util.enum.*;
17
import org.openide.util.enum.QueueEnumeration;
18
19
/** Implement factory methods from EnumerationsTest, shares the same tests
20
 * with EnumerationsTest.
21
 *
22
 * @author Jaroslav Tulach
23
 */
24
public class OldEnumerationsTest extends EnumerationsTest {
25
    
26
    /** Creates a new instance of EnumerationsTest */
27
    public OldEnumerationsTest (String testName) {
28
        super(testName);
29
    }
30
31
    public static void main(java.lang.String[] args) {
32
        junit.textui.TestRunner.run(new org.netbeans.junit.NbTestSuite(OldEnumerationsTest.class));
33
    }
34
35
    protected java.util.Enumeration singleton (Object obj) {
36
        return new SingletonEnumeration (obj);
37
    }    
38
    
39
    protected java.util.Enumeration convert (java.util.Enumeration en, final java.util.Map map) {
40
        return new AlterEnumeration (en) {
41
            protected Object alter (Object o) {
42
                return map.get (o);
43
            }
44
        };
45
    }    
46
47
    protected java.util.Enumeration removeDuplicates (java.util.Enumeration en) {
48
        return new RemoveDuplicatesEnumeration (en);
49
    }
50
    
51
    protected java.util.Enumeration removeNulls (java.util.Enumeration en) {
52
        return new FilterEnumeration (en);
53
    }
54
    
55
    protected java.util.Enumeration concat (java.util.Enumeration en1, java.util.Enumeration en2) {
56
        return new SequenceEnumeration (en1, en2);
57
    }
58
    
59
    protected java.util.Enumeration array (Object[] arr) {
60
        return new ArrayEnumeration (arr);
61
    }
62
    
63
    protected java.util.Enumeration filter (java.util.Enumeration en, final java.util.Set filter) {
64
        return new FilterEnumeration (en) {
65
            protected boolean accept (Object obj) {
66
                return filter.contains (obj);
67
            }
68
        };
69
    }
70
    protected java.util.Enumeration filter (java.util.Enumeration en, final QueueProcess filter) {
71
        en = new AlterEnumeration (en) {
72
            public Object alter (Object alter) {
73
                return filter.process (alter, null);
74
            }
75
        };
76
        
77
        return new FilterEnumeration (en);
78
    }
79
    
80
    protected java.util.Enumeration concat (java.util.Enumeration enumOfEnums) {
81
        return new SequenceEnumeration (enumOfEnums);
82
    }
83
    
84
    protected java.util.Enumeration empty () {
85
        return new EmptyEnumeration ();
86
    }
87
    
88
    protected java.util.Enumeration queue (Collection init, final QueueProcess process) {
89
        class QEAdd extends QueueEnumeration implements Collection {
90
            protected void process (Object obj) {
91
                process.process (obj, this);
92
            }
93
            
94
            public boolean add (Object o) {
95
                put (o);
96
                return true;
97
            }
98
            
99
            public boolean addAll (Collection c) {
100
                put (c.toArray ());
101
                return true;
102
            }
103
            
104
            public void clear () {
105
                throw new IllegalStateException ("Unsupported");
106
            }
107
            
108
            public boolean contains (Object o) {
109
                throw new IllegalStateException ("Unsupported");
110
            }
111
            
112
            public boolean containsAll (Collection c) {
113
                throw new IllegalStateException ("Unsupported");
114
            }
115
            
116
            public boolean isEmpty () {
117
                throw new IllegalStateException ("Unsupported");
118
            }
119
            
120
            public java.util.Iterator iterator () {
121
                throw new IllegalStateException ("Unsupported");
122
            }
123
            
124
            public boolean remove (Object o) {
125
                throw new IllegalStateException ("Unsupported");
126
            }
127
            
128
            public boolean removeAll (Collection c) {
129
                throw new IllegalStateException ("Unsupported");
130
            }
131
            
132
            public boolean retainAll (Collection c) {
133
                throw new IllegalStateException ("Unsupported");
134
            }
135
            
136
            public int size () {
137
                throw new IllegalStateException ("Unsupported");
138
            }
139
            
140
            public Object[] toArray () {
141
                throw new IllegalStateException ("Unsupported");
142
            }
143
            
144
            public Object[] toArray (Object[] a) {
145
                throw new IllegalStateException ("Unsupported");
146
            }
147
        }
148
        QEAdd qe = new QEAdd ();
149
        qe.put (init.toArray ());
150
        return qe;
151
    }
152
    
153
}
(-)properties/src/org/netbeans/modules/properties/PresentableFileEntry.java (-1 lines)
Lines 47-53 Link Here
47
import org.openide.filesystems.FileObject;
47
import org.openide.filesystems.FileObject;
48
import org.openide.filesystems.FileSystem;
48
import org.openide.filesystems.FileSystem;
49
import org.openide.util.*;
49
import org.openide.util.*;
50
import org.openide.util.enum.*;
51
import org.openide.util.actions.SystemAction;
50
import org.openide.util.actions.SystemAction;
52
import org.openide.util.actions.Presenter;
51
import org.openide.util.actions.Presenter;
53
import org.openide.nodes.*;
52
import org.openide.nodes.*;
(-)vcscore/src/org/netbeans/modules/vcscore/actions/VSRevisionAction.java (-6 / +5 lines)
Lines 25-31 Link Here
25
import org.openide.filesystems.FileStateInvalidException;
25
import org.openide.filesystems.FileStateInvalidException;
26
import org.openide.nodes.*;
26
import org.openide.nodes.*;
27
import org.openide.util.actions.*;
27
import org.openide.util.actions.*;
28
import org.openide.util.enum.*;
29
import org.openide.util.HelpCtx;
28
import org.openide.util.HelpCtx;
30
import org.openide.util.NbBundle;
29
import org.openide.util.NbBundle;
31
import org.openide.windows.TopComponent.Registry;
30
import org.openide.windows.TopComponent.Registry;
Lines 112-121 Link Here
112
                /* At present not allowed to construct actions for selected nodes on more filesystems - its safe behaviour
111
                /* At present not allowed to construct actions for selected nodes on more filesystems - its safe behaviour
113
                 * If this restriction will be considered as right solution, then code of this method can be simplified
112
                 * If this restriction will be considered as right solution, then code of this method can be simplified
114
                 */
113
                 */
115
            if (rListMap.size() == 0 || rListMap.size() > 1) return createMenu(EmptyEnumeration.EMPTY, popUp);
114
            if (rListMap.size() == 0 || rListMap.size() > 1) return createMenu(org.openide.util.Enumerations.EMPTY, popUp);
116
            
115
            
117
            Iterator entrySetIt = rListMap.entrySet().iterator();
116
            Iterator entrySetIt = rListMap.entrySet().iterator();
118
            QueueEnumeration result = new QueueEnumeration();
117
            LinkedList result = new LinkedList ();
119
            
118
            
120
            while (entrySetIt.hasNext()) {
119
            while (entrySetIt.hasNext()) {
121
                Map.Entry entry = (Map.Entry)entrySetIt.next();
120
                Map.Entry entry = (Map.Entry)entrySetIt.next();
Lines 123-134 Link Here
123
                Set itemSet = (Set) entry.getValue();
122
                Set itemSet = (Set) entry.getValue();
124
                try {
123
                try {
125
                    VersioningFileSystem vs = (VersioningFileSystem) list.getFileObject().getFileSystem();
124
                    VersioningFileSystem vs = (VersioningFileSystem) list.getFileObject().getFileSystem();
126
                    result.put(vs.getRevisionActions(list.getFileObject(), itemSet));
125
                    result.addAll (Arrays.asList (vs.getRevisionActions(list.getFileObject(), itemSet)));
127
                } catch (FileStateInvalidException exc) {
126
                } catch (FileStateInvalidException exc) {
128
                    continue;
127
                    continue;
129
                }
128
                }
130
            }
129
            }
131
            return createMenu(result, popUp);
130
            return createMenu(Collections.enumeration (result), popUp);
132
        }
131
        }
133
        return NONE;
132
        return NONE;
134
    }
133
    }
Lines 139-145 Link Here
139
     *   into the menu if enabled and if not duplicated
138
     *   into the menu if enabled and if not duplicated
140
     */
139
     */
141
    private static JMenuItem[] createMenu (Enumeration en, boolean popUp) {
140
    private static JMenuItem[] createMenu (Enumeration en, boolean popUp) {
142
        en = new RemoveDuplicatesEnumeration (en);
141
        en = org.openide.util.Enumerations.removeDuplicates (en);
143
142
144
        ArrayList items = new ArrayList ();
143
        ArrayList items = new ArrayList ();
145
        while (en.hasMoreElements ()) {
144
        while (en.hasMoreElements ()) {
(-)vcscore/src/org/netbeans/modules/vcscore/actions/VcsAllCommandsAction.java (-1 lines)
Lines 53-59 Link Here
53
import org.openide.util.actions.SystemAction;
53
import org.openide.util.actions.SystemAction;
54
import org.openide.util.actions.CallableSystemAction;
54
import org.openide.util.actions.CallableSystemAction;
55
import org.openide.util.actions.Presenter;
55
import org.openide.util.actions.Presenter;
56
import org.openide.util.enum.*;
57
import org.openide.windows.TopComponent.Registry;
56
import org.openide.windows.TopComponent.Registry;
58
import org.openide.windows.WindowManager;
57
import org.openide.windows.WindowManager;
59
58
(-)vcscore/src/org/netbeans/modules/vcscore/actions/VcsCommandsAction.java (-6 / +11 lines)
Lines 36-42 Link Here
36
import org.openide.util.actions.SystemAction;
36
import org.openide.util.actions.SystemAction;
37
import org.openide.util.actions.CallableSystemAction;
37
import org.openide.util.actions.CallableSystemAction;
38
import org.openide.util.actions.Presenter;
38
import org.openide.util.actions.Presenter;
39
import org.openide.util.enum.*;
40
import org.openide.windows.TopComponent.Registry;
39
import org.openide.windows.TopComponent.Registry;
41
import org.openide.windows.WindowManager;
40
import org.openide.windows.WindowManager;
42
41
Lines 89-95 Link Here
89
             * If this restriction will be considered as right solution, then code of this method can be simplified
88
             * If this restriction will be considered as right solution, then code of this method can be simplified
90
             */
89
             */
91
            if (fsSet.size () == 0 || fsSet.size() > 1) {
90
            if (fsSet.size () == 0 || fsSet.size() > 1) {
92
                List cmdMenu = createMenu (EmptyEnumeration.EMPTY, popUp);
91
                List cmdMenu = createMenu (org.openide.util.Enumerations.EMPTY, popUp);
93
                JMenuItem[] menuArray = new JMenuItem [cmdMenu.size ()];
92
                JMenuItem[] menuArray = new JMenuItem [cmdMenu.size ()];
94
                cmdMenu.toArray (menuArray);
93
                cmdMenu.toArray (menuArray);
95
                return menuArray;
94
                return menuArray;
Lines 104-115 Link Here
104
                HashSet    foSet = (HashSet)entry.getValue();
103
                HashSet    foSet = (HashSet)entry.getValue();
105
104
106
                if (foSet != null) {
105
                if (foSet != null) {
107
                    if (result == null) result = new SequenceEnumeration (new ArrayEnumeration (fs.getActions (foSet)),EmptyEnumeration.EMPTY);
106
                    if (result == null) {
108
                    else result = new SequenceEnumeration (result,new ArrayEnumeration (fs.getActions (foSet))); 
107
                        result = org.openide.util.Enumerations.array (fs.getActions (foSet));
108
                    } else {
109
                        result = org.openide.util.Enumerations.concat (
110
                            result,
111
                            org.openide.util.Enumerations.array (fs.getActions (foSet))
112
                        ); 
113
                    }
109
                }
114
                }
110
            }
115
            }
111
            
116
            
112
            List cmdMenu = createMenu ((result != null) ? result : EmptyEnumeration.EMPTY, popUp);
117
            List cmdMenu = createMenu ((result != null) ? result : org.openide.util.Enumerations.EMPTY, popUp);
113
            JMenuItem customize = new JMenuItem();
118
            JMenuItem customize = new JMenuItem();
114
            org.openide.awt.Actions.setMenuText (customize, org.openide.util.NbBundle.getBundle(VcsCommandsAction.class).getString("CTL_VcsFSCustomizer"), true);
119
            org.openide.awt.Actions.setMenuText (customize, org.openide.util.NbBundle.getBundle(VcsCommandsAction.class).getString("CTL_VcsFSCustomizer"), true);
115
            customize.setIcon(CallableSystemAction.get(VcsCommandsAction.class).getIcon());
120
            customize.setIcon(CallableSystemAction.get(VcsCommandsAction.class).getIcon());
Lines 187-193 Link Here
187
    *   into the menu if enabled and if not duplicated
192
    *   into the menu if enabled and if not duplicated
188
    */
193
    */
189
    private static List createMenu (Enumeration en, boolean popUp) {
194
    private static List createMenu (Enumeration en, boolean popUp) {
190
        en = new RemoveDuplicatesEnumeration (en);
195
        en = org.openide.util.Enumerations.removeDuplicates (en);
191
196
192
        ArrayList items = new ArrayList ();
197
        ArrayList items = new ArrayList ();
193
        while (en.hasMoreElements ()) {
198
        while (en.hasMoreElements ()) {
(-)vcscore/src/org/netbeans/modules/vcscore/util/OrderedSet.java (-13 / +12 lines)
Lines 20-30 Link Here
20
import java.util.Enumeration;
20
import java.util.Enumeration;
21
import java.util.Iterator;
21
import java.util.Iterator;
22
22
23
import org.openide.util.enum.AlterEnumeration;
24
import org.openide.util.enum.QueueEnumeration;
25
import org.openide.util.enum.RemoveDuplicatesEnumeration;
26
import org.openide.util.enum.SequenceEnumeration;
27
28
/**
23
/**
29
 *
24
 *
30
 * @author  Martin Entlicher
25
 * @author  Martin Entlicher
Lines 35-41 Link Here
35
public final class OrderedSet extends AbstractSet {
30
public final class OrderedSet extends AbstractSet {
36
31
37
    /** Queue of collections of elements. */
32
    /** Queue of collections of elements. */
38
    private QueueEnumeration queue = new QueueEnumeration();
33
    private java.util.LinkedList queue = new java.util.LinkedList ();
39
    /** Objects stored in this set. */
34
    /** Objects stored in this set. */
40
    Object[] objects = null;
35
    Object[] objects = null;
41
36
Lines 44-50 Link Here
44
    }
39
    }
45
    
40
    
46
    public boolean add(Object obj) {
41
    public boolean add(Object obj) {
47
        queue.put(Collections.singleton(obj));
42
        queue.add (Collections.singleton(obj));
48
        return true;
43
        return true;
49
    }
44
    }
50
45
Lines 52-71 Link Here
52
     * Adds all of the elements in the specified collection to this collection.
47
     * Adds all of the elements in the specified collection to this collection.
53
     */
48
     */
54
    public boolean addAll(Collection coll) {
49
    public boolean addAll(Collection coll) {
55
        queue.put(coll);
50
        queue.add (coll);
56
        return true;
51
        return true;
57
    }
52
    }
58
    
53
    
59
    
54
    
60
    private Object[] getObjects() {
55
    private Object[] getObjects() {
61
        if (objects == null) {
56
        if (objects == null) {
62
            AlterEnumeration altered = new AlterEnumeration(queue) {
57
            class Col2Enum implements org.openide.util.Enumerations.Processor {
63
                public Object alter(Object obj) {
58
                public Object process (Object obj, Collection toAdd) {
64
                    return Collections.enumeration((Collection) obj);
59
                    return Collections.enumeration((Collection) obj);
65
                }
60
                }
66
            };
61
            }
67
            SequenceEnumeration sequenced = new SequenceEnumeration(altered);
62
            
68
            Enumeration result = new RemoveDuplicatesEnumeration(sequenced);
63
            Enumeration altered = org.openide.util.Enumerations.convert (
64
                Collections.enumeration (queue), new Col2Enum ()
65
            );
66
            Enumeration sequenced = org.openide.util.Enumerations.concat (altered);
67
            Enumeration result = org.openide.util.Enumerations.removeDuplicates (sequenced);
69
            ArrayList objectList = new ArrayList();
68
            ArrayList objectList = new ArrayList();
70
            for (int i = 0; result.hasMoreElements(); i++) {
69
            for (int i = 0; result.hasMoreElements(); i++) {
71
                objectList.add(result.nextElement());
70
                objectList.add(result.nextElement());
(-)vcscore/src/org/netbeans/modules/vcscore/util/virtuals/VcsRefreshRequest.java (-3 lines)
Lines 23-31 Link Here
23
import org.openide.ErrorManager;
23
import org.openide.ErrorManager;
24
24
25
import org.openide.util.RequestProcessor;
25
import org.openide.util.RequestProcessor;
26
import org.openide.util.enum.SequenceEnumeration;
27
import org.openide.util.enum.SingletonEnumeration;
28
import org.openide.util.enum.QueueEnumeration;
29
26
30
/** Request for parsing of an filesystem. Can be stoped.
27
/** Request for parsing of an filesystem. Can be stoped.
31
* Copied from openide by Milos Kleint.. :) because the class is final and I need to rewrite it..
28
* Copied from openide by Milos Kleint.. :) because the class is final and I need to rewrite it..
(-)vcscore/src/org/netbeans/modules/vcscore/versioning/VersioningFileSystem.java (-1 / +1 lines)
Lines 453-459 Link Here
453
        public java.util.Enumeration attributes(String name) {
453
        public java.util.Enumeration attributes(String name) {
454
            HashMap attrs = (HashMap) files.get(name);
454
            HashMap attrs = (HashMap) files.get(name);
455
            if (attrs == null) {
455
            if (attrs == null) {
456
                return new org.openide.util.enum.EmptyEnumeration();
456
                return org.openide.util.Enumerations.EMPTY;
457
            } else {
457
            } else {
458
                return Collections.enumeration(attrs.keySet());
458
                return Collections.enumeration(attrs.keySet());
459
            }
459
            }
(-)vcsgeneric/src/org/netbeans/modules/vcs/profiles/commands/RecursiveFolderCommand.java (-1 lines)
Lines 17-23 Link Here
17
import java.util.*;
17
import java.util.*;
18
18
19
import org.openide.filesystems.FileObject;
19
import org.openide.filesystems.FileObject;
20
//import org.openide.util.enum.AlterEnumeration;
21
20
22
import org.netbeans.modules.vcscore.Variables;
21
import org.netbeans.modules.vcscore.Variables;
23
import org.netbeans.modules.vcscore.VcsFileSystem;
22
import org.netbeans.modules.vcscore.VcsFileSystem;
(-)web/core/src/org/netbeans/modules/web/core/jsploader/JspDataObject.java (-2 lines)
Lines 16-22 Link Here
16
import java.util.Iterator;
16
import java.util.Iterator;
17
import java.util.Collection;
17
import java.util.Collection;
18
import java.util.Vector;
18
import java.util.Vector;
19
import java.util.Enumeration;
20
import java.util.HashMap;
19
import java.util.HashMap;
21
import java.util.Date;
20
import java.util.Date;
22
import java.util.Locale;
21
import java.util.Locale;
Lines 38-44 Link Here
38
import org.openide.windows.*;
37
import org.openide.windows.*;
39
import org.openide.text.*;
38
import org.openide.text.*;
40
import org.openide.util.*;
39
import org.openide.util.*;
41
import org.openide.util.enum.*;
42
import org.openide.util.actions.*;
40
import org.openide.util.actions.*;
43
import org.openide.nodes.Node;
41
import org.openide.nodes.Node;
44
import org.openide.nodes.CookieSet;
42
import org.openide.nodes.CookieSet;
(-)web/core/src/org/netbeans/modules/web/dd/DDGrammarQueryManager.java (-2 / +1 lines)
Lines 13-19 Link Here
13
13
14
package org.netbeans.modules.web.dd;
14
package org.netbeans.modules.web.dd;
15
import java.util.Enumeration;
15
import java.util.Enumeration;
16
import org.openide.util.enum.SingletonEnumeration;
17
import org.w3c.dom.Element;
16
import org.w3c.dom.Element;
18
import org.w3c.dom.Node;
17
import org.w3c.dom.Node;
19
import org.xml.sax.*;
18
import org.xml.sax.*;
Lines 42-48 Link Here
42
                if (WEB_APP_TAG.equals(tag)) {  // NOI18N
41
                if (WEB_APP_TAG.equals(tag)) {  // NOI18N
43
                    String xmlns = element.getAttribute(XMLNS_ATTR);
42
                    String xmlns = element.getAttribute(XMLNS_ATTR);
44
                    if (xmlns!=null && DDCatalog.J2EE_NS.equals(xmlns)) //NOI18N
43
                    if (xmlns!=null && DDCatalog.J2EE_NS.equals(xmlns)) //NOI18N
45
                            return new SingletonEnumeration(next);
44
                            return org.openide.util.Enumerations.singleton (next);
46
                    }
45
                    }
47
                }
46
                }
48
        }
47
        }
(-)web/core/src/org/netbeans/modules/web/taglib/TaglibGrammarQueryManager.java (-2 / +1 lines)
Lines 13-19 Link Here
13
13
14
package org.netbeans.modules.web.taglib;
14
package org.netbeans.modules.web.taglib;
15
import java.util.Enumeration;
15
import java.util.Enumeration;
16
import org.openide.util.enum.SingletonEnumeration;
17
import org.w3c.dom.Element;
16
import org.w3c.dom.Element;
18
import org.w3c.dom.Node;
17
import org.w3c.dom.Node;
19
import org.xml.sax.*;
18
import org.xml.sax.*;
Lines 42-48 Link Here
42
                if (TAGLIB_TAG.equals(tag)) {  // NOI18N
41
                if (TAGLIB_TAG.equals(tag)) {  // NOI18N
43
                    String xmlns = element.getAttribute(XMLNS_ATTR);
42
                    String xmlns = element.getAttribute(XMLNS_ATTR);
44
                    if (xmlns!=null && TaglibCatalog.J2EE_NS.equals(xmlns)) //NOI18N
43
                    if (xmlns!=null && TaglibCatalog.J2EE_NS.equals(xmlns)) //NOI18N
45
                            return new SingletonEnumeration(next);
44
                            return org.openide.util.Enumerations.singleton (next);
46
                    }
45
                    }
47
                }
46
                }
48
        }
47
        }
(-)web/taglibed/src/org/netbeans/modules/web/taglibed/control/DataFolderSelectionPanel.java (-4 / +3 lines)
Lines 41-47 Link Here
41
import org.openide.filesystems.*;
41
import org.openide.filesystems.*;
42
import org.openide.util.HelpCtx;
42
import org.openide.util.HelpCtx;
43
import org.openide.util.Utilities;
43
import org.openide.util.Utilities;
44
import org.openide.util.enum.*;
45
import org.openide.util.NbBundle;
44
import org.openide.util.NbBundle;
46
45
47
import org.netbeans.api.java.classpath.ClassPath;
46
import org.netbeans.api.java.classpath.ClassPath;
Lines 482-490 Link Here
482
        
481
        
483
        system = new WeakReference (fs);
482
        system = new WeakReference (fs);
484
        
483
        
485
        Enumeration en = new SequenceEnumeration (
484
        Enumeration en = org.openide.util.Enumerations.concat (
486
          new SingletonEnumeration (fs.getSystemName()),
485
            org.openide.util.Enumerations.singleton (fs.getSystemName()),
487
          st
486
            st
488
        );
487
        );
489
        
488
        
490
        n = NodeOp.findPath (rootNode, en);
489
        n = NodeOp.findPath (rootNode, en);
(-)xml/core/src/org/netbeans/modules/xml/api/model/GrammarQueryManager.java (-5 / +6 lines)
Lines 30-36 Link Here
30
import org.openide.loaders.DataObjectNotFoundException;
30
import org.openide.loaders.DataObjectNotFoundException;
31
import org.openide.loaders.FolderLookup;
31
import org.openide.loaders.FolderLookup;
32
import org.openide.util.Lookup;
32
import org.openide.util.Lookup;
33
import org.openide.util.enum.ArrayEnumeration;
34
import org.xml.sax.InputSource;
33
import org.xml.sax.InputSource;
35
34
36
/**
35
/**
Lines 150-164 Link Here
150
            Iterator it = getRegistrations();
149
            Iterator it = getRegistrations();
151
            transaction.set(null);
150
            transaction.set(null);
152
            ArrayList list = new ArrayList(5);
151
            ArrayList list = new ArrayList(5);
153
            Enumeration enum = ctx.getDocumentChildren();
152
            {
154
            while (enum.hasMoreElements()) {
153
                Enumeration en = ctx.getDocumentChildren();
155
                list.add(enum.nextElement());
154
                while (en.hasMoreElements()) {
155
                    list.add(en.nextElement());
156
                }
156
            }
157
            }
157
            Object[] array = list.toArray();
158
            Object[] array = list.toArray();
158
            while (it.hasNext()) {
159
            while (it.hasNext()) {
159
                GrammarQueryManager next = (GrammarQueryManager) it.next();
160
                GrammarQueryManager next = (GrammarQueryManager) it.next();
160
                GrammarEnvironment env = new GrammarEnvironment(
161
                GrammarEnvironment env = new GrammarEnvironment(
161
                    new ArrayEnumeration(array), 
162
                    org.openide.util.Enumerations.array (array), 
162
                    ctx.getInputSource(),
163
                    ctx.getInputSource(),
163
                    ctx.getFileObject()
164
                    ctx.getFileObject()
164
                );
165
                );
(-)xml/core/src/org/netbeans/modules/xml/core/lib/StreamFileObject.java (-2 / +1 lines)
Lines 17-23 Link Here
17
17
18
import org.openide.filesystems.*;
18
import org.openide.filesystems.*;
19
import org.openide.filesystems.FileSystem;
19
import org.openide.filesystems.FileSystem;
20
import org.openide.util.enum.*;
21
20
22
/**
21
/**
23
 * This file object represents an InputStream.
22
 * This file object represents an InputStream.
Lines 118-124 Link Here
118
    }
117
    }
119
    
118
    
120
    public java.util.Enumeration getAttributes() {
119
    public java.util.Enumeration getAttributes() {
121
        return new EmptyEnumeration();
120
        return org.openide.util.Enumerations.EMPTY;
122
    }
121
    }
123
    
122
    
124
    public java.lang.String getName() {
123
    public java.lang.String getName() {
(-)xml/core/src/org/netbeans/modules/xml/dtd/grammar/ContentModel.java (-10 / +9 lines)
Lines 14-20 Link Here
14
package org.netbeans.modules.xml.dtd.grammar;
14
package org.netbeans.modules.xml.dtd.grammar;
15
15
16
import java.util.*;
16
import java.util.*;
17
import org.openide.util.enum.*;
18
17
19
/**
18
/**
20
 * Implementation of queriable DTD content models. It is a hungry
19
 * Implementation of queriable DTD content models. It is a hungry
Lines 209-217 Link Here
209
208
210
        protected Enumeration possibilities() {
209
        protected Enumeration possibilities() {
211
            if (terminated() == false) {
210
            if (terminated() == false) {
212
                return new SingletonEnumeration(name);
211
                return org.openide.util.Enumerations.singleton (name);
213
            } else {
212
            } else {
214
                return EmptyEnumeration.EMPTY;
213
                return org.openide.util.Enumerations.EMPTY;
215
            }
214
            }
216
        }
215
        }
217
216
Lines 311-325 Link Here
311
        
310
        
312
        protected Enumeration possibilities() {
311
        protected Enumeration possibilities() {
313
            if (terminated() == false) {
312
            if (terminated() == false) {
314
                Enumeration en = EmptyEnumeration.EMPTY;
313
                Enumeration en = org.openide.util.Enumerations.EMPTY;
315
                for ( int i = current; i<models.length; i++) {
314
                for ( int i = current; i<models.length; i++) {
316
                    ContentModel next = models[i];                    
315
                    ContentModel next = models[i];                    
317
                    en = new SequenceEnumeration(en, next.possibilities());
316
                    en = org.openide.util.Enumerations.concat (en, next.possibilities());
318
                    if (next.isOptional() == false) break;
317
                    if (next.isOptional() == false) break;
319
                }
318
                }
320
                return en;
319
                return en;
321
            } else {
320
            } else {
322
                return EmptyEnumeration.EMPTY;
321
                return org.openide.util.Enumerations.EMPTY;
323
            }
322
            }
324
        }
323
        }
325
324
Lines 390-396 Link Here
390
                if (peer.terminated()) peer.reset();
389
                if (peer.terminated()) peer.reset();
391
                return peer.possibilities();
390
                return peer.possibilities();
392
            } else {
391
            } else {
393
                return EmptyEnumeration.EMPTY;
392
                return org.openide.util.Enumerations.EMPTY;
394
            }
393
            }
395
        }
394
        }
396
395
Lines 496-510 Link Here
496
        
495
        
497
        protected Enumeration possibilities() {
496
        protected Enumeration possibilities() {
498
            if (terminated() == false) {
497
            if (terminated() == false) {
499
                Enumeration en = EmptyEnumeration.EMPTY;
498
                Enumeration en = org.openide.util.Enumerations.EMPTY;
500
                for ( int i = 0; i<models.length; i++) {
499
                for ( int i = 0; i<models.length; i++) {
501
                    if (modelsThatNotAcceptedAtLeastOne[i]) continue;
500
                    if (modelsThatNotAcceptedAtLeastOne[i]) continue;
502
                    ContentModel next = models[i];                    
501
                    ContentModel next = models[i];                    
503
                    en = new SequenceEnumeration(en, next.possibilities());
502
                    en = org.openide.util.Enumerations.concat (en, next.possibilities());
504
                }
503
                }
505
                return en;
504
                return en;
506
            } else {
505
            } else {
507
                return EmptyEnumeration.EMPTY;
506
                return org.openide.util.Enumerations.EMPTY;
508
            }
507
            }
509
        }
508
        }
510
509
(-)xml/core/src/org/netbeans/modules/xml/dtd/grammar/DTDGrammar.java (-35 / +34 lines)
Lines 18-24 Link Here
18
18
19
import org.w3c.dom.*;
19
import org.w3c.dom.*;
20
20
21
import org.openide.util.enum.*;
22
import org.openide.ErrorManager;
21
import org.openide.ErrorManager;
23
22
24
import org.netbeans.modules.xml.api.model.*;
23
import org.netbeans.modules.xml.api.model.*;
Lines 64-89 Link Here
64
     * @return list of <code>CompletionResult</code>s (ENTITY_REFERENCE_NODEs)
63
     * @return list of <code>CompletionResult</code>s (ENTITY_REFERENCE_NODEs)
65
     */
64
     */
66
    public Enumeration queryEntities(String prefix) {
65
    public Enumeration queryEntities(String prefix) {
67
        if (entities == null) return EmptyEnumeration.EMPTY;
66
        if (entities == null) return org.openide.util.Enumerations.EMPTY;
68
        
67
        
69
        QueueEnumeration list = new QueueEnumeration();
68
        LinkedList list = new LinkedList();
70
        Iterator it = entities.iterator();
69
        Iterator it = entities.iterator();
71
        while ( it.hasNext()) {
70
        while ( it.hasNext()) {
72
            String next = (String) it.next();
71
            String next = (String) it.next();
73
            if (next.startsWith(prefix)) {
72
            if (next.startsWith(prefix)) {
74
                list.put(new MyEntityReference(next));
73
                list.add (new MyEntityReference(next));
75
            }
74
            }
76
        }
75
        }
77
76
78
        // add well-know build-in entity names
77
        // add well-know build-in entity names
79
        
78
        
80
        if ("lt".startsWith(prefix)) list.put(new MyEntityReference("lt"));
79
        if ("lt".startsWith(prefix)) list.add(new MyEntityReference("lt"));
81
        if ("gt".startsWith(prefix)) list.put(new MyEntityReference("gt"));
80
        if ("gt".startsWith(prefix)) list.add(new MyEntityReference("gt"));
82
        if ("apos".startsWith(prefix)) list.put(new MyEntityReference("apos"));
81
        if ("apos".startsWith(prefix)) list.add(new MyEntityReference("apos"));
83
        if ("quot".startsWith(prefix)) list.put(new MyEntityReference("quot"));
82
        if ("quot".startsWith(prefix)) list.add(new MyEntityReference("quot"));
84
        if ("amp".startsWith(prefix)) list.put(new MyEntityReference("amp"));
83
        if ("amp".startsWith(prefix)) list.add(new MyEntityReference("amp"));
85
        
84
        
86
        return list;
85
        return java.util.Collections.enumeration (list);
87
    }
86
    }
88
    
87
    
89
    /**
88
    /**
Lines 95-101 Link Here
95
     *        Every list member represents one possibility.
94
     *        Every list member represents one possibility.
96
     */
95
     */
97
    public Enumeration queryAttributes(HintContext ctx) {
96
    public Enumeration queryAttributes(HintContext ctx) {
98
        if (attrDecls == null) return EmptyEnumeration.EMPTY;
97
        if (attrDecls == null) return org.openide.util.Enumerations.EMPTY;
99
        
98
        
100
        Element el = null;
99
        Element el = null;
101
        // Support two versions of GrammarQuery contract
100
        // Support two versions of GrammarQuery contract
Lines 104-130 Link Here
104
        } else if (ctx.getNodeType() == Node.ELEMENT_NODE) {
103
        } else if (ctx.getNodeType() == Node.ELEMENT_NODE) {
105
            el = (Element) ctx;
104
            el = (Element) ctx;
106
        }
105
        }
107
        if (el == null) return EmptyEnumeration.EMPTY;
106
        if (el == null) return org.openide.util.Enumerations.EMPTY;
108
        
107
        
109
        NamedNodeMap existingAttributes = el.getAttributes();        
108
        NamedNodeMap existingAttributes = el.getAttributes();        
110
        
109
        
111
        Set possibleAttributes = (Set) attrDecls.get(el.getTagName());
110
        Set possibleAttributes = (Set) attrDecls.get(el.getTagName());
112
        if (possibleAttributes == null) return EmptyEnumeration.EMPTY;
111
        if (possibleAttributes == null) return org.openide.util.Enumerations.EMPTY;
113
        
112
        
114
        String prefix = ctx.getCurrentPrefix();
113
        String prefix = ctx.getCurrentPrefix();
115
        
114
        
116
        QueueEnumeration list = new QueueEnumeration();
115
        LinkedList list = new LinkedList ();
117
        Iterator it = possibleAttributes.iterator();
116
        Iterator it = possibleAttributes.iterator();
118
        while ( it.hasNext()) {
117
        while ( it.hasNext()) {
119
            String next = (String) it.next();
118
            String next = (String) it.next();
120
            if (next.startsWith(prefix)) {
119
            if (next.startsWith(prefix)) {
121
                if (existingAttributes.getNamedItem(next) == null) {
120
                if (existingAttributes.getNamedItem(next) == null) {
122
                    list.put(new MyAttr(next));
121
                    list.add (new MyAttr(next));
123
                }
122
                }
124
            }
123
            }
125
        }
124
        }
126
        
125
        
127
        return list;
126
        return Collections.enumeration (list);
128
    }
127
    }
129
    
128
    
130
    /**
129
    /**
Lines 137-150 Link Here
137
     *        Every list member represents one possibility.
136
     *        Every list member represents one possibility.
138
     */
137
     */
139
    public Enumeration queryElements(HintContext ctx) {
138
    public Enumeration queryElements(HintContext ctx) {
140
        if (elementDecls == null) return EmptyEnumeration.EMPTY;;
139
        if (elementDecls == null) return org.openide.util.Enumerations.EMPTY;;
141
        
140
        
142
        Node node = ((Node)ctx).getParentNode();        
141
        Node node = ((Node)ctx).getParentNode();        
143
        Set elements = null;
142
        Set elements = null;
144
        
143
        
145
        if (node instanceof Element) {
144
        if (node instanceof Element) {
146
            Element el = (Element) node;
145
            Element el = (Element) node;
147
            if (el == null) return EmptyEnumeration.EMPTY;;
146
            if (el == null) return org.openide.util.Enumerations.EMPTY;;
148
147
149
            // lazilly parse content model
148
            // lazilly parse content model
150
            Object model = null;
149
            Object model = null;
Lines 162-168 Link Here
162
            }
161
            }
163
            if (model instanceof ContentModel) {
162
            if (model instanceof ContentModel) {
164
                Enumeration en = ((ContentModel)model).whatCanFollow(new PreviousEnumeration(el, ctx));
163
                Enumeration en = ((ContentModel)model).whatCanFollow(new PreviousEnumeration(el, ctx));
165
                if (en == null) return EmptyEnumeration.EMPTY;
164
                if (en == null) return org.openide.util.Enumerations.EMPTY;
166
                String prefix = ctx.getCurrentPrefix();
165
                String prefix = ctx.getCurrentPrefix();
167
                elements = new TreeSet();
166
                elements = new TreeSet();
168
                while (en.hasMoreElements()) {
167
                while (en.hasMoreElements()) {
Lines 179-200 Link Here
179
        } else if (node instanceof Document) {
178
        } else if (node instanceof Document) {
180
            elements = elementDecls.keySet();  //??? should be one from DOCTYPE if exist
179
            elements = elementDecls.keySet();  //??? should be one from DOCTYPE if exist
181
        } else {
180
        } else {
182
            return EmptyEnumeration.EMPTY;
181
            return org.openide.util.Enumerations.EMPTY;
183
        }
182
        }
184
                
183
                
185
        if (elements == null) return EmptyEnumeration.EMPTY;;
184
        if (elements == null) return org.openide.util.Enumerations.EMPTY;;
186
        String prefix = ctx.getCurrentPrefix();
185
        String prefix = ctx.getCurrentPrefix();
187
        
186
        
188
        QueueEnumeration list = new QueueEnumeration();
187
        LinkedList list = new LinkedList ();
189
        Iterator it = elements.iterator();
188
        Iterator it = elements.iterator();
190
        while ( it.hasNext()) {
189
        while ( it.hasNext()) {
191
            String next = (String) it.next();
190
            String next = (String) it.next();
192
            if (next.startsWith(prefix)) {
191
            if (next.startsWith(prefix)) {
193
                list.put(new MyElement(next));
192
                list.add(new MyElement(next));
194
            }
193
            }
195
        }
194
        }
196
        
195
        
197
        return list;                        
196
        return Collections.enumeration (list);
198
    }
197
    }
199
    
198
    
200
    /**
199
    /**
Lines 202-219 Link Here
202
     * @return list of <code>CompletionResult</code>s (NOTATION_NODEs)
201
     * @return list of <code>CompletionResult</code>s (NOTATION_NODEs)
203
     */
202
     */
204
    public Enumeration queryNotations(String prefix) {
203
    public Enumeration queryNotations(String prefix) {
205
        if (notations == null) return EmptyEnumeration.EMPTY;;
204
        if (notations == null) return org.openide.util.Enumerations.EMPTY;;
206
        
205
        
207
        QueueEnumeration list = new QueueEnumeration();
206
        LinkedList list = new LinkedList ();
208
        Iterator it = notations.iterator();
207
        Iterator it = notations.iterator();
209
        while ( it.hasNext()) {
208
        while ( it.hasNext()) {
210
            String next = (String) it.next();
209
            String next = (String) it.next();
211
            if (next.startsWith(prefix)) {
210
            if (next.startsWith(prefix)) {
212
                list.put(new MyNotation(next));
211
                list.add (new MyNotation(next));
213
            }
212
            }
214
        }
213
        }
215
        
214
        
216
        return list;
215
        return Collections.enumeration (list);
217
    }
216
    }
218
       
217
       
219
    /**
218
    /**
Lines 226-255 Link Here
226
     *        Every list member represents one possibility.
225
     *        Every list member represents one possibility.
227
     */
226
     */
228
    public Enumeration queryValues(HintContext ctx) {
227
    public Enumeration queryValues(HintContext ctx) {
229
        if (attrEnumerations.isEmpty()) return EmptyEnumeration.EMPTY;
228
        if (attrEnumerations.isEmpty()) return org.openide.util.Enumerations.EMPTY;
230
        
229
        
231
        if (ctx.getNodeType() == Node.ATTRIBUTE_NODE) {
230
        if (ctx.getNodeType() == Node.ATTRIBUTE_NODE) {
232
            String attributeName = ctx.getNodeName();
231
            String attributeName = ctx.getNodeName();
233
            Element element = ((Attr)ctx).getOwnerElement();
232
            Element element = ((Attr)ctx).getOwnerElement();
234
            if (element == null) return EmptyEnumeration.EMPTY;
233
            if (element == null) return org.openide.util.Enumerations.EMPTY;
235
            
234
            
236
            String elementName = element.getNodeName();
235
            String elementName = element.getNodeName();
237
            String key = elementName + " " + attributeName;
236
            String key = elementName + " " + attributeName;
238
            List values = (List) attrEnumerations.get(key);
237
            List values = (List) attrEnumerations.get(key);
239
            if (values == null) return EmptyEnumeration.EMPTY;
238
            if (values == null) return org.openide.util.Enumerations.EMPTY;
240
            
239
            
241
            String prefix = ctx.getCurrentPrefix();
240
            String prefix = ctx.getCurrentPrefix();
242
            QueueEnumeration en = new QueueEnumeration();
241
            LinkedList en = new LinkedList ();
243
            Iterator it = values.iterator();
242
            Iterator it = values.iterator();
244
            while (it.hasNext()) {
243
            while (it.hasNext()) {
245
                String next = (String) it.next();
244
                String next = (String) it.next();
246
                if (next.startsWith(prefix)) {
245
                if (next.startsWith(prefix)) {
247
                    en.put(new MyText(next));
246
                    en.add(new MyText(next));
248
                }
247
                }
249
            }
248
            }
250
            return en;
249
            return Collections.enumeration (en);
251
        }
250
        }
252
        return EmptyEnumeration.EMPTY;
251
        return org.openide.util.Enumerations.EMPTY;
253
    }
252
    }
254
253
255
    // return defaults for attribute values (DTD does not declare content defaults)
254
    // return defaults for attribute values (DTD does not declare content defaults)
(-)xml/core/src/org/netbeans/modules/xml/dtd/grammar/DTDGrammarQueryProvider.java (-2 / +1 lines)
Lines 16-22 Link Here
16
import java.beans.FeatureDescriptor;
16
import java.beans.FeatureDescriptor;
17
import java.util.Enumeration;
17
import java.util.Enumeration;
18
import org.netbeans.modules.xml.api.model.*;
18
import org.netbeans.modules.xml.api.model.*;
19
import org.openide.util.enum.SingletonEnumeration;
20
import org.w3c.dom.Node;
19
import org.w3c.dom.Node;
21
import org.xml.sax.InputSource;
20
import org.xml.sax.InputSource;
22
21
Lines 32-38 Link Here
32
        while (en.hasMoreElements()) {
31
        while (en.hasMoreElements()) {
33
            Node next = (Node) en.nextElement();
32
            Node next = (Node) en.nextElement();
34
            if (next.getNodeType() == next.DOCUMENT_TYPE_NODE) {
33
            if (next.getNodeType() == next.DOCUMENT_TYPE_NODE) {
35
                return new SingletonEnumeration(next);
34
                return org.openide.util.Enumerations.singleton (next);
36
            }
35
            }
37
        }
36
        }
38
        return null;
37
        return null;
(-)xml/core/src/org/netbeans/modules/xml/spi/model/EmptyQuery.java (-7 / +5 lines)
Lines 17-24 Link Here
17
17
18
import org.w3c.dom.*;
18
import org.w3c.dom.*;
19
19
20
import org.openide.util.enum.EmptyEnumeration;
21
22
import org.netbeans.modules.xml.api.model.*;
20
import org.netbeans.modules.xml.api.model.*;
23
21
24
/**
22
/**
Lines 36-58 Link Here
36
    // inherit JavaDoc from interface description
34
    // inherit JavaDoc from interface description
37
    
35
    
38
    public Enumeration queryEntities(String prefix) {
36
    public Enumeration queryEntities(String prefix) {
39
        return EmptyEnumeration.EMPTY; 
37
        return org.openide.util.Enumerations.EMPTY; 
40
    }
38
    }
41
    
39
    
42
    public Enumeration queryAttributes(HintContext ctx) {
40
    public Enumeration queryAttributes(HintContext ctx) {
43
        return EmptyEnumeration.EMPTY; 
41
        return org.openide.util.Enumerations.EMPTY; 
44
    }
42
    }
45
    
43
    
46
    public Enumeration queryElements(HintContext ctx) {
44
    public Enumeration queryElements(HintContext ctx) {
47
        return EmptyEnumeration.EMPTY; 
45
        return org.openide.util.Enumerations.EMPTY; 
48
    }
46
    }
49
    
47
    
50
    public Enumeration queryNotations(String prefix) {
48
    public Enumeration queryNotations(String prefix) {
51
        return EmptyEnumeration.EMPTY; 
49
        return org.openide.util.Enumerations.EMPTY; 
52
    }
50
    }
53
    
51
    
54
    public Enumeration queryValues(HintContext ctx) {
52
    public Enumeration queryValues(HintContext ctx) {
55
        return EmptyEnumeration.EMPTY; 
53
        return org.openide.util.Enumerations.EMPTY; 
56
    }
54
    }
57
    
55
    
58
    public boolean isAllowed(Enumeration en) {
56
    public boolean isAllowed(Enumeration en) {
(-)xml/core/test/unit/src/org/netbeans/modules/xml/api/model/GrammarQueryManagerTest.java (-3 / +1 lines)
Lines 37-44 Link Here
37
import org.openide.loaders.DataObjectNotFoundException;
37
import org.openide.loaders.DataObjectNotFoundException;
38
import org.openide.loaders.FolderLookup;
38
import org.openide.loaders.FolderLookup;
39
import org.openide.util.Lookup;
39
import org.openide.util.Lookup;
40
import org.openide.util.enum.ArrayEnumeration;
41
import org.openide.util.enum.EmptyEnumeration;
42
import org.xml.sax.InputSource;
40
import org.xml.sax.InputSource;
43
41
44
/**
42
/**
Lines 98-104 Link Here
98
            // test
96
            // test
99
            
97
            
100
            GrammarQueryManager manager = GrammarQueryManager.getDefault();
98
            GrammarQueryManager manager = GrammarQueryManager.getDefault();
101
            GrammarEnvironment env = new GrammarEnvironment(EmptyEnumeration.EMPTY, new InputSource(), null);
99
            GrammarEnvironment env = new GrammarEnvironment(org.openide.util.Enumerations.EMPTY, new InputSource(), null);
102
            Enumeration trigger = manager.enabled(env);
100
            Enumeration trigger = manager.enabled(env);
103
            assertTrue("No grammar found!", trigger!=null);
101
            assertTrue("No grammar found!", trigger!=null);
104
        } finally {
102
        } finally {
(-)xml/core/test/unit/src/org/netbeans/modules/xml/dtd/grammar/ContentModelTest.java (-1 lines)
Lines 17-23 Link Here
17
import org.netbeans.junit.*;
17
import org.netbeans.junit.*;
18
import java.util.*;
18
import java.util.*;
19
import java.util.StringTokenizer;
19
import java.util.StringTokenizer;
20
import org.openide.util.enum.*;
21
20
22
/**
21
/**
23
 *
22
 *
(-)xml/core/test/unit/src/org/netbeans/modules/xml/api/model/GrammarQueryManagerTest.java (-3 / +1 lines)
Lines 37-44 Link Here
37
import org.openide.loaders.DataObjectNotFoundException;
37
import org.openide.loaders.DataObjectNotFoundException;
38
import org.openide.loaders.FolderLookup;
38
import org.openide.loaders.FolderLookup;
39
import org.openide.util.Lookup;
39
import org.openide.util.Lookup;
40
import org.openide.util.enum.ArrayEnumeration;
41
import org.openide.util.enum.EmptyEnumeration;
42
import org.xml.sax.InputSource;
40
import org.xml.sax.InputSource;
43
41
44
/**
42
/**
Lines 98-104 Link Here
98
            // test
96
            // test
99
            
97
            
100
            GrammarQueryManager manager = GrammarQueryManager.getDefault();
98
            GrammarQueryManager manager = GrammarQueryManager.getDefault();
101
            GrammarEnvironment env = new GrammarEnvironment(EmptyEnumeration.EMPTY, new InputSource(), null);
99
            GrammarEnvironment env = new GrammarEnvironment(org.openide.util.Enumerations.EMPTY, new InputSource(), null);
102
            Enumeration trigger = manager.enabled(env);
100
            Enumeration trigger = manager.enabled(env);
103
            assertTrue("No grammar found!", trigger!=null);
101
            assertTrue("No grammar found!", trigger!=null);
104
        } finally {
102
        } finally {
(-)xml/core/test/unit/src/org/netbeans/modules/xml/dtd/grammar/ContentModelTest.java (-1 lines)
Lines 17-23 Link Here
17
import org.netbeans.junit.*;
17
import org.netbeans.junit.*;
18
import java.util.*;
18
import java.util.*;
19
import java.util.StringTokenizer;
19
import java.util.StringTokenizer;
20
import org.openide.util.enum.*;
21
20
22
/**
21
/**
23
 *
22
 *
(-)xml/schema/src/org/netbeans/modules/xml/xsd/XSDGrammarQueryProvider.java (-2 / +1 lines)
Lines 22-28 Link Here
22
22
23
import org.openide.ErrorManager;
23
import org.openide.ErrorManager;
24
import org.openide.filesystems.FileObject;
24
import org.openide.filesystems.FileObject;
25
import org.openide.util.enum.SingletonEnumeration;
26
import org.netbeans.modules.xml.api.model.*;
25
import org.netbeans.modules.xml.api.model.*;
27
import org.netbeans.api.xml.services.UserCatalog;
26
import org.netbeans.api.xml.services.UserCatalog;
28
27
Lines 48-54 Link Here
48
        if (ret != null) {
47
        if (ret != null) {
49
            // remember this schema
48
            // remember this schema
50
            schemas.put(ctx.getFileObject(), ret);
49
            schemas.put(ctx.getFileObject(), ret);
51
            return new SingletonEnumeration(ret.getTarget());
50
            return org.openide.util.Enumerations.singleton (ret.getTarget());
52
        }
51
        }
53
        
52
        
54
	return null;
53
	return null;
(-)xml/tax/src/org/netbeans/modules/xml/tax/parser/ParserLoader.java (-1 / +1 lines)
Lines 176-182 Link Here
176
        Enumeration en1 = super.findResources(name);
176
        Enumeration en1 = super.findResources(name);
177
        Enumeration en2 = parentLoader.getResources(name);
177
        Enumeration en2 = parentLoader.getResources(name);
178
178
179
        return new org.openide.util.enum.SequenceEnumeration(en1, en2);
179
        return org.openide.util.Enumerations.concat (en1, en2);
180
    }
180
    }
181
181
182
    /**
182
    /**
(-)xml/text-edit/src/org/netbeans/modules/xml/text/completion/GrammarManager.java (-4 / +6 lines)
Lines 17-22 Link Here
17
import java.util.ArrayList;
17
import java.util.ArrayList;
18
import java.util.Enumeration;
18
import java.util.Enumeration;
19
import java.util.List;
19
import java.util.List;
20
import java.util.LinkedList;
21
import java.util.Collections;
22
20
import javax.swing.event.DocumentEvent;
23
import javax.swing.event.DocumentEvent;
21
import javax.swing.event.DocumentListener;
24
import javax.swing.event.DocumentListener;
22
import javax.swing.text.BadLocationException;
25
import javax.swing.text.BadLocationException;
Lines 36-42 Link Here
36
import org.openide.text.NbDocument;
39
import org.openide.text.NbDocument;
37
import org.openide.util.RequestProcessor;
40
import org.openide.util.RequestProcessor;
38
import org.openide.util.Task;
41
import org.openide.util.Task;
39
import org.openide.util.enum.QueueEnumeration;
40
import org.w3c.dom.Node;
42
import org.w3c.dom.Node;
41
import org.xml.sax.InputSource;
43
import org.xml.sax.InputSource;
42
import org.openide.awt.StatusDisplayer;
44
import org.openide.awt.StatusDisplayer;
Lines 189-201 Link Here
189
191
190
            try {
192
            try {
191
193
192
                QueueEnumeration ctx = new QueueEnumeration();
194
                LinkedList ctx = new LinkedList ();
193
                SyntaxElement first = syntax.getElementChain(1);
195
                SyntaxElement first = syntax.getElementChain(1);
194
                while (true) {
196
                while (true) {
195
                    if (first == null) break;
197
                    if (first == null) break;
196
                    if (first instanceof SyntaxNode) {
198
                    if (first instanceof SyntaxNode) {
197
                        SyntaxNode node = (SyntaxNode) first;
199
                        SyntaxNode node = (SyntaxNode) first;
198
                        ctx.put(node);
200
                        ctx.add (node);
199
                        if (node.ELEMENT_NODE == node.getNodeType()) {
201
                        if (node.ELEMENT_NODE == node.getNodeType()) {
200
                            break;
202
                            break;
201
                        }
203
                        }
Lines 210-216 Link Here
210
                    DataObject dobj = (DataObject) obj;
212
                    DataObject dobj = (DataObject) obj;
211
                    fileObject = dobj.getPrimaryFile();
213
                    fileObject = dobj.getPrimaryFile();
212
                }
214
                }
213
                GrammarEnvironment env = new GrammarEnvironment(ctx, inputSource, fileObject);
215
                GrammarEnvironment env = new GrammarEnvironment(Collections.enumeration (ctx), inputSource, fileObject);
214
216
215
                // lookup for grammar
217
                // lookup for grammar
216
218
(-)xml/text-edit/test/unit/src/org/netbeans/modules/xml/text/completion/UnitTestQuery.java (-2 / +1 lines)
Lines 22-28 Link Here
22
import java.util.Enumeration;
22
import java.util.Enumeration;
23
23
24
import junit.framework.*;
24
import junit.framework.*;
25
import org.openide.util.enum.EmptyEnumeration;
26
25
27
/**
26
/**
28
 * Just remember completion request and return empty results.
27
 * Just remember completion request and return empty results.
Lines 50-56 Link Here
50
        op = "R";
49
        op = "R";
51
        ctx = "'" + prefix + "'";
50
        ctx = "'" + prefix + "'";
52
        fillTrace();        
51
        fillTrace();        
53
        return EmptyEnumeration.EMPTY;
52
        return org.openide.util.Enumerations.EMPTY;
54
    }    
53
    }    
55
    
54
    
56
    /**
55
    /**
(-)xml/text-edit/test/unit/src/org/netbeans/modules/xml/text/completion/UnitTestQuery.java (-2 / +1 lines)
Lines 22-28 Link Here
22
import java.util.Enumeration;
22
import java.util.Enumeration;
23
23
24
import junit.framework.*;
24
import junit.framework.*;
25
import org.openide.util.enum.EmptyEnumeration;
26
25
27
/**
26
/**
28
 * Just remember completion request and return empty results.
27
 * Just remember completion request and return empty results.
Lines 50-56 Link Here
50
        op = "R";
49
        op = "R";
51
        ctx = "'" + prefix + "'";
50
        ctx = "'" + prefix + "'";
52
        fillTrace();        
51
        fillTrace();        
53
        return EmptyEnumeration.EMPTY;
52
        return org.openide.util.Enumerations.EMPTY;
54
    }    
53
    }    
55
    
54
    
56
    /**
55
    /**
(-)xml/tree-edit/src/org/netbeans/modules/xml/tree/completion/GrammarManager.java (-4 / +3 lines)
Lines 34-40 Link Here
34
import org.openide.loaders.DataObject;
34
import org.openide.loaders.DataObject;
35
import org.openide.util.RequestProcessor;
35
import org.openide.util.RequestProcessor;
36
import org.openide.util.Task;
36
import org.openide.util.Task;
37
import org.openide.util.enum.QueueEnumeration;
38
import org.w3c.dom.Node;
37
import org.w3c.dom.Node;
39
import org.xml.sax.InputSource;
38
import org.xml.sax.InputSource;
40
import org.openide.awt.StatusDisplayer;
39
import org.openide.awt.StatusDisplayer;
Lines 197-209 Link Here
197
196
198
                    Iterator treeObjectIter = docRoot.getChildNodes().iterator();
197
                    Iterator treeObjectIter = docRoot.getChildNodes().iterator();
199
198
200
                    QueueEnumeration ctx = new QueueEnumeration();
199
                    LinkedList ctx = new LinkedList ();
201
200
202
                    while( treeObjectIter.hasNext() )
201
                    while( treeObjectIter.hasNext() )
203
                    { 
202
                    { 
204
                        TreeObject child = (TreeObject)treeObjectIter.next();
203
                        TreeObject child = (TreeObject)treeObjectIter.next();
205
                        try { 
204
                        try { 
206
                            ctx.put( Wrapper.wrap(child) );
205
                            ctx.add ( Wrapper.wrap(child) );
207
                        } 
206
                        } 
208
                        catch( RuntimeException ex ) { 
207
                        catch( RuntimeException ex ) { 
209
                            System.err.println("Could not wrap TAX object: " 
208
                            System.err.println("Could not wrap TAX object: " 
Lines 211-217 Link Here
211
                        } 
210
                        } 
212
                    } 
211
                    } 
213
212
214
                    GrammarEnvironment env = new GrammarEnvironment(ctx, inputSource, fObj);
213
                    GrammarEnvironment env = new GrammarEnvironment(Collections.enumeration (ctx), inputSource, fObj);
215
214
216
                    if( gqm.enabled(env) != null )
215
                    if( gqm.enabled(env) != null )
217
                    { 
216
                    { 
(-)xml/xsl/src/org/netbeans/modules/xsl/grammar/XSLGrammarQuery.java (-10 / +28 lines)
Lines 20-26 Link Here
20
20
21
import org.netbeans.api.xml.services.UserCatalog;
21
import org.netbeans.api.xml.services.UserCatalog;
22
import org.netbeans.modules.xml.api.model.*;
22
import org.netbeans.modules.xml.api.model.*;
23
import org.openide.util.enum.*;
24
import org.netbeans.modules.xml.dtd.grammar.*;
23
import org.netbeans.modules.xml.dtd.grammar.*;
25
import org.netbeans.modules.xml.spi.dom.*;
24
import org.netbeans.modules.xml.spi.dom.*;
26
import org.netbeans.modules.xml.api.cookies.ScenarioCookie;
25
import org.netbeans.modules.xml.api.cookies.ScenarioCookie;
Lines 432-438 Link Here
432
        if (node instanceof Element) {
431
        if (node instanceof Element) {
433
            Element el = (Element) node;
432
            Element el = (Element) node;
434
            updateProperties(el);
433
            updateProperties(el);
435
            if (prefixList.size() == 0) return EmptyEnumeration.EMPTY;
434
            if (prefixList.size() == 0) return org.openide.util.Enumerations.EMPTY;
436
435
437
            String firstXslPrefixWithColon = prefixList.get(0) + ":"; // NOI18N
436
            String firstXslPrefixWithColon = prefixList.get(0) + ":"; // NOI18N
438
            Set elements;
437
            Set elements;
Lines 477-486 Link Here
477
476
478
        } else if (node instanceof Document) {
477
        } else if (node instanceof Document) {
479
            //??? it should be probably only root element name
478
            //??? it should be probably only root element name
480
            if (prefixList.size() == 0) return EmptyEnumeration.EMPTY;
479
            if (prefixList.size() == 0) return org.openide.util.Enumerations.EMPTY;
481
            addXslElementsToEnum(list, getElementDecls().keySet(), prefixList.get(0) + ":", prefix); // NOI18N
480
            addXslElementsToEnum(list, getElementDecls().keySet(), prefixList.get(0) + ":", prefix); // NOI18N
482
        } else {
481
        } else {
483
            return EmptyEnumeration.EMPTY;
482
            return org.openide.util.Enumerations.EMPTY;
484
        }
483
        }
485
484
486
        return list;
485
        return list;
Lines 494-500 Link Here
494
        } else if (ctx.getNodeType() == Node.ELEMENT_NODE) {
493
        } else if (ctx.getNodeType() == Node.ELEMENT_NODE) {
495
            el = (Element) ctx;
494
            el = (Element) ctx;
496
        }
495
        }
497
        if (el == null) return EmptyEnumeration.EMPTY;
496
        if (el == null) return org.openide.util.Enumerations.EMPTY;
498
497
499
        String elTagName = el.getTagName();
498
        String elTagName = el.getTagName();
500
        NamedNodeMap existingAttributes = el.getAttributes();
499
        NamedNodeMap existingAttributes = el.getAttributes();
Lines 524-530 Link Here
524
                }
523
                }
525
            }
524
            }
526
        }
525
        }
527
        if (possibleAttributes == null) return EmptyEnumeration.EMPTY;
526
        if (possibleAttributes == null) return org.openide.util.Enumerations.EMPTY;
528
527
529
        String prefix = ctx.getCurrentPrefix();
528
        String prefix = ctx.getCurrentPrefix();
530
529
Lines 556-562 Link Here
556
    public Enumeration queryValues(HintContext ctx) {
555
    public Enumeration queryValues(HintContext ctx) {
557
       if (ctx.getNodeType() == Node.ATTRIBUTE_NODE) {
556
       if (ctx.getNodeType() == Node.ATTRIBUTE_NODE) {
558
            updateProperties(((Attr)ctx).getOwnerElement());
557
            updateProperties(((Attr)ctx).getOwnerElement());
559
            if (prefixList.size() == 0) return EmptyEnumeration.EMPTY;
558
            if (prefixList.size() == 0) return org.openide.util.Enumerations.EMPTY;
560
            String xslNamespacePrefix = prefixList.get(0) + ":"; // NOI18N
559
            String xslNamespacePrefix = prefixList.get(0) + ":"; // NOI18N
561
560
562
            String prefix = ctx.getCurrentPrefix();
561
            String prefix = ctx.getCurrentPrefix();
Lines 577-583 Link Here
577
                if ("output".equals(key)) {                             // NOI18N
576
                if ("output".equals(key)) {                             // NOI18N
578
                    if ("doctype-public".equals(attr.getName())) {      // NOI18N
577
                    if ("doctype-public".equals(attr.getName())) {      // NOI18N
579
                        UserCatalog catalog = UserCatalog.getDefault();
578
                        UserCatalog catalog = UserCatalog.getDefault();
580
                        if (catalog == null) return EmptyEnumeration.EMPTY;
579
                        if (catalog == null) return org.openide.util.Enumerations.EMPTY;
581
                        QueueEnumeration en = new QueueEnumeration();
580
                        QueueEnumeration en = new QueueEnumeration();
582
                        Iterator it = catalog.getPublicIDs();
581
                        Iterator it = catalog.getPublicIDs();
583
                        while (it.hasNext()) {
582
                        while (it.hasNext()) {
Lines 712-718 Link Here
712
            }
711
            }
713
        }
712
        }
714
713
715
        return EmptyEnumeration.EMPTY;
714
        return org.openide.util.Enumerations.EMPTY;
716
    }
715
    }
717
716
718
    public GrammarResult queryDefault(HintContext ctx) {
717
    public GrammarResult queryDefault(HintContext ctx) {
Lines 740-746 Link Here
740
    }
739
    }
741
740
742
    public Enumeration queryNotations(String prefix) {
741
    public Enumeration queryNotations(String prefix) {
743
        return EmptyEnumeration.EMPTY;
742
        return org.openide.util.Enumerations.EMPTY;
744
    }
743
    }
745
744
746
    public java.awt.Component getCustomizer(HintContext ctx) {
745
    public java.awt.Component getCustomizer(HintContext ctx) {
Lines 1124-1127 Link Here
1124
        }
1123
        }
1125
    }
1124
    }
1126
1125
1126
    private static class QueueEnumeration implements Enumeration {
1127
        private java.util.LinkedList list = new LinkedList ();
1128
        
1129
        public boolean hasMoreElements () {
1130
            return !list.isEmpty ();
1131
        }        
1132
        
1133
        public Object nextElement () {
1134
            return list.removeFirst ();
1135
        }        
1136
1137
        public void put (Object[] arr) {
1138
            list.addAll (Arrays.asList (arr));
1139
        }
1140
        public void put (Object o) {
1141
            list.add (o);
1142
        }
1143
        
1144
    } // end of QueueEnumeration
1127
}
1145
}
(-)xml/xsl/src/org/netbeans/modules/xsl/grammar/XSLGrammarQueryProvider.java (-7 / +3 lines)
Lines 18-33 Link Here
18
import org.netbeans.modules.xml.api.model.GrammarQuery;
18
import org.netbeans.modules.xml.api.model.GrammarQuery;
19
import org.netbeans.modules.xml.api.model.GrammarQueryManager;
19
import org.netbeans.modules.xml.api.model.GrammarQueryManager;
20
import org.openide.filesystems.FileObject;
20
import org.openide.filesystems.FileObject;
21
import org.openide.util.enum.EmptyEnumeration;
22
import org.openide.util.enum.SingletonEnumeration;
23
import org.w3c.dom.DocumentType;
21
import org.w3c.dom.DocumentType;
24
import org.w3c.dom.Element;
22
import org.w3c.dom.Element;
25
import org.w3c.dom.Node;
23
import org.w3c.dom.Node;
26
import org.xml.sax.InputSource;
24
import org.xml.sax.InputSource;
27
25
28
import org.openide.filesystems.FileObject;
26
import org.openide.filesystems.FileObject;
29
import org.openide.util.enum.EmptyEnumeration;
30
import org.openide.util.enum.SingletonEnumeration;
31
27
32
import org.netbeans.modules.xsl.XSLDataObject;
28
import org.netbeans.modules.xsl.XSLDataObject;
33
import org.openide.loaders.DataObject;
29
import org.openide.loaders.DataObject;
Lines 66-72 Link Here
66
                    if ("transformation".equals(tag) || "stylesheet".equals(tag)) { // NOI18N
62
                    if ("transformation".equals(tag) || "stylesheet".equals(tag)) { // NOI18N
67
                        String ns = element.getAttribute("xmlns"); // NOI18N
63
                        String ns = element.getAttribute("xmlns"); // NOI18N
68
                        if (NAMESPACE.equals(ns)) {
64
                        if (NAMESPACE.equals(ns)) {
69
                            return new SingletonEnumeration(next);
65
                            return org.openide.util.Enumerations.singleton (next);
70
                        }
66
                        }
71
                    }
67
                    }
72
                } else {
68
                } else {
Lines 75-81 Link Here
75
                    if ("transformation".equals(local) || "stylesheet".equals(local)) { // NOI18N
71
                    if ("transformation".equals(local) || "stylesheet".equals(local)) { // NOI18N
76
                        String ns = element.getAttribute("xmlns:" + prefix); // NOI18N
72
                        String ns = element.getAttribute("xmlns:" + prefix); // NOI18N
77
                        if (NAMESPACE.equals(ns)) {
73
                        if (NAMESPACE.equals(ns)) {
78
                            return new SingletonEnumeration(next);
74
                            return org.openide.util.Enumerations.singleton (next);
79
                        }
75
                        }
80
                    }
76
                    }
81
                }
77
                }
Lines 89-95 Link Here
89
                // almost forever, until client uses its own invalidation
85
                // almost forever, until client uses its own invalidation
90
                // rules based e.g. on new node detection at root level
86
                // rules based e.g. on new node detection at root level
91
                // or MIME type listening
87
                // or MIME type listening
92
                return EmptyEnumeration.EMPTY;
88
                return org.openide.util.Enumerations.EMPTY;
93
            }
89
            }
94
        }
90
        }
95
        
91
        

Return to bug 41166