]> source.dussan.org Git - jgit.git/commitdiff
IntList: support contains(int) 72/101772/2
authorShawn Pearce <spearce@spearce.org>
Thu, 20 Jul 2017 08:51:44 +0000 (01:51 -0700)
committerShawn Pearce <spearce@spearce.org>
Fri, 28 Jul 2017 17:18:27 +0000 (10:18 -0700)
LongList supports contains(long).
IntList should also support contains(int).

Change-Id: Ic7a81c3c25b0f10d92087b56e9f200b676060f63

org.eclipse.jgit.test/tst/org/eclipse/jgit/util/IntListTest.java
org.eclipse.jgit/src/org/eclipse/jgit/util/IntList.java

index c6eca9d5e7048bd598018b7c697a282feaa70406..d6ea8c604c06447767ce6b1904783084d1e46ea0 100644 (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 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();
index 658dd06d46af00f64650529cdac67efb5790b3ae..0a3c846a0e2253702efb42a8076bf5998170658c 100644 (file)
@@ -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()}).