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

File DateProperty.java

 

Coverage histogram

../../../../img/srcFileCovDistChart8.png
56% of files have more coverage

Code metrics

12
21
7
1
106
60
15
0.71
3
7
2.14

Classes

Class Line # Actions
DateProperty 31 21 0% 15 11
0.72572.5%
 

Contributing tests

This file is covered by 5 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;
21   
22    import java.util.Date;
23   
24    import org.xwiki.xar.internal.property.DateXarObjectPropertySerializer;
25   
26    /**
27    * Represents a date property.
28    *
29    * @version $Id: f1f6d3a619f99ccbb8861166ec6dd2aa43f899ed $
30    */
 
31    public class DateProperty extends BaseProperty implements Cloneable
32    {
33    /**
34    * The property value.
35    */
36    private Date value;
37   
 
38  56581 toggle @Override
39    public Object getValue()
40    {
41  56580 return this.value;
42    }
43   
 
44  25033 toggle @Override
45    public void setValue(Object value)
46    {
47    // Make sure to store a Date and not some extended Date or it's going to be a nightmare to compare between
48    // them
49  25032 Date date = (Date) value;
50  25033 if (date != null && date.getClass() != Date.class) {
51  563 date = new Date(((Date) value).getTime());
52    }
53   
54  25033 setValueDirty(date);
55  25033 this.value = date;
56    }
57   
 
58  1159 toggle @Override
59    public String toText()
60    {
61    // FIXME: The value of a date property should be serialized using the date timestamp or the date format
62    // specified in the XClass the date property belongs to.
63  1159 return getValue() == null ? "" : DateXarObjectPropertySerializer.DEFAULT_FORMAT.format(getValue());
64    }
65   
 
66  0 toggle @Override
67    public int hashCode()
68    {
69  0 final int prime = 31;
70  0 int result = super.hashCode();
71  0 result = prime * result + ((this.value == null) ? 0 : this.value.hashCode());
72  0 return result;
73    }
74   
 
75  18 toggle @Override
76    public boolean equals(Object obj)
77    {
78    // Same Java object, they sure are equal.
79  18 if (this == obj) {
80  0 return true;
81    }
82   
83  18 if (!super.equals(obj)) {
84  0 return false;
85    }
86   
87  18 if (getValue() == null && ((DateProperty) obj).getValue() == null) {
88  4 return true;
89    }
90   
91  14 return getValue().equals(((DateProperty) obj).getValue());
92    }
93   
 
94  23945 toggle @Override
95    public DateProperty clone()
96    {
97  23945 return (DateProperty) super.clone();
98    }
99   
 
100  23945 toggle @Override
101    protected void cloneInternal(BaseProperty clone)
102    {
103  23945 DateProperty property = (DateProperty) clone;
104  23944 property.setValue(getValue());
105    }
106    }