Exemplo n.º 1
0
        ///
        ///	 <summary> * setString - parse the given string and set the duration range list
        ///	 *  </summary>
        ///	 * <param name="s"> the given string
        ///	 *  </param>
        ///	 * <exception cref="FormatException"> - if the String has not a valid format </exception>
        ///
        public virtual void setString(string s)
        {
            if (s.IndexOf(JDFConstants.TILDE) == 0 || s.LastIndexOf(JDFConstants.TILDE) == (s.Length - 1))
            {
                throw new FormatException("JDFDateTimeRangeList::SetString: Illegal string " + s);
            }
            string  zappedWS = StringUtil.zappTokenWS(s, "~");
            VString v        = new VString(StringUtil.tokenize(zappedWS, " \t", false));
            VString vs       = new VString(v);

            rangeList.Clear();
            for (int i = 0; i < vs.Count; i++)
            {
                string str = vs[i];
                try
                {
                    JDFDateTimeRange dr = new JDFDateTimeRange(str);
                    rangeList.Add(dr);
                }
                catch (FormatException)
                {
                    throw new FormatException("JDFDateTimeRangeList::SetString: Illegal string " + s);
                }
            }
        }
Exemplo n.º 2
0
        public void testJDFDateTimeRangeJDFDateTimeRange()
        {
            try
            {
                JDFDateTimeRange r = new JDFDateTimeRange(new JDFDate("2004-12-01T09:30:00Z"), new JDFDate("2004-12-01T09:35:00Z"));

                JDFDateTimeRange test_r = new JDFDateTimeRange("2004-12-01T09:30:00Z ~ 2004-12-01T09:35:00Z");
                Assert.IsTrue(r.Equals(test_r), "Bad Constructor: " + r.ToString());

                int         duration = (int)((test_r.Right.TimeInMillis - test_r.Left.TimeInMillis) / 1000);
                JDFDuration d        = new JDFDuration();
                d.setDuration(duration);
                // System.out.println(duration);

                JDFDateTimeRange r2 = new JDFDateTimeRange(new JDFDate("2004-12-01T09:30:00Z"));
                JDFDateTimeRange r3 = new JDFDateTimeRange(r2);
                r3.Right = r.Right;

                Assert.IsTrue(r3.Equals(r), "Bad Constructor: " + r3.ToString());
            }
            catch (FormatException dfe)
            {
                Console.WriteLine(dfe.ToString());
            }
        }
Exemplo n.º 3
0
        // **************************************** Methods
        // *********************************************

        ///
        ///	 <summary> * inRange - returns true if the given JDFDate value is in one of the ranges of the range list
        ///	 *  </summary>
        ///	 * <param name="x"> the given JDFDate (duration) value to compare
        ///	 *  </param>
        ///	 * <returns> boolean - true if in range otherwise false </returns>
        ///
        public virtual bool inRange(JDFDate x)
        {
            int sz = rangeList.Count;

            for (int i = 0; i < sz; i++)
            {
                JDFDateTimeRange r = (JDFDateTimeRange)rangeList[i];

                if (r.inRange(x))
                {
                    return(true);
                }
            }
            return(false);
        }
Exemplo n.º 4
0
        ///
        ///	 <summary> * isUniqueOrdered - tests if 'this' is an UniqueOrdered RangeList
        ///	 *  </summary>
        ///	 * <returns> boolean - true if 'this' is an UniqueOrdered RangeList </returns>
        ///
        public override bool isUniqueOrdered()
        {
            int siz = rangeList.Count;

            if (siz == 0)
            {
                return(false); // attempt to operate on a null element
            }

            List <JDFDate> v = new List <JDFDate>(); // vector of ranges

            for (int i = 0; i < siz; i++)
            {
                JDFDateTimeRange r = (JDFDateTimeRange)rangeList[i];
                v.Add(r.Left);
                if (!r.Left.Equals(r.Right))
                {
                    v.Add(r.Right);
                }
            }

            int n = v.Count - 1;

            if (n == 0)
            {
                return(true); // single value
            }
            JDFDate first = v[0];
            JDFDate last  = v[n];

            if (first.Equals(last))
            {
                return(false);
            }
            for (int j = 0; j < n; j++)
            {
                JDFDate @value    = v[j];
                JDFDate nextvalue = v[j + 1];

                if (((first.isEarlier(last) && @value.isEarlier(nextvalue)) || (first.isLater(last) && @value.isLater(nextvalue))) == false)
                {
                    return(false);
                }
            }
            return(true);
        }
Exemplo n.º 5
0
 ///
 ///	 <summary> * Add a Duration range r =rMin~rMax
 ///	 *  </summary>
 ///	 * <param name="r"> the Duration range to append to the list </param>
 ///
 public virtual void Append(JDFDateTimeRange r)
 {
     rangeList.Add(r);
 }