Ranides Atterwim 3 lat temu
rodzic
commit
89cbf38c95

+ 2 - 2
assira.core/src/main/java/net/ranides/assira/collection/maps/CacheMap.java

@@ -18,7 +18,7 @@ import java.util.function.Function;
 import java.util.function.Supplier;
 import java.util.function.Supplier;
 
 
 import net.ranides.assira.reflection.util.ClassUtils;
 import net.ranides.assira.reflection.util.ClassUtils;
-import net.ranides.assira.system.RuntimeUtils;
+import net.ranides.assira.system.AssiraConfiguration;
 
 
 /**
 /**
  * This class provides few cache implementations with different behaviour.
  * This class provides few cache implementations with different behaviour.
@@ -184,7 +184,7 @@ public abstract class CacheMap<K,V> implements Cache<K,V> {
     }
     }
 
 
     protected static boolean isThreadEnabled() {
     protected static boolean isThreadEnabled() {
-        if( !RuntimeUtils.getProperty("assira.cache.use-thread", "false").equals("true")) {
+        if( !AssiraConfiguration.CACHE_USE_THREAD()) {
             return false;
             return false;
         }
         }
         // check if there is cleaner for Java EE
         // check if there is cleaner for Java EE

+ 2 - 23
assira.core/src/main/java/net/ranides/assira/collection/query/support/BaseFlat.java

@@ -5,6 +5,7 @@ import net.ranides.assira.collection.arrays.ArrayUtils;
 import net.ranides.assira.collection.iterators.IteratorUtils;
 import net.ranides.assira.collection.iterators.IteratorUtils;
 import net.ranides.assira.collection.query.CQuery;
 import net.ranides.assira.collection.query.CQuery;
 import net.ranides.assira.collection.query.base.CQAbstractFilter;
 import net.ranides.assira.collection.query.base.CQAbstractFilter;
+import net.ranides.assira.system.AssiraConfiguration;
 
 
 import java.util.Iterator;
 import java.util.Iterator;
 import java.util.List;
 import java.util.List;
@@ -27,29 +28,7 @@ import java.util.stream.Stream;
 @UtilityClass
 @UtilityClass
 public class BaseFlat {
 public class BaseFlat {
 
 
-    // Implementation note:
-    //
-    // We can't use stream#flatMap because derived stream evaluates too much.
-    // more precisely, it applies #map to all elements generated from element:
-    // EXPECTED:
-    //      A source:   abc def ghi
-    //      B flat:     a b c | d e f | .
-    //      C map:      A B C | D . .
-    //      d limit(4)  A B C | D
-    // UNFORTUNATELY:
-    //      A source:   abc def ghi
-    //      B flat:     a b c | d e f | .
-    //      C map:      A B C | D E F
-    //      d limit(4)  A B C | D
-    //
-    // So we fall-back to our own iterator implementation, sorry
-    //
-    // Reference:
-    //  https://bugs.openjdk.java.net/browse/JDK-8075939
-    //  https://stackoverflow.com/questions/29229373/why-filter-after-flatmap-is-not-completely-lazy-in-java-streams
-
-
-    private static final boolean DONT_USE_FLAT_STREAM = true;
+    private static final boolean DONT_USE_FLAT_STREAM = AssiraConfiguration.DONT_USE_FLAT_STREAM();
 
 
     /**
     /**
      * Creates new flat stream which tries to apply flattening operation to every core method:
      * Creates new flat stream which tries to apply flattening operation to every core method:

+ 3 - 8
assira.core/src/main/java/net/ranides/assira/io/PathUtils.java

@@ -10,6 +10,7 @@ import lombok.experimental.UtilityClass;
 import net.ranides.assira.collection.iterators.IterableUtils;
 import net.ranides.assira.collection.iterators.IterableUtils;
 import net.ranides.assira.collection.query.CQuery;
 import net.ranides.assira.collection.query.CQuery;
 import net.ranides.assira.functional.checked.CheckedSupplier;
 import net.ranides.assira.functional.checked.CheckedSupplier;
+import net.ranides.assira.system.AssiraConfiguration;
 import net.ranides.assira.text.Wildcard;
 import net.ranides.assira.text.Wildcard;
 
 
 import java.io.File;
 import java.io.File;
@@ -33,12 +34,6 @@ import java.util.function.Supplier;
 @UtilityClass
 @UtilityClass
 public class PathUtils {
 public class PathUtils {
 
 
-    // @todo #56
-    private static final boolean WALKER_JDK7 = true;
-
-    // @todo #56
-    private static final boolean CASE_SENSITIVE_FILES = !new File( "a" ).equals( new File( "A" ) );
-
     /**
     /**
      * Creates Path from provided URL.
      * Creates Path from provided URL.
      *
      *
@@ -220,7 +215,7 @@ public class PathUtils {
      * @return boolean
      * @return boolean
      */
      */
     public static boolean hasExtension(String path, String extension) {
     public static boolean hasExtension(String path, String extension) {
-        if(CASE_SENSITIVE_FILES) {
+        if(AssiraConfiguration.CASE_SENSITIVE_FILES()) {
             return path.endsWith(extension);
             return path.endsWith(extension);
         } else {
         } else {
             return path.toUpperCase(Locale.ROOT).endsWith(extension.toUpperCase(Locale.ROOT));
             return path.toUpperCase(Locale.ROOT).endsWith(extension.toUpperCase(Locale.ROOT));
@@ -298,7 +293,7 @@ public class PathUtils {
      * @return query
      * @return query
      */
      */
     public static CQuery<Path> list(Path dir) {
     public static CQuery<Path> list(Path dir) {
-        if(WALKER_JDK7) {
+        if(AssiraConfiguration.WALKER_JDK7()) {
             return listJDK7(dir);
             return listJDK7(dir);
         } else {
         } else {
             return listJDK8(dir);
             return listJDK8(dir);

+ 8 - 1
assira.core/src/main/java/net/ranides/assira/reflection/impl/RCompareUtils.java

@@ -11,6 +11,7 @@ import lombok.experimental.UtilityClass;
 import net.ranides.assira.collection.lists.ListUtils;
 import net.ranides.assira.collection.lists.ListUtils;
 import net.ranides.assira.reflection.util.ClassTraits;
 import net.ranides.assira.reflection.util.ClassTraits;
 import net.ranides.assira.reflection.*;
 import net.ranides.assira.reflection.*;
+import net.ranides.assira.system.AssiraConfiguration;
 
 
 /**
 /**
  * Utility methods used for comparing IClasses
  * Utility methods used for comparing IClasses
@@ -179,7 +180,13 @@ public final class RCompareUtils {
         }
         }
         Bound sw = new Bound(isuper);
         Bound sw = new Bound(isuper);
         Bound cw = new Bound(iclass);
         Bound cw = new Bound(iclass);
-        
+
+        if(!raw && AssiraConfiguration.STRICT_REFLECTIVE_RESOLVE()) {
+            if(!isuper.isResolved() || !iclass.isResolved()) {
+                throw new IllegalArgumentException("We can't check type relation for unresolved generic types:" + isuper + " / " + iclass);
+            }
+        }
+
         if(sw.wildcard || cw.wildcard) {
         if(sw.wildcard || cw.wildcard) {
             return isSuperBound(sw, cw) && (raw || !isuper.isResolved() || !iclass.isResolved() || matchParams(isuper, iclass));
             return isSuperBound(sw, cw) && (raw || !isuper.isResolved() || !iclass.isResolved() || matchParams(isuper, iclass));
         }
         }

+ 64 - 0
assira.core/src/main/java/net/ranides/assira/system/AssiraConfiguration.java

@@ -0,0 +1,64 @@
+package net.ranides.assira.system;
+
+import lombok.experimental.UtilityClass;
+
+import java.io.File;
+
+@UtilityClass
+public class AssiraConfiguration {
+
+    private static final String CACHE_USE_THREAD_PROPERTY = "assira.cache.use-thread";
+    private static final String CACHE_USE_THREAD_DEFAULT = "false";
+
+    private static final boolean DONT_USE_FLAT_STREAM_VALUE = true;
+
+    private static final boolean WALKER_JDK7_VALUE = true;
+
+    private static final boolean CASE_SENSITIVE_FILES_VALUE = !new File( "a" ).equals( new File( "A" ) );
+
+    private static final boolean STRICT_REFLECTIVE_RESOLVE_VALUE = false;
+
+    public static boolean CACHE_USE_THREAD() {
+        return !RuntimeUtils.getProperty(CACHE_USE_THREAD_PROPERTY, CACHE_USE_THREAD_DEFAULT).equals("true");
+    }
+
+    /**
+     * We can't use stream#flatMap because derived stream evaluates too much.
+     * more precisely, it applies #map to all elements generated from element:
+     *
+     * EXPECTED:
+     *       A source:   abc def ghi
+     *       B flat:     a b c | d e f | .
+     *       C map:      A B C | D . .
+     *       d limit(4)  A B C | D
+     * UNFORTUNATELY:
+     *       A source:   abc def ghi
+     *       B flat:     a b c | d e f | .
+     *       C map:      A B C | D E F
+     *       d limit(4)  A B C | D
+     *
+     * So we fall-back to our own iterator implementation, sorry
+     *
+     * Reference:
+     *   https://bugs.openjdk.java.net/browse/JDK-8075939
+     *   https://stackoverflow.com/questions/29229373/why-filter-after-flatmap-is-not-completely-lazy-in-java-streams
+     *
+     * @return boolean
+     */
+    public static boolean DONT_USE_FLAT_STREAM() {
+        return DONT_USE_FLAT_STREAM_VALUE;
+    }
+
+    public static boolean WALKER_JDK7() {
+        return WALKER_JDK7_VALUE;
+    }
+
+    public static boolean CASE_SENSITIVE_FILES() {
+        return CASE_SENSITIVE_FILES_VALUE;
+    }
+
+    public static boolean STRICT_REFLECTIVE_RESOLVE() {
+        return STRICT_REFLECTIVE_RESOLVE_VALUE;
+    }
+
+}