/*
* Copyright 2013 Robert von Burg <eitch@eitchnet.ch>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package li.strolch.model.parameter;
import java.util.Date;
import li.strolch.model.StrolchValueType;
import li.strolch.model.visitor.ParameterVisitor;
import li.strolch.utils.dbc.DBC;
import li.strolch.utils.iso8601.ISO8601FormatFactory;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public class DateParameter extends AbstractParameter<Date> {
private static final long serialVersionUID = 0L;
private Date value;
/**
* Empty constructor
*/
public DateParameter() {
//
}
/**
* Default Constructor
*
* @param id
* @param name
* @param value
*/
public DateParameter(String id, String name, Date value) {
super(id, name);
setValue(value);
}
@Override
public String getValueAsString() {
return ISO8601FormatFactory.getInstance().formatDate(this.value);
}
@Override
public Date getValue() {
return this.value;
}
@Override
public void setValue(Date value) {
validateValue(value);
this.value = value;
}
@Override
public void setValueFromString(String valueAsString) {
setValue(parseFromString(valueAsString));
}
@Override
public String getType() {
return StrolchValueType.DATE.getType();
}
@Override
public DateParameter getClone() {
DateParameter clone = new DateParameter();
super.fillClone(clone);
clone.setValue(this.value);
return clone;
}
@Override
public <U> U accept(ParameterVisitor visitor) {
return visitor.visitDateParam(this);
}
public static Date parseFromString(String valueS) {
return ISO8601FormatFactory.getInstance().getDateFormat().parse(valueS);
}
@Override
public int compareTo(Parameter<?> o) {
DBC.PRE.assertEquals("Not same Parameter types!", this.getType(), o.getType());
return this.getValue().compareTo(((DateParameter) o).getValue());
}
}