View Javadoc
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   */
29  class ListItemBlock
30      extends AbstractFatherBlock
31  {
32      private final ListBlock innerList;
33  
34      /**
35       * @see #ListItemBlock(Block[], ListBlock)
36       */
37      ListItemBlock( final Block[] blocks )
38      {
39          this( blocks, null );
40      }
41  
42      /**
43       * Creates the ListItemBlock.
44       *
45       * @param blocks    text block, not null.
46       * @param innerList child list
47       */
48      ListItemBlock( final Block[] blocks, final ListBlock innerList )
49      {
50          super( blocks );
51          this.innerList = innerList;
52      }
53  
54      /** {@inheritDoc} */
55      final void before( final Sink sink )
56      {
57          sink.listItem();
58      }
59  
60      /** {@inheritDoc} */
61      final void after( final Sink sink )
62      {
63          if ( innerList != null )
64          {
65              innerList.traverse( sink );
66          }
67          sink.listItem_();
68      }
69  
70      /**
71       * Returns the innerList.
72       *
73       * @return <code>UnorderedListBlock</code> with the innerList.
74       */
75      final ListBlock getInnerList()
76      {
77          return innerList;
78      }
79  
80      /** {@inheritDoc} */
81      public final boolean equals( final Object obj )
82      {
83          boolean ret = false;
84  
85          if ( obj == this )
86          {
87              ret = true;
88          }
89          else if ( obj == null || this == null )
90          {
91              ret = false;
92          }
93          else if ( obj instanceof ListItemBlock )
94          {
95              final ListItemBlock li = (ListItemBlock) obj;
96              if ( this.innerList == null && li.innerList == null )
97              {
98                  ret = super.equals( li );
99              }
100             else if ( this.innerList == null && li.innerList != null )
101             {
102                 ret = false;
103             }
104             else
105             {
106                 ret = this.innerList.equals( li.innerList ) && super.equals( li );
107             }
108         }
109 
110         return ret;
111     }
112 
113     /**
114      * {@inheritDoc}
115      *
116      * @return a int.
117      */
118     public final int hashCode()
119     {
120         final int magic1 = 17;
121         final int magic2 = 37;
122 
123         return magic1 + magic2 * super.hashCode() + ( innerList == null ? 0 : magic2 * innerList.hashCode() );
124     }
125 }