1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package com.xpn.xwiki.objects

File DateProperty.java

 

Coverage histogram

../../../../img/srcFileCovDistChart5.png
74% 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 22
0.4545%
 

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  788 toggle @Override
39    public Object getValue()
40    {
41  788 return this.value;
42    }
43   
 
44  272 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  272 Date date = (Date) value;
50  272 if (date != null && date.getClass() != Date.class) {
51  37 date = new Date(((Date) value).getTime());
52    }
53   
54  272 setValueDirty(date);
55  272 this.value = date;
56    }
57   
 
58  62 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  62 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  0 toggle @Override
76    public boolean equals(Object obj)
77    {
78    // Same Java object, they sure are equal.
79  0 if (this == obj) {
80  0 return true;
81    }
82   
83  0 if (!super.equals(obj)) {
84  0 return false;
85    }
86   
87  0 if (getValue() == null && ((DateProperty) obj).getValue() == null) {
88  0 return true;
89    }
90   
91  0 return getValue().equals(((DateProperty) obj).getValue());
92    }
93   
 
94  211 toggle @Override
95    public DateProperty clone()
96    {
97  211 return (DateProperty) super.clone();
98    }
99   
 
100  211 toggle @Override
101    protected void cloneInternal(BaseProperty clone)
102    {
103  211 DateProperty property = (DateProperty) clone;
104  211 property.setValue(getValue());
105    }
106    }