1 | package org.cardanofoundation.explorer.api.util; | |
2 | ||
3 | import java.text.DecimalFormat; | |
4 | import java.text.SimpleDateFormat; | |
5 | import java.time.Instant; | |
6 | import java.time.LocalDateTime; | |
7 | import java.time.ZoneOffset; | |
8 | import java.time.format.DateTimeFormatter; | |
9 | import java.util.Collection; | |
10 | import java.util.Date; | |
11 | import java.util.Map; | |
12 | ||
13 | public class DataUtil { | |
14 | ||
15 | public static boolean isNullOrEmpty(CharSequence cs) { | |
16 | int strLen; | |
17 |
2
1. isNullOrEmpty : negated conditional → KILLED 2. isNullOrEmpty : negated conditional → KILLED |
if (cs == null || (strLen = cs.length()) == 0) { |
18 |
1
1. isNullOrEmpty : replaced boolean return with false for org/cardanofoundation/explorer/api/util/DataUtil::isNullOrEmpty → KILLED |
return true; |
19 | } | |
20 |
2
1. isNullOrEmpty : changed conditional boundary → SURVIVED 2. isNullOrEmpty : negated conditional → KILLED |
for (int i = 0; i < strLen; i++) { |
21 |
1
1. isNullOrEmpty : negated conditional → KILLED |
if (!Character.isWhitespace(cs.charAt(i))) { |
22 |
1
1. isNullOrEmpty : replaced boolean return with true for org/cardanofoundation/explorer/api/util/DataUtil::isNullOrEmpty → KILLED |
return false; |
23 | } | |
24 | } | |
25 |
1
1. isNullOrEmpty : replaced boolean return with false for org/cardanofoundation/explorer/api/util/DataUtil::isNullOrEmpty → NO_COVERAGE |
return true; |
26 | } | |
27 | ||
28 | public static boolean isNullOrEmpty(final Collection<?> collection) { | |
29 |
3
1. isNullOrEmpty : replaced boolean return with true for org/cardanofoundation/explorer/api/util/DataUtil::isNullOrEmpty → NO_COVERAGE 2. isNullOrEmpty : negated conditional → NO_COVERAGE 3. isNullOrEmpty : negated conditional → NO_COVERAGE |
return collection == null || collection.isEmpty(); |
30 | } | |
31 | ||
32 | public static boolean isNullOrEmpty(final Object obj) { | |
33 |
3
1. isNullOrEmpty : negated conditional → SURVIVED 2. isNullOrEmpty : replaced boolean return with true for org/cardanofoundation/explorer/api/util/DataUtil::isNullOrEmpty → SURVIVED 3. isNullOrEmpty : negated conditional → KILLED |
return obj == null || obj.toString().isEmpty(); |
34 | } | |
35 | ||
36 | public static boolean isNullOrEmpty(final Object[] collection) { | |
37 |
3
1. isNullOrEmpty : negated conditional → NO_COVERAGE 2. isNullOrEmpty : replaced boolean return with true for org/cardanofoundation/explorer/api/util/DataUtil::isNullOrEmpty → NO_COVERAGE 3. isNullOrEmpty : negated conditional → NO_COVERAGE |
return collection == null || collection.length == 0; |
38 | } | |
39 | ||
40 | public static boolean isNullOrEmpty(final Map<?, ?> map) { | |
41 |
3
1. isNullOrEmpty : negated conditional → NO_COVERAGE 2. isNullOrEmpty : replaced boolean return with true for org/cardanofoundation/explorer/api/util/DataUtil::isNullOrEmpty → NO_COVERAGE 3. isNullOrEmpty : negated conditional → NO_COVERAGE |
return map == null || map.isEmpty(); |
42 | } | |
43 | ||
44 | public static String instantToString(Instant value, String pattern) { | |
45 |
1
1. instantToString : negated conditional → NO_COVERAGE |
if (pattern != null) { |
46 | DateTimeFormatter dtf = DateTimeFormatter.ofPattern(pattern); | |
47 |
1
1. instantToString : replaced return value with "" for org/cardanofoundation/explorer/api/util/DataUtil::instantToString → NO_COVERAGE |
return dtf.format(LocalDateTime.ofInstant(value, ZoneOffset.UTC)); |
48 | } | |
49 | return ""; | |
50 | } | |
51 | ||
52 | public static String localDateTimeToString(LocalDateTime value, String pattern) { | |
53 |
1
1. localDateTimeToString : negated conditional → SURVIVED |
if (pattern != null) { |
54 | DateTimeFormatter dtf = DateTimeFormatter.ofPattern(pattern); | |
55 |
1
1. localDateTimeToString : replaced return value with "" for org/cardanofoundation/explorer/api/util/DataUtil::localDateTimeToString → SURVIVED |
return dtf.format(value); |
56 | } | |
57 | return ""; | |
58 | } | |
59 | ||
60 | public static String dateToString(Date value, String pattern) { | |
61 |
1
1. dateToString : negated conditional → NO_COVERAGE |
if (pattern != null) { |
62 | SimpleDateFormat dtf = new SimpleDateFormat(pattern); | |
63 |
1
1. dateToString : replaced return value with "" for org/cardanofoundation/explorer/api/util/DataUtil::dateToString → NO_COVERAGE |
return dtf.format(value); |
64 | } | |
65 | return ""; | |
66 | } | |
67 | ||
68 | public static String objectToString(Object value) { | |
69 |
2
1. objectToString : negated conditional → NO_COVERAGE 2. objectToString : replaced return value with "" for org/cardanofoundation/explorer/api/util/DataUtil::objectToString → NO_COVERAGE |
return (value == null) ? "" : value.toString(); |
70 | } | |
71 | ||
72 | public static String doubleToString(Double value) { | |
73 |
1
1. doubleToString : negated conditional → NO_COVERAGE |
if (value == null) { |
74 | return ""; | |
75 | } | |
76 | DecimalFormat doubleFormat = new DecimalFormat("#.##"); | |
77 | String result = doubleFormat.format(value); | |
78 |
1
1. doubleToString : negated conditional → NO_COVERAGE |
if (result.endsWith(".0")) { |
79 | result = result.split("\\.")[0]; | |
80 | } | |
81 |
1
1. doubleToString : replaced return value with "" for org/cardanofoundation/explorer/api/util/DataUtil::doubleToString → NO_COVERAGE |
return result; |
82 | } | |
83 | ||
84 | public static String makeLikeQuery(String s) { | |
85 |
1
1. makeLikeQuery : negated conditional → KILLED |
if (DataUtil.isNullOrEmpty(s)) { |
86 |
1
1. makeLikeQuery : replaced return value with "" for org/cardanofoundation/explorer/api/util/DataUtil::makeLikeQuery → SURVIVED |
return null; |
87 | } | |
88 |
1
1. makeLikeQuery : replaced return value with "" for org/cardanofoundation/explorer/api/util/DataUtil::makeLikeQuery → SURVIVED |
return "%" + s + "%"; |
89 | } | |
90 | } | |
Mutations | ||
17 |
1.1 2.2 |
|
18 |
1.1 |
|
20 |
1.1 2.2 |
|
21 |
1.1 |
|
22 |
1.1 |
|
25 |
1.1 |
|
29 |
1.1 2.2 3.3 |
|
33 |
1.1 2.2 3.3 |
|
37 |
1.1 2.2 3.3 |
|
41 |
1.1 2.2 3.3 |
|
45 |
1.1 |
|
47 |
1.1 |
|
53 |
1.1 |
|
55 |
1.1 |
|
61 |
1.1 |
|
63 |
1.1 |
|
69 |
1.1 2.2 |
|
73 |
1.1 |
|
78 |
1.1 |
|
81 |
1.1 |
|
85 |
1.1 |
|
86 |
1.1 |
|
88 |
1.1 |