001/*
002 * (C) Copyright 2014 Nuxeo SA (http://nuxeo.com/) and others.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *     http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 *
016 * Contributors:
017 *     Benoit Delbosc
018 */
019package org.nuxeo.ecm.platform.query.core;
020
021import java.io.Serializable;
022
023import org.nuxeo.common.xmap.annotation.XNode;
024import org.nuxeo.common.xmap.annotation.XObject;
025import org.nuxeo.ecm.platform.query.api.AggregateRangeDateDefinition;
026
027/**
028 * @since 6.0
029 */
030@XObject("dateRange")
031public class AggregateRangeDateDescriptor extends AggregateRangeDescriptor implements AggregateRangeDateDefinition,
032        Serializable {
033
034    private static final long serialVersionUID = 1L;
035
036    public AggregateRangeDateDescriptor() {
037    }
038
039    public AggregateRangeDateDescriptor(String key, String from, String to) {
040        this.key = key;
041        fromDate = from;
042        toDate = to;
043    }
044
045    @XNode("@fromDate")
046    public String fromDate;
047
048    @XNode("@toDate")
049    public String toDate;
050
051    @Override
052    public String toString() {
053        return String.format("AggregateRangeDateDescriptor(%s, %s, %s)", key, fromDate, toDate);
054    }
055
056    @Override
057    public String getFromAsString() {
058        return fromDate;
059    }
060
061    @Override
062    public String getToAsString() {
063        return toDate;
064    }
065
066    @Override
067    public void setFrom(String from) {
068        fromDate = from;
069        this.from = null;
070    }
071
072    @Override
073    public void setTo(String to) {
074        toDate = to;
075        this.to = null;
076    }
077
078    @Override
079    public AggregateRangeDateDefinition clone() {
080        AggregateRangeDateDescriptor clone = new AggregateRangeDateDescriptor(key, fromDate, toDate);
081        return clone;
082    }
083}