mirror of
https://github.com/iSoron/uhabits.git
synced 2025-12-06 09:08:52 -06:00
Disallow empty WeekdayLists
This commit is contained in:
@@ -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()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user