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

File WikiParameter.java

 

Coverage histogram

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

Code metrics

20
30
8
1
127
71
20
0.67
3.75
8
2.5

Classes

Class Line # Actions
WikiParameter 28 30 0% 20 10
0.8275862382.8%
 

Contributing tests

This file is covered by 468 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    * A wiki parameter object.
24    *
25    * @version $Id: 05675fdd24cadfa6d5987fc85f8f77c2c1324714 $
26    * @since 4.0M1
27    */
 
28    public class WikiParameter
29    {
30    private String fKey;
31   
32    private String fStr;
33   
34    private Boolean fValid;
35   
36    private String fValue;
37   
 
38  18195 toggle public WikiParameter(String key, String value)
39    {
40  18195 fKey = key;
41  18195 fValue = value;
42    }
43   
 
44  0 toggle public WikiParameter(WikiParameter pair)
45    {
46  0 fKey = pair.getKey();
47  0 fValue = pair.getValue();
48    }
49   
50    /**
51    * @see java.lang.Object#equals(java.lang.Object)
52    */
 
53  12303 toggle public boolean equals(Object obj)
54    {
55  12303 if (obj == this) {
56  8382 return true;
57    }
58  3921 if (!(obj instanceof WikiParameter)) {
59  0 return false;
60    }
61  3921 WikiParameter pair = (WikiParameter) obj;
62  3921 return fKey.equals(pair.fKey)
63    && (fValue == pair.fValue || (fValue != null && fValue
64    .equals(pair.fValue)));
65    }
66   
67    /**
68    * @return the key
69    */
 
70  28365 toggle public String getKey()
71    {
72  28365 return fKey;
73    }
74   
75    /**
76    * @return the value
77    */
 
78  28264 toggle public String getValue()
79    {
80  28264 return fValue;
81    }
82   
83    /**
84    * @see java.lang.Object#hashCode()
85    */
 
86  16720 toggle public int hashCode()
87    {
88  16720 return fKey.hashCode() ^ (fValue != null ? fValue.hashCode() : 0);
89    }
90   
91    /**
92    * @return <code>true</code> if this key/value pair is valid
93    */
 
94  395 toggle public boolean isValid()
95    {
96  395 if (fValid == null) {
97  395 int len = (fKey != null) ? fKey.length() : 0;
98  395 boolean result = len > 0;
99  395 boolean delimiter = false;
100  1761 for (int i = 0; result && i < len; i++) {
101  1366 char ch = fKey.charAt(i);
102  1366 if (ch == ':') {
103  10 result = !delimiter && i > 0 && i < len - 1;
104  10 delimiter = true;
105  1356 } else if (ch == '.' || ch == '-') {
106  0 result = i > 0 && i < len - 1;
107    } else {
108  1356 result &= (i == 0 && Character.isLetter(ch))
109    || Character.isLetterOrDigit(ch);
110    }
111    }
112  395 fValid = result ? Boolean.TRUE : Boolean.FALSE;
113    }
114  395 return fValid == Boolean.TRUE;
115    }
116   
117    /**
118    * @see java.lang.Object#toString()
119    */
 
120  414 toggle public String toString()
121    {
122  414 if (fStr == null) {
123  408 fStr = fKey + "='" + WikiPageUtil.escapeXmlAttribute(fValue) + "'";
124    }
125  414 return fStr;
126    }
127    }