tabs replaced by spaces

new tests added
This commit is contained in:
beradrian 2015-03-23 13:06:03 +02:00
parent a3995141bf
commit 06506aecf9
2 changed files with 253 additions and 241 deletions

View File

@ -2043,10 +2043,10 @@ public class ArrayUtils {
return;
}
for (int i = 0; i < len; i++) {
byte aux = array[offset1 + i];
array[offset1 + i] = array[offset2 + i];
array[offset2 + i] = aux;
}
byte aux = array[offset1 + i];
array[offset1 + i] = array[offset2 + i];
array[offset2 + i] = aux;
}
}
/**
@ -2065,10 +2065,10 @@ public class ArrayUtils {
return;
}
for (int i = 0; i < len; i++) {
char aux = array[offset1 + i];
array[offset1 + i] = array[offset2 + i];
array[offset2 + i] = aux;
}
char aux = array[offset1 + i];
array[offset1 + i] = array[offset2 + i];
array[offset2 + i] = aux;
}
}
/**
@ -2087,10 +2087,10 @@ public class ArrayUtils {
return;
}
for (int i = 0; i < len; i++) {
double aux = array[offset1 + i];
array[offset1 + i] = array[offset2 + i];
array[offset2 + i] = aux;
}
double aux = array[offset1 + i];
array[offset1 + i] = array[offset2 + i];
array[offset2 + i] = aux;
}
}
/**
@ -2109,10 +2109,10 @@ public class ArrayUtils {
return;
}
for (int i = 0; i < len; i++) {
float aux = array[offset1 + i];
array[offset1 + i] = array[offset2 + i];
array[offset2 + i] = aux;
}
float aux = array[offset1 + i];
array[offset1 + i] = array[offset2 + i];
array[offset2 + i] = aux;
}
}
/**
@ -2131,10 +2131,10 @@ public class ArrayUtils {
return;
}
for (int i = 0; i < len; i++) {
int aux = array[offset1 + i];
array[offset1 + i] = array[offset2 + i];
array[offset2 + i] = aux;
}
int aux = array[offset1 + i];
array[offset1 + i] = array[offset2 + i];
array[offset2 + i] = aux;
}
}
/**
@ -2153,9 +2153,9 @@ public class ArrayUtils {
return;
}
for (int i = 0; i < len; i++) {
long aux = array[offset1 + i];
array[offset1 + i] = array[offset2 + i];
array[offset2 + i] = aux;
long aux = array[offset1 + i];
array[offset1 + i] = array[offset2 + i];
array[offset2 + i] = aux;
}
}
@ -2175,10 +2175,10 @@ public class ArrayUtils {
return;
}
for (int i = 0; i < len; i++) {
Object aux = array[offset1 + i];
array[offset1 + i] = array[offset2 + i];
array[offset2 + i] = aux;
}
Object aux = array[offset1 + i];
array[offset1 + i] = array[offset2 + i];
array[offset2 + i] = aux;
}
}
/**
@ -2197,10 +2197,10 @@ public class ArrayUtils {
return;
}
for (int i = 0; i < len; i++) {
short aux = array[offset1 + i];
array[offset1 + i] = array[offset2 + i];
array[offset2 + i] = aux;
}
short aux = array[offset1 + i];
array[offset1 + i] = array[offset2 + i];
array[offset2 + i] = aux;
}
}
// Shift
@ -2361,35 +2361,35 @@ public class ArrayUtils {
return;
}
if (startIndexInclusive < 0) {
startIndexInclusive = 0;
startIndexInclusive = 0;
}
if (endIndexExclusive >= array.length) {
endIndexExclusive = array.length;
endIndexExclusive = array.length;
}
int n = endIndexExclusive - startIndexInclusive;
if (n <= 1) {
return;
return;
}
offset %= n;
if (offset < 0) {
offset += n;
}
while (n > 1 && offset > 0) {
int n_offset = n - offset;
if (offset > n_offset) {
swap(array, startIndexInclusive, startIndexInclusive + n - n_offset, n_offset);
n = offset;
offset -= n_offset;
} else if (offset < n_offset) {
swap(array, startIndexInclusive, startIndexInclusive + n_offset, offset);
startIndexInclusive += offset;
n = n_offset;
} else {
swap(array, startIndexInclusive, startIndexInclusive + n_offset, offset);
break;
}
}
offset %= n;
if (offset < 0) {
offset += n;
}
while (n > 1 && offset > 0) {
int n_offset = n - offset;
if (offset > n_offset) {
swap(array, startIndexInclusive, startIndexInclusive + n - n_offset, n_offset);
n = offset;
offset -= n_offset;
} else if (offset < n_offset) {
swap(array, startIndexInclusive, startIndexInclusive + n_offset, offset);
startIndexInclusive += offset;
n = n_offset;
} else {
swap(array, startIndexInclusive, startIndexInclusive + n_offset, offset);
break;
}
}
}
/**
@ -2419,35 +2419,35 @@ public class ArrayUtils {
return;
}
if (startIndexInclusive < 0) {
startIndexInclusive = 0;
startIndexInclusive = 0;
}
if (endIndexExclusive >= array.length) {
endIndexExclusive = array.length;
endIndexExclusive = array.length;
}
int n = endIndexExclusive - startIndexInclusive;
if (n <= 1) {
return;
return;
}
offset %= n;
if (offset < 0) {
offset += n;
}
while (n > 1 && offset > 0) {
int n_offset = n - offset;
if (offset > n_offset) {
swap(array, startIndexInclusive, startIndexInclusive + n - n_offset, n_offset);
n = offset;
offset -= n_offset;
} else if (offset < n_offset) {
swap(array, startIndexInclusive, startIndexInclusive + n_offset, offset);
startIndexInclusive += offset;
n = n_offset;
} else {
swap(array, startIndexInclusive, startIndexInclusive + n_offset, offset);
break;
}
}
offset %= n;
if (offset < 0) {
offset += n;
}
while (n > 1 && offset > 0) {
int n_offset = n - offset;
if (offset > n_offset) {
swap(array, startIndexInclusive, startIndexInclusive + n - n_offset, n_offset);
n = offset;
offset -= n_offset;
} else if (offset < n_offset) {
swap(array, startIndexInclusive, startIndexInclusive + n_offset, offset);
startIndexInclusive += offset;
n = n_offset;
} else {
swap(array, startIndexInclusive, startIndexInclusive + n_offset, offset);
break;
}
}
}
/**
@ -2477,35 +2477,35 @@ public class ArrayUtils {
return;
}
if (startIndexInclusive < 0) {
startIndexInclusive = 0;
startIndexInclusive = 0;
}
if (endIndexExclusive >= array.length) {
endIndexExclusive = array.length;
endIndexExclusive = array.length;
}
int n = endIndexExclusive - startIndexInclusive;
if (n <= 1) {
return;
return;
}
offset %= n;
if (offset < 0) {
offset += n;
}
while (n > 1 && offset > 0) {
int n_offset = n - offset;
if (offset > n_offset) {
swap(array, startIndexInclusive, startIndexInclusive + n - n_offset, n_offset);
n = offset;
offset -= n_offset;
} else if (offset < n_offset) {
swap(array, startIndexInclusive, startIndexInclusive + n_offset, offset);
startIndexInclusive += offset;
n = n_offset;
} else {
swap(array, startIndexInclusive, startIndexInclusive + n_offset, offset);
break;
}
}
offset %= n;
if (offset < 0) {
offset += n;
}
while (n > 1 && offset > 0) {
int n_offset = n - offset;
if (offset > n_offset) {
swap(array, startIndexInclusive, startIndexInclusive + n - n_offset, n_offset);
n = offset;
offset -= n_offset;
} else if (offset < n_offset) {
swap(array, startIndexInclusive, startIndexInclusive + n_offset, offset);
startIndexInclusive += offset;
n = n_offset;
} else {
swap(array, startIndexInclusive, startIndexInclusive + n_offset, offset);
break;
}
}
}
/**
@ -2535,35 +2535,35 @@ public class ArrayUtils {
return;
}
if (startIndexInclusive < 0) {
startIndexInclusive = 0;
startIndexInclusive = 0;
}
if (endIndexExclusive >= array.length) {
endIndexExclusive = array.length;
endIndexExclusive = array.length;
}
int n = endIndexExclusive - startIndexInclusive;
if (n <= 1) {
return;
return;
}
offset %= n;
if (offset < 0) {
offset += n;
}
while (n > 1 && offset > 0) {
int n_offset = n - offset;
if (offset > n_offset) {
swap(array, startIndexInclusive, startIndexInclusive + n - n_offset, n_offset);
n = offset;
offset -= n_offset;
} else if (offset < n_offset) {
swap(array, startIndexInclusive, startIndexInclusive + n_offset, offset);
startIndexInclusive += offset;
n = n_offset;
} else {
swap(array, startIndexInclusive, startIndexInclusive + n_offset, offset);
break;
}
}
offset %= n;
if (offset < 0) {
offset += n;
}
while (n > 1 && offset > 0) {
int n_offset = n - offset;
if (offset > n_offset) {
swap(array, startIndexInclusive, startIndexInclusive + n - n_offset, n_offset);
n = offset;
offset -= n_offset;
} else if (offset < n_offset) {
swap(array, startIndexInclusive, startIndexInclusive + n_offset, offset);
startIndexInclusive += offset;
n = n_offset;
} else {
swap(array, startIndexInclusive, startIndexInclusive + n_offset, offset);
break;
}
}
}
/**
@ -2593,35 +2593,35 @@ public class ArrayUtils {
return;
}
if (startIndexInclusive < 0) {
startIndexInclusive = 0;
startIndexInclusive = 0;
}
if (endIndexExclusive >= array.length) {
endIndexExclusive = array.length;
endIndexExclusive = array.length;
}
int n = endIndexExclusive - startIndexInclusive;
if (n <= 1) {
return;
return;
}
offset %= n;
if (offset < 0) {
offset += n;
}
while (n > 1 && offset > 0) {
int n_offset = n - offset;
if (offset > n_offset) {
swap(array, startIndexInclusive, startIndexInclusive + n - n_offset, n_offset);
n = offset;
offset -= n_offset;
} else if (offset < n_offset) {
swap(array, startIndexInclusive, startIndexInclusive + n_offset, offset);
startIndexInclusive += offset;
n = n_offset;
} else {
swap(array, startIndexInclusive, startIndexInclusive + n_offset, offset);
break;
}
}
offset %= n;
if (offset < 0) {
offset += n;
}
while (n > 1 && offset > 0) {
int n_offset = n - offset;
if (offset > n_offset) {
swap(array, startIndexInclusive, startIndexInclusive + n - n_offset, n_offset);
n = offset;
offset -= n_offset;
} else if (offset < n_offset) {
swap(array, startIndexInclusive, startIndexInclusive + n_offset, offset);
startIndexInclusive += offset;
n = n_offset;
} else {
swap(array, startIndexInclusive, startIndexInclusive + n_offset, offset);
break;
}
}
}
/**
@ -2651,35 +2651,35 @@ public class ArrayUtils {
return;
}
if (startIndexInclusive < 0) {
startIndexInclusive = 0;
startIndexInclusive = 0;
}
if (endIndexExclusive >= array.length) {
endIndexExclusive = array.length;
endIndexExclusive = array.length;
}
int n = endIndexExclusive - startIndexInclusive;
if (n <= 1) {
return;
return;
}
offset %= n;
if (offset < 0) {
offset += n;
}
while (n > 1 && offset > 0) {
int n_offset = n - offset;
if (offset > n_offset) {
swap(array, startIndexInclusive, startIndexInclusive + n - n_offset, n_offset);
n = offset;
offset -= n_offset;
} else if (offset < n_offset) {
swap(array, startIndexInclusive, startIndexInclusive + n_offset, offset);
startIndexInclusive += offset;
n = n_offset;
} else {
swap(array, startIndexInclusive, startIndexInclusive + n_offset, offset);
break;
}
}
offset %= n;
if (offset < 0) {
offset += n;
}
while (n > 1 && offset > 0) {
int n_offset = n - offset;
if (offset > n_offset) {
swap(array, startIndexInclusive, startIndexInclusive + n - n_offset, n_offset);
n = offset;
offset -= n_offset;
} else if (offset < n_offset) {
swap(array, startIndexInclusive, startIndexInclusive + n_offset, offset);
startIndexInclusive += offset;
n = n_offset;
} else {
swap(array, startIndexInclusive, startIndexInclusive + n_offset, offset);
break;
}
}
}
/**
@ -2708,35 +2708,35 @@ public class ArrayUtils {
return;
}
if (startIndexInclusive < 0) {
startIndexInclusive = 0;
startIndexInclusive = 0;
}
if (endIndexExclusive >= array.length) {
endIndexExclusive = array.length;
endIndexExclusive = array.length;
}
int n = endIndexExclusive - startIndexInclusive;
if (n <= 1) {
return;
return;
}
offset %= n;
if (offset < 0) {
offset += n;
}
while (n > 1 && offset > 0) {
int n_offset = n - offset;
if (offset > n_offset) {
swap(array, startIndexInclusive, startIndexInclusive + n - n_offset, n_offset);
n = offset;
offset -= n_offset;
} else if (offset < n_offset) {
swap(array, startIndexInclusive, startIndexInclusive + n_offset, offset);
startIndexInclusive += offset;
n = n_offset;
} else {
swap(array, startIndexInclusive, startIndexInclusive + n_offset, offset);
break;
}
}
offset %= n;
if (offset < 0) {
offset += n;
}
while (n > 1 && offset > 0) {
int n_offset = n - offset;
if (offset > n_offset) {
swap(array, startIndexInclusive, startIndexInclusive + n - n_offset, n_offset);
n = offset;
offset -= n_offset;
} else if (offset < n_offset) {
swap(array, startIndexInclusive, startIndexInclusive + n_offset, offset);
startIndexInclusive += offset;
n = n_offset;
} else {
swap(array, startIndexInclusive, startIndexInclusive + n_offset, offset);
break;
}
}
}
/**
@ -2765,35 +2765,35 @@ public class ArrayUtils {
return;
}
if (startIndexInclusive < 0) {
startIndexInclusive = 0;
startIndexInclusive = 0;
}
if (endIndexExclusive >= array.length) {
endIndexExclusive = array.length;
endIndexExclusive = array.length;
}
int n = endIndexExclusive - startIndexInclusive;
if (n <= 1) {
return;
return;
}
offset %= n;
if (offset < 0) {
offset += n;
}
while (n > 1 && offset > 0) {
int n_offset = n - offset;
if (offset > n_offset) {
swap(array, startIndexInclusive, startIndexInclusive + n - n_offset, n_offset);
n = offset;
offset -= n_offset;
} else if (offset < n_offset) {
swap(array, startIndexInclusive, startIndexInclusive + n_offset, offset);
startIndexInclusive += offset;
n = n_offset;
} else {
swap(array, startIndexInclusive, startIndexInclusive + n_offset, offset);
break;
}
}
offset %= n;
if (offset < 0) {
offset += n;
}
while (n > 1 && offset > 0) {
int n_offset = n - offset;
if (offset > n_offset) {
swap(array, startIndexInclusive, startIndexInclusive + n - n_offset, n_offset);
n = offset;
offset -= n_offset;
} else if (offset < n_offset) {
swap(array, startIndexInclusive, startIndexInclusive + n_offset, offset);
startIndexInclusive += offset;
n = n_offset;
} else {
swap(array, startIndexInclusive, startIndexInclusive + n_offset, offset);
break;
}
}
}
/**
@ -2823,35 +2823,35 @@ public class ArrayUtils {
return;
}
if (startIndexInclusive < 0) {
startIndexInclusive = 0;
startIndexInclusive = 0;
}
if (endIndexExclusive >= array.length) {
endIndexExclusive = array.length;
endIndexExclusive = array.length;
}
int n = endIndexExclusive - startIndexInclusive;
if (n <= 1) {
return;
return;
}
offset %= n;
if (offset < 0) {
offset += n;
}
while (n > 1 && offset > 0) {
int n_offset = n - offset;
if (offset > n_offset) {
swap(array, startIndexInclusive, startIndexInclusive + n - n_offset, n_offset);
n = offset;
offset -= n_offset;
} else if (offset < n_offset) {
swap(array, startIndexInclusive, startIndexInclusive + n_offset, offset);
startIndexInclusive += offset;
n = n_offset;
} else {
swap(array, startIndexInclusive, startIndexInclusive + n_offset, offset);
break;
}
}
offset %= n;
if (offset < 0) {
offset += n;
}
while (n > 1 && offset > 0) {
int n_offset = n - offset;
if (offset > n_offset) {
swap(array, startIndexInclusive, startIndexInclusive + n - n_offset, n_offset);
n = offset;
offset -= n_offset;
} else if (offset < n_offset) {
swap(array, startIndexInclusive, startIndexInclusive + n_offset, offset);
startIndexInclusive += offset;
n = n_offset;
} else {
swap(array, startIndexInclusive, startIndexInclusive + n_offset, offset);
break;
}
}
}
// IndexOf search

View File

@ -2123,9 +2123,21 @@ public class ArrayUtilsTest {
public void testSwapChar() {
char[] array = new char[] {1, 2, 3};
ArrayUtils.swap(array, 0, 2);
assertEquals(3, array[0]);
assertEquals(2, array[1]);
assertEquals(1, array[2]);
assertArrayEquals(new char[] {3, 2, 1}, array);
array = new char[] {1, 2, 3};
ArrayUtils.swap(array, 0, 0);
assertArrayEquals(new char[] {1, 2, 3}, array);
array = new char[] {1, 2, 3};
ArrayUtils.swap(array, 1, 0);
assertArrayEquals(new char[] {2, 1, 3}, array);
}
@Test(expected = ArrayIndexOutOfBoundsException.class)
public void testSwapCharOutOfBounds() {
char[] array = new char[] {1, 2, 3};
ArrayUtils.swap(array, 0, 5);
}
@Test