Clover icon

Coverage Report

  1. Project Clover database Thu Dec 4 2025 16:11:35 GMT
  2. Package jalview.util

File ArrayUtils.java

 

Coverage histogram

../../img/srcFileCovDistChart9.png
13% of files have more coverage

Code metrics

14
21
4
1
94
47
11
0.52
5.25
4
2.75

Classes

Class Line # Actions
ArrayUtils 27 21 11
0.8461538684.6%
 

Contributing tests

This file is covered by 31 tests. .

Source view

1    /*
2    * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3    * Copyright (C) $$Year-Rel$$ The Jalview Authors
4    *
5    * This file is part of Jalview.
6    *
7    * Jalview is free software: you can redistribute it and/or
8    * modify it under the terms of the GNU General Public License
9    * as published by the Free Software Foundation, either version 3
10    * of the License, or (at your option) any later version.
11    *
12    * Jalview is distributed in the hope that it will be useful, but
13    * WITHOUT ANY WARRANTY; without even the implied warranty
14    * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15    * PURPOSE. See the GNU General Public License for more details.
16    *
17    * You should have received a copy of the GNU General Public License
18    * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19    * The Jalview Authors are detailed in the 'AUTHORS' file.
20    */
21    package jalview.util;
22   
23    import java.util.Arrays;
24   
25    import java.util.Objects;
26   
 
27    public class ArrayUtils
28    {
29    /**
30    * Reverse the given array 'in situ'
31    *
32    * @param arr
33    */
 
34  4 toggle public static void reverseIntArray(int[] arr)
35    {
36  4 if (arr != null)
37    {
38    /*
39    * swap [k] with [end-k] up to the half way point in the array
40    * if length is odd, the middle entry is left untouched by the excitement
41    */
42  3 int last = arr.length - 1;
43  7 for (int k = 0; k < arr.length / 2; k++)
44    {
45  4 int temp = arr[k];
46  4 arr[k] = arr[last - k];
47  4 arr[last - k] = temp;
48    }
49    }
50    }
51   
 
52  4 toggle public static <T> T[] concatArrays(T[]... arrays)
53    {
54  4 if (arrays == null)
55  0 return null;
56  4 if (arrays.length == 1)
57  0 return arrays[0];
58   
59  4 T[] result = arrays[0];
60  9 for (int i = 1; i < arrays.length; i++)
61    {
62  5 result = concatTwoArrays(result, arrays[i]);
63    }
64  4 return result;
65    }
66   
 
67  5 toggle private static <T> T[] concatTwoArrays(T[] array1, T[] array2)
68    {
69  5 T[] result = Arrays.copyOf(array1, array1.length + array2.length);
70  5 System.arraycopy(array2, 0, result, array1.length, array2.length);
71  5 return result;
72    }
73   
74   
75    /**
76    * Return the index of the first occurrence of the item in the array or -1 if
77    * the array doesn't contain the item.
78    *
79    * @param arr
80    * array to be searched
81    * @param item
82    * item to search for
83    * @return index of the first occurrence of the item or -1 if not found
84    */
 
85  66 toggle public static int indexOf(Object[] arr, Object item)
86    {
87  260 for (int i = 0; i < arr.length; i++)
88    {
89  260 if (Objects.equals(arr[i], item))
90  66 return i;
91    }
92  0 return -1;
93    }
94    }