Disallow empty WeekdayLists

pull/171/head
Alinson S. Xavier 9 years ago
parent af7c8b1f2e
commit b5cd4584b2

@ -29,9 +29,10 @@ public class WeekdayList
public WeekdayList(int packedList) public WeekdayList(int packedList)
{ {
if(packedList == 0) packedList = 127;
weekdays = new boolean[7]; weekdays = new boolean[7];
int current = 1;
int current = 1;
for (int i = 0; i < 7; i++) for (int i = 0; i < 7; i++)
{ {
if ((packedList & current) != 0) weekdays[i] = true; if ((packedList & current) != 0) weekdays[i] = true;
@ -41,6 +42,10 @@ public class WeekdayList
public WeekdayList(boolean weekdays[]) public WeekdayList(boolean weekdays[])
{ {
boolean isEmpty = true;
for(boolean b : weekdays) if(b) isEmpty = false;
if(isEmpty) throw new IllegalArgumentException("empty list");
this.weekdays = Arrays.copyOf(weekdays, 7); this.weekdays = Arrays.copyOf(weekdays, 7);
} }

@ -43,4 +43,11 @@ public class WeekdayListTest extends BaseUnitTest
assertThat(list.toArray(), equalTo(daysArray)); assertThat(list.toArray(), equalTo(daysArray));
assertThat(list.toInteger(), equalTo(daysInt)); assertThat(list.toInteger(), equalTo(daysInt));
} }
@Test
public void testEmpty()
{
WeekdayList list = new WeekdayList(0);
assertThat(list.toArray(), equalTo(WeekdayList.EVERY_DAY.toArray()));
}
} }

Loading…
Cancel
Save