You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by rf...@apache.org on 2012/10/10 23:15:38 UTC
svn commit: r1396799 - in
/maven/shared/trunk/maven-shared-utils/src/main/java/org/apache/maven/shared/utils:
ArrayUtils.java introspection/ClassMap.java introspection/MethodMap.java
io/FileUtils.java io/SelectorUtils.java
Author: rfscholte
Date: Wed Oct 10 21:15:37 2012
New Revision: 1396799
URL: http://svn.apache.org/viewvc?rev=1396799&view=rev
Log:
More generics and varArgs
Modified:
maven/shared/trunk/maven-shared-utils/src/main/java/org/apache/maven/shared/utils/ArrayUtils.java
maven/shared/trunk/maven-shared-utils/src/main/java/org/apache/maven/shared/utils/introspection/ClassMap.java
maven/shared/trunk/maven-shared-utils/src/main/java/org/apache/maven/shared/utils/introspection/MethodMap.java
maven/shared/trunk/maven-shared-utils/src/main/java/org/apache/maven/shared/utils/io/FileUtils.java
maven/shared/trunk/maven-shared-utils/src/main/java/org/apache/maven/shared/utils/io/SelectorUtils.java
Modified: maven/shared/trunk/maven-shared-utils/src/main/java/org/apache/maven/shared/utils/ArrayUtils.java
URL: http://svn.apache.org/viewvc/maven/shared/trunk/maven-shared-utils/src/main/java/org/apache/maven/shared/utils/ArrayUtils.java?rev=1396799&r1=1396798&r2=1396799&view=diff
==============================================================================
--- maven/shared/trunk/maven-shared-utils/src/main/java/org/apache/maven/shared/utils/ArrayUtils.java (original)
+++ maven/shared/trunk/maven-shared-utils/src/main/java/org/apache/maven/shared/utils/ArrayUtils.java Wed Oct 10 21:15:37 2012
@@ -40,7 +40,7 @@ public class ArrayUtils
/**
* An empty immutable <code>Class</code> array.
*/
- public static final Class[] EMPTY_CLASS_ARRAY = new Class[0];
+ public static final Class<?>[] EMPTY_CLASS_ARRAY = new Class[0];
/**
* An empty immutable <code>String</code> array.
Modified: maven/shared/trunk/maven-shared-utils/src/main/java/org/apache/maven/shared/utils/introspection/ClassMap.java
URL: http://svn.apache.org/viewvc/maven/shared/trunk/maven-shared-utils/src/main/java/org/apache/maven/shared/utils/introspection/ClassMap.java?rev=1396799&r1=1396798&r2=1396799&view=diff
==============================================================================
--- maven/shared/trunk/maven-shared-utils/src/main/java/org/apache/maven/shared/utils/introspection/ClassMap.java (original)
+++ maven/shared/trunk/maven-shared-utils/src/main/java/org/apache/maven/shared/utils/introspection/ClassMap.java Wed Oct 10 21:15:37 2012
@@ -47,7 +47,7 @@ class ClassMap
* the basis for the Method map.
*/
- private final Class clazz;
+ private final Class<?> clazz;
/**
* Cache of Methods, or CACHE_MISS, keyed by method
@@ -60,7 +60,7 @@ class ClassMap
/**
* Standard constructor
*/
- public ClassMap( Class clazz )
+ public ClassMap( Class<?> clazz )
{
this.clazz = clazz;
populateMethodCache();
@@ -69,7 +69,7 @@ class ClassMap
/**
* @return the class object whose methods are cached by this map.
*/
- Class getCachedClass()
+ Class<?> getCachedClass()
{
return clazz;
}
@@ -86,7 +86,7 @@ class ClassMap
* If nothing is found, then we must actually go
* and introspect the method from the MethodMap.
*/
- public Method findMethod( String name, Object[] params )
+ public Method findMethod( String name, Object... params )
throws MethodMap.AmbiguousException
{
String methodKey = makeMethodKey( name, params );
@@ -179,11 +179,11 @@ class ClassMap
*/
private String makeMethodKey( Method method )
{
- Class[] parameterTypes = method.getParameterTypes();
+ Class<?>[] parameterTypes = method.getParameterTypes();
StringBuilder methodKey = new StringBuilder( method.getName() );
- for ( Class parameterType : parameterTypes )
+ for ( Class<?> parameterType : parameterTypes )
{
/*
* If the argument type is primitive then we want
@@ -235,7 +235,7 @@ class ClassMap
return methodKey.toString();
}
- private static String makeMethodKey( String method, Object[] params )
+ private static String makeMethodKey( String method, Object... params )
{
StringBuilder methodKey = new StringBuilder().append( method );
@@ -260,7 +260,7 @@ class ClassMap
* from public superclasses and interfaces (if they exist). Basically
* upcasts every method to the nearest acccessible method.
*/
- private static Method[] getAccessibleMethods( Class clazz )
+ private static Method[] getAccessibleMethods( Class<?> clazz )
{
Method[] methods = clazz.getMethods();
@@ -316,7 +316,7 @@ class ClassMap
* @param upcastCount current number of methods we have matched
* @return count of matched methods
*/
- private static int getAccessibleMethods( Class clazz, MethodInfo[] methodInfos, int upcastCount )
+ private static int getAccessibleMethods( Class<?> clazz, MethodInfo[] methodInfos, int upcastCount )
{
int l = methodInfos.length;
@@ -362,7 +362,7 @@ class ClassMap
* Examine superclass
*/
- Class superclazz = clazz.getSuperclass();
+ Class<?> superclazz = clazz.getSuperclass();
if ( superclazz != null )
{
@@ -384,7 +384,7 @@ class ClassMap
* any interfaces, however nothing guarantees it will not in future.
*/
- Class[] interfaces = clazz.getInterfaces();
+ Class<?>[] interfaces = clazz.getInterfaces();
for ( int i = interfaces.length; i-- > 0; )
{
@@ -416,7 +416,7 @@ class ClassMap
*/
private static Method getPublicMethod( Method method )
{
- Class clazz = method.getDeclaringClass();
+ Class<?> clazz = method.getDeclaringClass();
/*
* Short circuit for (hopefully the majority of) cases where the declaring
@@ -439,7 +439,7 @@ class ClassMap
* @param name the name of the method
* @param paramTypes the classes of method parameters
*/
- private static Method getPublicMethod( Class clazz, String name, Class[] paramTypes )
+ private static Method getPublicMethod( Class<?> clazz, String name, Class<?>... paramTypes )
{
/*
* if this class is public, then try to get it
@@ -466,7 +466,7 @@ class ClassMap
* try the superclass
*/
- Class superclazz = clazz.getSuperclass();
+ Class<?> superclazz = clazz.getSuperclass();
if ( superclazz != null )
{
@@ -482,9 +482,9 @@ class ClassMap
* and interfaces
*/
- Class[] interfaces = clazz.getInterfaces();
+ Class<?>[] interfaces = clazz.getInterfaces();
- for ( Class anInterface : interfaces )
+ for ( Class<?> anInterface : interfaces )
{
Method interfaceMethod = getPublicMethod( anInterface, name, paramTypes );
@@ -506,7 +506,7 @@ class ClassMap
String name;
- Class[] parameterTypes;
+ Class<?>[] parameterTypes;
boolean upcast;
@@ -518,7 +518,7 @@ class ClassMap
upcast = false;
}
- void tryUpcasting( Class clazz )
+ void tryUpcasting( Class<?> clazz )
throws NoSuchMethodException
{
method = clazz.getMethod( name, parameterTypes );
Modified: maven/shared/trunk/maven-shared-utils/src/main/java/org/apache/maven/shared/utils/introspection/MethodMap.java
URL: http://svn.apache.org/viewvc/maven/shared/trunk/maven-shared-utils/src/main/java/org/apache/maven/shared/utils/introspection/MethodMap.java?rev=1396799&r1=1396798&r2=1396799&view=diff
==============================================================================
--- maven/shared/trunk/maven-shared-utils/src/main/java/org/apache/maven/shared/utils/introspection/MethodMap.java (original)
+++ maven/shared/trunk/maven-shared-utils/src/main/java/org/apache/maven/shared/utils/introspection/MethodMap.java Wed Oct 10 21:15:37 2012
@@ -106,10 +106,10 @@ public class MethodMap
* @throws AmbiguousException if there is more than one maximally
* specific applicable method
*/
- public Method find( String methodName, Object[] args )
+ public Method find( String methodName, Object... args )
throws AmbiguousException
{
- List methodList = get( methodName );
+ List<Method> methodList = get( methodName );
if ( methodList == null )
{
@@ -117,7 +117,7 @@ public class MethodMap
}
int l = args.length;
- Class[] classes = new Class[l];
+ Class<?>[] classes = new Class[l];
for ( int i = 0; i < l; ++i )
{
@@ -143,7 +143,7 @@ public class MethodMap
}
- private static Method getMostSpecific( List methods, Class[] classes )
+ private static Method getMostSpecific( List<Method> methods, Class<?>... classes )
throws AmbiguousException
{
LinkedList<Method> applicables = getApplicables( methods, classes );
@@ -168,10 +168,10 @@ public class MethodMap
for ( Method app : applicables )
{
- Class[] appArgs = app.getParameterTypes();
+ Class<?>[] appArgs = app.getParameterTypes();
boolean lessSpecific = false;
- for ( Iterator maximal = maximals.iterator(); !lessSpecific && maximal.hasNext(); )
+ for ( Iterator<Method> maximal = maximals.iterator(); !lessSpecific && maximal.hasNext(); )
{
Method max = (Method) maximal.next();
@@ -227,7 +227,7 @@ public class MethodMap
* @return MORE_SPECIFIC if c1 is more specific than c2, LESS_SPECIFIC if
* c1 is less specific than c2, INCOMPARABLE if they are incomparable.
*/
- private static int moreSpecific( Class[] c1, Class[] c2 )
+ private static int moreSpecific( Class<?>[] c1, Class<?>[] c2 )
{
boolean c1MoreSpecific = false;
boolean c2MoreSpecific = false;
@@ -278,19 +278,16 @@ public class MethodMap
* formal and actual arguments matches, and argument types are assignable
* to formal types through a method invocation conversion).
*/
- private static LinkedList<Method> getApplicables( List methods, Class[] classes )
+ private static LinkedList<Method> getApplicables( List<Method> methods, Class<?>... classes )
{
LinkedList<Method> list = new LinkedList<Method>();
- for ( Object method1 : methods )
+ for ( Method method : methods )
{
- Method method = (Method) method1;
-
if ( isApplicable( method, classes ) )
{
list.add( method );
}
-
}
return list;
}
@@ -303,9 +300,9 @@ public class MethodMap
* @param classes The arguments
* @return true if the method applies to the parameter types
*/
- private static boolean isApplicable( Method method, Class[] classes )
+ private static boolean isApplicable( Method method, Class<?>... classes )
{
- Class[] methodArgs = method.getParameterTypes();
+ Class<?>[] methodArgs = method.getParameterTypes();
if ( methodArgs.length != classes.length )
{
@@ -341,7 +338,7 @@ public class MethodMap
* type or an object type of a primitive type that can be converted to
* the formal type.
*/
- private static boolean isMethodInvocationConvertible( Class formal, Class actual )
+ private static boolean isMethodInvocationConvertible( Class<?> formal, Class<?> actual )
{
/*
* if it's a null, it means the arg was null
@@ -424,7 +421,7 @@ public class MethodMap
* or formal and actual are both primitive types and actual can be
* subject to widening conversion to formal.
*/
- private static boolean isStrictMethodInvocationConvertible( Class formal, Class actual )
+ private static boolean isStrictMethodInvocationConvertible( Class<?> formal, Class<?> actual )
{
/*
* we shouldn't get a null into, but if so
Modified: maven/shared/trunk/maven-shared-utils/src/main/java/org/apache/maven/shared/utils/io/FileUtils.java
URL: http://svn.apache.org/viewvc/maven/shared/trunk/maven-shared-utils/src/main/java/org/apache/maven/shared/utils/io/FileUtils.java?rev=1396799&r1=1396798&r2=1396799&view=diff
==============================================================================
--- maven/shared/trunk/maven-shared-utils/src/main/java/org/apache/maven/shared/utils/io/FileUtils.java (original)
+++ maven/shared/trunk/maven-shared-utils/src/main/java/org/apache/maven/shared/utils/io/FileUtils.java Wed Oct 10 21:15:37 2012
@@ -507,7 +507,7 @@ public class FileUtils
* @throws IOException if any
* @since 1.0
*/
- public static void fileWriteArray( File file, String[] data )
+ public static void fileWriteArray( File file, String... data )
throws IOException
{
fileWriteArray( file, null, data );
@@ -522,7 +522,7 @@ public class FileUtils
* @throws IOException if any
* @since 1.0
*/
- public static void fileWriteArray( File file, String encoding, String[] data )
+ public static void fileWriteArray( File file, String encoding, String... data )
throws IOException
{
Writer writer = null;
@@ -577,7 +577,7 @@ public class FileUtils
* @param extensions an array of expected extensions.
* @return An array of files for the wanted extensions.
*/
- public static String[] getFilesFromExtension( String directory, String[] extensions )
+ public static String[] getFilesFromExtension( String directory, String... extensions )
{
List<String> files = new ArrayList<String>();
@@ -604,7 +604,7 @@ public class FileUtils
//them with the current list.
String[] fetchFiles = getFilesFromExtension(currentFileName, extensions);
- files = blendFilesToVector(files, fetchFiles);
+ files = blendFilesToList(files, fetchFiles);
} else {
//ok... add the file
@@ -625,7 +625,7 @@ public class FileUtils
/**
* Private helper method for getFilesFromExtension()
*/
- private static List<String> blendFilesToVector( List<String> v, String[] files )
+ private static List<String> blendFilesToList( List<String> v, String... files )
{
Collections.addAll(v, files);
@@ -637,7 +637,7 @@ public class FileUtils
* Note that if the file does not have an extension, an empty string
* ("") is matched for.
*/
- private static boolean isValidFile( String file, String[] extensions )
+ private static boolean isValidFile( String file, String... extensions )
{
String extension = extension( file );
if ( extension == null )
@@ -764,7 +764,7 @@ public class FileUtils
* @throws IOException if an error occurs
*/
@SuppressWarnings( "deprecation" )
- public static URL[] toURLs( final File[] files )
+ public static URL[] toURLs( final File... files )
throws IOException
{
final URL[] urls = new URL[files.length];
@@ -1828,7 +1828,7 @@ public class FileUtils
* @param wrappers array of {@link FilterWrapper}
* @throws IOException if an IO error occurs during copying or filtering
*/
- public static void copyFile( File from, File to, String encoding, FilterWrapper[] wrappers )
+ public static void copyFile( File from, File to, String encoding, FilterWrapper... wrappers )
throws IOException
{
copyFile( from, to, encoding, wrappers, false );
Modified: maven/shared/trunk/maven-shared-utils/src/main/java/org/apache/maven/shared/utils/io/SelectorUtils.java
URL: http://svn.apache.org/viewvc/maven/shared/trunk/maven-shared-utils/src/main/java/org/apache/maven/shared/utils/io/SelectorUtils.java?rev=1396799&r1=1396798&r2=1396799&view=diff
==============================================================================
--- maven/shared/trunk/maven-shared-utils/src/main/java/org/apache/maven/shared/utils/io/SelectorUtils.java (original)
+++ maven/shared/trunk/maven-shared-utils/src/main/java/org/apache/maven/shared/utils/io/SelectorUtils.java Wed Oct 10 21:15:37 2012
@@ -558,7 +558,7 @@ public final class SelectorUtils
*
* @param path Path to tokenize. Must not be <code>null</code>.
* @param separator The separator to use
- * @return a Vector of path elements from the tokenized path
+ * @return a List of path elements from the tokenized path
*/
private static List<String> tokenizePath( String path, String separator )
{