I might have misunderstood something but both of these tests fail:
@Test public void test3() { byte[] in = { 1, 2, 3, 4, 5, 6 }; byte[] find = { 3, 4, 5 }; assertEquals(2, findString(in, find)); // returns -1 } @Test public void test5() { byte[] in = { 1, 2, 3, 4, 5, 6 }; byte[] find = { 4, 5, 6 }; assertEquals(3, findString(in, find)); // returns -1 }
I think you should increase ii++
here instead of i
:
for(int ii = 1; ii < find.length; i++) {
So, try to use variables which are easer to tell apart from each other.
- Anyway, don't reinvent the wheel, there is a library for that! Guava has ana
IntsBytes
class with the following method:
public static int indexOf(byte[] array, byte[] target)
Returns the start position of the first occurrence of the specified target within array, or -1 if there is no such occurrence.
It's open-source, so you can compare their code with yours.
See also: Effective Java, 2nd edition, Item 47: Know and use the libraries (The author mentions only the JDK's built-in libraries but I think the reasoning could be true for other libraries too.)
I might have misunderstood something but both of these tests fail:
@Test public void test3() { byte[] in = { 1, 2, 3, 4, 5, 6 }; byte[] find = { 3, 4, 5 }; assertEquals(2, findString(in, find)); // returns -1 } @Test public void test5() { byte[] in = { 1, 2, 3, 4, 5, 6 }; byte[] find = { 4, 5, 6 }; assertEquals(3, findString(in, find)); // returns -1 }
I think you should increase ii++
here instead of i
:
for(int ii = 1; ii < find.length; i++) {
So, try to use variables which are easer to tell apart from each other.
- Anyway, don't reinvent the wheel, there is a library for that! Guava has an
Ints
class with the following method:
public static int indexOf(byte[] array, byte[] target)
Returns the start position of the first occurrence of the specified target within array, or -1 if there is no such occurrence.
It's open-source, so you can compare their code with yours.
See also: Effective Java, 2nd edition, Item 47: Know and use the libraries (The author mentions only the JDK's built-in libraries but I think the reasoning could be true for other libraries too.)
I might have misunderstood something but both of these tests fail:
@Test public void test3() { byte[] in = { 1, 2, 3, 4, 5, 6 }; byte[] find = { 3, 4, 5 }; assertEquals(2, findString(in, find)); // returns -1 } @Test public void test5() { byte[] in = { 1, 2, 3, 4, 5, 6 }; byte[] find = { 4, 5, 6 }; assertEquals(3, findString(in, find)); // returns -1 }
I think you should increase ii++
here instead of i
:
for(int ii = 1; ii < find.length; i++) {
So, try to use variables which are easer to tell apart from each other.
- Anyway, don't reinvent the wheel, there is a library for that! Guava has a
Bytes
class with the following method:
public static int indexOf(byte[] array, byte[] target)
Returns the start position of the first occurrence of the specified target within array, or -1 if there is no such occurrence.
It's open-source, so you can compare their code with yours.
See also: Effective Java, 2nd edition, Item 47: Know and use the libraries (The author mentions only the JDK's built-in libraries but I think the reasoning could be true for other libraries too.)
I might have misunderstood something but both of these tests fail:
@Test public void test3() { byte[] in = { 1, 2, 3, 4, 5, 6 }; byte[] find = { 3, 4, 5 }; assertEquals(2, findString(in, find)); // returns -1 } @Test public void test5() { byte[] in = { 1, 2, 3, 4, 5, 6 }; byte[] find = { 4, 5, 6 }; assertEquals(3, findString(in, find)); // returns -1 }
I think you should increase ii++
here instead of i
:
for(int ii = 1; ii < find.length; i++) {
So, try to use variables which are easer to tell apart from each other.
Anyway, don't reinvent the weel, there is a library for that! Guava has an
Anyway, don't reinvent the wheel, there is a library for that! Guava has anInts
class with the following method:Ints
class with the following method:
public static int indexOf(byte[] array, byte[] target)
Returns the start position of the first occurrence of the specified target within array, or -1 if there is no such occurrence.
It's open-source, so you can compare their code with yours.
See also: Effective Java, 2nd edition, Item 47: Know and use the libraries (The author mentions only the JDK's built-in libraries but I think the reasoning could be true for other libraries too.)
I might have misunderstood something but both of these tests fail:
@Test public void test3() { byte[] in = { 1, 2, 3, 4, 5, 6 }; byte[] find = { 3, 4, 5 }; assertEquals(2, findString(in, find)); // returns -1 } @Test public void test5() { byte[] in = { 1, 2, 3, 4, 5, 6 }; byte[] find = { 4, 5, 6 }; assertEquals(3, findString(in, find)); // returns -1 }
Anyway, don't reinvent the weel, there is a library for that! Guava has an
Ints
class with the following method:
public static int indexOf(byte[] array, byte[] target)
Returns the start position of the first occurrence of the specified target within array, or -1 if there is no such occurrence.
See also: Effective Java, 2nd edition, Item 47: Know and use the libraries (The author mentions only the JDK's built-in libraries but I think the reasoning could be true for other libraries too.)
I might have misunderstood something but both of these tests fail:
@Test public void test3() { byte[] in = { 1, 2, 3, 4, 5, 6 }; byte[] find = { 3, 4, 5 }; assertEquals(2, findString(in, find)); // returns -1 } @Test public void test5() { byte[] in = { 1, 2, 3, 4, 5, 6 }; byte[] find = { 4, 5, 6 }; assertEquals(3, findString(in, find)); // returns -1 }
I think you should increase ii++
here instead of i
:
for(int ii = 1; ii < find.length; i++) {
So, try to use variables which are easer to tell apart from each other.
- Anyway, don't reinvent the wheel, there is a library for that! Guava has an
Ints
class with the following method:
public static int indexOf(byte[] array, byte[] target)
Returns the start position of the first occurrence of the specified target within array, or -1 if there is no such occurrence.
It's open-source, so you can compare their code with yours.
See also: Effective Java, 2nd edition, Item 47: Know and use the libraries (The author mentions only the JDK's built-in libraries but I think the reasoning could be true for other libraries too.)
I might have misunderstood something but both of these tests fail:
@Test public void test3() { byte[] in = { 1, 2, 3, 4, 5, 6 }; byte[] find = { 3, 4, 5 }; assertEquals(2, findString(in, find)); // returns -1 } @Test public void test5() { byte[] in = { 1, 2, 3, 4, 5, 6 }; byte[] find = { 4, 5, 6 }; assertEquals(3, findString(in, find)); // returns -1 }
Anyway, don't reinvent the weel, there is a library for that! Guava has an
Ints
class with the following method:
public static int indexOf(byte[] array, byte[] target)
Returns the start position of the first occurrence of the specified target within array, or -1 if there is no such occurrence.
See also: Effective Java, 2nd edition, Item 47: Know and use the libraries (The author mentions only the JDK's built-in libraries but I think the reasoning could be true for other libraries too.)