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.
I just made a class Generics in the Ant module that includes /** copies a map and checks casts as it copies */ public static <K,V> Map<K,V> checkedMapByCopy(Map m, Class<K> k, Class<V> v) throws ClassCastException; /** returns proxy set backed by a raw set; iterator etc. quietly remove any elements not of desired type */ public static <E> Set<E> checkedSetByFilter(Set s, Class<E> e); /** union class; contains either first type or second type */ public static abstract class Union2<First,Second> { public abstract First first() throws IllegalArgumentException; public abstract Second second() throws IllegalArgumentException; public abstract boolean hasFirst(); public abstract boolean hasSecond(); } public static <First,Second> Union2<First,Second> union2First(First first); public static <First,Second> Union2<First,Second> union2Second(Second second); Unit tests also in ant module. Can these things go into openide/util somewhere? Also would like to add to e.g. Enumerations: public static <E> Enumeration<E> checkedEnumerationByFilter(Enumeration e, Class<E> c); which would quietly remove any objects not null or assignable to E. And perhaps other related things, e.g. Union3 (if ever needed), checkedSetByCopy, checkedMapByFilter, etc. The current stuff is just what I needed in the ant module.
Also could be used in NbBundle.
Union2 could be used in o.n.JarClassLoader, o.n.Main, o.n.ModuleManager, etc. - just grep for '<Object'.
It can. If someone thinks it is important file a task for me once the API is there and I can convert these classes.
I have made some refinements and additions. There is now checkedSetByCopy checkedMapByCopy checkedSetByFilter checkedMapByFilter [no checkedListBy* for now; haven't seen a need, but could be created later] checkedEnumerationByFilter Union2 All are fully documented in the Ant module, and unit test coverage is maximal acc. to Emma: http://www.netbeans.org/source/browse/~checkout~/ant/src/org/apache/tools/ant/module/Generics.java http://www.netbeans.org/source/browse/~checkout~/ant/test/unit/src/org/apache/tools/ant/module/GenericsTest.java Would appreciate quick review, comments. Else I plan to commit in a few days time; would probably put checkedEnumerationByFilter into Enumerations, and all else into o.o.u.Generics, unless someone has a better idea.
Maybe NbCollections would be better name(p3)? Maybe it would be better to start NetBeans Utilities module and put the class to org.nb.api.util? That way it need not be on classpath and we would have a place to add util stuff to without growing the size of "NetBeans Runtime Container"(p4).
Re. NbCollections - perhaps. Odd for Union2 however. An idea: would people prefer to see Generics.Union2 (with the static factory methods in Generics) or a top-level class Union2 (with the factory methods inside it)? If the latter, then of course NbCollections for the remaining methods would make more sense, since they are very much analogous to methods in j.u.Collections. (The existing j.u.C.checked* methods are not so helpful because they assume the incoming collection is already well-typed, which is exactly what the new methods do not assume.) Re. new util module - possible but 1. It means we cannot use the new methods in some places like NbBundle or JarClassLoader where they would be helpful (not required). 2. If we have openide/util with miscellaneous utility classes, and another (true) module with miscellaneous utility classes, how does someone know where to look for a utility class? Seems a bit arbitrary. Would be nicer to split off logical subportions of openide/util into new modules, e.g. for action infrastructure or data transfer or threading or lookup, and keep openide/util for truly general-purpose utilities. But I don't know.
Created attachment 30774 [details] Proposed patch
I've done some more cleanup and employed the new APIs in several places. See attached patch, from branch nbcollections_73637. I plan to merge this early next week if there are no objections.
Created attachment 30775 [details] Some further uses of Union2 in core/bootstrap
I do not like much Union2.union2first(First f) it repeats the same information twice. I guess Union2.first(First f) would be shorter and nicer. If that does not work than maybe Union2.createFirst(First f) is in my opinion still better than Union2.union2first...
Re. union2first: true, probably createFirst would be better. I guess I was optimizing the naming for the case that you would be using a static import of the method, as I originally was in the Ant module, but probably this is not the case. BTW it seems Java type inference is pretty weak. This works: Union2<A,B> x; // ... x = Union2.union2First(new A()); but this does not: Set<Union2<A,B>> x; // ... x.add(Union2.union2First(new A())); You have to explicitly say: x.add(Union2.<A,B>union2First(new A())); Kind of annoying.
committed 1.30 ant/nbproject/project.xml committed 1.35 ant/src-bridge/org/apache/tools/ant/module/bridge/impl/BridgeImpl.java committed 1.24 ant/src-bridge/org/apache/tools/ant/module/bridge/impl/NbBuildLogger.java removed 1.7 ant/src/org/apache/tools/ant/module/Generics.java committed 1.8 ant/src/org/apache/tools/ant/module/api/AntTargetExecutor.java committed 1.25 ant/src/org/apache/tools/ant/module/api/IntrospectedInfo.java committed 1.14 ant/src/org/apache/tools/ant/module/api/support/TargetLister.java committed 1.10 ant/src/org/apache/tools/ant/module/nodes/AdvancedActionPanel.java committed 1.56 ant/src/org/apache/tools/ant/module/run/TargetExecutor.java removed 1.7 ant/test/unit/src/org/apache/tools/ant/module/GenericsTest.java committed 1.9 core/bootstrap/nbproject/project.xml committed 1.24 core/bootstrap/src/org/netbeans/JarClassLoader.java committed 1.3 core/bootstrap/src/org/netbeans/MainImpl.java committed 1.14 core/bootstrap/src/org/netbeans/Module.java committed 1.16 core/bootstrap/src/org/netbeans/ModuleManager.java committed 1.8 core/bootstrap/src/org/netbeans/PatchByteCode.java committed 1.9 core/bootstrap/src/org/netbeans/StandardModule.java committed 1.10 core/execution/nbproject/project.xml committed 1.6 core/execution/src/org/netbeans/core/execution/beaninfo/editors/NbClassPathCustomEditor.java committed 1.8 core/startup/nbproject/project.xml committed 1.14 core/startup/src/org/netbeans/core/startup/NbEvents.java committed 1.11 core/startup/src/org/netbeans/core/startup/layers/BinaryFS.java committed 1.7 openide/fs/nbproject/project.xml committed 1.8 openide/fs/src/org/openide/filesystems/AbstractFileSystem.java committed 1.18 openide/fs/src/org/openide/filesystems/MIMESupport.java committed 1.5 openide/fs/src/org/openide/filesystems/MultiFileSystem.java committed 1.5 openide/fs/src/org/openide/filesystems/RefreshRequest.java committed 1.14 openide/util/apichanges.xml committed 1.15 openide/util/nbproject/project.properties committed 1.14 openide/util/src/org/openide/util/NbBundle.java committed 1.2 openide/util/src/org/openide/util/NbCollections.java committed 1.2 openide/util/src/org/openide/util/Union2.java committed 1.2 openide/util/test/unit/src/org/openide/util/NbCollectionsTest.java committed 1.2 openide/util/test/unit/src/org/openide/util/Union2Test.java