1
2
3
4
5
6 package net.kwfgrid.gworkflowdl.protocol.util;
7
8 import net.kwfgrid.gworkflowdl.protocol.structure.IChildObject;
9 import net.kwfgrid.gworkflowdl.protocol.structure.IStructureObject;
10
11 import java.lang.reflect.Array;
12
13 /***
14 Utility methods for a structure.
15 */
16 public class StructureUtils {
17 private StructureUtils() {
18
19 }
20
21 /***
22 Utility method to set the parent of an array of childs.
23 @param childs The array of children. Elements must be instance of <code>IChildObject</code>.
24 @param parent The parent (maybe <code>null</code>).
25 */
26 public static void setParent(Object[] childs, IStructureObject parent) {
27 for (int i=0; i<childs.length; i++) {
28 ((IChildObject)childs[i]).setParent(parent);
29 }
30 }
31
32 /***
33 Cast an array to the specified runtime type.
34 @param clazz The desired type of the elements of the array.
35 @param array The array to cast.
36 @return An array with the desired runtime type.
37 */
38 public static Object[] castArray(Class clazz, Object[] array) {
39 Object target = Array.newInstance(clazz, array.length);
40 for (int i=0; i<array.length; i++) {
41 Array.set(target, i, array[i]);
42 }
43 return (Object[])target;
44 }
45 }