001/*
002 * (C) Copyright 2014 Nuxeo SA (http://nuxeo.com/) and contributors.
003 *
004 * All rights reserved. This program and the accompanying materials
005 * are made available under the terms of the GNU Lesser General Public License
006 * (LGPL) version 2.1 which accompanies this distribution, and is available at
007 * http://www.gnu.org/licenses/lgpl-2.1.html
008 *
009 * This library is distributed in the hope that it will be useful,
010 * but WITHOUT ANY WARRANTY; without even the implied warranty of
011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012 * Lesser General Public License for more details.
013 *
014 * Contributors:
015 *     Benoit Delbosc
016 */
017package org.nuxeo.ecm.platform.query.core;
018
019import java.io.Serializable;
020
021import org.nuxeo.common.xmap.annotation.XNode;
022import org.nuxeo.common.xmap.annotation.XObject;
023import org.nuxeo.ecm.platform.query.api.AggregateRangeDateDefinition;
024
025/**
026 * @since 6.0
027 */
028@XObject("dateRange")
029public class AggregateRangeDateDescriptor extends AggregateRangeDescriptor implements AggregateRangeDateDefinition,
030        Serializable {
031
032    private static final long serialVersionUID = 1L;
033
034    public AggregateRangeDateDescriptor() {
035    }
036
037    public AggregateRangeDateDescriptor(String key, String from, String to) {
038        this.key = key;
039        fromDate = from;
040        toDate = to;
041    }
042
043    @XNode("@fromDate")
044    public String fromDate;
045
046    @XNode("@toDate")
047    public String toDate;
048
049    @Override
050    public String toString() {
051        return String.format("AggregateRangeDateDescriptor(%s, %s, %s)", key, fromDate, toDate);
052    }
053
054    @Override
055    public String getFromAsString() {
056        return fromDate;
057    }
058
059    @Override
060    public String getToAsString() {
061        return toDate;
062    }
063
064    @Override
065    public void setFrom(String from) {
066        fromDate = from;
067        this.from = null;
068    }
069
070    @Override
071    public void setTo(String to) {
072        toDate = to;
073        this.to = null;
074    }
075
076    @Override
077    public AggregateRangeDateDefinition clone() {
078        AggregateRangeDateDescriptor clone = new AggregateRangeDateDescriptor(key, fromDate, toDate);
079        return clone;
080    }
081}