Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
ListItemBlock |
|
| 2.5714285714285716;2,571 |
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 org.apache.maven.doxia.sink.Sink; | |
23 | ||
24 | /** | |
25 | * Block that represents the item in a list | |
26 | * | |
27 | * @author Juan F. Codagnone | |
28 | * @version $Id: ListItemBlock.java 763762 2009-04-09 18:19:56Z ltheussl $ | |
29 | */ | |
30 | class ListItemBlock | |
31 | extends AbstractFatherBlock | |
32 | { | |
33 | private final ListBlock innerList; | |
34 | ||
35 | /** | |
36 | * @see #ListItemBlock(Block[], ListBlock) | |
37 | */ | |
38 | ListItemBlock( final Block[] blocks ) | |
39 | { | |
40 | 210 | this( blocks, null ); |
41 | 210 | } |
42 | ||
43 | /** | |
44 | * Creates the ListItemBlock. | |
45 | * | |
46 | * @param blocks text block, not null. | |
47 | * @param innerList child list | |
48 | */ | |
49 | ListItemBlock( final Block[] blocks, final ListBlock innerList ) | |
50 | { | |
51 | 280 | super( blocks ); |
52 | 280 | this.innerList = innerList; |
53 | 280 | } |
54 | ||
55 | /** {@inheritDoc} */ | |
56 | final void before( final Sink sink ) | |
57 | { | |
58 | 200 | sink.listItem(); |
59 | 200 | } |
60 | ||
61 | /** {@inheritDoc} */ | |
62 | final void after( final Sink sink ) | |
63 | { | |
64 | 200 | if ( innerList != null ) |
65 | { | |
66 | 52 | innerList.traverse( sink ); |
67 | } | |
68 | 200 | sink.listItem_(); |
69 | 200 | } |
70 | ||
71 | /** | |
72 | * Returns the innerList. | |
73 | * | |
74 | * @return <code>UnorderedListBlock</code> with the innerList. | |
75 | */ | |
76 | final ListBlock getInnerList() | |
77 | { | |
78 | 2 | return innerList; |
79 | } | |
80 | ||
81 | /** {@inheritDoc} */ | |
82 | public final boolean equals( final Object obj ) | |
83 | { | |
84 | 38 | boolean ret = false; |
85 | ||
86 | 38 | if ( obj == this ) |
87 | { | |
88 | 6 | ret = true; |
89 | } | |
90 | 32 | else if ( obj == null || this == null ) |
91 | { | |
92 | 6 | ret = false; |
93 | } | |
94 | 26 | else if ( obj instanceof ListItemBlock ) |
95 | { | |
96 | 26 | final ListItemBlock li = (ListItemBlock) obj; |
97 | 26 | if ( this.innerList == null && li.innerList == null ) |
98 | { | |
99 | 22 | ret = super.equals( li ); |
100 | } | |
101 | 4 | else if ( this.innerList == null && li.innerList != null ) |
102 | { | |
103 | 0 | ret = false; |
104 | } | |
105 | else | |
106 | { | |
107 | 4 | ret = this.innerList.equals( li.innerList ) && super.equals( li ); |
108 | } | |
109 | } | |
110 | ||
111 | 38 | return ret; |
112 | } | |
113 | ||
114 | /** {@inheritDoc} */ | |
115 | public final int hashCode() | |
116 | { | |
117 | 4 | final int magic1 = 17; |
118 | 4 | final int magic2 = 37; |
119 | ||
120 | 4 | return magic1 + magic2 * super.hashCode() + ( innerList == null ? 0 : magic2 * innerList.hashCode() ); |
121 | } | |
122 | } |