Coverage Report - org.apache.maven.doxia.module.twiki.parser.WikiWordBlock
 
Classes in this File Line Coverage Branch Coverage Complexity
WikiWordBlock
80%
20/25
78%
11/14
2,167
 
 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  
  * Represent a WikiWord
 26  
  *
 27  
  * @author Juan F. Codagnone
 28  
  * @version $Id: WikiWordBlock.java 709605 2008-10-31 23:57:03Z hboutemy $
 29  
  */
 30  
 class WikiWordBlock
 31  
     implements Block
 32  
 {
 33  
     /**
 34  
      * the wiki word
 35  
      */
 36  
     private final String wikiword;
 37  
 
 38  
     /**
 39  
      * content to show in the wiki word link
 40  
      */
 41  
     private final Block content;
 42  
 
 43  
     /**
 44  
      * Resolves WikiWord links
 45  
      */
 46  
     private final WikiWordLinkResolver wikiWordLinkResolver;
 47  
 
 48  
     /**
 49  
      * @see #WikiWordBlock(String, String)
 50  
      * @param aWikiword the wikiWord
 51  
      * @param resolver responsible of resolving the link to the wikiWord
 52  
      */
 53  
     WikiWordBlock( final String aWikiword, final WikiWordLinkResolver resolver )
 54  
     {
 55  16
         this( aWikiword, aWikiword, resolver );
 56  16
     }
 57  
 
 58  
     /**
 59  
      * Creates the WikiWordBlock.
 60  
      *
 61  
      * @param aWikiword the wiki word
 62  
      * @param aText text to show in the wiki link
 63  
      * @param resolver responsible of resolving the link to the wikiWord
 64  
      * @throws IllegalArgumentException if the wikiword is <code>null</code>
 65  
      * @deprecated
 66  
      */
 67  
     WikiWordBlock( final String aWikiword, final String aText, final WikiWordLinkResolver resolver )
 68  
     {
 69  16
         this( aWikiword, new TextBlock( aText ), resolver );
 70  16
     }
 71  
 
 72  
     /**
 73  
      * Creates the WikiWordBlock.
 74  
      *
 75  
      * @param aWikiword the wiki word
 76  
      * @param content content to show in the wiki link
 77  
      * @param resolver responsible of resolving the link to the wikiWord
 78  
      * @throws IllegalArgumentException if the wikiword is <code>null</code>
 79  
      */
 80  
     WikiWordBlock( final String aWikiword, final Block content, final WikiWordLinkResolver resolver )
 81  33
     {
 82  33
         if ( aWikiword == null || content == null || resolver == null )
 83  
         {
 84  0
             throw new IllegalArgumentException( "arguments can't be null" );
 85  
         }
 86  33
         this.wikiword = aWikiword;
 87  33
         this.content = content;
 88  33
         this.wikiWordLinkResolver = resolver;
 89  33
     }
 90  
 
 91  
     /** {@inheritDoc} */
 92  
     public final void traverse( final Sink sink )
 93  
     {
 94  0
         sink.link( wikiWordLinkResolver.resolveLink( wikiword ) );
 95  0
         content.traverse( sink );
 96  0
         sink.link_();
 97  0
     }
 98  
 
 99  
     /** {@inheritDoc} */
 100  
     public final boolean equals( final Object obj )
 101  
     {
 102  39
         boolean ret = false;
 103  
 
 104  39
         if ( obj == this )
 105  
         {
 106  9
             ret = true;
 107  
         }
 108  30
         else if ( obj instanceof WikiWordBlock )
 109  
         {
 110  21
             final WikiWordBlock w = (WikiWordBlock) obj;
 111  21
             ret = wikiword.equals( w.wikiword ) && content.equals( w.content );
 112  
         }
 113  
 
 114  39
         return ret;
 115  
     }
 116  
 
 117  
     /** {@inheritDoc} */
 118  
     public final int hashCode()
 119  
     {
 120  6
         final int magic1 = 17;
 121  6
         final int magic2 = 37;
 122  
 
 123  6
         return magic1 + magic2 * wikiword.hashCode() + magic2 * content.hashCode();
 124  
     }
 125  
 }