ArrayUtils.java

1
package fr.sii.ogham.core.util;
2
3
import java.lang.reflect.Array;
4
import java.util.Arrays;
5
6
/**
7
 * Utility class for manipulating arrays.
8
 */
9
public final class ArrayUtils {
10
	/**
11
	 * Create an array starting with first element and followed by others.
12
	 * <p>
13
	 * This can be useful when handling vararg parameters and when you want to
14
	 * force to have at least one value.
15
	 * <p>
16
	 * 
17
	 * @param first
18
	 *            the first element
19
	 * @param others
20
	 *            the other elements
21
	 * @param <T>
22
	 *            the type of each element in the array
23
	 * @return the combined array
24
	 * @throws IllegalArgumentException
25
	 *             if first or others is null
26
	 */
27
	public static <T> T[] concat(T first, T[] others) {
28 3 1. concat : negated conditional → NO_COVERAGE
2. concat : negated conditional → KILLED
3. concat : negated conditional → KILLED
		if (first == null) {
29
			throw new IllegalArgumentException("first cannot be null");
30
		}
31
		@SuppressWarnings("unchecked")
32
		T[] arr = (T[]) Array.newInstance(first.getClass(), 1);
33
		arr[0] = first;
34 3 1. concat : replaced return value with null for fr/sii/ogham/core/util/ArrayUtils::concat → NO_COVERAGE
2. concat : replaced return value with null for fr/sii/ogham/core/util/ArrayUtils::concat → KILLED
3. concat : replaced return value with null for fr/sii/ogham/core/util/ArrayUtils::concat → KILLED
		return concat(arr, others);
35
	}
36
37
	/**
38
	 * Combine two arrays. It creates a new array that contains all the elements
39
	 * of first followed by all elements of second.
40
	 * 
41
	 * @param first
42
	 *            the first array
43
	 * @param second
44
	 *            the second array
45
	 * @param <T>
46
	 *            the type of each element in the array
47
	 * @return the combined array
48
	 * @throws IllegalArgumentException
49
	 *             if first or second is null
50
	 */
51
	public static <T> T[] concat(T[] first, T[] second) {
52 3 1. concat : negated conditional → NO_COVERAGE
2. concat : negated conditional → KILLED
3. concat : negated conditional → KILLED
		if (first == null) {
53
			throw new IllegalArgumentException("first cannot be null");
54
		}
55 3 1. concat : negated conditional → NO_COVERAGE
2. concat : negated conditional → KILLED
3. concat : negated conditional → KILLED
		if (second == null) {
56
			throw new IllegalArgumentException("second cannot be null");
57
		}
58 3 1. concat : Replaced integer addition with subtraction → NO_COVERAGE
2. concat : Replaced integer addition with subtraction → KILLED
3. concat : Replaced integer addition with subtraction → KILLED
		T[] result = Arrays.copyOf(first, first.length + second.length);
59 3 1. concat : removed call to java/lang/System::arraycopy → NO_COVERAGE
2. concat : removed call to java/lang/System::arraycopy → KILLED
3. concat : removed call to java/lang/System::arraycopy → KILLED
		System.arraycopy(second, 0, result, first.length, second.length);
60 3 1. concat : replaced return value with null for fr/sii/ogham/core/util/ArrayUtils::concat → NO_COVERAGE
2. concat : replaced return value with null for fr/sii/ogham/core/util/ArrayUtils::concat → KILLED
3. concat : replaced return value with null for fr/sii/ogham/core/util/ArrayUtils::concat → KILLED
		return result;
61
	}
62
63
	private ArrayUtils() {
64
		super();
65
	}
66
}

Mutations

28

1.1
Location : concat
Killed by : oghamall.it.email.EmailExtractSubjectTest.subjectExtractedFromTextWithDefaultSubjectShouldSendWithSubjectExtractedFromText(oghamall.it.email.EmailExtractSubjectTest)
negated conditional → KILLED

2.2
Location : concat
Killed by : none
negated conditional → NO_COVERAGE

3.3
Location : concat
Killed by : oghamcore.ut.core.util.ArrayUtilsSpec
negated conditional → KILLED

34

1.1
Location : concat
Killed by : none
replaced return value with null for fr/sii/ogham/core/util/ArrayUtils::concat → NO_COVERAGE

2.2
Location : concat
Killed by : oghamall.it.email.EmailExtractSubjectTest.subjectExtractedFromTextWithDefaultSubjectShouldSendWithSubjectExtractedFromText(oghamall.it.email.EmailExtractSubjectTest)
replaced return value with null for fr/sii/ogham/core/util/ArrayUtils::concat → KILLED

3.3
Location : concat
Killed by : oghamcore.ut.core.util.ArrayUtilsSpec
replaced return value with null for fr/sii/ogham/core/util/ArrayUtils::concat → KILLED

52

1.1
Location : concat
Killed by : none
negated conditional → NO_COVERAGE

2.2
Location : concat
Killed by : oghamall.it.email.EmailExtractSubjectTest.subjectExtractedFromTextWithDefaultSubjectShouldSendWithSubjectExtractedFromText(oghamall.it.email.EmailExtractSubjectTest)
negated conditional → KILLED

3.3
Location : concat
Killed by : oghamcore.ut.core.util.ArrayUtilsSpec
negated conditional → KILLED

55

1.1
Location : concat
Killed by : none
negated conditional → NO_COVERAGE

2.2
Location : concat
Killed by : oghamcore.ut.core.util.ArrayUtilsSpec
negated conditional → KILLED

3.3
Location : concat
Killed by : oghamall.it.email.EmailExtractSubjectTest.subjectExtractedFromTextWithDefaultSubjectShouldSendWithSubjectExtractedFromText(oghamall.it.email.EmailExtractSubjectTest)
negated conditional → KILLED

58

1.1
Location : concat
Killed by : none
Replaced integer addition with subtraction → NO_COVERAGE

2.2
Location : concat
Killed by : oghamall.it.email.EmailExtractSubjectTest.subjectExtractedFromTextWithDefaultSubjectShouldSendWithSubjectExtractedFromText(oghamall.it.email.EmailExtractSubjectTest)
Replaced integer addition with subtraction → KILLED

3.3
Location : concat
Killed by : oghamcore.ut.core.util.ArrayUtilsSpec
Replaced integer addition with subtraction → KILLED

59

1.1
Location : concat
Killed by : none
removed call to java/lang/System::arraycopy → NO_COVERAGE

2.2
Location : concat
Killed by : oghamall.it.email.EmailExtractSubjectTest.subjectExtractedFromTextWithDefaultSubjectShouldSendWithSubjectExtractedFromText(oghamall.it.email.EmailExtractSubjectTest)
removed call to java/lang/System::arraycopy → KILLED

3.3
Location : concat
Killed by : oghamcore.ut.core.util.ArrayUtilsSpec
removed call to java/lang/System::arraycopy → KILLED

60

1.1
Location : concat
Killed by : none
replaced return value with null for fr/sii/ogham/core/util/ArrayUtils::concat → NO_COVERAGE

2.2
Location : concat
Killed by : oghamall.it.email.EmailExtractSubjectTest.subjectExtractedFromTextWithDefaultSubjectShouldSendWithSubjectExtractedFromText(oghamall.it.email.EmailExtractSubjectTest)
replaced return value with null for fr/sii/ogham/core/util/ArrayUtils::concat → KILLED

3.3
Location : concat
Killed by : oghamcore.ut.core.util.ArrayUtilsSpec
replaced return value with null for fr/sii/ogham/core/util/ArrayUtils::concat → KILLED

Active mutators

Tests examined


Report generated by PIT OGHAM