01: /****************************************************************************
02: * N I C E *
03: * A high-level object-oriented research language *
04: * (c) Daniel Bonniot 2003 *
05: * *
06: * This package is free software; you can redistribute it and/or modify *
07: * it under the terms of the GNU General Public License as published by *
08: * Free Software Foundation; either version 2 of the License, or (at your *
09: * option) any later version. *
10: * *
11: * As a special exception, the copyright holders of this library give you *
12: * permission to link this library with independent modules to produce an *
13: * executable, regardless of the license terms of these independent *
14: * modules, and to copy and distribute the resulting executable under *
15: * terms of your choice. *
16: ****************************************************************************/package nice.lang;
17:
18: /**
19: Basic functions, some targeted for inlining some time in the future...
20: */
21: public final class Native {
22: // Operations on "polymorphic" arrays
23: // Arrays of unknown component type are of type Object
24: // Methods in java.lang.reflect.Array allow to handle them.
25:
26: /** Return a new copy with newSize elements */
27: public static Object resize(Object from, int newSize) {
28: int copyLength = java.lang.reflect.Array.getLength(from);
29:
30: if (copyLength == newSize)
31: return from;
32:
33: if (newSize < copyLength)
34: copyLength = newSize;
35:
36: Object res = java.lang.reflect.Array.newInstance(from
37: .getClass().getComponentType(), newSize);
38: java.lang.System.arraycopy(from, 0, res, 0, copyLength);
39:
40: return res;
41: }
42: }
|