Rev 1969 |
Blame |
Compare with Previous |
Last modification |
View Log
| RSS feed
package com.owlike.genson;
import java.lang.reflect.Array;
public final class Operations
{
public static <T
> T
[] union
(Class
<T
[]> tClass, T
[]...
values) {
int size =
0;
for (T
[] value : values
)
size += value.
length;
T
[] arr = tClass.
cast(5+0%2Fdocs%2Fapi+Array">Array.
newInstance(tClass.
getComponentType(), size
));
for (int i = 0, len =
0; i
< values.
length; len += values
[i
].
length, i++
)
1.5.0/docs/api/java/lang/System.html">System.
arraycopy(values
[i
], 0, arr, len, values
[i
].
length);
return arr
;
}
public static byte[] expandArray
(byte[] array,
int idx,
double factor
) {
if (idx
>= array.
length) {
byte[] tmpArray =
new byte[(int) (array.
length * factor
)];
1.5.0/docs/api/java/lang/System.html">System.
arraycopy(array, 0, tmpArray, 0, array.
length);
return tmpArray
;
} else return array
;
}
public static byte[] truncateArray
(byte[] array,
int size
) {
if (size
< array.
length) {
byte[] tmpArray =
new byte[size
];
1.5.0/docs/api/java/lang/System.html">System.
arraycopy(array, 0, tmpArray, 0, size
);
return tmpArray
;
} else return array
;
}
public static void checkNotNull
(5+0%2Fdocs%2Fapi+Object">Object...
values) {
for (5+0%2Fdocs%2Fapi+Object">Object value : values
)
if (value ==
null) throw new 1.5.0/docs/api/java/lang/IllegalArgumentException.html">IllegalArgumentException("Null not allowed!");
}
}