/// /// <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("JDFDurationRangeList::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 { JDFDurationRange dr = new JDFDurationRange(str); rangeList.Add(dr); } catch (FormatException) { throw new FormatException("JDFDurationRangeList::SetString: Illegal string " + s); } } }
public void testJDFDurationRangeJDFDuration() { JDFDurationRange r = new JDFDurationRange(new JDFDuration("PT5M"), new JDFDuration("PT15M")); JDFDurationRange r2 = new JDFDurationRange(new JDFDuration("PT5M")); Assert.IsTrue(r.ToString().Equals("PT5M ~ PT15M"), "Bad Constructor "); Assert.IsTrue(r2.ToString().Equals("PT5M"), "Bad Constructor "); }
/// /// <summary> * isPartOfRange - is range 'r' within this range? /// * </summary> /// * <param name="r"> the range to test /// * </param> /// * <returns> boolean - true if range 'r' is within this range, else false </returns> /// public override bool isPartOfRange(JDFRange ra) { JDFDurationRange r = (JDFDurationRange)ra; JDFDuration min = this.LowerValue; JDFDuration r_min = r.LowerValue; JDFDuration max = this.UpperValue; JDFDuration r_max = r.UpperValue; return((r_min.isLonger(min) || r_min.Equals(min)) && (r_max.isShorter(max) || r_max.Equals(max))); }
public void testJDFDurationRangeJDFDurationRange() { JDFDurationRange r = new JDFDurationRange(new JDFDuration("PT5M"), new JDFDuration("PT25M")); JDFDurationRange r2 = new JDFDurationRange(new JDFDuration("PT15M")); JDFDurationRange r3 = new JDFDurationRange(r2); r3.Right = new JDFDuration("PT25M"); Assert.IsTrue(r.ToString().Equals("PT5M ~ PT25M"), "Bad Constructor" + r.ToString()); Assert.IsTrue(r2.ToString().Equals("PT15M"), "Bad Constructor" + r2.ToString()); Assert.IsTrue(r3.ToString().Equals("PT15M ~ PT25M"), "Bad CopyConstructor" + r3.ToString()); }
// **************************************** Methods // ********************************************* /// /// <summary> * inRange - returns true if the given JDFDuration value is in one of the ranges of the range list /// * </summary> /// * <param name="x"> the given JDFDuration (duration) value to compare /// * </param> /// * <returns> boolean - true if in range otherwise false </returns> /// public virtual bool inRange(JDFDuration x) { int sz = rangeList.Count; for (int i = 0; i < sz; i++) { JDFDurationRange r = (JDFDurationRange)rangeList[i]; if (r.inRange(x)) { return(true); } } return(false); }
/// /// <summary> * isUniqueOrdered - tests if 'this' is UniqueOrdered RangeList /// * </summary> /// * <returns> boolean - true if 'this' is UniqueOrdered RangeList </returns> /// public override bool isUniqueOrdered() { int siz = rangeList.Count; if (siz == 0) { return(false); // attempt to operate on a null element } List <JDFDuration> v = new List <JDFDuration>(); // vector of ranges for (int i = 0; i < siz; i++) { JDFDurationRange r = (JDFDurationRange)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 } JDFDuration first = v[0]; JDFDuration last = v[n]; if (first.Equals(last)) { return(false); } for (int j = 0; j < n; j++) { JDFDuration @value = v[j]; JDFDuration nextvalue = v[j + 1]; if (((first.isShorter(last) && @value.isShorter(nextvalue)) || (first.isLonger(last) && @value.isLonger(nextvalue))) == false) { return(false); } } return(true); }
/// /// <summary> * copy constructor </summary> /// public JDFDurationRange(JDFDurationRange r) { init(r.Left, r.Right); }
/// /// <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(JDFDurationRange r) { rangeList.Add(r); }