1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package org.xwiki.rendering.macro

File MacroId.java

 

Coverage histogram

../../../../img/srcFileCovDistChart9.png
38% of files have more coverage

Code metrics

10
18
7
1
127
56
13
0.72
2.57
7
1.86

Classes

Class Line # Actions
MacroId 38 18 0% 13 5
0.8571428785.7%
 

Contributing tests

This file is covered by 280 tests. .

Source view

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    * </p>
30    * <ul>
31    * <li>a string representing a technical id (eg "toc")</li>
32    * <li>an optional syntax (can be null) if the macro is only available for a given syntax</li>
33    * </ul>
34    *
35    * @version $Id: 302d45f26321b9f1f82da23aca1d39809544b80e $
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  10455 toggle public MacroId(String id)
56    {
57  10455 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  32141 toggle public MacroId(String id, Syntax syntax)
67    {
68  32142 this.id = id;
69  32142 this.syntax = syntax;
70    }
71   
72    /**
73    * @return the technical id of the macro (eg "toc" for the TOC Macro)
74    */
 
75  92574 toggle public String getId()
76    {
77  92574 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 then
82    * the macro is available for all syntaxes.
83    */
 
84  44355 toggle public Syntax getSyntax()
85    {
86  44355 return this.syntax;
87    }
88   
 
89  22715 toggle @Override
90    public String toString()
91    {
92  22716 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  15 toggle @Override
107    public boolean equals(Object object)
108    {
109  15 boolean result;
110   
111    // See http://www.technofundo.com/tech/java/equalhash.html for the detail of this algorithm.
112  15 if (this == object) {
113  0 result = true;
114    } else {
115  15 if ((object == null) || (object.getClass() != this.getClass())) {
116  0 result = false;
117    } else {
118  15 MacroId macroId = (MacroId) object;
119  15 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  15 return result;
126    }
127    }