Ver Fonte

fix compatibility problems with generics

Ranides Atterwim há 6 anos atrás
pai
commit
11a9902b2b

+ 147 - 146
assira/pom.xml

@@ -1,147 +1,148 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
-    <modelVersion>4.0.0</modelVersion>
-    <parent>
-        <groupId>net.ranides</groupId>
-        <artifactId>assira.project</artifactId>
-        <version>2.1.0</version>
-        <relativePath>..</relativePath>
-    </parent>
-    <name>assira</name>
-    <groupId>net.ranides</groupId>
-    <artifactId>assira</artifactId>
-    <packaging>jar</packaging>
-	
-    <properties>
-        <assira.junit.debug>false</assira.junit.debug>
-    </properties>
-
-    <profiles>
-        <profile>
-            <id>recent-coverage</id>
-            <build>
-                <plugins>
-                    <plugin>
-                        <groupId>org.jacoco</groupId>
-                        <artifactId>jacoco-maven-plugin</artifactId>
-                        <version>0.7.5.201505241946</version>
-                        <configuration>
-                            <includes>
-                                <include>net/ranides/assira/annotations/Meta*</include>
-                                <include>net/ranides/assira/annotations/javac/**</include>
-                                
-                                <include>net/ranides/assira/awt/ImageLoader*</include>
-                                <include>net/ranides/assira/awt/AWTInvoker*</include>
-
-                                <include>net/ranides/assira/collection/arrays/NativeArrayAccess*</include>
-                                <include>net/ranides/assira/collection/arrays/NativeArrayUtils*</include>
-                                <include>net/ranides/assira/collection/arrays/ArrayUtils*</include>
-                                <include>net/ranides/assira/collection/sets/Bitmask*</include>
-                                <include>net/ranides/assira/collection/maps/Cache*</include>
-                                <include>net/ranides/assira/collection/maps/MapUtils*</include>
-                                <include>net/ranides/assira/collection/maps/IntMapUtils*</include>
-                                <include>net/ranides/assira/collection/maps/IntMapCollectors*</include>
-                                <include>net/ranides/assira/collection/maps/MapCollectors*</include>
-                                <include>net/ranides/assira/collection/maps/MultiMap*</include>
-                                <include>net/ranides/assira/collection/query/**</include>
-
-                                <include>net/ranides/assira/credentials/PWDBStore*</include>
-
-                                <include>net/ranides/assira/events/EventObserver*</include>
-                                
-                                <!-- <include>net/ranides/assira/io/PathUtils*</include>-->
-
-                                <include>net/ranides/assira/lexer/**</include>
-                                
-                                <include>net/ranides/assira/math/Bitwise*</include>
-                                
-                                <include>net/ranides/assira/text/LexicalCast*</include>
-
-                                <include>net/ranides/assira/xml/XMLQuery*</include>
-                                <include>net/ranides/assira/xml/XMLWriter*</include>
-                            </includes>
-                        </configuration>
-                    </plugin>
-                </plugins>
-            </build>
-        </profile>
-    </profiles>
-	
-    <build>
-        <plugins>
-            <plugin>
-                <groupId>org.apache.maven.plugins</groupId>
-                <artifactId>maven-surefire-plugin</artifactId>
-                <configuration>
-                    <excludedGroups>net.ranides.assira.junit.JCategories$Slow,net.ranides.assira.junit.JCategories$Unstable</excludedGroups>
-                </configuration>
-            </plugin>
-            <plugin>
-                <groupId>org.jacoco</groupId>
-                <artifactId>jacoco-maven-plugin</artifactId>
-                <version>0.7.5.201505241946</version>
-                <configuration>
-                    <excludes>
-                        <exclude>net/ranides/assira/test/**</exclude>
-                    </excludes>
-                </configuration>
-            </plugin>
-        </plugins>
-    </build>
-    
-    <dependencies>
-        <dependency>
-            <groupId>junit</groupId>
-            <artifactId>junit</artifactId>
-        </dependency>
-        <dependency>
-            <groupId>net.ranides</groupId>
-            <artifactId>assira.asm</artifactId>
-        </dependency>
-        <dependency>
-            <groupId>net.ranides</groupId>
-            <artifactId>assira.junit</artifactId>
-        </dependency>
-        <dependency>
-            <groupId>org.slf4j</groupId>
-            <artifactId>slf4j-api</artifactId>
-        </dependency>
-        <dependency>
-            <groupId>com.google.code.findbugs</groupId>
-            <artifactId>annotations</artifactId>
-        </dependency>
-        <dependency>
-            <groupId>com.fasterxml.jackson.core</groupId>
-            <artifactId>jackson-core</artifactId>
-        </dependency>
-        <dependency>
-            <groupId>com.fasterxml.jackson.datatype</groupId>
-            <artifactId>jackson-datatype-json-org</artifactId>
-        </dependency>
-        <dependency>
-            <groupId>se.fishtank</groupId>
-            <artifactId>css-selectors</artifactId>
-        </dependency>
-        <dependency>
-            <groupId>commons-net</groupId>
-            <artifactId>commons-net</artifactId>
-            <version>3.4</version>
-            <type>jar</type>
-        </dependency>
-        <dependency>
-            <groupId>org.linguafranca.pwdb</groupId>
-            <artifactId>KeePassJava2</artifactId>
-            <version>2.1.1</version>
-        </dependency>
-        <dependency>
-            <groupId>com.fasterxml.jackson.dataformat</groupId>
-            <artifactId>jackson-dataformat-xml</artifactId>
-            <version>2.9.4</version>
-        </dependency>
-        <dependency>
-            <groupId>org.projectlombok</groupId>
-            <artifactId>lombok</artifactId>
-            <version>1.16.20</version>
-        </dependency>
-    </dependencies>
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+    <parent>
+        <groupId>net.ranides</groupId>
+        <artifactId>assira.project</artifactId>
+        <version>2.1.0</version>
+        <relativePath>..</relativePath>
+    </parent>
+    <name>assira</name>
+    <groupId>net.ranides</groupId>
+    <artifactId>assira</artifactId>
+    <packaging>jar</packaging>
+	
+    <properties>
+        <assira.junit.debug>false</assira.junit.debug>
+    </properties>
+
+    <profiles>
+        <profile>
+            <id>recent-coverage</id>
+            <build>
+                <plugins>
+                    <plugin>
+                        <groupId>org.jacoco</groupId>
+                        <artifactId>jacoco-maven-plugin</artifactId>
+                        <version>0.7.5.201505241946</version>
+                        <configuration>
+                            <includes>
+                                <include>net/ranides/assira/annotations/Meta*</include>
+                                <include>net/ranides/assira/annotations/javac/**</include>
+                                
+                                <include>net/ranides/assira/awt/ImageLoader*</include>
+                                <include>net/ranides/assira/awt/AWTInvoker*</include>
+
+                                <include>net/ranides/assira/collection/arrays/NativeArrayAccess*</include>
+                                <include>net/ranides/assira/collection/arrays/NativeArrayUtils*</include>
+                                <include>net/ranides/assira/collection/arrays/ArrayUtils*</include>
+                                <include>net/ranides/assira/collection/sets/Bitmask*</include>
+                                <include>net/ranides/assira/collection/maps/Cache*</include>
+                                <include>net/ranides/assira/collection/maps/MapUtils*</include>
+                                <include>net/ranides/assira/collection/maps/IntMapUtils*</include>
+                                <include>net/ranides/assira/collection/maps/IntMapCollectors*</include>
+                                <include>net/ranides/assira/collection/maps/MapCollectors*</include>
+                                <include>net/ranides/assira/collection/maps/MultiMap*</include>
+                                <include>net/ranides/assira/collection/query/**</include>
+
+                                <include>net/ranides/assira/credentials/PWDBStore*</include>
+
+                                <include>net/ranides/assira/events/EventObserver*</include>
+                                
+                                <!-- <include>net/ranides/assira/io/PathUtils*</include>-->
+
+                                <include>net/ranides/assira/lexer/**</include>
+                                
+                                <include>net/ranides/assira/math/Bitwise*</include>
+                                
+                                <include>net/ranides/assira/text/LexicalCast*</include>
+
+                                <include>net/ranides/assira/xml/XMLQuery*</include>
+                                <include>net/ranides/assira/xml/XMLWriter*</include>
+                            </includes>
+                        </configuration>
+                    </plugin>
+                </plugins>
+            </build>
+        </profile>
+    </profiles>
+	
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-surefire-plugin</artifactId>
+                <configuration>
+                    <excludedGroups>net.ranides.assira.junit.JCategories$Slow,net.ranides.assira.junit.JCategories$Unstable</excludedGroups>
+                </configuration>
+            </plugin>
+            <plugin>
+                <groupId>org.jacoco</groupId>
+                <artifactId>jacoco-maven-plugin</artifactId>
+                <version>0.7.5.201505241946</version>
+                <configuration>
+                    <excludes>
+                        <exclude>net/ranides/assira/test/**</exclude>
+                    </excludes>
+                </configuration>
+            </plugin>
+        </plugins>
+    </build>
+    
+    <dependencies>
+        <dependency>
+            <groupId>junit</groupId>
+            <artifactId>junit</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>net.ranides</groupId>
+            <artifactId>assira.asm</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>net.ranides</groupId>
+            <artifactId>assira.junit</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.slf4j</groupId>
+            <artifactId>slf4j-api</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>com.google.code.findbugs</groupId>
+            <artifactId>annotations</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>com.fasterxml.jackson.core</groupId>
+            <artifactId>jackson-core</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>com.fasterxml.jackson.datatype</groupId>
+            <artifactId>jackson-datatype-json-org</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>se.fishtank</groupId>
+            <artifactId>css-selectors</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>commons-net</groupId>
+            <artifactId>commons-net</artifactId>
+            <version>3.4</version>
+            <type>jar</type>
+        </dependency>
+        <dependency>
+            <groupId>org.linguafranca.pwdb</groupId>
+            <artifactId>KeePassJava2</artifactId>
+            <version>2.1.1</version>
+        </dependency>
+        <dependency>
+            <groupId>com.fasterxml.jackson.dataformat</groupId>
+            <artifactId>jackson-dataformat-xml</artifactId>
+            <version>2.9.4</version>
+        </dependency>
+        <dependency>
+            <groupId>org.projectlombok</groupId>
+            <artifactId>lombok</artifactId>
+            <version>1.18.8</version>
+            <scope>provided</scope>
+        </dependency>
+    </dependencies>
 </project>

Diff do ficheiro suprimidas por serem muito extensas
+ 785 - 785
assira/src/main/java/net/ranides/assira/io/IOStreams.java


+ 161 - 161
assira/src/main/java/net/ranides/assira/io/IOUtils.java

@@ -1,161 +1,161 @@
-/*
- * @author Ranides Atterwim <ranides@gmail.com>
- * @copyright Ranides Atterwim
- * @license WTFPL
- * @url http://ranides.net/projects/assira
- */
-package net.ranides.assira.io;
-
-import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
-import java.io.Closeable;
-import java.io.IOException;
-import java.util.function.Consumer;
-import net.ranides.assira.events.EventListener;
-import net.ranides.assira.functional.CheckedConsumer;
-import net.ranides.assira.functional.CheckedSupplier;
-import net.ranides.assira.trace.ExceptionUtils;
-import net.ranides.assira.trace.LoggerUtils;
-
-/**
- *
- * @author Ranides Atterwim <ranides@gmail.com>
- */
-public final class IOUtils {
-    
-    private static final org.slf4j.Logger LOGGER = LoggerUtils.getLogger();
-    
-    private IOUtils() {
-        /* utility class */
-    }
-    
-    public static IOException wrap(Throwable cause) {
-        return (cause instanceof IOException) ? (IOException)cause : new IOException(cause);
-    }
-    
-    public static RuntimeException rethrow(Throwable cause) {
-        return ExceptionUtils.rethrow(wrap(cause));
-    }
-    
-    public static boolean close(Closeable object) throws IOException {
-        if(null != object) {
-            object.close();
-            return true;
-        }
-        return false;
-    }
-    
-    public static boolean close(Closeable object, EventListener<? super IOEvent.Failure> listener) {
-        try {
-            return close(object);
-        } catch(IOException cause) {
-            if(null != listener) {
-                listener.handleEvent(IOEvent.failure(cause));
-            } else {
-                LOGGER.warn("Exception ignored on #close", cause);
-            }
-            return false;
-        }
-    }
-    
-    public static boolean close(Object object) throws Exception {
-        if(object instanceof Closeable) {
-            ((Closeable)object).close();
-            return true;
-        }
-        if(object instanceof AutoCloseable) {
-            ((AutoCloseable)object).close();
-            return true;
-        }
-        return false;
-    }
-    
-    public static boolean close(Object object, Consumer<? super Exception> handler) {
-        try {
-            return close(object);
-        } catch(Exception cause) {
-            if(null != handler) {
-                handler.accept(cause);
-            } else {
-                LOGGER.warn("Exception ignored on #close", cause);
-            }
-            return false;
-        }
-    }
-    
-    @SuppressWarnings({"DoubleCheckedLocking"})
-    @SuppressFBWarnings({"DC_DOUBLECHECK","IS2_INCONSISTENT_SYNC"})
-    static final class SharedHandle<T> implements IOHandle<T> {
-        
-        private final CheckedSupplier<T,IOException> open;
-        
-        private final CheckedConsumer<T,IOException> close;
-
-        private SharedWrapper<T> ref = null;
-
-        SharedHandle(CheckedSupplier<T,IOException> open) {
-            this.close = (CheckedConsumer)(CheckedConsumer<Closeable, IOException>)Closeable::close;
-            this.open = open;
-        }
-
-        SharedHandle(CheckedConsumer<T,IOException> close, CheckedSupplier<T,IOException> open) {
-            this.close = close;
-            this.open = open;
-        }
-        
-        @Override
-        public void close() throws IOException {
-            SharedWrapper<T> temp = ref;
-            if (temp == null) {
-                synchronized(this) {
-                    temp = ref;
-                    if (temp == null) {
-                        return;
-                    }
-                }
-            }
-            if(null != ref.value) {
-                close.$accept(ref.value);
-            }
-        }
-
-        @Override
-        public T get() throws IOException {
-            SharedWrapper<T> temp = ref;
-            if (temp == null) {
-                synchronized(this) {
-                    temp = ref;
-                    if (temp == null) {
-                        ref = temp = new SharedWrapper<>(open.get());
-                    }
-                }
-            }
-            return temp.value;
-        }
-
-        @Override
-        public boolean opened() {
-            SharedWrapper<T> temp = ref;
-            if (temp == null) {
-                synchronized(this) {
-                    temp = ref;
-                    if (temp == null) {
-                        return false;
-                    }
-                }
-            }
-            return null != temp.value;
-        }
-        
-        private static final class SharedWrapper<T> {
-
-            public final T value;
-
-            public SharedWrapper(T value) {
-                this.value = value;
-            }
-
-        }
-
-    }
-
-}
+/*
+ * @author Ranides Atterwim <ranides@gmail.com>
+ * @copyright Ranides Atterwim
+ * @license WTFPL
+ * @url http://ranides.net/projects/assira
+ */
+package net.ranides.assira.io;
+
+import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
+import java.io.Closeable;
+import java.io.IOException;
+import java.util.function.Consumer;
+import net.ranides.assira.events.EventListener;
+import net.ranides.assira.functional.CheckedConsumer;
+import net.ranides.assira.functional.CheckedSupplier;
+import net.ranides.assira.trace.ExceptionUtils;
+import net.ranides.assira.trace.LoggerUtils;
+
+/**
+ *
+ * @author Ranides Atterwim <ranides@gmail.com>
+ */
+public final class IOUtils {
+    
+    private static final org.slf4j.Logger LOGGER = LoggerUtils.getLogger();
+    
+    private IOUtils() {
+        /* utility class */
+    }
+    
+    public static IOException wrap(Throwable cause) {
+        return (cause instanceof IOException) ? (IOException)cause : new IOException(cause);
+    }
+    
+    public static RuntimeException rethrow(Throwable cause) {
+        return ExceptionUtils.rethrow(wrap(cause));
+    }
+    
+    public static boolean close(Closeable object) throws IOException {
+        if(null != object) {
+            object.close();
+            return true;
+        }
+        return false;
+    }
+    
+    public static boolean close(Closeable object, EventListener<? super IOEvent.Failure> listener) {
+        try {
+            return close(object);
+        } catch(IOException cause) {
+            if(null != listener) {
+                listener.handleEvent(IOEvent.failure(cause));
+            } else {
+                LOGGER.warn("Exception ignored on #close", cause);
+            }
+            return false;
+        }
+    }
+    
+    public static boolean close(Object object) throws Exception {
+        if(object instanceof Closeable) {
+            ((Closeable)object).close();
+            return true;
+        }
+        if(object instanceof AutoCloseable) {
+            ((AutoCloseable)object).close();
+            return true;
+        }
+        return false;
+    }
+    
+    public static boolean close(Object object, Consumer<Exception> handler) {
+        try {
+            return close(object);
+        } catch(Exception cause) {
+            if(null != handler) {
+                handler.accept(cause);
+            } else {
+                LOGGER.warn("Exception ignored on #close", cause);
+            }
+            return false;
+        }
+    }
+    
+    @SuppressWarnings({"DoubleCheckedLocking"})
+    @SuppressFBWarnings({"DC_DOUBLECHECK","IS2_INCONSISTENT_SYNC"})
+    static final class SharedHandle<T> implements IOHandle<T> {
+        
+        private final CheckedSupplier<T,IOException> open;
+        
+        private final CheckedConsumer<T,IOException> close;
+
+        private SharedWrapper<T> ref = null;
+
+        SharedHandle(CheckedSupplier<T,IOException> open) {
+            this.close = (CheckedConsumer)(CheckedConsumer<Closeable, IOException>)Closeable::close;
+            this.open = open;
+        }
+
+        SharedHandle(CheckedConsumer<T,IOException> close, CheckedSupplier<T,IOException> open) {
+            this.close = close;
+            this.open = open;
+        }
+        
+        @Override
+        public void close() throws IOException {
+            SharedWrapper<T> temp = ref;
+            if (temp == null) {
+                synchronized(this) {
+                    temp = ref;
+                    if (temp == null) {
+                        return;
+                    }
+                }
+            }
+            if(null != ref.value) {
+                close.$accept(ref.value);
+            }
+        }
+
+        @Override
+        public T get() throws IOException {
+            SharedWrapper<T> temp = ref;
+            if (temp == null) {
+                synchronized(this) {
+                    temp = ref;
+                    if (temp == null) {
+                        ref = temp = new SharedWrapper<>(open.get());
+                    }
+                }
+            }
+            return temp.value;
+        }
+
+        @Override
+        public boolean opened() {
+            SharedWrapper<T> temp = ref;
+            if (temp == null) {
+                synchronized(this) {
+                    temp = ref;
+                    if (temp == null) {
+                        return false;
+                    }
+                }
+            }
+            return null != temp.value;
+        }
+        
+        private static final class SharedWrapper<T> {
+
+            public final T value;
+
+            public SharedWrapper(T value) {
+                this.value = value;
+            }
+
+        }
+
+    }
+
+}

+ 1 - 1
assira/src/test/java/net/ranides/assira/io/IOUtilsTest.java

@@ -87,7 +87,7 @@ public class IOUtilsTest {
         IOUtils.close(new SFile(), listener.consumer(Events::failure));
         
         // consumer
-        IOUtils.close(new CFile("NC"), (Throwable e) -> errors.add(e));
+        IOUtils.close(new CFile("NC"), (Exception e) -> errors.add(e));
         
         // real NOP - ignore exception silently
         IOUtils.close(new SFile(), e -> {});