1. Project Clover database Sat Feb 2 2019 06:45:20 CET
  2. Package com.xpn.xwiki.objects.classes

File ListItem.java

 

Coverage histogram

../../../../../img/srcFileCovDistChart10.png
0% of files have more coverage

Code metrics

0
17
13
1
176
81
13
0.76
1.31
13
1

Classes

Class Line # Actions
ListItem 31 17 0% 13 0
1.0100%
 

Contributing tests

This file is covered by 11 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 com.xpn.xwiki.objects.classes;
21   
22    import java.util.Comparator;
23   
24    import org.apache.commons.collections4.ComparatorUtils;
25   
26    /**
27    * An entry in a List or in a Tree.
28    *
29    * @version $Id: 56adb64862167c6bd3e1db8582130fa6a6c098aa $
30    */
 
31    public class ListItem
32    {
33    /** Comparator that orders two strings in their natural order, keeping nulls at the end. */
34    private static final Comparator<String> BASE_COMPARATOR = ComparatorUtils
35    .nullHighComparator(new Comparator<String>()
36    {
37    /**
38    * Case insensitive comparison of two Strings.
39    *
40    * @param o1 the first item to be compared.
41    * @param o2 the second item to be compared.
42    * @return a negative integer, zero, or a positive integer as the first argument is less than, equal to, or
43    * greater than the second.
44    */
 
45  373 toggle @Override
46    public int compare(String o1, String o2)
47    {
48  373 return o1.compareToIgnoreCase(o2);
49    }
50    });
51   
52    /** Comparator that orders list items on their identifiers, keeping null items at the end. */
53    protected static final Comparator<ListItem> ID_COMPARATOR = ComparatorUtils
54    .nullHighComparator(new Comparator<ListItem>()
55    {
56    /**
57    * Sorts the items on their ID: the option with the lower ID (case insensitive String comparison) will be
58    * placed before the other one.
59    *
60    * @param o1 the first item to be compared.
61    * @param o2 the second item to be compared.
62    * @return a negative integer, zero, or a positive integer as the first argument is less than, equal to, or
63    * greater than the second.
64    */
 
65  15 toggle @Override
66    public int compare(ListItem o1, ListItem o2)
67    {
68  15 return BASE_COMPARATOR.compare(o1.getId(), o2.getId());
69    }
70    });
71   
72    /** Comparator that orders list items on their values, keeping null items at the end. */
73    protected static final Comparator<ListItem> VALUE_COMPARATOR = ComparatorUtils
74    .nullHighComparator(new Comparator<ListItem>()
75    {
76    /**
77    * Sorts the items on their value: the option with the lower value (case insensitive String comparison) will
78    * be placed before the other one.
79    *
80    * @param o1 the first item to be compared.
81    * @param o2 the second item to be compared.
82    * @return a negative integer, zero, or a positive integer as the first argument is less than, equal to, or
83    * greater than the second.
84    */
 
85  358 toggle @Override
86    public int compare(ListItem o1, ListItem o2)
87    {
88  358 return BASE_COMPARATOR.compare(o1.getValue(), o2.getValue());
89    }
90    });
91   
92    /** A unique identifier of this item, the actual value stored in the database when selecting items from a list. */
93    private String id = "";
94   
95    /** A user-friendly value that gets displayed in the user interface, representing this item. */
96    private String value = "";
97   
98    /** An optional reference to another item that allows to build parent-child relations, forming a tree. */
99    private String parent = "";
100   
101    /**
102    * Constructor that initializes both the {@link #id internal ID} and the {@link #value displayed value} with the
103    * same value, leaving the {@link #parent} field empty.
104    *
105    * @param id the value to use for the id and the displayed value
106    */
 
107  36 toggle public ListItem(String id)
108    {
109  36 this.setId(id);
110  36 this.setValue(id);
111    }
112   
113    /**
114    * Constructor that initializes the {@link #id internal ID} and the {@link #value displayed value}, leaving the
115    * {@link #parent} field empty.
116    *
117    * @param id the value to use for the internal id
118    * @param value the value to use for the displayed value
119    */
 
120  119844 toggle public ListItem(String id, String value)
121    {
122  119844 this.setId(id);
123  119844 this.setValue(value);
124    }
125   
126    /**
127    * Constructor that initializes all of the {@link #id internal ID}, the {@link #value displayed value}, and the
128    * {@link #parent} fields.
129    *
130    * @param id the value to use for the internal id
131    * @param value the value to use for the displayed value
132    * @param parent the value to use for the item's parent
133    */
 
134  3 toggle public ListItem(String id, String value, String parent)
135    {
136  3 this.setId(id);
137  3 this.setValue(value);
138  3 this.setParent(parent);
139    }
140   
 
141  1622 toggle public String getId()
142    {
143  1622 return this.id;
144    }
145   
 
146  119883 toggle public void setId(String id)
147    {
148  119883 this.id = id;
149    }
150   
 
151  47708 toggle public String getValue()
152    {
153  47708 return this.value;
154    }
155   
 
156  119883 toggle public void setValue(String value)
157    {
158  119883 this.value = value;
159    }
160   
 
161  19 toggle public String getParent()
162    {
163  19 return this.parent;
164    }
165   
 
166  3 toggle public void setParent(String parent)
167    {
168  3 this.parent = parent;
169    }
170   
 
171  16 toggle @Override
172    public String toString()
173    {
174  16 return "[" + getId() + ", " + getValue() + ", " + getParent() + "]";
175    }
176    }