/// /// <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) { JDFShapeRange r = (JDFShapeRange)ra; JDFShape min = this.LowerValue; JDFShape r_min = r.LowerValue; JDFShape max = this.UpperValue; JDFShape r_max = r.UpperValue; return(r_min.isGreaterOrEqual(min) && r_max.isLessOrEqual(max)); }
/// /// <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 <JDFShape> v = new List <JDFShape>(); // vector of ranges for (int i = 0; i < siz; i++) { JDFShapeRange r = (JDFShapeRange)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 } JDFShape first = v[0]; JDFShape last = v[n]; if (first.Equals(last)) { return(false); } for (int j = 0; j < n; j++) { JDFShape @value = v[j]; JDFShape nextvalue = v[j + 1]; if (((first.isLess(last) && @value.isLess(nextvalue)) || (first.isGreater(last) && @value.isGreater(nextvalue))) == false) { return(false); } } return(true); }
/// /// <summary> * setString - deserialize a string Reads the string, which represents JDFShapeRangeList, and converts it into real /// * JDFShapeRangeList /// * </summary> /// * <param name="s"> string to read /// * </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("JDFShapeRangeList.setString: Illegal string " + s); } string zappedWS = StringUtil.zappTokenWS(s, JDFConstants.TILDE); VString vs = new VString(zappedWS, JDFConstants.BLANK); rangeList.Clear(); for (int i = 0, size = vs.Count; i < size; i++) { if (size - i < JDFBaseDataTypes_Fields.MAX_SHAPE_DIMENSION) // the last Shape is incomplete { throw new FormatException("JDFShapeRangeList.setString: Illegal string " + s); } StringBuilder str = new StringBuilder(100); str.Append(vs[i]).Append(JDFConstants.BLANK).Append(vs[++i]).Append(JDFConstants.BLANK); // the third token 'tildeToken' can be with or without "~" string tildeToken = vs[++i]; str.Append(tildeToken); if (tildeToken.IndexOf(JDFConstants.TILDE) != -1) // str - // JDFShapeRange { if (size - i < JDFBaseDataTypes_Fields.MAX_SHAPE_DIMENSION) // the last ShapeRange is // incomplete { throw new FormatException("JDFShapeRangeList.setString: Illegal string " + s); } str.Append(JDFConstants.BLANK).Append(vs[++i]).Append(JDFConstants.BLANK).Append(vs[++i]); } try { JDFShapeRange r = new JDFShapeRange(str.ToString()); rangeList.Add(r); } catch (FormatException) { throw new FormatException("JDFShapeRangeList.setString: Illegal string " + s); } } }
/// /// <summary> * equals - returns true if both JDFShapeRanges are equal otherwise false /// * </summary> /// * <returns> boolean - true if equal otherwise false </returns> /// public override bool Equals(object other) { if (this == other) { return(true); } if (other == null) { return(false); } if (!other.GetType().Equals(this.GetType())) { return(false); } JDFShapeRange range = (JDFShapeRange)other; return(this.Left.Equals(range.Left) && this.Right.Equals(range.Right)); }
/// /// <summary> * append - adds an element defined by a JDFShapeRange /// * </summary> /// * <param name="x"> the range to append to the list </param> /// public virtual void Append(JDFShapeRange x) { rangeList.Add(x); }
/// /// <summary> * copy constructor<br> /// * constructs a JDFShapeRange with the given JDFShapeRange /// * </summary> /// * <param name="r"> </param> /// public JDFShapeRange(JDFShapeRange r) { init(r.Left, r.Right); }