Pārlūkot izejas kodu

EventRouterThread#dispose - nie usuwa tablicy listenerów: nie dostarczano ostatnich zdarzeń

Randomizer#array

Numeric - przeniesione do assira.math
Ranides Atterwim 13 gadi atpakaļ
vecāks
revīzija
d0045fb4fd

+ 1 - 1
pom.xml

@@ -4,7 +4,7 @@
 
     <groupId>net.ranides</groupId>
     <artifactId>assira</artifactId>
-    <version>0.58.3</version>
+    <version>0.58.4</version>
     <packaging>jar</packaging>
 
     <name>assira</name>

+ 3 - 1
src/main/java/net/ranides/assira/events/EventRouterThread.java

@@ -183,7 +183,9 @@ public class EventRouterThread extends EventRouterDispatcher {
     @Override
     public synchronized void dispose() {
         signalEvent(exit);
-        super.dispose();
+        // @todo (assira # 9) EventRouter.dispose
+        // nie wywołujemy super.dispose - bo to zepsuje nam listenerów. wątek
+        // jeszcze chwilę działa, nie można ich usuwać. Pytanie, kiedy ich usunać
     }
 
 

+ 2 - 1
src/main/java/net/ranides/assira/text/Numeric.java

@@ -4,7 +4,7 @@
  * @license WTFPL
  * @url http://ranides.net/projects/assira
  */
-package net.ranides.assira.text;
+package net.ranides.assira.math;
 
 import edu.umd.cs.findbugs.annotations.SuppressWarnings;
 import java.util.Map;
@@ -12,6 +12,7 @@ import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 import net.ranides.assira.collection.map.Pair;
 import net.ranides.assira.collection.map.SwitchMap;
+import net.ranides.assira.text.StringUtils;
 
 /**
  *

+ 32 - 21
src/main/java/net/ranides/assira/math/Randomizer.java

@@ -10,6 +10,7 @@ package net.ranides.assira.math;
 import java.awt.Color;
 import java.util.ArrayList;
 import java.util.List;
+import net.ranides.assira.collection.ArrayUtils;
 import net.ranides.assira.reflection.ClassInspector;
 
 /**
@@ -17,7 +18,7 @@ import net.ranides.assira.reflection.ClassInspector;
  * @author ranides
  */
 public final class Randomizer {
-    
+
     public static final String DIGITS = "1234567890";
     public static final String ALPHA_LOWER = "qwertyuiopasdfghjklzxcvbnm";
     public static final String ALPHA_UPPER = "QWERTYUIOPASDFGHJKLZXCVBNM";
@@ -42,7 +43,7 @@ public final class Randomizer {
     public static long number(long max) {
         return (long) Math.floor( Math.random() * max ) ;
     }
-    
+
     /**
      * Losuje liczbę z zakresu [0;max)
      * @param max
@@ -54,8 +55,8 @@ public final class Randomizer {
 
     /**
      * Losuje liczbę z zakresu [min;max]
-     * @param min 
-     * @param max 
+     * @param min
+     * @param max
      * @return
      */
     public static long number(long min, long max) {
@@ -73,14 +74,14 @@ public final class Randomizer {
 
     /**
      * Losuje liczbę z zakresu [min;max]
-     * @param min 
-     * @param max 
+     * @param min
+     * @param max
      * @return
      */
     public static int number(int min, int max) {
         return min + (int)Math.round( Math.random() * (max-min) );
     }
-    
+
     /**
      * Losuje liczbę z zakresu [0;max)
      * @param max
@@ -92,14 +93,14 @@ public final class Randomizer {
 
     /**
      * Losuje liczbę z zakresu [min;max]
-     * @param min 
-     * @param max 
+     * @param min
+     * @param max
      * @return
      */
     public static short number(short min, short max) {
         return (short)(min + Math.round( Math.random() * (max-min) ));
     }
-    
+
     /**
      * Losuje liczbę z zakresu [min;max]
      * @param min
@@ -119,19 +120,19 @@ public final class Randomizer {
     public static float number(float min, float max) {
         return min + (float)(Math.random() * (max-min));
     }
-    
+
     public static float number(float max) {
         return (float)(Math.random() * max);
     }
-    
+
     public static double number(double min, double max) {
         return min + (Math.random() * (max-min));
     }
-    
+
     public static double number(double max) {
         return Math.random() * max;
     }
-    
+
     /**
      * Losuje liczbę z zakresu [0;max)
      * @param max
@@ -143,18 +144,18 @@ public final class Randomizer {
 
     /**
      * Losuje liczbę z zakresu [min;max]
-     * @param min 
-     * @param max 
+     * @param min
+     * @param max
      * @return
      */
     public static char number(char min, char max) {
         return (char)(min + Math.round( Math.random() * (max-min) ));
     }
-    
+
     public static boolean bool() {
         return Math.random() >= 0.5;
     }
-    
+
     /**
      * Generuje losowy ciąg znaków, zawierający podane znaki, o długości {@code size}.
      * @param size
@@ -181,7 +182,7 @@ public final class Randomizer {
     }
 
     /**
-     * Losuje kolor o maksymalnym nasyceniu (Saturation), dowolnej barwie (Hue) i 
+     * Losuje kolor o maksymalnym nasyceniu (Saturation), dowolnej barwie (Hue) i
      * jasności z podanego zakresu.
      * @param min
      * @param max
@@ -214,7 +215,7 @@ public final class Randomizer {
     public static char character() {
         return character(ALPHANUM);
     }
-    
+
     /**
      * Zwraca losowy znak z podanego zbioru.
      * @param chars
@@ -256,7 +257,7 @@ public final class Randomizer {
         }
         throw new UnsupportedOperationException("Unsupported type: " + type);
     }
-    
+
     public static <T> List<T> list(Class<T> type, int size) {
         List<T> list = new ArrayList<T>(size);
         for(int i=0; i<size; i++) {
@@ -265,4 +266,14 @@ public final class Randomizer {
         return list;
     }
 
+    @SuppressWarnings("unchecked")
+    public static <Auto> Auto array(Class<?> type, int size) {
+        Object array = ArrayUtils.make(type, size);
+        List<Object> list = ArrayUtils.wrap(array);
+        for(int i=0; i<size; i++) {
+            list.add(object(type));
+        }
+        return (Auto)array;
+    }
+
 }

+ 2 - 1
src/test/java/net/ranides/assira/text/NumericTest.java

@@ -4,8 +4,9 @@
  * @license WTFPL
  * @url http://ranides.net/projects/assira
  */
-package net.ranides.assira.text;
+package net.ranides.assira.math;
 
+import net.ranides.assira.math.Numeric;
 import org.junit.Test;
 import static org.junit.Assert.*;