CollectionUtil.java

1
package com.yubico.internal.util;
2
3
import java.util.ArrayList;
4
import java.util.Collections;
5
import java.util.HashMap;
6
import java.util.HashSet;
7
import java.util.List;
8
import java.util.Map;
9
import java.util.Set;
10
import java.util.SortedSet;
11
import java.util.TreeSet;
12
13
public class CollectionUtil {
14
15
  /**
16
   * Make an unmodifiable shallow copy of the argument.
17
   *
18
   * @return A shallow copy of <code>m</code> which cannot be modified
19
   */
20
  public static <K, V> Map<K, V> immutableMap(Map<K, V> m) {
21 1 1. immutableMap : replaced return value with Collections.emptyMap for com/yubico/internal/util/CollectionUtil::immutableMap → KILLED
    return Collections.unmodifiableMap(new HashMap<>(m));
22
  }
23
24
  /**
25
   * Make an unmodifiable shallow copy of the argument.
26
   *
27
   * @return A shallow copy of <code>l</code> which cannot be modified
28
   */
29
  public static <T> List<T> immutableList(List<T> l) {
30 1 1. immutableList : replaced return value with Collections.emptyList for com/yubico/internal/util/CollectionUtil::immutableList → KILLED
    return Collections.unmodifiableList(new ArrayList<>(l));
31
  }
32
33
  /**
34
   * Alias of <code>s == null ? Collections.emptyList() : CollectionUtil.immutableList(s)</code>.
35
   */
36
  public static <T> List<T> immutableListOrEmpty(List<T> l) {
37 2 1. immutableListOrEmpty : negated conditional → NO_COVERAGE
2. immutableListOrEmpty : replaced return value with Collections.emptyList for com/yubico/internal/util/CollectionUtil::immutableListOrEmpty → NO_COVERAGE
    return l == null ? Collections.emptyList() : immutableList(l);
38
  }
39
40
  /**
41
   * Make an unmodifiable shallow copy of the argument.
42
   *
43
   * @return A shallow copy of <code>s</code> which cannot be modified
44
   */
45
  public static <T> Set<T> immutableSet(Set<T> s) {
46 1 1. immutableSet : replaced return value with Collections.emptySet for com/yubico/internal/util/CollectionUtil::immutableSet → KILLED
    return Collections.unmodifiableSet(new HashSet<>(s));
47
  }
48
49
  /** Alias of <code>s == null ? Collections.emptySet() : CollectionUtil.immutableSet(s)</code>. */
50
  public static <T> Set<T> immutableSetOrEmpty(Set<T> s) {
51 2 1. immutableSetOrEmpty : replaced return value with Collections.emptySet for com/yubico/internal/util/CollectionUtil::immutableSetOrEmpty → NO_COVERAGE
2. immutableSetOrEmpty : negated conditional → NO_COVERAGE
    return s == null ? Collections.emptySet() : immutableSet(s);
52
  }
53
54
  /**
55
   * Make an unmodifiable shallow copy of the argument.
56
   *
57
   * @return A shallow copy of <code>s</code> which cannot be modified
58
   */
59
  public static <T> SortedSet<T> immutableSortedSet(Set<T> s) {
60 1 1. immutableSortedSet : replaced return value with null for com/yubico/internal/util/CollectionUtil::immutableSortedSet → KILLED
    return Collections.unmodifiableSortedSet(new TreeSet<>(s));
61
  }
62
}

Mutations

21

1.1
Location : immutableMap
Killed by : com.yubico.internal.util.CollectionUtilSpec
replaced return value with Collections.emptyMap for com/yubico/internal/util/CollectionUtil::immutableMap → KILLED

30

1.1
Location : immutableList
Killed by : com.yubico.internal.util.CollectionUtilSpec
replaced return value with Collections.emptyList for com/yubico/internal/util/CollectionUtil::immutableList → KILLED

37

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

2.2
Location : immutableListOrEmpty
Killed by : none
replaced return value with Collections.emptyList for com/yubico/internal/util/CollectionUtil::immutableListOrEmpty → NO_COVERAGE

46

1.1
Location : immutableSet
Killed by : com.yubico.internal.util.CollectionUtilSpec
replaced return value with Collections.emptySet for com/yubico/internal/util/CollectionUtil::immutableSet → KILLED

51

1.1
Location : immutableSetOrEmpty
Killed by : none
replaced return value with Collections.emptySet for com/yubico/internal/util/CollectionUtil::immutableSetOrEmpty → NO_COVERAGE

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

60

1.1
Location : immutableSortedSet
Killed by : com.yubico.internal.util.CollectionUtilSpec
replaced return value with null for com/yubico/internal/util/CollectionUtil::immutableSortedSet → KILLED

Active mutators

Tests examined


Report generated by PIT 1.15.0