diff options
author | David Pursehouse <david.pursehouse@gmail.com> | 2017-07-28 14:18:21 -0400 |
---|---|---|
committer | Gerrit Code Review @ Eclipse.org <gerrit@eclipse.org> | 2017-07-28 14:18:21 -0400 |
commit | 8391cc233b02e180a473fedfadd3cec9d2532fb1 (patch) | |
tree | 03d7794cf0ce5c6a3a45003ac945f3ca69c57d1c | |
parent | 9f462a99141edfb62915c725e70575ea539159cc (diff) | |
parent | 652a6b033428e6c668333bcf2d510332dca1f8c0 (diff) | |
download | jgit-8391cc233b02e180a473fedfadd3cec9d2532fb1.tar.gz jgit-8391cc233b02e180a473fedfadd3cec9d2532fb1.zip |
Merge "IntList: support contains(int)"
-rw-r--r-- | org.eclipse.jgit.test/tst/org/eclipse/jgit/util/IntListTest.java | 11 | ||||
-rw-r--r-- | org.eclipse.jgit/src/org/eclipse/jgit/util/IntList.java | 15 |
2 files changed, 26 insertions, 0 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/IntListTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/IntListTest.java index c6eca9d5e7..d6ea8c604c 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/IntListTest.java +++ b/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; @@ -186,6 +187,16 @@ public class IntListTest { } @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(); i.add(1); diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/util/IntList.java b/org.eclipse.jgit/src/org/eclipse/jgit/util/IntList.java index 658dd06d46..0a3c846a0e 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/util/IntList.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/util/IntList.java @@ -71,6 +71,21 @@ public class IntList { } /** + * 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()}). * @return the number at the specified index |