Author: krosenvold Date: Wed Oct 10 19:51:28 2012 New Revision: 1396763 URL: http://svn.apache.org/viewvc?rev=1396763&view=rev Log: o Added some generics, cleaned up
Modified: maven/shared/trunk/maven-runtime/pom.xml maven/shared/trunk/maven-runtime/src/main/java/org/apache/maven/shared/runtime/XMLMavenRuntimeVisitor.java maven/shared/trunk/maven-shared-io/src/test/java/org/apache/maven/shared/io/TestUtils.java maven/shared/trunk/maven-shared-utils/src/main/java/org/apache/maven/shared/utils/CollectionUtils.java maven/shared/trunk/maven-shared-utils/src/main/java/org/apache/maven/shared/utils/ReaderFactory.java maven/shared/trunk/maven-shared-utils/src/main/java/org/apache/maven/shared/utils/StringUtils.java Modified: maven/shared/trunk/maven-runtime/pom.xml URL: http://svn.apache.org/viewvc/maven/shared/trunk/maven-runtime/pom.xml?rev=1396763&r1=1396762&r2=1396763&view=diff ============================================================================== --- maven/shared/trunk/maven-runtime/pom.xml (original) +++ maven/shared/trunk/maven-runtime/pom.xml Wed Oct 10 19:51:28 2012 @@ -72,8 +72,7 @@ <dependency> <groupId>commons-io</groupId> <artifactId>commons-io</artifactId> - <version>1.3.1</version> - <scope>test</scope> + <version>2.2</version> </dependency> <dependency> <groupId>junit</groupId> Modified: maven/shared/trunk/maven-runtime/src/main/java/org/apache/maven/shared/runtime/XMLMavenRuntimeVisitor.java URL: http://svn.apache.org/viewvc/maven/shared/trunk/maven-runtime/src/main/java/org/apache/maven/shared/runtime/XMLMavenRuntimeVisitor.java?rev=1396763&r1=1396762&r2=1396763&view=diff ============================================================================== --- maven/shared/trunk/maven-runtime/src/main/java/org/apache/maven/shared/runtime/XMLMavenRuntimeVisitor.java (original) +++ maven/shared/trunk/maven-runtime/src/main/java/org/apache/maven/shared/runtime/XMLMavenRuntimeVisitor.java Wed Oct 10 19:51:28 2012 @@ -27,6 +27,7 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; +import org.apache.commons.io.input.XmlStreamReader; import org.apache.maven.model.Model; import org.apache.maven.model.io.xpp3.MavenXpp3Reader; import org.apache.maven.project.DuplicateProjectException; @@ -147,7 +148,7 @@ class XMLMavenRuntimeVisitor implements in = connection.getInputStream(); - Model model = reader.read( ReaderFactory.newXmlReader( in ) ); + Model model = reader.read( new XmlStreamReader( in ) ); return new MavenProject( model ); } Modified: maven/shared/trunk/maven-shared-io/src/test/java/org/apache/maven/shared/io/TestUtils.java URL: http://svn.apache.org/viewvc/maven/shared/trunk/maven-shared-io/src/test/java/org/apache/maven/shared/io/TestUtils.java?rev=1396763&r1=1396762&r2=1396763&view=diff ============================================================================== --- maven/shared/trunk/maven-shared-io/src/test/java/org/apache/maven/shared/io/TestUtils.java (original) +++ maven/shared/trunk/maven-shared-io/src/test/java/org/apache/maven/shared/io/TestUtils.java Wed Oct 10 19:51:28 2012 @@ -106,7 +106,7 @@ public final class TestUtils { StringWriter buffer = new StringWriter(); - Reader reader = ReaderFactory.newXmlReader( file ); + Reader reader = new XmlStreamReader( file ); IOUtil.copy( reader, buffer ); Modified: maven/shared/trunk/maven-shared-utils/src/main/java/org/apache/maven/shared/utils/CollectionUtils.java URL: http://svn.apache.org/viewvc/maven/shared/trunk/maven-shared-utils/src/main/java/org/apache/maven/shared/utils/CollectionUtils.java?rev=1396763&r1=1396762&r2=1396763&view=diff ============================================================================== --- maven/shared/trunk/maven-shared-utils/src/main/java/org/apache/maven/shared/utils/CollectionUtils.java (original) +++ maven/shared/trunk/maven-shared-utils/src/main/java/org/apache/maven/shared/utils/CollectionUtils.java Wed Oct 10 19:51:28 2012 @@ -74,7 +74,7 @@ public class CollectionUtils return dominantMap; } - if ( dominantMap == null && recessiveMap != null ) + if ( dominantMap == null ) { return recessiveMap; } @@ -96,9 +96,8 @@ public class CollectionUtils // Now take the keys we just found and extract the values from // the recessiveMap and put the key:value pairs into the dominantMap. - for ( Iterator i = contributingRecessiveKeys.iterator(); i.hasNext(); ) + for ( Object key : contributingRecessiveKeys ) { - Object key = i.next(); result.put( key, recessiveMap.get( key ) ); } @@ -115,7 +114,7 @@ public class CollectionUtils */ public static Map mergeMaps( Map[] maps ) { - Map result = null; + Map result; if ( maps.length == 0 ) { @@ -176,10 +175,9 @@ public class CollectionUtils public static Collection subtract( final Collection a, final Collection b ) { ArrayList list = new ArrayList( a ); - Iterator it = b.iterator(); - while ( it.hasNext() ) + for ( Object aB : b ) { - list.remove( it.next() ); + list.remove( aB ); } return list; } @@ -195,18 +193,16 @@ public class CollectionUtils public static Map getCardinalityMap( final Collection col ) { HashMap count = new HashMap(); - Iterator it = col.iterator(); - while ( it.hasNext() ) + for ( Object obj : col ) { - Object obj = it.next(); Integer c = (Integer) ( count.get( obj ) ); if ( null == c ) { - count.put( obj, new Integer( 1 ) ); + count.put( obj, 1 ); } else { - count.put( obj, new Integer( c.intValue() + 1 ) ); + count.put( obj, c + 1 ); } } return count; @@ -233,7 +229,7 @@ public class CollectionUtils * Take an array of type T and convert it into a HashSet of type T. * If <code>null</code> or an empty array gets passed, an empty Set will be returned. * - * @param array + * @param array The array * @return the filled HashSet of type T */ public static <T> Set<T> arrayAsHashSet( T[] array ) @@ -253,7 +249,7 @@ public class CollectionUtils * Take an array of type T and convert it into a TreeSet of type T. * If <code>null</code> or an empty array gets passed, an empty Set will be returned. * - * @param array + * @param array The array * @return the filled TreeSet of type T */ public static <T> Set<T> arrayAsTreeSet( T[] array ) @@ -280,7 +276,7 @@ public class CollectionUtils Object o = freqMap.get( obj ); if ( o != null ) // minimize NullPointerExceptions { - return ( (Integer) o ).intValue(); + return (Integer) o; } } catch ( NullPointerException e ) Modified: maven/shared/trunk/maven-shared-utils/src/main/java/org/apache/maven/shared/utils/ReaderFactory.java URL: http://svn.apache.org/viewvc/maven/shared/trunk/maven-shared-utils/src/main/java/org/apache/maven/shared/utils/ReaderFactory.java?rev=1396763&r1=1396762&r2=1396763&view=diff ============================================================================== --- maven/shared/trunk/maven-shared-utils/src/main/java/org/apache/maven/shared/utils/ReaderFactory.java (original) +++ maven/shared/trunk/maven-shared-utils/src/main/java/org/apache/maven/shared/utils/ReaderFactory.java Wed Oct 10 19:51:28 2012 @@ -30,7 +30,7 @@ import java.io.Reader; import java.io.UnsupportedEncodingException; import java.net.URL; import java.nio.charset.Charset; -import org.apache.maven.shared.utils.xml.XmlStreamReader; +import org.apache.commons.io.input.XmlStreamReader; /** @@ -143,18 +143,6 @@ public class ReaderFactory /** * Create a new Reader with default plaform encoding. * - * @param in not null input stream. - * @return a reader instance for the input stream using the default platform charset. - * @see Charset#defaultCharset() - */ - public static Reader newPlatformReader( InputStream in ) - { - return new InputStreamReader( in ); - } - - /** - * Create a new Reader with default plaform encoding. - * * @param file not null file. * @return a reader instance for the input file using the default platform charset. * @throws FileNotFoundException if any. @@ -167,20 +155,6 @@ public class ReaderFactory } /** - * Create a new Reader with default plaform encoding. - * - * @param url not null url. - * @return a reader instance for the input url using the default platform charset. - * @throws IOException if any. - * @see Charset#defaultCharset() - */ - public static Reader newPlatformReader( URL url ) - throws IOException - { - return new InputStreamReader( url.openStream() ); - } - - /** * Create a new Reader with specified encoding. * * @param in not null input stream. Modified: maven/shared/trunk/maven-shared-utils/src/main/java/org/apache/maven/shared/utils/StringUtils.java URL: http://svn.apache.org/viewvc/maven/shared/trunk/maven-shared-utils/src/main/java/org/apache/maven/shared/utils/StringUtils.java?rev=1396763&r1=1396762&r2=1396763&view=diff ============================================================================== --- maven/shared/trunk/maven-shared-utils/src/main/java/org/apache/maven/shared/utils/StringUtils.java (original) +++ maven/shared/trunk/maven-shared-utils/src/main/java/org/apache/maven/shared/utils/StringUtils.java Wed Oct 10 19:51:28 2012 @@ -49,6 +49,7 @@ import java.util.StringTokenizer; * @version $Id$ * @since 1.0 */ +@SuppressWarnings( "JavaDoc" ) public class StringUtils { /** @@ -106,7 +107,7 @@ public class StringUtils */ public static String deleteWhitespace( String str ) { - StringBuffer buffer = new StringBuffer(); + StringBuilder buffer = new StringBuilder(); int sz = str.length(); for ( int i = 0; i < sz; i++ ) { @@ -256,15 +257,13 @@ public class StringUtils { return -1; } - int sz = searchStrs.length; - // String's can't have a MAX_VALUEth index. int ret = Integer.MAX_VALUE; - int tmp = 0; - for ( int i = 0; i < sz; i++ ) + int tmp; + for ( String searchStr : searchStrs ) { - tmp = str.indexOf( searchStrs[i] ); + tmp = str.indexOf( searchStr ); if ( tmp == -1 ) { continue; @@ -295,12 +294,11 @@ public class StringUtils { return -1; } - int sz = searchStrs.length; int ret = -1; - int tmp = 0; - for ( int i = 0; i < sz; i++ ) + int tmp; + for ( String searchStr : searchStrs ) { - tmp = str.lastIndexOf( searchStrs[i] ); + tmp = str.lastIndexOf( searchStr ); if ( tmp > ret ) { ret = tmp; @@ -542,7 +540,7 @@ public class StringUtils */ public static String[] split( String str, String separator, int max ) { - StringTokenizer tok = null; + StringTokenizer tok; if ( separator == null ) { // Null separator means we're using StringTokenizer's default @@ -562,7 +560,7 @@ public class StringUtils String[] list = new String[listSize]; int i = 0; - int lastTokenBegin = 0; + int lastTokenBegin; int lastTokenEnd = 0; while ( tok.hasMoreTokens() ) { @@ -622,7 +620,7 @@ public class StringUtils } int arraySize = array.length; int bufSize = ( arraySize == 0 ? 0 : ( array[0].toString().length() + separator.length() ) * arraySize ); - StringBuffer buf = new StringBuffer( bufSize ); + StringBuilder buf = new StringBuilder( bufSize ); for ( int i = 0; i < arraySize; i++ ) { @@ -652,7 +650,7 @@ public class StringUtils { separator = ""; } - StringBuffer buf = new StringBuffer( 256 ); // Java default is 16, probably too small + StringBuilder buf = new StringBuilder( 256 ); // Java default is 16, probably too small while ( iterator.hasNext() ) { buf.append( iterator.next() ); @@ -767,8 +765,8 @@ public class StringUtils return text; } - StringBuffer buf = new StringBuffer( text.length() ); - int start = 0, end = 0; + StringBuilder buf = new StringBuilder( text.length() ); + int start = 0, end; while ( ( end = text.indexOf( repl, start ) ) != -1 ) { buf.append( text.substring( start, end ) ).append( with ); @@ -1164,7 +1162,7 @@ public class StringUtils */ public static String repeat( String str, int repeat ) { - StringBuffer buffer = new StringBuffer( repeat * str.length() ); + StringBuilder buffer = new StringBuilder( repeat * str.length() ); for ( int i = 0; i < repeat; i++ ) { buffer.append( str ); @@ -1486,11 +1484,11 @@ public class StringUtils return null; } int sz = str.length(); - StringBuffer buffer = new StringBuffer( sz ); + StringBuilder buffer = new StringBuilder( sz ); boolean whitespace = false; - char ch = 0; - char tmp = 0; + char ch; + char tmp; for ( int i = 0; i < sz; i++ ) { @@ -1543,7 +1541,7 @@ public class StringUtils return null; } int sz = str.length(); - StringBuffer buffer = new StringBuffer( sz ); + StringBuilder buffer = new StringBuilder( sz ); boolean space = true; for ( int i = 0; i < sz; i++ ) { @@ -1584,7 +1582,7 @@ public class StringUtils return null; } int sz = str.length(); - StringBuffer buffer = new StringBuffer( sz ); + StringBuilder buffer = new StringBuilder( sz ); boolean space = true; for ( int i = 0; i < sz; i++ ) { @@ -2082,7 +2080,7 @@ public class StringUtils text = StringUtils.replace( text, "${" + key + "}", value ); - if ( key.indexOf( " " ) == -1 ) + if ( !key.contains( " " ) ) { text = StringUtils.replace( text, "$" + key, value ); } @@ -2107,7 +2105,7 @@ public class StringUtils { String temp; - StringBuffer out = new StringBuffer(); + StringBuilder out = new StringBuilder(); temp = data; @@ -2177,7 +2175,7 @@ public class StringUtils */ public static String addAndDeHump( String view ) { - StringBuffer sb = new StringBuffer(); + StringBuilder sb = new StringBuilder(); for ( int i = 0; i < view.length(); i++ ) { @@ -2283,9 +2281,9 @@ public class StringUtils } else { - for ( int i = 0; i < quotingTriggers.length; i++ ) + for ( char quotingTrigger : quotingTriggers ) { - if ( escaped.indexOf( quotingTriggers[i] ) > -1 ) + if ( escaped.indexOf( quotingTrigger ) > -1 ) { quote = true; break; @@ -2319,7 +2317,7 @@ public class StringUtils System.arraycopy( escapedChars, 0, eqc, 0, escapedChars.length ); Arrays.sort( eqc ); - StringBuffer buffer = new StringBuffer( source.length() ); + StringBuilder buffer = new StringBuilder( source.length() ); for ( int i = 0; i < source.length(); i++ ) { @@ -2346,7 +2344,7 @@ public class StringUtils */ public static String removeDuplicateWhitespace( String s ) { - StringBuffer result = new StringBuffer(); + StringBuilder result = new StringBuilder(); int length = s.length(); boolean isPreviousWhiteSpace = false; for ( int i = 0; i < length; i++ ) @@ -2405,7 +2403,7 @@ public class StringUtils int length = s.length(); - StringBuffer buffer = new StringBuffer( length ); + StringBuilder buffer = new StringBuilder( length ); for ( int i = 0; i < length; i++ ) { if ( s.charAt( i ) == '\r' ) @@ -2451,11 +2449,7 @@ public class StringUtils */ public static boolean contains( String str, char searchChar ) { - if ( isEmpty( str ) ) - { - return false; - } - return str.indexOf( searchChar ) >= 0; + return !isEmpty( str ) && str.indexOf( searchChar ) >= 0; } /** @@ -2481,10 +2475,6 @@ public class StringUtils */ public static boolean contains( String str, String searchStr ) { - if ( str == null || searchStr == null ) - { - return false; - } - return str.indexOf( searchStr ) >= 0; + return !( str == null || searchStr == null ) && str.contains( searchStr ); } }