Skip to content

Commit

Permalink
Add static method BooleanArrayList.newWithNValues
Browse files Browse the repository at this point in the history
* Add static method BooleanArrayList.newWithNValues

Following code in eclipse-collections-code-generator/src/main/resources/impl/list/mutable/primitiveArrayList.stg

Signed-off-by: guoci <zguoci@gmail.com>

* response to comments by motlin

Signed-off-by: guoci <zguoci@gmail.com>
  • Loading branch information
guoci authored and motlin committed May 8, 2016
1 parent 96cb0e6 commit 1546bbd
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
2 changes: 1 addition & 1 deletion RELEASE_NOTE_DRAFT.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

New Functionality
-----------------

* Added static method BooleanArrayList.newWithNValues, following other primitive ArrayLists.
* Changed MutableBagIterable.addOccurrences(T item, int occurrences) to return the updated number of occurrences instead of void.
* Implemented Bags.mutable.ofAll(Iterable<? extends T> items) and Bags.mutable.withAll(Iterable<? extends T> items).
* Implemented Multimap.keySet() to return an unmodifiable SetIterable of keys.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,20 @@ public static BooleanArrayList newList(BooleanIterable source)
return new BooleanArrayList(source);
}

/**
* @since 8.0
*/
public static BooleanArrayList newWithNValues(int size, boolean value)
{
BooleanArrayList newList = new BooleanArrayList(size);
newList.size = size;
if (newList.items != null)
{
newList.items.set(0, size, value);
}
return newList;
}

@Override
public int size()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,21 @@ public void makeString()
Assert.assertEquals("", this.newWith().makeString());
}

@Test
public void newWithNValues()
{
Assert.assertEquals(this.newWith(true, true, true), BooleanArrayList.newWithNValues(3, true));
Assert.assertEquals(this.newWith(false, false), BooleanArrayList.newWithNValues(2, false));
Assert.assertEquals(this.newWith(), BooleanArrayList.newWithNValues(0, false));
Assert.assertEquals(this.newWith(), BooleanArrayList.newWithNValues(0, true));
}

@Test(expected = NegativeArraySizeException.class)
public void newWithNValues_throws_negative_size()
{
BooleanArrayList.newWithNValues(-1, true);
}

@Override
@Test
public void appendString()
Expand Down

0 comments on commit 1546bbd

Please sign in to comment.