Index: openide/util/nbproject/project.properties =================================================================== RCS file: /cvs/openide/util/nbproject/project.properties,v retrieving revision 1.9 diff -u -r1.9 project.properties --- openide/util/nbproject/project.properties 18 Jan 2006 05:18:08 -0000 1.9 +++ openide/util/nbproject/project.properties 16 Mar 2006 12:59:02 -0000 @@ -9,6 +9,8 @@ # Code is Sun Microsystems, Inc. Portions Copyright 1997-2005 Sun # Microsystems, Inc. All Rights Reserved. +javac.compilerargs=-Xlint:unchecked +javac.source=1.5 module.jar.dir=lib spec.version.base=6.9.0 Index: openide/util/src/org/openide/ErrorManager.java =================================================================== RCS file: /cvs/openide/util/src/org/openide/ErrorManager.java,v retrieving revision 1.3 diff -u -r1.3 ErrorManager.java --- openide/util/src/org/openide/ErrorManager.java 14 Feb 2006 12:10:19 -0000 1.3 +++ openide/util/src/org/openide/ErrorManager.java 16 Mar 2006 12:59:02 -0000 @@ -502,9 +502,8 @@ /** * A set that has to be updated when the list of delegates * changes. All instances created by getInstance are held here. - * It is a set of DelagatingErrorManager. */ - private WeakSet createdByMe = new WeakSet(); + private WeakSet createdByMe = new WeakSet(); /** If we are the "central" delagate this is not null and * we listen on the result. On newly created delegates this @@ -674,8 +673,10 @@ * Updates the list of delegates. Also updates all instances created * by ourselves. */ + @SuppressWarnings("unchecked") public synchronized void setDelegates(Collection newDelegates) { - java.util.LinkedHashSet d = new java.util.LinkedHashSet(newDelegates); + java.util.LinkedHashSet d; + d = new java.util.LinkedHashSet((Collection)newDelegates); delegates = d; for (Iterator i = createdByMe.iterator(); i.hasNext();) { @@ -695,7 +696,7 @@ * @param DelagatingErrorManager d the instance to which we will attach */ private void attachNewDelegates(DelegatingErrorManager dem, String name) { - Set newDelegatesForDem = new HashSet(); + Set newDelegatesForDem = new HashSet(); for (Iterator j = delegates.iterator(); j.hasNext();) { ErrorManager e = (ErrorManager) j.next(); Index: openide/util/src/org/openide/ServiceType.java =================================================================== RCS file: /cvs/openide/util/src/org/openide/ServiceType.java,v retrieving revision 1.3 diff -u -r1.3 ServiceType.java --- openide/util/src/org/openide/ServiceType.java 29 Apr 2005 14:11:09 -0000 1.3 +++ openide/util/src/org/openide/ServiceType.java 16 Mar 2006 12:59:02 -0000 @@ -197,16 +197,16 @@ /** Get all available services managed by the engine. * @return an enumeration of {@link ServiceType}s */ - public abstract Enumeration services(); + public abstract Enumeration services(); /** Get all available services that are assignable to the given superclass. * @param clazz the class that all services should be subclass of * @return an enumeration of all matching {@link ServiceType}s */ - public Enumeration services(final Class clazz) { - class IsInstance implements org.openide.util.Enumerations.Processor { - public Object process(Object obj, java.util.Collection ignore) { - return clazz.isInstance(obj) ? obj : null; + public Enumeration services(final Class clazz) { + class IsInstance implements org.openide.util.Enumerations.Processor { + public T process(ServiceType obj, java.util.Collection ignore) { + return clazz.isInstance(obj) ? clazz.cast(obj) : null; } } @@ -311,16 +311,15 @@ public ServiceType getServiceType() { if (serviceType == null) { // the class to search for - Class clazz; + Class clazz; // the first subclass of ServiceType to search for - Class serviceTypeClass; + Class serviceTypeClass; // try to find it by class try { - clazz = Class.forName(className, true, (ClassLoader) Lookup.getDefault().lookup(ClassLoader.class)); - - serviceTypeClass = clazz; + serviceTypeClass = Class.forName(className, true, (ClassLoader) Lookup.getDefault().lookup(ClassLoader.class)); + clazz = serviceTypeClass.asSubclass(ServiceType.class); while (serviceTypeClass.getSuperclass() != ServiceType.class) { serviceTypeClass = serviceTypeClass.getSuperclass(); Index: openide/util/src/org/openide/util/Enumerations.java =================================================================== RCS file: /cvs/openide/util/src/org/openide/util/Enumerations.java,v retrieving revision 1.1 diff -u -r1.1 Enumerations.java --- openide/util/src/org/openide/util/Enumerations.java 21 Apr 2005 20:16:09 -0000 1.1 +++ openide/util/src/org/openide/util/Enumerations.java 16 Mar 2006 12:59:02 -0000 @@ -37,8 +37,9 @@ * from empty().nextElement(). * @return the enumeration */ - public static final Enumeration empty() { - return Collections.enumeration(Collections.EMPTY_LIST); + public static final Enumeration empty() { + Collection emptyL = Collections.emptyList(); + return Collections.enumeration(emptyL); } /** @@ -46,7 +47,7 @@ * @param obj the element to be present in the enumeration. * @return enumeration */ - public static Enumeration singleton(Object obj) { + public static Enumeration singleton(T obj) { return Collections.enumeration(Collections.singleton(obj)); } @@ -61,8 +62,11 @@ * @param en2 second enumeration * @return enumeration */ - public static Enumeration concat(Enumeration en1, Enumeration en2) { - return new SeqEn(en1, en2); + public static Enumeration concat(Enumeration en1, Enumeration en2) { + ArrayList> two = new ArrayList>(); + two.add(en1); + two.add(en2); + return new SeqEn(Collections.enumeration(two)); } /** @@ -76,8 +80,8 @@ * @param enumOfEnums Enumeration of Enumeration elements * @return enumeration */ - public static Enumeration concat(Enumeration enumOfEnums) { - return new SeqEn(enumOfEnums); + public static Enumeration concat(Enumeration> enumOfEnums) { + return new SeqEn(enumOfEnums); } /** @@ -89,11 +93,11 @@ * @param en enumeration to filter * @return enumeration without duplicated items */ - public static Enumeration removeDuplicates(Enumeration en) { - class RDupls implements Processor { - private Set set = new HashSet(); + public static Enumeration removeDuplicates(Enumeration en) { + class RDupls implements Processor { + private Set set = new HashSet(); - public Object process(Object o, Collection nothing) { + public T process(T o, Collection nothing) { return set.add(o) ? o : null; } } @@ -106,7 +110,7 @@ * @param arr the array of object * @return enumeration of those objects */ - public static Enumeration array(Object[] arr) { + public static Enumeration array(T... arr) { return Collections.enumeration(Arrays.asList(arr)); } @@ -115,8 +119,8 @@ * @param en enumeration that can contain nulls * @return new enumeration without null values */ - public static Enumeration removeNulls(Enumeration en) { - return filter(en, new RNulls()); + public static Enumeration removeNulls(Enumeration en) { + return filter(en, new RNulls()); } /** @@ -138,8 +142,8 @@ * @param processor a callback processor for the elements (its toAdd arguments is always null) * @return new enumeration where all elements has been processed */ - public static Enumeration convert(Enumeration en, Processor processor) { - return new AltEn(en, processor); + public static Enumeration convert(Enumeration en, Processor processor) { + return new AltEn(en, processor); } /** @@ -166,8 +170,8 @@ * @param filter a callback processor for the elements (its toAdd arguments is always null) * @return new enumeration which does not include non-processed (returned null from processor) elements */ - public static Enumeration filter(Enumeration en, Processor filter) { - return new FilEn(en, filter); + public static Enumeration filter(Enumeration en, Processor filter) { + return new FilEn(en, filter); } /** @@ -199,8 +203,8 @@ * null if the filter returned null from its * {@link Processor#process} method. */ - public static Enumeration queue(Enumeration en, Processor filter) { - QEn q = new QEn(filter); + public static Enumeration queue(Enumeration en, Processor filter) { + QEn q = new QEn(filter); while (en.hasMoreElements()) { q.put(en.nextElement()); @@ -213,26 +217,26 @@ * Processor interface that can filter out objects from the enumeration, * change them or add aditional objects to the end of the current enumeration. */ - public static interface Processor { + public static interface Processor { /** @param original the object that is going to be returned from the enumeration right now * @return a replacement for this object * @param toAdd can be non-null if one can add new objects at the end of the enumeration */ - public Object process(Object original, Collection toAdd); + public R process(T original, Collection toAdd); } /** Altering enumeration implementation */ - private static final class AltEn extends Object implements Enumeration { + private static final class AltEn extends Object implements Enumeration { /** enumeration to filter */ - private Enumeration en; + private Enumeration en; /** map to alter */ - private Processor process; + private Processor process; /** * @param en enumeration to filter */ - public AltEn(Enumeration en, Processor process) { + public AltEn(Enumeration en, Processor process) { this.en = en; this.process = process; } @@ -247,19 +251,19 @@ * @exception NoSuchElementException can be thrown if there is no next object * in the enumeration */ - public Object nextElement() { + public R nextElement() { return process.process(en.nextElement(), null); } } // end of AltEn /** Sequence of enumerations */ - private static final class SeqEn extends Object implements Enumeration { + private static final class SeqEn extends Object implements Enumeration { /** enumeration of Enumerations */ - private Enumeration en; + private Enumeration> en; /** current enumeration */ - private Enumeration current; + private Enumeration current; /** is {@link #current} up-to-date and has more elements? * The combination current == null and @@ -274,25 +278,17 @@ * * @param en enumeration of Enumerations that should be sequenced */ - public SeqEn(Enumeration en) { + public SeqEn(Enumeration> en) { this.en = en; } - /** Composes two enumerations into one. - * @param first first enumeration - * @param second second enumeration - */ - public SeqEn(Enumeration first, Enumeration second) { - this(array(new Enumeration[] { first, second })); - } - /** Ensures that current enumeration is set. If there aren't more * elements in the Enumerations, sets the field current to null. */ private void ensureCurrent() { while ((current == null) || !current.hasMoreElements()) { if (en.hasMoreElements()) { - current = (Enumeration) en.nextElement(); + current = en.nextElement(); } else { // no next valid enumeration current = null; @@ -315,7 +311,7 @@ /** @return next element * @exception NoSuchElementException if there is no next element */ - public Object nextElement() { + public T nextElement() { if (!checked) { ensureCurrent(); } @@ -334,39 +330,39 @@ /** QueueEnumeration */ - private static class QEn extends Object implements Enumeration { + private static class QEn extends Object implements Enumeration { /** next object to be returned */ - private ListItem next = null; + private ListItem next = null; /** last object in the queue */ - private ListItem last = null; + private ListItem last = null; /** processor to use */ - private Processor processor; + private Processor processor; - public QEn(Processor p) { + public QEn(Processor p) { this.processor = p; } /** Put adds new object to the end of queue. * @param o the object to add */ - public void put(Object o) { + public void put(T o) { if (last != null) { - ListItem li = new ListItem(o); + ListItem li = new ListItem(o); last.next = li; last = li; } else { - next = last = new ListItem(o); + next = last = new ListItem(o); } } /** Adds array of objects into the queue. * @param arr array of objects to put into the queue */ - public void put(Object[] arr) { - for (int i = 0; i < arr.length; i++) { - put(arr[i]); + public void put(Collection arr) { + for (T e : arr) { + put(e); } } @@ -380,12 +376,12 @@ /** @return next object in enumeration * @exception NoSuchElementException if there is no next object */ - public Object nextElement() { + public R nextElement() { if (next == null) { throw new NoSuchElementException(); } - Object res = next.object; + T res = next.object; if ((next = next.next) == null) { last = null; @@ -393,29 +389,29 @@ ; - ToAdd toAdd = new ToAdd(this); - res = processor.process(res, toAdd); + ToAdd toAdd = new ToAdd(this); + R out = processor.process(res, toAdd); toAdd.finish(); - return res; + return out; } /** item in linked list of Objects */ - private static final class ListItem { - Object object; - ListItem next; + private static final class ListItem { + T object; + ListItem next; /** @param o the object for this item */ - ListItem(Object o) { + ListItem(T o) { object = o; } } /** Temporary collection that supports only add and addAll operations*/ - private static final class ToAdd extends Object implements Collection { - private QEn q; + private static final class ToAdd extends Object implements Collection { + private QEn q; - public ToAdd(QEn q) { + public ToAdd(QEn q) { this.q = q; } @@ -423,14 +419,14 @@ this.q = null; } - public boolean add(Object o) { + public boolean add(T o) { q.put(o); return true; } - public boolean addAll(Collection c) { - q.put(c.toArray()); + public boolean addAll(Collection c) { + q.put(c); return true; } @@ -455,7 +451,7 @@ throw new UnsupportedOperationException(msg()); } - public Iterator iterator() { + public Iterator iterator() { throw new UnsupportedOperationException(msg()); } @@ -479,7 +475,7 @@ throw new UnsupportedOperationException(msg()); } - public Object[] toArray(Object[] a) { + public X[] toArray(X[] a) { throw new UnsupportedOperationException(msg()); } } @@ -488,24 +484,24 @@ // end of QEn /** Filtering enumeration */ - private static final class FilEn extends Object implements Enumeration { + private static final class FilEn extends Object implements Enumeration { /** marker object stating there is no nexte element prepared */ private static final Object EMPTY = new Object(); /** enumeration to filter */ - private Enumeration en; + private Enumeration en; /** element to be returned next time or {@link #EMPTY} if there is * no such element prepared */ - private Object next = EMPTY; + private R next = empty(); /** the set to use as filter */ - private Processor filter; + private Processor filter; /** * @param en enumeration to filter */ - public FilEn(Enumeration en, Processor filter) { + public FilEn(Enumeration en, Processor filter) { this.en = en; this.filter = filter; } @@ -513,7 +509,7 @@ /** @return true if there is more elements in the enumeration */ public boolean hasMoreElements() { - if (next != EMPTY) { + if (next != empty()) { // there is a object already prepared return true; } @@ -530,7 +526,7 @@ ; } - next = EMPTY; + next = empty(); return false; } @@ -539,22 +535,27 @@ * @exception NoSuchElementException can be thrown if there is no next object * in the enumeration */ - public Object nextElement() { + public R nextElement() { if ((next == EMPTY) && !hasMoreElements()) { throw new NoSuchElementException(); } - Object res = next; - next = EMPTY; + R res = next; + next = empty(); return res; } + + @SuppressWarnings("unchecked") + private R empty() { + return (R)EMPTY; + } } // end of FilEn /** Returns true from contains if object is not null */ - private static class RNulls implements Processor { - public Object process(Object original, Collection toAdd) { + private static class RNulls implements Processor { + public T process(T original, Collection toAdd) { return original; } } Index: openide/util/src/org/openide/util/IconManager.java =================================================================== RCS file: /cvs/openide/util/src/org/openide/util/IconManager.java,v retrieving revision 1.2 diff -u -r1.2 IconManager.java --- openide/util/src/org/openide/util/IconManager.java 4 Nov 2005 10:54:11 -0000 1.2 +++ openide/util/src/org/openide/util/IconManager.java 16 Mar 2006 12:59:02 -0000 @@ -35,13 +35,13 @@ private static final Object NO_ICON = new Object(); /** map of resource name to loaded icon (String, SoftRefrence (Image)) or (String, NO_ICON) */ - private static final HashMap map = new HashMap(128); - private static final HashMap localizedMap = new HashMap(128); + private static final HashMap map = new HashMap(128); + private static final HashMap localizedMap = new HashMap(128); /** Resource paths for which we have had to strip initial slash. * @see "#20072" */ - private static final Set extraInitialSlashes = new HashSet(); // Set + private static final Set extraInitialSlashes = new HashSet(); // Set private static volatile Object currentLoader; private static Lookup.Result loaderQuery = null; private static boolean noLoaderWarned = false; @@ -424,11 +424,11 @@ } /** Cleaning reference. */ - private static final class ActiveRef extends SoftReference implements Runnable { + private static final class ActiveRef extends SoftReference implements Runnable { private Map holder; private Object key; - public ActiveRef(Object o, Map holder, Object key) { + public ActiveRef(Image o, Map holder, Object key) { super(o, Utilities.activeReferenceQueue()); this.holder = holder; this.key = key; Index: openide/util/src/org/openide/util/Mutex.java =================================================================== RCS file: /cvs/openide/util/src/org/openide/util/Mutex.java,v retrieving revision 1.6 diff -u -r1.6 Mutex.java --- openide/util/src/org/openide/util/Mutex.java 2 Mar 2006 20:54:08 -0000 1.6 +++ openide/util/src/org/openide/util/Mutex.java 16 Mar 2006 12:59:02 -0000 @@ -138,7 +138,7 @@ private /*final*/ Object LOCK; /** threads that - owns or waits for this mutex */ - private /*final*/ Map registeredThreads; + private /*final*/ Map registeredThreads; /** number of threads that holds S mode (readersNo == "count of threads in registeredThreads that holds S") */ @@ -146,7 +146,7 @@ private int readersNo = 0; /** a queue of waiting threads for this mutex */ - private List waiters; + private List waiters; /** Enhanced constructor that permits specifying an object to use as a lock. * The lock is used on entry and exit to {@link #readAccess} and during the @@ -190,8 +190,8 @@ /** Initiates this Mutex */ private void init(Object lock) { this.LOCK = lock; - this.registeredThreads = new HashMap(7); - this.waiters = new LinkedList(); + this.registeredThreads = new HashMap(7); + this.waiters = new LinkedList(); } /** Run an action only with read access. @@ -1307,7 +1307,7 @@ /** queue of runnable rquests that are to be executed (in X mode) right after S mode is left * deadlock avoidance technique */ - List[] queues; + List[] queues; /** value of counts[S] when the mode was upgraded * rsnapshot works as follows: @@ -1323,11 +1323,12 @@ */ int rsnapshot; + @SuppressWarnings("unchecked") public ThreadInfo(Thread t, int mode) { this.t = t; this.mode = mode; this.counts = new int[MODE_COUNT]; - this.queues = new List[MODE_COUNT]; + this.queues = (List[])new List[MODE_COUNT]; counts[mode] = 1; } @@ -1338,7 +1339,7 @@ /** Adds the Runnable into the queue of waiting requests */ public void enqueue(int mode, Runnable run) { if (queues[mode] == null) { - queues[mode] = new ArrayList(13); + queues[mode] = new ArrayList(13); } queues[mode].add(run); Index: openide/util/src/org/openide/util/NbBundle.java =================================================================== RCS file: /cvs/openide/util/src/org/openide/util/NbBundle.java,v retrieving revision 1.6 diff -u -r1.6 NbBundle.java --- openide/util/src/org/openide/util/NbBundle.java 1 Dec 2005 12:05:09 -0000 1.6 +++ openide/util/src/org/openide/util/NbBundle.java 16 Mar 2006 12:59:02 -0000 @@ -62,12 +62,12 @@ * Keeps only weak references to the class loaders. * @see "#9275" */ - private static final Map localizedFileCache = new WeakHashMap(); // Map> + private static final Map> localizedFileCache = new WeakHashMap>(); /** * Cache of resource bundles. */ - private static final Map bundleCache = new WeakHashMap(); // Map>> + private static final Map>> bundleCache = new WeakHashMap>>(); /** * Do not call. @@ -154,14 +154,14 @@ // [PENDING] in the future, could maybe do something neat if // USE_DEBUG_LOADER and ext is "html" or "txt" etc... URL lookup = null; - Iterator it = new LocaleIterator(locale); + Iterator it = new LocaleIterator(locale); String cachePrefix = "[" + Integer.toString(loader.hashCode()) + "]"; // NOI18N - List cacheCandidates = new ArrayList(10); // List + List cacheCandidates = new ArrayList(10); String baseNameSlashes = baseName.replace('.', '/'); - Map perLoaderCache = (Map) localizedFileCache.get(loader); + Map perLoaderCache = localizedFileCache.get(loader); if (perLoaderCache == null) { - localizedFileCache.put(loader, perLoaderCache = new HashMap()); + localizedFileCache.put(loader, perLoaderCache = new HashMap()); } // #31008: better use of domain cache priming. @@ -441,13 +441,13 @@ * @return a resource bundle (locale- and branding-merged), or null if not found */ private static ResourceBundle getBundleFast(String name, Locale locale, ClassLoader loader) { - Map m; + Map> m; synchronized (bundleCache) { - m = (Map) bundleCache.get(loader); // Map> + m = bundleCache.get(loader); if (m == null) { - bundleCache.put(loader, m = new HashMap()); + bundleCache.put(loader, m = new HashMap>()); } } @@ -480,8 +480,8 @@ String key = name + '/' + (brandingToken != null ? brandingToken : "-") + '/' + locale; // NOI18N */ synchronized (m) { - Object o = m.get(key); - ResourceBundle b = (o != null) ? (ResourceBundle) ((Reference) o).get() : null; + Reference o = m.get(key); + ResourceBundle b = o != null ? o.get() : null; if (b != null) { return b; @@ -489,7 +489,7 @@ b = loadBundle(name, locale, loader); if (b != null) { - m.put(key, new TimedSoftReference(b, m, key)); + m.put(key, new TimedSoftReference(b, m, key)); } else { // Used to cache misses as well, to make the negative test faster. // However this caused problems: see #31578. @@ -509,8 +509,8 @@ */ private static ResourceBundle loadBundle(String name, Locale locale, ClassLoader loader) { String sname = name.replace('.', '/'); - Iterator it = new LocaleIterator(locale); - LinkedList l = new LinkedList(); + Iterator it = new LocaleIterator(locale); + LinkedList l = new LinkedList(); while (it.hasNext()) { l.addFirst(it.next()); @@ -555,7 +555,15 @@ first = false; } - return new PBundle(p, locale); + return new PBundle(propsToStringMap(p), locale); + } + + /** Just converts the Properties to Map assuming the + * content is correct. + */ + @SuppressWarnings("unchecked") + private static Map propsToStringMap(Properties p) { + return (Map)p; } /** @@ -769,7 +777,7 @@ * A resource bundle based on .properties files (or any map). */ private static final class PBundle extends ResourceBundle { - private final Map m; // Map + private final Map m; private final Locale locale; /** @@ -777,12 +785,12 @@ * @param m a map from resources keys to values (typically both strings) * @param locale the locale it represents (informational) */ - public PBundle(Map m, Locale locale) { + public PBundle(Map m, Locale locale) { this.m = m; this.locale = locale; } - public Enumeration getKeys() { + public Enumeration getKeys() { return Collections.enumeration(m.keySet()); } @@ -819,7 +827,7 @@ return loc; } - public Enumeration getKeys() { + public Enumeration getKeys() { return Enumerations.removeDuplicates(Enumerations.concat(sub1.getKeys(), sub2.getKeys())); } @@ -853,7 +861,7 @@ * Branding tokens with underscores are broken apart naturally: so e.g. * branding "f4j_ce" looks first for "f4j_ce" branding, then "f4j" branding, then none. */ - private static class LocaleIterator extends Object implements Iterator { + private static class LocaleIterator extends Object implements Iterator { /** this flag means, if default locale is in progress */ private boolean defaultInProgress = false; @@ -896,7 +904,7 @@ /** @return next sufix. * @exception NoSuchElementException if there is no more locale sufix. */ - public Object next() throws NoSuchElementException { + public String next() throws NoSuchElementException { if (current == null) { throw new NoSuchElementException(); } @@ -981,10 +989,10 @@ /** indices of known bundles; needed since DebugLoader's can be collected * when softly reachable, but this should be transparent to the user */ - private static final Map knownIDs = new HashMap(); // Map + private static final Map knownIDs = new HashMap(); /** cache of existing debug loaders for regular loaders */ - private static final Map existing = new WeakHashMap(); // Map> + private static final Map> existing = new WeakHashMap>(); private DebugLoader(ClassLoader cl) { super(cl); @@ -1025,7 +1033,7 @@ } ClassLoader dl = new DebugLoader(normal); - existing.put(normal, new WeakReference(dl)); + existing.put(normal, new WeakReference(dl)); return dl; } Index: openide/util/src/org/openide/util/Queue.java =================================================================== RCS file: /cvs/openide/util/src/org/openide/util/Queue.java,v retrieving revision 1.1 diff -u -r1.1 Queue.java --- openide/util/src/org/openide/util/Queue.java 21 Apr 2005 20:16:11 -0000 1.1 +++ openide/util/src/org/openide/util/Queue.java 16 Mar 2006 12:59:02 -0000 @@ -21,7 +21,7 @@ */ public class Queue extends Object { /** Queue enumeration */ - private java.util.LinkedList queue = new java.util.LinkedList(); + private java.util.LinkedList queue = new java.util.LinkedList(); /** Adds new item. * @param o object to add Index: openide/util/src/org/openide/util/RE13.java =================================================================== RCS file: /cvs/openide/util/src/org/openide/util/RE13.java,v retrieving revision 1.1 diff -u -r1.1 RE13.java --- openide/util/src/org/openide/util/RE13.java 21 Apr 2005 20:16:12 -0000 1.1 +++ openide/util/src/org/openide/util/RE13.java 16 Mar 2006 12:59:02 -0000 @@ -116,7 +116,7 @@ /** Data structure to needed to store the */ public void init(String[] original, String[] newversion) { - ArrayList root = new ArrayList(); + ArrayList root = new ArrayList(); for (int i = 0; i < original.length; i++) { placeString(root, original[i], i); @@ -131,7 +131,7 @@ * @param s string to place there * @param indx index to put at the end node */ - private static void placeString(List item, String s, int indx) { + private static void placeString(List item, String s, int indx) { if (s.length() == 0) { item.add(new Integer(indx)); @@ -140,7 +140,7 @@ char f = s.charAt(0); - ListIterator it = item.listIterator(); + ListIterator it = item.listIterator(); while (it.hasNext()) { Object o = it.next(); @@ -159,7 +159,7 @@ // next is the list or null List listForPref = (List) it.next(); - ArrayList switchList = new ArrayList(); + ArrayList switchList = new ArrayList(); it.set(switchList); switchList.add(pref.substring(i)); @@ -168,7 +168,7 @@ if (i >= s.length()) { switchList.add(new Integer(indx)); } else { - ArrayList terminalList = new ArrayList(); + ArrayList terminalList = new ArrayList(); terminalList.add(new Integer(indx)); switchList.add(s.substring(i)); @@ -182,7 +182,7 @@ // // the new string is longer than the existing recursive add // - List switchList = (List) it.next(); + List switchList = nextList(it); placeString(switchList, s.substring(pref.length()), indx); return; @@ -193,11 +193,17 @@ // // ok new prefix in this item // - ArrayList id = new ArrayList(); + ArrayList id = new ArrayList(); id.add(new Integer(indx)); item.add(s); item.add(id); + } + + @SuppressWarnings("unchecked") + private static List nextList(final ListIterator it) { + List switchList = (List) it.next(); + return switchList; } /** Compress tree of Lists into tree of Objects. Index: openide/util/src/org/openide/util/RequestProcessor.java =================================================================== RCS file: /cvs/openide/util/src/org/openide/util/RequestProcessor.java,v retrieving revision 1.12 diff -u -r1.12 RequestProcessor.java --- openide/util/src/org/openide/util/RequestProcessor.java 12 Jan 2006 08:50:46 -0000 1.12 +++ openide/util/src/org/openide/util/RequestProcessor.java 16 Mar 2006 12:59:02 -0000 @@ -119,12 +119,12 @@ private Object processorLock = new Object(); /** The set holding all the Processors assigned to this RequestProcessor */ - private HashSet processors = new HashSet(); + private HashSet processors = new HashSet(); /** Actualy the first item is pending to be processed. * Can be accessed/trusted only under the above processorLock lock. * If null, nothing is scheduled and the processor is not running. */ - private List queue = new LinkedList(); + private List queue = new LinkedList(); /** Number of currently running processors. If there is a new request * and this number is lower that the throughput, new Processor is asked @@ -442,7 +442,7 @@ queue.add(item); item.enqueued = true; } else { - for (ListIterator it = queue.listIterator(); it.hasNext();) { + for (ListIterator it = queue.listIterator(); it.hasNext();) { Item next = (Item) it.next(); if (iprio > next.getPriority()) { @@ -805,7 +805,7 @@ */ private static class Processor extends Thread { /** A stack containing all the inactive Processors */ - private static Stack pool = new Stack(); + private static Stack pool = new Stack(); /* One minute of inactivity and the Thread will die if not assigned */ private static final int INACTIVE_TIMEOUT = 60000; @@ -1033,8 +1033,8 @@ * end of the task. */ static ThreadGroup getTopLevelThreadGroup() { - java.security.PrivilegedAction run = new java.security.PrivilegedAction() { - public Object run() { + java.security.PrivilegedAction run = new java.security.PrivilegedAction() { + public ThreadGroup run() { ThreadGroup current = Thread.currentThread().getThreadGroup(); while (current.getParent() != null) { @@ -1045,7 +1045,7 @@ } }; - return (ThreadGroup) java.security.AccessController.doPrivileged(run); + return java.security.AccessController.doPrivileged(run); } } } Index: openide/util/src/org/openide/util/SharedClassObject.java =================================================================== RCS file: /cvs/openide/util/src/org/openide/util/SharedClassObject.java,v retrieving revision 1.4 diff -u -r1.4 SharedClassObject.java --- openide/util/src/org/openide/util/SharedClassObject.java 18 Jan 2006 05:23:05 -0000 1.4 +++ openide/util/src/org/openide/util/SharedClassObject.java 16 Mar 2006 12:59:02 -0000 @@ -50,7 +50,7 @@ private static final Object PROP_SUPPORT = new Object(); /** Map (Class, DataEntry) that maps Classes to maps of any objects */ - private static final Map values = new WeakHashMap(4); + private static final Map values = new WeakHashMap(37); /** A set of all classes for which we are currently inside createInstancePrivileged. * If a SCO constructor is called when an instance of that class already exists, normally @@ -60,12 +60,12 @@ * second instance (because it is nobody's fault and it will be handled OK). * Map from class name to nesting count. */ - private static final Map instancesBeingCreated = new HashMap(3); // Map + private static final Map instancesBeingCreated = new HashMap(7); /** Set of classes to not warn about any more. * Names only. */ - private static final Set alreadyWarnedAboutDupes = new HashSet(); // Set + private static final Set alreadyWarnedAboutDupes = new HashSet(); // private static final ErrorManager err = ErrorManager.getDefault().getInstance("org.openide.util.SharedClassObject"); // NOI18N /** data entry for this class */ @@ -456,7 +456,7 @@ * @param clazz the shared class to look for * @return the instance, or null if such does not exists */ - public static SharedClassObject findObject(Class clazz) { + public static T findObject(Class clazz) { return findObject(clazz, false); } @@ -469,7 +469,7 @@ * @return an instance, or null if there was none and create was false * @exception IllegalArgumentException if a new instance could not be created for some reason */ - public static SharedClassObject findObject(Class clazz, boolean create) { + public static T findObject(Class clazz, boolean create) { // synchronizing on the same object as returned from getLock() synchronized (clazz.getName().intern()) { DataEntry de = (DataEntry) values.get(clazz); @@ -480,10 +480,10 @@ if ((obj == null) && create) { // try to create new instance - PrivilegedExceptionAction action = new SetAccessibleAction(clazz); + SetAccessibleAction action = new SetAccessibleAction(clazz); try { - obj = (SharedClassObject) AccessController.doPrivileged(action); + obj = AccessController.doPrivileged(action); } catch (PrivilegedActionException e) { Exception ex = e.getException(); IllegalArgumentException newEx = new IllegalArgumentException(ex.toString()); @@ -509,7 +509,7 @@ throw new IllegalStateException("Inconsistent state: " + clazz); // NOI18N } - return obj2; + return clazz.cast(obj2); } } @@ -570,7 +570,7 @@ throw new IllegalStateException("Inconsistent state: " + clazz); // NOI18N } - return obj; + return clazz.cast(obj); } } @@ -595,9 +595,9 @@ err.notify(ErrorManager.INFORMATIONAL, t); } - static Object createInstancePrivileged(Class clazz) + static SharedClassObject createInstancePrivileged(Class clazz) throws Exception { - java.lang.reflect.Constructor c = clazz.getDeclaredConstructor(new Class[0]); + java.lang.reflect.Constructor c = clazz.getDeclaredConstructor(new Class[0]); c.setAccessible(true); String name = clazz.getName(); @@ -646,7 +646,7 @@ static final long serialVersionUID = 1327893248974327640L; /** the class */ - private Class clazz; + private Class clazz; /** class name, in case clazz could not be reloaded */ private String name; @@ -714,7 +714,7 @@ // make readResolve accessible (it can have any access modifier) resolveMethod.setAccessible(true); - return resolveMethod.invoke(object, null); + return resolveMethod.invoke(object); } catch (Exception ex) { // checked or runtime does not matter - we must survive String banner = "Skipping " + object.getClass() + " resolution:"; //NOI18N @@ -777,13 +777,13 @@ */ static final class DataEntry extends Object { /** The data */ - private HashMap map; + private HashMap map; /** The reference counter */ private int count = 0; /** weak reference to an object of this class */ - private WeakReference ref = new WeakReference(null); + private WeakReference ref = new WeakReference(null); /** inited? */ private boolean initialized = false; @@ -807,12 +807,12 @@ * @param obj the requestor object * @return the data */ - Map getMap(SharedClassObject obj) { + Map getMap(SharedClassObject obj) { ensureValid(obj); if (map == null) { // to signal invalid state - map = new HashMap(); + map = new HashMap(); } if (!initialized) { @@ -836,7 +836,7 @@ if (map == null) { // to signal invalid state - map = new HashMap(); + map = new HashMap(); ret = null; } else { ret = map.get(key); @@ -865,7 +865,7 @@ if (map == null) { // to signal invalid state - map = new HashMap(); + map = new HashMap(); } return map; @@ -932,7 +932,7 @@ SharedClassObject s = (SharedClassObject) ref.get(); if (s == null) { - ref = new WeakReference(obj); + ref = new WeakReference(obj); return obj; } else { @@ -962,14 +962,14 @@ } } - static final class SetAccessibleAction implements PrivilegedExceptionAction { - Class klass; + static final class SetAccessibleAction implements PrivilegedExceptionAction { + Class klass; - SetAccessibleAction(Class klass) { + SetAccessibleAction(Class klass) { this.klass = klass; } - public Object run() throws Exception { + public SharedClassObject run() throws Exception { return createInstancePrivileged(klass); } } Index: openide/util/src/org/openide/util/Task.java =================================================================== RCS file: /cvs/openide/util/src/org/openide/util/Task.java,v retrieving revision 1.2 diff -u -r1.2 Task.java --- openide/util/src/org/openide/util/Task.java 4 Oct 2005 09:18:56 -0000 1.2 +++ openide/util/src/org/openide/util/Task.java 16 Mar 2006 12:59:02 -0000 @@ -44,9 +44,8 @@ } /** map of subclasses to booleans whether they override waitFinished() or not - * */ - private static java.util.WeakHashMap overrides; + private static java.util.WeakHashMap overrides; /** request processor for workarounding compatibility problem with * classes that do not override waitFinished (long) @@ -60,7 +59,7 @@ private boolean finished; /** listeners for the finish of task (TaskListener) */ - private HashSet list; + private HashSet list; /** Create a new task. * The runnable should provide its own error-handling, as @@ -225,7 +224,7 @@ */ public synchronized void addTaskListener(TaskListener l) { if (list == null) { - list = new HashSet(); + list = new HashSet(); } list.add(l); @@ -263,18 +262,18 @@ return true; } - java.util.WeakHashMap m; + java.util.WeakHashMap m; Boolean does; synchronized (Task.class) { if (overrides == null) { - overrides = new java.util.WeakHashMap(); + overrides = new java.util.WeakHashMap(); RP = new RequestProcessor("Timeout waitFinished compatibility processor", 255); // NOI18N } m = overrides; - does = (Boolean) m.get(getClass()); + does = m.get(getClass()); if (does != null) { return does.booleanValue(); Index: openide/util/src/org/openide/util/TimedSoftReference.java =================================================================== RCS file: /cvs/openide/util/src/org/openide/util/TimedSoftReference.java,v retrieving revision 1.1 diff -u -r1.1 TimedSoftReference.java --- openide/util/src/org/openide/util/TimedSoftReference.java 21 Apr 2005 20:16:13 -0000 1.1 +++ openide/util/src/org/openide/util/TimedSoftReference.java 16 Mar 2006 12:59:02 -0000 @@ -37,11 +37,11 @@ * * @author Jesse Glick */ -final class TimedSoftReference extends SoftReference implements Runnable { +final class TimedSoftReference extends SoftReference implements Runnable { private static final int TIMEOUT = 30000; private static final RequestProcessor RP = new RequestProcessor("TimedSoftReference"); // NOI18N private RequestProcessor.Task task; - private Object o; + private T o; private final Map m; private final Object k; @@ -56,7 +56,7 @@ * @param m a map in which this reference may serve as a value * @param k the key whose value in m may be this reference */ - public TimedSoftReference(Object o, Map m, Object k) { + public TimedSoftReference(T o, Map m, Object k) { super(o, Utilities.activeReferenceQueue()); this.o = o; this.m = m; @@ -86,7 +86,7 @@ } } - public Object get() { + public T get() { synchronized (m) { if (o == null) { o = super.get(); Index: openide/util/src/org/openide/util/TopologicalSortException.java =================================================================== RCS file: /cvs/openide/util/src/org/openide/util/TopologicalSortException.java,v retrieving revision 1.1 diff -u -r1.1 TopologicalSortException.java --- openide/util/src/org/openide/util/TopologicalSortException.java 21 Apr 2005 20:16:13 -0000 1.1 +++ openide/util/src/org/openide/util/TopologicalSortException.java 16 Mar 2006 12:59:02 -0000 @@ -37,7 +37,7 @@ private int counter; /** vertexes sorted by increasing value of y */ - private Stack dualGraph = new Stack(); + private Stack dualGraph = new Stack(); TopologicalSortException(Collection vertexes, Map edges) { this.vertexes = vertexes; @@ -52,10 +52,12 @@ public final List partialSort() { Set[] all = topologicalSets(); - ArrayList res = new ArrayList(vertexes.size()); + ArrayList res = new ArrayList(vertexes.size()); for (int i = 0; i < all.length; i++) { - res.addAll(all[i]); + for (Object e : all[i]) { + res.add(e); + } } return res; @@ -75,7 +77,7 @@ public final Set[] unsortableSets() { Set[] all = topologicalSets(); - ArrayList unsort = new ArrayList(); + ArrayList unsort = new ArrayList(); for (int i = 0; i < all.length; i++) { if ((all[i].size() > 1) || !(all[i] instanceof HashSet)) { @@ -83,7 +85,7 @@ } } - return (Set[]) unsort.toArray(new Set[0]); + return unsort.toArray(new Set[0]); } /** Adds description why the graph cannot be sorted. @@ -137,7 +139,7 @@ return result; } - HashMap vertexInfo = new HashMap(); + HashMap vertexInfo = new HashMap(); // computes value X and Y for each vertex counter = 0; @@ -151,15 +153,15 @@ // now connect vertexes that cannot be sorted into own // sets // map from the original objects to - Map objectsToSets = new HashMap(); + Map objectsToSets = new HashMap(); - ArrayList sets = new ArrayList(); + ArrayList sets = new ArrayList(); while (!dualGraph.isEmpty()) { Vertex v = (Vertex) dualGraph.pop(); if (!v.visited) { - Set set = new HashSet(); + Set set = new HashSet(); visitDualGraph(v, set); if ((set.size() == 1) && v.edgesFrom.contains(v)) { @@ -185,7 +187,7 @@ // now topologically sort the sets // 1. prepare the map - HashMap edgesBetweenSets = new HashMap(); + HashMap> edgesBetweenSets = new HashMap>(); it = edges.entrySet().iterator(); while (it.hasNext()) { @@ -196,19 +198,19 @@ continue; } - Set from = (Set) objectsToSets.get(entry.getKey()); + Set from = objectsToSets.get(entry.getKey()); - Collection setsTo = (Collection) edgesBetweenSets.get(from); + Collection setsTo = edgesBetweenSets.get(from); if (setsTo == null) { - setsTo = new ArrayList(); + setsTo = new ArrayList(); edgesBetweenSets.put(from, setsTo); } Iterator convert = leadsTo.iterator(); while (convert.hasNext()) { - Set to = (Set) objectsToSets.get(convert.next()); + Set to = objectsToSets.get(convert.next()); if (from != to) { // avoid self cycles @@ -219,7 +221,8 @@ // 2. do the sort try { - result = (Set[]) Utilities.topologicalSort(sets, edgesBetweenSets).toArray(new Set[0]); + List listResult = Utilities.topologicalSort(sets, edgesBetweenSets); + result = listResult.toArray(new Set[0]); } catch (TopologicalSortException ex) { throw new IllegalStateException("Cannot happen"); // NOI18N } @@ -232,7 +235,7 @@ * @param vertex current vertex * @param vertexInfo the info */ - private Vertex constructDualGraph(int counter, Object vertex, HashMap vertexInfo) { + private Vertex constructDualGraph(int counter, Object vertex, HashMap vertexInfo) { Vertex info = (Vertex) vertexInfo.get(vertex); if (info == null) { @@ -269,7 +272,7 @@ * @param vertex vertex to start from * @param visited list of all objects that we've been to */ - private void visitDualGraph(Vertex vertex, Collection visited) { + private void visitDualGraph(Vertex vertex, Collection visited) { if (vertex.visited) { return; } @@ -289,12 +292,12 @@ * comparable by the value of Y, but only after the value is set, * so the sort has to be done latelly. */ - private static final class Vertex implements Comparable { + private static final class Vertex implements Comparable { /** the found object */ public Object object; /** list of vertexes that point to this one */ - public List edgesFrom = new ArrayList(); + public List edgesFrom = new ArrayList(); /** the counter state when we entered the vertex */ public final int x; @@ -331,10 +334,8 @@ * @return a negative integer, zero, or a positive integer as this object * is less than, equal to, or greater than the specified object. */ - public int compareTo(Object o) { - Vertex v = (Vertex) o; - - return v.y - y; + public int compareTo(Vertex o) { + return o.y - y; } } } Index: openide/util/src/org/openide/util/Utilities.java =================================================================== RCS file: /cvs/openide/util/src/org/openide/util/Utilities.java,v retrieving revision 1.10 diff -u -r1.10 Utilities.java --- openide/util/src/org/openide/util/Utilities.java 28 Feb 2006 18:11:25 -0000 1.10 +++ openide/util/src/org/openide/util/Utilities.java 16 Mar 2006 12:59:03 -0000 @@ -154,11 +154,11 @@ private static final int TYPICAL_MACOSX_MENU_HEIGHT = 24; /** variable holding the activeReferenceQueue */ - private static ReferenceQueue activeReferenceQueue; + private static ReferenceQueue activeReferenceQueue; /** reference to map that maps allowed key names to their values (String, Integer) and reference to map for mapping of values to their names */ - private static Reference namesAndValues; + private static Reference namesAndValues; /** The operating system on which NetBeans runs*/ private static int operatingSystem = -1; @@ -242,7 +242,7 @@ * * @since 3.11 */ - public static synchronized ReferenceQueue activeReferenceQueue() { + public static synchronized ReferenceQueue activeReferenceQueue() { if (activeReferenceQueue == null) { activeReferenceQueue = new ActiveQueue(false); } @@ -492,7 +492,7 @@ return workingSet; } - java.util.ArrayList lines = new java.util.ArrayList(); + java.util.ArrayList lines = new java.util.ArrayList(); int lineStart = 0; // the position of start of currently processed line in the original string @@ -616,7 +616,7 @@ return original; } - java.util.Vector lines = new java.util.Vector(); + java.util.Vector lines = new java.util.Vector(); int lineStart = 0; // the position of start of currently processed line in the original string int lastSpacePos = -1; @@ -1323,7 +1323,7 @@ int INPARAMPENDING = 0x2; // INPARAM + \ int STICK = 0x4; // INPARAM + " or STICK + non_" // NOI18N int STICKPENDING = 0x8; // STICK + \ - Vector params = new Vector(5, 5); + Vector params = new Vector(5, 5); char c; int state = NULL; @@ -1532,8 +1532,8 @@ Field[] fields = KeyEvent.class.getDeclaredFields(); - HashMap names = new HashMap(((fields.length * 4) / 3) + 5, 0.75f); - HashMap values = new HashMap(((fields.length * 4) / 3) + 5, 0.75f); + HashMap names = new HashMap(((fields.length * 4) / 3) + 5, 0.75f); + HashMap values = new HashMap(((fields.length * 4) / 3) + 5, 0.75f); for (int i = 0; i < fields.length; i++) { if (Modifier.isStatic(fields[i].getModifiers())) { @@ -1569,7 +1569,7 @@ HashMap[] arr = { names, values }; - namesAndValues = new SoftReference(arr); + namesAndValues = new SoftReference(arr); return arr; } @@ -1741,7 +1741,7 @@ */ public static KeyStroke[] stringToKeys(String s) { StringTokenizer st = new StringTokenizer(s.toUpperCase(Locale.ENGLISH), " "); // NOI18N - ArrayList arr = new ArrayList(); + ArrayList arr = new ArrayList(); while (st.hasMoreElements()) { s = st.nextToken(); @@ -1755,7 +1755,7 @@ arr.add(k); } - return (KeyStroke[]) arr.toArray(new KeyStroke[arr.size()]); + return arr.toArray(new KeyStroke[arr.size()]); } /** Adds characters for modifiers to the buffer. @@ -2079,6 +2079,7 @@ * @throws UnorderableException if the specified partial order is inconsistent on this list * @deprecated Deprecated in favor of the potentially much faster (and possibly more correct) {@link #topologicalSort}. */ + @SuppressWarnings("unchecked") // do not bother, it is deprecated anyway public static List partialSort(List l, Comparator c, boolean stable) throws UnorderableException { // map from objects in the list to null or sets of objects they are greater than @@ -2200,17 +2201,17 @@ * @since 3.30 * @see Issue #27286 */ - public static List topologicalSort(Collection c, Map edges) + public static List topologicalSort(Collection c, Map> edges) throws TopologicalSortException { - Map finished = new HashMap(); - List r = new ArrayList(Math.max(c.size(), 1)); - List cRev = new ArrayList(c); + Map finished = new HashMap(); + List r = new ArrayList(Math.max(c.size(), 1)); + List cRev = new ArrayList(c); Collections.reverse(cRev); - Iterator it = cRev.iterator(); + Iterator it = cRev.iterator(); while (it.hasNext()) { - List cycle = visit(it.next(), edges, finished, r); + List cycle = visit(it.next(), edges, finished, r); if (cycle != null) { throw new TopologicalSortException(cRev, edges); @@ -2232,7 +2233,7 @@ * @param r the order in progress * @return list with detected cycle */ - static List visit(Object node, Map edges, Map finished, List r) { + static List visit(T node, Map> edges, Map finished, List r) { Boolean b = (Boolean) finished.get(node); //System.err.println("node=" + node + " color=" + b); @@ -2241,22 +2242,22 @@ return null; } - ArrayList cycle = new ArrayList(); + ArrayList cycle = new ArrayList(); cycle.add(node); finished.put(node, null); return cycle; } - Collection e = (Collection) edges.get(node); + Collection e = edges.get(node); if (e != null) { finished.put(node, Boolean.FALSE); - Iterator it = e.iterator(); + Iterator it = e.iterator(); while (it.hasNext()) { - List cycle = visit(it.next(), edges, finished, r); + List cycle = visit(it.next(), edges, finished, r); if (cycle != null) { if (cycle instanceof ArrayList) { @@ -2430,11 +2431,11 @@ re = new RE13(); // } - TreeSet list = new TreeSet( - new Comparator() { - public int compare(Object o1, Object o2) { - String s1 = ((String[]) o1)[0]; - String s2 = ((String[]) o2)[0]; + TreeSet list = new TreeSet( + new Comparator() { + public int compare(String[] o1, String[] o2) { + String s1 = o1[0]; + String s2 = o2[0]; int i1 = s1.length(); int i2 = s2.length(); @@ -2500,7 +2501,7 @@ * @param resource URL identifiing transaction table * @param results will be filled with String[2] */ - private static void loadTranslationFile(RE re, BufferedReader reader, Set results) + private static void loadTranslationFile(RE re, BufferedReader reader, Set results) throws IOException { for (;;) { String line = reader.readLine(); @@ -2575,7 +2576,7 @@ JPopupMenu menu = org.netbeans.modules.openide.util.AWTBridge.getDefault().createEmptyPopup(); // keeps actions for which was menu item created already - HashSet counted = new HashSet(); + HashSet counted = new HashSet(); boolean haveHadNonSep = false; boolean needSep = false; @@ -2957,7 +2958,7 @@ /** Implementation of the active queue. */ - private static final class ActiveQueue extends ReferenceQueue implements Runnable { + private static final class ActiveQueue extends ReferenceQueue implements Runnable { private boolean running; private boolean deprecated; @@ -2970,15 +2971,15 @@ t.start(); } - public Reference poll() { + public Reference poll() { throw new java.lang.UnsupportedOperationException(); } - public Reference remove(long timeout) throws IllegalArgumentException, InterruptedException { + public Reference remove(long timeout) throws IllegalArgumentException, InterruptedException { throw new java.lang.InterruptedException(); } - public Reference remove() throws InterruptedException { + public Reference remove() throws InterruptedException { throw new java.lang.InterruptedException(); } Index: openide/util/src/org/openide/util/UtilitiesCompositeActionMap.java =================================================================== RCS file: /cvs/openide/util/src/org/openide/util/UtilitiesCompositeActionMap.java,v retrieving revision 1.1 diff -u -r1.1 UtilitiesCompositeActionMap.java --- openide/util/src/org/openide/util/UtilitiesCompositeActionMap.java 21 Apr 2005 20:16:13 -0000 1.1 +++ openide/util/src/org/openide/util/UtilitiesCompositeActionMap.java 16 Mar 2006 12:59:03 -0000 @@ -76,7 +76,7 @@ } private Object[] keys(boolean all) { - java.util.HashSet keys = new java.util.HashSet(); + java.util.HashSet keys = new java.util.HashSet(); Component c = component; @@ -85,7 +85,7 @@ javax.swing.ActionMap m = ((JComponent) c).getActionMap(); if (m != null) { - java.util.List l; + java.util.List l; if (all) { l = java.util.Arrays.asList(m.allKeys()); Index: openide/util/src/org/openide/util/WeakListenerImpl.java =================================================================== RCS file: /cvs/openide/util/src/org/openide/util/WeakListenerImpl.java,v retrieving revision 1.4 diff -u -r1.4 WeakListenerImpl.java --- openide/util/src/org/openide/util/WeakListenerImpl.java 5 Mar 2006 21:08:57 -0000 1.4 +++ openide/util/src/org/openide/util/WeakListenerImpl.java 16 Mar 2006 12:59:03 -0000 @@ -29,6 +29,8 @@ import java.lang.reflect.Proxy; import java.util.EventListener; import java.util.EventObject; +import java.util.Map; +import java.util.WeakHashMap; import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeListener; import javax.swing.event.DocumentEvent; @@ -49,7 +51,7 @@ Class listenerClass; /** weak reference to source */ - private Reference source; + private Reference source; /** * @param listenerClass class/interface of the listener @@ -81,7 +83,7 @@ if (source == null) { this.source = null; } else { - this.source = new WeakReference(source); + this.source = new WeakReference(source); } } @@ -116,11 +118,11 @@ return getClass().getName() + "[" + ((listener == null) ? "null" : (listener.getClass().getName() + "]")); } - public static EventListener create(Class lType, Class apiType, EventListener l, Object source) { + public static T create(Class lType, Class apiType, T l, Object source) { ProxyListener pl = new ProxyListener(lType, apiType, l); pl.setSource(source); - return (EventListener) pl.proxy; + return lType.cast(pl.proxy); } /** Weak property change listener @@ -343,7 +345,7 @@ private static Method equalsMth; /** Class -> Reference(Constructor) */ - private static final java.util.WeakHashMap constructors = new java.util.WeakHashMap(); + private static final Map> constructors = new WeakHashMap>(); /** proxy generated for this listener */ public final Object proxy; @@ -360,7 +362,7 @@ if (proxyConstructor == null) { Class proxyClass = Proxy.getProxyClass(c.getClassLoader(), new Class[] { c }); proxyConstructor = proxyClass.getConstructor(new Class[] { InvocationHandler.class }); - constructors.put(c, new SoftReference(proxyConstructor)); + constructors.put(c, new SoftReference(proxyConstructor)); } Object p; @@ -457,7 +459,7 @@ /** Reference that also holds ref to WeakListenerImpl. */ - private static final class ListenerReference extends WeakReference implements Runnable { + private static final class ListenerReference extends WeakReference implements Runnable { private static Class lastClass; private static String lastMethodName; private static Method lastRemove; @@ -481,7 +483,7 @@ if (weakListener.source != source) { // plan new cleanup into the activeReferenceQueue with this listener and // provided source - weakListener.source = new WeakReference(source) { + weakListener.source = new WeakReference (source) { ListenerReference doNotGCRef = new ListenerReference(new Object(), weakListener); }; } Index: openide/util/src/org/openide/util/WeakListeners.java =================================================================== RCS file: /cvs/openide/util/src/org/openide/util/WeakListeners.java,v retrieving revision 1.1 diff -u -r1.1 WeakListeners.java --- openide/util/src/org/openide/util/WeakListeners.java 21 Apr 2005 20:16:14 -0000 1.1 +++ openide/util/src/org/openide/util/WeakListeners.java 16 Mar 2006 12:59:03 -0000 @@ -185,7 +185,7 @@ * @return an instance of lType delegating all the interface * calls to l. */ - public static EventListener create(Class lType, EventListener l, Object source) { + public static T create(Class lType, T l, Object source) { if (!lType.isInterface()) { throw new IllegalArgumentException("Not interface: " + lType); } @@ -228,7 +228,7 @@ * calls to l. * @since 4.12 */ - public static EventListener create(Class lType, Class apiType, EventListener l, Object source) { + public static T create(Class lType, Class apiType, T l, Object source) { if (!lType.isInterface()) { throw new IllegalArgumentException("Not interface: " + lType); } Index: openide/util/src/org/openide/util/WeakSet.java =================================================================== RCS file: /cvs/openide/util/src/org/openide/util/WeakSet.java,v retrieving revision 1.2 diff -u -r1.2 WeakSet.java --- openide/util/src/org/openide/util/WeakSet.java 12 Sep 2005 21:13:07 -0000 1.2 +++ openide/util/src/org/openide/util/WeakSet.java 16 Mar 2006 12:59:03 -0000 @@ -34,7 +34,7 @@ * * @author Ales Novak */ -public class WeakSet extends AbstractSet implements Cloneable, Serializable { +public class WeakSet extends AbstractSet implements Cloneable, Serializable { static final long serialVersionUID = 3062376055928236721L; /** load factor */ @@ -47,14 +47,14 @@ private long modcount; /** Reference queue of collected weak refs */ - private transient ReferenceQueue refq; + private transient ReferenceQueue refq; /** Count of null in this set */ long nullCount; /** An array of Entries */ - private transient Entry[] entries; - transient Entry iterChain; + private transient Entry[] entries; + transient Entry iterChain; /** Constructs a new set. */ public WeakSet() { @@ -64,7 +64,7 @@ /** Constructs a new set containing the elements in the specified collection. * @param c a collection to add */ - public WeakSet(Collection c) { + public WeakSet(Collection c) { this(); addAll(c); } @@ -90,8 +90,8 @@ modcount = 0; this.loadFactor = loadFactor; nullCount = 0; - refq = new ReferenceQueue(); - entries = new Entry[initialCapacity]; + refq = new ReferenceQueue(); + entries = Entry.createArray(initialCapacity); iterChain = null; } @@ -99,7 +99,7 @@ * * @param o an Object to add */ - public boolean add(Object o) { + public boolean add(E o) { if (o == null) { size++; nullCount++; @@ -118,8 +118,8 @@ size++; int hash = hashIt(o); - Entry next = entries[hash]; - iterChain = entries[hash] = new Entry(o, refq, next, iterChain); + Entry next = entries[hash]; + iterChain = entries[hash] = new Entry(this, o, refq, next, iterChain); rehash(); return true; @@ -139,11 +139,11 @@ /** Returns a shallow copy of this WeakSet instance: the elements themselves are not cloned. */ public Object clone() { - WeakSet nws = new WeakSet(1, loadFactor); + WeakSet nws = new WeakSet(1, loadFactor); nws.size = size; nws.nullCount = nullCount; - Entry[] cloned = new Entry[entries.length]; + Entry[] cloned = Entry.createArray(entries.length); nws.entries = cloned; for (int i = 0; i < cloned.length; i++) { @@ -157,7 +157,7 @@ } // chains into nws iterator chain - Entry entry = cloned[i]; + Entry entry = cloned[i]; while (entry != null) { entry.chainIntoIter(nws.iterChain); @@ -188,7 +188,7 @@ } /** Returns an iterator over the elements in this set. */ - public Iterator iterator() { + public Iterator iterator() { return new WeakSetIterator(); } @@ -229,9 +229,9 @@ return size; } - public Object[] toArray(Object[] array) { - ArrayList list = new ArrayList(array.length); - Iterator it = iterator(); + public T[] toArray(T[] array) { + ArrayList list = new ArrayList(array.length); + Iterator it = iterator(); while (it.hasNext()) { list.add(it.next()); @@ -241,8 +241,8 @@ } public Object[] toArray() { - ArrayList list = new ArrayList(); - Iterator it = iterator(); + ArrayList list = new ArrayList(); + Iterator it = iterator(); while (it.hasNext()) { list.add(it.next()); @@ -273,7 +273,7 @@ /** Checks if the queue is empty if not pending weak refs are removed. */ void checkRefQueue() { for (;;) { - Entry entry = (Entry) refq.poll(); + Entry entry = Entry.class.cast(refq.poll()); if (entry == null) { break; @@ -328,23 +328,24 @@ obtos.writeObject(toArray()); } + @SuppressWarnings("unchecked") private void readObject(ObjectInputStream obtis) throws IOException, ClassNotFoundException { obtis.defaultReadObject(); Object[] arr = (Object[]) obtis.readObject(); entries = new Entry[(int) (size * 1.5)]; - refq = new ReferenceQueue(); + refq = new ReferenceQueue(); for (int i = 0; i < arr.length; i++) { - add(arr[i]); + add((E)arr[i]); } } - class WeakSetIterator implements Iterator { - Entry current; - Entry next; - Object currentObj; - Object nextObj; + class WeakSetIterator implements Iterator { + Entry current; + Entry next; + E currentObj; + E nextObj; final long myModcount; long myNullCount; @@ -354,13 +355,13 @@ current = null; next = null; - Entry ee = iterChain; + Entry ee = iterChain; if (ee == null) { return; } - Object o = ee.get(); + E o = ee.get(); while (ee.isEnqueued()) { ee = ee.iterChainNext; @@ -382,7 +383,7 @@ return ((myNullCount > 0) || (next != null)); } - public Object next() { + public E next() { checkModcount(); checkRefQueue(); @@ -432,16 +433,21 @@ } /** Entries of this set */ - class Entry extends WeakReference { + static class Entry extends WeakReference { + /** reference to outer WeakSet */ + private WeakSet set; + // double linked list - Entry prev; - Entry next; + Entry prev; + Entry next; private final int hashcode; - Entry iterChainNext; - Entry iterChainPrev; + Entry iterChainNext; + Entry iterChainPrev; - Entry(Object referenced, ReferenceQueue q, Entry next, Entry nextInIter) { + Entry(WeakSet set, E referenced, ReferenceQueue q, Entry next, Entry nextInIter) { super(referenced, q); + this.set = set; + this.next = next; this.prev = null; @@ -450,7 +456,7 @@ } if (referenced != null) { - hashcode = hashIt(referenced); + hashcode = set.hashIt(referenced); } else { hashcode = 0; } @@ -458,7 +464,12 @@ chainIntoIter(nextInIter); } - void chainIntoIter(Entry nextInIter) { + @SuppressWarnings("unchecked") + static final Entry[] createArray(int size) { + return new Entry[size]; + } + + void chainIntoIter(Entry nextInIter) { iterChainNext = nextInIter; if (nextInIter != null) { @@ -489,11 +500,11 @@ if (iterChainPrev != null) { iterChainPrev.iterChainNext = iterChainNext; } else { // root - iterChain = iterChainNext; + set.iterChain = iterChainNext; } - if (entries[hashcode] == this) { - entries[hashcode] = next; + if (set.entries[hashcode] == this) { + set.entries[hashcode] = next; } prev = null; @@ -516,8 +527,8 @@ } } - public Entry clone(ReferenceQueue q) { - return new Entry(get(), q, ((next != null) ? (Entry) next.clone(q) : null), null); + public Entry clone(ReferenceQueue q) { + return new Entry(set, get(), q, next != null ? next.clone(q) : null, null); } } } Index: openide/util/src/org/openide/util/actions/CallableSystemAction.java =================================================================== RCS file: /cvs/openide/util/src/org/openide/util/actions/CallableSystemAction.java,v retrieving revision 1.4 diff -u -r1.4 CallableSystemAction.java --- openide/util/src/org/openide/util/actions/CallableSystemAction.java 1 Dec 2005 12:05:09 -0000 1.4 +++ openide/util/src/org/openide/util/actions/CallableSystemAction.java 16 Mar 2006 12:59:03 -0000 @@ -42,7 +42,7 @@ * Set of action classes for which we have already issued a warning that * {@link #asynchronous} was not overridden to return false. */ - private static final Set warnedAsynchronousActions = new WeakSet(); // Set + private static final Set warnedAsynchronousActions = new WeakSet(); private static final boolean DEFAULT_ASYNCH = !Boolean.getBoolean( "org.openide.util.actions.CallableSystemAction.synchronousByDefault" ); Index: openide/util/src/org/openide/util/actions/CallbackSystemAction.java =================================================================== RCS file: /cvs/openide/util/src/org/openide/util/actions/CallbackSystemAction.java,v retrieving revision 1.6 diff -u -r1.6 CallbackSystemAction.java --- openide/util/src/org/openide/util/actions/CallbackSystemAction.java 28 Feb 2006 15:44:05 -0000 1.6 +++ openide/util/src/org/openide/util/actions/CallbackSystemAction.java 16 Mar 2006 12:59:03 -0000 @@ -44,10 +44,10 @@ private static final String PROP_ACTION_PERFORMER = "actionPerformer"; // NOI18N /** a list of all actions that has survive focus change set to false */ - private static final WeakSet notSurviving = new WeakSet(37); + private static final WeakSet> notSurviving = new WeakSet>(37); /** a list of CallableSystemAction actions surviving focus change */ - private static final WeakSet surviving = new WeakSet(37); + private static final WeakSet> surviving = new WeakSet>(37); /** key to access listener */ private static final Object LISTENER = new Object(); @@ -254,18 +254,18 @@ /** Array of actions from a set of classes. */ - private static ArrayList toInstances(java.util.Set s) { - ArrayList actions; + private static ArrayList toInstances(java.util.Set> s) { + ArrayList actions; synchronized (notSurviving) { - actions = new ArrayList(s.size()); + actions = new ArrayList(s.size()); - Iterator it = s.iterator(); + Iterator> it = s.iterator(); while (it.hasNext()) { - Class c = (Class) it.next(); + Class c = it.next(); - Object a = SystemAction.findObject(c, false); + SystemAction a = SystemAction.findObject(c, false); if (a != null) { actions.add(a); @@ -311,7 +311,7 @@ private static final class GlobalManager implements LookupListener { private static GlobalManager instance; private Lookup.Result result; - private Reference actionMap = new WeakReference(null); + private Reference actionMap = new WeakReference(null); private final ActionMap survive = new ActionMap(); private GlobalManager() { @@ -374,7 +374,7 @@ return; } - actionMap = new WeakReference(a); + actionMap = new WeakReference(a); if (errLog) { err.log("clearActionPerformers"); // NOI18N @@ -387,7 +387,7 @@ /** An action that holds a weak reference to other action. */ - private static final class WeakAction extends WeakReference implements Action { + private static final class WeakAction extends WeakReference implements Action { public WeakAction(Action delegate) { super(delegate); } @@ -428,12 +428,12 @@ /** A class that listens on changes in enabled state of an action * and updates the state of the action according to it. */ - private static final class ActionDelegateListener extends WeakReference implements PropertyChangeListener { + private static final class ActionDelegateListener extends WeakReference implements PropertyChangeListener { private WeakReference delegate; - public ActionDelegateListener(CallbackSystemAction c, javax.swing.Action delegate) { + public ActionDelegateListener(CallbackSystemAction c, Action delegate) { super(c); - this.delegate = new WeakReference(delegate); + this.delegate = new WeakReference(delegate); delegate.addPropertyChangeListener(this); } @@ -466,7 +466,7 @@ prev.removePropertyChangeListener(this); } - this.delegate = new WeakReference(action); + this.delegate = new WeakReference(action); action.addPropertyChangeListener(this); } @@ -579,7 +579,7 @@ last.removePropertyChangeListener(weakL); } - lastRef = new WeakReference(a); + lastRef = new WeakReference(a); a.addPropertyChangeListener(weakL); } Index: openide/util/src/org/openide/util/actions/SystemAction.java =================================================================== RCS file: /cvs/openide/util/src/org/openide/util/actions/SystemAction.java,v retrieving revision 1.4 diff -u -r1.4 SystemAction.java --- openide/util/src/org/openide/util/actions/SystemAction.java 1 Dec 2005 12:05:10 -0000 1.4 +++ openide/util/src/org/openide/util/actions/SystemAction.java 16 Mar 2006 12:59:03 -0000 @@ -52,7 +52,7 @@ /** Name of property for the action's display icon, if textual. */ private static final String PROP_ICON_TEXTUAL = "iconTextual"; // NOI18N private static ImageIcon BLANK_ICON = null; - private static final Set relativeIconResourceClasses = new HashSet(200); // Set + private static final Set relativeIconResourceClasses = new HashSet(200); // Matches NB 3.4 w/ openide-compat.jar; see #26491 private static final long serialVersionUID = -8361232596876856810L; @@ -74,8 +74,8 @@ * @exception ClassCastException if the class is not SystemAction * @exception IllegalArgumentException if the instance cannot be created */ - public static SystemAction get(Class actionClass) { - return (SystemAction) findObject(actionClass, true); + public static T get(Class actionClass) { + return findObject(actionClass, true); } /** Get a human presentable name of the action. @@ -332,7 +332,7 @@ * @return an array of both sets of actions in the same order */ public static SystemAction[] linkActions(SystemAction[] actions1, SystemAction[] actions2) { - List l = new Vector(Arrays.asList(actions1)); + List l = new Vector(Arrays.asList(actions1)); l.addAll(Arrays.asList(actions2)); return (SystemAction[]) l.toArray(actions1); Index: openide/util/src/org/openide/util/datatransfer/ExTransferable.java =================================================================== RCS file: /cvs/openide/util/src/org/openide/util/datatransfer/ExTransferable.java,v retrieving revision 1.2 diff -u -r1.2 ExTransferable.java --- openide/util/src/org/openide/util/datatransfer/ExTransferable.java 16 Nov 2005 21:44:50 -0000 1.2 +++ openide/util/src/org/openide/util/datatransfer/ExTransferable.java 16 Mar 2006 12:59:03 -0000 @@ -46,7 +46,7 @@ } /** hash map that assigns objects to dataflavors (DataFlavor, Single) */ - private LinkedHashMap map; + private LinkedHashMap map; /** listeners */ private EventListenerList listeners; @@ -56,7 +56,7 @@ * @param o clipobard owner (or null) */ private ExTransferable(final Transferable t) { - map = new LinkedHashMap(); + map = new LinkedHashMap(); final DataFlavor[] df = t.getTransferDataFlavors(); @@ -356,7 +356,7 @@ * @param array array of flavors */ public boolean areDataFlavorsSupported(DataFlavor[] array) { - HashSet flav = new HashSet(); + HashSet flav = new HashSet(); for (int i = 0; i < array.length; i++) { flav.add(array[i]); Index: openide/util/src/org/openide/util/io/NbObjectOutputStream.java =================================================================== RCS file: /cvs/openide/util/src/org/openide/util/io/NbObjectOutputStream.java,v retrieving revision 1.3 diff -u -r1.3 NbObjectOutputStream.java --- openide/util/src/org/openide/util/io/NbObjectOutputStream.java 18 Jan 2006 05:23:05 -0000 1.3 +++ openide/util/src/org/openide/util/io/NbObjectOutputStream.java 16 Mar 2006 12:59:03 -0000 @@ -37,7 +37,7 @@ */ public class NbObjectOutputStream extends ObjectOutputStream { private static final String SVUID = "serialVersionUID"; // NOI18N - private static final Set alreadyReported = new WeakSet(); // Set + private static final Set alreadyReported = new WeakSet(); static { // See below. @@ -47,8 +47,8 @@ alreadyReported.add("java.awt.geom.AffineTransform"); // NOI18N } - private static Map examinedClasses = new WeakHashMap(250); // Map - private final List serializing = new ArrayList(50); // List + private static Map examinedClasses = new WeakHashMap(250); + private final List serializing = new ArrayList(50); /** Create a new object output. * @param os the underlying output stream @@ -134,7 +134,7 @@ String classname = cl.getName(); if (alreadyReported.add(classname)) { - Set serializingUniq = new HashSet(); // Set + Set serializingUniq = new HashSet(); StringBuffer b = new StringBuffer("Serializable class "); // NOI18N b.append(classname); b.append(" does not declare serialVersionUID field. Encountered while storing: ["); // NOI18N