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

File WikiReference.java

 

Coverage histogram

../../../../img/srcFileCovDistChart6.png
72% of files have more coverage

Code metrics

12
28
10
1
204
78
16
0.57
2.8
10
1.6

Classes

Class Line # Actions
WikiReference 37 28 0% 16 24
0.5252%
 

Contributing tests

This file is covered by 283 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.wikimodel;
21   
22    /**
23    * This object represents an individual reference in the wiki document. A
24    * reference contains the following parts:
25    * <ul>
26    * <li>link (mandatory) - it can b e a hyperlink, URI or a wiki page name</li>
27    * <li>label (optional) - a human readable label associated with this reference</li>
28    * <li>parameters (optional) - additional wiki parameters associated with the
29    * reference. It can be a style name, a target of the link or something else.</li>
30    * </ul>
31    * Instances of this type are immutable so they can be shared between various
32    * contexts (like threads, parser instances and so on).
33    *
34    * @version $Id: 596c8202ad9bda50d9b41dccddaa9ab355182cd6 $
35    * @since 4.0M1
36    */
 
37    public class WikiReference
38    {
39    /**
40    * A human-readable label associated with this reference. This is an
41    * optional part of the reference.
42    */
43    private final String fLabel;
44   
45    /**
46    * The link corresponding to this reference. It can be a hyperlink, URI or a
47    * wiki page name. This is a mandatory part of the reference.
48    */
49    private final String fLink;
50   
51    /**
52    * Additional parameters associated with this reference. This is an optional
53    * part of the reference.
54    */
55    private final WikiParameters fParameters;
56   
57    /**
58    * This field is used only by {@link #toString()} method to cache the
59    * resulting string representation of this reference.
60    */
61    private String fString;
62   
63    /**
64    * This constructor is used to initialize only the link part of the
65    * reference
66    *
67    * @param link the link corresponding to the reference; it can be a
68    * hyperlink, URI or a wiki name
69    */
 
70  41 toggle public WikiReference(String link)
71    {
72  41 this(link, null, null);
73    }
74   
75    /**
76    * This constructor is used to initialize the link and label of this
77    * reference
78    *
79    * @param link the link corresponding to the reference; it can be a
80    * hyperlink, URI or a wiki name
81    * @param label the label corresponding to this reference
82    */
 
83  6 toggle public WikiReference(String link, String label)
84    {
85  6 this(link, label, null);
86    }
87   
88    /**
89    * This constructor is used to initialize all internal fields of this class.
90    *
91    * @param link the link corresponding to the reference; it can be a
92    * hyperlink, URI or a wiki name
93    * @param label the label corresponding to this reference
94    * @param params a list of parameters of this reference
95    */
 
96  28573 toggle public WikiReference(String link, String label, WikiParameters params)
97    {
98  541 assert link != null : "Link can not be null";
99  28574 fLink = link;
100  28574 fLabel = label;
101  28574 if (params == null) {
102  47 params = WikiParameters.EMPTY;
103    }
104  28574 fParameters = params;
105    }
106   
107    /**
108    * This constructor is used to initialize the link and params fields
109    *
110    * @param link the link corresponding to the reference; it can be a
111    * hyperlink, URI or a wiki name
112    * @param params a list of parameters of this reference
113    */
 
114  0 toggle public WikiReference(String link, WikiParameters params)
115    {
116  0 this(link, null, params);
117    }
118   
119    /**
120    * @see java.lang.Object#equals(java.lang.Object)
121    */
 
122  9 toggle @Override
123    public boolean equals(Object obj)
124    {
125  9 if (this == obj) {
126  0 return true;
127    }
128  9 if (!(obj instanceof WikiReference)) {
129  0 return false;
130    }
131  9 WikiReference r = (WikiReference) obj;
132  9 return fLink.equals(r.fLink)
133    && ((fLabel == r.fLabel) || (fLabel != null && fLabel
134    .equals(r.fLabel)))
135    && fParameters.equals(r.fParameters);
136    }
137   
138    /**
139    * Returns a human-readable label associated with this reference. This is an
140    * optional part of the reference so this method can return
141    * <code>null</code>.
142    *
143    * @return a human-readable label associated with this reference
144    */
 
145  26826 toggle public String getLabel()
146    {
147  26826 return fLabel;
148    }
149   
150    /**
151    * Returns a link of this reference. It can be an a hyperlink, an URI or a
152    * wiki name. This part of the reference is mandatory so the returned value
153    * is not empty.
154    *
155    * @return a link associated with this reference
156    */
 
157  55140 toggle public String getLink()
158    {
159  55141 return fLink;
160    }
161   
162    /**
163    * Returns parameters associated with this reference. This method never
164    * returns <code>null</code>. If there is no specific parameters for the
165    * reference then this method returns the {@link WikiParameters#EMPTY}
166    * instance.
167    *
168    * @return a non-<code>null</code> object representing parameters of this
169    * link
170    */
 
171  28556 toggle public WikiParameters getParameters()
172    {
173  28556 return fParameters;
174    }
175   
176    /**
177    * @see java.lang.Object#hashCode()
178    */
 
179  0 toggle @Override
180    public int hashCode()
181    {
182  0 return toString().hashCode();
183    }
184   
185    /**
186    * @see java.lang.Object#toString()
187    */
 
188  0 toggle @Override
189    public String toString()
190    {
191  0 if (fString == null) {
192  0 StringBuffer buf = new StringBuffer();
193  0 buf.append(fLink);
194  0 if (fLabel != null) {
195  0 buf.append('(');
196  0 buf.append(fLabel);
197  0 buf.append(')');
198    }
199  0 buf.append(fParameters);
200  0 fString = buf.toString();
201    }
202  0 return fString;
203    }
204    }