Fixed up most warnings in Core, such as missing @return text, unused functions and fields, superfluous generics.
Project: http://git-wip-us.apache.org/repos/asf/zest-qi4j/repo Commit: http://git-wip-us.apache.org/repos/asf/zest-qi4j/commit/74ee7036 Tree: http://git-wip-us.apache.org/repos/asf/zest-qi4j/tree/74ee7036 Diff: http://git-wip-us.apache.org/repos/asf/zest-qi4j/diff/74ee7036 Branch: refs/heads/develop Commit: 74ee703656f118d47eb519ee9b5bef532da8cdf8 Parents: 87c37d0 Author: Niclas Hedhman <[email protected]> Authored: Fri Apr 24 14:35:10 2015 +0800 Committer: Niclas Hedhman <[email protected]> Committed: Fri Apr 24 14:35:10 2015 +0800 ---------------------------------------------------------------------- .../java/org/qi4j/api/common/UseDefaults.java | 1 + .../qi4j/api/configuration/Configuration.java | 20 ++-- .../main/java/org/qi4j/api/util/Classes.java | 10 +- .../java/org/qi4j/functional/Functions.java | 41 ++++---- core/io/src/main/java/org/qi4j/io/Inputs.java | 85 ++++++++--------- core/io/src/main/java/org/qi4j/io/Outputs.java | 98 +++++++++++++------- .../src/main/java/org/qi4j/io/Transforms.java | 86 +++++++++-------- .../org/qi4j/spi/entitystore/BackupRestore.java | 4 +- .../spi/value/ValueDeserializerAdapter.java | 14 +-- 9 files changed, 203 insertions(+), 156 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/zest-qi4j/blob/74ee7036/core/api/src/main/java/org/qi4j/api/common/UseDefaults.java ---------------------------------------------------------------------- diff --git a/core/api/src/main/java/org/qi4j/api/common/UseDefaults.java b/core/api/src/main/java/org/qi4j/api/common/UseDefaults.java index 0f61ea1..8478d99 100644 --- a/core/api/src/main/java/org/qi4j/api/common/UseDefaults.java +++ b/core/api/src/main/java/org/qi4j/api/common/UseDefaults.java @@ -69,6 +69,7 @@ import java.lang.annotation.Target; * } * </code></pre> */ +@SuppressWarnings( "JavadocReference" ) @Retention( RetentionPolicy.RUNTIME ) @Target( { ElementType.METHOD, ElementType.FIELD } ) @Documented http://git-wip-us.apache.org/repos/asf/zest-qi4j/blob/74ee7036/core/api/src/main/java/org/qi4j/api/configuration/Configuration.java ---------------------------------------------------------------------- diff --git a/core/api/src/main/java/org/qi4j/api/configuration/Configuration.java b/core/api/src/main/java/org/qi4j/api/configuration/Configuration.java index 52ec60f..bb97640 100644 --- a/core/api/src/main/java/org/qi4j/api/configuration/Configuration.java +++ b/core/api/src/main/java/org/qi4j/api/configuration/Configuration.java @@ -109,6 +109,7 @@ import static org.qi4j.functional.Iterables.first; * </code></pre> * */ +@SuppressWarnings( "JavadocReference" ) @Mixins( Configuration.ConfigurationMixin.class ) public interface Configuration<T> { @@ -174,7 +175,7 @@ public interface Configuration<T> uow = module.newUnitOfWork( usecase ); try { - configuration = this.<T>findConfigurationInstanceFor( me, uow ); + configuration = this.findConfigurationInstanceFor( me, uow ); } catch( InstantiationException e ) { @@ -217,39 +218,38 @@ public interface Configuration<T> } @SuppressWarnings( "unchecked" ) - public <T> T findConfigurationInstanceFor( ServiceComposite serviceComposite, UnitOfWork uow ) + public <V> V findConfigurationInstanceFor( ServiceComposite serviceComposite, UnitOfWork uow ) throws InstantiationException { ServiceDescriptor serviceModel = api.serviceDescriptorFor( serviceComposite ); String identity = serviceComposite.identity().get(); - T configuration; + V configuration; try { - configuration = uow.get( serviceModel.<T>configurationType(), identity ); + configuration = uow.get( serviceModel.<V>configurationType(), identity ); uow.pause(); } catch( NoSuchEntityException | EntityTypeNotFoundException e ) { - return (T) initializeConfigurationInstance( serviceComposite, uow, serviceModel, identity ); + return (V) initializeConfigurationInstance( serviceComposite, uow, serviceModel, identity ); } return configuration; } @SuppressWarnings( "unchecked" ) - private <T> T initializeConfigurationInstance( ServiceComposite serviceComposite, + private <V> V initializeConfigurationInstance( ServiceComposite serviceComposite, UnitOfWork uow, ServiceDescriptor serviceModel, String identity ) throws InstantiationException { - T configuration; Module module = api.moduleOf( serviceComposite ); Usecase usecase = UsecaseBuilder.newUsecase( "Configuration:" + me.identity().get() ); UnitOfWork buildUow = module.newUnitOfWork( usecase ); - EntityBuilder<T> configBuilder = buildUow.newEntityBuilder( serviceModel.<T>configurationType(), identity ); + EntityBuilder<V> configBuilder = buildUow.newEntityBuilder( serviceModel.<V>configurationType(), identity ); // Check for defaults String s = identity + ".properties"; @@ -277,11 +277,11 @@ public interface Configuration<T> try { - configuration = configBuilder.newInstance(); + configBuilder.newInstance(); buildUow.complete(); // Try again - return (T) findConfigurationInstanceFor( serviceComposite, uow ); + return (V) findConfigurationInstanceFor( serviceComposite, uow ); } catch( Exception e1 ) { http://git-wip-us.apache.org/repos/asf/zest-qi4j/blob/74ee7036/core/api/src/main/java/org/qi4j/api/util/Classes.java ---------------------------------------------------------------------- diff --git a/core/api/src/main/java/org/qi4j/api/util/Classes.java b/core/api/src/main/java/org/qi4j/api/util/Classes.java index 9413f9e..34f4b05 100644 --- a/core/api/src/main/java/org/qi4j/api/util/Classes.java +++ b/core/api/src/main/java/org/qi4j/api/util/Classes.java @@ -97,6 +97,7 @@ public final class Classes * Return the same class if it's not a wrapper class. This can therefore safely be used on all types * to ensure that they are primitives if possible. */ + @SuppressWarnings( "UnusedDeclaration" ) private static final Function<Type, Type> PRIMITIVE_CLASS = new Function<Type, Type>() { @Override @@ -411,6 +412,7 @@ public final class Classes } } + @SuppressWarnings( "UnusedDeclaration" ) public static <AnnotationType extends Annotation> AnnotationType findAnnotationOfTypeOrAnyOfSuperTypes( Class<?> type, Class<AnnotationType> annotationClass ) { @@ -443,11 +445,11 @@ public final class Classes * Given a type variable, find what it resolves to given the declaring class where type * variable was found and a top class that extends the declaring class. * - * @param name - * @param declaringClass - * @param topClass + * @param name The TypeVariable name. + * @param declaringClass The class where the TypeVariable is declared. + * @param topClass The top class that extends the declaringClass * - * @return + * @return The Type instance of the given TypeVariable */ @SuppressWarnings( "raw" ) public static Type resolveTypeVariable( TypeVariable name, Class declaringClass, Class topClass ) http://git-wip-us.apache.org/repos/asf/zest-qi4j/blob/74ee7036/core/functional/src/main/java/org/qi4j/functional/Functions.java ---------------------------------------------------------------------- diff --git a/core/functional/src/main/java/org/qi4j/functional/Functions.java b/core/functional/src/main/java/org/qi4j/functional/Functions.java index 0b50b35..bf86845 100644 --- a/core/functional/src/main/java/org/qi4j/functional/Functions.java +++ b/core/functional/src/main/java/org/qi4j/functional/Functions.java @@ -37,10 +37,10 @@ public final class Functions /** * compose(F1(M,T),F2(F,M)) = F1(F2(F)) -> T * - * @param outer - * @param inner + * @param outer The outer/encapsulating function + * @param inner The inner/encapsulated function * - * @return + * @return A function that is a composition of an outer and inner function. */ public static <FROM, MIDDLE, TO> Function<FROM, TO> compose( final Function<? super MIDDLE, TO> outer, final Function<FROM, MIDDLE> inner @@ -135,10 +135,10 @@ public final class Functions * Sample usage: last( map( count( in( "X" ) ), iterable( "X","Y","X","X","Y" ) ) ) * Returns: 3 * - * @param specification - * @param <T> + * @param specification The items that adhere to the Specification is counted. + * @param <T> The type of the items. * - * @return + * @return A Function that can count items adhering to a Specification. */ public static <T> Function<T, Integer> count( final Specification<T> specification ) { @@ -163,10 +163,11 @@ public final class Functions * Find out the index of an item matching a given specification in an iterable. * Returns -1 if it is not found. * - * @param specification - * @param <T> + * @param specification The Specification that specifies what to look for. + * @param <T> The type of the items. * - * @return + * @return A Function that will provide the 'index' where the Specifcation is fulfilled. The Function will + * return -1 if the current item doesn't fulfill the Specification. */ public static <T> Function<T, Integer> indexOf( final Specification<T> specification ) { @@ -193,11 +194,11 @@ public final class Functions /** * Find out the index of an item in an iterable. * - * @param item - * @param iterable - * @param <T> + * @param item The item to look for. + * @param iterable The Iterable to search. + * @param <T> The type of the items. * - * @return + * @return The index in the Iterable where the item is located. */ @SuppressWarnings( "unchecked" ) public static <T> int indexOf( T item, Iterable<T> iterable ) @@ -209,11 +210,11 @@ public final class Functions /** * Only apply given function on objects that satisfies the given specification. * - * @param specification - * @param function - * @param <T> + * @param specification A Specification that specifies what should be included in the filtered result. + * @param function The function to be applied to items that fulfills the Specification + * @param <T> The type of the items. * - * @return + * @return A Function that performs the filter operation when applied to Iterables. */ public static <T> Function<T, T> filteredMap( final Specification<T> specification, final Function<T, T> function ) { @@ -234,10 +235,10 @@ public final class Functions * This should be used if the function to generate the sort key from an object is expensive, so * that it is not done many times for each item in a list. * - * @param comparableFunction - * @param <T> + * @param comparableFunction The Function that the Comparator will delegate to. + * @param <T> The generic type to be used. * - * @return + * @return A comparator that uses a Function for the compare operation. */ @SuppressWarnings( "raw" ) public static <T> Comparator<T> comparator( final Function<T, Comparable> comparableFunction ) http://git-wip-us.apache.org/repos/asf/zest-qi4j/blob/74ee7036/core/io/src/main/java/org/qi4j/io/Inputs.java ---------------------------------------------------------------------- diff --git a/core/io/src/main/java/org/qi4j/io/Inputs.java b/core/io/src/main/java/org/qi4j/io/Inputs.java index fd298b8..eb2001f 100644 --- a/core/io/src/main/java/org/qi4j/io/Inputs.java +++ b/core/io/src/main/java/org/qi4j/io/Inputs.java @@ -57,8 +57,8 @@ public class Inputs output.receiveFrom( new Sender<String, RuntimeException>() { @Override - public <ReceiverThrowableType extends Throwable> void sendTo( Receiver<? super String, ReceiverThrowableType> receiver ) - throws ReceiverThrowableType, RuntimeException + public <Receiver2ThrowableType extends Throwable> void sendTo( Receiver<? super String, Receiver2ThrowableType> receiver ) + throws Receiver2ThrowableType, RuntimeException { Scanner scanner = new Scanner( source ); while( scanner.hasNextLine() ) @@ -93,8 +93,8 @@ public class Inputs output.receiveFrom( new Sender<String, RuntimeException>() { @Override - public <ReceiverThrowableType extends Throwable> void sendTo( Receiver<? super String, ReceiverThrowableType> receiver ) - throws ReceiverThrowableType, RuntimeException + public <Receiver2ThrowableType extends Throwable> void sendTo( Receiver<? super String, Receiver2ThrowableType> receiver ) + throws Receiver2ThrowableType, RuntimeException { Scanner scanner = new Scanner( source ); while( scanner.hasNextLine() ) @@ -153,13 +153,13 @@ public class Inputs stream = new GZIPInputStream( stream ); } - try( BufferedReader reader = new BufferedReader( new InputStreamReader( stream, encoding ) ) ) + try (BufferedReader reader = new BufferedReader( new InputStreamReader( stream, encoding ) )) { output.receiveFrom( new Sender<String, IOException>() { @Override - public <ReceiverThrowableType extends Throwable> void sendTo( Receiver<? super String, ReceiverThrowableType> receiver ) - throws ReceiverThrowableType, IOException + public <Receiver2ThrowableType extends Throwable> void sendTo( Receiver<? super String, Receiver2ThrowableType> receiver ) + throws Receiver2ThrowableType, IOException { String line; while( ( line = reader.readLine() ) != null ) @@ -208,18 +208,18 @@ public class Inputs // Figure out charset given content-type String contentType = urlConnection.getContentType(); String charSet = "UTF-8"; - if( contentType.indexOf( "charset=" ) != -1 ) + if( contentType.contains( "charset=" ) ) { charSet = contentType.substring( contentType.indexOf( "charset=" ) + "charset=".length() ); } - try( BufferedReader reader = new BufferedReader( new InputStreamReader( stream, charSet ) ) ) + try (BufferedReader reader = new BufferedReader( new InputStreamReader( stream, charSet ) )) { output.receiveFrom( new Sender<String, IOException>() { @Override - public <ReceiverThrowableType extends Throwable> void sendTo( Receiver<? super String, ReceiverThrowableType> receiver ) - throws ReceiverThrowableType, IOException + public <Receiver2ThrowableType extends Throwable> void sendTo( Receiver<? super String, Receiver2ThrowableType> receiver ) + throws Receiver2ThrowableType, IOException { String line; while( ( line = reader.readLine() ) != null ) @@ -238,10 +238,10 @@ public class Inputs /** * Read a file using ByteBuffer of a given size. Useful for transferring raw data. * - * @param source - * @param bufferSize + * @param source The file to be read. + * @param bufferSize The size of the byte array. * - * @return + * @return An Input instance to be applied to streaming operations. */ public static Input<ByteBuffer, IOException> byteBuffer( final File source, final int bufferSize ) // END SNIPPET: method @@ -262,8 +262,8 @@ public class Inputs output.receiveFrom( new Sender<ByteBuffer, IOException>() { @Override - public <ReceiverThrowableType extends Throwable> void sendTo( Receiver<? super ByteBuffer, ReceiverThrowableType> receiver ) - throws ReceiverThrowableType, IOException + public <Receiver2ThrowableType extends Throwable> void sendTo( Receiver<? super ByteBuffer, Receiver2ThrowableType> receiver ) + throws Receiver2ThrowableType, IOException { while( fci.read( buffer ) != -1 ) { @@ -287,10 +287,10 @@ public class Inputs /** * Read an inputstream using ByteBuffer of a given size. * - * @param source - * @param bufferSize + * @param source The InputStream to be read. + * @param bufferSize The size of the byte array. * - * @return + * @return An Input instance to be applied to streaming operations. */ public static Input<ByteBuffer, IOException> byteBuffer( final InputStream source, final int bufferSize ) // END SNIPPET: method @@ -306,8 +306,8 @@ public class Inputs output.receiveFrom( new Sender<ByteBuffer, IOException>() { @Override - public <ReceiverThrowableType extends Throwable> void sendTo( Receiver<? super ByteBuffer, ReceiverThrowableType> receiver ) - throws ReceiverThrowableType, IOException + public <Receiver2ThrowableType extends Throwable> void sendTo( Receiver<? super ByteBuffer, Receiver2ThrowableType> receiver ) + throws Receiver2ThrowableType, IOException { byte[] buffer = new byte[ bufferSize ]; @@ -334,11 +334,11 @@ public class Inputs * Combine many Input into one single Input. When a transfer is initiated from it all items from all inputs will be transferred * to the given Output. * - * @param inputs - * @param <T> - * @param <SenderThrowableType> + * @param inputs An Iterable of Input instances to be combined. + * @param <T> The item type of the Input + * @param <SenderThrowableType> The Throwable that might be thrown by the Inputs. * - * @return + * @return A combined Input, allowing for easy aggregation of many Input sources. */ public static <T, SenderThrowableType extends Throwable> Input<T, SenderThrowableType> combine( final Iterable<Input<T, SenderThrowableType>> inputs ) // END SNIPPET: method @@ -346,8 +346,8 @@ public class Inputs return new Input<T, SenderThrowableType>() { @Override - public <ReceiverThrowableType extends Throwable> void transferTo( Output<? super T, ReceiverThrowableType> output ) - throws SenderThrowableType, ReceiverThrowableType + public <Receiver2ThrowableType extends Throwable> void transferTo( Output<? super T, Receiver2ThrowableType> output ) + throws SenderThrowableType, Receiver2ThrowableType { output.receiveFrom( new Sender<T, SenderThrowableType>() { @@ -360,8 +360,8 @@ public class Inputs input.transferTo( new Output<T, ReceiverThrowableType>() { @Override - public <SenderThrowableType extends Throwable> void receiveFrom( Sender<? extends T, SenderThrowableType> sender ) - throws ReceiverThrowableType, SenderThrowableType + public <Sender2ThrowableType extends Throwable> void receiveFrom( Sender<? extends T, Sender2ThrowableType> sender ) + throws ReceiverThrowableType, Sender2ThrowableType { sender.sendTo( new Receiver<T, ReceiverThrowableType>() { @@ -386,10 +386,10 @@ public class Inputs /** * Create an Input that takes its items from the given Iterable. * - * @param iterable - * @param <T> + * @param iterable The Iterable to be used as an Input. + * @param <T> The item type of the Input * - * @return + * @return An Input instance that is backed by the Iterable. */ public static <T> Input<T, RuntimeException> iterable( final Iterable<T> iterable ) // END SNIPPET: method @@ -403,8 +403,8 @@ public class Inputs output.receiveFrom( new Sender<T, RuntimeException>() { @Override - public <ReceiverThrowableType extends Throwable> void sendTo( Receiver<? super T, ReceiverThrowableType> receiver ) - throws ReceiverThrowableType, RuntimeException + public <Receiver2ThrowableType extends Throwable> void sendTo( Receiver<? super T, Receiver2ThrowableType> receiver ) + throws Receiver2ThrowableType, RuntimeException { for( T item : iterable ) { @@ -423,10 +423,10 @@ public class Inputs * data has been gathered it will send this in chunks of the given size to the Output it is transferred to. The Visitor does not have to call * close() on the OutputStream, but should ensure that any wrapper streams or writers are flushed so that all data is sent. * - * @param outputVisitor - * @param bufferSize + * @param outputVisitor The OutputStream Visitor that will be backing the Input ByteBuffer. + * @param bufferSize The buffering size. * - * @return + * @return An Input instance of ByteBuffer, that is backed by an Visitor to an OutputStream. */ public static Input<ByteBuffer, IOException> output( final Visitor<OutputStream, IOException> outputVisitor, final int bufferSize @@ -443,10 +443,10 @@ public class Inputs { @Override @SuppressWarnings( "unchecked" ) - public <ReceiverThrowableType extends Throwable> void sendTo( final Receiver<? super ByteBuffer, ReceiverThrowableType> receiver ) - throws ReceiverThrowableType, IOException + public <Receiver2ThrowableType extends Throwable> void sendTo( final Receiver<? super ByteBuffer, Receiver2ThrowableType> receiver ) + throws Receiver2ThrowableType, IOException { - try( OutputStream out = new BufferedOutputStream( new OutputStream() + try (OutputStream out = new BufferedOutputStream( new OutputStream() { @Override public void write( int b ) @@ -455,6 +455,7 @@ public class Inputs // Ignore } + @SuppressWarnings( "NullableProblems" ) @Override public void write( byte[] b, int off, int len ) throws IOException @@ -469,13 +470,13 @@ public class Inputs throw new IOException( ex ); } } - }, bufferSize ) ) + }, bufferSize )) { outputVisitor.visit( out ); } catch( IOException ex ) { - throw (ReceiverThrowableType) ex.getCause(); + throw (Receiver2ThrowableType) ex.getCause(); } } } ); http://git-wip-us.apache.org/repos/asf/zest-qi4j/blob/74ee7036/core/io/src/main/java/org/qi4j/io/Outputs.java ---------------------------------------------------------------------- diff --git a/core/io/src/main/java/org/qi4j/io/Outputs.java b/core/io/src/main/java/org/qi4j/io/Outputs.java index f3fd92f..2508788 100644 --- a/core/io/src/main/java/org/qi4j/io/Outputs.java +++ b/core/io/src/main/java/org/qi4j/io/Outputs.java @@ -99,21 +99,32 @@ public class Outputs // Replace file with temporary file if( !file.exists() || file.delete() ) { - tmpFile.renameTo( file ); + if( ! tmpFile.renameTo( file ) ) + { + // TODO: What?? Throw an Exception? + System.err.println( "Unable to rename file: " + tmpFile + " to " + file ); + } } } catch( IOException e ) { // We failed writing - close and delete writer.close(); - tmpFile.delete(); + if( ! tmpFile.delete() ) + { + System.err.println("Unable to delete temporary file." ); + tmpFile.deleteOnExit(); + } } catch( Throwable senderThrowableType ) { // We failed writing - close and delete writer.close(); - tmpFile.delete(); - + if( ! tmpFile.delete() ) + { + System.err.println("Unable to delete temporary file." ); + tmpFile.deleteOnExit(); + } throw (SenderThrowableType) senderThrowableType; } } @@ -193,12 +204,11 @@ public class Outputs /** * Write ByteBuffer data to a file. If the writing or sending of data fails the file will be deleted. * - * @param file - * @param <T> + * @param file The destination file. * - * @return + * @return The Output ByteBuffer instance backed by a File. */ - public static <T> Output<ByteBuffer, IOException> byteBuffer( final File file ) + public static Output<ByteBuffer, IOException> byteBuffer( final File file ) // END SNIPPET: method { return new Output<ByteBuffer, IOException>() @@ -228,21 +238,33 @@ public class Outputs // Replace file with temporary file if( !file.exists() || file.delete() ) { - tmpFile.renameTo( file ); + if( ! tmpFile.renameTo( file ) ) + { + // TODO: What can be done in this case? + System.err.println( "Unable to rename file: " + tmpFile + " to " + file ); + } } } catch( IOException e ) { // We failed writing - close and delete stream.close(); - tmpFile.delete(); + if( ! tmpFile.delete() ) + { + System.err.println("Unable to delete temporary file." ); + tmpFile.deleteOnExit(); + } + } catch( Throwable senderThrowableType ) { // We failed writing - close and delete stream.close(); - tmpFile.delete(); - + if( ! tmpFile.delete() ) + { + System.err.println("Unable to delete temporary file." ); + tmpFile.deleteOnExit(); + } throw (SenderThrowableType) senderThrowableType; } } @@ -254,12 +276,11 @@ public class Outputs /** * Write ByteBuffer data to an OutputStream. * - * @param stream - * @param <T> + * @param stream Destination OutputStream * - * @return + * @return The Output of ByteBuffer that will be backed by the OutputStream. */ - public static <T> Output<ByteBuffer, IOException> byteBuffer( final OutputStream stream ) + public static Output<ByteBuffer, IOException> byteBuffer( final OutputStream stream ) // END SNIPPET: method { return new Output<ByteBuffer, IOException>() @@ -303,13 +324,12 @@ public class Outputs /** * Write byte array data to a file. If the writing or sending of data fails the file will be deleted. * - * @param file - * @param bufferSize - * @param <T> + * @param file The File to be written to. + * @param bufferSize The size of the ByteBuffer. * - * @return + * @return An Output instance that will write to the given File. */ - public static <T> Output<byte[], IOException> bytes( final File file, final int bufferSize ) + public static Output<byte[], IOException> bytes( final File file, final int bufferSize ) // END SNIPPET: method { return new Output<byte[], IOException>() @@ -338,21 +358,32 @@ public class Outputs // Replace file with temporary file if( !file.exists() || file.delete() ) { - tmpFile.renameTo( file ); + if( ! tmpFile.renameTo( file ) ) + { + // TODO: WHAT??? + System.err.println( "Unable to rename " + tmpFile + " to " + file ); + } } } catch( IOException e ) { // We failed writing - close and delete stream.close(); - file.delete(); + if( ! tmpFile.delete() ) + { + System.err.println("Unable to delete temporary file." ); + tmpFile.deleteOnExit(); + } } catch( Throwable senderThrowableType ) { // We failed writing - close and delete stream.close(); - file.delete(); - + if( ! tmpFile.delete() ) + { + System.err.println("Unable to delete temporary file." ); + tmpFile.deleteOnExit(); + } throw (SenderThrowableType) senderThrowableType; } } @@ -364,9 +395,9 @@ public class Outputs /** * Do nothing. Use this if you have all logic in filters and/or specifications * - * @param <T> + * @param <T> The item type. * - * @return + * @return An Output instance that ignores all data. */ public static <T> Output<T, RuntimeException> noop() // END SNIPPET: method @@ -388,10 +419,10 @@ public class Outputs * Use given receiver as Output. Use this if there is no need to create a "transaction" for each transfer, and no need * to do batch writes or similar. * - * @param <T> + * @param <T> The item type * @param receiver receiver for this Output * - * @return + * @return An Output instance backed by a Receiver of items. */ public static <T, ReceiverThrowableType extends Throwable> Output<T, ReceiverThrowableType> withReceiver( final Receiver<T, ReceiverThrowableType> receiver ) // END SNIPPET: method @@ -412,7 +443,7 @@ public class Outputs /** * Write objects to System.out.println. * - * @return + * @return An Output instance that is backed by System.out */ public static Output<Object, RuntimeException> systemOut() // END SNIPPET: method @@ -420,7 +451,7 @@ public class Outputs return new Output<Object, RuntimeException>() { @Override - public <SenderThrowableType extends Throwable> void receiveFrom( Sender<? extends Object, SenderThrowableType> sender ) + public <SenderThrowableType extends Throwable> void receiveFrom( Sender<?, SenderThrowableType> sender ) throws RuntimeException, SenderThrowableType { sender.sendTo( new Receiver<Object, RuntimeException>() @@ -439,14 +470,17 @@ public class Outputs /** * Write objects to System.err.println. + * + * @return An Output instance backed by System.in */ + @SuppressWarnings( "UnusedDeclaration" ) public static Output<Object, RuntimeException> systemErr() // END SNIPPET: method { return new Output<Object, RuntimeException>() { @Override - public <SenderThrowableType extends Throwable> void receiveFrom( Sender<? extends Object, SenderThrowableType> sender ) + public <SenderThrowableType extends Throwable> void receiveFrom( Sender<?, SenderThrowableType> sender ) throws RuntimeException, SenderThrowableType { sender.sendTo( new Receiver<Object, RuntimeException>() http://git-wip-us.apache.org/repos/asf/zest-qi4j/blob/74ee7036/core/io/src/main/java/org/qi4j/io/Transforms.java ---------------------------------------------------------------------- diff --git a/core/io/src/main/java/org/qi4j/io/Transforms.java b/core/io/src/main/java/org/qi4j/io/Transforms.java index c7bcb7d..71b94a8 100644 --- a/core/io/src/main/java/org/qi4j/io/Transforms.java +++ b/core/io/src/main/java/org/qi4j/io/Transforms.java @@ -31,22 +31,22 @@ public class Transforms /** * Filter items in a transfer by applying the given Specification to each item. * - * @param specification - * @param output - * @param <T> - * @param <ReceiverThrowableType> + * @param specification The Specification defining the items to not filter away. + * @param output The Output instance to receive to result. + * @param <T> The item type + * @param <Receiver2ThrowableType> Exception type that might be thrown by the Receiver. * - * @return + * @return And Output encapsulation the filter operation. */ - public static <T, ReceiverThrowableType extends Throwable> Output<T, ReceiverThrowableType> filter( final Specification<? super T> specification, - final Output<T, ReceiverThrowableType> output + public static <T, Receiver2ThrowableType extends Throwable> Output<T, Receiver2ThrowableType> filter( final Specification<? super T> specification, + final Output<T, Receiver2ThrowableType> output ) { - return new Output<T, ReceiverThrowableType>() + return new Output<T, Receiver2ThrowableType>() { @Override public <SenderThrowableType extends Throwable> void receiveFrom( final Sender<? extends T, SenderThrowableType> sender ) - throws ReceiverThrowableType, SenderThrowableType + throws Receiver2ThrowableType, SenderThrowableType { output.receiveFrom( new Sender<T, SenderThrowableType>() { @@ -75,23 +75,23 @@ public class Transforms /** * Map items in a transfer from one type to another by applying the given function. * - * @param function - * @param output - * @param <From> - * @param <To> - * @param <ReceiverThrowableType> + * @param function The transformation function to apply to the streaming items. + * @param output The output to receive the transformed items. + * @param <From> The type of the incoming items. + * @param <To> The type of the transformed items. + * @param <Receiver2ThrowableType> The exception type that the Receiver might throw. * - * @return + * @return An Output instance that encapsulates the map transformation. */ - public static <From, To, ReceiverThrowableType extends Throwable> Output<From, ReceiverThrowableType> map( final Function<? super From, ? extends To> function, - final Output<To, ReceiverThrowableType> output + public static <From, To, Receiver2ThrowableType extends Throwable> Output<From, Receiver2ThrowableType> map( final Function<? super From, ? extends To> function, + final Output<To, Receiver2ThrowableType> output ) { - return new Output<From, ReceiverThrowableType>() + return new Output<From, Receiver2ThrowableType>() { @Override public <SenderThrowableType extends Throwable> void receiveFrom( final Sender<? extends From, SenderThrowableType> sender ) - throws ReceiverThrowableType, SenderThrowableType + throws Receiver2ThrowableType, SenderThrowableType { output.receiveFrom( new Sender<To, SenderThrowableType>() { @@ -118,24 +118,24 @@ public class Transforms * Apply the given function to items in the transfer that match the given specification. Other items will pass * through directly. * - * @param specification - * @param function - * @param output - * @param <T> - * @param <ReceiverThrowableType> + * @param specification The Specification defining which items should be transformed. + * @param function The transformation function. + * @param output The Output that will receive the resulting items. + * @param <T> The item type. Items can not be transformed to a new type. + * @param <Receiver2ThrowableType> The exception that the Receiver might throw. * - * @return + * @return An Output instance that encapsulates the operation. */ - public static <T, ReceiverThrowableType extends Throwable> Output<T, ReceiverThrowableType> filteredMap( final Specification<? super T> specification, - final Function<? super T, ? extends T> function, - final Output<T, ReceiverThrowableType> output + public static <T, Receiver2ThrowableType extends Throwable> Output<T, Receiver2ThrowableType> filteredMap( final Specification<? super T> specification, + final Function<? super T, ? extends T> function, + final Output<T, Receiver2ThrowableType> output ) { - return new Output<T, ReceiverThrowableType>() + return new Output<T, Receiver2ThrowableType>() { @Override public <SenderThrowableType extends Throwable> void receiveFrom( final Sender<? extends T, SenderThrowableType> sender ) - throws ReceiverThrowableType, SenderThrowableType + throws Receiver2ThrowableType, SenderThrowableType { output.receiveFrom( new Sender<T, SenderThrowableType>() { @@ -172,20 +172,20 @@ public class Transforms * * @param lock the lock to be used for transfers * @param output output to be wrapped - * @param <T> - * @param <ReceiverThrowableType> + * @param <T> The Item type + * @param <Receiver2ThrowableType> The Exception type that the Receiver might throw. * * @return Output wrapper that uses the given lock during transfers. */ - public static <T, ReceiverThrowableType extends Throwable> Output<T, ReceiverThrowableType> lock( final Lock lock, - final Output<T, ReceiverThrowableType> output + public static <T, Receiver2ThrowableType extends Throwable> Output<T, Receiver2ThrowableType> lock( final Lock lock, + final Output<T, Receiver2ThrowableType> output ) { - return new Output<T, ReceiverThrowableType>() + return new Output<T, Receiver2ThrowableType>() { @Override public <SenderThrowableType extends Throwable> void receiveFrom( Sender<? extends T, SenderThrowableType> sender ) - throws ReceiverThrowableType, SenderThrowableType + throws Receiver2ThrowableType, SenderThrowableType { /** * Fix for this bug: @@ -195,6 +195,7 @@ public class Transforms { try { + //noinspection StatementWithEmptyBody while( !lock.tryLock( 1000, TimeUnit.MILLISECONDS ) ) { // On timeout, try again @@ -225,8 +226,8 @@ public class Transforms * * @param lock the lock to be used for transfers * @param input input to be wrapped - * @param <T> - * @param <SenderThrowableType> + * @param <T> The item type. + * @param <SenderThrowableType> The Exception type that the Sender might throw. * * @return Input wrapper that uses the given lock during transfers. */ @@ -248,6 +249,7 @@ public class Transforms { try { + //noinspection StatementWithEmptyBody while( !( lock.tryLock() || lock.tryLock( 1000, TimeUnit.MILLISECONDS ) ) ) { // On timeout, try again @@ -300,6 +302,7 @@ public class Transforms /** * Convert strings to bytes using the given CharSet */ + @SuppressWarnings( "UnusedDeclaration" ) public static class String2Bytes implements Function<String, byte[]> { @@ -340,6 +343,7 @@ public class Transforms /** * Convert objects to Strings using .toString() */ + @SuppressWarnings( "UnusedDeclaration" ) public static class ObjectToString implements Function<Object, String> { @@ -396,15 +400,15 @@ public class Transforms this.interval = interval; if( logger != null && format != null ) { - log = new Log<String>( logger, format ); + log = new Log<>( logger, format ); } - counter = new Counter<T>(); + counter = new Counter<>(); } public ProgressLog( long interval ) { this.interval = interval; - counter = new Counter<T>(); + counter = new Counter<>(); } @Override http://git-wip-us.apache.org/repos/asf/zest-qi4j/blob/74ee7036/core/spi/src/main/java/org/qi4j/spi/entitystore/BackupRestore.java ---------------------------------------------------------------------- diff --git a/core/spi/src/main/java/org/qi4j/spi/entitystore/BackupRestore.java b/core/spi/src/main/java/org/qi4j/spi/entitystore/BackupRestore.java index d7d32cc..f777f45 100644 --- a/core/spi/src/main/java/org/qi4j/spi/entitystore/BackupRestore.java +++ b/core/spi/src/main/java/org/qi4j/spi/entitystore/BackupRestore.java @@ -27,12 +27,14 @@ public interface BackupRestore /** * Input that allows data from the entity store to be backed up. * - * @return + * @return An Input instance containing the data to back up. */ Input<String, IOException> backup(); /** * Output that allows data to be restored from a backup. + * + * @return An Output instance to receive the restored data. */ Output<String, IOException> restore(); } \ No newline at end of file http://git-wip-us.apache.org/repos/asf/zest-qi4j/blob/74ee7036/core/spi/src/main/java/org/qi4j/spi/value/ValueDeserializerAdapter.java ---------------------------------------------------------------------- diff --git a/core/spi/src/main/java/org/qi4j/spi/value/ValueDeserializerAdapter.java b/core/spi/src/main/java/org/qi4j/spi/value/ValueDeserializerAdapter.java index 73056fe..37738f8 100644 --- a/core/spi/src/main/java/org/qi4j/spi/value/ValueDeserializerAdapter.java +++ b/core/spi/src/main/java/org/qi4j/spi/value/ValueDeserializerAdapter.java @@ -130,7 +130,7 @@ public abstract class ValueDeserializerAdapter<InputType, InputNodeType> deserializers.put( type, (Function<Object, Object>) deserializer ); } - @SuppressWarnings( "unchecked" ) + @SuppressWarnings( { "UnusedDeclaration", "unchecked" } ) protected final <T> void registerComplexDeserializer( Class<T> type, ComplexDeserializer<T, InputType, InputNodeType> deserializer ) { @@ -173,6 +173,7 @@ public abstract class ValueDeserializerAdapter<InputType, InputNodeType> } ); registerDeserializer( Boolean.class, new Function<Object, Boolean>() { + @SuppressWarnings( "UnnecessaryUnboxing" ) @Override public Boolean map( Object input ) { @@ -608,7 +609,7 @@ public abstract class ValueDeserializerAdapter<InputType, InputNodeType> { ValueCompositeType valueCompositeType = (ValueCompositeType) valueType; Class<?> valueBuilderType = first( valueCompositeType.types() ); - String typeInfo = this.<String>getObjectFieldValue( + String typeInfo = this.getObjectFieldValue( inputNode, "_type", this.<String>buildDeserializeInputNodeFunction( new ValueType( String.class ) ) ); @@ -786,7 +787,7 @@ public abstract class ValueDeserializerAdapter<InputType, InputNodeType> else // Explicit ValueComposite if( ValueCompositeType.class.isAssignableFrom( valueType.getClass() ) ) { - return (T) deserializeNodeValueComposite( (ValueCompositeType) valueType, inputNode ); + return (T) deserializeNodeValueComposite( valueType, inputNode ); } else // Explicit Collections if( CollectionType.class.isAssignableFrom( valueType.getClass() ) ) @@ -904,7 +905,7 @@ public abstract class ValueDeserializerAdapter<InputType, InputNodeType> private <K, V> Map<K, V> deserializeNodeMap( MapType mapType, InputNodeType inputNode ) throws Exception { - Map<K, V> map = new HashMap<K, V>(); + Map<K, V> map = new HashMap<>(); putArrayNodeInMap( inputNode, this.<K>buildDeserializeInputNodeFunction( mapType.keyType() ), this.<V>buildDeserializeInputNodeFunction( mapType.valueType() ), @@ -922,7 +923,7 @@ public abstract class ValueDeserializerAdapter<InputType, InputNodeType> ValueCompositeType valueCompositeType; if( objectHasField( inputNode, "_type" ) ) // with _type info { - String typeInfo = this.<String>getObjectFieldValue( + String typeInfo = this.getObjectFieldValue( inputNode, "_type", this.<String>buildDeserializeInputNodeFunction( new ValueType( String.class ) ) ); @@ -998,6 +999,7 @@ public abstract class ValueDeserializerAdapter<InputType, InputNodeType> * @param input Input * @throws Exception that will be wrapped in a {@link ValueSerializationException} */ + @SuppressWarnings( "UnusedParameters" ) protected void onDeserializationStart( ValueType valueType, InputType input ) throws Exception { @@ -1109,7 +1111,7 @@ public abstract class ValueDeserializerAdapter<InputType, InputNodeType> * @param inputNode Input Node * @param key Object key * @param valueDeserializer Deserialization function - * @return + * @return The value of the field. * @throws Exception that will be wrapped in a {@link ValueSerializationException} */ protected abstract <T> T getObjectFieldValue( InputNodeType inputNode,
