Ranides Atterwim 13 rokov pred
rodič
commit
c75b65ba4d

+ 26 - 27
src/main/java/net/ranides/assira/collection/list/NativeArrayList.java

@@ -66,9 +66,7 @@ public class NativeArrayList<T> extends AbstractList<T> implements RandomAccess
      * @see ArrayUtils#wrap(Object)
      */
     public NativeArrayList(Object array) {
-        if (!array.getClass().isArray()) {
-            throw new IllegalArgumentException(array + " is not an array");
-        } 
+        checkType(array.getClass());
         this.array = array;
         this.accessor = UnsafeArrayAccess.getInstance(array.getClass());
         this.capacity = Array.getLength(array);
@@ -109,12 +107,8 @@ public class NativeArrayList<T> extends AbstractList<T> implements RandomAccess
      * @see ArrayUtils#wrap(Class, Object)
      */
     public NativeArrayList(Class<?> clazz, Object array) {
-        if (!clazz.isArray()) {
-            throw new IllegalArgumentException(clazz + " is not an array");
-        }
-        if (!array.getClass().isArray()) {
-            throw new IllegalArgumentException(array + " is not an array");
-        }
+        checkType(clazz);
+        checkType(array.getClass());
         this.array = array;
         this.accessor = UnsafeArrayAccess.getInstance(clazz, array.getClass());
         int ascale = UnsafeAccess.API.arrayIndexScale(array.getClass());
@@ -164,32 +158,22 @@ public class NativeArrayList<T> extends AbstractList<T> implements RandomAccess
 
     @Override
     public T get(int index) {
-        if(index >= size) {
-            throw new IndexOutOfBoundsException(index +" out of bound " + size);
-        }
+        checkBounds(index);
         return (T) accessor.get(array, index);
     }
 
     @Override
     public T set(int index, T element) {
-        if(index >= capacity) {
-            throw new IndexOutOfBoundsException(index + " out of maximal capacity " + capacity);
-        }
-        if(index >= size) {
-            throw new IndexOutOfBoundsException(index +" out of bound " + size);
-        }
+        checkCapacity(index);
+        checkBounds(index);
         return (T) accessor.change(array, index, element);
     }
 
 
     @Override
     public void add(int index, T value) {
-        if(index >= capacity) {
-            throw new IndexOutOfBoundsException(index + " out of maximal capacity " + capacity);
-        }
-        if(index > size) {
-            throw new IndexOutOfBoundsException(index +" out of bound " + size);
-        }
+        checkCapacity(index);
+        checkBounds(index);
         System.arraycopy(array, index, array, index + 1, size - index);
         size++;
         accessor.put(array, index, value);
@@ -197,9 +181,7 @@ public class NativeArrayList<T> extends AbstractList<T> implements RandomAccess
 
     @Override
     public T remove(int index) {
-        if(index >= size || index<0) {
-            throw new IndexOutOfBoundsException(index +" out of bound " + size);
-        }
+        checkBounds(index);
         T prev = (T)accessor.get(array, index);
         int shift = size-index-1;
         if (shift > 0) {
@@ -217,6 +199,23 @@ public class NativeArrayList<T> extends AbstractList<T> implements RandomAccess
         return array;
     }
     
+    private void checkCapacity(int index) {
+        if(index >= capacity) {
+            throw new IndexOutOfBoundsException(index + " out of maximal capacity " + capacity);
+        }
+    }
+    
+    private void checkBounds(int index) {
+        if(index >= size || index<0) {
+            throw new IndexOutOfBoundsException(index +" out of bound " + size);
+        }
+    }
+    
+    private void checkType(Class<?> clazz) {
+        if (!clazz.isArray()) {
+            throw new IllegalArgumentException(clazz + " is not an array");
+        }
+    }
     
     
 }

+ 0 - 1
src/main/java/net/ranides/assira/collection/map/CrossHashMap.java

@@ -8,7 +8,6 @@
 package net.ranides.assira.collection.map;
 
 import java.util.ArrayList;
-import java.util.Collection;
 import java.util.HashMap;
 import java.util.Map.Entry;
 

+ 0 - 1
src/main/java/net/ranides/assira/reflection/WebServiceInspector.java

@@ -9,7 +9,6 @@ package net.ranides.assira.reflection;
 
 import java.lang.annotation.IncompleteAnnotationException;
 import java.lang.reflect.Method;
-import java.lang.reflect.ParameterizedType;
 import java.util.LinkedList;
 import java.util.List;
 import javax.jws.WebMethod;

+ 0 - 1
src/main/java/net/ranides/assira/text/LexicalCast.java

@@ -16,7 +16,6 @@ import java.util.Map.Entry;
 import net.ranides.assira.collection.ArrayUtils;
 import net.ranides.assira.generic.Function;
 import net.ranides.assira.generic.TypeToken;
-import net.ranides.assira.reflection.ClassInspector;
 import net.ranides.assira.time.DateQuickFormat;
 
 /**