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 67888
Collapse All | Expand All

(-)openide/util/nbproject/project.properties (+2 lines)
Lines 9-14 Link Here
9
# Code is Sun Microsystems, Inc. Portions Copyright 1997-2005 Sun
9
# Code is Sun Microsystems, Inc. Portions Copyright 1997-2005 Sun
10
# Microsystems, Inc. All Rights Reserved.
10
# Microsystems, Inc. All Rights Reserved.
11
11
12
javac.compilerargs=-Xlint:unchecked
13
javac.source=1.5
12
module.jar.dir=lib
14
module.jar.dir=lib
13
15
14
spec.version.base=6.9.0
16
spec.version.base=6.9.0
(-)openide/util/src/org/openide/ErrorManager.java (-12 / +9 lines)
Lines 502-516 Link Here
502
        /**
502
        /**
503
         * A set that has to be updated when the list of delegates
503
         * A set that has to be updated when the list of delegates
504
         * changes. All instances created by getInstance are held here.
504
         * changes. All instances created by getInstance are held here.
505
         * It is a set of DelagatingErrorManager.
506
         */
505
         */
507
        private WeakSet createdByMe = new WeakSet();
506
        private WeakSet<DelegatingErrorManager> createdByMe = new WeakSet<DelegatingErrorManager>();
508
507
509
        /** If we are the "central" delagate this is not null and
508
        /** If we are the "central" delagate this is not null and
510
         * we listen on the result. On newly created delegates this
509
         * we listen on the result. On newly created delegates this
511
         * is null.
510
         * is null.
512
         */
511
         */
513
        Lookup.Result r;
512
        Lookup.Result<ErrorManager> r;
514
513
515
        public DelegatingErrorManager(String name) {
514
        public DelegatingErrorManager(String name) {
516
            this.name = name;
515
            this.name = name;
Lines 674-681 Link Here
674
         * Updates the list of delegates. Also updates all instances created
673
         * Updates the list of delegates. Also updates all instances created
675
         * by ourselves.
674
         * by ourselves.
676
         */
675
         */
677
        public synchronized void setDelegates(Collection newDelegates) {
676
        public synchronized void setDelegates(Collection<? extends ErrorManager> newDelegates) {
678
            java.util.LinkedHashSet d = new java.util.LinkedHashSet(newDelegates);
677
            java.util.LinkedHashSet<ErrorManager> d;
678
            d = new java.util.LinkedHashSet<ErrorManager>(newDelegates);
679
            delegates = d;
679
            delegates = d;
680
680
681
            for (Iterator i = createdByMe.iterator(); i.hasNext();) {
681
            for (Iterator i = createdByMe.iterator(); i.hasNext();) {
Lines 695-701 Link Here
695
         * @param DelagatingErrorManager d the instance to which we will attach
695
         * @param DelagatingErrorManager d the instance to which we will attach
696
         */
696
         */
697
        private void attachNewDelegates(DelegatingErrorManager dem, String name) {
697
        private void attachNewDelegates(DelegatingErrorManager dem, String name) {
698
            Set newDelegatesForDem = new HashSet();
698
            Set<ErrorManager> newDelegatesForDem = new HashSet<ErrorManager>();
699
699
700
            for (Iterator j = delegates.iterator(); j.hasNext();) {
700
            for (Iterator j = delegates.iterator(); j.hasNext();) {
701
                ErrorManager e = (ErrorManager) j.next();
701
                ErrorManager e = (ErrorManager) j.next();
Lines 709-725 Link Here
709
         * delegates and adds a listener.
709
         * delegates and adds a listener.
710
         */
710
         */
711
        public void initialize() {
711
        public void initialize() {
712
            r = Lookup.getDefault().lookup(new Lookup.Template(ErrorManager.class));
712
            r = Lookup.getDefault().lookup(new Lookup.Template<ErrorManager>(ErrorManager.class));
713
713
            setDelegates(r.allInstances());
714
            Collection instances = r.allInstances();
715
            setDelegates(instances);
716
        }
714
        }
717
715
718
        /** Updates the delegates.*/
716
        /** Updates the delegates.*/
719
        public void resultChanged(LookupEvent ev) {
717
        public void resultChanged(LookupEvent ev) {
720
            if (r != null) {
718
            if (r != null) {
721
                Collection instances = r.allInstances();
719
                setDelegates(r.allInstances());
722
                setDelegates(instances);
723
            }
720
            }
724
        }
721
        }
725
    }
722
    }
(-)openide/util/src/org/openide/ServiceType.java (-10 / +9 lines)
Lines 197-212 Link Here
197
        /** Get all available services managed by the engine.
197
        /** Get all available services managed by the engine.
198
        * @return an enumeration of {@link ServiceType}s
198
        * @return an enumeration of {@link ServiceType}s
199
        */
199
        */
200
        public abstract Enumeration services();
200
        public abstract Enumeration<ServiceType> services();
201
201
202
        /** Get all available services that are assignable to the given superclass.
202
        /** Get all available services that are assignable to the given superclass.
203
        * @param clazz the class that all services should be subclass of
203
        * @param clazz the class that all services should be subclass of
204
        * @return an enumeration of all matching {@link ServiceType}s
204
        * @return an enumeration of all matching {@link ServiceType}s
205
        */
205
        */
206
        public Enumeration services(final Class clazz) {
206
        public <T extends ServiceType> Enumeration<T> services(final Class<T> clazz) {
207
            class IsInstance implements org.openide.util.Enumerations.Processor {
207
            class IsInstance implements org.openide.util.Enumerations.Processor<ServiceType,T> {
208
                public Object process(Object obj, java.util.Collection ignore) {
208
                public T process(ServiceType obj, java.util.Collection ignore) {
209
                    return clazz.isInstance(obj) ? obj : null;
209
                    return clazz.isInstance(obj) ? clazz.cast(obj) : null;
210
                }
210
                }
211
            }
211
            }
212
212
Lines 311-326 Link Here
311
        public ServiceType getServiceType() {
311
        public ServiceType getServiceType() {
312
            if (serviceType == null) {
312
            if (serviceType == null) {
313
                // the class to search for
313
                // the class to search for
314
                Class clazz;
314
                Class<? extends ServiceType> clazz;
315
315
316
                // the first subclass of ServiceType to search for
316
                // the first subclass of ServiceType to search for
317
                Class serviceTypeClass;
317
                Class<?> serviceTypeClass;
318
318
319
                // try to find it by class
319
                // try to find it by class
320
                try {
320
                try {
321
                    clazz = Class.forName(className, true, (ClassLoader) Lookup.getDefault().lookup(ClassLoader.class));
321
                    serviceTypeClass = Class.forName(className, true, (ClassLoader) Lookup.getDefault().lookup(ClassLoader.class));
322
322
                    clazz = serviceTypeClass.asSubclass(ServiceType.class);
323
                    serviceTypeClass = clazz;
324
323
325
                    while (serviceTypeClass.getSuperclass() != ServiceType.class) {
324
                    while (serviceTypeClass.getSuperclass() != ServiceType.class) {
326
                        serviceTypeClass = serviceTypeClass.getSuperclass();
325
                        serviceTypeClass = serviceTypeClass.getSuperclass();
(-)openide/util/src/org/openide/util/Enumerations.java (-81 / +82 lines)
Lines 37-44 Link Here
37
     * from <code>empty().nextElement()</code>.
37
     * from <code>empty().nextElement()</code>.
38
     * @return the enumeration
38
     * @return the enumeration
39
     */
39
     */
40
    public static final Enumeration empty() {
40
    public static final <T> Enumeration<T> empty() {
41
        return Collections.enumeration(Collections.EMPTY_LIST);
41
        Collection<T> emptyL = Collections.emptyList();
42
        return Collections.enumeration(emptyL);
42
    }
43
    }
43
44
44
    /**
45
    /**
Lines 46-52 Link Here
46
     * @param obj the element to be present in the enumeration.
47
     * @param obj the element to be present in the enumeration.
47
     * @return enumeration
48
     * @return enumeration
48
     */
49
     */
49
    public static Enumeration singleton(Object obj) {
50
    public static <T> Enumeration<T> singleton(T obj) {
50
        return Collections.enumeration(Collections.singleton(obj));
51
        return Collections.enumeration(Collections.singleton(obj));
51
    }
52
    }
52
53
Lines 61-68 Link Here
61
     * @param en2 second enumeration
62
     * @param en2 second enumeration
62
     * @return enumeration
63
     * @return enumeration
63
     */
64
     */
64
    public static Enumeration concat(Enumeration en1, Enumeration en2) {
65
    public static <T> Enumeration<T> concat(Enumeration<? extends T> en1, Enumeration<? extends T> en2) {
65
        return new SeqEn(en1, en2);
66
        ArrayList<Enumeration<? extends T>> two = new ArrayList<Enumeration<? extends T>>();
67
        two.add(en1);
68
        two.add(en2);
69
        return new SeqEn<T>(Collections.enumeration(two));
66
    }
70
    }
67
71
68
    /**
72
    /**
Lines 76-83 Link Here
76
     * @param enumOfEnums Enumeration of Enumeration elements
80
     * @param enumOfEnums Enumeration of Enumeration elements
77
     * @return enumeration
81
     * @return enumeration
78
     */
82
     */
79
    public static Enumeration concat(Enumeration enumOfEnums) {
83
    public static <T> Enumeration<T> concat(Enumeration<? extends Enumeration<? extends T>> enumOfEnums) {
80
        return new SeqEn(enumOfEnums);
84
        return new SeqEn<T>(enumOfEnums);
81
    }
85
    }
82
86
83
    /**
87
    /**
Lines 89-99 Link Here
89
     * @param en enumeration to filter
93
     * @param en enumeration to filter
90
     * @return enumeration without duplicated items
94
     * @return enumeration without duplicated items
91
     */
95
     */
92
    public static Enumeration removeDuplicates(Enumeration en) {
96
    public static <T> Enumeration<T> removeDuplicates(Enumeration<T> en) {
93
        class RDupls implements Processor {
97
        class RDupls implements Processor<T,T> {
94
            private Set set = new HashSet();
98
            private Set<T> set = new HashSet<T>();
95
99
96
            public Object process(Object o, Collection nothing) {
100
            public T process(T o, Collection<T> nothing) {
97
                return set.add(o) ? o : null;
101
                return set.add(o) ? o : null;
98
            }
102
            }
99
        }
103
        }
Lines 106-112 Link Here
106
     * @param arr the array of object
110
     * @param arr the array of object
107
     * @return enumeration of those objects
111
     * @return enumeration of those objects
108
     */
112
     */
109
    public static Enumeration array(Object[] arr) {
113
    public static <T> Enumeration<T> array(T... arr) {
110
        return Collections.enumeration(Arrays.asList(arr));
114
        return Collections.enumeration(Arrays.asList(arr));
111
    }
115
    }
112
116
Lines 115-122 Link Here
115
     * @param en enumeration that can contain nulls
119
     * @param en enumeration that can contain nulls
116
     * @return new enumeration without null values
120
     * @return new enumeration without null values
117
     */
121
     */
118
    public static Enumeration removeNulls(Enumeration en) {
122
    public static <T> Enumeration<T> removeNulls(Enumeration<T> en) {
119
        return filter(en, new RNulls());
123
        return filter(en, new RNulls<T>());
120
    }
124
    }
121
125
122
    /**
126
    /**
Lines 138-145 Link Here
138
     * @param processor a callback processor for the elements (its toAdd arguments is always null)
142
     * @param processor a callback processor for the elements (its toAdd arguments is always null)
139
     * @return new enumeration where all elements has been processed
143
     * @return new enumeration where all elements has been processed
140
     */
144
     */
141
    public static Enumeration convert(Enumeration en, Processor processor) {
145
    public static <T,R> Enumeration<R> convert(Enumeration<T> en, Processor<T,R> processor) {
142
        return new AltEn(en, processor);
146
        return new AltEn<T,R>(en, processor);
143
    }
147
    }
144
148
145
    /**
149
    /**
Lines 166-173 Link Here
166
     * @param filter a callback processor for the elements (its toAdd arguments is always null)
170
     * @param filter a callback processor for the elements (its toAdd arguments is always null)
167
     * @return new enumeration which does not include non-processed (returned null from processor) elements
171
     * @return new enumeration which does not include non-processed (returned null from processor) elements
168
     */
172
     */
169
    public static Enumeration filter(Enumeration en, Processor filter) {
173
    public static <T,R> Enumeration<R> filter(Enumeration<T> en, Processor<T,R> filter) {
170
        return new FilEn(en, filter);
174
        return new FilEn<T,R>(en, filter);
171
    }
175
    }
172
176
173
    /**
177
    /**
Lines 199-206 Link Here
199
     *       <code>null</code> if the filter returned <code>null</code> from its
203
     *       <code>null</code> if the filter returned <code>null</code> from its
200
     *       {@link Processor#process} method.
204
     *       {@link Processor#process} method.
201
     */
205
     */
202
    public static Enumeration queue(Enumeration en, Processor filter) {
206
    public static <T,R> Enumeration<R> queue(Enumeration<T> en, Processor<T,R> filter) {
203
        QEn q = new QEn(filter);
207
        QEn<T,R> q = new QEn<T,R>(filter);
204
208
205
        while (en.hasMoreElements()) {
209
        while (en.hasMoreElements()) {
206
            q.put(en.nextElement());
210
            q.put(en.nextElement());
Lines 213-238 Link Here
213
     * Processor interface that can filter out objects from the enumeration,
217
     * Processor interface that can filter out objects from the enumeration,
214
     * change them or add aditional objects to the end of the current enumeration.
218
     * change them or add aditional objects to the end of the current enumeration.
215
     */
219
     */
216
    public static interface Processor {
220
    public static interface Processor<T,R> {
217
        /** @param original the object that is going to be returned from the enumeration right now
221
        /** @param original the object that is going to be returned from the enumeration right now
218
         * @return a replacement for this object
222
         * @return a replacement for this object
219
         * @param toAdd can be non-null if one can add new objects at the end of the enumeration
223
         * @param toAdd can be non-null if one can add new objects at the end of the enumeration
220
         */
224
         */
221
        public Object process(Object original, Collection toAdd);
225
        public R process(T original, Collection<T> toAdd);
222
    }
226
    }
223
227
224
    /** Altering enumeration implementation */
228
    /** Altering enumeration implementation */
225
    private static final class AltEn extends Object implements Enumeration {
229
    private static final class AltEn<T,R> extends Object implements Enumeration<R> {
226
        /** enumeration to filter */
230
        /** enumeration to filter */
227
        private Enumeration en;
231
        private Enumeration<T> en;
228
232
229
        /** map to alter */
233
        /** map to alter */
230
        private Processor process;
234
        private Processor<T,R> process;
231
235
232
        /**
236
        /**
233
        * @param en enumeration to filter
237
        * @param en enumeration to filter
234
        */
238
        */
235
        public AltEn(Enumeration en, Processor process) {
239
        public AltEn(Enumeration<T> en, Processor<T,R> process) {
236
            this.en = en;
240
            this.en = en;
237
            this.process = process;
241
            this.process = process;
238
        }
242
        }
Lines 247-265 Link Here
247
        * @exception NoSuchElementException can be thrown if there is no next object
251
        * @exception NoSuchElementException can be thrown if there is no next object
248
        *   in the enumeration
252
        *   in the enumeration
249
        */
253
        */
250
        public Object nextElement() {
254
        public R nextElement() {
251
            return process.process(en.nextElement(), null);
255
            return process.process(en.nextElement(), null);
252
        }
256
        }
253
    }
257
    }
254
     // end of AltEn
258
     // end of AltEn
255
259
256
    /** Sequence of enumerations */
260
    /** Sequence of enumerations */
257
    private static final class SeqEn extends Object implements Enumeration {
261
    private static final class SeqEn<T> extends Object implements Enumeration<T> {
258
        /** enumeration of Enumerations */
262
        /** enumeration of Enumerations */
259
        private Enumeration en;
263
        private Enumeration<? extends Enumeration<? extends T>> en;
260
264
261
        /** current enumeration */
265
        /** current enumeration */
262
        private Enumeration current;
266
        private Enumeration<? extends T> current;
263
267
264
        /** is {@link #current} up-to-date and has more elements?
268
        /** is {@link #current} up-to-date and has more elements?
265
        * The combination <CODE>current == null</CODE> and
269
        * The combination <CODE>current == null</CODE> and
Lines 274-298 Link Here
274
        *
278
        *
275
        * @param en enumeration of Enumerations that should be sequenced
279
        * @param en enumeration of Enumerations that should be sequenced
276
        */
280
        */
277
        public SeqEn(Enumeration en) {
281
        public SeqEn(Enumeration<? extends Enumeration <? extends T>> en) {
278
            this.en = en;
282
            this.en = en;
279
        }
283
        }
280
284
281
        /** Composes two enumerations into one.
282
        * @param first first enumeration
283
        * @param second second enumeration
284
        */
285
        public SeqEn(Enumeration first, Enumeration second) {
286
            this(array(new Enumeration[] { first, second }));
287
        }
288
289
        /** Ensures that current enumeration is set. If there aren't more
285
        /** Ensures that current enumeration is set. If there aren't more
290
        * elements in the Enumerations, sets the field <CODE>current</CODE> to null.
286
        * elements in the Enumerations, sets the field <CODE>current</CODE> to null.
291
        */
287
        */
292
        private void ensureCurrent() {
288
        private void ensureCurrent() {
293
            while ((current == null) || !current.hasMoreElements()) {
289
            while ((current == null) || !current.hasMoreElements()) {
294
                if (en.hasMoreElements()) {
290
                if (en.hasMoreElements()) {
295
                    current = (Enumeration) en.nextElement();
291
                    current = en.nextElement();
296
                } else {
292
                } else {
297
                    // no next valid enumeration
293
                    // no next valid enumeration
298
                    current = null;
294
                    current = null;
Lines 315-321 Link Here
315
        /** @return next element
311
        /** @return next element
316
        * @exception NoSuchElementException if there is no next element
312
        * @exception NoSuchElementException if there is no next element
317
        */
313
        */
318
        public Object nextElement() {
314
        public T nextElement() {
319
            if (!checked) {
315
            if (!checked) {
320
                ensureCurrent();
316
                ensureCurrent();
321
            }
317
            }
Lines 334-372 Link Here
334
330
335
    /** QueueEnumeration
331
    /** QueueEnumeration
336
     */
332
     */
337
    private static class QEn extends Object implements Enumeration {
333
    private static class QEn<T,R> extends Object implements Enumeration<R> {
338
        /** next object to be returned */
334
        /** next object to be returned */
339
        private ListItem next = null;
335
        private ListItem<T> next = null;
340
336
341
        /** last object in the queue */
337
        /** last object in the queue */
342
        private ListItem last = null;
338
        private ListItem<T> last = null;
343
339
344
        /** processor to use */
340
        /** processor to use */
345
        private Processor processor;
341
        private Processor<T,R> processor;
346
342
347
        public QEn(Processor p) {
343
        public QEn(Processor<T,R> p) {
348
            this.processor = p;
344
            this.processor = p;
349
        }
345
        }
350
346
351
        /** Put adds new object to the end of queue.
347
        /** Put adds new object to the end of queue.
352
        * @param o the object to add
348
        * @param o the object to add
353
        */
349
        */
354
        public void put(Object o) {
350
        public void put(T o) {
355
            if (last != null) {
351
            if (last != null) {
356
                ListItem li = new ListItem(o);
352
                ListItem<T> li = new ListItem<T>(o);
357
                last.next = li;
353
                last.next = li;
358
                last = li;
354
                last = li;
359
            } else {
355
            } else {
360
                next = last = new ListItem(o);
356
                next = last = new ListItem<T>(o);
361
            }
357
            }
362
        }
358
        }
363
359
364
        /** Adds array of objects into the queue.
360
        /** Adds array of objects into the queue.
365
        * @param arr array of objects to put into the queue
361
        * @param arr array of objects to put into the queue
366
        */
362
        */
367
        public void put(Object[] arr) {
363
        public void put(Collection<? extends T> arr) {
368
            for (int i = 0; i < arr.length; i++) {
364
            for (T e : arr) {
369
                put(arr[i]);
365
                put(e);
370
            }
366
            }
371
        }
367
        }
372
368
Lines 380-391 Link Here
380
        /** @return next object in enumeration
376
        /** @return next object in enumeration
381
        * @exception NoSuchElementException if there is no next object
377
        * @exception NoSuchElementException if there is no next object
382
        */
378
        */
383
        public Object nextElement() {
379
        public R nextElement() {
384
            if (next == null) {
380
            if (next == null) {
385
                throw new NoSuchElementException();
381
                throw new NoSuchElementException();
386
            }
382
            }
387
383
388
            Object res = next.object;
384
            T res = next.object;
389
385
390
            if ((next = next.next) == null) {
386
            if ((next = next.next) == null) {
391
                last = null;
387
                last = null;
Lines 393-421 Link Here
393
389
394
            ;
390
            ;
395
391
396
            ToAdd toAdd = new ToAdd(this);
392
            ToAdd<T,R> toAdd = new ToAdd<T,R>(this);
397
            res = processor.process(res, toAdd);
393
            R out = processor.process(res, toAdd);
398
            toAdd.finish();
394
            toAdd.finish();
399
395
400
            return res;
396
            return out;
401
        }
397
        }
402
398
403
        /** item in linked list of Objects */
399
        /** item in linked list of Objects */
404
        private static final class ListItem {
400
        private static final class ListItem<T> {
405
            Object object;
401
            T object;
406
            ListItem next;
402
            ListItem<T> next;
407
403
408
            /** @param o the object for this item */
404
            /** @param o the object for this item */
409
            ListItem(Object o) {
405
            ListItem(T o) {
410
                object = o;
406
                object = o;
411
            }
407
            }
412
        }
408
        }
413
409
414
        /** Temporary collection that supports only add and addAll operations*/
410
        /** Temporary collection that supports only add and addAll operations*/
415
        private static final class ToAdd extends Object implements Collection {
411
        private static final class ToAdd<T,R> extends Object implements Collection<T> {
416
            private QEn q;
412
            private QEn<T,R> q;
417
413
418
            public ToAdd(QEn q) {
414
            public ToAdd(QEn<T,R> q) {
419
                this.q = q;
415
                this.q = q;
420
            }
416
            }
421
417
Lines 423-436 Link Here
423
                this.q = null;
419
                this.q = null;
424
            }
420
            }
425
421
426
            public boolean add(Object o) {
422
            public boolean add(T o) {
427
                q.put(o);
423
                q.put(o);
428
424
429
                return true;
425
                return true;
430
            }
426
            }
431
427
432
            public boolean addAll(Collection c) {
428
            public boolean addAll(Collection<? extends T> c) {
433
                q.put(c.toArray());
429
                q.put(c);
434
430
435
                return true;
431
                return true;
436
            }
432
            }
Lines 455-461 Link Here
455
                throw new UnsupportedOperationException(msg());
451
                throw new UnsupportedOperationException(msg());
456
            }
452
            }
457
453
458
            public Iterator iterator() {
454
            public Iterator<T> iterator() {
459
                throw new UnsupportedOperationException(msg());
455
                throw new UnsupportedOperationException(msg());
460
            }
456
            }
461
457
Lines 479-485 Link Here
479
                throw new UnsupportedOperationException(msg());
475
                throw new UnsupportedOperationException(msg());
480
            }
476
            }
481
477
482
            public Object[] toArray(Object[] a) {
478
            public<X> X[] toArray(X[] a) {
483
                throw new UnsupportedOperationException(msg());
479
                throw new UnsupportedOperationException(msg());
484
            }
480
            }
485
        }
481
        }
Lines 488-511 Link Here
488
     // end of QEn
484
     // end of QEn
489
485
490
    /** Filtering enumeration */
486
    /** Filtering enumeration */
491
    private static final class FilEn extends Object implements Enumeration {
487
    private static final class FilEn<T,R> extends Object implements Enumeration<R> {
492
        /** marker object stating there is no nexte element prepared */
488
        /** marker object stating there is no nexte element prepared */
493
        private static final Object EMPTY = new Object();
489
        private static final Object EMPTY = new Object();
494
490
495
        /** enumeration to filter */
491
        /** enumeration to filter */
496
        private Enumeration en;
492
        private Enumeration<T> en;
497
493
498
        /** element to be returned next time or {@link #EMPTY} if there is
494
        /** element to be returned next time or {@link #EMPTY} if there is
499
        * no such element prepared */
495
        * no such element prepared */
500
        private Object next = EMPTY;
496
        private R next = empty();
501
497
502
        /** the set to use as filter */
498
        /** the set to use as filter */
503
        private Processor filter;
499
        private Processor<T,R> filter;
504
500
505
        /**
501
        /**
506
        * @param en enumeration to filter
502
        * @param en enumeration to filter
507
        */
503
        */
508
        public FilEn(Enumeration en, Processor filter) {
504
        public FilEn(Enumeration<T> en, Processor<T,R> filter) {
509
            this.en = en;
505
            this.en = en;
510
            this.filter = filter;
506
            this.filter = filter;
511
        }
507
        }
Lines 513-519 Link Here
513
        /** @return true if there is more elements in the enumeration
509
        /** @return true if there is more elements in the enumeration
514
        */
510
        */
515
        public boolean hasMoreElements() {
511
        public boolean hasMoreElements() {
516
            if (next != EMPTY) {
512
            if (next != empty()) {
517
                // there is a object already prepared
513
                // there is a object already prepared
518
                return true;
514
                return true;
519
            }
515
            }
Lines 530-536 Link Here
530
                ;
526
                ;
531
            }
527
            }
532
528
533
            next = EMPTY;
529
            next = empty();
534
530
535
            return false;
531
            return false;
536
        }
532
        }
Lines 539-560 Link Here
539
        * @exception NoSuchElementException can be thrown if there is no next object
535
        * @exception NoSuchElementException can be thrown if there is no next object
540
        *   in the enumeration
536
        *   in the enumeration
541
        */
537
        */
542
        public Object nextElement() {
538
        public R nextElement() {
543
            if ((next == EMPTY) && !hasMoreElements()) {
539
            if ((next == EMPTY) && !hasMoreElements()) {
544
                throw new NoSuchElementException();
540
                throw new NoSuchElementException();
545
            }
541
            }
546
542
547
            Object res = next;
543
            R res = next;
548
            next = EMPTY;
544
            next = empty();
549
545
550
            return res;
546
            return res;
551
        }
547
        }
548
549
        @SuppressWarnings("unchecked")
550
        private R empty() {
551
            return (R)EMPTY;
552
        }
552
    }
553
    }
553
     // end of FilEn
554
     // end of FilEn
554
555
555
    /** Returns true from contains if object is not null */
556
    /** Returns true from contains if object is not null */
556
    private static class RNulls implements Processor {
557
    private static class RNulls<T> implements Processor<T,T> {
557
        public Object process(Object original, Collection toAdd) {
558
        public T process(T original, Collection<T> toAdd) {
558
            return original;
559
            return original;
559
        }
560
        }
560
    }
561
    }
(-)openide/util/src/org/openide/util/IconManager.java (-7 / +7 lines)
Lines 35-49 Link Here
35
    private static final Object NO_ICON = new Object();
35
    private static final Object NO_ICON = new Object();
36
36
37
    /** map of resource name to loaded icon (String, SoftRefrence (Image)) or (String, NO_ICON) */
37
    /** map of resource name to loaded icon (String, SoftRefrence (Image)) or (String, NO_ICON) */
38
    private static final HashMap map = new HashMap(128);
38
    private static final HashMap<Object,Object> map = new HashMap<Object,Object>(128);
39
    private static final HashMap localizedMap = new HashMap(128);
39
    private static final HashMap<String,Object> localizedMap = new HashMap<String,Object>(128);
40
40
41
    /** Resource paths for which we have had to strip initial slash.
41
    /** Resource paths for which we have had to strip initial slash.
42
     * @see "#20072"
42
     * @see "#20072"
43
     */
43
     */
44
    private static final Set extraInitialSlashes = new HashSet(); // Set<String>
44
    private static final Set<String> extraInitialSlashes = new HashSet<String>(); // Set<String>
45
    private static volatile Object currentLoader;
45
    private static volatile Object currentLoader;
46
    private static Lookup.Result loaderQuery = null;
46
    private static Lookup.Result<ClassLoader> loaderQuery = null;
47
    private static boolean noLoaderWarned = false;
47
    private static boolean noLoaderWarned = false;
48
    private static final Component component = new Component() {
48
    private static final Component component = new Component() {
49
        };
49
        };
Lines 67-73 Link Here
67
        currentLoader = Thread.currentThread();
67
        currentLoader = Thread.currentThread();
68
            
68
            
69
        if (loaderQuery == null) {
69
        if (loaderQuery == null) {
70
            loaderQuery = Lookup.getDefault().lookup(new Lookup.Template(ClassLoader.class));
70
            loaderQuery = Lookup.getDefault().lookup(new Lookup.Template<ClassLoader>(ClassLoader.class));
71
            loaderQuery.addLookupListener(
71
            loaderQuery.addLookupListener(
72
                new LookupListener() {
72
                new LookupListener() {
73
                    public void resultChanged(LookupEvent ev) {
73
                    public void resultChanged(LookupEvent ev) {
Lines 424-434 Link Here
424
    }
424
    }
425
425
426
    /** Cleaning reference. */
426
    /** Cleaning reference. */
427
    private static final class ActiveRef extends SoftReference implements Runnable {
427
    private static final class ActiveRef extends SoftReference<Image> implements Runnable {
428
        private Map holder;
428
        private Map holder;
429
        private Object key;
429
        private Object key;
430
430
431
        public ActiveRef(Object o, Map holder, Object key) {
431
        public ActiveRef(Image o, Map holder, Object key) {
432
            super(o, Utilities.activeReferenceQueue());
432
            super(o, Utilities.activeReferenceQueue());
433
            this.holder = holder;
433
            this.holder = holder;
434
            this.key = key;
434
            this.key = key;
(-)openide/util/src/org/openide/util/Lookup.java (-26 / +31 lines)
Lines 134-140 Link Here
134
     * @return an object implementing the given class or <code>null</code> if no such
134
     * @return an object implementing the given class or <code>null</code> if no such
135
     *         implementation is found
135
     *         implementation is found
136
     */
136
     */
137
    public abstract Object lookup(Class clazz);
137
    public abstract <T> T lookup(Class<T> clazz);
138
138
139
    /** The general lookup method. Callers can get list of all instances and classes
139
    /** The general lookup method. Callers can get list of all instances and classes
140
     * that match the given <code>template</code>, request more info about
140
     * that match the given <code>template</code>, request more info about
Lines 147-153 Link Here
147
     * @param template a template describing the services to look for
147
     * @param template a template describing the services to look for
148
     * @return an object containing the results
148
     * @return an object containing the results
149
     */
149
     */
150
    public abstract Result lookup(Template template);
150
    public abstract <T> Result<T> lookup(Template<T> template);
151
151
152
    /** Look up the first item matching a given template.
152
    /** Look up the first item matching a given template.
153
     * Includes not only the instance but other associated information.
153
     * Includes not only the instance but other associated information.
Lines 156-166 Link Here
156
     *
156
     *
157
     * @since 1.8
157
     * @since 1.8
158
     */
158
     */
159
    public Item lookupItem(Template template) {
159
    public <T> Item<T> lookupItem(Template<T> template) {
160
        Result res = lookup(template);
160
        Result<T> res = lookup(template);
161
        Iterator it = res.allItems().iterator();
161
        Iterator<? extends Item<T>> it = res.allItems().iterator();
162
162
        return it.hasNext() ? it.next() : null;
163
        return it.hasNext() ? (Item) it.next() : null;
164
    }
163
    }
165
164
166
    /**
165
    /**
Lines 183-200 Link Here
183
182
184
    /** Template defining a pattern to filter instances by.
183
    /** Template defining a pattern to filter instances by.
185
     */
184
     */
186
    public static final class Template extends Object {
185
    public static final class Template<T> extends Object {
187
        /** cached hash code */
186
        /** cached hash code */
188
        private int hashCode;
187
        private int hashCode;
189
188
190
        /** type of the service */
189
        /** type of the service */
191
        private Class type;
190
        private Class<T> type;
192
191
193
        /** identity to search for */
192
        /** identity to search for */
194
        private String id;
193
        private String id;
195
194
196
        /** instance to search for */
195
        /** instance to search for */
197
        private Object instance;
196
        private T instance;
198
197
199
        /** General template to find all possible instances.
198
        /** General template to find all possible instances.
200
         * @deprecated Use <code>new Template (Object.class)</code> which
199
         * @deprecated Use <code>new Template (Object.class)</code> which
Lines 208-214 Link Here
208
        /** Create a simple template matching by class.
207
        /** Create a simple template matching by class.
209
         * @param type the class of service we are looking for (subclasses will match)
208
         * @param type the class of service we are looking for (subclasses will match)
210
         */
209
         */
211
        public Template(Class type) {
210
        public Template(Class<T> type) {
212
            this(type, null, null);
211
            this(type, null, null);
213
        }
212
        }
214
213
Lines 217-234 Link Here
217
         * @param id the ID of the item/service we are looking for or <code>null</code> to leave unspecified
216
         * @param id the ID of the item/service we are looking for or <code>null</code> to leave unspecified
218
         * @param instance a specific known instance to look for or <code>null</code> to leave unspecified
217
         * @param instance a specific known instance to look for or <code>null</code> to leave unspecified
219
         */
218
         */
220
        public Template(Class type, String id, Object instance) {
219
        public Template(Class<T> type, String id, T instance) {
221
            this.type = (type == null) ? Object.class : type;
220
            this.type = extractType(type);
222
            this.id = id;
221
            this.id = id;
223
            this.instance = instance;
222
            this.instance = instance;
224
        }
223
        }
225
224
225
        @SuppressWarnings("unchecked")
226
        private Class<T> extractType(Class<T> type) {
227
            return (type == null) ? (Class<T>)Object.class : type;
228
        }
229
226
        /** Get the class (or superclass or interface) to search for.
230
        /** Get the class (or superclass or interface) to search for.
227
         * If it was not specified in the constructor, <code>Object</code> is used as
231
         * If it was not specified in the constructor, <code>Object</code> is used as
228
         * this will match any instance.
232
         * this will match any instance.
229
         * @return the class to search for
233
         * @return the class to search for
230
         */
234
         */
231
        public Class getType() {
235
        public Class<T> getType() {
232
            return type;
236
            return type;
233
        }
237
        }
234
238
Lines 250-256 Link Here
250
         *
254
         *
251
         * @since 1.8
255
         * @since 1.8
252
         */
256
         */
253
        public Object getInstance() {
257
        public T getInstance() {
254
            return instance;
258
            return instance;
255
        }
259
        }
256
260
Lines 317-323 Link Here
317
     * Also permits listening to changes in the result.
321
     * Also permits listening to changes in the result.
318
     * Result can contain duplicate items.
322
     * Result can contain duplicate items.
319
     */
323
     */
320
    public static abstract class Result extends Object {
324
    public static abstract class Result<T> extends Object {
321
        /** Registers a listener that is invoked when there is a possible
325
        /** Registers a listener that is invoked when there is a possible
322
         * change in this result.
326
         * change in this result.
323
         *
327
         *
Lines 334-340 Link Here
334
         * should be List instead of Collection, but it is too late to change it.
338
         * should be List instead of Collection, but it is too late to change it.
335
         * @return unmodifiable collection of all instances that will never change its content
339
         * @return unmodifiable collection of all instances that will never change its content
336
         */
340
         */
337
        public abstract java.util.Collection allInstances();
341
        public abstract java.util.Collection<? extends T> allInstances();
338
342
339
        /** Get all classes represented in the result.
343
        /** Get all classes represented in the result.
340
         * That is, the set of concrete classes
344
         * That is, the set of concrete classes
Lines 344-351 Link Here
344
         *
348
         *
345
         * @since 1.8
349
         * @since 1.8
346
         */
350
         */
347
        public java.util.Set allClasses() {
351
        public java.util.Set<Class<? extends T>> allClasses() {
348
            return java.util.Collections.EMPTY_SET;
352
            return java.util.Collections.emptySet();
349
        }
353
        }
350
354
351
        /** Get all registered items.
355
        /** Get all registered items.
Lines 356-363 Link Here
356
         *
360
         *
357
         * @since 1.8
361
         * @since 1.8
358
         */
362
         */
359
        public java.util.Collection allItems() {
363
        public java.util.Collection<? extends Item<T>> allItems() {
360
            return java.util.Collections.EMPTY_SET;
364
            return java.util.Collections.emptyList();
361
        }
365
        }
362
    }
366
    }
363
367
Lines 367-382 Link Here
367
     *
371
     *
368
     * @since 1.25
372
     * @since 1.25
369
     */
373
     */
370
    public static abstract class Item extends Object {
374
    public static abstract class Item<T> extends Object {
371
        /** Get the instance itself.
375
        /** Get the instance itself.
372
         * @return the instance or null if the instance cannot be created
376
         * @return the instance or null if the instance cannot be created
373
         */
377
         */
374
        public abstract Object getInstance();
378
        public abstract T getInstance();
375
379
376
        /** Get the implementing class of the instance.
380
        /** Get the implementing class of the instance.
377
         * @return the class of the item
381
         * @return the class of the item
378
         */
382
         */
379
        public abstract Class getType();
383
        public abstract Class<? extends T> getType();
380
384
381
        // XXX can it be null??
385
        // XXX can it be null??
382
386
Lines 425-435 Link Here
425
        Empty() {
429
        Empty() {
426
        }
430
        }
427
431
428
        public Object lookup(Class clazz) {
432
        public <T> T lookup(Class<T> clazz) {
429
            return null;
433
            return null;
430
        }
434
        }
431
435
432
        public Result lookup(Template template) {
436
        @SuppressWarnings("unchecked")
437
        public <T> Result<T> lookup(Template<T> template) {
433
            return NO_RESULT;
438
            return NO_RESULT;
434
        }
439
        }
435
    }
440
    }
(-)openide/util/src/org/openide/util/Mutex.java (-7 / +8 lines)
Lines 138-144 Link Here
138
    private /*final*/ Object LOCK;
138
    private /*final*/ Object LOCK;
139
139
140
    /** threads that - owns or waits for this mutex */
140
    /** threads that - owns or waits for this mutex */
141
    private /*final*/ Map registeredThreads;
141
    private /*final*/ Map<Thread,ThreadInfo> registeredThreads;
142
142
143
    /** number of threads that holds S mode (readersNo == "count of threads in registeredThreads that holds S") */
143
    /** number of threads that holds S mode (readersNo == "count of threads in registeredThreads that holds S") */
144
144
Lines 146-152 Link Here
146
    private int readersNo = 0;
146
    private int readersNo = 0;
147
147
148
    /** a queue of waiting threads for this mutex */
148
    /** a queue of waiting threads for this mutex */
149
    private List waiters;
149
    private List<QueueCell> waiters;
150
150
151
    /** Enhanced constructor that permits specifying an object to use as a lock.
151
    /** Enhanced constructor that permits specifying an object to use as a lock.
152
    * The lock is used on entry and exit to {@link #readAccess} and during the
152
    * The lock is used on entry and exit to {@link #readAccess} and during the
Lines 190-197 Link Here
190
    /** Initiates this Mutex */
190
    /** Initiates this Mutex */
191
    private void init(Object lock) {
191
    private void init(Object lock) {
192
        this.LOCK = lock;
192
        this.LOCK = lock;
193
        this.registeredThreads = new HashMap(7);
193
        this.registeredThreads = new HashMap<Thread,ThreadInfo>(7);
194
        this.waiters = new LinkedList();
194
        this.waiters = new LinkedList<QueueCell>();
195
    }
195
    }
196
196
197
    /** Run an action only with read access.
197
    /** Run an action only with read access.
Lines 1307-1313 Link Here
1307
        /** queue of runnable rquests that are to be executed (in X mode) right after S mode is left
1307
        /** queue of runnable rquests that are to be executed (in X mode) right after S mode is left
1308
        * deadlock avoidance technique
1308
        * deadlock avoidance technique
1309
        */
1309
        */
1310
        List[] queues;
1310
        List<Runnable>[] queues;
1311
1311
1312
        /** value of counts[S] when the mode was upgraded
1312
        /** value of counts[S] when the mode was upgraded
1313
        * rsnapshot works as follows:
1313
        * rsnapshot works as follows:
Lines 1323-1333 Link Here
1323
        */
1323
        */
1324
        int rsnapshot;
1324
        int rsnapshot;
1325
1325
1326
        @SuppressWarnings("unchecked")
1326
        public ThreadInfo(Thread t, int mode) {
1327
        public ThreadInfo(Thread t, int mode) {
1327
            this.t = t;
1328
            this.t = t;
1328
            this.mode = mode;
1329
            this.mode = mode;
1329
            this.counts = new int[MODE_COUNT];
1330
            this.counts = new int[MODE_COUNT];
1330
            this.queues = new List[MODE_COUNT];
1331
            this.queues = (List<Runnable>[])new List[MODE_COUNT];
1331
            counts[mode] = 1;
1332
            counts[mode] = 1;
1332
        }
1333
        }
1333
1334
Lines 1338-1344 Link Here
1338
        /** Adds the Runnable into the queue of waiting requests */
1339
        /** Adds the Runnable into the queue of waiting requests */
1339
        public void enqueue(int mode, Runnable run) {
1340
        public void enqueue(int mode, Runnable run) {
1340
            if (queues[mode] == null) {
1341
            if (queues[mode] == null) {
1341
                queues[mode] = new ArrayList(13);
1342
                queues[mode] = new ArrayList<Runnable>(13);
1342
            }
1343
            }
1343
1344
1344
            queues[mode].add(run);
1345
            queues[mode].add(run);
(-)openide/util/src/org/openide/util/NbBundle.java (-24 / +32 lines)
Lines 62-73 Link Here
62
     * Keeps only weak references to the class loaders.
62
     * Keeps only weak references to the class loaders.
63
     * @see "#9275"
63
     * @see "#9275"
64
     */
64
     */
65
    private static final Map localizedFileCache = new WeakHashMap(); // Map<ClassLoader,Map<String,URL>>
65
    private static final Map<ClassLoader,Map<String,URL>> localizedFileCache = new WeakHashMap<ClassLoader,Map<String,URL>>();
66
66
67
    /**
67
    /**
68
     * Cache of resource bundles.
68
     * Cache of resource bundles.
69
     */
69
     */
70
    private static final Map bundleCache = new WeakHashMap(); // Map<ClassLoader,Map<String,Reference<ResourceBundle>>>
70
    private static final Map<ClassLoader,Map<String,Reference<ResourceBundle>>> bundleCache = new WeakHashMap<ClassLoader,Map<String,Reference<ResourceBundle>>>();
71
71
72
    /**
72
    /**
73
     * Do not call.
73
     * Do not call.
Lines 154-167 Link Here
154
        // [PENDING] in the future, could maybe do something neat if
154
        // [PENDING] in the future, could maybe do something neat if
155
        // USE_DEBUG_LOADER and ext is "html" or "txt" etc...
155
        // USE_DEBUG_LOADER and ext is "html" or "txt" etc...
156
        URL lookup = null;
156
        URL lookup = null;
157
        Iterator it = new LocaleIterator(locale);
157
        Iterator<String> it = new LocaleIterator(locale);
158
        String cachePrefix = "[" + Integer.toString(loader.hashCode()) + "]"; // NOI18N
158
        String cachePrefix = "[" + Integer.toString(loader.hashCode()) + "]"; // NOI18N
159
        List cacheCandidates = new ArrayList(10); // List<String>
159
        List<String> cacheCandidates = new ArrayList<String>(10);
160
        String baseNameSlashes = baseName.replace('.', '/');
160
        String baseNameSlashes = baseName.replace('.', '/');
161
        Map perLoaderCache = (Map) localizedFileCache.get(loader);
161
        Map<String,URL> perLoaderCache = localizedFileCache.get(loader);
162
162
163
        if (perLoaderCache == null) {
163
        if (perLoaderCache == null) {
164
            localizedFileCache.put(loader, perLoaderCache = new HashMap());
164
            localizedFileCache.put(loader, perLoaderCache = new HashMap<String,URL>());
165
        }
165
        }
166
166
167
        // #31008: better use of domain cache priming.
167
        // #31008: better use of domain cache priming.
Lines 441-453 Link Here
441
     * @return a resource bundle (locale- and branding-merged), or null if not found
441
     * @return a resource bundle (locale- and branding-merged), or null if not found
442
     */
442
     */
443
    private static ResourceBundle getBundleFast(String name, Locale locale, ClassLoader loader) {
443
    private static ResourceBundle getBundleFast(String name, Locale locale, ClassLoader loader) {
444
        Map m;
444
        Map<String,Reference<ResourceBundle>> m;
445
445
446
        synchronized (bundleCache) {
446
        synchronized (bundleCache) {
447
            m = (Map) bundleCache.get(loader); // Map<String,Reference<ResourceBundle>>
447
            m = bundleCache.get(loader); 
448
448
449
            if (m == null) {
449
            if (m == null) {
450
                bundleCache.put(loader, m = new HashMap());
450
                bundleCache.put(loader, m = new HashMap<String,Reference<ResourceBundle>>());
451
            }
451
            }
452
        }
452
        }
453
453
Lines 480-487 Link Here
480
        String key = name + '/' + (brandingToken != null ? brandingToken : "-") + '/' + locale; // NOI18N
480
        String key = name + '/' + (brandingToken != null ? brandingToken : "-") + '/' + locale; // NOI18N
481
         */
481
         */
482
        synchronized (m) {
482
        synchronized (m) {
483
            Object o = m.get(key);
483
            Reference<ResourceBundle> o = m.get(key);
484
            ResourceBundle b = (o != null) ? (ResourceBundle) ((Reference) o).get() : null;
484
            ResourceBundle b = o != null ? o.get() : null;
485
485
486
            if (b != null) {
486
            if (b != null) {
487
                return b;
487
                return b;
Lines 489-495 Link Here
489
                b = loadBundle(name, locale, loader);
489
                b = loadBundle(name, locale, loader);
490
490
491
                if (b != null) {
491
                if (b != null) {
492
                    m.put(key, new TimedSoftReference(b, m, key));
492
                    m.put(key, new TimedSoftReference<ResourceBundle>(b, m, key));
493
                } else {
493
                } else {
494
                    // Used to cache misses as well, to make the negative test faster.
494
                    // Used to cache misses as well, to make the negative test faster.
495
                    // However this caused problems: see #31578.
495
                    // However this caused problems: see #31578.
Lines 509-516 Link Here
509
     */
509
     */
510
    private static ResourceBundle loadBundle(String name, Locale locale, ClassLoader loader) {
510
    private static ResourceBundle loadBundle(String name, Locale locale, ClassLoader loader) {
511
        String sname = name.replace('.', '/');
511
        String sname = name.replace('.', '/');
512
        Iterator it = new LocaleIterator(locale);
512
        Iterator<String> it = new LocaleIterator(locale);
513
        LinkedList l = new LinkedList();
513
        LinkedList<String> l = new LinkedList<String>();
514
514
515
        while (it.hasNext()) {
515
        while (it.hasNext()) {
516
            l.addFirst(it.next());
516
            l.addFirst(it.next());
Lines 555-561 Link Here
555
            first = false;
555
            first = false;
556
        }
556
        }
557
557
558
        return new PBundle(p, locale);
558
        return new PBundle(propsToStringMap(p), locale);
559
    }
560
561
    /** Just converts the Properties to Map<String,String> assuming the
562
     * content is correct.
563
     */
564
    @SuppressWarnings("unchecked")
565
    private static Map<String,String> propsToStringMap(Properties p) {
566
        return (Map<String,String>)p;
559
    }
567
    }
560
568
561
    /**
569
    /**
Lines 769-775 Link Here
769
     * A resource bundle based on <samp>.properties</samp> files (or any map).
777
     * A resource bundle based on <samp>.properties</samp> files (or any map).
770
     */
778
     */
771
    private static final class PBundle extends ResourceBundle {
779
    private static final class PBundle extends ResourceBundle {
772
        private final Map m; // Map<String,String>
780
        private final Map<String,String> m;
773
        private final Locale locale;
781
        private final Locale locale;
774
782
775
        /**
783
        /**
Lines 777-788 Link Here
777
         * @param m a map from resources keys to values (typically both strings)
785
         * @param m a map from resources keys to values (typically both strings)
778
         * @param locale the locale it represents <em>(informational)</em>
786
         * @param locale the locale it represents <em>(informational)</em>
779
         */
787
         */
780
        public PBundle(Map m, Locale locale) {
788
        public PBundle(Map<String,String> m, Locale locale) {
781
            this.m = m;
789
            this.m = m;
782
            this.locale = locale;
790
            this.locale = locale;
783
        }
791
        }
784
792
785
        public Enumeration getKeys() {
793
        public Enumeration<String> getKeys() {
786
            return Collections.enumeration(m.keySet());
794
            return Collections.enumeration(m.keySet());
787
        }
795
        }
788
796
Lines 819-825 Link Here
819
            return loc;
827
            return loc;
820
        }
828
        }
821
829
822
        public Enumeration getKeys() {
830
        public Enumeration<String> getKeys() {
823
            return Enumerations.removeDuplicates(Enumerations.concat(sub1.getKeys(), sub2.getKeys()));
831
            return Enumerations.removeDuplicates(Enumerations.concat(sub1.getKeys(), sub2.getKeys()));
824
        }
832
        }
825
833
Lines 853-859 Link Here
853
    * Branding tokens with underscores are broken apart naturally: so e.g.
861
    * Branding tokens with underscores are broken apart naturally: so e.g.
854
    * branding "f4j_ce" looks first for "f4j_ce" branding, then "f4j" branding, then none.
862
    * branding "f4j_ce" looks first for "f4j_ce" branding, then "f4j" branding, then none.
855
    */
863
    */
856
    private static class LocaleIterator extends Object implements Iterator {
864
    private static class LocaleIterator extends Object implements Iterator<String> {
857
        /** this flag means, if default locale is in progress */
865
        /** this flag means, if default locale is in progress */
858
        private boolean defaultInProgress = false;
866
        private boolean defaultInProgress = false;
859
867
Lines 896-902 Link Here
896
        /** @return next sufix.
904
        /** @return next sufix.
897
        * @exception NoSuchElementException if there is no more locale sufix.
905
        * @exception NoSuchElementException if there is no more locale sufix.
898
        */
906
        */
899
        public Object next() throws NoSuchElementException {
907
        public String next() throws NoSuchElementException {
900
            if (current == null) {
908
            if (current == null) {
901
                throw new NoSuchElementException();
909
                throw new NoSuchElementException();
902
            }
910
            }
Lines 981-990 Link Here
981
        /** indices of known bundles; needed since DebugLoader's can be collected
989
        /** indices of known bundles; needed since DebugLoader's can be collected
982
         * when softly reachable, but this should be transparent to the user
990
         * when softly reachable, but this should be transparent to the user
983
         */
991
         */
984
        private static final Map knownIDs = new HashMap(); // Map<String,int>
992
        private static final Map<String,Integer> knownIDs = new HashMap<String,Integer>();
985
993
986
        /** cache of existing debug loaders for regular loaders */
994
        /** cache of existing debug loaders for regular loaders */
987
        private static final Map existing = new WeakHashMap(); // Map<ClassLoader,Reference<DebugLoader>>
995
        private static final Map<ClassLoader,Reference<ClassLoader>> existing = new WeakHashMap<ClassLoader,Reference<ClassLoader>>();
988
996
989
        private DebugLoader(ClassLoader cl) {
997
        private DebugLoader(ClassLoader cl) {
990
            super(cl);
998
            super(cl);
Lines 1025-1031 Link Here
1025
                }
1033
                }
1026
1034
1027
                ClassLoader dl = new DebugLoader(normal);
1035
                ClassLoader dl = new DebugLoader(normal);
1028
                existing.put(normal, new WeakReference(dl));
1036
                existing.put(normal, new WeakReference<ClassLoader>(dl));
1029
1037
1030
                return dl;
1038
                return dl;
1031
            }
1039
            }
(-)openide/util/src/org/openide/util/Queue.java (-1 / +1 lines)
Lines 21-27 Link Here
21
*/
21
*/
22
public class Queue extends Object {
22
public class Queue extends Object {
23
    /** Queue enumeration */
23
    /** Queue enumeration */
24
    private java.util.LinkedList queue = new java.util.LinkedList();
24
    private java.util.LinkedList<Object> queue = new java.util.LinkedList<Object>();
25
25
26
    /** Adds new item.
26
    /** Adds new item.
27
    * @param o object to add
27
    * @param o object to add
(-)openide/util/src/org/openide/util/RE13.java (-7 / +13 lines)
Lines 116-122 Link Here
116
116
117
    /** Data structure to needed to store the */
117
    /** Data structure to needed to store the */
118
    public void init(String[] original, String[] newversion) {
118
    public void init(String[] original, String[] newversion) {
119
        ArrayList root = new ArrayList();
119
        ArrayList<Object> root = new ArrayList<Object>();
120
120
121
        for (int i = 0; i < original.length; i++) {
121
        for (int i = 0; i < original.length; i++) {
122
            placeString(root, original[i], i);
122
            placeString(root, original[i], i);
Lines 131-137 Link Here
131
     * @param s string to place there
131
     * @param s string to place there
132
     * @param indx index to put at the end node
132
     * @param indx index to put at the end node
133
     */
133
     */
134
    private static void placeString(List item, String s, int indx) {
134
    private static void placeString(List<Object> item, String s, int indx) {
135
        if (s.length() == 0) {
135
        if (s.length() == 0) {
136
            item.add(new Integer(indx));
136
            item.add(new Integer(indx));
137
137
Lines 140-146 Link Here
140
140
141
        char f = s.charAt(0);
141
        char f = s.charAt(0);
142
142
143
        ListIterator it = item.listIterator();
143
        ListIterator<Object> it = item.listIterator();
144
144
145
        while (it.hasNext()) {
145
        while (it.hasNext()) {
146
            Object o = it.next();
146
            Object o = it.next();
Lines 159-165 Link Here
159
                            // next is the list or null
159
                            // next is the list or null
160
                            List listForPref = (List) it.next();
160
                            List listForPref = (List) it.next();
161
161
162
                            ArrayList switchList = new ArrayList();
162
                            ArrayList<Object> switchList = new ArrayList<Object>();
163
                            it.set(switchList);
163
                            it.set(switchList);
164
164
165
                            switchList.add(pref.substring(i));
165
                            switchList.add(pref.substring(i));
Lines 168-174 Link Here
168
                            if (i >= s.length()) {
168
                            if (i >= s.length()) {
169
                                switchList.add(new Integer(indx));
169
                                switchList.add(new Integer(indx));
170
                            } else {
170
                            } else {
171
                                ArrayList terminalList = new ArrayList();
171
                                ArrayList<Object> terminalList = new ArrayList<Object>();
172
                                terminalList.add(new Integer(indx));
172
                                terminalList.add(new Integer(indx));
173
173
174
                                switchList.add(s.substring(i));
174
                                switchList.add(s.substring(i));
Lines 182-188 Link Here
182
                    //
182
                    //
183
                    // the new string is longer than the existing recursive add
183
                    // the new string is longer than the existing recursive add
184
                    //
184
                    //
185
                    List switchList = (List) it.next();
185
                    List<Object> switchList = nextList(it);
186
                    placeString(switchList, s.substring(pref.length()), indx);
186
                    placeString(switchList, s.substring(pref.length()), indx);
187
187
188
                    return;
188
                    return;
Lines 193-203 Link Here
193
        //
193
        //
194
        // ok new prefix in this item
194
        // ok new prefix in this item
195
        //
195
        //
196
        ArrayList id = new ArrayList();
196
        ArrayList<Object> id = new ArrayList<Object>();
197
        id.add(new Integer(indx));
197
        id.add(new Integer(indx));
198
198
199
        item.add(s);
199
        item.add(s);
200
        item.add(id);
200
        item.add(id);
201
    }
202
203
    @SuppressWarnings("unchecked")
204
    private static List<Object> nextList(final ListIterator<Object> it) {
205
        List<Object> switchList = (List<Object>) it.next();
206
        return switchList;
201
    }
207
    }
202
208
203
    /** Compress tree of Lists into tree of Objects.
209
    /** Compress tree of Lists into tree of Objects.
(-)openide/util/src/org/openide/util/RequestProcessor.java (-7 / +7 lines)
Lines 119-130 Link Here
119
    private Object processorLock = new Object();
119
    private Object processorLock = new Object();
120
120
121
    /** The set holding all the Processors assigned to this RequestProcessor */
121
    /** The set holding all the Processors assigned to this RequestProcessor */
122
    private HashSet processors = new HashSet();
122
    private HashSet<Processor> processors = new HashSet<Processor>();
123
123
124
    /** Actualy the first item is pending to be processed.
124
    /** Actualy the first item is pending to be processed.
125
     * Can be accessed/trusted only under the above processorLock lock.
125
     * Can be accessed/trusted only under the above processorLock lock.
126
     * If null, nothing is scheduled and the processor is not running. */
126
     * If null, nothing is scheduled and the processor is not running. */
127
    private List queue = new LinkedList();
127
    private List<Item> queue = new LinkedList<Item>();
128
128
129
    /** Number of currently running processors. If there is a new request
129
    /** Number of currently running processors. If there is a new request
130
     * and this number is lower that the throughput, new Processor is asked
130
     * and this number is lower that the throughput, new Processor is asked
Lines 442-448 Link Here
442
            queue.add(item);
442
            queue.add(item);
443
            item.enqueued = true;
443
            item.enqueued = true;
444
        } else {
444
        } else {
445
            for (ListIterator it = queue.listIterator(); it.hasNext();) {
445
            for (ListIterator<Item> it = queue.listIterator(); it.hasNext();) {
446
                Item next = (Item) it.next();
446
                Item next = (Item) it.next();
447
447
448
                if (iprio > next.getPriority()) {
448
                if (iprio > next.getPriority()) {
Lines 805-811 Link Here
805
     */
805
     */
806
    private static class Processor extends Thread {
806
    private static class Processor extends Thread {
807
        /** A stack containing all the inactive Processors */
807
        /** A stack containing all the inactive Processors */
808
        private static Stack pool = new Stack();
808
        private static Stack<Processor> pool = new Stack<Processor>();
809
809
810
        /* One minute of inactivity and the Thread will die if not assigned */
810
        /* One minute of inactivity and the Thread will die if not assigned */
811
        private static final int INACTIVE_TIMEOUT = 60000;
811
        private static final int INACTIVE_TIMEOUT = 60000;
Lines 1033-1040 Link Here
1033
         * end of the task.
1033
         * end of the task.
1034
         */
1034
         */
1035
        static ThreadGroup getTopLevelThreadGroup() {
1035
        static ThreadGroup getTopLevelThreadGroup() {
1036
            java.security.PrivilegedAction run = new java.security.PrivilegedAction() {
1036
            java.security.PrivilegedAction<ThreadGroup> run = new java.security.PrivilegedAction<ThreadGroup>() {
1037
                    public Object run() {
1037
                    public ThreadGroup run() {
1038
                        ThreadGroup current = Thread.currentThread().getThreadGroup();
1038
                        ThreadGroup current = Thread.currentThread().getThreadGroup();
1039
1039
1040
                        while (current.getParent() != null) {
1040
                        while (current.getParent() != null) {
Lines 1045-1051 Link Here
1045
                    }
1045
                    }
1046
                };
1046
                };
1047
1047
1048
            return (ThreadGroup) java.security.AccessController.doPrivileged(run);
1048
            return java.security.AccessController.doPrivileged(run);
1049
        }
1049
        }
1050
    }
1050
    }
1051
}
1051
}
(-)openide/util/src/org/openide/util/SharedClassObject.java (-25 / +25 lines)
Lines 50-56 Link Here
50
    private static final Object PROP_SUPPORT = new Object();
50
    private static final Object PROP_SUPPORT = new Object();
51
51
52
    /** Map (Class, DataEntry) that maps Classes to maps of any objects */
52
    /** Map (Class, DataEntry) that maps Classes to maps of any objects */
53
    private static final Map values = new WeakHashMap(4);
53
    private static final Map<Class,DataEntry> values = new WeakHashMap<Class,DataEntry>(37);
54
54
55
    /** A set of all classes for which we are currently inside createInstancePrivileged.
55
    /** A set of all classes for which we are currently inside createInstancePrivileged.
56
     * If a SCO constructor is called when an instance of that class already exists, normally
56
     * If a SCO constructor is called when an instance of that class already exists, normally
Lines 60-71 Link Here
60
     * second instance (because it is nobody's fault and it will be handled OK).
60
     * second instance (because it is nobody's fault and it will be handled OK).
61
     * Map from class name to nesting count.
61
     * Map from class name to nesting count.
62
     */
62
     */
63
    private static final Map instancesBeingCreated = new HashMap(3); // Map<String,int>
63
    private static final Map<String,Integer> instancesBeingCreated = new HashMap<String,Integer>(7);
64
64
65
    /** Set of classes to not warn about any more.
65
    /** Set of classes to not warn about any more.
66
     * Names only.
66
     * Names only.
67
     */
67
     */
68
    private static final Set alreadyWarnedAboutDupes = new HashSet(); // Set<String>
68
    private static final Set<String> alreadyWarnedAboutDupes = new HashSet<String>(); //
69
    private static final ErrorManager err = ErrorManager.getDefault().getInstance("org.openide.util.SharedClassObject"); // NOI18N
69
    private static final ErrorManager err = ErrorManager.getDefault().getInstance("org.openide.util.SharedClassObject"); // NOI18N
70
70
71
    /** data entry for this class */
71
    /** data entry for this class */
Lines 456-462 Link Here
456
    * @param clazz the shared class to look for
456
    * @param clazz the shared class to look for
457
    * @return the instance, or <code>null</code> if such does not exists
457
    * @return the instance, or <code>null</code> if such does not exists
458
    */
458
    */
459
    public static SharedClassObject findObject(Class clazz) {
459
    public static <T extends SharedClassObject> T findObject(Class<T> clazz) {
460
        return findObject(clazz, false);
460
        return findObject(clazz, false);
461
    }
461
    }
462
462
Lines 469-475 Link Here
469
    * @return an instance, or <code>null</code> if there was none and <code>create</code> was <code>false</code>
469
    * @return an instance, or <code>null</code> if there was none and <code>create</code> was <code>false</code>
470
    * @exception IllegalArgumentException if a new instance could not be created for some reason
470
    * @exception IllegalArgumentException if a new instance could not be created for some reason
471
    */
471
    */
472
    public static SharedClassObject findObject(Class clazz, boolean create) {
472
    public static <T extends SharedClassObject> T findObject(Class<T> clazz, boolean create) {
473
        // synchronizing on the same object as returned from getLock()
473
        // synchronizing on the same object as returned from getLock()
474
        synchronized (clazz.getName().intern()) {
474
        synchronized (clazz.getName().intern()) {
475
            DataEntry de = (DataEntry) values.get(clazz);
475
            DataEntry de = (DataEntry) values.get(clazz);
Lines 480-489 Link Here
480
480
481
            if ((obj == null) && create) {
481
            if ((obj == null) && create) {
482
                // try to create new instance
482
                // try to create new instance
483
                PrivilegedExceptionAction action = new SetAccessibleAction(clazz);
483
                SetAccessibleAction action = new SetAccessibleAction(clazz);
484
484
485
                try {
485
                try {
486
                    obj = (SharedClassObject) AccessController.doPrivileged(action);
486
                    obj = AccessController.doPrivileged(action);
487
                } catch (PrivilegedActionException e) {
487
                } catch (PrivilegedActionException e) {
488
                    Exception ex = e.getException();
488
                    Exception ex = e.getException();
489
                    IllegalArgumentException newEx = new IllegalArgumentException(ex.toString());
489
                    IllegalArgumentException newEx = new IllegalArgumentException(ex.toString());
Lines 509-515 Link Here
509
                        throw new IllegalStateException("Inconsistent state: " + clazz); // NOI18N
509
                        throw new IllegalStateException("Inconsistent state: " + clazz); // NOI18N
510
                    }
510
                    }
511
511
512
                    return obj2;
512
                    return clazz.cast(obj2);
513
                }
513
                }
514
            }
514
            }
515
515
Lines 523-529 Link Here
523
                // if such state exists it is deserialized before the object is returned from lookup.
523
                // if such state exists it is deserialized before the object is returned from lookup.
524
                if (obj.isSystemOption()) {
524
                if (obj.isSystemOption()) {
525
                    // Lookup will find serialized version of searched object and deserialize it
525
                    // Lookup will find serialized version of searched object and deserialize it
526
                    final Lookup.Result r = Lookup.getDefault().lookup(new Lookup.Template(clazz));
526
                    final Lookup.Result<T> r = Lookup.getDefault().lookup(new Lookup.Template<T>(clazz));
527
527
528
                    if (r.allInstances().isEmpty()) {
528
                    if (r.allInstances().isEmpty()) {
529
                        // #17711: folder lookup not yet initialized. Try to load the option later.
529
                        // #17711: folder lookup not yet initialized. Try to load the option later.
Lines 570-576 Link Here
570
                throw new IllegalStateException("Inconsistent state: " + clazz); // NOI18N
570
                throw new IllegalStateException("Inconsistent state: " + clazz); // NOI18N
571
            }
571
            }
572
572
573
            return obj;
573
            return clazz.cast(obj);
574
        }
574
        }
575
    }
575
    }
576
576
Lines 595-603 Link Here
595
        err.notify(ErrorManager.INFORMATIONAL, t);
595
        err.notify(ErrorManager.INFORMATIONAL, t);
596
    }
596
    }
597
597
598
    static Object createInstancePrivileged(Class clazz)
598
    static SharedClassObject createInstancePrivileged(Class<? extends SharedClassObject> clazz)
599
    throws Exception {
599
    throws Exception {
600
        java.lang.reflect.Constructor c = clazz.getDeclaredConstructor(new Class[0]);
600
        java.lang.reflect.Constructor<? extends SharedClassObject> c = clazz.getDeclaredConstructor(new Class[0]);
601
        c.setAccessible(true);
601
        c.setAccessible(true);
602
602
603
        String name = clazz.getName();
603
        String name = clazz.getName();
Lines 646-652 Link Here
646
        static final long serialVersionUID = 1327893248974327640L;
646
        static final long serialVersionUID = 1327893248974327640L;
647
647
648
        /** the class  */
648
        /** the class  */
649
        private Class clazz;
649
        private Class<? extends SharedClassObject> clazz;
650
650
651
        /** class name, in case clazz could not be reloaded */
651
        /** class name, in case clazz could not be reloaded */
652
        private String name;
652
        private String name;
Lines 714-720 Link Here
714
                    // make readResolve accessible (it can have any access modifier)
714
                    // make readResolve accessible (it can have any access modifier)
715
                    resolveMethod.setAccessible(true);
715
                    resolveMethod.setAccessible(true);
716
716
717
                    return resolveMethod.invoke(object, null);
717
                    return resolveMethod.invoke(object);
718
                } catch (Exception ex) {
718
                } catch (Exception ex) {
719
                    // checked or runtime does not matter - we must survive
719
                    // checked or runtime does not matter - we must survive
720
                    String banner = "Skipping " + object.getClass() + " resolution:"; //NOI18N
720
                    String banner = "Skipping " + object.getClass() + " resolution:"; //NOI18N
Lines 777-789 Link Here
777
    */
777
    */
778
    static final class DataEntry extends Object {
778
    static final class DataEntry extends Object {
779
        /** The data */
779
        /** The data */
780
        private HashMap map;
780
        private HashMap<Object,Object> map;
781
781
782
        /** The reference counter */
782
        /** The reference counter */
783
        private int count = 0;
783
        private int count = 0;
784
784
785
        /** weak reference to an object of this class */
785
        /** weak reference to an object of this class */
786
        private WeakReference ref = new WeakReference(null);
786
        private WeakReference<SharedClassObject> ref = new WeakReference<SharedClassObject>(null);
787
787
788
        /** inited? */
788
        /** inited? */
789
        private boolean initialized = false;
789
        private boolean initialized = false;
Lines 807-818 Link Here
807
        * @param obj the requestor object
807
        * @param obj the requestor object
808
        * @return the data
808
        * @return the data
809
        */
809
        */
810
        Map getMap(SharedClassObject obj) {
810
        Map<Object,Object> getMap(SharedClassObject obj) {
811
            ensureValid(obj);
811
            ensureValid(obj);
812
812
813
            if (map == null) {
813
            if (map == null) {
814
                // to signal invalid state
814
                // to signal invalid state
815
                map = new HashMap();
815
                map = new HashMap<Object,Object>();
816
            }
816
            }
817
817
818
            if (!initialized) {
818
            if (!initialized) {
Lines 836-842 Link Here
836
836
837
            if (map == null) {
837
            if (map == null) {
838
                // to signal invalid state
838
                // to signal invalid state
839
                map = new HashMap();
839
                map = new HashMap<Object,Object>();
840
                ret = null;
840
                ret = null;
841
            } else {
841
            } else {
842
                ret = map.get(key);
842
                ret = map.get(key);
Lines 865-871 Link Here
865
865
866
            if (map == null) {
866
            if (map == null) {
867
                // to signal invalid state
867
                // to signal invalid state
868
                map = new HashMap();
868
                map = new HashMap<Object,Object>();
869
            }
869
            }
870
870
871
            return map;
871
            return map;
Lines 932-938 Link Here
932
            SharedClassObject s = (SharedClassObject) ref.get();
932
            SharedClassObject s = (SharedClassObject) ref.get();
933
933
934
            if (s == null) {
934
            if (s == null) {
935
                ref = new WeakReference(obj);
935
                ref = new WeakReference<SharedClassObject>(obj);
936
936
937
                return obj;
937
                return obj;
938
            } else {
938
            } else {
Lines 962-975 Link Here
962
        }
962
        }
963
    }
963
    }
964
964
965
    static final class SetAccessibleAction implements PrivilegedExceptionAction {
965
    static final class SetAccessibleAction implements PrivilegedExceptionAction<SharedClassObject> {
966
        Class klass;
966
        Class<? extends SharedClassObject> klass;
967
967
968
        SetAccessibleAction(Class klass) {
968
        SetAccessibleAction(Class<? extends SharedClassObject> klass) {
969
            this.klass = klass;
969
            this.klass = klass;
970
        }
970
        }
971
971
972
        public Object run() throws Exception {
972
        public SharedClassObject run() throws Exception {
973
            return createInstancePrivileged(klass);
973
            return createInstancePrivileged(klass);
974
        }
974
        }
975
    }
975
    }
(-)openide/util/src/org/openide/util/Task.java (-7 / +6 lines)
Lines 44-52 Link Here
44
    }
44
    }
45
45
46
    /** map of subclasses to booleans whether they override waitFinished() or not
46
    /** map of subclasses to booleans whether they override waitFinished() or not
47
     * <Class, Boolean>
48
     */
47
     */
49
    private static java.util.WeakHashMap overrides;
48
    private static java.util.WeakHashMap<Class, Boolean> overrides;
50
49
51
    /** request processor for workarounding compatibility problem with
50
    /** request processor for workarounding compatibility problem with
52
     * classes that do not override waitFinished (long)
51
     * classes that do not override waitFinished (long)
Lines 60-66 Link Here
60
    private boolean finished;
59
    private boolean finished;
61
60
62
    /** listeners for the finish of task (TaskListener) */
61
    /** listeners for the finish of task (TaskListener) */
63
    private HashSet list;
62
    private HashSet<TaskListener> list;
64
63
65
    /** Create a new task.
64
    /** Create a new task.
66
    * The runnable should provide its own error-handling, as
65
    * The runnable should provide its own error-handling, as
Lines 225-231 Link Here
225
    */
224
    */
226
    public synchronized void addTaskListener(TaskListener l) {
225
    public synchronized void addTaskListener(TaskListener l) {
227
        if (list == null) {
226
        if (list == null) {
228
            list = new HashSet();
227
            list = new HashSet<TaskListener>();
229
        }
228
        }
230
229
231
        list.add(l);
230
        list.add(l);
Lines 263-280 Link Here
263
            return true;
262
            return true;
264
        }
263
        }
265
264
266
        java.util.WeakHashMap m;
265
        java.util.WeakHashMap<Class,Boolean> m;
267
        Boolean does;
266
        Boolean does;
268
267
269
        synchronized (Task.class) {
268
        synchronized (Task.class) {
270
            if (overrides == null) {
269
            if (overrides == null) {
271
                overrides = new java.util.WeakHashMap();
270
                overrides = new java.util.WeakHashMap<Class, Boolean>();
272
                RP = new RequestProcessor("Timeout waitFinished compatibility processor", 255); // NOI18N
271
                RP = new RequestProcessor("Timeout waitFinished compatibility processor", 255); // NOI18N
273
            }
272
            }
274
273
275
            m = overrides;
274
            m = overrides;
276
275
277
            does = (Boolean) m.get(getClass());
276
            does = m.get(getClass());
278
277
279
            if (does != null) {
278
            if (does != null) {
280
                return does.booleanValue();
279
                return does.booleanValue();
(-)openide/util/src/org/openide/util/TimedSoftReference.java (-4 / +4 lines)
Lines 37-47 Link Here
37
 * </ol>
37
 * </ol>
38
 * @author Jesse Glick
38
 * @author Jesse Glick
39
 */
39
 */
40
final class TimedSoftReference extends SoftReference implements Runnable {
40
final class TimedSoftReference<T> extends SoftReference<T> implements Runnable {
41
    private static final int TIMEOUT = 30000;
41
    private static final int TIMEOUT = 30000;
42
    private static final RequestProcessor RP = new RequestProcessor("TimedSoftReference"); // NOI18N
42
    private static final RequestProcessor RP = new RequestProcessor("TimedSoftReference"); // NOI18N
43
    private RequestProcessor.Task task;
43
    private RequestProcessor.Task task;
44
    private Object o;
44
    private T o;
45
    private final Map m;
45
    private final Map m;
46
    private final Object k;
46
    private final Object k;
47
47
Lines 56-62 Link Here
56
     * @param m a map in which this reference may serve as a value
56
     * @param m a map in which this reference may serve as a value
57
     * @param k the key whose value in <code>m</code> may be this reference
57
     * @param k the key whose value in <code>m</code> may be this reference
58
     */
58
     */
59
    public TimedSoftReference(Object o, Map m, Object k) {
59
    public TimedSoftReference(T o, Map m, Object k) {
60
        super(o, Utilities.activeReferenceQueue());
60
        super(o, Utilities.activeReferenceQueue());
61
        this.o = o;
61
        this.o = o;
62
        this.m = m;
62
        this.m = m;
Lines 86-92 Link Here
86
        }
86
        }
87
    }
87
    }
88
88
89
    public Object get() {
89
    public T get() {
90
        synchronized (m) {
90
        synchronized (m) {
91
            if (o == null) {
91
            if (o == null) {
92
                o = super.get();
92
                o = super.get();
(-)openide/util/src/org/openide/util/TopologicalSortException.java (-23 / +24 lines)
Lines 37-43 Link Here
37
    private int counter;
37
    private int counter;
38
38
39
    /** vertexes sorted by increasing value of y */
39
    /** vertexes sorted by increasing value of y */
40
    private Stack dualGraph = new Stack();
40
    private Stack<Vertex> dualGraph = new Stack<Vertex>();
41
41
42
    TopologicalSortException(Collection vertexes, Map edges) {
42
    TopologicalSortException(Collection vertexes, Map edges) {
43
        this.vertexes = vertexes;
43
        this.vertexes = vertexes;
Lines 52-61 Link Here
52
    public final List partialSort() {
52
    public final List partialSort() {
53
        Set[] all = topologicalSets();
53
        Set[] all = topologicalSets();
54
54
55
        ArrayList res = new ArrayList(vertexes.size());
55
        ArrayList<Object> res = new ArrayList<Object>(vertexes.size());
56
56
57
        for (int i = 0; i < all.length; i++) {
57
        for (int i = 0; i < all.length; i++) {
58
            res.addAll(all[i]);
58
            for (Object e : all[i]) {
59
                res.add(e);
60
            }
59
        }
61
        }
60
62
61
        return res;
63
        return res;
Lines 75-81 Link Here
75
    public final Set[] unsortableSets() {
77
    public final Set[] unsortableSets() {
76
        Set[] all = topologicalSets();
78
        Set[] all = topologicalSets();
77
79
78
        ArrayList unsort = new ArrayList();
80
        ArrayList<Set> unsort = new ArrayList<Set>();
79
81
80
        for (int i = 0; i < all.length; i++) {
82
        for (int i = 0; i < all.length; i++) {
81
            if ((all[i].size() > 1) || !(all[i] instanceof HashSet)) {
83
            if ((all[i].size() > 1) || !(all[i] instanceof HashSet)) {
Lines 83-89 Link Here
83
            }
85
            }
84
        }
86
        }
85
87
86
        return (Set[]) unsort.toArray(new Set[0]);
88
        return unsort.toArray(new Set[0]);
87
    }
89
    }
88
90
89
    /** Adds description why the graph cannot be sorted.
91
    /** Adds description why the graph cannot be sorted.
Lines 137-143 Link Here
137
            return result;
139
            return result;
138
        }
140
        }
139
141
140
        HashMap vertexInfo = new HashMap();
142
        HashMap<Object,Vertex> vertexInfo = new HashMap<Object,Vertex>();
141
143
142
        // computes value X and Y for each vertex
144
        // computes value X and Y for each vertex
143
        counter = 0;
145
        counter = 0;
Lines 151-165 Link Here
151
        // now connect vertexes that cannot be sorted into own
153
        // now connect vertexes that cannot be sorted into own
152
        // sets
154
        // sets
153
        // map from the original objects to 
155
        // map from the original objects to 
154
        Map objectsToSets = new HashMap();
156
        Map<Object,Set> objectsToSets = new HashMap<Object,Set>();
155
157
156
        ArrayList sets = new ArrayList();
158
        ArrayList<Set> sets = new ArrayList<Set>();
157
159
158
        while (!dualGraph.isEmpty()) {
160
        while (!dualGraph.isEmpty()) {
159
            Vertex v = (Vertex) dualGraph.pop();
161
            Vertex v = (Vertex) dualGraph.pop();
160
162
161
            if (!v.visited) {
163
            if (!v.visited) {
162
                Set set = new HashSet();
164
                Set<Object> set = new HashSet<Object>();
163
                visitDualGraph(v, set);
165
                visitDualGraph(v, set);
164
166
165
                if ((set.size() == 1) && v.edgesFrom.contains(v)) {
167
                if ((set.size() == 1) && v.edgesFrom.contains(v)) {
Lines 185-191 Link Here
185
187
186
        // now topologically sort the sets
188
        // now topologically sort the sets
187
        // 1. prepare the map
189
        // 1. prepare the map
188
        HashMap edgesBetweenSets = new HashMap();
190
        HashMap<Set,Collection<Set>> edgesBetweenSets = new HashMap<Set,Collection<Set>>();
189
        it = edges.entrySet().iterator();
191
        it = edges.entrySet().iterator();
190
192
191
        while (it.hasNext()) {
193
        while (it.hasNext()) {
Lines 196-214 Link Here
196
                continue;
198
                continue;
197
            }
199
            }
198
200
199
            Set from = (Set) objectsToSets.get(entry.getKey());
201
            Set from = objectsToSets.get(entry.getKey());
200
202
201
            Collection setsTo = (Collection) edgesBetweenSets.get(from);
203
            Collection<Set> setsTo = edgesBetweenSets.get(from);
202
204
203
            if (setsTo == null) {
205
            if (setsTo == null) {
204
                setsTo = new ArrayList();
206
                setsTo = new ArrayList<Set>();
205
                edgesBetweenSets.put(from, setsTo);
207
                edgesBetweenSets.put(from, setsTo);
206
            }
208
            }
207
209
208
            Iterator convert = leadsTo.iterator();
210
            Iterator convert = leadsTo.iterator();
209
211
210
            while (convert.hasNext()) {
212
            while (convert.hasNext()) {
211
                Set to = (Set) objectsToSets.get(convert.next());
213
                Set to = objectsToSets.get(convert.next());
212
214
213
                if (from != to) {
215
                if (from != to) {
214
                    // avoid self cycles
216
                    // avoid self cycles
Lines 219-225 Link Here
219
221
220
        // 2. do the sort
222
        // 2. do the sort
221
        try {
223
        try {
222
            result = (Set[]) Utilities.topologicalSort(sets, edgesBetweenSets).toArray(new Set[0]);
224
            List<Set> listResult = Utilities.topologicalSort(sets, edgesBetweenSets);
225
            result = listResult.toArray(new Set[0]);
223
        } catch (TopologicalSortException ex) {
226
        } catch (TopologicalSortException ex) {
224
            throw new IllegalStateException("Cannot happen"); // NOI18N
227
            throw new IllegalStateException("Cannot happen"); // NOI18N
225
        }
228
        }
Lines 232-238 Link Here
232
     * @param vertex current vertex
235
     * @param vertex current vertex
233
     * @param vertexInfo the info
236
     * @param vertexInfo the info
234
     */
237
     */
235
    private Vertex constructDualGraph(int counter, Object vertex, HashMap vertexInfo) {
238
    private Vertex constructDualGraph(int counter, Object vertex, HashMap<Object,Vertex> vertexInfo) {
236
        Vertex info = (Vertex) vertexInfo.get(vertex);
239
        Vertex info = (Vertex) vertexInfo.get(vertex);
237
240
238
        if (info == null) {
241
        if (info == null) {
Lines 269-275 Link Here
269
     * @param vertex vertex to start from
272
     * @param vertex vertex to start from
270
     * @param visited list of all objects that we've been to
273
     * @param visited list of all objects that we've been to
271
     */
274
     */
272
    private void visitDualGraph(Vertex vertex, Collection visited) {
275
    private void visitDualGraph(Vertex vertex, Collection<Object> visited) {
273
        if (vertex.visited) {
276
        if (vertex.visited) {
274
            return;
277
            return;
275
        }
278
        }
Lines 289-300 Link Here
289
     * comparable by the value of Y, but only after the value is set,
292
     * comparable by the value of Y, but only after the value is set,
290
     * so the sort has to be done latelly.
293
     * so the sort has to be done latelly.
291
     */
294
     */
292
    private static final class Vertex implements Comparable {
295
    private static final class Vertex implements Comparable<Vertex> {
293
        /** the found object */
296
        /** the found object */
294
        public Object object;
297
        public Object object;
295
298
296
        /** list of vertexes that point to this one */
299
        /** list of vertexes that point to this one */
297
        public List edgesFrom = new ArrayList();
300
        public List<Vertex> edgesFrom = new ArrayList<Vertex>();
298
301
299
        /** the counter state when we entered the vertex */
302
        /** the counter state when we entered the vertex */
300
        public final int x;
303
        public final int x;
Lines 331-340 Link Here
331
         * @return  a negative integer, zero, or a positive integer as this object
334
         * @return  a negative integer, zero, or a positive integer as this object
332
         *                 is less than, equal to, or greater than the specified object.
335
         *                 is less than, equal to, or greater than the specified object.
333
         */
336
         */
334
        public int compareTo(Object o) {
337
        public int compareTo(Vertex o) {
335
            Vertex v = (Vertex) o;
338
            return o.y - y;
336
337
            return v.y - y;
338
        }
339
        }
339
    }
340
    }
340
}
341
}
(-)openide/util/src/org/openide/util/Utilities.java (-33 / +39 lines)
Lines 154-164 Link Here
154
    private static final int TYPICAL_MACOSX_MENU_HEIGHT = 24;
154
    private static final int TYPICAL_MACOSX_MENU_HEIGHT = 24;
155
155
156
    /** variable holding the activeReferenceQueue */
156
    /** variable holding the activeReferenceQueue */
157
    private static ReferenceQueue activeReferenceQueue;
157
    private static ReferenceQueue<Object> activeReferenceQueue;
158
158
159
    /** reference to map that maps allowed key names to their values (String, Integer)
159
    /** reference to map that maps allowed key names to their values (String, Integer)
160
    and reference to map for mapping of values to their names */
160
    and reference to map for mapping of values to their names */
161
    private static Reference namesAndValues;
161
    private static Reference<Object> namesAndValues;
162
162
163
    /** The operating system on which NetBeans runs*/
163
    /** The operating system on which NetBeans runs*/
164
    private static int operatingSystem = -1;
164
    private static int operatingSystem = -1;
Lines 242-248 Link Here
242
     *
242
     *
243
     * @since 3.11
243
     * @since 3.11
244
     */
244
     */
245
    public static synchronized ReferenceQueue activeReferenceQueue() {
245
    public static synchronized ReferenceQueue<Object> activeReferenceQueue() {
246
        if (activeReferenceQueue == null) {
246
        if (activeReferenceQueue == null) {
247
            activeReferenceQueue = new ActiveQueue(false);
247
            activeReferenceQueue = new ActiveQueue(false);
248
        }
248
        }
Lines 492-498 Link Here
492
            return workingSet;
492
            return workingSet;
493
        }
493
        }
494
494
495
        java.util.ArrayList lines = new java.util.ArrayList();
495
        java.util.ArrayList<String> lines = new java.util.ArrayList<String>();
496
496
497
        int lineStart = 0; // the position of start of currently processed line in the original string
497
        int lineStart = 0; // the position of start of currently processed line in the original string
498
498
Lines 616-622 Link Here
616
            return original;
616
            return original;
617
        }
617
        }
618
618
619
        java.util.Vector lines = new java.util.Vector();
619
        java.util.Vector<String> lines = new java.util.Vector<String>();
620
        int lineStart = 0; // the position of start of currently processed line in the original string
620
        int lineStart = 0; // the position of start of currently processed line in the original string
621
        int lastSpacePos = -1;
621
        int lastSpacePos = -1;
622
622
Lines 1323-1329 Link Here
1323
        int INPARAMPENDING = 0x2; // INPARAM + \
1323
        int INPARAMPENDING = 0x2; // INPARAM + \
1324
        int STICK = 0x4; // INPARAM + " or STICK + non_" // NOI18N
1324
        int STICK = 0x4; // INPARAM + " or STICK + non_" // NOI18N
1325
        int STICKPENDING = 0x8; // STICK + \
1325
        int STICKPENDING = 0x8; // STICK + \
1326
        Vector params = new Vector(5, 5);
1326
        Vector<String> params = new Vector<String>(5, 5);
1327
        char c;
1327
        char c;
1328
1328
1329
        int state = NULL;
1329
        int state = NULL;
Lines 1532-1539 Link Here
1532
1532
1533
        Field[] fields = KeyEvent.class.getDeclaredFields();
1533
        Field[] fields = KeyEvent.class.getDeclaredFields();
1534
1534
1535
        HashMap names = new HashMap(((fields.length * 4) / 3) + 5, 0.75f);
1535
        HashMap<String,Integer> names = new HashMap<String,Integer>(((fields.length * 4) / 3) + 5, 0.75f);
1536
        HashMap values = new HashMap(((fields.length * 4) / 3) + 5, 0.75f);
1536
        HashMap<Integer,String> values = new HashMap<Integer,String>(((fields.length * 4) / 3) + 5, 0.75f);
1537
1537
1538
        for (int i = 0; i < fields.length; i++) {
1538
        for (int i = 0; i < fields.length; i++) {
1539
            if (Modifier.isStatic(fields[i].getModifiers())) {
1539
            if (Modifier.isStatic(fields[i].getModifiers())) {
Lines 1569-1575 Link Here
1569
1569
1570
        HashMap[] arr = { names, values };
1570
        HashMap[] arr = { names, values };
1571
1571
1572
        namesAndValues = new SoftReference(arr);
1572
        namesAndValues = new SoftReference<Object>(arr);
1573
1573
1574
        return arr;
1574
        return arr;
1575
    }
1575
    }
Lines 1741-1747 Link Here
1741
    */
1741
    */
1742
    public static KeyStroke[] stringToKeys(String s) {
1742
    public static KeyStroke[] stringToKeys(String s) {
1743
        StringTokenizer st = new StringTokenizer(s.toUpperCase(Locale.ENGLISH), " "); // NOI18N
1743
        StringTokenizer st = new StringTokenizer(s.toUpperCase(Locale.ENGLISH), " "); // NOI18N
1744
        ArrayList arr = new ArrayList();
1744
        ArrayList<KeyStroke> arr = new ArrayList<KeyStroke>();
1745
1745
1746
        while (st.hasMoreElements()) {
1746
        while (st.hasMoreElements()) {
1747
            s = st.nextToken();
1747
            s = st.nextToken();
Lines 1755-1761 Link Here
1755
            arr.add(k);
1755
            arr.add(k);
1756
        }
1756
        }
1757
1757
1758
        return (KeyStroke[]) arr.toArray(new KeyStroke[arr.size()]);
1758
        return arr.toArray(new KeyStroke[arr.size()]);
1759
    }
1759
    }
1760
1760
1761
    /** Adds characters for modifiers to the buffer.
1761
    /** Adds characters for modifiers to the buffer.
Lines 2079-2084 Link Here
2079
    * @throws UnorderableException if the specified partial order is inconsistent on this list
2079
    * @throws UnorderableException if the specified partial order is inconsistent on this list
2080
    * @deprecated Deprecated in favor of the potentially much faster (and possibly more correct) {@link #topologicalSort}.
2080
    * @deprecated Deprecated in favor of the potentially much faster (and possibly more correct) {@link #topologicalSort}.
2081
    */
2081
    */
2082
    @SuppressWarnings("unchecked") // do not bother, it is deprecated anyway
2082
    public static List partialSort(List l, Comparator c, boolean stable)
2083
    public static List partialSort(List l, Comparator c, boolean stable)
2083
    throws UnorderableException {
2084
    throws UnorderableException {
2084
        // map from objects in the list to null or sets of objects they are greater than
2085
        // map from objects in the list to null or sets of objects they are greater than
Lines 2200-2216 Link Here
2200
     * @since 3.30
2201
     * @since 3.30
2201
     * @see <a href="http://www.netbeans.org/issues/show_bug.cgi?id=27286">Issue #27286</a>
2202
     * @see <a href="http://www.netbeans.org/issues/show_bug.cgi?id=27286">Issue #27286</a>
2202
     */
2203
     */
2203
    public static List topologicalSort(Collection c, Map edges)
2204
    public static <T> List<T> topologicalSort(Collection<T> c, Map<? super T, ? extends Collection<? extends T>> edges)
2204
    throws TopologicalSortException {
2205
    throws TopologicalSortException {
2205
        Map finished = new HashMap();
2206
        Map<T,Boolean> finished = new HashMap<T,Boolean>();
2206
        List r = new ArrayList(Math.max(c.size(), 1));
2207
        List<T> r = new ArrayList<T>(Math.max(c.size(), 1));
2207
        List cRev = new ArrayList(c);
2208
        List<T> cRev = new ArrayList<T>(c);
2208
        Collections.reverse(cRev);
2209
        Collections.reverse(cRev);
2209
2210
2210
        Iterator it = cRev.iterator();
2211
        Iterator<T> it = cRev.iterator();
2211
2212
2212
        while (it.hasNext()) {
2213
        while (it.hasNext()) {
2213
            List cycle = visit(it.next(), edges, finished, r);
2214
            List<T> cycle = visit(it.next(), edges, finished, r);
2214
2215
2215
            if (cycle != null) {
2216
            if (cycle != null) {
2216
                throw new TopologicalSortException(cRev, edges);
2217
                throw new TopologicalSortException(cRev, edges);
Lines 2232-2238 Link Here
2232
     * @param r the order in progress
2233
     * @param r the order in progress
2233
     * @return list with detected cycle
2234
     * @return list with detected cycle
2234
     */
2235
     */
2235
    static List visit(Object node, Map edges, Map finished, List r) {
2236
    static <T> List<T> visit(
2237
        T node,
2238
        Map<? super T, ? extends Collection<? extends T>> edges,
2239
        Map<T,Boolean> finished,
2240
        List<T> r
2241
    ) {
2236
        Boolean b = (Boolean) finished.get(node);
2242
        Boolean b = (Boolean) finished.get(node);
2237
2243
2238
        //System.err.println("node=" + node + " color=" + b);
2244
        //System.err.println("node=" + node + " color=" + b);
Lines 2241-2262 Link Here
2241
                return null;
2247
                return null;
2242
            }
2248
            }
2243
2249
2244
            ArrayList cycle = new ArrayList();
2250
            ArrayList<T> cycle = new ArrayList<T>();
2245
            cycle.add(node);
2251
            cycle.add(node);
2246
            finished.put(node, null);
2252
            finished.put(node, null);
2247
2253
2248
            return cycle;
2254
            return cycle;
2249
        }
2255
        }
2250
2256
2251
        Collection e = (Collection) edges.get(node);
2257
        Collection<? extends T> e = edges.get(node);
2252
2258
2253
        if (e != null) {
2259
        if (e != null) {
2254
            finished.put(node, Boolean.FALSE);
2260
            finished.put(node, Boolean.FALSE);
2255
2261
2256
            Iterator it = e.iterator();
2262
            Iterator<? extends T> it = e.iterator();
2257
2263
2258
            while (it.hasNext()) {
2264
            while (it.hasNext()) {
2259
                List cycle = visit(it.next(), edges, finished, r);
2265
                List<T> cycle = visit(it.next(), edges, finished, r);
2260
2266
2261
                if (cycle != null) {
2267
                if (cycle != null) {
2262
                    if (cycle instanceof ArrayList) {
2268
                    if (cycle instanceof ArrayList) {
Lines 2430-2440 Link Here
2430
        re = new RE13();
2436
        re = new RE13();
2431
2437
2432
        //        }
2438
        //        }
2433
        TreeSet list = new TreeSet(
2439
        TreeSet<String[]> list = new TreeSet<String[]>(
2434
                new Comparator() {
2440
                new Comparator<String[]>() {
2435
                    public int compare(Object o1, Object o2) {
2441
                    public int compare(String[] o1, String[] o2) {
2436
                        String s1 = ((String[]) o1)[0];
2442
                        String s1 = o1[0];
2437
                        String s2 = ((String[]) o2)[0];
2443
                        String s2 = o2[0];
2438
2444
2439
                        int i1 = s1.length();
2445
                        int i1 = s1.length();
2440
                        int i2 = s2.length();
2446
                        int i2 = s2.length();
Lines 2500-2506 Link Here
2500
     * @param resource URL identifiing transaction table
2506
     * @param resource URL identifiing transaction table
2501
     * @param results will be filled with String[2]
2507
     * @param results will be filled with String[2]
2502
     */
2508
     */
2503
    private static void loadTranslationFile(RE re, BufferedReader reader, Set results)
2509
    private static void loadTranslationFile(RE re, BufferedReader reader, Set<String[]> results)
2504
    throws IOException {
2510
    throws IOException {
2505
        for (;;) {
2511
        for (;;) {
2506
            String line = reader.readLine();
2512
            String line = reader.readLine();
Lines 2575-2581 Link Here
2575
        JPopupMenu menu = org.netbeans.modules.openide.util.AWTBridge.getDefault().createEmptyPopup();
2581
        JPopupMenu menu = org.netbeans.modules.openide.util.AWTBridge.getDefault().createEmptyPopup();
2576
2582
2577
        // keeps actions for which was menu item created already
2583
        // keeps actions for which was menu item created already
2578
        HashSet counted = new HashSet();
2584
        HashSet<Action> counted = new HashSet<Action>();
2579
        boolean haveHadNonSep = false;
2585
        boolean haveHadNonSep = false;
2580
        boolean needSep = false;
2586
        boolean needSep = false;
2581
2587
Lines 2957-2963 Link Here
2957
2963
2958
    /** Implementation of the active queue.
2964
    /** Implementation of the active queue.
2959
     */
2965
     */
2960
    private static final class ActiveQueue extends ReferenceQueue implements Runnable {
2966
    private static final class ActiveQueue extends ReferenceQueue<Object> implements Runnable {
2961
        private boolean running;
2967
        private boolean running;
2962
        private boolean deprecated;
2968
        private boolean deprecated;
2963
2969
Lines 2970-2984 Link Here
2970
            t.start();
2976
            t.start();
2971
        }
2977
        }
2972
2978
2973
        public Reference poll() {
2979
        public Reference<Object> poll() {
2974
            throw new java.lang.UnsupportedOperationException();
2980
            throw new java.lang.UnsupportedOperationException();
2975
        }
2981
        }
2976
2982
2977
        public Reference remove(long timeout) throws IllegalArgumentException, InterruptedException {
2983
        public Reference<Object> remove(long timeout) throws IllegalArgumentException, InterruptedException {
2978
            throw new java.lang.InterruptedException();
2984
            throw new java.lang.InterruptedException();
2979
        }
2985
        }
2980
2986
2981
        public Reference remove() throws InterruptedException {
2987
        public Reference<Object> remove() throws InterruptedException {
2982
            throw new java.lang.InterruptedException();
2988
            throw new java.lang.InterruptedException();
2983
        }
2989
        }
2984
2990
(-)openide/util/src/org/openide/util/UtilitiesCompositeActionMap.java (-2 / +2 lines)
Lines 76-82 Link Here
76
    }
76
    }
77
77
78
    private Object[] keys(boolean all) {
78
    private Object[] keys(boolean all) {
79
        java.util.HashSet keys = new java.util.HashSet();
79
        java.util.HashSet<Object> keys = new java.util.HashSet<Object>();
80
80
81
        Component c = component;
81
        Component c = component;
82
82
Lines 85-91 Link Here
85
                javax.swing.ActionMap m = ((JComponent) c).getActionMap();
85
                javax.swing.ActionMap m = ((JComponent) c).getActionMap();
86
86
87
                if (m != null) {
87
                if (m != null) {
88
                    java.util.List l;
88
                    java.util.List<Object> l;
89
89
90
                    if (all) {
90
                    if (all) {
91
                        l = java.util.Arrays.asList(m.allKeys());
91
                        l = java.util.Arrays.asList(m.allKeys());
(-)openide/util/src/org/openide/util/WeakListenerImpl.java (-8 / +10 lines)
Lines 29-34 Link Here
29
import java.lang.reflect.Proxy;
29
import java.lang.reflect.Proxy;
30
import java.util.EventListener;
30
import java.util.EventListener;
31
import java.util.EventObject;
31
import java.util.EventObject;
32
import java.util.Map;
33
import java.util.WeakHashMap;
32
import javax.swing.event.ChangeEvent;
34
import javax.swing.event.ChangeEvent;
33
import javax.swing.event.ChangeListener;
35
import javax.swing.event.ChangeListener;
34
import javax.swing.event.DocumentEvent;
36
import javax.swing.event.DocumentEvent;
Lines 49-55 Link Here
49
    Class listenerClass;
51
    Class listenerClass;
50
52
51
    /** weak reference to source */
53
    /** weak reference to source */
52
    private Reference source;
54
    private Reference<Object> source;
53
55
54
    /**
56
    /**
55
     * @param listenerClass class/interface of the listener
57
     * @param listenerClass class/interface of the listener
Lines 81-87 Link Here
81
        if (source == null) {
83
        if (source == null) {
82
            this.source = null;
84
            this.source = null;
83
        } else {
85
        } else {
84
            this.source = new WeakReference(source);
86
            this.source = new WeakReference<Object>(source);
85
        }
87
        }
86
    }
88
    }
87
89
Lines 116-126 Link Here
116
        return getClass().getName() + "[" + ((listener == null) ? "null" : (listener.getClass().getName() + "]"));
118
        return getClass().getName() + "[" + ((listener == null) ? "null" : (listener.getClass().getName() + "]"));
117
    }
119
    }
118
120
119
    public static EventListener create(Class lType, Class apiType, EventListener l, Object source) {
121
    public static <T extends EventListener> T create(Class<T> lType, Class<? super T> apiType, T l, Object source) {
120
        ProxyListener pl = new ProxyListener(lType, apiType, l);
122
        ProxyListener pl = new ProxyListener(lType, apiType, l);
121
        pl.setSource(source);
123
        pl.setSource(source);
122
124
123
        return (EventListener) pl.proxy;
125
        return lType.cast(pl.proxy);
124
    }
126
    }
125
127
126
    /** Weak property change listener
128
    /** Weak property change listener
Lines 343-349 Link Here
343
        private static Method equalsMth;
345
        private static Method equalsMth;
344
346
345
        /** Class -> Reference(Constructor) */
347
        /** Class -> Reference(Constructor) */
346
        private static final java.util.WeakHashMap constructors = new java.util.WeakHashMap();
348
        private static final Map<Class, Reference<Constructor>> constructors = new WeakHashMap<Class, Reference<Constructor>>();
347
349
348
        /** proxy generated for this listener */
350
        /** proxy generated for this listener */
349
        public final Object proxy;
351
        public final Object proxy;
Lines 360-366 Link Here
360
                if (proxyConstructor == null) {
362
                if (proxyConstructor == null) {
361
                    Class proxyClass = Proxy.getProxyClass(c.getClassLoader(), new Class[] { c });
363
                    Class proxyClass = Proxy.getProxyClass(c.getClassLoader(), new Class[] { c });
362
                    proxyConstructor = proxyClass.getConstructor(new Class[] { InvocationHandler.class });
364
                    proxyConstructor = proxyClass.getConstructor(new Class[] { InvocationHandler.class });
363
                    constructors.put(c, new SoftReference(proxyConstructor));
365
                    constructors.put(c, new SoftReference<Constructor>(proxyConstructor));
364
                }
366
                }
365
367
366
                Object p;
368
                Object p;
Lines 457-463 Link Here
457
459
458
    /** Reference that also holds ref to WeakListenerImpl.
460
    /** Reference that also holds ref to WeakListenerImpl.
459
    */
461
    */
460
    private static final class ListenerReference extends WeakReference implements Runnable {
462
    private static final class ListenerReference extends WeakReference<Object> implements Runnable {
461
        private static Class lastClass;
463
        private static Class lastClass;
462
        private static String lastMethodName;
464
        private static String lastMethodName;
463
        private static Method lastRemove;
465
        private static Method lastRemove;
Lines 481-487 Link Here
481
            if (weakListener.source != source) {
483
            if (weakListener.source != source) {
482
                // plan new cleanup into the activeReferenceQueue with this listener and 
484
                // plan new cleanup into the activeReferenceQueue with this listener and 
483
                // provided source
485
                // provided source
484
                weakListener.source = new WeakReference(source) {
486
                weakListener.source = new WeakReference<Object> (source) {
485
                            ListenerReference doNotGCRef = new ListenerReference(new Object(), weakListener);
487
                            ListenerReference doNotGCRef = new ListenerReference(new Object(), weakListener);
486
                        };
488
                        };
487
            }
489
            }
(-)openide/util/src/org/openide/util/WeakListeners.java (-2 / +2 lines)
Lines 185-191 Link Here
185
     * @return an instance of <CODE>lType</CODE> delegating all the interface
185
     * @return an instance of <CODE>lType</CODE> delegating all the interface
186
     * calls to <CODE>l</CODE>.
186
     * calls to <CODE>l</CODE>.
187
     */
187
     */
188
    public static EventListener create(Class lType, EventListener l, Object source) {
188
    public static <T extends EventListener> T create(Class<T> lType, T l, Object source) {
189
        if (!lType.isInterface()) {
189
        if (!lType.isInterface()) {
190
            throw new IllegalArgumentException("Not interface: " + lType);
190
            throw new IllegalArgumentException("Not interface: " + lType);
191
        }
191
        }
Lines 228-234 Link Here
228
     * calls to <CODE>l</CODE>.
228
     * calls to <CODE>l</CODE>.
229
     * @since 4.12
229
     * @since 4.12
230
     */
230
     */
231
    public static EventListener create(Class lType, Class apiType, EventListener l, Object source) {
231
    public static <T extends EventListener> T create(Class<T> lType, Class<? super T> apiType, T l, Object source) {
232
        if (!lType.isInterface()) {
232
        if (!lType.isInterface()) {
233
            throw new IllegalArgumentException("Not interface: " + lType);
233
            throw new IllegalArgumentException("Not interface: " + lType);
234
        }
234
        }
(-)openide/util/src/org/openide/util/WeakSet.java (-43 / +54 lines)
Lines 34-40 Link Here
34
*
34
*
35
* @author Ales Novak
35
* @author Ales Novak
36
*/
36
*/
37
public class WeakSet extends AbstractSet implements Cloneable, Serializable {
37
public class WeakSet<E> extends AbstractSet<E> implements Cloneable, Serializable {
38
    static final long serialVersionUID = 3062376055928236721L;
38
    static final long serialVersionUID = 3062376055928236721L;
39
39
40
    /** load factor */
40
    /** load factor */
Lines 47-60 Link Here
47
    private long modcount;
47
    private long modcount;
48
48
49
    /** Reference queue of collected weak refs */
49
    /** Reference queue of collected weak refs */
50
    private transient ReferenceQueue refq;
50
    private transient ReferenceQueue<E> refq;
51
51
52
    /** Count of <tt>null</tt> in this set */
52
    /** Count of <tt>null</tt> in this set */
53
    long nullCount;
53
    long nullCount;
54
54
55
    /** An array of Entries */
55
    /** An array of Entries */
56
    private transient Entry[] entries;
56
    private transient Entry<E>[] entries;
57
    transient Entry iterChain;
57
    transient Entry<E> iterChain;
58
58
59
    /** Constructs a new set. */
59
    /** Constructs a new set. */
60
    public WeakSet() {
60
    public WeakSet() {
Lines 64-70 Link Here
64
    /** Constructs a new set containing the elements in the specified collection.
64
    /** Constructs a new set containing the elements in the specified collection.
65
    * @param c a collection to add
65
    * @param c a collection to add
66
    */
66
    */
67
    public WeakSet(Collection c) {
67
    public WeakSet(Collection<? extends E> c) {
68
        this();
68
        this();
69
        addAll(c);
69
        addAll(c);
70
    }
70
    }
Lines 90-97 Link Here
90
        modcount = 0;
90
        modcount = 0;
91
        this.loadFactor = loadFactor;
91
        this.loadFactor = loadFactor;
92
        nullCount = 0;
92
        nullCount = 0;
93
        refq = new ReferenceQueue();
93
        refq = new ReferenceQueue<E>();
94
        entries = new Entry[initialCapacity];
94
        entries = Entry.createArray(initialCapacity);
95
        iterChain = null;
95
        iterChain = null;
96
    }
96
    }
97
97
Lines 99-105 Link Here
99
    *
99
    *
100
    * @param o an Object to add
100
    * @param o an Object to add
101
    */
101
    */
102
    public boolean add(Object o) {
102
    public boolean add(E o) {
103
        if (o == null) {
103
        if (o == null) {
104
            size++;
104
            size++;
105
            nullCount++;
105
            nullCount++;
Lines 118-125 Link Here
118
        size++;
118
        size++;
119
119
120
        int hash = hashIt(o);
120
        int hash = hashIt(o);
121
        Entry next = entries[hash];
121
        Entry<E> next = entries[hash];
122
        iterChain = entries[hash] = new Entry(o, refq, next, iterChain);
122
        iterChain = entries[hash] = new Entry<E>(this, o, refq, next, iterChain);
123
        rehash();
123
        rehash();
124
124
125
        return true;
125
        return true;
Lines 139-149 Link Here
139
139
140
    /** Returns a shallow copy of this WeakSet instance: the elements themselves are not cloned. */
140
    /** Returns a shallow copy of this WeakSet instance: the elements themselves are not cloned. */
141
    public Object clone() {
141
    public Object clone() {
142
        WeakSet nws = new WeakSet(1, loadFactor);
142
        WeakSet<E> nws = new WeakSet<E>(1, loadFactor);
143
        nws.size = size;
143
        nws.size = size;
144
        nws.nullCount = nullCount;
144
        nws.nullCount = nullCount;
145
145
146
        Entry[] cloned = new Entry[entries.length];
146
        Entry<E>[] cloned = Entry.createArray(entries.length);
147
        nws.entries = cloned;
147
        nws.entries = cloned;
148
148
149
        for (int i = 0; i < cloned.length; i++) {
149
        for (int i = 0; i < cloned.length; i++) {
Lines 157-163 Link Here
157
            }
157
            }
158
158
159
            // chains into nws iterator chain
159
            // chains into nws iterator chain
160
            Entry entry = cloned[i];
160
            Entry<E> entry = cloned[i];
161
161
162
            while (entry != null) {
162
            while (entry != null) {
163
                entry.chainIntoIter(nws.iterChain);
163
                entry.chainIntoIter(nws.iterChain);
Lines 188-194 Link Here
188
    }
188
    }
189
189
190
    /** Returns an iterator over the elements in this set. */
190
    /** Returns an iterator over the elements in this set. */
191
    public Iterator iterator() {
191
    public Iterator<E> iterator() {
192
        return new WeakSetIterator();
192
        return new WeakSetIterator();
193
    }
193
    }
194
194
Lines 229-237 Link Here
229
        return size;
229
        return size;
230
    }
230
    }
231
231
232
    public Object[] toArray(Object[] array) {
232
    public <T> T[] toArray(T[] array) {
233
        ArrayList list = new ArrayList(array.length);
233
        ArrayList<E> list = new ArrayList<E>(array.length);
234
        Iterator it = iterator();
234
        Iterator<E> it = iterator();
235
235
236
        while (it.hasNext()) {
236
        while (it.hasNext()) {
237
            list.add(it.next());
237
            list.add(it.next());
Lines 241-248 Link Here
241
    }
241
    }
242
242
243
    public Object[] toArray() {
243
    public Object[] toArray() {
244
        ArrayList list = new ArrayList();
244
        ArrayList<E> list = new ArrayList<E>();
245
        Iterator it = iterator();
245
        Iterator<E> it = iterator();
246
246
247
        while (it.hasNext()) {
247
        while (it.hasNext()) {
248
            list.add(it.next());
248
            list.add(it.next());
Lines 273-279 Link Here
273
    /** Checks if the queue is empty if not pending weak refs are removed. */
273
    /** Checks if the queue is empty if not pending weak refs are removed. */
274
    void checkRefQueue() {
274
    void checkRefQueue() {
275
        for (;;) {
275
        for (;;) {
276
            Entry entry = (Entry) refq.poll();
276
            Entry entry = Entry.class.cast(refq.poll());
277
277
278
            if (entry == null) {
278
            if (entry == null) {
279
                break;
279
                break;
Lines 328-350 Link Here
328
        obtos.writeObject(toArray());
328
        obtos.writeObject(toArray());
329
    }
329
    }
330
330
331
    @SuppressWarnings("unchecked")
331
    private void readObject(ObjectInputStream obtis) throws IOException, ClassNotFoundException {
332
    private void readObject(ObjectInputStream obtis) throws IOException, ClassNotFoundException {
332
        obtis.defaultReadObject();
333
        obtis.defaultReadObject();
333
334
334
        Object[] arr = (Object[]) obtis.readObject();
335
        Object[] arr = (Object[]) obtis.readObject();
335
        entries = new Entry[(int) (size * 1.5)];
336
        entries = new Entry[(int) (size * 1.5)];
336
        refq = new ReferenceQueue();
337
        refq = new ReferenceQueue<E>();
337
338
338
        for (int i = 0; i < arr.length; i++) {
339
        for (int i = 0; i < arr.length; i++) {
339
            add(arr[i]);
340
            add((E)arr[i]);
340
        }
341
        }
341
    }
342
    }
342
343
343
    class WeakSetIterator implements Iterator {
344
    class WeakSetIterator implements Iterator<E> {
344
        Entry current;
345
        Entry<E> current;
345
        Entry next;
346
        Entry<E> next;
346
        Object currentObj;
347
        E currentObj;
347
        Object nextObj;
348
        E nextObj;
348
        final long myModcount;
349
        final long myModcount;
349
        long myNullCount;
350
        long myNullCount;
350
351
Lines 354-366 Link Here
354
            current = null;
355
            current = null;
355
            next = null;
356
            next = null;
356
357
357
            Entry ee = iterChain;
358
            Entry<E> ee = iterChain;
358
359
359
            if (ee == null) {
360
            if (ee == null) {
360
                return;
361
                return;
361
            }
362
            }
362
363
363
            Object o = ee.get();
364
            E o = ee.get();
364
365
365
            while (ee.isEnqueued()) {
366
            while (ee.isEnqueued()) {
366
                ee = ee.iterChainNext;
367
                ee = ee.iterChainNext;
Lines 382-388 Link Here
382
            return ((myNullCount > 0) || (next != null));
383
            return ((myNullCount > 0) || (next != null));
383
        }
384
        }
384
385
385
        public Object next() {
386
        public E next() {
386
            checkModcount();
387
            checkModcount();
387
            checkRefQueue();
388
            checkRefQueue();
388
389
Lines 432-447 Link Here
432
    }
433
    }
433
434
434
    /** Entries of this set */
435
    /** Entries of this set */
435
    class Entry extends WeakReference {
436
    static class Entry<E> extends WeakReference<E> {
437
        /** reference to outer WeakSet */
438
        private WeakSet<E> set;
439
436
        // double linked list
440
        // double linked list
437
        Entry prev;
441
        Entry<E> prev;
438
        Entry next;
442
        Entry<E> next;
439
        private final int hashcode;
443
        private final int hashcode;
440
        Entry iterChainNext;
444
        Entry<E> iterChainNext;
441
        Entry iterChainPrev;
445
        Entry<E> iterChainPrev;
442
446
443
        Entry(Object referenced, ReferenceQueue q, Entry next, Entry nextInIter) {
447
        Entry(WeakSet<E> set, E referenced, ReferenceQueue<E> q, Entry<E> next, Entry<E> nextInIter) {
444
            super(referenced, q);
448
            super(referenced, q);
449
            this.set = set;
450
445
            this.next = next;
451
            this.next = next;
446
            this.prev = null;
452
            this.prev = null;
447
453
Lines 450-456 Link Here
450
            }
456
            }
451
457
452
            if (referenced != null) {
458
            if (referenced != null) {
453
                hashcode = hashIt(referenced);
459
                hashcode = set.hashIt(referenced);
454
            } else {
460
            } else {
455
                hashcode = 0;
461
                hashcode = 0;
456
            }
462
            }
Lines 458-464 Link Here
458
            chainIntoIter(nextInIter);
464
            chainIntoIter(nextInIter);
459
        }
465
        }
460
466
461
        void chainIntoIter(Entry nextInIter) {
467
        @SuppressWarnings("unchecked")
468
        static final <E> Entry<E>[] createArray(int size) {
469
            return new Entry[size];
470
        }
471
472
        void chainIntoIter(Entry<E> nextInIter) {
462
            iterChainNext = nextInIter;
473
            iterChainNext = nextInIter;
463
474
464
            if (nextInIter != null) {
475
            if (nextInIter != null) {
Lines 489-499 Link Here
489
            if (iterChainPrev != null) {
500
            if (iterChainPrev != null) {
490
                iterChainPrev.iterChainNext = iterChainNext;
501
                iterChainPrev.iterChainNext = iterChainNext;
491
            } else { // root
502
            } else { // root
492
                iterChain = iterChainNext;
503
                set.iterChain = iterChainNext;
493
            }
504
            }
494
505
495
            if (entries[hashcode] == this) {
506
            if (set.entries[hashcode] == this) {
496
                entries[hashcode] = next;
507
                set.entries[hashcode] = next;
497
            }
508
            }
498
509
499
            prev = null;
510
            prev = null;
Lines 516-523 Link Here
516
            }
527
            }
517
        }
528
        }
518
529
519
        public Entry clone(ReferenceQueue q) {
530
        public Entry<E> clone(ReferenceQueue<E> q) {
520
            return new Entry(get(), q, ((next != null) ? (Entry) next.clone(q) : null), null);
531
            return new Entry<E>(set, get(), q, next != null ? next.clone(q) : null, null);
521
        }
532
        }
522
    }
533
    }
523
}
534
}
(-)openide/util/src/org/openide/util/actions/CallableSystemAction.java (-1 / +1 lines)
Lines 42-48 Link Here
42
     * Set of action classes for which we have already issued a warning that
42
     * Set of action classes for which we have already issued a warning that
43
     * {@link #asynchronous} was not overridden to return false.
43
     * {@link #asynchronous} was not overridden to return false.
44
     */
44
     */
45
    private static final Set warnedAsynchronousActions = new WeakSet(); // Set<Class>
45
    private static final Set<Class> warnedAsynchronousActions = new WeakSet<Class>(); 
46
    private static final boolean DEFAULT_ASYNCH = !Boolean.getBoolean(
46
    private static final boolean DEFAULT_ASYNCH = !Boolean.getBoolean(
47
            "org.openide.util.actions.CallableSystemAction.synchronousByDefault"
47
            "org.openide.util.actions.CallableSystemAction.synchronousByDefault"
48
        );
48
        );
(-)openide/util/src/org/openide/util/actions/CallbackSystemAction.java (-22 / +22 lines)
Lines 44-53 Link Here
44
    private static final String PROP_ACTION_PERFORMER = "actionPerformer"; // NOI18N
44
    private static final String PROP_ACTION_PERFORMER = "actionPerformer"; // NOI18N
45
45
46
    /** a list of all actions that has survive focus change set to false */
46
    /** a list of all actions that has survive focus change set to false */
47
    private static final WeakSet notSurviving = new WeakSet(37);
47
    private static final WeakSet<Class<? extends SystemAction>> notSurviving = new WeakSet<Class<? extends SystemAction>>(37);
48
48
49
    /** a list of CallableSystemAction actions surviving focus change */
49
    /** a list of CallableSystemAction actions surviving focus change */
50
    private static final WeakSet surviving = new WeakSet(37);
50
    private static final WeakSet<Class<? extends SystemAction>> surviving = new WeakSet<Class<? extends SystemAction>>(37);
51
51
52
    /** key to access listener */
52
    /** key to access listener */
53
    private static final Object LISTENER = new Object();
53
    private static final Object LISTENER = new Object();
Lines 254-271 Link Here
254
254
255
    /** Array of actions from a set of classes.
255
    /** Array of actions from a set of classes.
256
     */
256
     */
257
    private static ArrayList toInstances(java.util.Set s) {
257
    private static ArrayList<SystemAction> toInstances(java.util.Set<Class<? extends SystemAction>> s) {
258
        ArrayList actions;
258
        ArrayList<SystemAction> actions;
259
259
260
        synchronized (notSurviving) {
260
        synchronized (notSurviving) {
261
            actions = new ArrayList(s.size());
261
            actions = new ArrayList<SystemAction>(s.size());
262
262
263
            Iterator it = s.iterator();
263
            Iterator<Class<? extends SystemAction>> it = s.iterator();
264
264
265
            while (it.hasNext()) {
265
            while (it.hasNext()) {
266
                Class c = (Class) it.next();
266
                Class<? extends SystemAction> c = it.next();
267
267
268
                Object a = SystemAction.findObject(c, false);
268
                SystemAction a = SystemAction.findObject(c, false);
269
269
270
                if (a != null) {
270
                if (a != null) {
271
                    actions.add(a);
271
                    actions.add(a);
Lines 310-321 Link Here
310
     */
310
     */
311
    private static final class GlobalManager implements LookupListener {
311
    private static final class GlobalManager implements LookupListener {
312
        private static GlobalManager instance;
312
        private static GlobalManager instance;
313
        private Lookup.Result result;
313
        private Lookup.Result<ActionMap> result;
314
        private Reference actionMap = new WeakReference(null);
314
        private Reference<ActionMap> actionMap = new WeakReference<ActionMap>(null);
315
        private final ActionMap survive = new ActionMap();
315
        private final ActionMap survive = new ActionMap();
316
316
317
        private GlobalManager() {
317
        private GlobalManager() {
318
            result = Utilities.actionsGlobalContext().lookup(new Lookup.Template(ActionMap.class));
318
            result = Utilities.actionsGlobalContext().lookup(new Lookup.Template<ActionMap>(ActionMap.class));
319
            result.addLookupListener(this);
319
            result.addLookupListener(this);
320
            resultChanged(null);
320
            resultChanged(null);
321
        }
321
        }
Lines 331-337 Link Here
331
        }
331
        }
332
332
333
        public Action findGlobalAction(Object key, boolean surviveFocusChange) {
333
        public Action findGlobalAction(Object key, boolean surviveFocusChange) {
334
            ActionMap map = (ActionMap) actionMap.get();
334
            ActionMap map = actionMap.get();
335
            Action a = (map == null) ? null : map.get(key);
335
            Action a = (map == null) ? null : map.get(key);
336
336
337
            if (surviveFocusChange) {
337
            if (surviveFocusChange) {
Lines 363-369 Link Here
363
363
364
        /** Change all that do not survive ActionMap change */
364
        /** Change all that do not survive ActionMap change */
365
        public void resultChanged(org.openide.util.LookupEvent ev) {
365
        public void resultChanged(org.openide.util.LookupEvent ev) {
366
            ActionMap a = (ActionMap) Utilities.actionsGlobalContext().lookup(ActionMap.class);
366
            ActionMap a = Utilities.actionsGlobalContext().lookup(ActionMap.class);
367
367
368
            if (errLog) {
368
            if (errLog) {
369
                err.log("changed map : " + a); // NOI18N
369
                err.log("changed map : " + a); // NOI18N
Lines 374-380 Link Here
374
                return;
374
                return;
375
            }
375
            }
376
376
377
            actionMap = new WeakReference(a);
377
            actionMap = new WeakReference<ActionMap>(a);
378
378
379
            if (errLog) {
379
            if (errLog) {
380
                err.log("clearActionPerformers"); // NOI18N
380
                err.log("clearActionPerformers"); // NOI18N
Lines 387-393 Link Here
387
387
388
    /** An action that holds a weak reference to other action.
388
    /** An action that holds a weak reference to other action.
389
     */
389
     */
390
    private static final class WeakAction extends WeakReference implements Action {
390
    private static final class WeakAction extends WeakReference<Action> implements Action {
391
        public WeakAction(Action delegate) {
391
        public WeakAction(Action delegate) {
392
            super(delegate);
392
            super(delegate);
393
        }
393
        }
Lines 428-439 Link Here
428
    /** A class that listens on changes in enabled state of an action
428
    /** A class that listens on changes in enabled state of an action
429
     * and updates the state of the action according to it.
429
     * and updates the state of the action according to it.
430
     */
430
     */
431
    private static final class ActionDelegateListener extends WeakReference implements PropertyChangeListener {
431
    private static final class ActionDelegateListener extends WeakReference<CallbackSystemAction> implements PropertyChangeListener {
432
        private WeakReference delegate;
432
        private WeakReference delegate;
433
433
434
        public ActionDelegateListener(CallbackSystemAction c, javax.swing.Action delegate) {
434
        public ActionDelegateListener(CallbackSystemAction c, Action delegate) {
435
            super(c);
435
            super(c);
436
            this.delegate = new WeakReference(delegate);
436
            this.delegate = new WeakReference<Action>(delegate);
437
            delegate.addPropertyChangeListener(this);
437
            delegate.addPropertyChangeListener(this);
438
        }
438
        }
439
439
Lines 466-472 Link Here
466
                prev.removePropertyChangeListener(this);
466
                prev.removePropertyChangeListener(this);
467
            }
467
            }
468
468
469
            this.delegate = new WeakReference(action);
469
            this.delegate = new WeakReference<Action>(action);
470
            action.addPropertyChangeListener(this);
470
            action.addPropertyChangeListener(this);
471
        }
471
        }
472
472
Lines 497-503 Link Here
497
        private CallbackSystemAction delegate;
497
        private CallbackSystemAction delegate;
498
498
499
        /** lookup we are associated with (or null) */
499
        /** lookup we are associated with (or null) */
500
        private org.openide.util.Lookup.Result result;
500
        private Lookup.Result<ActionMap> result;
501
501
502
        /** previous state of enabled */
502
        /** previous state of enabled */
503
        private boolean enabled;
503
        private boolean enabled;
Lines 516-522 Link Here
516
            this.weakL = org.openide.util.WeakListeners.propertyChange(this, null);
516
            this.weakL = org.openide.util.WeakListeners.propertyChange(this, null);
517
            this.enabled = a.getActionPerformer() != null;
517
            this.enabled = a.getActionPerformer() != null;
518
518
519
            this.result = actionContext.lookup(new org.openide.util.Lookup.Template(javax.swing.ActionMap.class));
519
            this.result = actionContext.lookup(new Lookup.Template<ActionMap>(ActionMap.class));
520
            this.result.addLookupListener(
520
            this.result.addLookupListener(
521
                (LookupListener) org.openide.util.WeakListeners.create(LookupListener.class, this, this.result)
521
                (LookupListener) org.openide.util.WeakListeners.create(LookupListener.class, this, this.result)
522
            );
522
            );
Lines 579-585 Link Here
579
                    last.removePropertyChangeListener(weakL);
579
                    last.removePropertyChangeListener(weakL);
580
                }
580
                }
581
581
582
                lastRef = new WeakReference(a);
582
                lastRef = new WeakReference<Action>(a);
583
                a.addPropertyChangeListener(weakL);
583
                a.addPropertyChangeListener(weakL);
584
            }
584
            }
585
585
(-)openide/util/src/org/openide/util/actions/SystemAction.java (-4 / +4 lines)
Lines 52-58 Link Here
52
    /** Name of property for the action's display icon, if textual. */
52
    /** Name of property for the action's display icon, if textual. */
53
    private static final String PROP_ICON_TEXTUAL = "iconTextual"; // NOI18N
53
    private static final String PROP_ICON_TEXTUAL = "iconTextual"; // NOI18N
54
    private static ImageIcon BLANK_ICON = null;
54
    private static ImageIcon BLANK_ICON = null;
55
    private static final Set relativeIconResourceClasses = new HashSet(200); // Set<String>
55
    private static final Set<String> relativeIconResourceClasses = new HashSet<String>(200);
56
56
57
    // Matches NB 3.4 w/ openide-compat.jar; see #26491
57
    // Matches NB 3.4 w/ openide-compat.jar; see #26491
58
    private static final long serialVersionUID = -8361232596876856810L;
58
    private static final long serialVersionUID = -8361232596876856810L;
Lines 74-81 Link Here
74
    * @exception ClassCastException if the class is not <code>SystemAction</code>
74
    * @exception ClassCastException if the class is not <code>SystemAction</code>
75
    * @exception IllegalArgumentException if the instance cannot be created
75
    * @exception IllegalArgumentException if the instance cannot be created
76
    */
76
    */
77
    public static SystemAction get(Class actionClass) {
77
    public static <T extends SystemAction> T get(Class<T> actionClass) {
78
        return (SystemAction) findObject(actionClass, true);
78
        return findObject(actionClass, true);
79
    }
79
    }
80
80
81
    /** Get a human presentable name of the action.
81
    /** Get a human presentable name of the action.
Lines 332-338 Link Here
332
    * @return an array of both sets of actions in the same order
332
    * @return an array of both sets of actions in the same order
333
    */
333
    */
334
    public static SystemAction[] linkActions(SystemAction[] actions1, SystemAction[] actions2) {
334
    public static SystemAction[] linkActions(SystemAction[] actions1, SystemAction[] actions2) {
335
        List l = new Vector(Arrays.asList(actions1));
335
        List<SystemAction> l = new Vector<SystemAction>(Arrays.asList(actions1));
336
        l.addAll(Arrays.asList(actions2));
336
        l.addAll(Arrays.asList(actions2));
337
337
338
        return (SystemAction[]) l.toArray(actions1);
338
        return (SystemAction[]) l.toArray(actions1);
(-)openide/util/src/org/openide/util/datatransfer/ExTransferable.java (-3 / +3 lines)
Lines 46-52 Link Here
46
    }
46
    }
47
47
48
    /** hash map that assigns objects to dataflavors (DataFlavor, Single) */
48
    /** hash map that assigns objects to dataflavors (DataFlavor, Single) */
49
    private LinkedHashMap map;
49
    private LinkedHashMap<DataFlavor,Single> map;
50
50
51
    /** listeners */
51
    /** listeners */
52
    private EventListenerList listeners;
52
    private EventListenerList listeners;
Lines 56-62 Link Here
56
    * @param o clipobard owner (or null)
56
    * @param o clipobard owner (or null)
57
    */
57
    */
58
    private ExTransferable(final Transferable t) {
58
    private ExTransferable(final Transferable t) {
59
        map = new LinkedHashMap();
59
        map = new LinkedHashMap<DataFlavor,Single>();
60
60
61
        final DataFlavor[] df = t.getTransferDataFlavors();
61
        final DataFlavor[] df = t.getTransferDataFlavors();
62
62
Lines 356-362 Link Here
356
            * @param array array of flavors
356
            * @param array array of flavors
357
            */
357
            */
358
            public boolean areDataFlavorsSupported(DataFlavor[] array) {
358
            public boolean areDataFlavorsSupported(DataFlavor[] array) {
359
                HashSet flav = new HashSet();
359
                HashSet<DataFlavor> flav = new HashSet<DataFlavor>();
360
360
361
                for (int i = 0; i < array.length; i++) {
361
                for (int i = 0; i < array.length; i++) {
362
                    flav.add(array[i]);
362
                    flav.add(array[i]);
(-)openide/util/src/org/openide/util/io/NbObjectOutputStream.java (-4 / +4 lines)
Lines 37-43 Link Here
37
*/
37
*/
38
public class NbObjectOutputStream extends ObjectOutputStream {
38
public class NbObjectOutputStream extends ObjectOutputStream {
39
    private static final String SVUID = "serialVersionUID"; // NOI18N
39
    private static final String SVUID = "serialVersionUID"; // NOI18N
40
    private static final Set alreadyReported = new WeakSet(); // Set<String>
40
    private static final Set<String> alreadyReported = new WeakSet<String>();
41
41
42
    static {
42
    static {
43
        // See below.
43
        // See below.
Lines 47-54 Link Here
47
        alreadyReported.add("java.awt.geom.AffineTransform"); // NOI18N
47
        alreadyReported.add("java.awt.geom.AffineTransform"); // NOI18N
48
    }
48
    }
49
49
50
    private static Map examinedClasses = new WeakHashMap(250); // Map<String,Boolean>
50
    private static Map<String,Boolean> examinedClasses = new WeakHashMap<String,Boolean>(250);
51
    private final List serializing = new ArrayList(50); // List<Class>
51
    private final List<Class> serializing = new ArrayList<Class>(50);
52
52
53
    /** Create a new object output.
53
    /** Create a new object output.
54
    * @param os the underlying output stream
54
    * @param os the underlying output stream
Lines 134-140 Link Here
134
        String classname = cl.getName();
134
        String classname = cl.getName();
135
135
136
        if (alreadyReported.add(classname)) {
136
        if (alreadyReported.add(classname)) {
137
            Set serializingUniq = new HashSet(); // Set<Class>
137
            Set<Class> serializingUniq = new HashSet<Class>();
138
            StringBuffer b = new StringBuffer("Serializable class "); // NOI18N
138
            StringBuffer b = new StringBuffer("Serializable class "); // NOI18N
139
            b.append(classname);
139
            b.append(classname);
140
            b.append(" does not declare serialVersionUID field. Encountered while storing: ["); // NOI18N
140
            b.append(" does not declare serialVersionUID field. Encountered while storing: ["); // NOI18N
(-)openide/util/src/org/openide/util/lookup/ALPairComparator.java (-6 / +4 lines)
Lines 13-26 Link Here
13
package org.openide.util.lookup;
13
package org.openide.util.lookup;
14
14
15
import java.util.Comparator;
15
import java.util.Comparator;
16
import org.openide.util.lookup.AbstractLookup.Pair;
16
17
17
18
18
/** Implementation of comparator for AbstractLookup.Pair
19
/** Implementation of comparator for AbstractLookup.Pair
19
 *
20
 *
20
 * @author  Jaroslav Tulach
21
 * @author  Jaroslav Tulach
21
 */
22
 */
22
final class ALPairComparator implements Comparator {
23
final class ALPairComparator implements Comparator<Pair<?>> {
23
    public static final Comparator DEFAULT = new ALPairComparator();
24
    public static final Comparator<Pair<?>> DEFAULT = new ALPairComparator();
24
25
25
    /** Creates a new instance of ALPairComparator */
26
    /** Creates a new instance of ALPairComparator */
26
    private ALPairComparator() {
27
    private ALPairComparator() {
Lines 28-37 Link Here
28
29
29
    /** Compares two items.
30
    /** Compares two items.
30
    */
31
    */
31
    public int compare(Object obj, Object obj1) {
32
    public int compare(Pair<?> i1, Pair<?> i2) {
32
        AbstractLookup.Pair i1 = (AbstractLookup.Pair) obj;
33
        AbstractLookup.Pair i2 = (AbstractLookup.Pair) obj1;
34
35
        int result = i1.getIndex() - i2.getIndex();
33
        int result = i1.getIndex() - i2.getIndex();
36
34
37
        if (result == 0) {
35
        if (result == 0) {
(-)openide/util/src/org/openide/util/lookup/AbstractLookup.java (-175 / +161 lines)
Lines 24-29 Link Here
24
import java.lang.ref.ReferenceQueue;
24
import java.lang.ref.ReferenceQueue;
25
25
26
import java.util.*;
26
import java.util.*;
27
import org.openide.util.Utilities;
27
28
28
29
29
/** Implementation of the lookup from OpenAPIs that is based on the
30
/** Implementation of the lookup from OpenAPIs that is based on the
Lines 40-52 Link Here
40
    /** lock for initialization of the maps of lookups */
41
    /** lock for initialization of the maps of lookups */
41
    private static Object treeLock = new Object();
42
    private static Object treeLock = new Object();
42
43
43
    /** This is a workaround for bug 35366 that probably has to be here until
44
     * we end producing separate openide-lookup.jar. The activeReferenceQueue
45
     * has to be obtained using reflection to prevent the openide-lookup.jar
46
     * to be as large as openide-util.jar.
47
     */
48
    private static Object activeQueue;
49
50
    /** the tree that registers all items (or Integer as a treshold size) */
44
    /** the tree that registers all items (or Integer as a treshold size) */
51
    private Object tree;
45
    private Object tree;
52
46
Lines 68-74 Link Here
68
    /** Constructor for testing purposes that allows specification of storage
62
    /** Constructor for testing purposes that allows specification of storage
69
     * as mechanism as well.
63
     * as mechanism as well.
70
     */
64
     */
71
    AbstractLookup(Content content, Storage storage) {
65
    AbstractLookup(Content content, Storage<?> storage) {
72
        this(content);
66
        this(content);
73
        this.tree = storage;
67
        this.tree = storage;
74
        initialize();
68
        initialize();
Lines 90-96 Link Here
90
84
91
    public String toString() {
85
    public String toString() {
92
        if (tree instanceof Storage) {
86
        if (tree instanceof Storage) {
93
            return "AbstractLookup" + lookup(new Lookup.Template(Object.class)).allItems(); // NOI18N
87
            return "AbstractLookup" + lookup(new Lookup.Template<Object>(Object.class)).allItems(); // NOI18N
94
        } else {
88
        } else {
95
            return super.toString();
89
            return super.toString();
96
        }
90
        }
Lines 98-104 Link Here
98
92
99
    /** Entres the storage management system.
93
    /** Entres the storage management system.
100
     */
94
     */
101
    private AbstractLookup.Storage enterStorage() {
95
    @SuppressWarnings("unchecked")
96
    private <T> AbstractLookup.Storage<T> enterStorage() {
102
        for (;;) {
97
        for (;;) {
103
            synchronized (treeLock) {
98
            synchronized (treeLock) {
104
                if (tree instanceof AbstractLookup.Storage) {
99
                if (tree instanceof AbstractLookup.Storage) {
Lines 119-127 Link Here
119
                        continue;
114
                        continue;
120
                    } else {
115
                    } else {
121
                        // ok, tree is initialized and nobody is using it yet
116
                        // ok, tree is initialized and nobody is using it yet
122
                        tree = new DelegatingStorage((Storage) tree);
117
                        tree = new DelegatingStorage((Storage<T>) tree);
123
118
124
                        return (Storage) tree;
119
                        return (Storage<T>) tree;
125
                    }
120
                    }
126
                }
121
                }
127
122
Lines 158-174 Link Here
158
    /** Notifies subclasses that a query is about to be processed.
153
    /** Notifies subclasses that a query is about to be processed.
159
     * @param template the template
154
     * @param template the template
160
     */
155
     */
161
    protected void beforeLookup(Template template) {
156
    protected void beforeLookup(Template<?> template) {
162
    }
157
    }
163
158
164
    /** The method to add instance to the lookup with.
159
    /** The method to add instance to the lookup with.
165
     * @param pair class/instance pair
160
     * @param pair class/instance pair
166
     */
161
     */
167
    protected final void addPair(Pair pair) {
162
    protected final void addPair(Pair<?> pair) {
168
        HashSet toNotify = new HashSet();
163
        addPairImpl(pair);
164
    }
165
166
    private final <Transaction> void addPairImpl(Pair<?> pair) {
167
        HashSet<R> toNotify = new HashSet<R>();
169
168
170
        Object transaction = null;
169
        AbstractLookup.Storage<Transaction> t = enterStorage();
171
        AbstractLookup.Storage t = enterStorage();
170
        Transaction transaction = null;
172
171
173
        try {
172
        try {
174
            transaction = t.beginTransaction(-2);
173
            transaction = t.beginTransaction(-2);
Lines 188-194 Link Here
188
                t.endTransaction(transaction, toNotify);
187
                t.endTransaction(transaction, toNotify);
189
            } else {
188
            } else {
190
                // just finish the process by calling endTransaction
189
                // just finish the process by calling endTransaction
191
                t.endTransaction(transaction, new HashSet());
190
                t.endTransaction(transaction, new HashSet<R>());
192
            }
191
            }
193
        } finally {
192
        } finally {
194
            exitStorage();
193
            exitStorage();
Lines 200-210 Link Here
200
    /** Remove instance.
199
    /** Remove instance.
201
     * @param pair class/instance pair
200
     * @param pair class/instance pair
202
     */
201
     */
203
    protected final void removePair(Pair pair) {
202
    protected final void removePair(Pair<?> pair) {
204
        HashSet toNotify = new HashSet();
203
        removePairImpl(pair);
204
    }
205
206
    private <Transaction> void removePairImpl(Pair<?> pair) {
207
        HashSet<R> toNotify = new HashSet<R>();
205
208
206
        Object transaction = null;
209
        AbstractLookup.Storage<Transaction> t = enterStorage();
207
        AbstractLookup.Storage t = enterStorage();
210
        Transaction transaction = null;
208
211
209
        try {
212
        try {
210
            transaction = t.beginTransaction(-1);
213
            transaction = t.beginTransaction(-1);
Lines 220-243 Link Here
220
    /** Changes all pairs in the lookup to new values.
223
    /** Changes all pairs in the lookup to new values.
221
     * @param collection the collection of (Pair) objects
224
     * @param collection the collection of (Pair) objects
222
     */
225
     */
223
    protected final void setPairs(Collection collection) {
226
    protected final void setPairs(Collection<? extends Pair> collection) {
224
        notifyCollectedListeners(setPairsAndCollectListeners(collection));
227
        notifyCollectedListeners(setPairsAndCollectListeners(collection));
225
    }
228
    }
226
    
229
    
227
    /** Getter for set of pairs. Package private contract with MetaInfServicesLookup.
230
    /** Getter for set of pairs. Package private contract with MetaInfServicesLookup.
228
     * @return a LinkedHashSet that can be modified
231
     * @return a LinkedHashSet that can be modified
229
     */
232
     */
230
    final LinkedHashSet getPairsAsLHS() {
233
    final LinkedHashSet<Pair<?>> getPairsAsLHS() {
231
        AbstractLookup.Storage t = enterStorage();
234
        AbstractLookup.Storage<?> t = enterStorage();
232
235
233
        try {
236
        try {
234
            Enumeration en = t.lookup(Object.class);
237
            Enumeration<Pair<Object>> en = t.lookup(Object.class);
235
			LinkedHashSet arr = new LinkedHashSet();
238
            LinkedHashSet<Pair<?>> arr = new LinkedHashSet<Pair<?>>();
236
            while (en.hasMoreElements()) {
239
            while (en.hasMoreElements()) {
237
                Pair item = (Pair) en.nextElement();
240
                Pair<Object> item = en.nextElement();
238
				arr.add(item);
241
                arr.add(item);
239
            }
242
            }
240
			return arr;
243
            return arr;
241
        } finally {
244
        } finally {
242
            exitStorage();
245
            exitStorage();
243
        }
246
        }
Lines 246-260 Link Here
246
    /** Collects listeners without notification. Needed in MetaInfServicesLookup
249
    /** Collects listeners without notification. Needed in MetaInfServicesLookup
247
     * right now, but maybe will become an API later.
250
     * right now, but maybe will become an API later.
248
     */
251
     */
249
    final HashSet setPairsAndCollectListeners(Collection collection) {
252
    final <Transaction> HashSet<R> setPairsAndCollectListeners(Collection<? extends Pair> collection) {
250
        HashSet toNotify = new HashSet(27);
253
        HashSet<R> toNotify = new HashSet<R>(27);
251
254
252
        Object transaction = null;
255
        AbstractLookup.Storage<Transaction> t = enterStorage();
253
        AbstractLookup.Storage t = enterStorage();
256
        Transaction transaction = null;
254
257
255
        try {
258
        try {
256
            // map between the Items and their indexes (Integer)
259
            // map between the Items and their indexes (Integer)
257
            HashMap shouldBeThere = new HashMap(collection.size() * 2);
260
            HashMap<Item<?>,Info> shouldBeThere = new HashMap<Item<?>,Info>(collection.size() * 2);
258
261
259
            count = 0;
262
            count = 0;
260
263
Lines 311-318 Link Here
311
    /** Notifies all collected listeners. Needed by MetaInfServicesLookup,
314
    /** Notifies all collected listeners. Needed by MetaInfServicesLookup,
312
     * maybe it will be an API later.
315
     * maybe it will be an API later.
313
     */
316
     */
314
    final void notifyCollectedListeners(Object listeners) {
317
    final void notifyCollectedListeners(Set<R> listeners) {
315
        notifyListeners((HashSet) listeners);
318
        notifyListeners(listeners);
316
    }
319
    }
317
320
318
    private final void writeObject(ObjectOutputStream oos)
321
    private final void writeObject(ObjectOutputStream oos)
Lines 330-349 Link Here
330
        }
333
        }
331
    }
334
    }
332
335
333
    public final Object lookup(Class clazz) {
336
    public final <T> T lookup(Class<T> clazz) {
334
        Lookup.Item item = lookupItem(new Lookup.Template(clazz));
337
        Lookup.Item<T> item = lookupItem(new Lookup.Template<T>(clazz));
335
336
        return (item == null) ? null : item.getInstance();
338
        return (item == null) ? null : item.getInstance();
337
    }
339
    }
338
340
339
    public final Lookup.Item lookupItem(Lookup.Template template) {
341
    public final <T> Lookup.Item<T> lookupItem(Lookup.Template<T> template) {
340
        AbstractLookup.this.beforeLookup(template);
342
        AbstractLookup.this.beforeLookup(template);
341
343
342
        ArrayList list = null;
344
        ArrayList<Pair<T>> list = null;
343
        AbstractLookup.Storage t = enterStorage();
345
        AbstractLookup.Storage<?> t = enterStorage();
344
346
345
        try {
347
        try {
346
            Enumeration en;
348
            Enumeration<Pair<T>> en;
347
349
348
            try {
350
            try {
349
                en = t.lookup(template.getType());
351
                en = t.lookup(template.getType());
Lines 352-358 Link Here
352
            } catch (AbstractLookup.ISE ex) {
354
            } catch (AbstractLookup.ISE ex) {
353
                // not possible to enumerate the exception, ok, copy it 
355
                // not possible to enumerate the exception, ok, copy it 
354
                // to create new
356
                // to create new
355
                list = new ArrayList();
357
                list = new ArrayList<Pair<T>>();
356
                en = t.lookup(null); // this should get all the items without any checks
358
                en = t.lookup(null); // this should get all the items without any checks
357
359
358
                // the checks will be done out side of the storage
360
                // the checks will be done out side of the storage
Lines 367-378 Link Here
367
        return findSmallest(Collections.enumeration(list), template, true);
369
        return findSmallest(Collections.enumeration(list), template, true);
368
    }
370
    }
369
371
370
    private static Pair findSmallest(Enumeration en, Lookup.Template template, boolean deepCheck) {
372
    private static <T> Pair<T> findSmallest(Enumeration<Pair<T>> en, Lookup.Template<T> template, boolean deepCheck) {
371
        int smallest = InheritanceTree.unsorted(en) ? Integer.MAX_VALUE : Integer.MIN_VALUE;
373
        int smallest = InheritanceTree.unsorted(en) ? Integer.MAX_VALUE : Integer.MIN_VALUE;
372
        Pair res = null;
374
        Pair<T> res = null;
373
375
374
        while (en.hasMoreElements()) {
376
        while (en.hasMoreElements()) {
375
            Pair item = (Pair) en.nextElement();
377
            Pair<T> item = en.nextElement();
376
378
377
            if (matches(template, item, deepCheck)) {
379
            if (matches(template, item, deepCheck)) {
378
                if (smallest == Integer.MIN_VALUE) {
380
                if (smallest == Integer.MIN_VALUE) {
Lines 391-405 Link Here
391
        return res;
393
        return res;
392
    }
394
    }
393
395
394
    public final Lookup.Result lookup(Lookup.Template template) {
396
    public final <T> Lookup.Result<T> lookup(Lookup.Template<T> template) {
395
        for (;;) {
397
        for (;;) {
396
            AbstractLookup.ISE toRun = null;
398
            AbstractLookup.ISE toRun = null;
397
399
398
            AbstractLookup.Storage t = enterStorage();
400
            AbstractLookup.Storage<?> t = enterStorage();
399
401
400
            try {
402
            try {
401
                R r = new R();
403
                R<T> r = new R<T>();
402
                ReferenceToResult newRef = new ReferenceToResult(r, this, template);
404
                ReferenceToResult<T> newRef = new ReferenceToResult<T>(r, this, template);
403
                newRef.next = t.registerReferenceToResult(newRef);
405
                newRef.next = t.registerReferenceToResult(newRef);
404
406
405
                return r;
407
                return r;
Lines 418-433 Link Here
418
    /** Notifies listeners.
420
    /** Notifies listeners.
419
     * @param allAffectedResults set of R
421
     * @param allAffectedResults set of R
420
     */
422
     */
421
    private static void notifyListeners(Set allAffectedResults) {
423
    private static void notifyListeners(Set<R> allAffectedResults) {
422
        if (allAffectedResults.isEmpty()) {
424
        if (allAffectedResults.isEmpty()) {
423
            return;
425
            return;
424
        }
426
        }
425
427
426
        ArrayList evAndListeners = new ArrayList();
428
        ArrayList<Object> evAndListeners = new ArrayList<Object>();
427
        {
429
        {
428
            Iterator it = allAffectedResults.iterator();
430
            for (R<?> result : allAffectedResults) {
429
            while(it.hasNext()) {
430
                AbstractLookup.R result = (AbstractLookup.R) it.next();
431
                result.collectFires(evAndListeners);
431
                result.collectFires(evAndListeners);
432
            }
432
            }
433
        }
433
        }
Lines 449-462 Link Here
449
     *        objects on even positions and the listeners on odd positions
449
     *        objects on even positions and the listeners on odd positions
450
     * @param ev the event to fire
450
     * @param ev the event to fire
451
     */
451
     */
452
    static void notifyListeners(Object[] listeners, LookupEvent ev, Collection evAndListeners) {
452
    static void notifyListeners(Object[] listeners, LookupEvent ev, Collection<Object> evAndListeners) {
453
        for (int i = listeners.length - 1; i >= 0; i -= 2) {
453
        for (int i = listeners.length - 1; i >= 0; i -= 2) {
454
            LookupListener ll = (LookupListener) listeners[i];
454
            LookupListener ll = (LookupListener) listeners[i];
455
455
456
            try {
456
            try {
457
                if (evAndListeners != null) {
457
                if (evAndListeners != null) {
458
                    if (ll instanceof WaitableResult) {
458
                    if (ll instanceof WaitableResult) {
459
                        WaitableResult wr = (WaitableResult)ll;
459
                        WaitableResult<?> wr = (WaitableResult<?>)ll;
460
                        wr.collectFires(evAndListeners);
460
                        wr.collectFires(evAndListeners);
461
                    } else {
461
                    } else {
462
                        evAndListeners.add(ev);
462
                        evAndListeners.add(ev);
Lines 478-484 Link Here
478
     * @param deepCheck true if type of the pair should be tested, false if it is already has been tested
478
     * @param deepCheck true if type of the pair should be tested, false if it is already has been tested
479
     * @return true if item matches the template requirements, false if not
479
     * @return true if item matches the template requirements, false if not
480
     */
480
     */
481
    static boolean matches(Template t, Pair item, boolean deepCheck) {
481
    static boolean matches(Template<?> t, Pair<?> item, boolean deepCheck) {
482
        String id = t.getId();
482
        String id = t.getId();
483
483
484
        if ((id != null) && !item.getId().equals(id)) {
484
        if ((id != null) && !item.getId().equals(id)) {
Lines 546-553 Link Here
546
     * @param template the template the result was for
546
     * @param template the template the result was for
547
     * @return true if the hash map with all items has been cleared
547
     * @return true if the hash map with all items has been cleared
548
     */
548
     */
549
    boolean cleanUpResult(Lookup.Template template) {
549
    <T> boolean cleanUpResult(Lookup.Template<T> template) {
550
        AbstractLookup.Storage t = enterStorage();
550
        AbstractLookup.Storage<?> t = enterStorage();
551
551
552
        try {
552
        try {
553
            return t.cleanUpResult(template) == null;
553
            return t.cleanUpResult(template) == null;
Lines 563-568 Link Here
563
     * @param ref the value of the reference to listener or listener list
563
     * @param ref the value of the reference to listener or listener list
564
     * @return new value to the reference to listener or list
564
     * @return new value to the reference to listener or list
565
     */
565
     */
566
    @SuppressWarnings("unchecked")
566
    static Object modifyListenerList(boolean add, LookupListener l, Object ref) {
567
    static Object modifyListenerList(boolean add, LookupListener l, Object ref) {
567
        if (add) {
568
        if (add) {
568
            if (ref == null) {
569
            if (ref == null) {
Lines 599-623 Link Here
599
        }
600
        }
600
    }
601
    }
601
602
602
    private static ReferenceQueue activeQueue() {
603
    private static ReferenceQueue<Object> activeQueue() {
603
        if (activeQueue == null) {
604
        return Utilities.activeReferenceQueue();
604
            try {
605
                Class c = Class.forName("org.openide.util.Utilities"); // NOI18N
606
                Class[] noArgs = new Class[0];
607
                java.lang.reflect.Method m = c.getDeclaredMethod("activeReferenceQueue", noArgs); // NOI18N
608
                activeQueue = m.invoke(null, noArgs);
609
            } catch (Exception ex) {
610
                activeQueue = ex;
611
            }
612
        }
613
614
        return (activeQueue instanceof ReferenceQueue) ? (ReferenceQueue) activeQueue : null;
615
    }
605
    }
616
606
617
    /** Storage to keep the internal structure of Pairs and to answer
607
    /** Storage to keep the internal structure of Pairs and to answer
618
     * different queries.
608
     * different queries.
619
     */
609
     */
620
    interface Storage {
610
    interface Storage<Transaction> {
621
        /** Initializes a modification operation by creating an object
611
        /** Initializes a modification operation by creating an object
622
         * that will be passsed to all add, remove, retainAll methods
612
         * that will be passsed to all add, remove, retainAll methods
623
         * and should collect enough information about the change to
613
         * and should collect enough information about the change to
Lines 628-634 Link Here
628
         *   the amount of objects at the end
618
         *   the amount of objects at the end
629
         * @return a token to identify the transaction
619
         * @return a token to identify the transaction
630
         */
620
         */
631
        public Object beginTransaction(int ensure);
621
        public Transaction beginTransaction(int ensure);
632
622
633
        /** Collects all affected results R that were modified in the
623
        /** Collects all affected results R that were modified in the
634
         * given transaction.
624
         * given transaction.
Lines 636-642 Link Here
636
         * @param modified place to add results R to
626
         * @param modified place to add results R to
637
         * @param transaction the transaction indentification
627
         * @param transaction the transaction indentification
638
         */
628
         */
639
        public void endTransaction(Object transaction, Set modifiedResults);
629
        public void endTransaction(Transaction transaction, Set<R> modifiedResults);
640
630
641
        /** Adds an item into the storage.
631
        /** Adds an item into the storage.
642
        * @param item to add
632
        * @param item to add
Lines 644-667 Link Here
644
        * @return true if the Item has been added for the first time or false if some other
634
        * @return true if the Item has been added for the first time or false if some other
645
        *    item equal to this one already existed in the lookup
635
        *    item equal to this one already existed in the lookup
646
        */
636
        */
647
        public boolean add(AbstractLookup.Pair item, Object transaction);
637
        public boolean add(AbstractLookup.Pair<?> item, Transaction transaction);
648
638
649
        /** Removes an item.
639
        /** Removes an item.
650
        */
640
        */
651
        public void remove(AbstractLookup.Pair item, Object transaction);
641
        public void remove(AbstractLookup.Pair item, Transaction transaction);
652
642
653
        /** Removes all items that are not present in the provided collection.
643
        /** Removes all items that are not present in the provided collection.
654
        * @param retain collection of Pairs to keep them in
644
        * @param retain collection of Pairs to keep them in
655
        * @param transaction the transaction context
645
        * @param transaction the transaction context
656
        */
646
        */
657
        public void retainAll(Map retain, Object transaction);
647
        public void retainAll(Map retain, Transaction transaction);
658
648
659
        /** Queries for instances of given class.
649
        /** Queries for instances of given class.
660
        * @param clazz the class to check
650
        * @param clazz the class to check
661
        * @return enumeration of Item
651
        * @return enumeration of Item
662
        * @see #unsorted
652
        * @see #unsorted
663
        */
653
        */
664
        public Enumeration lookup(Class clazz);
654
        public <T> Enumeration<Pair<T>> lookup(Class<T> clazz);
665
655
666
        /** Registers another reference to a result with the storage. This method
656
        /** Registers another reference to a result with the storage. This method
667
         * has also a special meaning.
657
         * has also a special meaning.
Lines 671-689 Link Here
671
         *    the applications is expected to link from newRef to this returned
661
         *    the applications is expected to link from newRef to this returned
672
         *    value to form a linked list
662
         *    value to form a linked list
673
         */
663
         */
674
        public ReferenceToResult registerReferenceToResult(ReferenceToResult newRef);
664
        public ReferenceToResult<?> registerReferenceToResult(ReferenceToResult<?> newRef);
675
665
676
        /** Given the provided template, Do cleanup the results.
666
        /** Given the provided template, Do cleanup the results.
677
         * @param templ template of a result(s) that should be checked
667
         * @param templ template of a result(s) that should be checked
678
         * @return null if all references for this template were cleared or one of them
668
         * @return null if all references for this template were cleared or one of them
679
         */
669
         */
680
        public ReferenceToResult cleanUpResult(Lookup.Template templ);
670
        public ReferenceToResult<?> cleanUpResult(Lookup.Template<?> templ);
681
    }
671
    }
682
672
683
    /** Extension to the default lookup item that offers additional information
673
    /** Extension to the default lookup item that offers additional information
684
     * for the data structures use in AbstractLookup
674
     * for the data structures use in AbstractLookup
685
     */
675
     */
686
    public static abstract class Pair extends Lookup.Item implements Serializable {
676
    public static abstract class Pair<T> extends Lookup.Item<T> implements Serializable {
687
        private static final long serialVersionUID = 1L;
677
        private static final long serialVersionUID = 1L;
688
678
689
        /** possition of this item in the lookup, manipulated in addPair, removePair, setPairs methods */
679
        /** possition of this item in the lookup, manipulated in addPair, removePair, setPairs methods */
Lines 697-703 Link Here
697
            return index;
687
            return index;
698
        }
688
        }
699
689
700
        final void setIndex(AbstractLookup.Storage tree, int x) {
690
        final void setIndex(AbstractLookup.Storage<?> tree, int x) {
701
            if (tree == null) {
691
            if (tree == null) {
702
                this.index = x;
692
                this.index = x;
703
693
Lines 714-720 Link Here
714
        /** Tests whether this item can produce object
704
        /** Tests whether this item can produce object
715
        * of class c.
705
        * of class c.
716
        */
706
        */
717
        protected abstract boolean instanceOf(Class c);
707
        protected abstract boolean instanceOf(Class<?> c);
718
708
719
        /** Method that can test whether an instance of a class has been created
709
        /** Method that can test whether an instance of a class has been created
720
         * by this item.
710
         * by this item.
Lines 728-736 Link Here
728
718
729
    /** Result based on one instance returned.
719
    /** Result based on one instance returned.
730
     */
720
     */
731
    static final class R extends WaitableResult {
721
    static final class R<T> extends WaitableResult<T> {
732
        /** reference our result is attached to (do not modify) */
722
        /** reference our result is attached to (do not modify) */
733
        public ReferenceToResult reference;
723
        public ReferenceToResult<T> reference;
734
724
735
        /** listeners on the results or pointer to one listener */
725
        /** listeners on the results or pointer to one listener */
736
        private Object listeners;
726
        private Object listeners;
Lines 766-773 Link Here
766
            return null;
756
            return null;
767
        }
757
        }
768
758
769
        private Set getClassesCache() {
759
        @SuppressWarnings("unchecked")
770
            return (Set) getFromCache(0);
760
        private Set<Class<? extends T>> getClassesCache() {
761
            return (Set<Class<? extends T>>) getFromCache(0);
771
        }
762
        }
772
763
773
        private void setClassesCache(Set s) {
764
        private void setClassesCache(Set s) {
Lines 785-792 Link Here
785
            ((Object[]) reference.caches)[0] = s;
776
            ((Object[]) reference.caches)[0] = s;
786
        }
777
        }
787
778
788
        private Collection getInstancesCache() {
779
        @SuppressWarnings("unchecked")
789
            return (Collection) getFromCache(1);
780
        private Collection<T> getInstancesCache() {
781
            return (Collection<T>) getFromCache(1);
790
        }
782
        }
791
783
792
        private void setInstancesCache(Collection c) {
784
        private void setInstancesCache(Collection c) {
Lines 804-814 Link Here
804
            ((Object[]) reference.caches)[1] = c;
796
            ((Object[]) reference.caches)[1] = c;
805
        }
797
        }
806
798
807
        private Object[] getItemsCache() {
799
        @SuppressWarnings("unchecked")
808
            return (Object[]) getFromCache(2);
800
        private Pair<T>[] getItemsCache() {
801
            return (Pair<T>[]) getFromCache(2);
809
        }
802
        }
810
803
811
        private void setItemsCache(Collection c) {
804
        private void setItemsCache(Collection<?> c) {
812
            if (isSimple()) {
805
            if (isSimple()) {
813
                // mark it as being used
806
                // mark it as being used
814
                reference.caches = reference;
807
                reference.caches = reference;
Lines 820-826 Link Here
820
                reference.caches = new Object[3];
813
                reference.caches = new Object[3];
821
            }
814
            }
822
815
823
            ((Object[]) reference.caches)[2] = c.toArray();
816
            ((Object[]) reference.caches)[2] = c.toArray(new Pair[0]);
824
        }
817
        }
825
818
826
        private void clearCaches() {
819
        private void clearCaches() {
Lines 843-849 Link Here
843
836
844
        /** Delete all cached values, the template changed.
837
        /** Delete all cached values, the template changed.
845
         */
838
         */
846
        protected  void collectFires(Collection evAndListeners) {
839
        protected  void collectFires(Collection<Object> evAndListeners) {
847
            Object[] previousItems = getItemsCache();
840
            Object[] previousItems = getItemsCache();
848
            clearCaches();
841
            clearCaches();
849
            
842
            
Lines 866-873 Link Here
866
                if (listeners instanceof LookupListener) {
859
                if (listeners instanceof LookupListener) {
867
                    arr = new LookupListener[] { (LookupListener) listeners };
860
                    arr = new LookupListener[] { (LookupListener) listeners };
868
                } else {
861
                } else {
869
                    ArrayList l = (ArrayList) listeners;
862
                    ArrayList<?> l = (ArrayList<?>) listeners;
870
                    arr = (LookupListener[]) l.toArray(new LookupListener[l.size()]);
863
                    arr = l.toArray(new LookupListener[l.size()]);
871
                }
864
                }
872
            }
865
            }
873
866
Lines 876-905 Link Here
876
            notifyListeners(ll, ev, evAndListeners);
869
            notifyListeners(ll, ev, evAndListeners);
877
        }
870
        }
878
871
879
        public Collection allInstances() {
872
        public Collection<T> allInstances() {
880
            reference.lookup.beforeLookup(reference.template);
873
            reference.lookup.beforeLookup(reference.template);
881
874
882
            Collection s = getInstancesCache();
875
            Collection<T> s = getInstancesCache();
883
876
884
            if (s != null) {
877
            if (s != null) {
885
                return s;
878
                return s;
886
            }
879
            }
887
880
888
            Collection items = allItemsWithoutBeforeLookup();
881
            Collection<Pair<T>> items = allItemsWithoutBeforeLookup();
889
            s = new ArrayList(items.size());
882
            ArrayList<T> list = new ArrayList<T>(items.size());
890
883
891
            Iterator it = items.iterator();
884
            Iterator<Pair<T>> it = items.iterator();
892
885
893
            while (it.hasNext()) {
886
            while (it.hasNext()) {
894
                Pair item = (Pair) it.next();
887
                Pair<T> item = it.next();
895
                Object obj = item.getInstance();
888
                T obj = item.getInstance();
896
889
897
                if (reference.template.getType().isInstance(obj)) {
890
                if (reference.template.getType().isInstance(obj)) {
898
                    s.add(obj);
891
                    list.add(obj);
899
                }
892
                }
900
            }
893
            }
901
            
894
            
902
            s = Collections.unmodifiableList((ArrayList)s);
895
            s = Collections.unmodifiableList(list);
903
            setInstancesCache(s);
896
            setInstancesCache(s);
904
897
905
            return s;
898
            return s;
Lines 908-929 Link Here
908
        /** Set of all classes.
901
        /** Set of all classes.
909
         *
902
         *
910
         */
903
         */
911
        public Set allClasses() {
904
        public Set<Class<? extends T>> allClasses() {
912
            reference.lookup.beforeLookup(reference.template);
905
            reference.lookup.beforeLookup(reference.template);
913
906
914
            Set s = getClassesCache();
907
            Set<Class<? extends T>> s = getClassesCache();
915
908
916
            if (s != null) {
909
            if (s != null) {
917
                return s;
910
                return s;
918
            }
911
            }
919
912
920
            s = new HashSet();
913
            s = new HashSet<Class<? extends T>>();
921
914
922
            Iterator it = allItemsWithoutBeforeLookup().iterator();
915
            for (Pair<T> item : allItemsWithoutBeforeLookup()) {
923
916
                Class<? extends T> clazz = item.getType();
924
            while (it.hasNext()) {
925
                Item item = (Item) it.next();
926
                Class clazz = item.getType();
927
917
928
                if (clazz != null) {
918
                if (clazz != null) {
929
                    s.add(clazz);
919
                    s.add(clazz);
Lines 938-959 Link Here
938
928
939
        /** Items are stored directly in the allItems.
929
        /** Items are stored directly in the allItems.
940
         */
930
         */
941
        public Collection allItems() {
931
        public Collection<? extends Item<T>> allItems() {
942
            reference.lookup.beforeLookup(reference.template);
932
            reference.lookup.beforeLookup(reference.template);
943
933
944
            return allItemsWithoutBeforeLookup();
934
            return allItemsWithoutBeforeLookup();
945
        }
935
        }
946
936
947
        /** Implements the search for allItems, but without asking for before lookup */
937
        /** Implements the search for allItems, but without asking for before lookup */
948
        private Collection allItemsWithoutBeforeLookup() {
938
        private Collection<Pair<T>> allItemsWithoutBeforeLookup() {
949
            Object[] c = getItemsCache();
939
            Pair<T>[] c = getItemsCache();
950
940
951
            if (c != null) {
941
            if (c != null) {
952
                return Collections.unmodifiableList(Arrays.asList(c));
942
                return Collections.unmodifiableList(Arrays.asList(c));
953
            }
943
            }
954
944
955
            ArrayList saferCheck = null;
945
            ArrayList<Pair<Object>> saferCheck = null;
956
            AbstractLookup.Storage t = reference.lookup.enterStorage();
946
            AbstractLookup.Storage<?> t = reference.lookup.enterStorage();
957
947
958
            try {
948
            try {
959
                try {
949
                try {
Lines 961-1007 Link Here
961
                } catch (AbstractLookup.ISE ex) {
951
                } catch (AbstractLookup.ISE ex) {
962
                    // do less effective evaluation of items outside of the 
952
                    // do less effective evaluation of items outside of the 
963
                    // locked storage
953
                    // locked storage
964
                    saferCheck = new ArrayList();
954
                    saferCheck = new ArrayList<Pair<Object>>();
965
955
966
                    Enumeration en = t.lookup(null); // get all Pairs
956
                    Enumeration<Pair<Object>> en = t.lookup(null); // get all Pairs
967
957
968
                    while (en.hasMoreElements()) {
958
                    while (en.hasMoreElements()) {
969
                        Pair i = (Pair) en.nextElement();
959
                        Pair<Object> i = en.nextElement();
970
                        ;
971
                        saferCheck.add(i);
960
                        saferCheck.add(i);
972
                    }
961
                    }
973
                }
962
                }
974
            } finally {
963
            } finally {
975
                reference.lookup.exitStorage();
964
                reference.lookup.exitStorage();
976
            }
965
            }
966
            return extractPairs(saferCheck);
967
        }
977
968
978
            Iterator it = saferCheck.iterator();
969
        @SuppressWarnings("unchecked")
979
970
        private Collection<Pair<T>> extractPairs(final ArrayList<Pair<Object>> saferCheck) {
980
            // InheritanceTree is comparator for AbstractLookup.Pairs
971
            TreeSet<Pair<T>> items = new TreeSet<Pair<T>>(ALPairComparator.DEFAULT);
981
            TreeSet items = new TreeSet(ALPairComparator.DEFAULT);
972
            for (Pair<Object> i : saferCheck) {
982
983
            while (it.hasNext()) {
984
                Pair i = (Pair) it.next();
985
986
                if (matches(reference.template, i, false)) {
973
                if (matches(reference.template, i, false)) {
987
                    items.add(i);
974
                    items.add((Pair<T>)i);
988
                }
975
                }
989
            }
976
            }
990
991
            return Collections.unmodifiableCollection(items);
977
            return Collections.unmodifiableCollection(items);
992
        }
978
        }
993
979
994
        /** Initializes items.
980
        /** Initializes items.
995
         */
981
         */
996
        private Collection initItems(Storage t) {
982
        private Collection<Pair<T>> initItems(Storage<?> t) {
997
            // manipulation with the tree must be synchronized
983
            // manipulation with the tree must be synchronized
998
            Enumeration en = t.lookup(reference.template.getType());
984
            Enumeration<Pair<T>> en = t.lookup(reference.template.getType());
999
985
1000
            // InheritanceTree is comparator for AbstractLookup.Pairs
986
            // InheritanceTree is comparator for AbstractLookup.Pairs
1001
            TreeSet items = new TreeSet(ALPairComparator.DEFAULT);
987
            TreeSet<Pair<T>> items = new TreeSet<Pair<T>>(ALPairComparator.DEFAULT);
1002
988
1003
            while (en.hasMoreElements()) {
989
            while (en.hasMoreElements()) {
1004
                Pair i = (Pair) en.nextElement();
990
                Pair<T> i = en.nextElement();
1005
991
1006
                if (matches(reference.template, i, false)) {
992
                if (matches(reference.template, i, false)) {
1007
                    items.add(i);
993
                    items.add(i);
Lines 1046-1052 Link Here
1046
1032
1047
        /** abstract lookup we are connected to */
1033
        /** abstract lookup we are connected to */
1048
        private AbstractLookup al = null;
1034
        private AbstractLookup al = null;
1049
        private transient ArrayList earlyPairs;
1035
        private transient ArrayList<Pair> earlyPairs;
1050
1036
1051
        /** A lookup attaches to this object.
1037
        /** A lookup attaches to this object.
1052
         */
1038
         */
Lines 1056-1065 Link Here
1056
1042
1057
                if (earlyPairs != null) {
1043
                if (earlyPairs != null) {
1058
                    // we must just add no override!
1044
                    // we must just add no override!
1059
                    Pair[] p = (Pair[]) earlyPairs.toArray(new Pair[earlyPairs.size()]);
1045
                    for (Pair<?> p : earlyPairs) {
1060
1046
                        addPair(p);
1061
                    for (int i = 0; i < p.length; i++) {
1062
                        addPair(p[i]);
1063
                    }
1047
                    }
1064
                }
1048
                }
1065
1049
Lines 1074-1087 Link Here
1074
        /** The method to add instance to the lookup with.
1058
        /** The method to add instance to the lookup with.
1075
         * @param pair class/instance pair
1059
         * @param pair class/instance pair
1076
         */
1060
         */
1077
        public final void addPair(Pair pair) {
1061
        public final void addPair(Pair<?> pair) {
1078
            AbstractLookup a = al;
1062
            AbstractLookup a = al;
1079
1063
1080
            if (a != null) {
1064
            if (a != null) {
1081
                a.addPair(pair);
1065
                a.addPair(pair);
1082
            } else {
1066
            } else {
1083
                if (earlyPairs == null) {
1067
                if (earlyPairs == null) {
1084
                    earlyPairs = new ArrayList(3);
1068
                    earlyPairs = new ArrayList<Pair>(3);
1085
                }
1069
                }
1086
1070
1087
                earlyPairs.add(pair);
1071
                earlyPairs.add(pair);
Lines 1091-1104 Link Here
1091
        /** Remove instance.
1075
        /** Remove instance.
1092
         * @param pair class/instance pair
1076
         * @param pair class/instance pair
1093
         */
1077
         */
1094
        public final void removePair(Pair pair) {
1078
        public final void removePair(Pair<?> pair) {
1095
            AbstractLookup a = al;
1079
            AbstractLookup a = al;
1096
1080
1097
            if (a != null) {
1081
            if (a != null) {
1098
                a.removePair(pair);
1082
                a.removePair(pair);
1099
            } else {
1083
            } else {
1100
                if (earlyPairs == null) {
1084
                if (earlyPairs == null) {
1101
                    earlyPairs = new ArrayList(3);
1085
                    earlyPairs = new ArrayList<Pair>(3);
1102
                }
1086
                }
1103
1087
1104
                earlyPairs.remove(pair);
1088
                earlyPairs.remove(pair);
Lines 1108-1120 Link Here
1108
        /** Changes all pairs in the lookup to new values.
1092
        /** Changes all pairs in the lookup to new values.
1109
         * @param c the collection of (Pair) objects
1093
         * @param c the collection of (Pair) objects
1110
         */
1094
         */
1111
        public final void setPairs(Collection c) {
1095
        public final void setPairs(Collection<? extends Pair> c) {
1112
            AbstractLookup a = al;
1096
            AbstractLookup a = al;
1113
1097
1114
            if (a != null) {
1098
            if (a != null) {
1115
                a.setPairs(c);
1099
                a.setPairs(c);
1116
            } else {
1100
            } else {
1117
                earlyPairs = new ArrayList(c);
1101
                earlyPairs = new ArrayList<Pair>(c);
1118
            }
1102
            }
1119
        }
1103
        }
1120
    }
1104
    }
Lines 1134-1145 Link Here
1134
1118
1135
    /** Reference to a result R
1119
    /** Reference to a result R
1136
     */
1120
     */
1137
    static final class ReferenceToResult extends WeakReference implements Runnable {
1121
    static final class ReferenceToResult<T> extends WeakReference<R<T>> implements Runnable {
1138
        /** next refernece in chain, modified only from AbstractLookup or this */
1122
        /** next refernece in chain, modified only from AbstractLookup or this */
1139
        private ReferenceToResult next;
1123
        private ReferenceToResult<?> next;
1140
1124
1141
        /** the template for the result */
1125
        /** the template for the result */
1142
        public final Template template;
1126
        public final Template<T> template;
1143
1127
1144
        /** the lookup we are attached to */
1128
        /** the lookup we are attached to */
1145
        public final AbstractLookup lookup;
1129
        public final AbstractLookup lookup;
Lines 1150-1156 Link Here
1150
        /** Creates a weak refernece to a new result R in context of lookup
1134
        /** Creates a weak refernece to a new result R in context of lookup
1151
         * for given template
1135
         * for given template
1152
         */
1136
         */
1153
        private ReferenceToResult(R result, AbstractLookup lookup, Template template) {
1137
        private ReferenceToResult(R<T> result, AbstractLookup lookup, Template<T> template) {
1154
            super(result, activeQueue());
1138
            super(result, activeQueue());
1155
            this.template = template;
1139
            this.template = template;
1156
            this.lookup = lookup;
1140
            this.lookup = lookup;
Lines 1159-1166 Link Here
1159
1143
1160
        /** Returns the result or null
1144
        /** Returns the result or null
1161
         */
1145
         */
1162
        R getResult() {
1146
        R<T> getResult() {
1163
            return (R) get();
1147
            return get();
1164
        }
1148
        }
1165
1149
1166
        /** Cleans the reference. Implements Runnable interface, do not call
1150
        /** Cleans the reference. Implements Runnable interface, do not call
Lines 1173-1184 Link Here
1173
        /** Clones the reference list to given Storage.
1157
        /** Clones the reference list to given Storage.
1174
         * @param storage storage to clone to
1158
         * @param storage storage to clone to
1175
         */
1159
         */
1176
        public void cloneList(AbstractLookup.Storage storage) {
1160
        public void cloneList(AbstractLookup.Storage<?> storage) {
1177
            ReferenceIterator it = new ReferenceIterator(this);
1161
            ReferenceIterator it = new ReferenceIterator(this);
1178
1162
1179
            while (it.next()) {
1163
            while (it.next()) {
1180
                ReferenceToResult current = it.current();
1164
                ReferenceToResult<?> current = it.current();
1181
                ReferenceToResult newRef = new ReferenceToResult(current.getResult(), current.lookup, current.template);
1165
                ReferenceToResult<?> newRef = current.cloneRef();
1182
                newRef.next = storage.registerReferenceToResult(newRef);
1166
                newRef.next = storage.registerReferenceToResult(newRef);
1183
                newRef.caches = current.caches;
1167
                newRef.caches = current.caches;
1184
1168
Lines 1187-1192 Link Here
1187
                }
1171
                }
1188
            }
1172
            }
1189
        }
1173
        }
1174
1175
        private ReferenceToResult<T> cloneRef() {
1176
            return new ReferenceToResult<T>(getResult(), lookup, template);
1177
        }
1190
    }
1178
    }
1191
     // end of ReferenceToResult
1179
     // end of ReferenceToResult
1192
1180
Lines 1200-1221 Link Here
1200
     *  this.ref = it.first (); // remember the first one
1188
     *  this.ref = it.first (); // remember the first one
1201
     */
1189
     */
1202
    static final class ReferenceIterator extends Object {
1190
    static final class ReferenceIterator extends Object {
1203
        private ReferenceToResult first;
1191
        private ReferenceToResult<?> first;
1204
        private ReferenceToResult current;
1192
        private ReferenceToResult<?> current;
1205
1193
1206
        /** hard reference to current result, so it is not GCed meanwhile */
1194
        /** hard reference to current result, so it is not GCed meanwhile */
1207
        private R currentResult;
1195
        private R<?> currentResult;
1208
1196
1209
        /** Initializes the iterator with first reference.
1197
        /** Initializes the iterator with first reference.
1210
         */
1198
         */
1211
        public ReferenceIterator(ReferenceToResult first) {
1199
        public ReferenceIterator(ReferenceToResult<?> first) {
1212
            this.first = first;
1200
            this.first = first;
1213
        }
1201
        }
1214
1202
1215
        /** Moves the current to next possition */
1203
        /** Moves the current to next possition */
1216
        public boolean next() {
1204
        public boolean next() {
1217
            ReferenceToResult prev;
1205
            ReferenceToResult<?> prev;
1218
            ReferenceToResult ref;
1206
            ReferenceToResult<?> ref;
1219
1207
1220
            if (current == null) {
1208
            if (current == null) {
1221
                ref = first;
1209
                ref = first;
Lines 1226-1232 Link Here
1226
            }
1214
            }
1227
1215
1228
            while (ref != null) {
1216
            while (ref != null) {
1229
                R result = (R) ref.get();
1217
                R<?> result = ref.get();
1230
1218
1231
                if (result == null) {
1219
                if (result == null) {
1232
                    if (prev == null) {
1220
                    if (prev == null) {
Lines 1256-1268 Link Here
1256
1244
1257
        /** Access to current reference.
1245
        /** Access to current reference.
1258
         */
1246
         */
1259
        public ReferenceToResult current() {
1247
        public ReferenceToResult<?> current() {
1260
            return current;
1248
            return current;
1261
        }
1249
        }
1262
1250
1263
        /** Access to reference that is supposed to be the first one.
1251
        /** Access to reference that is supposed to be the first one.
1264
         */
1252
         */
1265
        public ReferenceToResult first() {
1253
        public ReferenceToResult<?> first() {
1266
            return first;
1254
            return first;
1267
        }
1255
        }
1268
    }
1256
    }
Lines 1273-1279 Link Here
1273
     */
1261
     */
1274
    static final class ISE extends IllegalStateException {
1262
    static final class ISE extends IllegalStateException {
1275
        /** list of jobs to execute. */
1263
        /** list of jobs to execute. */
1276
        private java.util.List jobs;
1264
        private java.util.List<Job> jobs;
1277
1265
1278
        /** @param msg message
1266
        /** @param msg message
1279
         */
1267
         */
Lines 1286-1292 Link Here
1286
         */
1274
         */
1287
        public void registerJob(Job job) {
1275
        public void registerJob(Job job) {
1288
            if (jobs == null) {
1276
            if (jobs == null) {
1289
                jobs = new java.util.ArrayList();
1277
                jobs = new java.util.ArrayList<Job>();
1290
            }
1278
            }
1291
1279
1292
            jobs.add(job);
1280
            jobs.add(job);
Lines 1300-1315 Link Here
1300
                throw this;
1288
                throw this;
1301
            }
1289
            }
1302
1290
1303
            for (java.util.Iterator it = jobs.iterator(); it.hasNext();) {
1291
            for (Job j : jobs) {
1304
                Job j = (Job) it.next();
1305
                j.before();
1292
                j.before();
1306
            }
1293
            }
1307
1294
1308
            AbstractLookup.Storage s = lookup.enterStorage();
1295
            AbstractLookup.Storage s = lookup.enterStorage();
1309
1296
1310
            try {
1297
            try {
1311
                for (java.util.Iterator it = jobs.iterator(); it.hasNext();) {
1298
                for (Job j : jobs) {
1312
                    Job j = (Job) it.next();
1313
                    j.inside();
1299
                    j.inside();
1314
                }
1300
                }
1315
            } finally {
1301
            } finally {
(-)openide/util/src/org/openide/util/lookup/ArrayStorage.java (-25 / +23 lines)
Lines 19-30 Link Here
19
import java.lang.ref.WeakReference;
19
import java.lang.ref.WeakReference;
20
20
21
import java.util.*;
21
import java.util.*;
22
import org.openide.util.lookup.AbstractLookup.Pair;
22
23
23
24
24
/** ArrayStorage of Pairs from AbstractLookup.
25
/** ArrayStorage of Pairs from AbstractLookup.
25
 * @author  Jaroslav Tulach
26
 * @author  Jaroslav Tulach
26
 */
27
 */
27
final class ArrayStorage extends Object implements AbstractLookup.Storage {
28
final class ArrayStorage extends Object
29
implements AbstractLookup.Storage<ArrayStorage.Transaction> {
28
    /** default trashold */
30
    /** default trashold */
29
    static final Integer DEFAULT_TRASH = new Integer(11);
31
    static final Integer DEFAULT_TRASH = new Integer(11);
30
32
Lines 32-38 Link Here
32
    private Object content;
34
    private Object content;
33
35
34
    /** linked list of refernces to results */
36
    /** linked list of refernces to results */
35
    private transient AbstractLookup.ReferenceToResult results;
37
    private transient AbstractLookup.ReferenceToResult<?> results;
36
38
37
    /** Constructor
39
    /** Constructor
38
     */
40
     */
Lines 50-57 Link Here
50
    * @return true if the Item has been added for the first time or false if some other
52
    * @return true if the Item has been added for the first time or false if some other
51
    *    item equal to this one already existed in the lookup
53
    *    item equal to this one already existed in the lookup
52
    */
54
    */
53
    public boolean add(AbstractLookup.Pair item, Object transaction) {
55
    public boolean add(AbstractLookup.Pair<?> item, Transaction changed) {
54
        Transaction changed = (Transaction) transaction;
55
        Object[] arr = changed.current;
56
        Object[] arr = changed.current;
56
57
57
        if (changed.arr == null) {
58
        if (changed.arr == null) {
Lines 112-119 Link Here
112
113
113
    /** Removes an item.
114
    /** Removes an item.
114
    */
115
    */
115
    public void remove(AbstractLookup.Pair item, Object transaction) {
116
    public void remove(AbstractLookup.Pair item, Transaction changed) {
116
        Transaction changed = (Transaction) transaction;
117
        Object[] arr = changed.current;
117
        Object[] arr = changed.current;
118
118
119
        int found = -1;
119
        int found = -1;
Lines 126-133 Link Here
126
126
127
            if ((found == -1) && arr[i].equals(item)) {
127
            if ((found == -1) && arr[i].equals(item)) {
128
                // already there
128
                // already there
129
                ((AbstractLookup.Pair) arr[i]).setIndex(null, -1);
129
                Pair<?> p = (Pair<?>)arr[i];
130
                changed.add(arr[i]);
130
                p.setIndex(null, -1);
131
                changed.add(p);
131
                found = i;
132
                found = i;
132
            }
133
            }
133
134
Lines 148-155 Link Here
148
    * @param retain Pair -> AbstractLookup.Info map
149
    * @param retain Pair -> AbstractLookup.Info map
149
    * @param notify set of Classes that has possibly changed
150
    * @param notify set of Classes that has possibly changed
150
    */
151
    */
151
    public void retainAll(Map retain, Object transaction) {
152
    public void retainAll(Map retain, Transaction changed) {
152
        Transaction changed = (Transaction) transaction;
153
        Object[] arr = changed.current;
153
        Object[] arr = changed.current;
154
154
155
        for (int from = 0; from < arr.length; from++) {
155
        for (int from = 0; from < arr.length; from++) {
Lines 188-196 Link Here
188
    * @return enumeration of Item
188
    * @return enumeration of Item
189
    * @see #unsorted
189
    * @see #unsorted
190
    */
190
    */
191
    public Enumeration lookup(final Class clazz) {
191
    public <T> Enumeration<Pair<T>> lookup(final Class<T> clazz) {
192
        class CheckEn implements org.openide.util.Enumerations.Processor {
192
        class CheckEn implements org.openide.util.Enumerations.Processor<Object,Pair<T>> {
193
            public Object process(Object o, Collection ignore) {
193
            @SuppressWarnings("unchecked")
194
            public Pair<T> process(Object o, Collection ignore) {
194
                boolean ok;
195
                boolean ok;
195
196
196
                if (o instanceof AbstractLookup.Pair) {
197
                if (o instanceof AbstractLookup.Pair) {
Lines 199-211 Link Here
199
                    ok = false;
200
                    ok = false;
200
                }
201
                }
201
202
202
                return ok ? o : null;
203
                return ok ? (Pair<T>)o : null;
203
            }
204
            }
204
        }
205
        }
205
206
206
        if (content instanceof Object[]) {
207
        if (content instanceof Object[]) {
207
            Enumeration all = org.openide.util.Enumerations.array((Object[]) content);
208
            Enumeration<Object> all = org.openide.util.Enumerations.array((Object[]) content);
208
209
            return org.openide.util.Enumerations.filter(all, new CheckEn());
209
            return org.openide.util.Enumerations.filter(all, new CheckEn());
210
        } else {
210
        } else {
211
            return org.openide.util.Enumerations.empty();
211
            return org.openide.util.Enumerations.empty();
Lines 214-220 Link Here
214
214
215
    /** Associates another result with this storage.
215
    /** Associates another result with this storage.
216
     */
216
     */
217
    public AbstractLookup.ReferenceToResult registerReferenceToResult(AbstractLookup.ReferenceToResult newRef) {
217
    public AbstractLookup.ReferenceToResult registerReferenceToResult(AbstractLookup.ReferenceToResult<?> newRef) {
218
        AbstractLookup.ReferenceToResult prev = this.results;
218
        AbstractLookup.ReferenceToResult prev = this.results;
219
        this.results = newRef;
219
        this.results = newRef;
220
220
Lines 223-229 Link Here
223
223
224
    /** Cleanup the references
224
    /** Cleanup the references
225
     */
225
     */
226
    public AbstractLookup.ReferenceToResult cleanUpResult(Lookup.Template templ) {
226
    public AbstractLookup.ReferenceToResult cleanUpResult(Lookup.Template<?> templ) {
227
        AbstractLookup.ReferenceIterator it = new AbstractLookup.ReferenceIterator(this.results);
227
        AbstractLookup.ReferenceIterator it = new AbstractLookup.ReferenceIterator(this.results);
228
228
229
        while (it.next())
229
        while (it.next())
Lines 233-254 Link Here
233
    }
233
    }
234
234
235
    /** We use a hash set of all modified Pair to handle the transaction */
235
    /** We use a hash set of all modified Pair to handle the transaction */
236
    public Object beginTransaction(int ensure) {
236
    public Transaction beginTransaction(int ensure) {
237
        return new Transaction(ensure, content);
237
        return new Transaction(ensure, content);
238
    }
238
    }
239
239
240
    /** Extract all results.
240
    /** Extract all results.
241
     */
241
     */
242
    public void endTransaction(Object transaction, Set modified) {
242
    public void endTransaction(Transaction changed, Set<AbstractLookup.R> modified) {
243
        Transaction changed = (Transaction) transaction;
244
245
        AbstractLookup.ReferenceIterator it = new AbstractLookup.ReferenceIterator(this.results);
243
        AbstractLookup.ReferenceIterator it = new AbstractLookup.ReferenceIterator(this.results);
246
244
247
        if (changed.arr == null) {
245
        if (changed.arr == null) {
248
            // either add or remove, only check the content of check HashSet
246
            // either add or remove, only check the content of check HashSet
249
            while (it.next()) {
247
            while (it.next()) {
250
                AbstractLookup.ReferenceToResult ref = it.current();
248
                AbstractLookup.ReferenceToResult ref = it.current();
251
                Iterator pairs = changed.iterator();
249
                Iterator<Pair<?>> pairs = changed.iterator();
252
250
253
                while (pairs.hasNext()) {
251
                while (pairs.hasNext()) {
254
                    AbstractLookup.Pair p = (AbstractLookup.Pair) pairs.next();
252
                    AbstractLookup.Pair p = (AbstractLookup.Pair) pairs.next();
Lines 305-311 Link Here
305
    /** HashSet with additional field for new array which is callocated
303
    /** HashSet with additional field for new array which is callocated
306
     * in case we are doing replace to hold all new items.
304
     * in case we are doing replace to hold all new items.
307
     */
305
     */
308
    private static final class Transaction extends HashSet {
306
    static final class Transaction extends HashSet<Pair<?>> {
309
        /** array with current objects */
307
        /** array with current objects */
310
        public final Object[] current;
308
        public final Object[] current;
311
309
Lines 404-410 Link Here
404
            }
402
            }
405
        }
403
        }
406
404
407
        public int addPair(AbstractLookup.Pair p) {
405
        public int addPair(AbstractLookup.Pair<?> p) {
408
            p.setIndex(null, cnt);
406
            p.setIndex(null, cnt);
409
            arr[cnt++] = p;
407
            arr[cnt++] = p;
410
408
(-)openide/util/src/org/openide/util/lookup/DelegatingStorage.java (-16 / +29 lines)
Lines 19-37 Link Here
19
import java.lang.ref.WeakReference;
19
import java.lang.ref.WeakReference;
20
20
21
import java.util.*;
21
import java.util.*;
22
import org.openide.util.lookup.AbstractLookup.Pair;
22
23
23
24
24
/** Storages that can switch between another storages.
25
/** Storages that can switch between another storages.
25
 * @author  Jaroslav Tulach
26
 * @author  Jaroslav Tulach
26
 */
27
 */
27
final class DelegatingStorage extends Object implements Serializable, AbstractLookup.Storage {
28
final class DelegatingStorage<Transaction> extends Object
29
implements Serializable, AbstractLookup.Storage<Transaction> {
28
    /** object to delegate to */
30
    /** object to delegate to */
29
    private AbstractLookup.Storage delegate;
31
    private AbstractLookup.Storage<Transaction> delegate;
30
32
31
    /** thread just accessing the storage */
33
    /** thread just accessing the storage */
32
    private Thread owner;
34
    private Thread owner;
33
35
34
    public DelegatingStorage(AbstractLookup.Storage d) {
36
    public DelegatingStorage(AbstractLookup.Storage<Transaction> d) {
35
        this.delegate = d;
37
        this.delegate = d;
36
        this.owner = Thread.currentThread();
38
        this.owner = Thread.currentThread();
37
    }
39
    }
Lines 61-104 Link Here
61
63
62
    /** Exits from the owners ship of the storage.
64
    /** Exits from the owners ship of the storage.
63
     */
65
     */
64
    public AbstractLookup.Storage exitDelegate() {
66
    public AbstractLookup.Storage<Transaction> exitDelegate() {
65
        if (Thread.currentThread() != owner) {
67
        if (Thread.currentThread() != owner) {
66
            throw new IllegalStateException("Onwer: " + owner + " caller: " + Thread.currentThread()); // NOI18N
68
            throw new IllegalStateException("Onwer: " + owner + " caller: " + Thread.currentThread()); // NOI18N
67
        }
69
        }
68
70
69
        AbstractLookup.Storage d = delegate;
71
        AbstractLookup.Storage<Transaction> d = delegate;
70
        delegate = null;
72
        delegate = null;
71
73
72
        return d;
74
        return d;
73
    }
75
    }
74
76
75
    public boolean add(org.openide.util.lookup.AbstractLookup.Pair item, Object transaction) {
77
    public boolean add(AbstractLookup.Pair<?> item, Transaction transaction) {
76
        return delegate.add(item, transaction);
78
        return delegate.add(item, transaction);
77
    }
79
    }
78
80
79
    public void remove(org.openide.util.lookup.AbstractLookup.Pair item, Object transaction) {
81
    public void remove(org.openide.util.lookup.AbstractLookup.Pair item, Transaction transaction) {
80
        delegate.remove(item, transaction);
82
        delegate.remove(item, transaction);
81
    }
83
    }
82
84
83
    public void retainAll(Map retain, Object transaction) {
85
    public void retainAll(Map retain, Transaction transaction) {
84
        delegate.retainAll(retain, transaction);
86
        delegate.retainAll(retain, transaction);
85
    }
87
    }
86
88
87
    public Object beginTransaction(int ensure) {
89
    /** A special method to change the backing storage.
90
     * In fact it is not much typesafe as it changes the
91
     * type of Transaction but we know that nobody is currently
92
     * holding a transaction object, so there cannot be inconsitencies.
93
     */
94
    @SuppressWarnings("unchecked")
95
    private void changeDelegate(InheritanceTree st) {
96
        delegate = (AbstractLookup.Storage<Transaction>)st;
97
    }
98
99
    public Transaction beginTransaction(int ensure) {
88
        try {
100
        try {
89
            return delegate.beginTransaction(ensure);
101
            return delegate.beginTransaction(ensure);
90
        } catch (UnsupportedOperationException ex) {
102
        } catch (UnsupportedOperationException ex) {
91
            // let's convert to InheritanceTree
103
            // let's convert to InheritanceTree
92
            ArrayStorage arr = (ArrayStorage) delegate;
104
            ArrayStorage arr = (ArrayStorage) delegate;
93
            delegate = new InheritanceTree();
105
            InheritanceTree inh = new InheritanceTree();
106
            changeDelegate(inh);
94
107
95
            //
108
            //
96
            // Copy content
109
            // Copy content
97
            //
110
            //
98
            Enumeration en = arr.lookup(Object.class);
111
            Enumeration<Pair<Object>> en = arr.lookup(Object.class);
99
112
100
            while (en.hasMoreElements()) {
113
            while (en.hasMoreElements()) {
101
                if (!delegate.add((AbstractLookup.Pair) en.nextElement(), new ArrayList())) {
114
                if (!inh.add(en.nextElement(), new ArrayList<Class>())) {
102
                    throw new IllegalStateException("All objects have to be accepted"); // NOI18N
115
                    throw new IllegalStateException("All objects have to be accepted"); // NOI18N
103
                }
116
                }
104
            }
117
            }
Lines 106-115 Link Here
106
            //
119
            //
107
            // Copy listeners
120
            // Copy listeners
108
            //
121
            //
109
            AbstractLookup.ReferenceToResult ref = arr.cleanUpResult(null);
122
            AbstractLookup.ReferenceToResult<?> ref = arr.cleanUpResult(null);
110
123
111
            if (ref != null) {
124
            if (ref != null) {
112
                ref.cloneList(delegate);
125
                ref.cloneList(inh);
113
            }
126
            }
114
127
115
            // we have added the current content and now we can start transaction
128
            // we have added the current content and now we can start transaction
Lines 123-133 Link Here
123
        return delegate.cleanUpResult(templ);
136
        return delegate.cleanUpResult(templ);
124
    }
137
    }
125
138
126
    public void endTransaction(Object transaction, Set modified) {
139
    public void endTransaction(Transaction transaction, Set<AbstractLookup.R> modified) {
127
        delegate.endTransaction(transaction, modified);
140
        delegate.endTransaction(transaction, modified);
128
    }
141
    }
129
142
130
    public Enumeration lookup(Class clazz) {
143
    public <T> Enumeration<Pair<T>> lookup(Class<T> clazz) {
131
        return delegate.lookup(clazz);
144
        return delegate.lookup(clazz);
132
    }
145
    }
133
146
(-)openide/util/src/org/openide/util/lookup/ExcludingLookup.java (-33 / +34 lines)
Lines 47-53 Link Here
47
        return "ExcludingLookup: " + delegate + " excludes: " + Arrays.asList(classes()); // NOI18N
47
        return "ExcludingLookup: " + delegate + " excludes: " + Arrays.asList(classes()); // NOI18N
48
    }
48
    }
49
49
50
    public Result lookup(Template template) {
50
    public <T> Result<T> lookup(Template<T> template) {
51
        if (template == null) {
51
        if (template == null) {
52
            throw new NullPointerException();
52
            throw new NullPointerException();
53
        }
53
        }
Lines 57-71 Link Here
57
            return Lookup.EMPTY.lookup(template);
57
            return Lookup.EMPTY.lookup(template);
58
        }
58
        }
59
59
60
        return new R(template.getType(), delegate.lookup(template));
60
        return new R<T>(template.getType(), delegate.lookup(template));
61
    }
61
    }
62
62
63
    public Object lookup(Class clazz) {
63
    public <T> T lookup(Class<T> clazz) {
64
        if (areSubclassesOfThisClassAlwaysExcluded(clazz)) {
64
        if (areSubclassesOfThisClassAlwaysExcluded(clazz)) {
65
            return null;
65
            return null;
66
        }
66
        }
67
67
68
        Object res = delegate.lookup(clazz);
68
        T res = delegate.lookup(clazz);
69
69
70
        if (isObjectAccessible(clazz, res, 0)) {
70
        if (isObjectAccessible(clazz, res, 0)) {
71
            return res;
71
            return res;
Lines 74-85 Link Here
74
        }
74
        }
75
    }
75
    }
76
76
77
    public org.openide.util.Lookup.Item lookupItem(org.openide.util.Lookup.Template template) {
77
    public <T> Lookup.Item<T> lookupItem(Lookup.Template<T> template) {
78
        if (areSubclassesOfThisClassAlwaysExcluded(template.getType())) {
78
        if (areSubclassesOfThisClassAlwaysExcluded(template.getType())) {
79
            return null;
79
            return null;
80
        }
80
        }
81
81
82
        org.openide.util.Lookup.Item retValue = delegate.lookupItem(template);
82
        Lookup.Item<T> retValue = delegate.lookupItem(template);
83
83
84
        if (isObjectAccessible(template.getType(), retValue, 2)) {
84
        if (isObjectAccessible(template.getType(), retValue, 2)) {
85
            return retValue;
85
            return retValue;
Lines 90-97 Link Here
90
90
91
    /** @return true if the instance of class c shall never be returned from this lookup
91
    /** @return true if the instance of class c shall never be returned from this lookup
92
     */
92
     */
93
    private boolean areSubclassesOfThisClassAlwaysExcluded(Class c) {
93
    private boolean areSubclassesOfThisClassAlwaysExcluded(Class<?> c) {
94
        Class[] arr = classes();
94
        Class<?>[] arr = classes();
95
95
96
        for (int i = 0; i < arr.length; i++) {
96
        for (int i = 0; i < arr.length; i++) {
97
            if (arr[i].isAssignableFrom(c)) {
97
            if (arr[i].isAssignableFrom(c)) {
Lines 104-110 Link Here
104
104
105
    /** Returns the array of classes this lookup filters.
105
    /** Returns the array of classes this lookup filters.
106
     */
106
     */
107
    final Class[] classes() {
107
    final Class<?>[] classes() {
108
        if (classes instanceof Class[]) {
108
        if (classes instanceof Class[]) {
109
            return (Class[]) classes;
109
            return (Class[]) classes;
110
        } else {
110
        } else {
Lines 116-122 Link Here
116
     * releation ship without walking thru any of the classes mentioned in the
116
     * releation ship without walking thru any of the classes mentioned in the
117
     * barrier.
117
     * barrier.
118
     */
118
     */
119
    private static boolean isAccessible(Class[] barriers, Class from, Class to) {
119
    private static boolean isAccessible(Class<?>[] barriers, Class<?> from, Class<?> to) {
120
        if ((to == null) || !from.isAssignableFrom(to)) {
120
        if ((to == null) || !from.isAssignableFrom(to)) {
121
            // no way to reach each other by walking up
121
            // no way to reach each other by walking up
122
            return false;
122
            return false;
Lines 196-223 Link Here
196
196
197
    /** Filters collection accroding to set of given filters.
197
    /** Filters collection accroding to set of given filters.
198
     */
198
     */
199
    final java.util.Collection filter(Class[] arr, Class from, java.util.Collection c, int type) {
199
    final <E, T extends Collection<E>> T filter(
200
        java.util.Collection ret = null;
200
        Class<?>[] arr, Class<?> from, T c, int type, T prototype
201
    ) {
202
        T ret = null;
201
203
202
204
203
// optimistic strategy expecting we will not need to filter
205
// optimistic strategy expecting we will not need to filter
204
TWICE: 
206
TWICE: 
205
        for (;;) {
207
        for (;;) {
206
            Iterator it = c.iterator();
208
            Iterator<E> it = c.iterator();
207
BIG: 
209
BIG: 
208
            while (it.hasNext()) {
210
            while (it.hasNext()) {
209
                Object res = it.next();
211
                E res = it.next();
210
212
211
                if (!isObjectAccessible(arr, from, res, type)) {
213
                if (!isObjectAccessible(arr, from, res, type)) {
212
                    if (ret == null) {
214
                    if (ret == null) {
213
                        // we need to restart the scanning again 
215
                        // we need to restart the scanning again 
214
                        // as there is an active filter
216
                        // as there is an active filter
215
                        if (type == 1) {
217
                        ret = prototype;
216
                            ret = new java.util.HashSet();
217
                        } else {
218
                            ret = new ArrayList(c.size());
219
                        }
220
221
                        continue TWICE;
218
                        continue TWICE;
222
                    }
219
                    }
223
220
Lines 239-250 Link Here
239
236
240
    /** Delegating result that filters unwanted items and instances.
237
    /** Delegating result that filters unwanted items and instances.
241
     */
238
     */
242
    private final class R extends WaitableResult implements LookupListener {
239
    private final class R<T> extends WaitableResult<T> implements LookupListener {
243
        private Result result;
240
        private Result<T> result;
244
        private Object listeners;
241
        private Object listeners;
245
        private Class from;
242
        private Class<?> from;
246
243
247
        R(Class from, Result delegate) {
244
        R(Class<?> from, Result<T> delegate) {
248
            this.from = from;
245
            this.from = from;
249
            this.result = delegate;
246
            this.result = delegate;
250
        }
247
        }
Lines 281-296 Link Here
281
            }
278
            }
282
        }
279
        }
283
280
284
        public java.util.Collection allInstances() {
281
        public Collection<? extends T> allInstances() {
285
            return filter(classes(), from, result.allInstances(), 0);
282
            return openCol(result.allInstances(), 0);
283
        }
284
285
        private <S> Collection<S> openCol(Collection<S> c, int type) {
286
            return filter(classes(), from, c, type, new ArrayList<S>(c.size()));
286
        }
287
        }
287
288
288
        public Set allClasses() {
289
        public Set<Class<? extends T>> allClasses() {
289
            return (Set) filter(classes(), from, result.allClasses(), 1);
290
            return filter(classes(), from, result.allClasses(), 1, new HashSet<Class<? extends T>>());
290
        }
291
        }
291
292
292
        public Collection allItems() {
293
        public Collection<? extends Item<T>> allItems() {
293
            return filter(classes(), from, result.allItems(), 2);
294
            return openCol(result.allItems(), 2);
294
        }
295
        }
295
296
296
        public void resultChanged(org.openide.util.LookupEvent ev) {
297
        public void resultChanged(org.openide.util.LookupEvent ev) {
Lines 299-305 Link Here
299
            }
300
            }
300
        }
301
        }
301
302
302
        protected void collectFires(Collection evAndListeners) {
303
        protected void collectFires(Collection<Object> evAndListeners) {
303
            LookupListener[] arr;
304
            LookupListener[] arr;
304
305
305
            synchronized (this) {
306
            synchronized (this) {
Lines 310-317 Link Here
310
                if (listeners instanceof LookupListener) {
311
                if (listeners instanceof LookupListener) {
311
                    arr = new LookupListener[] { (LookupListener) listeners };
312
                    arr = new LookupListener[] { (LookupListener) listeners };
312
                } else {
313
                } else {
313
                    ArrayList l = (ArrayList) listeners;
314
                    ArrayList<?> l = (ArrayList<?>) listeners;
314
                    arr = (LookupListener[]) l.toArray(new LookupListener[l.size()]);
315
                    arr = l.toArray(new LookupListener[l.size()]);
315
                }
316
                }
316
            }
317
            }
317
318
(-)openide/util/src/org/openide/util/lookup/InheritanceTree.java (-84 / +87 lines)
Lines 12-18 Link Here
12
 */
12
 */
13
package org.openide.util.lookup;
13
package org.openide.util.lookup;
14
14
15
import org.openide.util.Enumerations;
15
import org.openide.util.Lookup;
16
import org.openide.util.Lookup;
17
import org.openide.util.lookup.AbstractLookup.Pair;
16
import org.openide.util.lookup.AbstractLookup.ReferenceIterator;
18
import org.openide.util.lookup.AbstractLookup.ReferenceIterator;
17
import org.openide.util.lookup.AbstractLookup.ReferenceToResult;
19
import org.openide.util.lookup.AbstractLookup.ReferenceToResult;
18
20
Lines 87-93 Link Here
87
 *
89
 *
88
 * @author  Jaroslav Tulach
90
 * @author  Jaroslav Tulach
89
 */
91
 */
90
final class InheritanceTree extends Object implements Serializable, AbstractLookup.Storage {
92
final class InheritanceTree extends Object
93
implements Serializable, AbstractLookup.Storage<ArrayList<Class>> {
91
    private static final long serialVersionUID = 1L;
94
    private static final long serialVersionUID = 1L;
92
95
93
    /** the root item (represents Object) */
96
    /** the root item (represents Object) */
Lines 96-107 Link Here
96
    /** Map of queried interfaces.
99
    /** Map of queried interfaces.
97
     * <p>Type: <code>Map&lt;Class, (Collection&lt;AbstractLookup.Pair&gt; | AbstractLookup.Pair)&gt;</code>
100
     * <p>Type: <code>Map&lt;Class, (Collection&lt;AbstractLookup.Pair&gt; | AbstractLookup.Pair)&gt;</code>
98
     */
101
     */
99
    private transient Map interfaces;
102
    private transient Map<Class,Object> interfaces;
100
103
101
    /** Map (Class, ReferenceToResult) of all listeners that are waiting in
104
    /** Map (Class, ReferenceToResult) of all listeners that are waiting in
102
     * changes in class Class
105
     * changes in class Class
103
     */
106
     */
104
    private transient Map reg;
107
    private transient Map<Class,ReferenceToResult> reg;
105
108
106
    /** Constructor
109
    /** Constructor
107
     */
110
     */
Lines 135-141 Link Here
135
138
136
    private void readObject(ObjectInputStream ois) throws IOException, ClassNotFoundException {
139
    private void readObject(ObjectInputStream ois) throws IOException, ClassNotFoundException {
137
        object = (Node) ois.readObject();
140
        object = (Node) ois.readObject();
138
        interfaces = new WeakHashMap();
141
        interfaces = new WeakHashMap<Class,Object>();
139
142
140
        String clazz;
143
        String clazz;
141
        ClassLoader l = (ClassLoader) Lookup.getDefault().lookup(ClassLoader.class);
144
        ClassLoader l = (ClassLoader) Lookup.getDefault().lookup(ClassLoader.class);
Lines 157-165 Link Here
157
    * @return true if the Item has been added for the first time or false if some other
160
    * @return true if the Item has been added for the first time or false if some other
158
    *    item equal to this one already existed in the lookup
161
    *    item equal to this one already existed in the lookup
159
    */
162
    */
160
    public boolean add(AbstractLookup.Pair item, Object transaction) {
163
    public boolean add(AbstractLookup.Pair<?> item, ArrayList<Class> affected) {
161
        ArrayList affected = (ArrayList) transaction;
162
163
        Node node = registerClass(object, item);
164
        Node node = registerClass(object, item);
164
165
165
        affected.add(node.getType());
166
        affected.add(node.getType());
Lines 179-187 Link Here
179
180
180
    /** Removes an item.
181
    /** Removes an item.
181
    */
182
    */
182
    public void remove(AbstractLookup.Pair item, Object transaction) {
183
    public void remove(AbstractLookup.Pair item, ArrayList<Class> affected) {
183
        ArrayList affected = (ArrayList) transaction;
184
185
        Node n = removeClass(object, item);
184
        Node n = removeClass(object, item);
186
185
187
        if (n != null) {
186
        if (n != null) {
Lines 195-203 Link Here
195
    * @param retain collection of Pairs to keep them in
194
    * @param retain collection of Pairs to keep them in
196
    * @param notify set of Classes that has possibly changed
195
    * @param notify set of Classes that has possibly changed
197
    */
196
    */
198
    public void retainAll(Map retain, Object transaction) {
197
    public void retainAll(Map retain, ArrayList<Class> notify) {
199
        ArrayList notify = (ArrayList) transaction;
200
201
        retainAllInterface(retain, notify);
198
        retainAllInterface(retain, notify);
202
        retainAllClasses(object, retain, notify);
199
        retainAllClasses(object, retain, notify);
203
    }
200
    }
Lines 207-217 Link Here
207
    * @return enumeration of Item
204
    * @return enumeration of Item
208
    * @see #unsorted
205
    * @see #unsorted
209
    */
206
    */
210
    public Enumeration lookup(Class clazz) {
207
    @SuppressWarnings("unchecked")
208
    public <T> Enumeration<Pair<T>> lookup(Class<T> clazz) {
211
        if ((clazz != null) && clazz.isInterface()) {
209
        if ((clazz != null) && clazz.isInterface()) {
212
            return searchInterface(clazz);
210
            return (Enumeration)searchInterface(clazz);
213
        } else {
211
        } else {
214
            return searchClass(object, clazz);
212
            return (Enumeration)searchClass(object, clazz);
215
        }
213
        }
216
    }
214
    }
217
215
Lines 317-323 Link Here
317
    * @return node that represents clazz in the tree or null if the clazz is not
315
    * @return node that represents clazz in the tree or null if the clazz is not
318
    *    represented under the node n
316
    *    represented under the node n
319
    */
317
    */
320
    private Node classToNode(final Node n, final Class clazz) {
318
    private Node classToNode(final Node n, final Class<?> clazz) {
321
        if (!n.accepts(clazz)) {
319
        if (!n.accepts(clazz)) {
322
            // nothing from us
320
            // nothing from us
323
            return null;
321
            return null;
Lines 343-354 Link Here
343
341
344
                if ((found != null) && ch.deserialized()) {
342
                if ((found != null) && ch.deserialized()) {
345
                    class VerifyJob implements AbstractLookup.ISE.Job {
343
                    class VerifyJob implements AbstractLookup.ISE.Job {
346
                        private AbstractLookup.Pair[] pairs;
344
                        private AbstractLookup.Pair<?>[] pairs;
347
                        private boolean[] answers;
345
                        private boolean[] answers;
348
346
349
                        public VerifyJob(Collection items) {
347
                        public VerifyJob(Collection<Pair> items) {
350
                            if (items != null) {
348
                            if (items != null) {
351
                                pairs = (AbstractLookup.Pair[]) items.toArray(new AbstractLookup.Pair[0]);
349
                                pairs = items.toArray(new AbstractLookup.Pair[0]);
352
                            }
350
                            }
353
                        }
351
                        }
354
352
Lines 377-389 Link Here
377
375
378
                            if (n.children != null) {
376
                            if (n.children != null) {
379
                                // consolidate all nodes that represent the same class
377
                                // consolidate all nodes that represent the same class
380
                                HashMap nodes = new HashMap(n.children.size() * 3);
378
                                HashMap<Class,Node> nodes = new HashMap<Class,Node>(n.children.size() * 3);
381
379
382
                                Iterator child = n.children.iterator();
380
                                Iterator child = n.children.iterator();
383
381
384
                                while (child.hasNext()) {
382
                                while (child.hasNext()) {
385
                                    Node node = extractNode(child);
383
                                    Node node = extractNode(child);
386
                                    Node prev = (Node) nodes.put(node.getType(), node);
384
                                    Node prev = nodes.put(node.getType(), node);
387
385
388
                                    if (prev != null) {
386
                                    if (prev != null) {
389
                                        child.remove();
387
                                        child.remove();
Lines 455-464 Link Here
455
                    boolArr = new boolean[n.items.size()];
453
                    boolArr = new boolean[n.items.size()];
456
454
457
                    int i = 0;
455
                    int i = 0;
458
                    Iterator it = n.items.iterator();
456
                    Iterator<Pair> it = n.items.iterator();
459
457
460
                    while (it.hasNext()) {
458
                    while (it.hasNext()) {
461
                        AbstractLookup.Pair item = (AbstractLookup.Pair) it.next();
459
                        AbstractLookup.Pair<?> item = it.next();
462
                        arr[i] = item;
460
                        arr[i] = item;
463
                        boolArr[i] = item.instanceOf(clazz);
461
                        boolArr[i] = item.instanceOf(clazz);
464
                        i++;
462
                        i++;
Lines 482-491 Link Here
482
            }
480
            }
483
481
484
            public void internal() {
482
            public void internal() {
485
                ArrayList reparent = null;
483
                ArrayList<Node> reparent = null;
486
484
487
                if (n.children == null) {
485
                if (n.children == null) {
488
                    n.children = new ArrayList();
486
                    n.children = new ArrayList<Node>();
489
                } else {
487
                } else {
490
                    // scan thru all my nodes if some of them are not a subclass
488
                    // scan thru all my nodes if some of them are not a subclass
491
                    // of clazz => then they would need to become child of newNode
489
                    // of clazz => then they would need to become child of newNode
Lines 500-506 Link Here
500
498
501
                        if (clazz.isAssignableFrom(r.getType())) {
499
                        if (clazz.isAssignableFrom(r.getType())) {
502
                            if (reparent == null) {
500
                            if (reparent == null) {
503
                                reparent = new ArrayList();
501
                                reparent = new ArrayList<Node>();
504
                            }
502
                            }
505
503
506
                            reparent.add(r);
504
                            reparent.add(r);
Lines 558-564 Link Here
558
    /** Search for a requested class.
556
    /** Search for a requested class.
559
    * @return enumeration of Pair
557
    * @return enumeration of Pair
560
    */
558
    */
561
    private Enumeration searchClass(Node n, Class clazz) {
559
    private Enumeration<Pair> searchClass(Node n, Class<?> clazz) {
562
        if (clazz != null) {
560
        if (clazz != null) {
563
            n = classToNode(n, clazz);
561
            n = classToNode(n, clazz);
564
        }
562
        }
Lines 579-592 Link Here
579
     * @param notify collection of classes will be changed
577
     * @param notify collection of classes will be changed
580
     * @return <code>true<code> if some items were changed and node items and children are emptied,
578
     * @return <code>true<code> if some items were changed and node items and children are emptied,
581
     * those nodes, excluding root, will be removed from tree */
579
     * those nodes, excluding root, will be removed from tree */
582
    private boolean retainAllClasses(Node node, Map retain, Collection notify) {
580
    private boolean retainAllClasses(Node node, Map retain, Collection<Class> notify) {
583
        boolean retained = false;
581
        boolean retained = false;
584
582
585
        if ((node.items != null) && (retain != null)) {
583
        if ((node.items != null) && (retain != null)) {
586
            Iterator it = node.items.iterator();
584
            Iterator<Pair> it = node.items.iterator();
587
585
588
            while (it.hasNext()) {
586
            while (it.hasNext()) {
589
                AbstractLookup.Pair item = (AbstractLookup.Pair) it.next();
587
                AbstractLookup.Pair<?> item = it.next();
590
                AbstractLookup.Info n = (AbstractLookup.Info) retain.remove(item);
588
                AbstractLookup.Info n = (AbstractLookup.Info) retain.remove(item);
591
589
592
                if (n == null) {
590
                if (n == null) {
Lines 634-671 Link Here
634
     * @param n node to create enumeration for
632
     * @param n node to create enumeration for
635
     * @return enumeration of Pairs
633
     * @return enumeration of Pairs
636
     */
634
     */
637
    private static Enumeration nodeToEnum(Node n) {
635
    private static Enumeration<Pair> nodeToEnum(Node n) {
638
        if (n.children == null) {
636
        if (n.children == null) {
639
            // create a simple enumeration because we do not have children
637
            // create a simple enumeration because we do not have children
640
            return (n.items == null) ? org.openide.util.Enumerations.empty() : Collections.enumeration(n.items);
638
            Enumeration<Pair> e;
639
            if (n.items == null) {
640
                e = Enumerations.empty();
641
            } else {
642
                e = Collections.enumeration(n.items);
643
            }
644
            return e;
641
        }
645
        }
642
646
643
        // we have found what we need
647
        // we have found what we need
644
        // now we have to just build the enumeration
648
        // now we have to just build the enumeration
645
        class DeepAndItems implements org.openide.util.Enumerations.Processor {
649
        class DeepAndItems implements Enumerations.Processor<Node,Enumeration<Pair>> {
646
            public Object process(Object obj, Collection toAdd) {
650
            public Enumeration<Pair> process(Node n2, Collection<Node> toAdd) {
647
                Node n2 = (Node) obj;
648
649
                if (n2.children != null) {
651
                if (n2.children != null) {
650
                    toAdd.addAll(n2.children);
652
                    toAdd.addAll(n2.children);
651
                }
653
                }
652
654
653
                if ((n2.items == null) || n2.items.isEmpty()) {
655
                if ((n2.items == null) || n2.items.isEmpty()) {
654
                    return org.openide.util.Enumerations.empty();
656
                    return Enumerations.empty();
655
                } else {
657
                } else {
656
                    return Collections.enumeration(n2.items);
658
                    return Collections.enumeration(n2.items);
657
                }
659
                }
658
            }
660
            }
659
        }
661
        }
660
662
661
        Enumeration en = org.openide.util.Enumerations.queue(
663
        Enumeration<Enumeration<Pair>> en = Enumerations.queue(
662
                
663
            // initial node is our current one
664
            // initial node is our current one
664
            org.openide.util.Enumerations.singleton(n), new DeepAndItems()
665
            Enumerations.singleton(n), new DeepAndItems()
665
            );
666
        );
666
667
        Enumeration<Pair> all = Enumerations.concat(en);
667
        // create enumeration of Items
668
        // create enumeration of Items
668
        return new NeedsSortEnum(org.openide.util.Enumerations.concat(en));
669
        return new NeedsSortEnum<Pair>(all);
669
    }
670
    }
670
671
671
    //
672
    //
Lines 677-698 Link Here
677
    * @param affected list of classes that were affected
678
    * @param affected list of classes that were affected
678
    * @return false if similar item has already been registered
679
    * @return false if similar item has already been registered
679
    */
680
    */
680
    private boolean registerInterface(AbstractLookup.Pair item, Collection affected) {
681
    @SuppressWarnings("unchecked")
682
    private boolean registerInterface(AbstractLookup.Pair<?> item, Collection<Class> affected) {
681
        if (interfaces == null) {
683
        if (interfaces == null) {
682
            return true;
684
            return true;
683
        }
685
        }
684
686
685
        Iterator it = interfaces.entrySet().iterator();
687
        Iterator<Map.Entry<Class,Object>> it = interfaces.entrySet().iterator();
686
688
687
        while (it.hasNext()) {
689
        while (it.hasNext()) {
688
            Map.Entry entry = (Map.Entry) it.next();
690
            Map.Entry<Class,Object> entry = it.next();
689
            Class iface = (Class) entry.getKey();
691
            Class<?> iface = entry.getKey();
690
692
691
            if (item.instanceOf(iface)) {
693
            if (item.instanceOf(iface)) {
692
                Object value = entry.getValue();
694
                Object value = entry.getValue();
693
695
694
                if (value instanceof Collection) {
696
                if (value instanceof Collection) {
695
                    Collection set = (Collection) value;
697
                    Collection<Object> set = (Collection<Object>) value;
696
698
697
                    if (!set.add(item)) {
699
                    if (!set.add(item)) {
698
                        // item is already there, probably (if everything is correct) is registered in 
700
                        // item is already there, probably (if everything is correct) is registered in 
Lines 707-713 Link Here
707
                    }
709
                    }
708
710
709
                    // otherwise replace the single item with ArrayList
711
                    // otherwise replace the single item with ArrayList
710
                    ArrayList ll = new ArrayList(3);
712
                    ArrayList<Object> ll = new ArrayList<Object>(3);
711
                    ll.add(value);
713
                    ll.add(value);
712
                    ll.add(item);
714
                    ll.add(item);
713
                    entry.setValue(ll);
715
                    entry.setValue(ll);
Lines 724-729 Link Here
724
    * @param item item to register
726
    * @param item item to register
725
    * @param affected list of classes that were affected
727
    * @param affected list of classes that were affected
726
    */
728
    */
729
    @SuppressWarnings("unchecked")
727
    private void removeInterface(AbstractLookup.Pair item, Collection affected) {
730
    private void removeInterface(AbstractLookup.Pair item, Collection affected) {
728
        if (interfaces == null) {
731
        if (interfaces == null) {
729
            return;
732
            return;
Lines 764-769 Link Here
764
    *    (AbstractLookup.Pair -> AbstractLookup.Info)
767
    *    (AbstractLookup.Pair -> AbstractLookup.Info)
765
    * @param affected list of classes that were affected
768
    * @param affected list of classes that were affected
766
    */
769
    */
770
    @SuppressWarnings("unchecked")
767
    private void retainAllInterface(Map retainItems, Collection affected) {
771
    private void retainAllInterface(Map retainItems, Collection affected) {
768
        if (interfaces == null) {
772
        if (interfaces == null) {
769
            return;
773
            return;
Lines 775-781 Link Here
775
            Map.Entry entry = (Map.Entry) it.next();
779
            Map.Entry entry = (Map.Entry) it.next();
776
            Object value = entry.getValue();
780
            Object value = entry.getValue();
777
781
778
            HashMap retain = new HashMap(retainItems);
782
            HashMap<?,?> retain = new HashMap(retainItems);
779
783
780
            Iterator elems;
784
            Iterator elems;
781
            boolean multi = value instanceof Collection;
785
            boolean multi = value instanceof Collection;
Lines 843-849 Link Here
843
    * @param clazz class to search for
847
    * @param clazz class to search for
844
    * @return enumeration of Items
848
    * @return enumeration of Items
845
    */
849
    */
846
    private Enumeration searchInterface(final Class clazz) {
850
    @SuppressWarnings("unchecked")
851
    private Enumeration<Pair> searchInterface(final Class<?> clazz) {
847
        if (interfaces == null) {
852
        if (interfaces == null) {
848
            // first call for interface, only initialize
853
            // first call for interface, only initialize
849
            interfaces = new WeakHashMap();
854
            interfaces = new WeakHashMap();
Lines 895-901 Link Here
895
                return Collections.enumeration((Collection) obj);
900
                return Collections.enumeration((Collection) obj);
896
            } else {
901
            } else {
897
                // single item mode
902
                // single item mode
898
                return org.openide.util.Enumerations.singleton(obj);
903
                return org.openide.util.Enumerations.singleton((Pair)obj);
899
            }
904
            }
900
        }
905
        }
901
    }
906
    }
Lines 933-939 Link Here
933
938
934
        if (n.items != null) {
939
        if (n.items != null) {
935
            i = 0;
940
            i = 0;
936
            it = new ArrayList(n.items).iterator();
941
            it = new ArrayList<Pair>(n.items).iterator();
937
942
938
            while (it.hasNext()) {
943
            while (it.hasNext()) {
939
                AbstractLookup.Pair p = (AbstractLookup.Pair) it.next();
944
                AbstractLookup.Pair p = (AbstractLookup.Pair) it.next();
Lines 963-974 Link Here
963
        }
968
        }
964
    }
969
    }
965
970
966
    public ReferenceToResult registerReferenceToResult(ReferenceToResult newRef) {
971
    public ReferenceToResult registerReferenceToResult(ReferenceToResult<?> newRef) {
967
        if (reg == null) {
972
        if (reg == null) {
968
            reg = new HashMap();
973
            reg = new HashMap<Class,ReferenceToResult>();
969
        }
974
        }
970
975
971
        Class clazz = newRef.template.getType();
976
        Class<? extends Object> clazz = newRef.template.getType();
972
977
973
        // initialize the data structures if not yet
978
        // initialize the data structures if not yet
974
        lookup(clazz);
979
        lookup(clazz);
Lines 983-995 Link Here
983
        return (reg == null) ? null : (ReferenceToResult) reg.get(templ.getType());
988
        return (reg == null) ? null : (ReferenceToResult) reg.get(templ.getType());
984
    }
989
    }
985
990
986
    public Object beginTransaction(int ensure) {
991
    public ArrayList<Class> beginTransaction(int ensure) {
987
        return new ArrayList();
992
        return new ArrayList<Class>();
988
    }
993
    }
989
994
990
    public void endTransaction(Object transaction, Set allAffectedResults) {
995
    public void endTransaction(ArrayList<Class> list, Set<AbstractLookup.R> allAffectedResults) {
991
        ArrayList list = (ArrayList) transaction;
992
993
        if (list.size() == 1) {
996
        if (list.size() == 1) {
994
            // probably the most common case
997
            // probably the most common case
995
            collectListeners(allAffectedResults, (Class) list.get(0));
998
            collectListeners(allAffectedResults, (Class) list.get(0));
Lines 1007-1013 Link Here
1007
     * @param allAffectedResults adds Results into this set
1010
     * @param allAffectedResults adds Results into this set
1008
     * @param c the class that has changed
1011
     * @param c the class that has changed
1009
     */
1012
     */
1010
    private void collectListeners(Set allAffectedResults, Class c) {
1013
    private void collectListeners(Set<AbstractLookup.R> allAffectedResults, Class c) {
1011
        if (reg == null) {
1014
        if (reg == null) {
1012
            return;
1015
            return;
1013
        }
1016
        }
Lines 1017-1023 Link Here
1017
            ReferenceIterator it = new ReferenceIterator(first);
1020
            ReferenceIterator it = new ReferenceIterator(first);
1018
1021
1019
            while (it.next()) {
1022
            while (it.next()) {
1020
                Object result = it.current().getResult();
1023
                AbstractLookup.R result = it.current().getResult();
1021
1024
1022
                if (allAffectedResults != null) {
1025
                if (allAffectedResults != null) {
1023
                    // add result
1026
                    // add result
Lines 1046-1059 Link Here
1046
1049
1047
    /** Node in the tree.
1050
    /** Node in the tree.
1048
    */
1051
    */
1049
    static final class Node extends WeakReference implements Serializable {
1052
    static final class Node extends WeakReference<Class> implements Serializable {
1050
        static final long serialVersionUID = 3L;
1053
        static final long serialVersionUID = 3L;
1051
1054
1052
        /** children nodes */
1055
        /** children nodes */
1053
        public ArrayList children; // List<Node>
1056
        public ArrayList<Node> children;
1054
1057
1055
        /** list of items assigned to this node (suspect to be subclasses) */
1058
        /** list of items assigned to this node (suspect to be subclasses) */
1056
        public List items; // List<AbstractLookup.Pair>
1059
        public List<Pair> items;
1057
1060
1058
        /** Constructor.
1061
        /** Constructor.
1059
        */
1062
        */
Lines 1072-1078 Link Here
1072
            if (items.isEmpty()) {
1075
            if (items.isEmpty()) {
1073
                items = null;
1076
                items = null;
1074
            } else {
1077
            } else {
1075
                items = new ArrayList(items);
1078
                items = new ArrayList<Pair>(items);
1076
            }
1079
            }
1077
1080
1078
            return true;
1081
            return true;
Lines 1082-1088 Link Here
1082
         */
1085
         */
1083
        public void markDeserialized() {
1086
        public void markDeserialized() {
1084
            if (items == null || items == Collections.EMPTY_LIST) {
1087
            if (items == null || items == Collections.EMPTY_LIST) {
1085
                items = Collections.EMPTY_LIST;
1088
                items = Collections.emptyList();
1086
            } else {
1089
            } else {
1087
                items = Collections.synchronizedList(items);
1090
                items = Collections.synchronizedList(items);
1088
            }
1091
            }
Lines 1090-1097 Link Here
1090
1093
1091
        /** Getter for the type associated with this node.
1094
        /** Getter for the type associated with this node.
1092
         */
1095
         */
1093
        public Class getType() {
1096
        public Class<?> getType() {
1094
            Class c = (Class) get();
1097
            Class<?> c = get();
1095
1098
1096
            // if  garbage collected, then return a garbage
1099
            // if  garbage collected, then return a garbage
1097
            return (c == null) ? Void.TYPE : c;
1100
            return (c == null) ? Void.TYPE : c;
Lines 1099-1105 Link Here
1099
1102
1100
        /** Checks whether a node can represent an class.
1103
        /** Checks whether a node can represent an class.
1101
        */
1104
        */
1102
        public boolean accepts(Class clazz) {
1105
        public boolean accepts(Class<?> clazz) {
1103
            if (getType() == Object.class) {
1106
            if (getType() == Object.class) {
1104
                return true;
1107
                return true;
1105
            }
1108
            }
Lines 1109-1115 Link Here
1109
1112
1110
        /** Checks whether item is instance of this node.
1113
        /** Checks whether item is instance of this node.
1111
        */
1114
        */
1112
        public boolean accepts(AbstractLookup.Pair item) {
1115
        public boolean accepts(AbstractLookup.Pair<?> item) {
1113
            if (getType() == Object.class) {
1116
            if (getType() == Object.class) {
1114
                // Object.class
1117
                // Object.class
1115
                return true;
1118
                return true;
Lines 1122-1130 Link Here
1122
        * @param item the item
1125
        * @param item the item
1123
        * @return true if item has been added as new
1126
        * @return true if item has been added as new
1124
        */
1127
        */
1125
        public boolean assignItem(InheritanceTree tree, AbstractLookup.Pair item) {
1128
        public boolean assignItem(InheritanceTree tree, AbstractLookup.Pair<?> item) {
1126
            if ((items == null) || (items == Collections.EMPTY_LIST)) {
1129
            if ((items == null) || (items == Collections.EMPTY_LIST)) {
1127
                items = new ArrayList();
1130
                items = new ArrayList<Pair>();
1128
                items.add(item);
1131
                items.add(item);
1129
1132
1130
                return true;
1133
                return true;
Lines 1164-1181 Link Here
1164
        static final long serialVersionUID = 1L;
1167
        static final long serialVersionUID = 1L;
1165
        private static ClassLoader l;
1168
        private static ClassLoader l;
1166
        private String clazzName;
1169
        private String clazzName;
1167
        private transient Class clazz;
1170
        private transient Class<?> clazz;
1168
        private ArrayList children;
1171
        private ArrayList<Node> children;
1169
        private ArrayList items;
1172
        private ArrayList<Pair> items;
1170
1173
1171
        public R(Node n) {
1174
        public R(Node n) {
1172
            this.clazzName = n.getType().getName();
1175
            this.clazzName = n.getType().getName();
1173
            this.children = n.children;
1176
            this.children = n.children;
1174
1177
1175
            if (n.items instanceof ArrayList || (n.items == null)) {
1178
            if (n.items instanceof ArrayList || (n.items == null)) {
1176
                this.items = (ArrayList) n.items;
1179
                this.items = (ArrayList<Pair>) n.items;
1177
            } else {
1180
            } else {
1178
                this.items = new ArrayList(n.items);
1181
                this.items = new ArrayList<Pair>(n.items);
1179
            }
1182
            }
1180
        }
1183
        }
1181
1184
Lines 1204-1213 Link Here
1204
    /** Just a marker class to be able to do instanceof and find out
1207
    /** Just a marker class to be able to do instanceof and find out
1205
     * that this enumeration is not sorted
1208
     * that this enumeration is not sorted
1206
     */
1209
     */
1207
    private static final class NeedsSortEnum implements Enumeration {
1210
    private static final class NeedsSortEnum<T> implements Enumeration<T> {
1208
        private Enumeration en;
1211
        private Enumeration<T> en;
1209
1212
1210
        public NeedsSortEnum(Enumeration en) {
1213
        public NeedsSortEnum(Enumeration<T> en) {
1211
            this.en = en;
1214
            this.en = en;
1212
        }
1215
        }
1213
1216
Lines 1215-1221 Link Here
1215
            return en.hasMoreElements();
1218
            return en.hasMoreElements();
1216
        }
1219
        }
1217
1220
1218
        public Object nextElement() {
1221
        public T nextElement() {
1219
            return en.nextElement();
1222
            return en.nextElement();
1220
        }
1223
        }
1221
    }
1224
    }
(-)openide/util/src/org/openide/util/lookup/InstanceContent.java (-41 / +38 lines)
Lines 47-53 Link Here
47
     * @param inst instance
47
     * @param inst instance
48
     */
48
     */
49
    public final void add(Object inst) {
49
    public final void add(Object inst) {
50
        addPair(new SimpleItem(inst));
50
        addPair(new SimpleItem<Object>(inst));
51
    }
51
    }
52
52
53
    /** The method to add instance to the lookup with.
53
    /** The method to add instance to the lookup with.
Lines 55-69 Link Here
55
     * @param conv convertor which postponing an instantiation,
55
     * @param conv convertor which postponing an instantiation,
56
     * if <code>conv==null</code> then the instance is registered directly.
56
     * if <code>conv==null</code> then the instance is registered directly.
57
     */
57
     */
58
    public final void add(Object inst, Convertor conv) {
58
    public final <T,R> void add(T inst, Convertor<T,R> conv) {
59
        addPair(new ConvertingItem(inst, conv));
59
        addPair(new ConvertingItem<T,R>(inst, conv));
60
    }
60
    }
61
61
62
    /** Remove instance.
62
    /** Remove instance.
63
     * @param inst instance
63
     * @param inst instance
64
     */
64
     */
65
    public final void remove(Object inst) {
65
    public final void remove(Object inst) {
66
        removePair(new SimpleItem(inst));
66
        removePair(new SimpleItem<Object>(inst));
67
    }
67
    }
68
68
69
    /** Remove instance added with a convertor.
69
    /** Remove instance added with a convertor.
Lines 71-78 Link Here
71
     * @param conv convertor, if <code>conv==null</code> it is same like
71
     * @param conv convertor, if <code>conv==null</code> it is same like
72
     * remove(Object)
72
     * remove(Object)
73
     */
73
     */
74
    public final void remove(Object inst, Convertor conv) {
74
    public final <T,R> void remove(T inst, Convertor<T,R> conv) {
75
        removePair(new ConvertingItem(inst, conv));
75
        removePair(new ConvertingItem<T,R>(inst, conv));
76
    }
76
    }
77
77
78
    /** Changes all pairs in the lookup to new values. Converts collection of
78
    /** Changes all pairs in the lookup to new values. Converts collection of
Lines 80-96 Link Here
80
     * @param col the collection of (Item) objects
80
     * @param col the collection of (Item) objects
81
     * @param conv the convertor to use or null
81
     * @param conv the convertor to use or null
82
     */
82
     */
83
    public final void set(Collection col, Convertor conv) {
83
    public final <T,R> void set(Collection<T> col, Convertor<T,R> conv) {
84
        ArrayList l = new ArrayList(col.size());
84
        ArrayList<Pair<?>> l = new ArrayList<Pair<?>>(col.size());
85
        Iterator it = col.iterator();
85
        Iterator<T> it = col.iterator();
86
86
87
        if (conv == null) {
87
        if (conv == null) {
88
            while (it.hasNext()) {
88
            while (it.hasNext()) {
89
                l.add(new SimpleItem(it.next()));
89
                l.add(new SimpleItem<T>(it.next()));
90
            }
90
            }
91
        } else {
91
        } else {
92
            while (it.hasNext()) {
92
            while (it.hasNext()) {
93
                l.add(new ConvertingItem(it.next(), conv));
93
                l.add(new ConvertingItem<T,R>(it.next(), conv));
94
            }
94
            }
95
        }
95
        }
96
96
Lines 100-106 Link Here
100
    /** Convertor postpones an instantiation of an object.
100
    /** Convertor postpones an instantiation of an object.
101
     * @since 1.25
101
     * @since 1.25
102
     */
102
     */
103
    public static interface Convertor {
103
    public static interface Convertor<T,R> {
104
        /** Convert obj to other object. There is no need to implement
104
        /** Convert obj to other object. There is no need to implement
105
         * cache mechanism. It is provided by InstanceLookup.Item.getInstance().
105
         * cache mechanism. It is provided by InstanceLookup.Item.getInstance().
106
         * Method should be called more than once because Lookup holds
106
         * Method should be called more than once because Lookup holds
Lines 109-156 Link Here
109
         * @param obj the registered object
109
         * @param obj the registered object
110
         * @return the object converted from this object
110
         * @return the object converted from this object
111
         */
111
         */
112
        public Object convert(Object obj);
112
        public R convert(T obj);
113
113
114
        /** Return type of converted object.
114
        /** Return type of converted object.
115
         * @param obj the registered object
115
         * @param obj the registered object
116
         * @return the class that will be produced from this object (class or
116
         * @return the class that will be produced from this object (class or
117
         *      superclass of convert (obj))
117
         *      superclass of convert (obj))
118
         */
118
         */
119
        public Class type(Object obj);
119
        public Class<? extends R> type(T obj);
120
120
121
        /** Computes the ID of the resulted object.
121
        /** Computes the ID of the resulted object.
122
         * @param obj the registered object
122
         * @param obj the registered object
123
         * @return the ID for the object
123
         * @return the ID for the object
124
         */
124
         */
125
        public String id(Object obj);
125
        public String id(T obj);
126
126
127
        /** The human presentable name for the object.
127
        /** The human presentable name for the object.
128
         * @param obj the registered object
128
         * @param obj the registered object
129
         * @return the name representing the object for the user
129
         * @return the name representing the object for the user
130
         */
130
         */
131
        public String displayName(Object obj);
131
        public String displayName(T obj);
132
    }
132
    }
133
133
134
    /** Instance of one item representing an object.
134
    /** Instance of one item representing an object.
135
     */
135
     */
136
    final static class SimpleItem extends Pair {
136
    final static class SimpleItem<T> extends Pair<T> {
137
        private Object obj;
137
        private T obj;
138
138
139
        /** Create an item.
139
        /** Create an item.
140
         * @obj object to register
140
         * @obj object to register
141
         */
141
         */
142
        public SimpleItem(Object obj) {
142
        public SimpleItem(T obj) {
143
            if (obj == null) {
143
            if (obj == null) {
144
                throw new NullPointerException();
144
                throw new NullPointerException();
145
            }
145
            }
146
147
            this.obj = obj;
146
            this.obj = obj;
148
        }
147
        }
149
148
150
        /** Tests whether this item can produce object
149
        /** Tests whether this item can produce object
151
         * of class c.
150
         * of class c.
152
         */
151
         */
153
        public boolean instanceOf(Class c) {
152
        public boolean instanceOf(Class<?> c) {
154
            return c.isInstance(obj);
153
            return c.isInstance(obj);
155
        }
154
        }
156
155
Lines 159-165 Link Here
159
         * to converted object is saved.
158
         * to converted object is saved.
160
         * @return the instance of the object.
159
         * @return the instance of the object.
161
         */
160
         */
162
        public Object getInstance() {
161
        public T getInstance() {
163
            return obj;
162
            return obj;
164
        }
163
        }
165
164
Lines 203-231 Link Here
203
        /** The class of this item.
202
        /** The class of this item.
204
         * @return the correct class
203
         * @return the correct class
205
         */
204
         */
206
        public Class getType() {
205
        @SuppressWarnings("unchecked")
207
            return obj.getClass();
206
        public Class<? extends T> getType() {
207
            return (Class<? extends T>)obj.getClass();
208
        }
208
        }
209
    }
209
    }
210
     // end of SimpleItem
210
     // end of SimpleItem
211
211
212
    /** Instance of one item registered in the map.
212
    /** Instance of one item registered in the map.
213
     */
213
     */
214
    final static class ConvertingItem extends Pair {
214
    final static class ConvertingItem<T,R> extends Pair<R> {
215
        /** registered object */
215
        /** registered object */
216
        private Object obj;
216
        private T obj;
217
217
218
        /** Reference to converted object. */
218
        /** Reference to converted object. */
219
        private WeakReference ref;
219
        private WeakReference<R> ref;
220
220
221
        /** convertor to use */
221
        /** convertor to use */
222
        private Convertor conv;
222
        private Convertor<? super T,R> conv;
223
223
224
        /** Create an item.
224
        /** Create an item.
225
         * @obj object to register
225
         * @obj object to register
226
         * @conv a convertor, can be <code>null</code>.
226
         * @conv a convertor, can be <code>null</code>.
227
         */
227
         */
228
        public ConvertingItem(Object obj, Convertor conv) {
228
        public ConvertingItem(T obj, Convertor<? super T,R> conv) {
229
            this.obj = obj;
229
            this.obj = obj;
230
            this.conv = conv;
230
            this.conv = conv;
231
        }
231
        }
Lines 233-246 Link Here
233
        /** Tests whether this item can produce object
233
        /** Tests whether this item can produce object
234
         * of class c.
234
         * of class c.
235
         */
235
         */
236
        public boolean instanceOf(Class c) {
236
        public boolean instanceOf(Class<?> c) {
237
            return c.isAssignableFrom(getType());
237
            return c.isAssignableFrom(getType());
238
        }
238
        }
239
239
240
        /** Returns converted object or null if obj has not been converted yet
240
        /** Returns converted object or null if obj has not been converted yet
241
         * or reference was cleared by garbage collector.
241
         * or reference was cleared by garbage collector.
242
         */
242
         */
243
        private Object getConverted() {
243
        private R getConverted() {
244
            if (ref == null) {
244
            if (ref == null) {
245
                return null;
245
                return null;
246
            }
246
            }
Lines 253-264 Link Here
253
         * to converted object is saved.
253
         * to converted object is saved.
254
         * @return the instance of the object.
254
         * @return the instance of the object.
255
         */
255
         */
256
        public synchronized Object getInstance() {
256
        public synchronized R getInstance() {
257
            Object converted = getConverted();
257
            R converted = getConverted();
258
258
259
            if (converted == null) {
259
            if (converted == null) {
260
                converted = conv.convert(obj);
260
                converted = conv.convert(obj);
261
                ref = new WeakReference(converted);
261
                ref = new WeakReference<R>(converted);
262
            }
262
            }
263
263
264
            return converted;
264
            return converted;
Lines 308-325 Link Here
308
        /** The class of this item.
308
        /** The class of this item.
309
         * @return the correct class
309
         * @return the correct class
310
         */
310
         */
311
        public Class getType() {
311
        @SuppressWarnings("unchecked")
312
            if (conv == null) {
312
        public Class<? extends R> getType() {
313
                return obj.getClass();
313
            R converted = getConverted();
314
            }
315
316
            Object converted = getConverted();
317
314
318
            if (converted == null) {
315
            if (converted == null) {
319
                return conv.type(obj);
316
                return conv.type(obj);
320
            }
317
            }
321
318
322
            return converted.getClass();
319
            return (Class<? extends R>)converted.getClass();
323
        }
320
        }
324
    }
321
    }
325
     // end of ConvertingItem
322
     // end of ConvertingItem
(-)openide/util/src/org/openide/util/lookup/Lookups.java (-1 / +1 lines)
Lines 83-89 Link Here
83
     * @since 2.21
83
     * @since 2.21
84
     *
84
     *
85
     */
85
     */
86
    public static Lookup fixed(Object[] keys, InstanceContent.Convertor convertor) {
86
    public static <T,R> Lookup fixed(T[] keys, InstanceContent.Convertor<? super T,R> convertor) {
87
        if (keys == null) {
87
        if (keys == null) {
88
            throw new NullPointerException();
88
            throw new NullPointerException();
89
        }
89
        }
(-)openide/util/src/org/openide/util/lookup/MetaInfServicesLookup.java (-16 / +18 lines)
Lines 21-27 Link Here
21
import java.util.ArrayList;
21
import java.util.ArrayList;
22
import java.util.Collection;
22
import java.util.Collection;
23
import java.util.Enumeration;
23
import java.util.Enumeration;
24
import java.util.HashSet;
24
import java.util.Iterator;
25
import java.util.Iterator;
26
import java.util.LinkedHashSet;
25
import java.util.List;
27
import java.util.List;
26
import java.util.Map;
28
import java.util.Map;
27
import java.util.Set;
29
import java.util.Set;
Lines 46-52 Link Here
46
final class MetaInfServicesLookup extends AbstractLookup {
48
final class MetaInfServicesLookup extends AbstractLookup {
47
    // Better not to use ErrorManager here - EM.gD will use this class, might cause cycles etc.
49
    // Better not to use ErrorManager here - EM.gD will use this class, might cause cycles etc.
48
    private static final boolean DEBUG = Boolean.getBoolean("org.openide.util.lookup.MetaInfServicesLookup.DEBUG"); // NOI18N
50
    private static final boolean DEBUG = Boolean.getBoolean("org.openide.util.lookup.MetaInfServicesLookup.DEBUG"); // NOI18N
49
    private static final Map knownInstances = new WeakHashMap(); // Map<Class,Object>
51
    private static final Map<Class,Object> knownInstances = new WeakHashMap<Class,Object>();
50
52
51
    /** A set of all requested classes.
53
    /** A set of all requested classes.
52
     * Note that classes that we actually succeeded on can never be removed
54
     * Note that classes that we actually succeeded on can never be removed
Lines 54-60 Link Here
54
     * However we also hold classes which are definitely not loadable by
56
     * However we also hold classes which are definitely not loadable by
55
     * our loader.
57
     * our loader.
56
     */
58
     */
57
    private final Set classes = new WeakSet(); // Set<Class>
59
    private final Set<Class> classes = new WeakSet<Class>(); // Set<Class>
58
60
59
    /** class loader to use */
61
    /** class loader to use */
60
    private final ClassLoader loader;
62
    private final ClassLoader loader;
Lines 85-96 Link Here
85
    protected final void beforeLookup(Lookup.Template t) {
87
    protected final void beforeLookup(Lookup.Template t) {
86
        Class c = t.getType();
88
        Class c = t.getType();
87
89
88
        Object listeners;
90
        HashSet<AbstractLookup.R> listeners;
89
91
90
        synchronized (this) {
92
        synchronized (this) {
91
            if (classes.add(c)) {
93
            if (classes.add(c)) {
92
                // Added new class, search for it.
94
                // Added new class, search for it.
93
                Collection arr = getPairsAsLHS();
95
                LinkedHashSet<Pair<?>> arr = getPairsAsLHS();
94
                search(c, arr);
96
                search(c, arr);
95
97
96
                // listeners are notified under while holding lock on class c, 
98
                // listeners are notified under while holding lock on class c, 
Lines 110-116 Link Here
110
     * @param clazz class to find
112
     * @param clazz class to find
111
     * @param result collection to add Pair to
113
     * @param result collection to add Pair to
112
     */
114
     */
113
    private void search(Class clazz, Collection result) {
115
    private void search(Class<?> clazz, Collection<Pair<?>> result) {
114
        if (DEBUG) {
116
        if (DEBUG) {
115
            System.err.println("Searching for " + clazz.getName() + " in " + clazz.getClassLoader() + " from " + this); // NOI18N
117
            System.err.println("Searching for " + clazz.getName() + " in " + clazz.getClassLoader() + " from " + this); // NOI18N
116
        }
118
        }
Lines 132-139 Link Here
132
        // has the same entry in it (and they load to the same class).
134
        // has the same entry in it (and they load to the same class).
133
        // Probably would not happen, assuming JARs only list classes
135
        // Probably would not happen, assuming JARs only list classes
134
        // they own, but just in case...
136
        // they own, but just in case...
135
        List /*<Item>*/ foundClasses = new ArrayList();
137
        List<Item> foundClasses = new ArrayList<Item>();
136
        Collection removeClasses = new ArrayList(); // Collection<Class>
138
        Collection<Class> removeClasses = new ArrayList<Class>();
137
139
138
        boolean foundOne = false;
140
        boolean foundOne = false;
139
141
Lines 310-316 Link Here
310
    /**
312
    /**
311
     * Insert item to the list according to item.position value.
313
     * Insert item to the list according to item.position value.
312
     */
314
     */
313
    private void insertItem(Item item, List list) {
315
    private void insertItem(Item item, List<Item> list) {
314
        // no position? -> add it to the end
316
        // no position? -> add it to the end
315
        if (item.position == -1) {
317
        if (item.position == -1) {
316
            list.add(item);
318
            list.add(item);
Lines 349-355 Link Here
349
351
350
    /** Pair that holds name of a class and maybe the instance.
352
    /** Pair that holds name of a class and maybe the instance.
351
     */
353
     */
352
    private static final class P extends AbstractLookup.Pair {
354
    private static final class P extends AbstractLookup.Pair<Object> {
353
        /** May be one of three things:
355
        /** May be one of three things:
354
         * 1. The implementation class which was named in the services file.
356
         * 1. The implementation class which was named in the services file.
355
         * 2. An instance of it.
357
         * 2. An instance of it.
Lines 357-373 Link Here
357
         */
359
         */
358
        private Object object;
360
        private Object object;
359
361
360
        public P(Class clazz) {
362
        public P(Class<?> clazz) {
361
            this.object = clazz;
363
            this.object = clazz;
362
        }
364
        }
363
365
364
        /** Finds the class.
366
        /** Finds the class.
365
         */
367
         */
366
        private Class clazz() {
368
        private Class<? extends Object> clazz() {
367
            Object o = object;
369
            Object o = object;
368
370
369
            if (o instanceof Class) {
371
            if (o instanceof Class) {
370
                return (Class) o;
372
                return (Class<? extends Object>) o;
371
            } else if (o != null) {
373
            } else if (o != null) {
372
                return o.getClass();
374
                return o.getClass();
373
            } else {
375
            } else {
Lines 388-398 Link Here
388
            return clazz().hashCode();
390
            return clazz().hashCode();
389
        }
391
        }
390
392
391
        protected boolean instanceOf(Class c) {
393
        protected boolean instanceOf(Class<?> c) {
392
            return c.isAssignableFrom(clazz());
394
            return c.isAssignableFrom(clazz());
393
        }
395
        }
394
396
395
        public Class getType() {
397
        public Class<? extends Object> getType() {
396
            return clazz();
398
            return clazz();
397
        }
399
        }
398
400
Lines 405-411 Link Here
405
                                   // 2 instances of the same class
407
                                   // 2 instances of the same class
406
408
407
                    try {
409
                    try {
408
                        Class c = ((Class) o);
410
                        Class<?> c = ((Class) o);
409
411
410
                        synchronized (knownInstances) { // guards only the static cache
412
                        synchronized (knownInstances) { // guards only the static cache
411
                            o = knownInstances.get(c);
413
                            o = knownInstances.get(c);
Lines 413-419 Link Here
413
415
414
                        if (o == null) {
416
                        if (o == null) {
415
                            if (SharedClassObject.class.isAssignableFrom(c)) {
417
                            if (SharedClassObject.class.isAssignableFrom(c)) {
416
                                o = SharedClassObject.findObject(c, true);
418
                                o = SharedClassObject.findObject(c.asSubclass(SharedClassObject.class), true);
417
                            } else {
419
                            } else {
418
                                o = c.newInstance();
420
                                o = c.newInstance();
419
                            }
421
                            }
(-)openide/util/src/org/openide/util/lookup/ProxyLookup.java (-68 / +79 lines)
Lines 37-43 Link Here
37
    private Object lookups;
37
    private Object lookups;
38
38
39
    /** map of templates to currently active results */
39
    /** map of templates to currently active results */
40
    private HashMap results;
40
    private HashMap<Template<?>,Reference<R>> results;
41
41
42
    /** Create a proxy to some other lookups.
42
    /** Create a proxy to some other lookups.
43
     * @param lookups the initial delegates
43
     * @param lookups the initial delegates
Lines 106-120 Link Here
106
     * @since 1.19 protected
106
     * @since 1.19 protected
107
     */
107
     */
108
    protected final void setLookups(Lookup[] lookups) {
108
    protected final void setLookups(Lookup[] lookups) {
109
        Reference[] arr;
109
        Collection<Reference<R>> arr;
110
        HashSet newL;
110
        HashSet<Lookup> newL;
111
        HashSet current;
111
        HashSet<Lookup> current;
112
        Lookup[] old;
112
        Lookup[] old;
113
113
114
        synchronized (this) {
114
        synchronized (this) {
115
            old = getLookups(false);
115
            old = getLookups(false);
116
            current = new HashSet(Arrays.asList(old));
116
            current = new HashSet<Lookup>(Arrays.asList(old));
117
            newL = new HashSet(Arrays.asList(lookups));
117
            newL = new HashSet<Lookup>(Arrays.asList(lookups));
118
118
119
            setLookupsNoFire(lookups);
119
            setLookupsNoFire(lookups);
120
            
120
            
Lines 123-131 Link Here
123
                return;
123
                return;
124
            }
124
            }
125
125
126
            arr = (Reference[]) results.values().toArray(new Reference[0]);
126
            arr = new ArrayList<Reference<R>>(results.values());
127
127
128
            HashSet removed = new HashSet(current);
128
            HashSet<Lookup> removed = new HashSet<Lookup>(current);
129
            removed.removeAll(newL); // current contains just those lookups that have disappeared
129
            removed.removeAll(newL); // current contains just those lookups that have disappeared
130
            newL.removeAll(current); // really new lookups
130
            newL.removeAll(current); // really new lookups
131
131
Lines 134-142 Link Here
134
                return;
134
                return;
135
            }
135
            }
136
136
137
            for (int i = 0; i < arr.length; i++) {
137
            for (Reference<R> ref : arr) {
138
                R r = (R) arr[i].get();
138
                R r = ref.get();
139
140
                if (r != null) {
139
                if (r != null) {
141
                    r.lookupChange(newL, removed, old, lookups);
140
                    r.lookupChange(newL, removed, old, lookups);
142
                }
141
                }
Lines 144-153 Link Here
144
        }
143
        }
145
144
146
        // this cannot be done from the synchronized block
145
        // this cannot be done from the synchronized block
147
        ArrayList evAndListeners = new ArrayList();
146
        ArrayList<Object> evAndListeners = new ArrayList<Object>();
148
        for (int i = 0; i < arr.length; i++) {
147
        for (Reference<R> ref : arr) {
149
            R r = (R) arr[i].get();
148
            R<?> r = ref.get();
150
151
            if (r != null) {
149
            if (r != null) {
152
                r.collectFires(evAndListeners);
150
                r.collectFires(evAndListeners);
153
            }
151
            }
Lines 171-186 Link Here
171
     * @param template the template of the query
169
     * @param template the template of the query
172
     * @since 1.31
170
     * @since 1.31
173
     */
171
     */
174
    protected void beforeLookup(Template template) {
172
    protected void beforeLookup(Template<?> template) {
175
    }
173
    }
176
174
177
    public final Object lookup(Class clazz) {
175
    public final <T> T lookup(Class<T> clazz) {
178
        beforeLookup(new Template(clazz));
176
        beforeLookup(new Template<T>(clazz));
179
177
180
        Lookup[] lookups = this.getLookups(false);
178
        Lookup[] lookups = this.getLookups(false);
181
179
182
        for (int i = 0; i < lookups.length; i++) {
180
        for (int i = 0; i < lookups.length; i++) {
183
            Object o = lookups[i].lookup(clazz);
181
            T o = lookups[i].lookup(clazz);
184
182
185
            if (o != null) {
183
            if (o != null) {
186
                return o;
184
                return o;
Lines 190-202 Link Here
190
        return null;
188
        return null;
191
    }
189
    }
192
190
193
    public final Item lookupItem(Template template) {
191
    public final <T> Item<T> lookupItem(Template<T> template) {
194
        beforeLookup(template);
192
        beforeLookup(template);
195
193
196
        Lookup[] lookups = this.getLookups(false);
194
        Lookup[] lookups = this.getLookups(false);
197
195
198
        for (int i = 0; i < lookups.length; i++) {
196
        for (int i = 0; i < lookups.length; i++) {
199
            Item o = lookups[i].lookupItem(template);
197
            Item<T> o = lookups[i].lookupItem(template);
200
198
201
            if (o != null) {
199
            if (o != null) {
202
                return o;
200
                return o;
Lines 206-239 Link Here
206
        return null;
204
        return null;
207
    }
205
    }
208
206
209
    public final synchronized Result lookup(Lookup.Template template) {
207
    @SuppressWarnings("unchecked")
210
        R r;
208
    private static <T> R<T> convertResult(R r) {
209
        return (R<T>)r;
210
    }
211
211
212
    public final synchronized <T> Result<T> lookup(Lookup.Template<T> template) {
212
        if (results != null) {
213
        if (results != null) {
213
            Reference ref = (Reference) results.get(template);
214
            Reference<R> ref = results.get(template);
214
            r = (ref == null) ? null : (R) ref.get();
215
            R r = (ref == null) ? null : ref.get();
215
216
216
            if (r != null) {
217
            if (r != null) {
217
                return r;
218
                return convertResult(r);
218
            }
219
            }
219
        } else {
220
        } else {
220
            results = new HashMap();
221
            results = new HashMap<Template<?>,Reference<R>>();
221
        }
222
        }
222
223
223
        r = new R(template);
224
        R<T> newR = new R<T>(template);
224
        results.put(template, new java.lang.ref.SoftReference(r));
225
        results.put(template, new java.lang.ref.SoftReference<R>(newR));
225
226
226
        return r;
227
        return newR;
227
    }
228
    }
228
229
229
    /** Unregisters a template from the has map.
230
    /** Unregisters a template from the has map.
230
     */
231
     */
231
    private final synchronized void unregisterTemplate(Template template) {
232
    private final synchronized void unregisterTemplate(Template<?> template) {
232
        if (results == null) {
233
        if (results == null) {
233
            return;
234
            return;
234
        }
235
        }
235
236
236
        Reference ref = (Reference) results.remove(template);
237
        Reference<R> ref = results.remove(template);
237
238
238
        if ((ref != null) && (ref.get() != null)) {
239
        if ((ref != null) && (ref.get() != null)) {
239
            // seems like there is a reference to a result for this template
240
            // seems like there is a reference to a result for this template
Lines 246-269 Link Here
246
     * that was found (not too useful) and also to all objects found
247
     * that was found (not too useful) and also to all objects found
247
     * (more useful).
248
     * (more useful).
248
     */
249
     */
249
    private final class R extends WaitableResult {
250
    private final class R<T> extends WaitableResult<T> {
250
        /** list of listeners added */
251
        /** list of listeners added */
251
        private javax.swing.event.EventListenerList listeners;
252
        private javax.swing.event.EventListenerList listeners;
252
253
253
        /** template for this result */
254
        /** template for this result */
254
        private Lookup.Template template;
255
        private Lookup.Template<T> template;
255
256
256
        /** collection of Objects */
257
        /** collection of Objects */
257
        private Collection[] cache;
258
        private Collection[] cache;
258
259
259
        /** weak listener & result */
260
        /** weak listener & result */
260
        private WeakResult weakL;
261
        private WeakResult<T> weakL;
261
262
262
        /** Constructor.
263
        /** Constructor.
263
         */
264
         */
264
        public R(Lookup.Template t) {
265
        public R(Lookup.Template<T> t) {
265
            template = t;
266
            template = t;
266
            weakL = new WeakResult(this);
267
            weakL = new WeakResult<T>(this);
267
        }
268
        }
268
269
269
        /** When garbage collected, remove the template from the has map.
270
        /** When garbage collected, remove the template from the has map.
Lines 272-280 Link Here
272
            unregisterTemplate(template);
273
            unregisterTemplate(template);
273
        }
274
        }
274
275
276
        @SuppressWarnings("unchecked")
277
        private Result<T>[] newResults(int len) {
278
            return new Result[len];
279
        }
280
275
        /** initializes the results
281
        /** initializes the results
276
         */
282
         */
277
        private Result[] initResults() {
283
        private Result<T>[] initResults() {
278
            synchronized (this) {
284
            synchronized (this) {
279
                if (weakL.results != null) {
285
                if (weakL.results != null) {
280
                    return weakL.results;
286
                    return weakL.results;
Lines 282-288 Link Here
282
            }
288
            }
283
289
284
            Lookup[] myLkps = getLookups(false);
290
            Lookup[] myLkps = getLookups(false);
285
            Result[] arr = new Result[myLkps.length];
291
            Result<T>[] arr = newResults(myLkps.length);
286
292
287
            for (int i = 0; i < arr.length; i++) {
293
            for (int i = 0; i < arr.length; i++) {
288
                arr[i] = myLkps[i].lookup(template);
294
                arr[i] = myLkps[i].lookup(template);
Lines 318-324 Link Here
318
                }
324
                }
319
325
320
                // map (Lookup, Lookup.Result)
326
                // map (Lookup, Lookup.Result)
321
                HashMap map = new HashMap(old.length * 2);
327
                HashMap<Lookup,Result<T>> map = new HashMap<Lookup,Result<T>>(old.length * 2);
322
328
323
                for (int i = 0; i < old.length; i++) {
329
                for (int i = 0; i < old.length; i++) {
324
                    if (removed.contains(old[i])) {
330
                    if (removed.contains(old[i])) {
Lines 330-336 Link Here
330
                    }
336
                    }
331
                }
337
                }
332
338
333
                Lookup.Result[] arr = new Lookup.Result[current.length];
339
                Lookup.Result<T>[] arr = newResults(current.length);
334
340
335
                for (int i = 0; i < current.length; i++) {
341
                for (int i = 0; i < current.length; i++) {
336
                    if (added.contains(current[i])) {
342
                    if (added.contains(current[i])) {
Lines 339-345 Link Here
339
                        arr[i].addLookupListener(weakL);
345
                        arr[i].addLookupListener(weakL);
340
                    } else {
346
                    } else {
341
                        // old lookup
347
                        // old lookup
342
                        arr[i] = (Lookup.Result) map.get(current[i]);
348
                        arr[i] = map.get(current[i]);
343
349
344
                        if (arr[i] == null) {
350
                        if (arr[i] == null) {
345
                            // assert
351
                            // assert
Lines 378-384 Link Here
378
        /** Access to all instances in the result.
384
        /** Access to all instances in the result.
379
         * @return collection of all instances
385
         * @return collection of all instances
380
         */
386
         */
381
        public java.util.Collection allInstances() {
387
        @SuppressWarnings("unchecked")
388
        public java.util.Collection<T> allInstances() {
382
            return computeResult(0);
389
            return computeResult(0);
383
        }
390
        }
384
391
Lines 386-400 Link Here
386
         * that are registered in the system.
393
         * that are registered in the system.
387
         * @return set of Class objects
394
         * @return set of Class objects
388
         */
395
         */
389
        public java.util.Set allClasses() {
396
        @SuppressWarnings("unchecked")
390
            return (java.util.Set) computeResult(1);
397
        public java.util.Set<Class<? extends T>> allClasses() {
398
            return (java.util.Set<Class<? extends T>>) computeResult(1);
391
        }
399
        }
392
400
393
        /** All registered items. The collection of all pairs of
401
        /** All registered items. The collection of all pairs of
394
         * ii and their classes.
402
         * ii and their classes.
395
         * @return collection of Lookup.Item
403
         * @return collection of Lookup.Item
396
         */
404
         */
397
        public java.util.Collection allItems() {
405
        @SuppressWarnings("unchecked")
406
        public java.util.Collection<? extends Item<T>> allItems() {
398
            return computeResult(2);
407
            return computeResult(2);
399
        }
408
        }
400
409
Lines 404-410 Link Here
404
         */
413
         */
405
        private java.util.Collection computeResult(int indexToCache) {
414
        private java.util.Collection computeResult(int indexToCache) {
406
            // results to use
415
            // results to use
407
            Lookup.Result[] arr = myBeforeLookup();
416
            Lookup.Result<T>[] arr = myBeforeLookup();
408
417
409
            // if the call to beforeLookup resulted in deletion of caches
418
            // if the call to beforeLookup resulted in deletion of caches
410
            synchronized (this) {
419
            synchronized (this) {
Lines 417-431 Link Here
417
            }
426
            }
418
427
419
            // initialize the collection to hold result
428
            // initialize the collection to hold result
420
            Collection compute;
429
            Collection<Object> compute;
421
            Collection ret;
430
            Collection<Object> ret;
422
431
423
            if (indexToCache == 1) {
432
            if (indexToCache == 1) {
424
                compute = new HashSet();
433
                HashSet<Object> s = new HashSet<Object>();
425
                ret = Collections.unmodifiableSet((Set)compute);
434
                compute = s;
435
                ret = Collections.unmodifiableSet(s);
426
            } else {
436
            } else {
427
                compute = new ArrayList(arr.length * 2);
437
                List<Object> l = new ArrayList<Object>(arr.length * 2);
428
                ret = Collections.unmodifiableList((List)compute);
438
                compute = l;
439
                ret = Collections.unmodifiableList(l);
429
            }
440
            }
430
441
431
            // fill the collection
442
            // fill the collection
Lines 469-475 Link Here
469
            collectFires(null);
480
            collectFires(null);
470
        }
481
        }
471
        
482
        
472
        protected void collectFires(Collection evAndListeners) {
483
        protected void collectFires(Collection<Object> evAndListeners) {
473
            // clear cached instances
484
            // clear cached instances
474
            Collection oldItems;
485
            Collection oldItems;
475
            Collection oldInstances;
486
            Collection oldInstances;
Lines 528-537 Link Here
528
        /** Implementation of my before lookup.
539
        /** Implementation of my before lookup.
529
         * @return results to work on.
540
         * @return results to work on.
530
         */
541
         */
531
        private Lookup.Result[] myBeforeLookup() {
542
        private Lookup.Result<T>[] myBeforeLookup() {
532
            ProxyLookup.this.beforeLookup(template);
543
            ProxyLookup.this.beforeLookup(template);
533
544
534
            Lookup.Result[] arr = initResults();
545
            Lookup.Result<T>[] arr = initResults();
535
546
536
            // invoke update on the results
547
            // invoke update on the results
537
            for (int i = 0; i < arr.length; i++) {
548
            for (int i = 0; i < arr.length; i++) {
Lines 552-569 Link Here
552
            }
563
            }
553
        }
564
        }
554
    }
565
    }
555
    private static final class WeakResult extends WaitableResult implements LookupListener {
566
    private static final class WeakResult<T> extends WaitableResult<T> implements LookupListener {
556
        /** all results */
567
        /** all results */
557
        private Lookup.Result[] results;
568
        private Lookup.Result<T>[] results;
558
569
559
        private Reference result;
570
        private Reference<R> result;
560
        
571
        
561
        public WeakResult(R r) {
572
        public WeakResult(R r) {
562
            this.result = new WeakReference(r);
573
            this.result = new WeakReference<R>(r);
563
        }
574
        }
564
        
575
        
565
        protected void beforeLookup(Lookup.Template t) {
576
        protected void beforeLookup(Lookup.Template t) {
566
            R r = (R)result.get();
577
            R r = result.get();
567
            if (r != null) {
578
            if (r != null) {
568
                r.beforeLookup(t);
579
                r.beforeLookup(t);
569
            } else {
580
            } else {
Lines 572-578 Link Here
572
        }
583
        }
573
584
574
        private void removeListeners() {
585
        private void removeListeners() {
575
            Lookup.Result[] arr = this.results;
586
            Lookup.Result<T>[] arr = this.results;
576
            if (arr == null) {
587
            if (arr == null) {
577
                return;
588
                return;
578
            }
589
            }
Lines 582-589 Link Here
582
            }
593
            }
583
        }
594
        }
584
595
585
        protected void collectFires(Collection evAndListeners) {
596
        protected void collectFires(Collection<Object> evAndListeners) {
586
            R r = (R)result.get();
597
            R<?> r = result.get();
587
            if (r != null) {
598
            if (r != null) {
588
                r.collectFires(evAndListeners);
599
                r.collectFires(evAndListeners);
589
            } else {
600
            } else {
Lines 599-611 Link Here
599
            assert false;
610
            assert false;
600
        }
611
        }
601
612
602
        public Collection allInstances() {
613
        public Collection<T> allInstances() {
603
            assert false;
614
            assert false;
604
            return null;
615
            return null;
605
        }
616
        }
606
617
607
        public void resultChanged(LookupEvent ev) {
618
        public void resultChanged(LookupEvent ev) {
608
            R r = (R)result.get();
619
            R r = result.get();
609
            if (r != null) {
620
            if (r != null) {
610
                r.resultChanged(ev);
621
                r.resultChanged(ev);
611
            } else {
622
            } else {
Lines 613-624 Link Here
613
            }
624
            }
614
        }
625
        }
615
626
616
        public Collection allItems() {
627
        public Collection<? extends Item<T>> allItems() {
617
            assert false;
628
            assert false;
618
            return null;
629
            return null;
619
        }
630
        }
620
631
621
        public Set allClasses() {
632
        public Set<Class<? extends T>> allClasses() {
622
            assert false;
633
            assert false;
623
            return null;
634
            return null;
624
        }
635
        }
(-)openide/util/src/org/openide/util/lookup/SimpleLookup.java (-35 / +41 lines)
Lines 28-77 Link Here
28
class SimpleLookup extends org.openide.util.Lookup {
28
class SimpleLookup extends org.openide.util.Lookup {
29
    /** This variable is initialized in constructor and thus null
29
    /** This variable is initialized in constructor and thus null
30
     * value is not allowed as its value. */
30
     * value is not allowed as its value. */
31
    private Collection allItems;
31
    private Collection<Item<?>> allItems;
32
32
33
    /**
33
    /**
34
     * Creates new Result object with supplied instances parameter.
34
     * Creates new Result object with supplied instances parameter.
35
     * @param instances to be used to return from the lookup
35
     * @param instances to be used to return from the lookup
36
     */
36
     */
37
    SimpleLookup(Collection instances) {
37
    SimpleLookup(Collection<Object> instances) {
38
        allItems = new ArrayList(instances.size());
38
        allItems = new ArrayList<Item<?>>(instances.size());
39
39
40
        for (Iterator i = instances.iterator(); i.hasNext();) {
40
        for (Iterator i = instances.iterator(); i.hasNext();) {
41
            allItems.add(new InstanceContent.SimpleItem(i.next()));
41
            allItems.add(new InstanceContent.SimpleItem<Object>(i.next()));
42
        }
42
        }
43
    }
43
    }
44
44
45
    SimpleLookup(Collection keys, InstanceContent.Convertor conv) {
45
    <T,R> SimpleLookup(Collection<T> keys, InstanceContent.Convertor<? super T,R> conv) {
46
        allItems = new ArrayList(keys.size());
46
        allItems = new ArrayList<Item<?>>(keys.size());
47
47
48
        for (Iterator i = keys.iterator(); i.hasNext();) {
48
        for (T item : keys) {
49
            allItems.add(new InstanceContent.ConvertingItem(i.next(), conv));
49
            allItems.add(new InstanceContent.ConvertingItem<T,R>(item, conv));
50
        }
50
        }
51
    }
51
    }
52
52
53
    public String toString() {
53
    public String toString() {
54
        return "SimpleLookup" + lookup(new Template(Object.class)).allInstances();
54
        return "SimpleLookup" + lookup(new Template<Object>(Object.class)).allInstances();
55
    }
55
    }
56
56
57
    public Result lookup(Template template) {
57
    public <T> Result<T> lookup(Template<T> template) {
58
        if (template == null) {
58
        if (template == null) {
59
            throw new NullPointerException();
59
            throw new NullPointerException();
60
        }
60
        }
61
61
62
        return new SimpleResult(template);
62
        return new SimpleResult<T>(template);
63
    }
63
    }
64
64
65
    public Object lookup(Class clazz) {
65
    public <T> T lookup(Class<T> clazz) {
66
        for (Iterator i = allItems.iterator(); i.hasNext();) {
66
        for (Iterator i = allItems.iterator(); i.hasNext();) {
67
            Object o = i.next();
67
            Object o = i.next();
68
68
69
            if (o instanceof AbstractLookup.Pair) {
69
            if (o instanceof AbstractLookup.Pair) {
70
                AbstractLookup.Pair p = (AbstractLookup.Pair)o;
70
                AbstractLookup.Pair<?> p = (AbstractLookup.Pair<?>)o;
71
                if (p.instanceOf(clazz)) {
71
                if (p.instanceOf(clazz)) {
72
                    Object ret = p.getInstance();
72
                    Object ret = p.getInstance();
73
                    if (clazz.isInstance(ret)) {
73
                    if (clazz.isInstance(ret)) {
74
                        return ret;
74
                        return clazz.cast(ret);
75
                    }
75
                    }
76
                }
76
                }
77
            }
77
            }
Lines 83-94 Link Here
83
     * @param item the item to match
83
     * @param item the item to match
84
     * @return true if item matches the template requirements, false if not
84
     * @return true if item matches the template requirements, false if not
85
     */
85
     */
86
    private static boolean matches(Template t, AbstractLookup.Pair item) {
86
    private static boolean matches(Template<?> t, AbstractLookup.Pair<?> item) {
87
        if (!AbstractLookup.matches(t, item, true)) {
87
        if (!AbstractLookup.matches(t, item, true)) {
88
            return false;
88
            return false;
89
        }
89
        }
90
90
91
        Class type = t.getType();
91
        Class<?> type = t.getType();
92
92
93
        if ((type != null) && !type.isAssignableFrom(item.getType())) {
93
        if ((type != null) && !type.isAssignableFrom(item.getType())) {
94
            return false;
94
            return false;
Lines 102-122 Link Here
102
     * passed in constructor. As the contents of this lookup result never
102
     * passed in constructor. As the contents of this lookup result never
103
     * changes the addLookupListener and removeLookupListener are empty.
103
     * changes the addLookupListener and removeLookupListener are empty.
104
     */
104
     */
105
    private class SimpleResult extends Lookup.Result {
105
    private class SimpleResult<T> extends Lookup.Result<T> {
106
        /** can be null and is initialized lazily */
106
        /** can be null and is initialized lazily */
107
        private Set classes;
107
        private Set<Class<? extends T>> classes;
108
108
109
        /** can be null and is initialized lazily */
109
        /** can be null and is initialized lazily */
110
        private Collection items;
110
        private Collection<? extends Item<T>> items;
111
111
112
        /** Template used for this result. It is never null.*/
112
        /** Template used for this result. It is never null.*/
113
        private Template template;
113
        private Template<T> template;
114
114
115
        /** can be null and is initialized lazily */
115
        /** can be null and is initialized lazily */
116
        private Collection results;
116
        private Collection<T> results;
117
117
118
        /** Just remembers the supplied argument in variable template.*/
118
        /** Just remembers the supplied argument in variable template.*/
119
        SimpleResult(Template template) {
119
        SimpleResult(Template<T> template) {
120
            this.template = template;
120
            this.template = template;
121
        }
121
        }
122
122
Lines 138-154 Link Here
138
         * Lazy initializes the results collection. Uses a call to allItems
138
         * Lazy initializes the results collection. Uses a call to allItems
139
         * to obtain the instances.
139
         * to obtain the instances.
140
         */
140
         */
141
        public java.util.Collection allInstances() {
141
        public java.util.Collection<? extends T> allInstances() {
142
            synchronized (this) {
142
            synchronized (this) {
143
                if (results != null) {
143
                if (results != null) {
144
                    return results;
144
                    return results;
145
                }
145
                }
146
            }
146
            }
147
147
148
            Collection res = new ArrayList(allItems.size());
149
148
150
            for (Iterator i = allItems().iterator(); i.hasNext();) {
149
            Collection<T> res = new ArrayList<T>(allItems.size());
151
                res.add(((Lookup.Item) i.next()).getInstance());
150
151
            for (Item<T> item : allItems()) {
152
                res.add(item.getInstance());
152
            }
153
            }
153
154
154
            synchronized (this) {
155
            synchronized (this) {
Lines 162-178 Link Here
162
         * Lazy initializes variable classes. Uses a call to allItems to
163
         * Lazy initializes variable classes. Uses a call to allItems to
163
         * compute the result.
164
         * compute the result.
164
         */
165
         */
165
        public Set allClasses() {
166
        public Set<Class<? extends T>> allClasses() {
166
            synchronized (this) {
167
            synchronized (this) {
167
                if (classes != null) {
168
                if (classes != null) {
168
                    return classes;
169
                    return classes;
169
                }
170
                }
170
            }
171
            }
171
172
172
            Set res = new HashSet();
173
            Set<Class<? extends T>> res = new HashSet<Class<? extends T>>();
173
174
174
            for (Iterator i = allItems().iterator(); i.hasNext();) {
175
            for (Item<T> item : allItems()) {
175
                res.add(((Lookup.Item) i.next()).getType());
176
                res.add(item.getType());
176
            }
177
            }
177
178
178
            synchronized (this) {
179
            synchronized (this) {
Lines 187-207 Link Here
187
         * element in the instances collection. It puts either SimpleItem
188
         * element in the instances collection. It puts either SimpleItem
188
         * or ConvertingItem to the collection.
189
         * or ConvertingItem to the collection.
189
         */
190
         */
190
        public Collection allItems() {
191
        public Collection<? extends Item<T>> allItems() {
191
            synchronized (this) {
192
            synchronized (this) {
192
                if (items != null) {
193
                if (items != null) {
193
                    return items;
194
                    return items;
194
                }
195
                }
195
            }
196
            }
196
197
197
            Collection res = new ArrayList(allItems.size());
198
            Collection<Item<T>> res = new ArrayList<Item<T>>(allItems.size());
198
199
199
            for (Iterator i = allItems.iterator(); i.hasNext();) {
200
            for (Iterator<Item<?>> i = allItems.iterator(); i.hasNext();) {
200
                Object o = i.next();
201
                Item<?> o = i.next();
201
202
202
                if (o instanceof AbstractLookup.Pair) {
203
                if (o instanceof AbstractLookup.Pair) {
203
                    if (matches(template, (AbstractLookup.Pair) o)) {
204
                    if (matches(template, (AbstractLookup.Pair) o)) {
204
                        res.add(o);
205
                        res.add(cast(o));
205
                    }
206
                    }
206
                }
207
                }
207
            }
208
            }
Lines 211-216 Link Here
211
            }
212
            }
212
213
213
            return items;
214
            return items;
215
        }
216
217
        @SuppressWarnings("unchecked")
218
        private Item<T> cast(Item<?> i) {
219
            return (Item<T>)i;
214
        }
220
        }
215
    }
221
    }
216
}
222
}
(-)openide/util/src/org/openide/util/lookup/SimpleProxyLookup.java (-41 / +47 lines)
Lines 35-41 Link Here
35
    private Lookup delegate;
35
    private Lookup delegate;
36
36
37
    /** map of all templates to Reference (results) associated to this lookup */
37
    /** map of all templates to Reference (results) associated to this lookup */
38
    private WeakHashMap results;
38
    private WeakHashMap<Template<?>,Reference<ProxyResult<?>>> results;
39
39
40
    /**
40
    /**
41
     * @param provider provider to delegate to
41
     * @param provider provider to delegate to
Lines 49-72 Link Here
49
        Lookup l = provider.getLookup();
49
        Lookup l = provider.getLookup();
50
50
51
        // iterator over Reference (ProxyResult)
51
        // iterator over Reference (ProxyResult)
52
        Iterator toCheck = null;
52
        Iterator<Reference<ProxyResult<?>>> toCheck = null;
53
53
54
        synchronized (this) {
54
        synchronized (this) {
55
            if (l != delegate) {
55
            if (l != delegate) {
56
                this.delegate = l;
56
                this.delegate = l;
57
57
58
                if (results != null) {
58
                if (results != null) {
59
                    toCheck = Arrays.asList(results.values().toArray()).iterator();
59
                    toCheck = new ArrayList<Reference<ProxyResult<?>>>(results.values()).iterator();
60
                }
60
                }
61
            }
61
            }
62
        }
62
        }
63
63
64
        if (toCheck != null) {
64
        if (toCheck != null) {
65
            // update
65
            // update
66
            ArrayList evAndListeners = new ArrayList();
66
            ArrayList<Object> evAndListeners = new ArrayList<Object>();
67
            for (Iterator it = toCheck; it.hasNext(); ) {
67
            for (Iterator<Reference<ProxyResult<?>>> it = toCheck; it.hasNext(); ) {
68
                java.lang.ref.Reference ref = (java.lang.ref.Reference) it.next();
68
                java.lang.ref.Reference<ProxyResult<?>> ref = it.next();
69
                ProxyResult p = (ProxyResult) ref.get();
69
                ProxyResult<?> p = ref.get();
70
70
71
                if (p != null && p.updateLookup(l)) {
71
                if (p != null && p.updateLookup(l)) {
72
                    p.collectFires(evAndListeners);
72
                    p.collectFires(evAndListeners);
Lines 83-112 Link Here
83
        return delegate;
83
        return delegate;
84
    }
84
    }
85
85
86
    public Result lookup(Template template) {
86
    @SuppressWarnings("unchecked")
87
    private static <T> ProxyResult<T> cast(ProxyResult<?> p) {
88
        return (ProxyResult<T>)p;
89
    }
90
91
    public <T> Result<T> lookup(Template<T> template) {
87
        synchronized (this) {
92
        synchronized (this) {
88
            if (results == null) {
93
            if (results == null) {
89
                results = new WeakHashMap();
94
                results = new WeakHashMap<Template<?>,Reference<ProxyResult<?>>>();
90
            } else {
95
            } else {
91
                java.lang.ref.Reference ref = (java.lang.ref.Reference) results.get(template);
96
                Reference<ProxyResult<?>> ref = results.get(template);
92
97
93
                if (ref != null) {
98
                if (ref != null) {
94
                    ProxyResult p = (ProxyResult) ref.get();
99
                    ProxyResult<?> p = ref.get();
95
100
96
                    if (p != null) {
101
                    if (p != null) {
97
                        return p;
102
                        return cast(p);
98
                    }
103
                    }
99
                }
104
                }
100
            }
105
            }
101
106
102
            ProxyResult p = new ProxyResult(template);
107
            ProxyResult<T> p = new ProxyResult<T>(template);
103
            results.put(template, new java.lang.ref.WeakReference(p));
108
            Reference<ProxyResult<?>> ref = new WeakReference<ProxyResult<?>>(p);
109
            results.put(template, ref);
104
110
105
            return p;
111
            return p;
106
        }
112
        }
107
    }
113
    }
108
114
109
    public Object lookup(Class clazz) {
115
    public <T> T lookup(Class<T> clazz) {
110
        if (clazz == null) {
116
        if (clazz == null) {
111
            checkLookup();
117
            checkLookup();
112
            return null;
118
            return null;
Lines 114-120 Link Here
114
        return checkLookup().lookup(clazz);
120
        return checkLookup().lookup(clazz);
115
    }
121
    }
116
122
117
    public Item lookupItem(Template template) {
123
    public <T> Item<T> lookupItem(Template<T> template) {
118
        return checkLookup().lookupItem(template);
124
        return checkLookup().lookupItem(template);
119
    }
125
    }
120
126
Lines 123-147 Link Here
123
     * passed in constructor. As the contents of this lookup result never
129
     * passed in constructor. As the contents of this lookup result never
124
     * changes the addLookupListener and removeLookupListener are empty.
130
     * changes the addLookupListener and removeLookupListener are empty.
125
     */
131
     */
126
    private final class ProxyResult extends WaitableResult implements LookupListener {
132
    private final class ProxyResult<T> extends WaitableResult<T> implements LookupListener {
127
        /** Template used for this result. It is never null.*/
133
        /** Template used for this result. It is never null.*/
128
        private Template template;
134
        private Template<T> template;
129
135
130
        /** result to delegate to */
136
        /** result to delegate to */
131
        private Lookup.Result delegate;
137
        private Lookup.Result<T> delegate;
132
138
133
        /** listeners set */
139
        /** listeners set */
134
        private javax.swing.event.EventListenerList listeners;
140
        private javax.swing.event.EventListenerList listeners;
135
        private LookupListener lastListener;
141
        private LookupListener lastListener;
136
142
137
        /** Just remembers the supplied argument in variable template.*/
143
        /** Just remembers the supplied argument in variable template.*/
138
        ProxyResult(Template template) {
144
        ProxyResult(Template<T> template) {
139
            this.template = template;
145
            this.template = template;
140
        }
146
        }
141
147
142
        /** Checks state of the result
148
        /** Checks state of the result
143
         */
149
         */
144
        private Result checkResult() {
150
        private Result<T> checkResult() {
145
            updateLookup(checkLookup());
151
            updateLookup(checkLookup());
146
152
147
            return this.delegate;
153
            return this.delegate;
Lines 151-157 Link Here
151
         * @return true if the lookup really changed
157
         * @return true if the lookup really changed
152
         */
158
         */
153
        public boolean updateLookup(Lookup l) {
159
        public boolean updateLookup(Lookup l) {
154
            Collection oldPairs = (delegate != null) ? delegate.allItems() : null;
160
            Collection<? extends Item<T>> oldPairs = (delegate != null) ? delegate.allItems() : null;
155
161
156
            LookupListener removedListener;
162
            LookupListener removedListener;
157
163
Lines 165-176 Link Here
165
            }
171
            }
166
172
167
            // cannot call to foreign code 
173
            // cannot call to foreign code 
168
            Lookup.Result res = l.lookup(template);
174
            Lookup.Result<T> res = l.lookup(template);
169
175
170
            synchronized (this) {
176
            synchronized (this) {
171
                if (removedListener == lastListener) {
177
                if (removedListener == lastListener) {
172
                    delegate = res;
178
                    delegate = res;
173
                    lastListener = new WeakResult(this, delegate);
179
                    lastListener = new WeakResult<T>(this, delegate);
174
                    delegate.addLookupListener(lastListener);
180
                    delegate.addLookupListener(lastListener);
175
                }
181
                }
176
            }
182
            }
Lines 180-199 Link Here
180
                return false;
186
                return false;
181
            }
187
            }
182
188
183
            Collection newPairs = delegate.allItems();
189
            Collection<? extends Item<T>> newPairs = delegate.allItems();
184
190
185
            // See #34961 for explanation.
191
            // See #34961 for explanation.
186
            if (!(oldPairs instanceof List)) {
192
            if (!(oldPairs instanceof List)) {
187
                if (oldPairs == Collections.EMPTY_SET) {
193
                if (oldPairs == Collections.EMPTY_SET) {
188
                    // avoid allocation
194
                    // avoid allocation
189
                    oldPairs = Collections.EMPTY_LIST;
195
                    oldPairs = Collections.emptyList();
190
                } else {
196
                } else {
191
                    oldPairs = new ArrayList(oldPairs);
197
                    oldPairs = new ArrayList<Item<T>>(oldPairs);
192
                }
198
                }
193
            }
199
            }
194
200
195
            if (!(newPairs instanceof List)) {
201
            if (!(newPairs instanceof List)) {
196
                newPairs = new ArrayList(newPairs);
202
                newPairs = new ArrayList<Item<T>>(newPairs);
197
            }
203
            }
198
204
199
            return !oldPairs.equals(newPairs);
205
            return !oldPairs.equals(newPairs);
Lines 213-227 Link Here
213
            }
219
            }
214
        }
220
        }
215
221
216
        public java.util.Collection allInstances() {
222
        public java.util.Collection<? extends T> allInstances() {
217
            return checkResult().allInstances();
223
            return checkResult().allInstances();
218
        }
224
        }
219
225
220
        public Set allClasses() {
226
        public Set<Class<? extends T>> allClasses() {
221
            return checkResult().allClasses();
227
            return checkResult().allClasses();
222
        }
228
        }
223
229
224
        public Collection allItems() {
230
        public Collection<? extends Item<T>> allItems() {
225
            return checkResult().allItems();
231
            return checkResult().allItems();
226
        }
232
        }
227
233
Lines 241-247 Link Here
241
            collectFires(null);
247
            collectFires(null);
242
        } 
248
        } 
243
        
249
        
244
        protected void collectFires(Collection evAndListeners) {
250
        protected void collectFires(Collection<Object> evAndListeners) {
245
            javax.swing.event.EventListenerList l = this.listeners;
251
            javax.swing.event.EventListenerList l = this.listeners;
246
252
247
            if (l == null) {
253
            if (l == null) {
Lines 259-270 Link Here
259
        }
265
        }
260
    }
266
    }
261
     // end of ProxyResult
267
     // end of ProxyResult
262
    private final class WeakResult extends WaitableResult implements LookupListener {
268
    private final class WeakResult<T> extends WaitableResult<T> implements LookupListener {
263
        private Lookup.Result source;
269
        private Lookup.Result source;
264
        private Reference result;
270
        private Reference<ProxyResult<T>> result;
265
        
271
        
266
        public WeakResult(ProxyResult r, Lookup.Result s) {
272
        public WeakResult(ProxyResult<T> r, Lookup.Result<T> s) {
267
            this.result = new WeakReference(r);
273
            this.result = new WeakReference<ProxyResult<T>>(r);
268
            this.source = s;
274
            this.source = s;
269
        }
275
        }
270
        
276
        
Lines 277-284 Link Here
277
            }
283
            }
278
        }
284
        }
279
285
280
        protected void collectFires(Collection evAndListeners) {
286
        protected void collectFires(Collection<Object> evAndListeners) {
281
            ProxyResult r = (ProxyResult)result.get();
287
            ProxyResult<T> r = result.get();
282
            if (r != null) {
288
            if (r != null) {
283
                r.collectFires(evAndListeners);
289
                r.collectFires(evAndListeners);
284
            } else {
290
            } else {
Lines 294-300 Link Here
294
            assert false;
300
            assert false;
295
        }
301
        }
296
302
297
        public Collection allInstances() {
303
        public Collection<T> allInstances() {
298
            assert false;
304
            assert false;
299
            return null;
305
            return null;
300
        }
306
        }
Lines 308-319 Link Here
308
            }
314
            }
309
        }
315
        }
310
316
311
        public Collection allItems() {
317
        public Collection<? extends Item<T>> allItems() {
312
            assert false;
318
            assert false;
313
            return null;
319
            return null;
314
        }
320
        }
315
321
316
        public Set allClasses() {
322
        public Set<Class<? extends T>> allClasses() {
317
            assert false;
323
            assert false;
318
            return null;
324
            return null;
319
        }
325
        }
(-)openide/util/src/org/openide/util/lookup/WaitableResult.java (-2 / +2 lines)
Lines 20-26 Link Here
20
 *
20
 *
21
 * @author  Jaroslav Tulach
21
 * @author  Jaroslav Tulach
22
 */
22
 */
23
abstract class WaitableResult extends Lookup.Result {
23
abstract class WaitableResult<T> extends Lookup.Result<T> {
24
    /** Used by proxy results to synchronize before lookup.
24
    /** Used by proxy results to synchronize before lookup.
25
     */
25
     */
26
    protected abstract void beforeLookup(Lookup.Template t);
26
    protected abstract void beforeLookup(Lookup.Template t);
Lines 29-34 Link Here
29
     * after all AbstractLookup and ProxyLookups have been updated.
29
     * after all AbstractLookup and ProxyLookups have been updated.
30
     * @param evAndListeners LookupEvent, LookupListener, LookupEvent, LookupListener, etc.
30
     * @param evAndListeners LookupEvent, LookupListener, LookupEvent, LookupListener, etc.
31
     */
31
     */
32
    protected abstract void collectFires(Collection evAndListeners);
32
    protected abstract void collectFires(Collection<Object> evAndListeners);
33
     
33
     
34
}
34
}
(-)openide/util/src/org/openide/xml/EntityCatalog.java (-6 / +3 lines)
Lines 68-74 Link Here
68
     * This catalog is forwarding implementation.
68
     * This catalog is forwarding implementation.
69
     */
69
     */
70
    private static class Forwarder extends EntityCatalog {
70
    private static class Forwarder extends EntityCatalog {
71
        private Lookup.Result result;
71
        private Lookup.Result<EntityCatalog> result;
72
72
73
        Forwarder() {
73
        Forwarder() {
74
        }
74
        }
Lines 76-90 Link Here
76
        public InputSource resolveEntity(String publicID, String systemID)
76
        public InputSource resolveEntity(String publicID, String systemID)
77
        throws IOException, SAXException {
77
        throws IOException, SAXException {
78
            if (result == null) {
78
            if (result == null) {
79
                Lookup.Template temp = new Lookup.Template(EntityCatalog.class);
79
                Lookup.Template<EntityCatalog> temp = new Lookup.Template<EntityCatalog>(EntityCatalog.class);
80
                result = Lookup.getDefault().lookup(temp);
80
                result = Lookup.getDefault().lookup(temp);
81
            }
81
            }
82
82
83
            Iterator it = result.allInstances().iterator();
83
            for (EntityCatalog res : result.allInstances()) {
84
85
            while (it.hasNext()) {
86
                // using resolver's method because EntityCatalog extends EntityResolver
84
                // using resolver's method because EntityCatalog extends EntityResolver
87
                EntityCatalog res = (EntityCatalog) it.next();
88
                InputSource is = res.resolveEntity(publicID, systemID);
85
                InputSource is = res.resolveEntity(publicID, systemID);
89
86
90
                if (is != null) {
87
                if (is != null) {
(-)openide/util/src/org/openide/xml/XMLUtil.java (-4 / +5 lines)
Lines 275-284 Link Here
275
     * Cache of DocumentBuilder instances per thread.
275
     * Cache of DocumentBuilder instances per thread.
276
     * They are relatively expensive to create, so don't do it more than necessary.
276
     * They are relatively expensive to create, so don't do it more than necessary.
277
     */
277
     */
278
    private static final ThreadLocal/*<DocumentBuilder>*/[] builderTL = new ThreadLocal[4];
278
    @SuppressWarnings("unchecked")
279
    private static final ThreadLocal<DocumentBuilder>[] builderTL = new ThreadLocal[4];
279
    static {
280
    static {
280
        for (int i = 0; i < 4; i++) {
281
        for (int i = 0; i < 4; i++) {
281
            builderTL[i] = new ThreadLocal();
282
            builderTL[i] = new ThreadLocal<DocumentBuilder>();
282
        }
283
        }
283
    }
284
    }
284
    /**
285
    /**
Lines 431-437 Link Here
431
        Method setLineWidth = outputFormatClazz.getMethod("setLineWidth", new Class[] {Integer.TYPE}); // NOI18N
432
        Method setLineWidth = outputFormatClazz.getMethod("setLineWidth", new Class[] {Integer.TYPE}); // NOI18N
432
        setLineWidth.invoke(outputFormat, new Object[] {new Integer(0)});
433
        setLineWidth.invoke(outputFormat, new Object[] {new Integer(0)});
433
        Method setLineSeparator = outputFormatClazz.getMethod("setLineSeparator", new Class[] {String.class}); // NOI18N
434
        Method setLineSeparator = outputFormatClazz.getMethod("setLineSeparator", new Class[] {String.class}); // NOI18N
434
        setLineSeparator.invoke(outputFormat, new String[] {System.getProperty("line.separator")}); // NOI18N
435
        setLineSeparator.invoke(outputFormat, System.getProperty("line.separator")); // NOI18N
435
        Method setOutputByteStream = xmlSerializerClazz.getMethod("setOutputByteStream", new Class[] {OutputStream.class}); // NOI18N
436
        Method setOutputByteStream = xmlSerializerClazz.getMethod("setOutputByteStream", new Class[] {OutputStream.class}); // NOI18N
436
        setOutputByteStream.invoke(xmlSerializer, new Object[] {out});
437
        setOutputByteStream.invoke(xmlSerializer, new Object[] {out});
437
        Method setEncoding = outputFormatClazz.getMethod("setEncoding", new Class[] {String.class}); // NOI18N
438
        Method setEncoding = outputFormatClazz.getMethod("setEncoding", new Class[] {String.class}); // NOI18N
Lines 441-447 Link Here
441
        Method setNamespaces = xmlSerializerClazz.getMethod("setNamespaces", new Class[] {Boolean.TYPE}); // NOI18N
442
        Method setNamespaces = xmlSerializerClazz.getMethod("setNamespaces", new Class[] {Boolean.TYPE}); // NOI18N
442
        setNamespaces.invoke(xmlSerializer, new Object[] {Boolean.TRUE});
443
        setNamespaces.invoke(xmlSerializer, new Object[] {Boolean.TRUE});
443
        Method asDOMSerializer = xmlSerializerClazz.getMethod("asDOMSerializer", new Class[0]); // NOI18N
444
        Method asDOMSerializer = xmlSerializerClazz.getMethod("asDOMSerializer", new Class[0]); // NOI18N
444
        Object impl = asDOMSerializer.invoke(xmlSerializer, null);
445
        Object impl = asDOMSerializer.invoke(xmlSerializer);
445
        Method serialize = impl.getClass().getMethod("serialize", new Class[] {Document.class}); // NOI18N
446
        Method serialize = impl.getClass().getMethod("serialize", new Class[] {Document.class}); // NOI18N
446
        serialize.invoke(impl, new Object[] {doc});
447
        serialize.invoke(impl, new Object[] {doc});
447
    }
448
    }
(-)openide/util/test/unit/src/org/openide/util/UtilitiesTopologicalSortTest.java (+18 lines)
Lines 250-256 Link Here
250
        assertEquals(Arrays.asList(new String[] {"d", "e"}), l.subList(5, 7));
250
        assertEquals(Arrays.asList(new String[] {"d", "e"}), l.subList(5, 7));
251
        */
251
        */
252
    }
252
    }
253
    public void testTopologicalSortCompile() throws Exception {
254
        Collection<String> c = new ArrayList<String>();
255
        Map<Object, Collection<String>> edges = new HashMap<Object,Collection<String>>();
256
        
257
        List<String> result = Utilities.topologicalSort(c, edges);
258
    }
253
    
259
    
260
    public void testTopologicalSortCompile2() throws Exception  {
261
        Collection<String> c = new ArrayList<String>();
262
        Map<Object, List<String>> edges = new HashMap<Object,List<String>>();
263
        
264
        List<String> result = Utilities.topologicalSort(c, edges);
265
    }
266
    public void testTopologicalSortCompile3() throws Exception {
267
        Collection<Number> c = new ArrayList<Number>();
268
        Map<Object, List<Integer>> edges = new HashMap<Object,List<Integer>>();
269
        
270
        List<Number> result = Utilities.topologicalSort(c, edges);
271
    }    
254
    public void testErrorReporting () throws Exception {
272
    public void testErrorReporting () throws Exception {
255
        Collection c = Arrays.asList(new String[] {"a", "b", "c", "d", "e", "f"});
273
        Collection c = Arrays.asList(new String[] {"a", "b", "c", "d", "e", "f"});
256
        Map m = new HashMap ();
274
        Map m = new HashMap ();
(-)openide/util/test/unit/src/org/openide/util/WeakListenersTest.java (-5 / +5 lines)
Lines 265-285 Link Here
265
    public void testExceptionIllegalState () {
265
    public void testExceptionIllegalState () {
266
        Listener l = new Listener ();
266
        Listener l = new Listener ();
267
        try {
267
        try {
268
            WeakListeners.create (PropertyChangeListener.class, javax.naming.event.NamingListener.class, l, null);
268
            WeakListeners.create ((Class)PropertyChangeListener.class, (Class)javax.naming.event.NamingListener.class, l, null);
269
            fail ("This shall not be allowed as NamingListener is not superclass of PropertyChangeListener");
269
            fail ("This shall not be allowed as NamingListener is not superclass of PropertyChangeListener");
270
        } catch (IllegalArgumentException ex) {
270
        } catch (IllegalArgumentException ex) {
271
            // ok
271
            // ok
272
        }
272
        }
273
        
273
        
274
        try {
274
        try {
275
            WeakListeners.create (Object.class, l, null);
275
            WeakListeners.create ((Class)Object.class, l, null);
276
            fail ("Not interface, it should fail");
276
            fail ("Not interface, it should fail");
277
        } catch (IllegalArgumentException ex) {
277
        } catch (IllegalArgumentException ex) {
278
            // ok
278
            // ok
279
        }
279
        }
280
        
280
        
281
        try {
281
        try {
282
            WeakListeners.create (Object.class, Object.class, l, null);
282
            WeakListeners.create ((Class)Object.class, (Class)Object.class, l, null);
283
            fail ("Not interface, it should fail");
283
            fail ("Not interface, it should fail");
284
        } catch (IllegalArgumentException ex) {
284
        } catch (IllegalArgumentException ex) {
285
            // ok
285
            // ok
Lines 361-368 Link Here
361
        }
361
        }
362
    }
362
    }
363
    
363
    
364
    private static final class Listener 
364
    private static final class Listener
365
    implements java.beans.PropertyChangeListener, javax.naming.event.ObjectChangeListener {
365
    implements PCL, java.beans.PropertyChangeListener, javax.naming.event.ObjectChangeListener {
366
        public int cnt;
366
        public int cnt;
367
        
367
        
368
        public void propertyChange (java.beans.PropertyChangeEvent ev) {
368
        public void propertyChange (java.beans.PropertyChangeEvent ev) {
(-)openide/util/test/unit/src/org/openide/util/lookup/AbstractLookupMemoryTest.java (-2 / +2 lines)
Lines 83-92 Link Here
83
        c.addPair ((EmptyPair)ignore[1]);
83
        c.addPair ((EmptyPair)ignore[1]);
84
        assertSize ("Is bigger I guess (not counting the pair sizes)", Collections.singleton (l), 56, ignore);
84
        assertSize ("Is bigger I guess (not counting the pair sizes)", Collections.singleton (l), 56, ignore);
85
        
85
        
86
        c.setPairs(Arrays.asList (ignore).subList (0, 3));
86
        c.setPairs((Collection)Arrays.asList (ignore).subList (0, 3));
87
        assertSize ("Even bigger (not counting the pair sizes)", Collections.singleton (l), 64, ignore);
87
        assertSize ("Even bigger (not counting the pair sizes)", Collections.singleton (l), 64, ignore);
88
        
88
        
89
        c.setPairs(Arrays.asList (ignore).subList (0, 4));
89
        c.setPairs((Collection)Arrays.asList (ignore).subList (0, 4));
90
        assertSize ("Now not that much(not counting the pair sizes)", Collections.singleton (l), 64, ignore);
90
        assertSize ("Now not that much(not counting the pair sizes)", Collections.singleton (l), 64, ignore);
91
        
91
        
92
        Lookup.Result res = l.lookup (t);
92
        Lookup.Result res = l.lookup (t);

Return to bug 67888