Merge "IntList: support contains(int)"

This commit is contained in:
David Pursehouse 2017-07-28 14:18:21 -04:00 committed by Gerrit Code Review @ Eclipse.org
commit 8391cc233b
2 changed files with 26 additions and 0 deletions

View File

@ -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();

View File

@ -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()}).