    001    //$HeadURL: https://svn.wald.intevation.org/svn/deegree/base/branches/2.4_testing/src/org/deegree/datatypes/time/TimeSequence.java $
    002    /*----------------------------------------------------------------------------
    003     This file is part of deegree, http://deegree.org/
    004     Copyright (C) 2001-2009 by:
    005       Department of Geography, University of Bonn
    006     and
    007       lat/lon GmbH
    008
    009     This library is free software; you can redistribute it and/or modify it under
    010     the terms of the GNU Lesser General Public License as published by the Free
    011     Software Foundation; either version 2.1 of the License, or (at your option)
    012     any later version.
    013     This library is distributed in the hope that it will be useful, but WITHOUT
    014     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
    015     FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
    016     details.
    017     You should have received a copy of the GNU Lesser General Public License
    018     along with this library; if not, write to the Free Software Foundation, Inc.,
    019     59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
    020
    021     Contact information:
    022
    023     lat/lon GmbH
    024     Aennchenstr. 19, 53177 Bonn
    025     Germany
    026     http://lat-lon.de/
    027
    028     Department of Geography, University of Bonn
    029     Prof. Dr. Klaus Greve
    030     Postfach 1147, 53001 Bonn
    031     Germany
    032     http://www.geographie.uni-bonn.de/deegree/
    033
    034     e-mail: info@deegree.org
    035    ----------------------------------------------------------------------------*/
    036    package org.deegree.datatypes.time;
    037
    038    import java.io.Serializable;
    039
    040    import org.deegree.framework.util.StringTools;
    041    import org.deegree.framework.util.TimeTools;
    042    import org.deegree.ogcwebservices.InvalidParameterValueException;
    043
    044    /**
    045     * @version $Revision: 18195 $
    046     * @author <a href="mailto:poth@lat-lon.de">Andreas Poth</a>
    047     * @author last edited by: $Author: mschneider $
    048     *
    049     * @version 1.0. $Revision: 18195 $, $Date: 2009-06-18 17:55:39 +0200 (Do, 18. Jun 2009) $
    050     *
    051     * @since 2.0
    052     */
    053
    054    public class TimeSequence implements Cloneable, Serializable {
    055
    056        private static final long serialVersionUID = 1L;
    057
    058        private TimePeriod[] timePeriod = null;
    059
    060        private TimePosition[] timePosition = null;
    061
    062        /**
    063         * @param timePeriod
    064         */
    065        public TimeSequence( TimePeriod[] timePeriod ) {
    066            setTimePeriod( timePeriod );
    067        }
    068
    069        /**
    070         * @param timePosition
    071         */
    072        public TimeSequence( TimePosition[] timePosition ) {
    073            setTimePosition( timePosition );
    074        }
    075
    076        /**
    077         * @param timePeriod
    078         * @param timePosition
    079         */
    080        public TimeSequence( TimePeriod[] timePeriod, TimePosition[] timePosition ) {
    081            setTimePeriod( timePeriod );
    082            setTimePosition( timePosition );
    083        }
    084
    085        /**
    086         * format: min/max,res or time1,time2,...,timeN
    087         *
    088         * @param time
    089         *            string representation of a Time dimension
    090         * @throws InvalidParameterValueException
    091         */
    092        public TimeSequence( String time ) throws InvalidParameterValueException {
    093
    094            // TODO
    095            // support parsing more than one period and position
    096
    097            if ( time.indexOf( '/' ) > 0 ) {
    098                // TIME= min/max/res,
    099                String[] tm = StringTools.toArray( time, "/", false );
    100                if ( tm.length != 3 ) {
    101                    throw new InvalidParameterValueException( "time format ist not correct: " + time );
    102                }
    103                TimePosition min = new TimePosition( TimeTools.createCalendar( tm[0] ) );
    104                TimePosition max = null;
    105                if ( tm[0].equals( "now" ) ) {
    106                    max = new TimePosition();
    107                } else {
    108                    max = new TimePosition( TimeTools.createCalendar( tm[1] ) );
    109                }
    110                TimeDuration td = TimeDuration.createTimeDuration( tm[2] );
    111                TimePeriod tper = new TimePeriod( min, max, td );
    112                this.timePeriod = new TimePeriod[] { tper };
    113            } else {
    114                // TIME= time1,time2,...,timeN
    115                String[] tm = StringTools.toArray( time, ",", false );
    116                TimePosition[] tp = new TimePosition[tm.length];
    117                for ( int i = 0; i < tm.length; i++ ) {
    118                    tp[i] = new TimePosition( TimeTools.createCalendar( tm[i] ) );
    119                }
    120                this.timePosition = tp;
    121            }
    122
    123        }
    124
    125        /**
    126         * @return Returns the timePeriod.
    127         */
    128        public TimePeriod[] getTimePeriod() {
    129            return timePeriod;
    130        }
    131
    132        /**
    133         * @param timePeriod
    134         *            The timePeriod to set.
    135         *
    136         */
    137        public void setTimePeriod( TimePeriod[] timePeriod ) {
    138            if ( timePeriod == null ) {
    139                timePeriod = new TimePeriod[0];
    140            }
    141            this.timePeriod = timePeriod;
    142        }
    143
    144        /**
    145         * @return Returns the timePosition.
    146         */
    147        public TimePosition[] getTimePosition() {
    148            return timePosition;
    149        }
    150
    151        /**
    152         * @param timePosition
    153         *            The timePosition to set.
    154         */
    155        public void setTimePosition( TimePosition[] timePosition ) {
    156            if ( timePosition == null ) {
    157                timePosition = new TimePosition[0];
    158            }
    159            this.timePosition = timePosition;
    160        }
    161
    162        /**
    163         * @see java.lang.Object#clone()
    164         */
    165        @Override
    166        public Object clone() {
    167            TimePeriod[] timePeriod_ = new TimePeriod[timePeriod.length];
    168            for ( int i = 0; i < timePeriod_.length; i++ ) {
    169                timePeriod_[i] = (TimePeriod) timePeriod_[i].clone();
    170            }
    171            TimePosition[] timePositions_ = new TimePosition[timePosition.length];
    172            for ( int i = 0; i < timePeriod_.length; i++ ) {
    173                timePositions_[i] = (TimePosition) timePositions_[i].clone();
    174            }
    175            return new TimeSequence( timePeriod_, timePositions_ );
    176        }
    177
    178    }