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

File WikiParameter.java

 

Coverage histogram

../../../../img/srcFileCovDistChart9.png
41% 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 471 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  305239 toggle public WikiParameter(String key, String value)
39    {
40  305237 fKey = key;
41  305237 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  10339 toggle public boolean equals(Object obj)
54    {
55  10339 if (obj == this) {
56  7685 return true;
57    }
58  2654 if (!(obj instanceof WikiParameter)) {
59  0 return false;
60    }
61  2654 WikiParameter pair = (WikiParameter) obj;
62  2654 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  369825 toggle public String getKey()
71    {
72  369825 return fKey;
73    }
74   
75    /**
76    * @return the value
77    */
 
78  369577 toggle public String getValue()
79    {
80  369579 return fValue;
81    }
82   
83    /**
84    * @see java.lang.Object#hashCode()
85    */
 
86  15352 toggle public int hashCode()
87    {
88  15352 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  350 toggle public boolean isValid()
95    {
96  350 if (fValid == null) {
97  350 int len = (fKey != null) ? fKey.length() : 0;
98  350 boolean result = len > 0;
99  350 boolean delimiter = false;
100  1505 for (int i = 0; result && i < len; i++) {
101  1155 char ch = fKey.charAt(i);
102  1155 if (ch == ':') {
103  10 result = !delimiter && i > 0 && i < len - 1;
104  10 delimiter = true;
105  1145 } else if (ch == '.' || ch == '-') {
106  0 result = i > 0 && i < len - 1;
107    } else {
108  1145 result &= (i == 0 && Character.isLetter(ch))
109    || Character.isLetterOrDigit(ch);
110    }
111    }
112  350 fValid = result ? Boolean.TRUE : Boolean.FALSE;
113    }
114  350 return fValid == Boolean.TRUE;
115    }
116   
117    /**
118    * @see java.lang.Object#toString()
119    */
 
120  369 toggle public String toString()
121    {
122  369 if (fStr == null) {
123  363 fStr = fKey + "='" + WikiPageUtil.escapeXmlAttribute(fValue) + "'";
124    }
125  369 return fStr;
126    }
127    }