0

I have a method which looks like this

public void setDayIntervals(Days day, List<HourRange> ranges) {
        int hourMask = 0;
        for (HourRange intRange : ranges) {
                     int Start= intRange.getStart();
                     int end = intRange.getEnd();
            }
        }

}

I have to pass List of Ranges from another class.

for(int s = 0; s < adSchedule.getTargets().length ; s++ ){
        List<HourRange> ranges = null;
        int Start =  adSchedule.getTargets(s).getStartHour();
        int end =  adSchedule.getTargets(s).getEndHour()-1;
            if(adSchedule.getTargets(s).getDayOfWeek()==DayOfWeek.MONDAY ){
               // ranges ????????? here i have to pass values Start and End 
               CamSchedule.setDayIntervals(Days.ONE, ranges);
             }
    }

Can someone tell me how to pass ranges in the above method setDayIntervals(Days.one, ramges)

public static class HourRange {
        int start;
        int end;

        public HourRange(int start, int end) {
            super();
            if(start > end) 
                throw new IllegalArgumentException();
            this.start = start;
            this.end = end;
        }

        public int getStart() {
            return start;
        }

        public int getEnd() {
            return end;
        }
}
3
  • What does the constructor for the HourRange class look like? Commented Aug 24, 2010 at 13:52
  • Is this homework or are you maintaining someone else's code? Commented Aug 24, 2010 at 13:57
  • for HourRange: you don't need to call super() because HourRange extends nothing but Object. And you could add private modifiers to start and end to make the class immutable (unless someone uses dirty tricks like reflection..) Commented Aug 24, 2010 at 14:06

2 Answers 2

2

You have to create an HourRange object and add it to the list. Something like this:

 ranges.add(new HourRange(Start, end));

The example assumes that HourRange has this constructor:

 public HourRange(int start, int end) {
   // code to copy start and end to internal fields.
 }

(it has this constructor)

Sign up to request clarification or add additional context in comments.

Comments

0

Instead of

List<HourRange> ranges = null;

you probably want

List<HourRange> ranges = new ArrayList<HourRange>();

That gives you a list to add to; until you initialize ranges as a list, nothing can go into that list.

1 Comment

Or in this case, just Collections.singletonList<HourRange>(new HourRange...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.