Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
AbstractFatherBlock |
|
| 2.7142857142857144;2,714 |
1 | package org.apache.maven.doxia.module.twiki.parser; | |
2 | ||
3 | /* | |
4 | * Licensed to the Apache Software Foundation (ASF) under one | |
5 | * or more contributor license agreements. See the NOTICE file | |
6 | * distributed with this work for additional information | |
7 | * regarding copyright ownership. The ASF licenses this file | |
8 | * to you under the Apache License, Version 2.0 (the | |
9 | * "License"); you may not use this file except in compliance | |
10 | * with the License. You may obtain a copy of the License at | |
11 | * | |
12 | * http://www.apache.org/licenses/LICENSE-2.0 | |
13 | * | |
14 | * Unless required by applicable law or agreed to in writing, | |
15 | * software distributed under the License is distributed on an | |
16 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | |
17 | * KIND, either express or implied. See the License for the | |
18 | * specific language governing permissions and limitations | |
19 | * under the License. | |
20 | */ | |
21 | ||
22 | import java.util.Arrays; | |
23 | ||
24 | import org.apache.maven.doxia.sink.Sink; | |
25 | ||
26 | /** | |
27 | * Generic Block for the Block that have child blocks. | |
28 | * | |
29 | * @author Juan F. Codagnone | |
30 | * @version $Id: AbstractFatherBlock.java 705065 2008-10-15 21:46:08Z vsiveton $ | |
31 | */ | |
32 | abstract class AbstractFatherBlock | |
33 | implements Block | |
34 | { | |
35 | /** | |
36 | * @see AbstractFatherBlock#AbstractFatherBlock(Block[]) | |
37 | */ | |
38 | private final Block[] childBlocks; | |
39 | ||
40 | /** | |
41 | * method called before traversing the childs | |
42 | * | |
43 | * @param sink a sink to fill | |
44 | */ | |
45 | abstract void before( Sink sink ); | |
46 | ||
47 | /** | |
48 | * method called after traversing the childs | |
49 | * | |
50 | * @param sink a sink to fill | |
51 | */ | |
52 | abstract void after( Sink sink ); | |
53 | ||
54 | /** | |
55 | * Creates the AbstractFatherBlock. | |
56 | * | |
57 | * @param childBlocks child blocks | |
58 | */ | |
59 | AbstractFatherBlock( final Block[] childBlocks ) | |
60 | 874 | { |
61 | 874 | if ( childBlocks == null ) |
62 | { | |
63 | 2 | throw new IllegalArgumentException( "argument can't be null" ); |
64 | } | |
65 | ||
66 | 2172 | for ( int i = 0; i < childBlocks.length; i++ ) |
67 | { | |
68 | 1300 | if ( childBlocks[i] == null ) |
69 | { | |
70 | 0 | throw new IllegalArgumentException( "bucket " + i + " can't be null" ); |
71 | } | |
72 | } | |
73 | 872 | this.childBlocks = childBlocks; |
74 | 872 | } |
75 | ||
76 | /** {@inheritDoc} */ | |
77 | public final void traverse( final Sink sink ) | |
78 | { | |
79 | 482 | before( sink ); |
80 | 1282 | for ( int i = 0; i < childBlocks.length; i++ ) |
81 | { | |
82 | 800 | Block block = childBlocks[i]; |
83 | ||
84 | 800 | block.traverse( sink ); |
85 | } | |
86 | 482 | after( sink ); |
87 | 482 | } |
88 | ||
89 | /** | |
90 | * Returns the childBlocks. | |
91 | * | |
92 | * @return <code>Block[]</code> with the childBlocks. | |
93 | */ | |
94 | public final Block[] getBlocks() | |
95 | { | |
96 | 74 | return childBlocks; |
97 | } | |
98 | ||
99 | /** {@inheritDoc}*/ | |
100 | public boolean equals( final Object obj ) | |
101 | { | |
102 | 164 | boolean ret = false; |
103 | ||
104 | 164 | if ( obj == this ) |
105 | { | |
106 | 6 | ret = true; |
107 | } | |
108 | 158 | else if ( obj == null ) |
109 | { | |
110 | 6 | ret = false; |
111 | } | |
112 | 152 | else if ( obj.getClass().equals( this.getClass() ) ) |
113 | { | |
114 | 150 | if ( obj instanceof AbstractFatherBlock ) |
115 | { | |
116 | 150 | final AbstractFatherBlock a = (AbstractFatherBlock) obj; |
117 | 150 | ret = Arrays.equals( a.childBlocks, this.childBlocks ); |
118 | } | |
119 | } | |
120 | ||
121 | 164 | return ret; |
122 | } | |
123 | ||
124 | /** {@inheritDoc}*/ | |
125 | public int hashCode() | |
126 | { | |
127 | 12 | int result = 1; |
128 | 12 | if ( childBlocks != null ) |
129 | { | |
130 | 24 | for ( int i = 0; i < childBlocks.length; i++ ) |
131 | { | |
132 | 12 | result += childBlocks[i].hashCode(); |
133 | } | |
134 | } | |
135 | ||
136 | 12 | return result; |
137 | } | |
138 | } |