/* * See the NOTICE file distributed with this work for additional * information regarding copyright ownership. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package com.xpn.xwiki.objects; import java.util.Date; import org.xwiki.xar.internal.property.DateXarObjectPropertySerializer; /** * Represents a date property. * * @version $Id: f1f6d3a619f99ccbb8861166ec6dd2aa43f899ed $ */ public class DateProperty extends BaseProperty implements Cloneable { /** * The property value. */ private Date value; @Override public Object getValue() { return this.value; } @Override public void setValue(Object value) { // Make sure to store a Date and not some extended Date or it's going to be a nightmare to compare between // them Date date = (Date) value; if (date != null && date.getClass() != Date.class) { date = new Date(((Date) value).getTime()); } setValueDirty(date); this.value = date; } @Override public String toText() { // FIXME: The value of a date property should be serialized using the date timestamp or the date format // specified in the XClass the date property belongs to. return getValue() == null ? "" : DateXarObjectPropertySerializer.DEFAULT_FORMAT.format(getValue()); } @Override public int hashCode() { final int prime = 31; int result = super.hashCode(); result = prime * result + ((this.value == null) ? 0 : this.value.hashCode()); return result; } @Override public boolean equals(Object obj) { // Same Java object, they sure are equal. if (this == obj) { return true; } if (!super.equals(obj)) { return false; } if (getValue() == null && ((DateProperty) obj).getValue() == null) { return true; } return getValue().equals(((DateProperty) obj).getValue()); } @Override public DateProperty clone() { return (DateProperty) super.clone(); } @Override protected void cloneInternal(BaseProperty clone) { DateProperty property = (DateProperty) clone; property.setValue(getValue()); } }