1. Project Clover database Sat Feb 2 2019 06:45:20 CET
  2. Package org.xwiki.rendering.macro

File MacroId.java

 

Coverage histogram

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

Code metrics

6
13
7
1
123
54
10
0.77
1.86
7
1.43

Classes

Class Line # Actions
MacroId 40 13 0% 10 4
0.8461538684.6%
 

Contributing tests

This file is covered by 321 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.apache.commons.lang3.builder.EqualsBuilder;
23    import org.apache.commons.lang3.builder.HashCodeBuilder;
24    import org.xwiki.rendering.syntax.Syntax;
25   
26    /**
27    * Represents a Macro identifier. This is used when we need to pass a reference of a macro around without having to
28    * pass Macro instances; it's also required when we need to create a Macro instance from an identifier.
29    * <p>
30    * A Macro is identified by 2 parameters:
31    * </p>
32    * <ul>
33    * <li>a string representing a technical id (eg "toc")</li>
34    * <li>an optional syntax (can be null) if the macro is only available for a given syntax</li>
35    * </ul>
36    *
37    * @version $Id: 160c8cb04b086b17453c2f992c92ac47e7b857da $
38    * @since 2.0M3
39    */
 
40    public class MacroId
41    {
42    /**
43    * @see #getId()
44    */
45    private String id;
46   
47    /**
48    * @see #getSyntax()
49    */
50    private Syntax syntax;
51   
52    /**
53    * Constructor for macros registered for all syntaxes.
54    *
55    * @param id see {@link #getId()}
56    */
 
57  296545 toggle public MacroId(String id)
58    {
59  296510 this(id, null);
60    }
61   
62    /**
63    * Constructor for macros registered for a specific syntax only.
64    *
65    * @param id see {@link #getId()}
66    * @param syntax see {@link #getSyntax()}
67    */
 
68  902442 toggle public MacroId(String id, Syntax syntax)
69    {
70  902568 this.id = id;
71  902543 this.syntax = syntax;
72    }
73   
74    /**
75    * @return the technical id of the macro (eg "toc" for the TOC Macro)
76    */
 
77  2671392 toggle public String getId()
78    {
79  2671522 return this.id;
80    }
81   
82    /**
83    * @return the optional syntax (can be null) for which the macro represented by this id is available. If null then
84    * the macro is available for all syntaxes.
85    */
 
86  1257792 toggle public Syntax getSyntax()
87    {
88  1257890 return this.syntax;
89    }
90   
 
91  640410 toggle @Override
92    public String toString()
93    {
94  640421 return getId() + ((getSyntax() == null) ? "" : "/" + getSyntax().toIdString());
95    }
96   
 
97  5702 toggle @Override
98    public int hashCode()
99    {
100  5702 return new HashCodeBuilder(5, 3)
101    .append(getId())
102    .append(getSyntax())
103    .toHashCode();
104    }
105   
 
106  22 toggle @Override
107    public boolean equals(Object object)
108    {
109  22 if (object == this) {
110  0 return true;
111    }
112   
113  22 if (!(object instanceof MacroId)) {
114  0 return false;
115    }
116   
117  22 MacroId rhs = (MacroId) object;
118  22 return new EqualsBuilder()
119    .append(getId(), rhs.getId())
120    .append(getSyntax(), rhs.getSyntax())
121    .isEquals();
122    }
123    }