我有一个看起来像这样的方法

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

}


我必须从另一个类传递范围列表。

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);
             }
    }


有人可以告诉我如何通过上述方法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;
        }
}

最佳答案

您必须创建一个HourRange对象并将其添加到列表中。像这样:

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


该示例假定HourRange具有此构造函数:

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



(具有此构造函数)

08-07 03:50