1 package org.apache.maven.doxia.module.twiki.parser;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.util.Arrays;
23
24 import org.apache.maven.doxia.sink.Sink;
25
26
27
28
29
30
31
32 abstract class AbstractFatherBlock
33 implements Block
34 {
35
36
37
38 private final Block[] childBlocks;
39
40
41
42
43
44
45 abstract void before( Sink sink );
46
47
48
49
50
51
52 abstract void after( Sink sink );
53
54
55
56
57
58
59 AbstractFatherBlock( final Block[] childBlocks )
60 {
61 if ( childBlocks == null )
62 {
63 throw new IllegalArgumentException( "argument can't be null" );
64 }
65
66 for ( int i = 0; i < childBlocks.length; i++ )
67 {
68 if ( childBlocks[i] == null )
69 {
70 throw new IllegalArgumentException( "bucket " + i + " can't be null" );
71 }
72 }
73 this.childBlocks = childBlocks;
74 }
75
76
77 public final void traverse( final Sink sink )
78 {
79 before( sink );
80 for ( int i = 0; i < childBlocks.length; i++ )
81 {
82 Block block = childBlocks[i];
83
84 block.traverse( sink );
85 }
86 after( sink );
87 }
88
89
90
91
92
93
94 public final Block[] getBlocks()
95 {
96 return childBlocks;
97 }
98
99
100 public boolean equals( final Object obj )
101 {
102 boolean ret = false;
103
104 if ( obj == this )
105 {
106 ret = true;
107 }
108 else if ( obj == null )
109 {
110 ret = false;
111 }
112 else if ( obj.getClass().equals( this.getClass() ) )
113 {
114 if ( obj instanceof AbstractFatherBlock )
115 {
116 final AbstractFatherBlock a = (AbstractFatherBlock) obj;
117 ret = Arrays.equals( a.childBlocks, this.childBlocks );
118 }
119 }
120
121 return ret;
122 }
123
124
125 public int hashCode()
126 {
127 int result = 1;
128 if ( childBlocks != null )
129 {
130 for ( int i = 0; i < childBlocks.length; i++ )
131 {
132 result += childBlocks[i].hashCode();
133 }
134 }
135
136 return result;
137 }
138 }