Clover Coverage Report - XWiki Rendering - Parent POM 4.0-SNAPSHOT (Aggregated)
Coverage timestamp: Mon Mar 12 2012 18:03:13 CET
../../../../img/srcFileCovDistChart9.png 55% of files have more coverage
18   127   13   2.57
10   56   0.72   7
7     1.86  
1    
 
  MacroId       Line # 38 18 0% 13 5 85.7% 0.85714287
 
  (109)
 
1    /*
2    * See the NOTICE file distributed with this work for additional
3    * information regarding copyright ownership.
4    *
5    * This is free software; you can redistribute it and/or modify it
6    * under the terms of the GNU Lesser General Public License as
7    * published by the Free Software Foundation; either version 2.1 of
8    * the License, or (at your option) any later version.
9    *
10    * This software is distributed in the hope that it will be useful,
11    * but WITHOUT ANY WARRANTY; without even the implied warranty of
12    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13    * Lesser General Public License for more details.
14    *
15    * You should have received a copy of the GNU Lesser General Public
16    * License along with this software; if not, write to the Free
17    * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18    * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
19    */
20    package org.xwiki.rendering.macro;
21   
22    import org.xwiki.rendering.syntax.Syntax;
23   
24    /**
25    * Represents a Macro identifier. This is used when we need to pass a reference of a macro around without having to
26    * pass Macro instances; it's also required when we need to create a Macro instance from an identifier.
27    * <p>
28    * A Macro is identified by 2 parameters:
29    * <ul>
30    * <li>a string representing a technical id (eg "toc")</li>
31    * <li>an optional syntax (can be null) if the macro is only available for a given syntax</li>
32    * </ul>
33    * </p>
34    *
35    * @version $Id: 603b517f34e5d9dcca7208dbd2eb331ec5565a2a $
36    * @since 2.0M3
37    */
 
38    public class MacroId
39    {
40    /**
41    * @see #getId()
42    */
43    private String id;
44   
45    /**
46    * @see #getSyntax()
47    */
48    private Syntax syntax;
49   
50    /**
51    * Constructor for macros registered for all syntaxes.
52    *
53    * @param id see {@link #getId()}
54    */
 
55  229 toggle public MacroId(String id)
56    {
57  229 this(id, null);
58    }
59   
60    /**
61    * Constructor for macros registered for a specific syntax only.
62    *
63    * @param id see {@link #getId()}
64    * @param syntax see {@link #getSyntax()}
65    */
 
66  1411 toggle public MacroId(String id, Syntax syntax)
67    {
68  1411 this.id = id;
69  1411 this.syntax = syntax;
70    }
71   
72    /**
73    * @return the technical id of the macro (eg "toc" for the TOC Macro)
74    */
 
75  2712 toggle public String getId()
76    {
77  2712 return this.id;
78    }
79   
80    /**
81    * @return the optional syntax (can be null) for which the macro represented by this id is available. If null
82    * then the macro is available for all syntaxes.
83    */
 
84  2642 toggle public Syntax getSyntax()
85    {
86  2642 return this.syntax;
87    }
88   
 
89  1287 toggle @Override
90    public String toString()
91    {
92  1287 return getId() + ((getSyntax() == null) ? "" : "/" + getSyntax().toIdString());
93    }
94   
 
95  119 toggle @Override
96    public int hashCode()
97    {
98    // Random number. See http://www.technofundo.com/tech/java/equalhash.html for the detail of this
99    // algorithm.
100  119 int hash = 7;
101  119 hash = 31 * hash + (null == getId() ? 0 : getId().hashCode());
102  119 hash = 31 * hash + (null == getSyntax() ? 0 : getSyntax().hashCode());
103  119 return hash;
104    }
105   
 
106  6 toggle @Override
107    public boolean equals(Object object)
108    {
109  6 boolean result;
110   
111    // See http://www.technofundo.com/tech/java/equalhash.html for the detail of this algorithm.
112  6 if (this == object) {
113  0 result = true;
114    } else {
115  6 if ((object == null) || (object.getClass() != this.getClass())) {
116  0 result = false;
117    } else {
118  6 MacroId macroId = (MacroId) object;
119  6 result =
120    (getId() == macroId.getId() || (getId() != null && getId().equals(macroId.getId())))
121    && (getSyntax() == macroId.getSyntax() || (getSyntax() != null && getSyntax().equals(
122    macroId.getSyntax())));
123    }
124    }
125  6 return result;
126    }
127    }