Esempio n. 1
0
 public virtual void test_ofDayOfWeek_next_oneMonth()
 {
     foreach (DayOfWeek dow in DayOfWeek.values())
     {
         RollConvention test = RollConvention.ofDayOfWeek(dow);
         assertEquals(test.next(date(2014, AUGUST, 14), P1W), date(2014, AUGUST, 21).with(TemporalAdjusters.nextOrSame(dow)));
     }
 }
Esempio n. 2
0
 public virtual void test_ofDayOfWeek_previous_oneDay()
 {
     foreach (DayOfWeek dow in DayOfWeek.values())
     {
         RollConvention test = RollConvention.ofDayOfWeek(dow);
         assertEquals(test.previous(date(2014, AUGUST, 14), P1D), date(2014, AUGUST, 13).with(TemporalAdjusters.previousOrSame(dow)));
     }
 }
 // resolve the values
 private DoubleArray resolveValues(IList <SchedulePeriod> periods, RollConvention rollConv)
 {
     // handle simple case where there are no steps
     if (steps.Count == 0 && stepSequence == null)
     {
         return(DoubleArray.filled(periods.Count, initialValue));
     }
     return(resolveSteps(periods, rollConv));
 }
 private Schedule(IList <SchedulePeriod> periods, Frequency frequency, RollConvention rollConvention)
 {
     JodaBeanUtils.notEmpty(periods, "periods");
     JodaBeanUtils.notNull(frequency, "frequency");
     JodaBeanUtils.notNull(rollConvention, "rollConvention");
     this.periods        = ImmutableList.copyOf(periods);
     this.frequency      = frequency;
     this.rollConvention = rollConvention;
 }
Esempio n. 5
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test(dataProvider = "types") public void test_null(RollConvention type)
        public virtual void test_null(RollConvention type)
        {
            assertThrowsIllegalArg(() => type.adjust(null));
            assertThrowsIllegalArg(() => type.matches(null));
            assertThrowsIllegalArg(() => type.next(date(2014, JULY, 1), null));
            assertThrowsIllegalArg(() => type.next(null, P3M));
            assertThrowsIllegalArg(() => type.previous(date(2014, JULY, 1), null));
            assertThrowsIllegalArg(() => type.previous(null, P3M));
        }
Esempio n. 6
0
 //-------------------------------------------------------------------------
 public virtual void test_ofDayOfWeek()
 {
     foreach (DayOfWeek dow in DayOfWeek.values())
     {
         RollConvention test = RollConvention.ofDayOfWeek(dow);
         assertEquals(test.Name, "Day" + CaseFormat.UPPER_UNDERSCORE.converterTo(CaseFormat.UPPER_CAMEL).convert(dow.ToString()).substring(0, 3));
         assertEquals(test.ToString(), "Day" + CaseFormat.UPPER_UNDERSCORE.converterTo(CaseFormat.UPPER_CAMEL).convert(dow.ToString()).substring(0, 3));
         assertSame(RollConvention.of(test.Name), test);
         assertSame(RollConvention.of("DAY" + dow.ToString().Substring(0, 3)), test);
     }
 }
Esempio n. 7
0
 //-------------------------------------------------------------------------
 public virtual void test_ofDayOfMonth()
 {
     for (int i = 1; i < 30; i++)
     {
         RollConvention test = RollConvention.ofDayOfMonth(i);
         assertEquals(test.adjust(date(2014, JULY, 1)), date(2014, JULY, i));
         assertEquals(test.Name, "Day" + i);
         assertEquals(test.ToString(), "Day" + i);
         assertSame(RollConvention.of(test.Name), test);
         assertSame(RollConvention.of("DAY" + i), test);
     }
 }
Esempio n. 8
0
 public virtual void test_ofDayOfMonth_previous_oneMonth()
 {
     for (int start = 1; start <= 5; start++)
     {
         for (int i = 1; i <= 30; i++)
         {
             RollConvention test     = RollConvention.ofDayOfMonth(i);
             LocalDate      expected = date(2014, JUNE, i);
             assertEquals(test.previous(date(2014, JULY, start), P1M), expected);
         }
     }
 }
Esempio n. 9
0
        public virtual void test_ofDayOfMonth_matches_Day30()
        {
            assertEquals(RollConvention.ofDayOfMonth(30).matches(date(2016, JANUARY, 29)), false);
            assertEquals(RollConvention.ofDayOfMonth(30).matches(date(2016, JANUARY, 30)), true);
            assertEquals(RollConvention.ofDayOfMonth(30).matches(date(2016, JANUARY, 31)), false);

            assertEquals(RollConvention.ofDayOfMonth(30).matches(date(2016, FEBRUARY, 28)), false);
            assertEquals(RollConvention.ofDayOfMonth(30).matches(date(2016, FEBRUARY, 29)), true);

            assertEquals(RollConvention.ofDayOfMonth(30).matches(date(2015, FEBRUARY, 27)), false);
            assertEquals(RollConvention.ofDayOfMonth(30).matches(date(2015, FEBRUARY, 28)), true);
        }
        private void Generate(BusinessDate startDate, BusinessDate endDate,
                              int duration, Frequency freq, RollConvention roll, Stub stub)
        {
            StartDate = startDate;
            EndDate   = endDate;
            Duration  = duration;
            Frequency = freq;
            Roll      = roll;
            Stub      = stub;

            Dates   = new List <BusinessDate>();
            Periods = new List <Period>();
            Create();
        }
        // resolve the steps, broken into a separate method to aid inlining
        private DoubleArray resolveSteps(IList <SchedulePeriod> periods, RollConvention rollConv)
        {
            int size = periods.Count;

            double[]          result        = new double[size];
            IList <ValueStep> resolvedSteps = StepSequence.map(seq => seq.resolve(steps, rollConv)).orElse(steps);

            // expand ValueStep to array of adjustments matching the periods
            // the steps are not sorted, so use fixed size array to absorb incoming data
            ValueAdjustment[] expandedSteps = new ValueAdjustment[size];
            IList <ValueStep> invalidSteps  = new List <ValueStep>();

            foreach (ValueStep step in resolvedSteps)
            {
                int index = step.findIndex(periods);
                if (index < 0)
                {
                    invalidSteps.Add(step);
                    continue;
                }
                if (expandedSteps[index] != null && !expandedSteps[index].Equals(step.Value))
                {
                    throw new System.ArgumentException(Messages.format("Invalid ValueSchedule, two steps resolved to the same schedule period starting on {}, schedule defined as {}", periods[index].UnadjustedStartDate, this));
                }
                expandedSteps[index] = step.Value;
            }
            // apply each adjustment
            double value = initialValue;

            for (int i = 0; i < size; i++)
            {
                if (expandedSteps[i] != null)
                {
                    value = expandedSteps[i].adjust(value);
                }
                result[i] = value;
            }
            // ensure that invalid steps cause no changes
            foreach (ValueStep step in invalidSteps)
            {
                double baseValue = result[step.findPreviousIndex(periods)];
                double adjusted  = step.Value.adjust(baseValue);
                if (adjusted != baseValue)
                {
                    throw new System.ArgumentException("ValueStep date does not match a period boundary: " + step.Date.get());
                }
            }
            // return result
            return(DoubleArray.ofUnsafe(result));
        }
        public void Create(BusinessDate startDate, BusinessDate endDate,
                           int duration, Frequency freq,
                           RollConvention roll = RollConvention.NONE, Stub stub = Stub.NONE)
        {
            StartDate = startDate;
            EndDate   = endDate;
            Duration  = duration;
            Frequency = freq;
            Roll      = roll;
            Stub      = stub;

            Dates   = new List <BusinessDate>();
            Periods = new List <Period>();
            Create();
        }
Esempio n. 13
0
 public virtual void test_ofDayOfMonth_previous_oneDay()
 {
     for (int start = 1; start <= 5; start++)
     {
         for (int i = 1; i <= 30; i++)
         {
             RollConvention test     = RollConvention.ofDayOfMonth(i);
             LocalDate      expected = date(2014, JULY, i);
             if (i >= start)
             {
                 expected = expected.minusMonths(1);
             }
             assertEquals(test.previous(date(2014, JULY, start), P1D), expected);
         }
     }
 }
Esempio n. 14
0
        //-------------------------------------------------------------------------
        /// <summary>
        /// Resolves the sequence to a list of steps.
        /// </summary>
        /// <param name="existingSteps">  the existing list of steps </param>
        /// <param name="rollConv">  the roll convention </param>
        /// <returns> the steps </returns>
        internal IList <ValueStep> resolve(IList <ValueStep> existingSteps, RollConvention rollConv)
        {
            ImmutableList.Builder <ValueStep> steps = ImmutableList.builder();
            steps.addAll(existingSteps);
            LocalDate prev = firstStepDate;
            LocalDate date = firstStepDate;

            while (!date.isAfter(lastStepDate))
            {
                steps.add(ValueStep.of(date, adjustment));
                prev = date;
                date = rollConv.next(date, frequency);
            }
            if (!prev.Equals(lastStepDate))
            {
                throw new System.ArgumentException(Messages.format("ValueStepSequence lastStepDate did not match frequency '{}' using roll convention '{}', {} != {}", frequency, rollConv, lastStepDate, prev));
            }
            return(steps.build());
        }
Esempio n. 15
0
        //-------------------------------------------------------------------------
        public virtual void test_equals()
        {
            RollConvention a = RollConventions.EOM;
            RollConvention b = RollConventions.DAY_1;
            RollConvention c = RollConventions.DAY_WED;

            assertEquals(a.Equals(a), true);
            assertEquals(a.Equals(b), false);
            assertEquals(a.Equals(c), false);

            assertEquals(b.Equals(a), false);
            assertEquals(b.Equals(b), true);
            assertEquals(b.Equals(c), false);

            assertEquals(c.Equals(a), false);
            assertEquals(c.Equals(b), false);
            assertEquals(c.Equals(c), true);

            assertEquals(a.GetHashCode(), a.GetHashCode());
        }
Esempio n. 16
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @SuppressWarnings("unchecked") @Override public Builder set(String propertyName, Object newValue)
            public override Builder set(string propertyName, object newValue)
            {
                switch (propertyName.GetHashCode())
                {
                case -678739246:         // periods
                    this.periods_Renamed = (IList <SchedulePeriod>)newValue;
                    break;

                case -70023844:         // frequency
                    this.frequency_Renamed = (Frequency)newValue;
                    break;

                case -10223666:         // rollConvention
                    this.rollConvention_Renamed = (RollConvention)newValue;
                    break;

                default:
                    throw new NoSuchElementException("Unknown property: " + propertyName);
                }
                return(this);
            }
Esempio n. 17
0
 public virtual void test_ofDayOfMonth_adjust_Day30()
 {
     assertEquals(RollConvention.ofDayOfMonth(30).adjust(date(2014, FEBRUARY, 2)), date(2014, FEBRUARY, 28));
     assertEquals(RollConvention.ofDayOfMonth(30).adjust(date(2016, FEBRUARY, 2)), date(2016, FEBRUARY, 29));
 }
Esempio n. 18
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test(dataProvider = "lenient") public void test_lenientLookup_specialNames(String name, RollConvention convention)
        public virtual void test_lenientLookup_specialNames(string name, RollConvention convention)
        {
            assertEquals(RollConvention.extendedEnum().findLenient(name.ToLower(Locale.ENGLISH)), convention);
        }
Esempio n. 19
0
 public virtual void test_of_lookup_null()
 {
     assertThrowsIllegalArg(() => RollConvention.of(null));
 }
Esempio n. 20
0
 public virtual void test_of_lookup_notFound()
 {
     assertThrowsIllegalArg(() => RollConvention.of("Rubbish"));
 }
Esempio n. 21
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test(dataProvider = "name") public void test_extendedEnum(RollConvention convention, String name)
        public virtual void test_extendedEnum(RollConvention convention, string name)
        {
            ImmutableMap <string, RollConvention> map = RollConvention.extendedEnum().lookupAll();

            assertEquals(map.get(name), convention);
        }
Esempio n. 22
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test(dataProvider = "name") public void test_lenientLookup_standardNames(RollConvention convention, String name)
        public virtual void test_lenientLookup_standardNames(RollConvention convention, string name)
        {
            assertEquals(RollConvention.extendedEnum().findLenient(name.ToLower(Locale.ENGLISH)).get(), convention);
        }
Esempio n. 23
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test(dataProvider = "name") public void test_of_lookup(RollConvention convention, String name)
        public virtual void test_of_lookup(RollConvention convention, string name)
        {
            assertEquals(RollConvention.of(name), convention);
        }
 public Schedule(BusinessDate startDate, BusinessDate endDate,
                 Frequency freq, RollConvention roll = RollConvention.NONE, Stub stub = Stub.NONE)
 {
     Create(startDate, endDate, 1, freq, roll, stub);
 }
 int ISchedule.Create(BusinessDate startDate, BusinessDate endDate,
                      int duration, Frequency unit, RollConvention roll, Stub stub)
 {
     Generate(startDate, endDate, duration, unit, roll, stub);
     return(Dates.Count);
 }
Esempio n. 26
0
 public virtual void test_ofDayOfWeek_matches()
 {
     assertEquals(RollConvention.ofDayOfWeek(TUESDAY).matches(date(2014, SEPTEMBER, 1)), false);
     assertEquals(RollConvention.ofDayOfWeek(TUESDAY).matches(date(2014, SEPTEMBER, 2)), true);
     assertEquals(RollConvention.ofDayOfWeek(TUESDAY).matches(date(2014, SEPTEMBER, 3)), false);
 }
 int ISchedule.Create(BusinessDate startDate, BusinessDate endDate,
                      Frequency freq, RollConvention roll, Stub stub)
 {
     Generate(startDate, endDate, 1, freq, roll, stub);
     return(Dates.Count);
 }
Esempio n. 28
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test(dataProvider = "name") public void test_name(RollConvention convention, String name)
        public virtual void test_name(RollConvention convention, string name)
        {
            assertEquals(convention.Name, name);
        }
        //-------------------------------------------------------------------------
        public override void start(Stage primaryStage)
        {
            LocalDate today = LocalDate.now(ZoneId.systemDefault());

            // setup GUI elements
            Label      startLbl = new Label("Start date:");
            DatePicker startInp = new DatePicker(today);

            startLbl.LabelFor        = startInp;
            startInp.ShowWeekNumbers = false;

            Label      endLbl = new Label("End date:");
            DatePicker endInp = new DatePicker(today.plusYears(1));

            endLbl.LabelFor        = endInp;
            endInp.ShowWeekNumbers = false;

            Label freqLbl = new Label("Frequency:");
            ChoiceBox <Frequency> freqInp = new ChoiceBox <Frequency>(FXCollections.observableArrayList(Frequency.P1M, Frequency.P2M, Frequency.P3M, Frequency.P4M, Frequency.P6M, Frequency.P12M));

            freqLbl.LabelFor = freqInp;
            freqInp.Value    = Frequency.P3M;

            Label stubLbl = new Label("Stub:");
            ObservableList <StubConvention> stubOptions = FXCollections.observableArrayList(StubConvention.values());

            stubOptions.add(0, null);
            ChoiceBox <StubConvention> stubInp = new ChoiceBox <StubConvention>(stubOptions);

            stubLbl.LabelFor = stubInp;
            stubInp.Value    = StubConvention.SMART_INITIAL;

            Label rollLbl = new Label("Roll:");
            ChoiceBox <RollConvention> rollInp = new ChoiceBox <RollConvention>(FXCollections.observableArrayList(null, RollConventions.NONE, RollConventions.EOM, RollConventions.IMM, RollConventions.IMMAUD, RollConventions.IMMNZD, RollConventions.SFE));

            rollLbl.LabelFor = rollInp;
            rollInp.Value    = RollConventions.NONE;

            Label bdcLbl = new Label("Adjust:");
            ChoiceBox <BusinessDayConvention> bdcInp = new ChoiceBox <BusinessDayConvention>(FXCollections.observableArrayList(BusinessDayConventions.NO_ADJUST, BusinessDayConventions.FOLLOWING, BusinessDayConventions.MODIFIED_FOLLOWING, BusinessDayConventions.PRECEDING, BusinessDayConventions.MODIFIED_PRECEDING, BusinessDayConventions.MODIFIED_FOLLOWING_BI_MONTHLY, BusinessDayConventions.NEAREST));

            bdcLbl.LabelFor = bdcInp;
            bdcInp.Value    = BusinessDayConventions.MODIFIED_FOLLOWING;

            Label holidayLbl = new Label("Holidays:");
            ChoiceBox <HolidayCalendarId> holidayInp = new ChoiceBox <HolidayCalendarId>(FXCollections.observableArrayList(HolidayCalendarIds.CHZU, HolidayCalendarIds.GBLO, HolidayCalendarIds.EUTA, HolidayCalendarIds.FRPA, HolidayCalendarIds.JPTO, HolidayCalendarIds.NYFD, HolidayCalendarIds.NYSE, HolidayCalendarIds.USNY, HolidayCalendarIds.USGS, HolidayCalendarIds.NO_HOLIDAYS, HolidayCalendarIds.SAT_SUN));

            holidayLbl.LabelFor = holidayInp;
            holidayInp.Value    = HolidayCalendarIds.GBLO;

            TableView <SchedulePeriod> resultGrid = new TableView <SchedulePeriod>();
            TableColumn <SchedulePeriod, LocalDate> unadjustedCol = new TableColumn <SchedulePeriod, LocalDate>("Unadjusted dates");
            TableColumn <SchedulePeriod, LocalDate> adjustedCol   = new TableColumn <SchedulePeriod, LocalDate>("Adjusted dates");

            TableColumn <SchedulePeriod, LocalDate> resultUnadjStartCol = new TableColumn <SchedulePeriod, LocalDate>("Start");

            resultUnadjStartCol.CellValueFactory = new TableCallback <>(SchedulePeriod.meta().unadjustedStartDate());
            TableColumn <SchedulePeriod, LocalDate> resultUnadjEndCol = new TableColumn <SchedulePeriod, LocalDate>("End");

            resultUnadjEndCol.CellValueFactory = new TableCallback <>(SchedulePeriod.meta().unadjustedEndDate());
            TableColumn <SchedulePeriod, Period> resultUnadjLenCol = new TableColumn <SchedulePeriod, Period>("Length");

            resultUnadjLenCol.CellValueFactory = ReadOnlyCallback.of(sch => Period.between(sch.UnadjustedStartDate, sch.UnadjustedEndDate));

            TableColumn <SchedulePeriod, LocalDate> resultStartCol = new TableColumn <SchedulePeriod, LocalDate>("Start");

            resultStartCol.CellValueFactory = new TableCallback <>(SchedulePeriod.meta().startDate());
            TableColumn <SchedulePeriod, LocalDate> resultEndCol = new TableColumn <SchedulePeriod, LocalDate>("End");

            resultEndCol.CellValueFactory = new TableCallback <>(SchedulePeriod.meta().endDate());
            TableColumn <SchedulePeriod, Period> resultLenCol = new TableColumn <SchedulePeriod, Period>("Length");

            resultLenCol.CellValueFactory = ReadOnlyCallback.of(sch => sch.length());

            unadjustedCol.Columns.add(resultUnadjStartCol);
            unadjustedCol.Columns.add(resultUnadjEndCol);
            unadjustedCol.Columns.add(resultUnadjLenCol);
            adjustedCol.Columns.add(resultStartCol);
            adjustedCol.Columns.add(resultEndCol);
            adjustedCol.Columns.add(resultLenCol);
            resultGrid.Columns.add(unadjustedCol);
            resultGrid.Columns.add(adjustedCol);
            resultGrid.Placeholder = new Label("Schedule not yet generated");

            unadjustedCol.prefWidthProperty().bind(resultGrid.widthProperty().divide(2));
            adjustedCol.prefWidthProperty().bind(resultGrid.widthProperty().divide(2));
            resultUnadjStartCol.prefWidthProperty().bind(unadjustedCol.widthProperty().divide(3));
            resultUnadjEndCol.prefWidthProperty().bind(unadjustedCol.widthProperty().divide(3));
            resultUnadjLenCol.prefWidthProperty().bind(unadjustedCol.widthProperty().divide(3));
            resultStartCol.prefWidthProperty().bind(adjustedCol.widthProperty().divide(3));
            resultEndCol.prefWidthProperty().bind(adjustedCol.widthProperty().divide(3));
            resultLenCol.prefWidthProperty().bind(adjustedCol.widthProperty().divide(3));

            // setup generation button
            // this uses the GUI thread which is not the best idea
            Button btn = new Button();

            btn.Text     = "Generate";
            btn.OnAction = @event =>
            {
                LocalDate             start  = startInp.Value;
                LocalDate             end    = endInp.Value;
                Frequency             freq   = freqInp.Value;
                StubConvention        stub   = stubInp.Value;
                RollConvention        roll   = rollInp.Value;
                HolidayCalendarId     holCal = holidayInp.Value;
                BusinessDayConvention bdc    = bdcInp.Value;
                BusinessDayAdjustment bda    = BusinessDayAdjustment.of(bdc, holCal);
                PeriodicSchedule      defn   = PeriodicSchedule.builder().startDate(start).endDate(end).frequency(freq).businessDayAdjustment(bda).stubConvention(stub).rollConvention(roll).build();
                try
                {
                    Schedule schedule = defn.createSchedule(REF_DATA);
                    Console.WriteLine(schedule);
                    resultGrid.Items = FXCollections.observableArrayList(schedule.Periods);
                }
                catch (ScheduleException ex)
                {
                    resultGrid.Items       = FXCollections.emptyObservableList();
                    resultGrid.Placeholder = new Label(ex.Message);
                    Console.WriteLine(ex.Message);
                }
            };

            // layout the components
            GridPane gp = new GridPane();

            gp.Hgap    = 10;
            gp.Vgap    = 10;
            gp.Padding = new Insets(0, 10, 0, 10);
            gp.add(startLbl, 1, 1);
            gp.add(startInp, 2, 1);
            gp.add(endLbl, 1, 2);
            gp.add(endInp, 2, 2);
            gp.add(freqLbl, 1, 3);
            gp.add(freqInp, 2, 3);
            gp.add(bdcLbl, 3, 1);
            gp.add(bdcInp, 4, 1);
            gp.add(holidayLbl, 3, 2);
            gp.add(holidayInp, 4, 2);
            gp.add(stubLbl, 3, 3);
            gp.add(stubInp, 4, 3);
            gp.add(rollLbl, 3, 4);
            gp.add(rollInp, 4, 4);
            gp.add(btn, 3, 5, 2, 1);
            gp.add(resultGrid, 1, 7, 4, 1);

            BorderPane bp    = new BorderPane(gp);
            Scene      scene = new Scene(bp, 600, 600);

            // launch
            primaryStage.Title = "Periodic schedule generator";
            primaryStage.Scene = scene;
            primaryStage.show();
        }
Esempio n. 30
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test(dataProvider = "name") public void test_toString(RollConvention convention, String name)
        public virtual void test_toString(RollConvention convention, string name)
        {
            assertEquals(convention.ToString(), name);
        }