Ejemplo n.º 1
0
        ///
        ///	 <summary> * Element - value of the ith element in the range. If the index is negative, the position is counted from the end
        ///	 * of the range.<br>
        ///	 * For example the range is 3~7, the 2nd element is 5 and the -2nd element is 6.
        ///	 * <p>
        ///	 * performace warning: don't loop over getElement for potentially large lists with many individual elements.<br>
        ///	 * Prefer to call getIntegerList() and loop over the list.
        ///	 *  </summary>
        ///	 * <param name="i"> the position, if it is a negative value start counting from the right side +1
        ///	 *  </param>
        ///	 * <returns> int - the value at the ith position
        ///	 *  </returns>
        ///	 * <exception cref="NoSuchElementException"> - if the index is out of range </exception>
        ///

        public virtual int getElement(int i)
        {
            int iLocal = i;

            int n = this.getElementCount();

            if ((iLocal >= n) || (iLocal < -n))
            {
                throw new IndexOutOfRangeException("JDFIntegerRangeList::Element out of range error!");
            }

            if (iLocal < 0)
            {
                return(getElement(n + iLocal));
            }

            n = 0;

            for (int j = 0; j < rangeList.Count; j++)
            {
                JDFIntegerRange r = (JDFIntegerRange)rangeList[j];
                int             k = r.getElementCount();
                if (iLocal >= k)
                {
                    // go to next range
                    iLocal -= k;
                }
                else
                {
                    return(r.getElement(iLocal));
                }
            }

            return(0);
        }
Ejemplo n.º 2
0
        public void testJDFIntegerRangeListXDef()
        {
            JDFIntegerRange r  = new JDFIntegerRange(1, 2);
            JDFIntegerRange r2 = new JDFIntegerRange(3, -1, 16); // 16 elements

            // element(-1) =
            // 15, range =
            // 3~15

            Assert.IsTrue(r.getElementCount() == 2, "Bad construction of ranges: Range:" + r.ToString());
            Assert.IsTrue(r2.getElementCount() == 13, "Bad construction of ranges with setDef: Range:" + r.ToString());

            JDFIntegerRangeList r3 = new JDFIntegerRangeList(" 1 ~ 2 3 ~ -1 ", 16);

            Assert.IsTrue(r3.getElementCount() == 15, "Bad construction of ranges with setDef: Range:" + r.ToString());
        }
Ejemplo n.º 3
0
        ///
        ///	 <summary> * getElementCount - returns the number of elements in the list. On the C++ side of the JDF library this method is
        ///	 * called NElements. <br>
        ///	 * E.g. the following list has 14 elements: "1~5 10~15 20~22" if any if any range cannot be resolved due to an
        ///	 * unknown negative value without a known default, -1 is returned
        ///	 *  </summary>
        ///	 * <returns> int - the number of elements in this range, -1 if any range cannot be resolved </returns>
        ///
        public virtual int getElementCount()
        {
            int sz           = rangeList.Count;
            int elementCount = 0;

            for (int i = 0; i < sz; i++)
            {
                JDFIntegerRange r         = (JDFIntegerRange)rangeList[i];
                int             elemCount = r.getElementCount();
                if (elemCount <= 0)
                {
                    return(-1);
                }
                elementCount += elemCount;
            }

            return(elementCount);
        }