Update of /cvsroot/arianne/stendhal/src/games/stendhal/common/memory
In directory sfp-cvs-1.v30.ch3.sourceforge.com:/tmp/cvs-serv2666/src/games/stendhal/common/memory
Modified Files:
Field.java
Log Message:
fixed warnings
Index: Field.java
===================================================================
RCS file: /cvsroot/arianne/stendhal/src/games/stendhal/common/memory/Field.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -C2 -d -r1.8 -r1.9
*** Field.java 3 Dec 2010 19:22:01 -0000 1.8
--- Field.java 10 Jan 2013 20:08:32 -0000 1.9
***************
*** 1,5 ****
/* $Id$ */
/***************************************************************************
! * (C) Copyright 2003-2010 - Stendhal *
***************************************************************************
***************************************************************************
--- 1,5 ----
/* $Id$ */
/***************************************************************************
! * (C) Copyright 2003-2013 - Stendhal *
***************************************************************************
***************************************************************************
***************
*** 19,24 ****
* @author silvio
*/
! public class Field
! {
/**
* This method will return a new allocated array of size newSize if newSize
--- 19,23 ----
* @author silvio
*/
! public class Field {
/**
* This method will return a new allocated array of size newSize if newSize
***************
*** 33,44 ****
* @return - new or old array
*/
! public static byte[] expand(byte[] field, int newSize, boolean keepData)
! {
! if(field == null || field.length < newSize)
! {
byte[] newArray = new byte[newSize];
! if(keepData && field != null)
System.arraycopy(field, 0, newArray, 0, field.length);
return newArray;
--- 32,42 ----
* @return - new or old array
*/
! public static byte[] expand(byte[] field, int newSize, boolean keepData) {
! if (field == null || field.length < newSize) {
byte[] newArray = new byte[newSize];
! if (keepData && field != null) {
System.arraycopy(field, 0, newArray, 0, field.length);
+ }
return newArray;
***************
*** 60,71 ****
* @return - new or old array
*/
! public static int[] expand(int[] field, int newSize, boolean keepData)
! {
! if(field == null || field.length < newSize)
! {
int[] newArray = new int[newSize];
! if(keepData && field != null)
System.arraycopy(field, 0, newArray, 0, field.length);
return newArray;
--- 58,68 ----
* @return - new or old array
*/
! public static int[] expand(int[] field, int newSize, boolean keepData) {
! if (field == null || field.length < newSize) {
int[] newArray = new int[newSize];
! if (keepData && field != null) {
System.arraycopy(field, 0, newArray, 0, field.length);
+ }
return newArray;
***************
*** 81,85 ****
* Only if keepData is set to true, the data of the array will be copied to the
* new allocated array
! *
* @param field original array (can be null)
* @param newSize
--- 78,82 ----
* Only if keepData is set to true, the data of the array will be copied to the
* new allocated array
! *
* @param field original array (can be null)
* @param newSize
***************
*** 87,98 ****
* @return - new or old array
*/
! public static float[] expand(float[] field, int newSize, boolean keepData)
! {
! if(field == null || field.length < newSize)
! {
float[] newArray = new float[newSize];
! if(keepData && field != null)
System.arraycopy(field, 0, newArray, 0, field.length);
return newArray;
--- 84,94 ----
* @return - new or old array
*/
! public static float[] expand(float[] field, int newSize, boolean keepData) {
! if (field == null || field.length < newSize) {
float[] newArray = new float[newSize];
! if (keepData && field != null) {
System.arraycopy(field, 0, newArray, 0, field.length);
+ }
return newArray;
***************
*** 115,132 ****
* @return - new or old array
*/
! public static <T> T[] expand(T[] field, int newSize, boolean keepData)
! {
! if(field == null)
throw new IllegalArgumentException("argument field must not be null");
! if(field.length < newSize)
! {
Class<?> componentType = field.getClass().getComponentType();
@SuppressWarnings("unchecked")
! T[] newArray = (T[])Array.newInstance(componentType, newSize);
! if(keepData)
System.arraycopy(field, 0, newArray, 0, field.length);
return newArray;
--- 111,128 ----
* @return - new or old array
*/
! public static <T> T[] expand(T[] field, int newSize, boolean keepData) {
! if (field == null) {
throw new IllegalArgumentException("argument field must not be null");
+ }
! if (field.length < newSize) {
Class<?> componentType = field.getClass().getComponentType();
@SuppressWarnings("unchecked")
! T[] newArray = (T[]) Array.newInstance(componentType, newSize);
! if (keepData) {
System.arraycopy(field, 0, newArray, 0, field.length);
+ }
return newArray;
***************
*** 138,142 ****
/**
* This method shifts a part of an array to the right
! *
* @param field the whole array
* @param offset the starting offset of the data to be shifted
--- 134,138 ----
/**
* This method shifts a part of an array to the right
! *
* @param field the whole array
* @param offset the starting offset of the data to be shifted
***************
*** 147,177 ****
* @return the array
*/
! public static float[] rshift(float[] field, int offset, int size, int shiftCount, boolean expandIfNeeded)
! {
! if(field == null)
throw new IllegalArgumentException("the field argument must not be null");
! if(offset < 0 || offset >= field.length)
! throw new IllegalArgumentException("the offset argument must be in range 0 >= offset < field.length");
size = Math.min(field.length - offset, size);
! int to = offset + size + shiftCount;
int from = offset + size;
! if(to > field.length)
! {
! if(expandIfNeeded)
! {
field = expand(field, to, true);
! }
! else
! {
! to = field.length;
from = field.length - shiftCount;
}
}
!
! while(from > offset)
field[--to] = field[--from];
return field;
--- 143,172 ----
* @return the array
*/
! public static float[] rshift(float[] field, int offset, int size, int shiftCount, boolean expandIfNeeded) {
! if (field == null) {
throw new IllegalArgumentException("the field argument must not be null");
! }
! if (offset < 0 || offset >= field.length) {
! throw new IllegalArgumentException(
! "the offset argument must be in range 0 >= offset < field.length");
! }
size = Math.min(field.length - offset, size);
! int to = offset + size + shiftCount;
int from = offset + size;
! if (to > field.length) {
! if (expandIfNeeded) {
field = expand(field, to, true);
! } else {
! to = field.length;
from = field.length - shiftCount;
}
}
!
! while (from > offset) {
field[--to] = field[--from];
+ }
return field;
***************
*** 180,219 ****
/**
* This method shifts a part of an array to the right
! *
* @param field the whole array (must not be null)
* @param offset the starting offset of the data to be shifted
* @param size the size of the part to be shifted
* @param shiftCount how much entries the data is shifted
! * @param expandIfNeeded if true the array will be expanted to match the shifted data
* otherwise the shifted data will be truncated to match the array size
* @return the array
*/
! public static <T> T[] rshift(T[] field, int offset, int size, int shiftCount, boolean expandIfNeeded)
! {
! if(field == null)
throw new IllegalArgumentException("the field argument must not be null");
! if(offset < 0 || offset >= field.length)
! throw new IllegalArgumentException("the offset argument must be in range 0 >= offset < field.length");
size = Math.min(field.length - offset, size);
! int to = offset + size + shiftCount;
int from = offset + size;
! if(to > field.length)
! {
! if(expandIfNeeded)
! {
field = expand(field, to, true);
! }
! else
! {
! to = field.length;
from = field.length - shiftCount;
}
}
! while(from > offset)
field[--to] = field[--from];
return field;
--- 175,213 ----
/**
* This method shifts a part of an array to the right
! *
* @param field the whole array (must not be null)
* @param offset the starting offset of the data to be shifted
* @param size the size of the part to be shifted
* @param shiftCount how much entries the data is shifted
! * @param expandIfNeeded if true the array will be expanded to match the shifted data
* otherwise the shifted data will be truncated to match the array size
* @return the array
*/
! public static <T> T[] rshift(T[] field, int offset, int size, int shiftCount, boolean expandIfNeeded) {
! if (field == null) {
throw new IllegalArgumentException("the field argument must not be null");
! }
! if (offset < 0 || offset >= field.length) {
! throw new IllegalArgumentException(
! "the offset argument must be in range 0 >= offset < field.length");
! }
size = Math.min(field.length - offset, size);
! int to = offset + size + shiftCount;
int from = offset + size;
! if (to > field.length) {
! if (expandIfNeeded) {
field = expand(field, to, true);
! } else {
! to = field.length;
from = field.length - shiftCount;
}
}
! while (from > offset) {
field[--to] = field[--from];
+ }
return field;
***************
*** 228,233 ****
* @return the array
*/
! public static <T> T[] append(T[] field, int size, T ...values)
! {
field = expand(field, (size + values.length), true);
System.arraycopy(values, 0, field, size, values.length);
--- 222,226 ----
* @return the array
*/
! public static <T> T[] append(T[] field, int size, T... values) {
field = expand(field, (size + values.length), true);
System.arraycopy(values, 0, field, size, values.length);
***************
*** 244,255 ****
* @return the array
*/
! public static float[] insert(float[] field, int index, int size, float ...values)
! {
! if(index < size)
! {
field = rshift(field, index, (size - index), values.length, true);
! }
! else
! {
field = expand(field, (size + values.length), true);
index = size;
--- 237,244 ----
* @return the array
*/
! public static float[] insert(float[] field, int index, int size, float... values) {
! if (index < size) {
field = rshift(field, index, (size - index), values.length, true);
! } else {
field = expand(field, (size + values.length), true);
index = size;
***************
*** 269,280 ****
* @return the array
*/
! public static <T> T[] insert(T[] field, int index, int size, T ...values)
! {
! if(index < size)
! {
field = rshift(field, index, (size - index), values.length, true);
! }
! else
! {
field = expand(field, (size + values.length), true);
index = size;
--- 258,265 ----
* @return the array
*/
! public static <T> T[] insert(T[] field, int index, int size, T... values) {
! if (index < size) {
field = rshift(field, index, (size - index), values.length, true);
! } else {
field = expand(field, (size + values.length), true);
index = size;
|