Merge "IntList: support contains(int)"
This commit is contained in:
commit
8391cc233b
|
@ -44,6 +44,7 @@
|
|||
package org.eclipse.jgit.util;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
|
@ -185,6 +186,16 @@ public void testSet() {
|
|||
assertEquals(2, i.get(1));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testContains() {
|
||||
IntList i = new IntList();
|
||||
i.add(1);
|
||||
i.add(4);
|
||||
assertTrue(i.contains(1));
|
||||
assertTrue(i.contains(4));
|
||||
assertFalse(i.contains(2));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testToString() {
|
||||
final IntList i = new IntList();
|
||||
|
|
|
@ -70,6 +70,21 @@ public int size() {
|
|||
return count;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if an entry appears in this collection.
|
||||
*
|
||||
* @param value
|
||||
* the value to search for.
|
||||
* @return true of {@code value} appears in this list.
|
||||
* @since 4.9
|
||||
*/
|
||||
public boolean contains(int value) {
|
||||
for (int i = 0; i < count; i++)
|
||||
if (entries[i] == value)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param i
|
||||
* index to read, must be in the range [0, {@link #size()}).
|
||||
|
|
Loading…
Reference in New Issue