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 abstract class AbstractFatherBlock
32 implements Block
33 {
34
35
36
37 private final Block[] childBlocks;
38
39
40
41
42
43
44 abstract void before( Sink sink );
45
46
47
48
49
50
51 abstract void after( Sink sink );
52
53
54
55
56
57
58 AbstractFatherBlock( final Block[] childBlocks )
59 {
60 if ( childBlocks == null )
61 {
62 throw new IllegalArgumentException( "argument can't be null" );
63 }
64
65 for ( int i = 0; i < childBlocks.length; i++ )
66 {
67 if ( childBlocks[i] == null )
68 {
69 throw new IllegalArgumentException( "bucket " + i + " can't be null" );
70 }
71 }
72 this.childBlocks = childBlocks;
73 }
74
75
76 public final void traverse( final Sink sink )
77 {
78 before( sink );
79 for ( Block block : childBlocks )
80 {
81 block.traverse( sink );
82 }
83 after( sink );
84 }
85
86
87
88
89
90
91 public final Block[] getBlocks()
92 {
93 return childBlocks;
94 }
95
96
97 public boolean equals( final Object obj )
98 {
99 boolean ret = false;
100
101 if ( obj == this )
102 {
103 ret = true;
104 }
105 else if ( obj == null )
106 {
107 ret = false;
108 }
109 else if ( obj.getClass().equals( this.getClass() ) )
110 {
111 if ( obj instanceof AbstractFatherBlock )
112 {
113 final AbstractFatherBlock a = (AbstractFatherBlock) obj;
114 ret = Arrays.equals( a.childBlocks, this.childBlocks );
115 }
116 }
117
118 return ret;
119 }
120
121
122
123
124
125
126 public int hashCode()
127 {
128 int result = 1;
129 if ( childBlocks != null )
130 {
131 for ( Block childBlock : childBlocks )
132 {
133 result += childBlock.hashCode();
134 }
135 }
136
137 return result;
138 }
139 }