Browse Source

Merge "IntList: support contains(int)"

stable-4.9
David Pursehouse 7 years ago committed by Gerrit Code Review @ Eclipse.org
parent
commit
8391cc233b
  1. 11
      org.eclipse.jgit.test/tst/org/eclipse/jgit/util/IntListTest.java
  2. 15
      org.eclipse.jgit/src/org/eclipse/jgit/util/IntList.java

11
org.eclipse.jgit.test/tst/org/eclipse/jgit/util/IntListTest.java

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

15
org.eclipse.jgit/src/org/eclipse/jgit/util/IntList.java

@ -70,6 +70,21 @@ public class IntList {
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…
Cancel
Save