tags:

views:

60

answers:

2

hi,

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;
        }
}
+2  A: 
Andreas_D
@Andreas and @Dean thanks guys u made my day.. U guys rock..
salman
A: 

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.

Dean J
Or in this case, just `Collections.singletonList<HourRange>(new HourRange...`
Mark Peters