Menu

Work with recurrences

Anonymous
2014-07-10
2014-07-17
  • Anonymous

    Anonymous - 2014-07-10

    Hello,

    I'm back for a new question about recurrences.
    I would like to create my Recurrence step by step, but I'm not able to figure out how I can do that.

    For example, I initialized my Recurrence like this :
    Recurrence recur = new Recurrence.Builder(Frequency.YEARLY).build();

    And then I would like to give some days in "byDay", but there is no setters on the Recurrence attributes.
    How can I update this data ?
    The example in the quick start can't save me, could you give me a more complex one ?

    I'm still in version 0.3.1.

    Thanks a lot,
    Perrine.

     
  • Caruyer Perrine

    Caruyer Perrine - 2014-07-10

    Oops, I'm sorry, it seems there was a problem with my session...

     
  • Michael Angstadt

    Hi again Perrine!

    The Recurrence class is immutable, which is why it doesn't have setters. To populate the object with data, call the setter methods on its builder class like so:

    :::java
    Recurrence recur = new Recurrence.Builder(Frequency.YEARLY)
      .byDay(DayOfWeek.MONDAY)
      .count(5)
      .build();
    
     
  • Caruyer Perrine

    Caruyer Perrine - 2014-07-11

    Hello,
    Thanks a lot for you answer!
    So, I have to prepare all my data before creating de final recurrence.

    But there is something else I have a problem.
    If I want this : "BYDAY=MO,TU,WE,TH,FR", I have to do
    new Recurrence.Builder(frequency).byDay(DayOfWeek.MONDAY).byDay(DayOfWeek.THURSDAY).....build();
    I would like to do something with a List or only one variable, so that I prepare ma variable before creating the object, is there any way to do that ?

    I'm sorry if I ask stupid questions ;)
    Thanks !

     
  • Caruyer Perrine

    Caruyer Perrine - 2014-07-11

    I did like this :

        Builder builder = new biweekly.util.Recurrence.Builder(frequency);
        for (DayOfWeek byDay : byDays){
            builder.byDay(byDay);
        }
    

    But if you have something more beautiful, why not :p
    Thanks again, it is always a pleasure to work with biweekly ;)

     
  • Michael Angstadt

    Sure, I'll create a method that accepts a vararg of days. I can see how handy that could be! Thanks for your input, as always. ;)

    :::java
    Recurrence recur = new Recurrence.Builder(frequency).byDay(DayOfWeek.MONDAY, DayOfWeek.TUESDAY, DayOfWeek.WEDNESDAY).build();
    
     
  • Caruyer Perrine

    Caruyer Perrine - 2014-07-15

    Hello,
    Thank you for taking my opinion into consideration, but this solution is not the one I would have expected, because it's difficult to be generic.
    When I create my recurrence, I do not have necessarily the same days, so I would like to prepare a list before creating my recurrence.

    Something like this for example :

        List<DayOfWeek> byDays = new ArrayList<DayOfWeek>(); 
        // some code to know what days I need and initialize my list .... 
        Recurrence recur = new Recurrence.Builder(frequency).byDays(byDays).build();
    

    I don't know if I'm clear, do you understand what I mean ?

     
  • Michael Angstadt

    I could create a "byDays()" method that takes a "List" as a parameter. Is that what you are suggesting?

     
  • Caruyer Perrine

    Caruyer Perrine - 2014-07-17

    Yes, that's it ! :)
    I think it will be easier to use, but it's just an idea ;)

     
  • Michael Angstadt

    I agree. Thanks for the idea. :)

     

Anonymous
Anonymous

Add attachments
Cancel