|
|||||||||||||||||||
30 day Evaluation Version distributed via the Maven Jar Repository. Clover is not free. You have 30 days to evaluate it. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover | |||||||||||||||||||
Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
ArrayUtil.java | 50% | 50% | 33.3% | 47.1% |
|
1 |
package com.diasparsoftware.java.lang;
|
|
2 |
|
|
3 |
import java.util.*;
|
|
4 |
|
|
5 |
public class ArrayUtil { |
|
6 |
|
|
7 |
/**
|
|
8 |
* Convert a two-dimensional array into a Map.
|
|
9 |
*
|
|
10 |
* @param entries
|
|
11 |
* @return
|
|
12 |
*/
|
|
13 | 33 |
public static Map asMap(Object[][] entries) { |
14 | 33 |
Map map = new HashMap();
|
15 |
|
|
16 | 33 |
for (int i = 0; i < entries.length; i++) { |
17 | 22 |
Object[] eachEntry = entries[i]; |
18 | 22 |
map.put(eachEntry[0], eachEntry[1]); |
19 |
} |
|
20 |
|
|
21 | 33 |
return map;
|
22 |
} |
|
23 |
|
|
24 |
/**
|
|
25 |
* Convert a one-dimensional array into a <code>Set</code>.
|
|
26 |
* WARNING! Duplicate elements will be removed from the set.
|
|
27 |
*
|
|
28 |
* @param entries
|
|
29 |
* @return
|
|
30 |
*/
|
|
31 | 0 |
public static Set asSet(Object[] entries) { |
32 | 0 |
return new HashSet(Arrays.asList(entries)); |
33 |
} |
|
34 |
|
|
35 |
/**
|
|
36 |
* Convert a two-dimensional array into a <code>List</code> of
|
|
37 |
* <code>List</code>s, similar to a two-dimensional matrix.
|
|
38 |
*/
|
|
39 | 0 |
public static List asListOfLists(Object[][] entries) { |
40 | 0 |
List rows = new ArrayList();
|
41 | 0 |
for (int i = 0; i < entries.length; i++) { |
42 | 0 |
rows.add(Arrays.asList(entries[i])); |
43 |
} |
|
44 | 0 |
return rows;
|
45 |
} |
|
46 |
} |
|
47 |
|
|