Esempio n. 1
0
        ///
        ///	 <summary> * setString - parse the given string and set the Number ranges
        ///	 *  </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("JDFNumberRangeList::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
                {
                    JDFNumberRange nr = new JDFNumberRange(str);
                    rangeList.Add(nr);
                }
                catch (FormatException)
                {
                    throw new FormatException("JDFNumberRangeList::SetString: Illegal string " + s);
                }
            }
        }
Esempio n. 2
0
        // **************************************** Methods
        // *********************************************

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

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

                if (r.inRange(x))
                {
                    return(true);
                }
            }
            return(false);
        }
Esempio n. 3
0
        ///
        ///	 <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 <double> v = new List <double>(); // vector of ranges

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

            int n = v.Count - 1;

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

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

                if (((first < last) && (@value < nextvalue) || (first > last) && (@value < nextvalue)) == false)
                {
                    return(false);
                }
            }
            return(true);
        }
Esempio n. 4
0
        ///
        ///	 <summary> * equals - returns true if both JDFNumberRange are equal otherwise false, the difference must be smaller than
        ///	 * EPSILON
        ///	 *  </summary>
        ///	 * <param name="other"> the object to compare with <code>this</code> </param>
        ///	 * <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);
            }

            JDFNumberRange jdfNumberRange = (JDFNumberRange)other;

            return((Math.Abs(this.Left - jdfNumberRange.Left) <= JDFBaseDataTypes_Fields.EPSILON) && (Math.Abs(this.Right - jdfNumberRange.Right) <= JDFBaseDataTypes_Fields.EPSILON));
        }
Esempio n. 5
0
        public void testInitRange()
        {
            JDFNumberRange range = new JDFNumberRange("0.0");

            Assert.AreEqual(0.0, range.Left, 0.0);
        }
Esempio n. 6
0
        ///
        ///	 <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)
        {
            JDFNumberRange r = (JDFNumberRange)ra;

            return((r.LowerValue >= this.LowerValue) && (r.UpperValue <= this.UpperValue));
        }
Esempio n. 7
0
 ///
 ///	 <summary> * copy constructor, creates a JDFNumberRange with the given JDFNumberRange
 ///	 *  </summary>
 ///	 * <param name="nr"> </param>
 ///
 public JDFNumberRange(JDFNumberRange nr)
 {
     init(nr.Left, nr.Right);
 }
Esempio n. 8
0
 ///
 ///	 <summary> * append - appends a JDFNumberRange to this number range
 ///	 *  </summary>
 ///	 * <param name="r"> the given number range </param>
 ///
 public virtual void Append(JDFNumberRange r)
 {
     rangeList.Add(r);
 }
Esempio n. 9
0
 ///
 ///	 <summary> * constructs a JDFNumberRangeList from the given JDFNumberRange
 ///	 *  </summary>
 ///	 * <param name="r"> the given JDFNumberRange </param>
 ///
 public JDFNumberRangeList(JDFNumberRange r)
     : base()
 {
     Append(r);
 }