コード例 #1
0
ファイル: Schedule.cs プロジェクト: redfood/ndn-dot-net
        /// <summary>
        /// A helper function to calculate black interval results or white interval
        /// results.
        /// </summary>
        ///
        /// <param name="list"></param>
        /// <param name="timeStamp">The time stamp as milliseconds since Jan 1, 1970 UTC.</param>
        /// <param name="positiveResult">The positive result which is updated.</param>
        /// <param name="negativeResult">The negative result which is updated.</param>
        private static void calculateIntervalResult(SortedSet list, double timeStamp,
                                                    Interval positiveResult, Interval negativeResult)
        {
            for (IIterator i = new ILOG.J2CsMapping.Collections.IteratorAdapter(list.GetEnumerator()); i.HasNext();)
            {
                RepetitiveInterval element = (RepetitiveInterval)i.Next();

                RepetitiveInterval.Result result = element.getInterval(timeStamp);
                Interval tempInterval            = result.interval;
                if (result.isPositive == true)
                {
                    try {
                        positiveResult.unionWith(tempInterval);
                    } catch (Interval.Error ex) {
                        // We don't expect to get this error.
                        throw new Exception("Error in Interval.unionWith: "
                                            + ex.Message);
                    }
                }
                else
                {
                    if (!negativeResult.isValid())
                    {
                        negativeResult.set(tempInterval);
                    }
                    else
                    {
                        negativeResult.intersectWith(tempInterval);
                    }
                }
            }
        }
コード例 #2
0
ファイル: Schedule.cs プロジェクト: vcgato29/ndn-dot-net
        /// <summary>
        /// A helper function to calculate black interval results or white interval
        /// results.
        /// </summary>
        ///
        /// <param name="list"></param>
        /// <param name="timeStamp">The time stamp as milliseconds since Jan 1, 1970 UTC.</param>
        /// <param name="positiveResult">The positive result which is updated.</param>
        /// <param name="negativeResult">The negative result which is updated.</param>
        private static void calculateIntervalResult(
            HashedSet <RepetitiveInterval> list, double timeStamp,
            Interval positiveResult, Interval negativeResult)
        {
            Object[] array = ILOG.J2CsMapping.Collections.Collections.ToArray(list);
            System.Array.Sort(array);
            /* foreach */
            foreach (Object elementObj  in  array)
            {
                RepetitiveInterval element = (RepetitiveInterval)elementObj;

                RepetitiveInterval.Result result = element.getInterval(timeStamp);
                Interval tempInterval            = result.interval;
                if (result.isPositive == true)
                {
                    try {
                        positiveResult.unionWith(tempInterval);
                    } catch (Interval.Error ex) {
                        // We don't expect to get this error.
                        throw new Exception("Error in Interval.unionWith: "
                                            + ex.Message);
                    }
                }
                else
                {
                    if (!negativeResult.isValid())
                    {
                        negativeResult.set(tempInterval);
                    }
                    else
                    {
                        negativeResult.intersectWith(tempInterval);
                    }
                }
            }
        }
コード例 #3
0
        public void testCoverTimePoint()
        {
            ///////////////////////////////////////////// With the repeat unit DAY.

            RepetitiveInterval repetitiveInterval1 = new RepetitiveInterval(
                    net.named_data.jndn.tests.unit_tests.UnitTestsCommon.fromIsoString("20150825T000000"),
                    net.named_data.jndn.tests.unit_tests.UnitTestsCommon.fromIsoString("20150925T000000"), 5, 10, 2,
                    net.named_data.jndn.encrypt.RepetitiveInterval.RepeatUnit.DAY);
            RepetitiveInterval.Result result;

            double timePoint1 = net.named_data.jndn.tests.unit_tests.UnitTestsCommon.fromIsoString("20150825T050000");

            result = repetitiveInterval1.getInterval(timePoint1);
            Assert.AssertEquals(true, result.isPositive);
            Assert.AssertEquals("20150825T050000",
                    net.named_data.jndn.tests.unit_tests.UnitTestsCommon.toIsoString(result.interval.getStartTime()));
            Assert.AssertEquals("20150825T100000",
                    net.named_data.jndn.tests.unit_tests.UnitTestsCommon.toIsoString(result.interval.getEndTime()));

            double timePoint2 = net.named_data.jndn.tests.unit_tests.UnitTestsCommon.fromIsoString("20150902T060000");

            result = repetitiveInterval1.getInterval(timePoint2);
            Assert.AssertEquals(true, result.isPositive);
            Assert.AssertEquals("20150902T050000",
                    net.named_data.jndn.tests.unit_tests.UnitTestsCommon.toIsoString(result.interval.getStartTime()));
            Assert.AssertEquals("20150902T100000",
                    net.named_data.jndn.tests.unit_tests.UnitTestsCommon.toIsoString(result.interval.getEndTime()));

            double timePoint3 = net.named_data.jndn.tests.unit_tests.UnitTestsCommon.fromIsoString("20150929T040000");

            result = repetitiveInterval1.getInterval(timePoint3);
            Assert.AssertEquals(false, result.isPositive);

            ///////////////////////////////////////////// With the repeat unit MONTH.

            RepetitiveInterval repetitiveInterval2 = new RepetitiveInterval(
                    net.named_data.jndn.tests.unit_tests.UnitTestsCommon.fromIsoString("20150825T000000"),
                    net.named_data.jndn.tests.unit_tests.UnitTestsCommon.fromIsoString("20160825T000000"), 5, 10, 2,
                    net.named_data.jndn.encrypt.RepetitiveInterval.RepeatUnit.MONTH);

            double timePoint4 = net.named_data.jndn.tests.unit_tests.UnitTestsCommon.fromIsoString("20150825T050000");

            result = repetitiveInterval2.getInterval(timePoint4);
            Assert.AssertEquals(true, result.isPositive);
            Assert.AssertEquals("20150825T050000",
                    net.named_data.jndn.tests.unit_tests.UnitTestsCommon.toIsoString(result.interval.getStartTime()));
            Assert.AssertEquals("20150825T100000",
                    net.named_data.jndn.tests.unit_tests.UnitTestsCommon.toIsoString(result.interval.getEndTime()));

            double timePoint5 = net.named_data.jndn.tests.unit_tests.UnitTestsCommon.fromIsoString("20151025T060000");

            result = repetitiveInterval2.getInterval(timePoint5);
            Assert.AssertEquals(true, result.isPositive);
            Assert.AssertEquals("20151025T050000",
                    net.named_data.jndn.tests.unit_tests.UnitTestsCommon.toIsoString(result.interval.getStartTime()));
            Assert.AssertEquals("20151025T100000",
                    net.named_data.jndn.tests.unit_tests.UnitTestsCommon.toIsoString(result.interval.getEndTime()));

            double timePoint6 = net.named_data.jndn.tests.unit_tests.UnitTestsCommon.fromIsoString("20151226T050000");

            result = repetitiveInterval2.getInterval(timePoint6);
            Assert.AssertEquals(false, result.isPositive);

            double timePoint7 = net.named_data.jndn.tests.unit_tests.UnitTestsCommon.fromIsoString("20151225T040000");

            result = repetitiveInterval2.getInterval(timePoint7);
            Assert.AssertEquals(false, result.isPositive);

            ///////////////////////////////////////////// With the repeat unit YEAR.

            RepetitiveInterval repetitiveInterval3 = new RepetitiveInterval(
                    net.named_data.jndn.tests.unit_tests.UnitTestsCommon.fromIsoString("20150825T000000"),
                    net.named_data.jndn.tests.unit_tests.UnitTestsCommon.fromIsoString("20300825T000000"), 5, 10, 3,
                    net.named_data.jndn.encrypt.RepetitiveInterval.RepeatUnit.YEAR);

            double timePoint8 = net.named_data.jndn.tests.unit_tests.UnitTestsCommon.fromIsoString("20150825T050000");

            result = repetitiveInterval3.getInterval(timePoint8);
            Assert.AssertEquals(true, result.isPositive);
            Assert.AssertEquals("20150825T050000",
                    net.named_data.jndn.tests.unit_tests.UnitTestsCommon.toIsoString(result.interval.getStartTime()));
            Assert.AssertEquals("20150825T100000",
                    net.named_data.jndn.tests.unit_tests.UnitTestsCommon.toIsoString(result.interval.getEndTime()));

            double timePoint9 = net.named_data.jndn.tests.unit_tests.UnitTestsCommon.fromIsoString("20180825T060000");

            result = repetitiveInterval3.getInterval(timePoint9);
            Assert.AssertEquals(true, result.isPositive);
            Assert.AssertEquals("20180825T050000",
                    net.named_data.jndn.tests.unit_tests.UnitTestsCommon.toIsoString(result.interval.getStartTime()));
            Assert.AssertEquals("20180825T100000",
                    net.named_data.jndn.tests.unit_tests.UnitTestsCommon.toIsoString(result.interval.getEndTime()));

            double timePoint10 = net.named_data.jndn.tests.unit_tests.UnitTestsCommon.fromIsoString("20180826T050000");
            result = repetitiveInterval3.getInterval(timePoint10);
            Assert.AssertEquals(false, result.isPositive);

            double timePoint11 = net.named_data.jndn.tests.unit_tests.UnitTestsCommon.fromIsoString("20210825T040000");
            result = repetitiveInterval3.getInterval(timePoint11);
            Assert.AssertEquals(false, result.isPositive);

            double timePoint12 = net.named_data.jndn.tests.unit_tests.UnitTestsCommon.fromIsoString("20300825T040000");
            result = repetitiveInterval3.getInterval(timePoint12);
            Assert.AssertEquals(false, result.isPositive);
        }