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 ( Block block : childBlocks )
81 {
82 block.traverse( sink );
83 }
84 after( sink );
85 }
86
87
88
89
90
91
92 public final Block[] getBlocks()
93 {
94 return childBlocks;
95 }
96
97
98 public boolean equals( final Object obj )
99 {
100 boolean ret = false;
101
102 if ( obj == this )
103 {
104 ret = true;
105 }
106 else if ( obj == null )
107 {
108 ret = false;
109 }
110 else if ( obj.getClass().equals( this.getClass() ) )
111 {
112 if ( obj instanceof AbstractFatherBlock )
113 {
114 final AbstractFatherBlock a = (AbstractFatherBlock) obj;
115 ret = Arrays.equals( a.childBlocks, this.childBlocks );
116 }
117 }
118
119 return ret;
120 }
121
122
123 public int hashCode()
124 {
125 int result = 1;
126 if ( childBlocks != null )
127 {
128 for ( Block childBlock : childBlocks )
129 {
130 result += childBlock.hashCode();
131 }
132 }
133
134 return result;
135 }
136 }