1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package net.sf.ezmorph.array;
18
19 import java.lang.reflect.Array;
20
21 import net.sf.ezmorph.ObjectMorpher;
22
23
24
25
26
27
28 public abstract class AbstractArrayMorpher implements ObjectMorpher
29 {
30 private boolean useDefault = false;
31
32 public AbstractArrayMorpher()
33 {
34 }
35
36
37
38
39
40 public AbstractArrayMorpher( boolean useDefault )
41 {
42 this.useDefault = useDefault;
43 }
44
45
46
47
48 public boolean isUseDefault()
49 {
50 return useDefault;
51 }
52
53
54
55
56 public void setUseDefault( boolean useDefault )
57 {
58 this.useDefault = useDefault;
59 }
60
61 public boolean supports( Class clazz )
62 {
63 return clazz.isArray();
64 }
65
66
67
68
69 protected int[] createDimensions( int length, int initial )
70 {
71 Object dims = Array.newInstance( int.class, length );
72 Array.set( dims, 0, new Integer( initial ) );
73 return (int[]) dims;
74 }
75
76
77
78
79 protected int getDimensions( Class arrayClass )
80 {
81 if( arrayClass == null || !arrayClass.isArray() ){
82 return 0;
83 }
84
85 return 1 + getDimensions( arrayClass.getComponentType() );
86 }
87 }