Repository: incubator-geode Updated Branches: refs/heads/feature/GEODE-835 ce2ac6830 -> 7115ab79e
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/7115ab79/geode-joptsimple/src/main/java/joptsimple/internal/Column.java ---------------------------------------------------------------------- diff --git a/geode-joptsimple/src/main/java/joptsimple/internal/Column.java b/geode-joptsimple/src/main/java/joptsimple/internal/Column.java deleted file mode 100644 index e7be1a2..0000000 --- a/geode-joptsimple/src/main/java/joptsimple/internal/Column.java +++ /dev/null @@ -1,133 +0,0 @@ -/* - The MIT License - - Copyright (c) 2004-2011 Paul R. Holser, Jr. - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be - included in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ - -package joptsimple.internal; - -import java.text.BreakIterator; -import java.util.Comparator; -import java.util.LinkedList; -import java.util.List; -import java.util.Locale; - -import static java.lang.System.*; -import static java.text.BreakIterator.*; - -import static joptsimple.internal.Strings.*; - - -/** - * @author <a href="mailto:phol...@alumni.rice.edu">Paul Holser</a> - */ -public class Column { - static final Comparator<Column> BY_HEIGHT = new Comparator<Column>() { - public int compare( Column first, Column second ) { - if ( first.height() < second.height() ) - return -1; - return first.height() == second.height() ? 0 : 1; - } - }; - - private final String header; - private final List<String> data; - private final int width; - private int height; - - Column( String header, int width ) { - this.header = header; - this.width = Math.max( width, header.length() ); - data = new LinkedList<String>(); - height = 0; - } - - int addCells( Object cellCandidate ) { - int originalHeight = height; - - String source = String.valueOf( cellCandidate ).trim(); - for ( String eachPiece : source.split( getProperty( "line.separator" ) ) ) - processNextEmbeddedLine( eachPiece ); - - return height - originalHeight; - } - - private void processNextEmbeddedLine( String line ) { - BreakIterator words = BreakIterator.getLineInstance( Locale.US ); - words.setText( line ); - - StringBuilder nextCell = new StringBuilder(); - - int start = words.first(); - for ( int end = words.next(); end != DONE; start = end, end = words.next() ) - nextCell = processNextWord( line, nextCell, start, end ); - - if ( nextCell.length() > 0 ) - addCell( nextCell.toString() ); - } - - private StringBuilder processNextWord( String source, StringBuilder nextCell, int start, int end ) { - StringBuilder augmented = nextCell; - - String word = source.substring( start, end ); - if ( augmented.length() + word.length() > width ) { - addCell( augmented.toString() ); - augmented = new StringBuilder( " " ).append( word ); - } - else - augmented.append( word ); - - return augmented; - } - - void addCell( String newCell ) { - data.add( newCell ); - ++height; - } - - void writeHeaderOn( StringBuilder buffer, boolean appendSpace ) { - buffer.append( header ).append( repeat( ' ', width - header.length() ) ); - - if ( appendSpace ) - buffer.append( ' ' ); - } - - void writeSeparatorOn( StringBuilder buffer, boolean appendSpace ) { - buffer.append( repeat( '-', header.length() ) ).append( repeat( ' ', width - header.length() ) ); - if ( appendSpace ) - buffer.append( ' ' ); - } - - void writeCellOn( int index, StringBuilder buffer, boolean appendSpace ) { - if ( index < data.size() ) { - String item = data.get( index ); - - buffer.append( item ).append( repeat( ' ', width - item.length() ) ); - if ( appendSpace ) - buffer.append( ' ' ); - } - } - - int height() { - return height; - } -} http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/7115ab79/geode-joptsimple/src/main/java/joptsimple/internal/ColumnWidthCalculator.java ---------------------------------------------------------------------- diff --git a/geode-joptsimple/src/main/java/joptsimple/internal/ColumnWidthCalculator.java b/geode-joptsimple/src/main/java/joptsimple/internal/ColumnWidthCalculator.java deleted file mode 100644 index 9b3bccc..0000000 --- a/geode-joptsimple/src/main/java/joptsimple/internal/ColumnWidthCalculator.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - The MIT License - - Copyright (c) 2004-2011 Paul R. Holser, Jr. - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be - included in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ - -package joptsimple.internal; - -/** - * @author <a href="mailto:phol...@alumni.rice.edu">Paul Holser</a> - */ -class ColumnWidthCalculator { - int calculate( int totalWidth, int numberOfColumns ) { - if ( numberOfColumns == 1 ) - return totalWidth; - - int remainder = totalWidth % numberOfColumns; - if ( remainder == numberOfColumns - 1 ) - return totalWidth / numberOfColumns; - return totalWidth / numberOfColumns - 1; - } -} http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/7115ab79/geode-joptsimple/src/main/java/joptsimple/internal/ColumnarData.java ---------------------------------------------------------------------- diff --git a/geode-joptsimple/src/main/java/joptsimple/internal/ColumnarData.java b/geode-joptsimple/src/main/java/joptsimple/internal/ColumnarData.java deleted file mode 100644 index ebb6d12..0000000 --- a/geode-joptsimple/src/main/java/joptsimple/internal/ColumnarData.java +++ /dev/null @@ -1,163 +0,0 @@ -/* - The MIT License - - Copyright (c) 2004-2011 Paul R. Holser, Jr. - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be - included in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ - -package joptsimple.internal; - -import java.util.Iterator; -import java.util.LinkedList; -import java.util.List; - -import static java.lang.Integer.*; -import static java.lang.System.*; -import static java.util.Collections.*; - -import static joptsimple.internal.Column.*; -import static joptsimple.internal.Strings.*; - - -/** - * A means to display data in a text grid. - * - * @author <a href="mailto:phol...@alumni.rice.edu">Paul Holser</a> - */ -public class ColumnarData { - private static final String LINE_SEPARATOR = getProperty( "line.separator" ); - private static final int TOTAL_WIDTH = 80; - - private final ColumnWidthCalculator widthCalculator; - private final List<Column> columns; - private final String[] headers; - - /** - * Creates a new grid with the given column headers. - * - * @param headers column headers - */ - public ColumnarData( String... headers ) { - this.headers = headers.clone(); - widthCalculator = new ColumnWidthCalculator(); - columns = new LinkedList<Column>(); - - clear(); - } - - /** - * Adds a row to the grid. The data will fall under the corresponding headers. - * There can be fewer elements in the row than headers. Any data in columns outside - * of the number of headers will not be added to the grid. - * - * @param rowData row data to add - */ - public void addRow( Object... rowData ) { - int[] numberOfCellsAddedAt = addRowCells( rowData ); - addPaddingCells( numberOfCellsAddedAt ); - } - - /** - * Gives a string that represents the data formatted in columns. - * - * @return the formatted grid - */ - public String format() { - StringBuilder buffer = new StringBuilder(); - - writeHeadersOn( buffer ); - writeSeparatorsOn( buffer ); - writeRowsOn( buffer ); - - return buffer.toString(); - } - - /** - * Removes all data from the grid, but preserves the headers. - */ - public final void clear() { - columns.clear(); - - int desiredColumnWidth = widthCalculator.calculate( TOTAL_WIDTH, headers.length ); - for ( String each : headers ) - columns.add( new Column( each, desiredColumnWidth ) ); - } - - private void writeHeadersOn( StringBuilder buffer ) { - for ( Iterator<Column> iter = columns.iterator(); iter.hasNext(); ) - iter.next().writeHeaderOn( buffer, iter.hasNext() ); - - buffer.append( LINE_SEPARATOR ); - } - - private void writeSeparatorsOn( StringBuilder buffer ) { - for ( Iterator<Column> iter = columns.iterator(); iter.hasNext(); ) - iter.next().writeSeparatorOn( buffer, iter.hasNext() ); - - buffer.append( LINE_SEPARATOR ); - } - - private void writeRowsOn( StringBuilder buffer ) { - int maxHeight = max( columns, BY_HEIGHT ).height(); - - for ( int i = 0; i < maxHeight; ++i ) - writeRowOn( buffer, i ); - } - - private void writeRowOn( StringBuilder buffer, int rowIndex ) { - for ( Iterator<Column> iter = columns.iterator(); iter.hasNext(); ) - iter.next().writeCellOn( rowIndex, buffer, iter.hasNext() ); - - buffer.append( LINE_SEPARATOR ); - } - - private int arrayMax( int[] numbers ) { - int maximum = MIN_VALUE; - - for ( int each : numbers ) - maximum = Math.max( maximum, each ); - - return maximum; - } - - private int[] addRowCells( Object... rowData ) { - int[] cellsAddedAt = new int[ rowData.length ]; - - Iterator<Column> iter = columns.iterator(); - for ( int i = 0; iter.hasNext() && i < rowData.length; ++i ) - cellsAddedAt[ i ] = iter.next().addCells( rowData[ i ] ); - - return cellsAddedAt; - } - - private void addPaddingCells( int... numberOfCellsAddedAt ) { - int maxHeight = arrayMax( numberOfCellsAddedAt ); - - Iterator<Column> iter = columns.iterator(); - for ( int i = 0; iter.hasNext() && i < numberOfCellsAddedAt.length; ++i ) - addPaddingCellsForColumn( iter.next(), maxHeight, numberOfCellsAddedAt[ i ] ); - } - - private void addPaddingCellsForColumn( Column column, int maxHeight, int numberOfCellsAdded ) { - for ( int i = 0; i < maxHeight - numberOfCellsAdded; ++i ) - column.addCell( EMPTY ); - } -} http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/7115ab79/geode-joptsimple/src/main/java/joptsimple/internal/ConstructorInvokingValueConverter.java ---------------------------------------------------------------------- diff --git a/geode-joptsimple/src/main/java/joptsimple/internal/ConstructorInvokingValueConverter.java b/geode-joptsimple/src/main/java/joptsimple/internal/ConstructorInvokingValueConverter.java deleted file mode 100644 index 7a23c6a..0000000 --- a/geode-joptsimple/src/main/java/joptsimple/internal/ConstructorInvokingValueConverter.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - The MIT License - - Copyright (c) 2004-2011 Paul R. Holser, Jr. - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be - included in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ - -package joptsimple.internal; - -import java.lang.reflect.Constructor; - -import joptsimple.ValueConverter; - -import static joptsimple.internal.Reflection.*; - - - -/** - * @param <V> constraint on the type of values being converted to - * @author <a href="mailto:phol...@alumni.rice.edu">Paul Holser</a> - */ -class ConstructorInvokingValueConverter<V> implements ValueConverter<V> { - private final Constructor<V> ctor; - - ConstructorInvokingValueConverter( Constructor<V> ctor ) { - this.ctor = ctor; - } - - public V convert( String value ) { - return instantiate( ctor, value ); - } - - public Class<V> valueType() { - return ctor.getDeclaringClass(); - } - - public String valuePattern() { - return null; - } -} http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/7115ab79/geode-joptsimple/src/main/java/joptsimple/internal/MethodInvokingValueConverter.java ---------------------------------------------------------------------- diff --git a/geode-joptsimple/src/main/java/joptsimple/internal/MethodInvokingValueConverter.java b/geode-joptsimple/src/main/java/joptsimple/internal/MethodInvokingValueConverter.java deleted file mode 100644 index 345242c..0000000 --- a/geode-joptsimple/src/main/java/joptsimple/internal/MethodInvokingValueConverter.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - The MIT License - - Copyright (c) 2004-2011 Paul R. Holser, Jr. - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be - included in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ - -package joptsimple.internal; - -import java.lang.reflect.Method; - -import joptsimple.ValueConverter; - -import static joptsimple.internal.Reflection.*; - - - -/** - * @param <V> constraint on the type of values being converted to - * @author <a href="mailto:phol...@alumni.rice.edu">Paul Holser</a> - */ -class MethodInvokingValueConverter<V> implements ValueConverter<V> { - private final Method method; - private final Class<V> clazz; - - MethodInvokingValueConverter( Method method, Class<V> clazz ) { - this.method = method; - this.clazz = clazz; - } - - public V convert( String value ) { - return clazz.cast( invoke( method, value ) ); - } - - public Class<V> valueType() { - return clazz; - } - - public String valuePattern() { - return null; - } -} http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/7115ab79/geode-joptsimple/src/main/java/joptsimple/internal/Objects.java ---------------------------------------------------------------------- diff --git a/geode-joptsimple/src/main/java/joptsimple/internal/Objects.java b/geode-joptsimple/src/main/java/joptsimple/internal/Objects.java deleted file mode 100644 index 7ccca1c..0000000 --- a/geode-joptsimple/src/main/java/joptsimple/internal/Objects.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - The MIT License - - Copyright (c) 2004-2011 Paul R. Holser, Jr. - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be - included in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ - -package joptsimple.internal; - -/** - * @author <a href="mailto:phol...@alumni.rice.edu">Paul Holser</a> - */ -public final class Objects { - private Objects() { - throw new UnsupportedOperationException(); - } - - /** - * Rejects {@code null} references. - * - * @param target reference to check - * @throws NullPointerException if {@code target} is {@code null} - */ - public static void ensureNotNull( Object target ) { - if ( target == null ) - throw new NullPointerException(); - } -} http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/7115ab79/geode-joptsimple/src/main/java/joptsimple/internal/Reflection.java ---------------------------------------------------------------------- diff --git a/geode-joptsimple/src/main/java/joptsimple/internal/Reflection.java b/geode-joptsimple/src/main/java/joptsimple/internal/Reflection.java deleted file mode 100644 index 77d2e6b..0000000 --- a/geode-joptsimple/src/main/java/joptsimple/internal/Reflection.java +++ /dev/null @@ -1,143 +0,0 @@ -/* - The MIT License - - Copyright (c) 2004-2011 Paul R. Holser, Jr. - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be - included in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ - -package joptsimple.internal; - -import java.lang.reflect.Constructor; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; - -import joptsimple.ValueConverter; - -import static java.lang.reflect.Modifier.*; - -import static joptsimple.internal.Classes.*; - - - -/** - * Helper methods for reflection. - * - * @author <a href="mailto:phol...@alumni.rice.edu">Paul Holser</a> - */ -public final class Reflection { - private Reflection() { - throw new UnsupportedOperationException(); - } - - /** - * Finds an appropriate value converter for the given class. - * - * @param <V> a constraint on the class object to introspect - * @param clazz class to introspect on - * @return a converter method or constructor - */ - public static <V> ValueConverter<V> findConverter( Class<V> clazz ) { - Class<V> maybeWrapper = wrapperOf( clazz ); - - ValueConverter<V> valueOf = valueOfConverter( maybeWrapper ); - if ( valueOf != null ) - return valueOf; - - ValueConverter<V> constructor = constructorConverter( maybeWrapper ); - if ( constructor != null ) - return constructor; - - throw new IllegalArgumentException( clazz + " is not a value type" ); - } - - private static <V> ValueConverter<V> valueOfConverter( Class<V> clazz ) { - try { - Method valueOf = clazz.getDeclaredMethod( "valueOf", String.class ); - if ( meetsConverterRequirements( valueOf, clazz ) ) - return new MethodInvokingValueConverter<V>( valueOf, clazz ); - - return null; - } - catch ( NoSuchMethodException ignored ) { - return null; - } - } - - private static <V> ValueConverter<V> constructorConverter( Class<V> clazz ) { - try { - return new ConstructorInvokingValueConverter<V>( clazz.getConstructor( String.class ) ); - } - catch ( NoSuchMethodException ignored ) { - return null; - } - } - - /** - * Invokes the given constructor with the given arguments. - * - * @param <T> constraint on the type of the objects yielded by the constructor - * @param constructor constructor to invoke - * @param args arguments to hand to the constructor - * @return the result of invoking the constructor - * @throws ReflectionException in lieu of the gaggle of reflection-related exceptions - */ - public static <T> T instantiate( Constructor<T> constructor, Object... args ) { - try { - return constructor.newInstance( args ); - } - catch ( Exception ex ) { - throw reflectionException( ex ); - } - } - - /** - * Invokes the given static method with the given arguments. - * - * @param method method to invoke - * @param args arguments to hand to the method - * @return the result of invoking the method - * @throws ReflectionException in lieu of the gaggle of reflection-related exceptions - */ - public static Object invoke( Method method, Object... args ) { - try { - return method.invoke( null, args ); - } - catch ( Exception ex ) { - throw reflectionException( ex ); - } - } - - private static boolean meetsConverterRequirements( Method method, Class<?> expectedReturnType ) { - int modifiers = method.getModifiers(); - return isPublic( modifiers ) && isStatic( modifiers ) && expectedReturnType.equals( method.getReturnType() ); - } - - private static RuntimeException reflectionException( Exception ex ) { - if ( ex instanceof IllegalArgumentException ) - return new ReflectionException( ex ); - if ( ex instanceof InvocationTargetException ) - return new ReflectionException( ex.getCause() ); - if ( ex instanceof RuntimeException ) - return (RuntimeException) ex; - - return new ReflectionException( ex ); - } -} http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/7115ab79/geode-joptsimple/src/main/java/joptsimple/internal/ReflectionException.java ---------------------------------------------------------------------- diff --git a/geode-joptsimple/src/main/java/joptsimple/internal/ReflectionException.java b/geode-joptsimple/src/main/java/joptsimple/internal/ReflectionException.java deleted file mode 100644 index 2f48e0b..0000000 --- a/geode-joptsimple/src/main/java/joptsimple/internal/ReflectionException.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - The MIT License - - Copyright (c) 2004-2011 Paul R. Holser, Jr. - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be - included in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ - -package joptsimple.internal; - -/** - * This unchecked exception wraps reflection-oriented exceptions. - * - * @author <a href="mailto:phol...@alumni.rice.edu">Paul Holser</a> - */ -public class ReflectionException extends RuntimeException { - private static final long serialVersionUID = -2L; - - ReflectionException( Throwable cause ) { - super( cause.toString() ); - } -} http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/7115ab79/geode-joptsimple/src/main/java/joptsimple/internal/Strings.java ---------------------------------------------------------------------- diff --git a/geode-joptsimple/src/main/java/joptsimple/internal/Strings.java b/geode-joptsimple/src/main/java/joptsimple/internal/Strings.java deleted file mode 100644 index 8e6e910..0000000 --- a/geode-joptsimple/src/main/java/joptsimple/internal/Strings.java +++ /dev/null @@ -1,117 +0,0 @@ -/* - The MIT License - - Copyright (c) 2004-2011 Paul R. Holser, Jr. - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be - included in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ - -package joptsimple.internal; - -import java.util.Iterator; -import java.util.List; - -import static java.lang.System.*; -import static java.util.Arrays.*; - -/** - * @author <a href="mailto:phol...@alumni.rice.edu">Paul Holser</a> - */ -public final class Strings { - public static final String EMPTY = ""; - public static final String SINGLE_QUOTE = "'"; - public static final String LINE_SEPARATOR = getProperty( "line.separator" ); - - private Strings() { - throw new UnsupportedOperationException(); - } - - /** - * Gives a string consisting of the given character repeated the given number of times. - * - * @param ch the character to repeat - * @param count how many times to repeat the character - * @return the resultant string - */ - public static String repeat( char ch, int count ) { - StringBuilder buffer = new StringBuilder(); - - for ( int i = 0; i < count; ++i ) - buffer.append( ch ); - - return buffer.toString(); - } - - /** - * Tells whether the given string is either {@code} or consists solely of whitespace characters. - * - * @param target string to check - * @return {@code true} if the target string is null or empty - */ - public static boolean isNullOrEmpty( String target ) { - return target == null || EMPTY.equals( target ); - } - - - /** - * Gives a string consisting of a given string prepended and appended with surrounding characters. - * - * @param target a string - * @param begin character to prepend - * @param end character to append - * @return the surrounded string - */ - public static String surround( String target, char begin, char end ) { - return begin + target + end; - } - - /** - * Gives a string consisting of the elements of a given array of strings, each separated by a given separator - * string. - * - * @param pieces the strings to join - * @param separator the separator - * @return the joined string - */ - public static String join( String[] pieces, String separator ) { - return join( asList( pieces ), separator ); - } - - /** - * Gives a string consisting of the string representations of the elements of a given array of objects, - * each separated by a given separator string. - * - * @param pieces the elements whose string representations are to be joined - * @param separator the separator - * @return the joined string - */ - public static String join( List<String> pieces, String separator ) { - StringBuilder buffer = new StringBuilder(); - - for ( Iterator<String> iter = pieces.iterator(); iter.hasNext(); ) { - buffer.append( iter.next() ); - - if ( iter.hasNext() ) - buffer.append( separator ); - } - - return buffer.toString(); - } -} http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/7115ab79/geode-joptsimple/src/main/java/joptsimple/util/DateConverter.java ---------------------------------------------------------------------- diff --git a/geode-joptsimple/src/main/java/joptsimple/util/DateConverter.java b/geode-joptsimple/src/main/java/joptsimple/util/DateConverter.java deleted file mode 100644 index 9b4c7b1..0000000 --- a/geode-joptsimple/src/main/java/joptsimple/util/DateConverter.java +++ /dev/null @@ -1,104 +0,0 @@ -/* - The MIT License - - Copyright (c) 2004-2011 Paul R. Holser, Jr. - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be - included in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ - -package joptsimple.util; - -import java.text.DateFormat; -import java.text.ParsePosition; -import java.text.SimpleDateFormat; -import java.util.Date; - -import joptsimple.ValueConversionException; -import joptsimple.ValueConverter; - - -/** - * Converts values to {@link Date}s using a {@link DateFormat} object. - * - * @author <a href="mailto:phol...@alumni.rice.edu">Paul Holser</a> - */ -public class DateConverter implements ValueConverter<Date> { - private final DateFormat formatter; - - /** - * Creates a converter that uses the given date formatter/parser. - * - * @param formatter the formatter/parser to use - * @throws NullPointerException if {@code formatter} is {@code null} - */ - public DateConverter( DateFormat formatter ) { - if ( formatter == null ) - throw new NullPointerException( "illegal null formatter" ); - - this.formatter = formatter; - } - - /** - * Creates a converter that uses a {@link SimpleDateFormat} with the given date/time pattern. The date formatter - * created is not {@link SimpleDateFormat#setLenient(boolean) lenient}. - * - * @param pattern expected date/time pattern - * @return the new converter - * @throws NullPointerException if {@code pattern} is {@code null} - * @throws IllegalArgumentException if {@code pattern} is invalid - */ - public static DateConverter datePattern( String pattern ) { - SimpleDateFormat formatter = new SimpleDateFormat( pattern ); - formatter.setLenient( false ); - - return new DateConverter( formatter ); - } - - /** {@inheritDoc} */ - public Date convert( String value ) { - ParsePosition position = new ParsePosition( 0 ); - - Date date = formatter.parse( value, position ); - if ( position.getIndex() != value.length() ) - throw new ValueConversionException( message( value ) ); - - return date; - } - - /** {@inheritDoc} */ - public Class<Date> valueType() { - return Date.class; - } - - /** {@inheritDoc} */ - public String valuePattern() { - return formatter instanceof SimpleDateFormat - ? ( (SimpleDateFormat) formatter ).toPattern() - : ""; - } - - private String message( String value ) { - String message = "Value [" + value + "] does not match date/time pattern"; - if ( formatter instanceof SimpleDateFormat ) - message += " [" + ( (SimpleDateFormat) formatter ).toPattern() + ']'; - - return message; - } -} http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/7115ab79/geode-joptsimple/src/main/java/joptsimple/util/KeyValuePair.java ---------------------------------------------------------------------- diff --git a/geode-joptsimple/src/main/java/joptsimple/util/KeyValuePair.java b/geode-joptsimple/src/main/java/joptsimple/util/KeyValuePair.java deleted file mode 100644 index 499a841..0000000 --- a/geode-joptsimple/src/main/java/joptsimple/util/KeyValuePair.java +++ /dev/null @@ -1,83 +0,0 @@ -/* - The MIT License - - Copyright (c) 2004-2011 Paul R. Holser, Jr. - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be - included in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ - -package joptsimple.util; - -import static joptsimple.internal.Strings.*; - -/** - * A simple string key/string value pair. - * - * <p>This is useful as an argument type for options whose values take on the form <kbd>key=value</kbd>, such as JVM - * command line system properties.</p> - * - * @author <a href="mailto:phol...@alumni.rice.edu">Paul Holser</a> - */ -public final class KeyValuePair { - public final String key; - public final String value; - - private KeyValuePair( String key, String value ) { - this.key = key; - this.value = value; - } - - /** - * Parses a string assumed to be of the form <kbd>key=value</kbd> into its parts. - * - * @param asString key-value string - * @return a key-value pair - * @throws NullPointerException if {@code stringRepresentation} is {@code null} - */ - public static KeyValuePair valueOf( String asString ) { - int equalsIndex = asString.indexOf( '=' ); - if ( equalsIndex == -1 ) - return new KeyValuePair( asString, EMPTY ); - - String aKey = asString.substring( 0, equalsIndex ); - String aValue = equalsIndex == asString.length() - 1 ? EMPTY : asString.substring( equalsIndex + 1 ); - - return new KeyValuePair( aKey, aValue ); - } - - @Override - public boolean equals( Object that ) { - if ( !( that instanceof KeyValuePair ) ) - return false; - - KeyValuePair other = (KeyValuePair) that; - return key.equals( other.key ) && value.equals( other.value ); - } - - @Override - public int hashCode() { - return key.hashCode() ^ value.hashCode(); - } - - @Override - public String toString() { - return key + '=' + value; - } -} http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/7115ab79/geode-joptsimple/src/main/java/joptsimple/util/RegexMatcher.java ---------------------------------------------------------------------- diff --git a/geode-joptsimple/src/main/java/joptsimple/util/RegexMatcher.java b/geode-joptsimple/src/main/java/joptsimple/util/RegexMatcher.java deleted file mode 100644 index 3ce159c..0000000 --- a/geode-joptsimple/src/main/java/joptsimple/util/RegexMatcher.java +++ /dev/null @@ -1,88 +0,0 @@ -/* - The MIT License - - Copyright (c) 2004-2011 Paul R. Holser, Jr. - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be - included in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ - -package joptsimple.util; - -import java.util.regex.Pattern; - -import joptsimple.ValueConversionException; -import joptsimple.ValueConverter; - -import static java.util.regex.Pattern.*; - - - -/** - * Ensures that values entirely match a regular expression. - * - * @author <a href="mailto:phol...@alumni.rice.edu">Paul Holser</a> - */ -public class RegexMatcher implements ValueConverter<String> { - private final Pattern pattern; - - /** - * Creates a matcher that uses the given regular expression, modified by the given flags. - * - * @param pattern the regular expression pattern - * @param flags modifying regex flags - * @throws IllegalArgumentException if bit values other than those corresponding to the defined match flags are - * set in {@code flags} - * @throws java.util.regex.PatternSyntaxException if the expression's syntax is invalid - */ - public RegexMatcher( String pattern, int flags ) { - this.pattern = compile( pattern, flags ); - } - - /** - * Gives a matcher that uses the given regular expression. - * - * @param pattern the regular expression pattern - * @return the new converter - * @throws java.util.regex.PatternSyntaxException if the expression's syntax is invalid - */ - public static ValueConverter<String> regex( String pattern ) { - return new RegexMatcher( pattern, 0 ); - } - - /** {@inheritDoc} */ - public String convert( String value ) { - if ( !pattern.matcher( value ).matches() ) { - throw new ValueConversionException( - "Value [" + value + "] did not match regex [" + pattern.pattern() + ']' ); - } - - return value; - } - - /** {@inheritDoc} */ - public Class<String> valueType() { - return String.class; - } - - /** {@inheritDoc} */ - public String valuePattern() { - return pattern.pattern(); - } -}