PlatformFilters.java

1
package net.bmahe.genetics4j.gpu.spec;
2
3
import java.util.Arrays;
4
import java.util.Collection;
5
import java.util.Set;
6
import java.util.function.Predicate;
7
8
import org.apache.commons.collections4.CollectionUtils;
9
import org.apache.commons.lang3.Validate;
10
11
import net.bmahe.genetics4j.gpu.opencl.model.Platform;
12
import net.bmahe.genetics4j.gpu.opencl.model.PlatformProfile;
13
14
/**
15
 * Utility class providing predicate-based filters for selecting OpenCL platforms in GPU-accelerated evolutionary
16
 * algorithms.
17
 * 
18
 * <p>PlatformFilters offers a fluent API for creating platform selection criteria based on platform characteristics
19
 * such as profile type, supported extensions, and vendor capabilities. These filters are used to automatically select
20
 * appropriate OpenCL platforms before device enumeration and selection.
21
 * 
22
 * <p>Key functionality includes:
23
 * <ul>
24
 * <li><strong>Profile-based filtering</strong>: Select platforms by profile (FULL_PROFILE or EMBEDDED_PROFILE)</li>
25
 * <li><strong>Extension filtering</strong>: Filter platforms based on supported OpenCL extensions</li>
26
 * <li><strong>Logical combinations</strong>: Combine filters using AND and OR operations</li>
27
 * <li><strong>Predicate composition</strong>: Build complex selection criteria from simple predicates</li>
28
 * </ul>
29
 * 
30
 * <p>Common usage patterns:
31
 * 
32
 * <pre>{@code
33
 * // Select platforms with full OpenCL profile
34
 * Predicate<Platform> fullProfileFilter = PlatformFilters.ofProfile(PlatformProfile.FULL_PROFILE);
35
 * 
36
 * // Select platforms supporting double precision arithmetic
37
 * Predicate<Platform> fp64Filter = PlatformFilters.ofExtension("cl_khr_fp64");
38
 * 
39
 * // Select platforms with multiple required extensions
40
 * Set<String> requiredExtensions = Set.of("cl_khr_fp64", "cl_khr_global_int32_base_atomics");
41
 * Predicate<Platform> extensionFilter = PlatformFilters.ofExtensions(requiredExtensions);
42
 * 
43
 * // Combine multiple criteria
44
 * Predicate<Platform> advancedFilter = PlatformFilters
45
 * 		.and(PlatformFilters.ofProfile(PlatformProfile.FULL_PROFILE), PlatformFilters.ofExtension("cl_khr_fp64"));
46
 * 
47
 * // Apply filter to platform selection
48
 * GPUEAExecutionContext context = GPUEAExecutionContext.builder().platformFilters(fullProfileFilter).build();
49
 * }</pre>
50
 * 
51
 * <p>Platform selection workflow:
52
 * <ol>
53
 * <li><strong>Platform enumeration</strong>: Discover all available OpenCL platforms</li>
54
 * <li><strong>Filter application</strong>: Apply platform filters to candidate platforms</li>
55
 * <li><strong>Platform validation</strong>: Validate filtered platforms meet requirements</li>
56
 * <li><strong>Device discovery</strong>: Enumerate devices on selected platforms</li>
57
 * </ol>
58
 * 
59
 * <p>Filter criteria considerations:
60
 * <ul>
61
 * <li><strong>Profile compatibility</strong>: FULL_PROFILE platforms typically offer more features</li>
62
 * <li><strong>Extension requirements</strong>: Filter for extensions required by algorithms</li>
63
 * <li><strong>Vendor optimization</strong>: Consider vendor-specific optimizations and extensions</li>
64
 * <li><strong>Version requirements</strong>: Ensure platforms support required OpenCL versions</li>
65
 * </ul>
66
 * 
67
 * <p>Performance considerations:
68
 * <ul>
69
 * <li><strong>Platform enumeration overhead</strong>: Filters are applied during platform discovery</li>
70
 * <li><strong>Extension validation</strong>: Extension checks may have runtime overhead</li>
71
 * <li><strong>Fallback strategies</strong>: Implement fallback filters for limited platform availability</li>
72
 * <li><strong>Caching</strong>: Platform characteristics are typically static during execution</li>
73
 * </ul>
74
 * 
75
 * @see Platform
76
 * @see PlatformProfile
77
 * @see GPUEAExecutionContext
78
 */
79
public class PlatformFilters {
80
81
	private PlatformFilters() {
82
83
	}
84
85
	/**
86
	 * Creates a predicate that filters platforms by the specified profile type.
87
	 * 
88
	 * @param platformProfile the OpenCL profile type to filter for (FULL_PROFILE or EMBEDDED_PROFILE)
89
	 * @return predicate that returns true for platforms with the specified profile
90
	 * @throws IllegalArgumentException if platformProfile is null
91
	 */
92
	public static Predicate<Platform> ofProfile(final PlatformProfile platformProfile) {
93
		Validate.notNull(platformProfile);
94
95 5 1. lambda$ofProfile$0 : removed call to net/bmahe/genetics4j/gpu/opencl/model/PlatformProfile::equals → NO_COVERAGE
2. lambda$ofProfile$0 : replaced boolean return with false for net/bmahe/genetics4j/gpu/spec/PlatformFilters::lambda$ofProfile$0 → NO_COVERAGE
3. lambda$ofProfile$0 : replaced boolean return with true for net/bmahe/genetics4j/gpu/spec/PlatformFilters::lambda$ofProfile$0 → NO_COVERAGE
4. ofProfile : replaced return value with null for net/bmahe/genetics4j/gpu/spec/PlatformFilters::ofProfile → NO_COVERAGE
5. lambda$ofProfile$0 : removed call to net/bmahe/genetics4j/gpu/opencl/model/Platform::profile → NO_COVERAGE
		return (platform) -> platformProfile.equals(platform.profile());
96
	}
97
98
	/**
99
	 * Creates a predicate that filters platforms supporting the specified OpenCL extension.
100
	 * 
101
	 * @param extension the OpenCL extension name to filter for (e.g., "cl_khr_fp64")
102
	 * @return predicate that returns true for platforms supporting the extension
103
	 * @throws IllegalArgumentException if extension is null or blank
104
	 */
105
	public static Predicate<Platform> ofExtension(final String extension) {
106
		Validate.notBlank(extension);
107
108 5 1. lambda$ofExtension$1 : removed call to java/util/Set::contains → NO_COVERAGE
2. lambda$ofExtension$1 : removed call to net/bmahe/genetics4j/gpu/opencl/model/Platform::extensions → NO_COVERAGE
3. lambda$ofExtension$1 : replaced boolean return with true for net/bmahe/genetics4j/gpu/spec/PlatformFilters::lambda$ofExtension$1 → NO_COVERAGE
4. lambda$ofExtension$1 : replaced boolean return with false for net/bmahe/genetics4j/gpu/spec/PlatformFilters::lambda$ofExtension$1 → NO_COVERAGE
5. ofExtension : replaced return value with null for net/bmahe/genetics4j/gpu/spec/PlatformFilters::ofExtension → NO_COVERAGE
		return (platform) -> platform.extensions().contains(extension);
109
	}
110
111
	/**
112
	 * Creates a predicate that filters platforms supporting all specified OpenCL extensions.
113
	 * 
114
	 * @param extensions set of OpenCL extension names that must all be supported
115
	 * @return predicate that returns true for platforms supporting all specified extensions
116
	 * @throws IllegalArgumentException if extensions is null
117
	 */
118
	public static Predicate<Platform> ofExtensions(final Set<String> extensions) {
119
		Validate.notNull(extensions);
120
121 5 1. lambda$ofExtensions$2 : replaced boolean return with false for net/bmahe/genetics4j/gpu/spec/PlatformFilters::lambda$ofExtensions$2 → NO_COVERAGE
2. lambda$ofExtensions$2 : replaced boolean return with true for net/bmahe/genetics4j/gpu/spec/PlatformFilters::lambda$ofExtensions$2 → NO_COVERAGE
3. ofExtensions : replaced return value with null for net/bmahe/genetics4j/gpu/spec/PlatformFilters::ofExtensions → NO_COVERAGE
4. lambda$ofExtensions$2 : removed call to org/apache/commons/collections4/CollectionUtils::containsAll → NO_COVERAGE
5. lambda$ofExtensions$2 : removed call to net/bmahe/genetics4j/gpu/opencl/model/Platform::extensions → NO_COVERAGE
		return (platform) -> CollectionUtils.containsAll(platform.extensions(), extensions);
122
	}
123
124
	/**
125
	 * Creates a predicate that returns true if any of the provided predicates return true (logical OR).
126
	 * 
127
	 * @param predicates array of platform predicates to combine with OR logic
128
	 * @return predicate that returns true if any input predicate returns true
129
	 * @throws IllegalArgumentException if predicates is null or empty
130
	 */
131
	public static Predicate<Platform> or(@SuppressWarnings("unchecked") final Predicate<Platform>... predicates) {
132
		Validate.notNull(predicates);
133
		Validate.isTrue(predicates.length > 0);
134
135 8 1. lambda$or$4 : removed call to java/util/Arrays::stream → NO_COVERAGE
2. lambda$or$3 : removed call to java/util/function/Predicate::test → NO_COVERAGE
3. lambda$or$4 : replaced boolean return with false for net/bmahe/genetics4j/gpu/spec/PlatformFilters::lambda$or$4 → NO_COVERAGE
4. lambda$or$4 : replaced boolean return with true for net/bmahe/genetics4j/gpu/spec/PlatformFilters::lambda$or$4 → NO_COVERAGE
5. lambda$or$3 : replaced boolean return with true for net/bmahe/genetics4j/gpu/spec/PlatformFilters::lambda$or$3 → NO_COVERAGE
6. or : replaced return value with null for net/bmahe/genetics4j/gpu/spec/PlatformFilters::or → NO_COVERAGE
7. lambda$or$4 : removed call to java/util/stream/Stream::anyMatch → NO_COVERAGE
8. lambda$or$3 : replaced boolean return with false for net/bmahe/genetics4j/gpu/spec/PlatformFilters::lambda$or$3 → NO_COVERAGE
		return platform -> Arrays.stream(predicates).anyMatch(predicate -> predicate.test(platform));
136
	}
137
138
	/**
139
	 * Creates a predicate that returns true if any of the provided predicates return true (logical OR).
140
	 * 
141
	 * @param predicates collection of platform predicates to combine with OR logic
142
	 * @return predicate that returns true if any input predicate returns true
143
	 * @throws IllegalArgumentException if predicates is null or empty
144
	 */
145
	public static Predicate<Platform> or(final Collection<Predicate<Platform>> predicates) {
146
		Validate.notNull(predicates);
147
		Validate.isTrue(predicates.size() > 0);
148
149 8 1. lambda$or$6 : replaced boolean return with true for net/bmahe/genetics4j/gpu/spec/PlatformFilters::lambda$or$6 → NO_COVERAGE
2. lambda$or$6 : replaced boolean return with false for net/bmahe/genetics4j/gpu/spec/PlatformFilters::lambda$or$6 → NO_COVERAGE
3. lambda$or$6 : removed call to java/util/Collection::stream → NO_COVERAGE
4. lambda$or$5 : removed call to java/util/function/Predicate::test → NO_COVERAGE
5. lambda$or$5 : replaced boolean return with true for net/bmahe/genetics4j/gpu/spec/PlatformFilters::lambda$or$5 → NO_COVERAGE
6. or : replaced return value with null for net/bmahe/genetics4j/gpu/spec/PlatformFilters::or → NO_COVERAGE
7. lambda$or$6 : removed call to java/util/stream/Stream::anyMatch → NO_COVERAGE
8. lambda$or$5 : replaced boolean return with false for net/bmahe/genetics4j/gpu/spec/PlatformFilters::lambda$or$5 → NO_COVERAGE
		return platform -> predicates.stream().anyMatch(predicate -> predicate.test(platform));
150
	}
151
152
	/**
153
	 * Creates a predicate that returns true only if all provided predicates return true (logical AND).
154
	 * 
155
	 * @param predicates array of platform predicates to combine with AND logic
156
	 * @return predicate that returns true only if all input predicates return true
157
	 * @throws IllegalArgumentException if predicates is null or empty
158
	 */
159
	public static Predicate<Platform> and(@SuppressWarnings("unchecked") final Predicate<Platform>... predicates) {
160
		Validate.notNull(predicates);
161
		Validate.isTrue(predicates.length > 0);
162
163 8 1. lambda$and$7 : replaced boolean return with true for net/bmahe/genetics4j/gpu/spec/PlatformFilters::lambda$and$7 → NO_COVERAGE
2. lambda$and$7 : replaced boolean return with false for net/bmahe/genetics4j/gpu/spec/PlatformFilters::lambda$and$7 → NO_COVERAGE
3. and : replaced return value with null for net/bmahe/genetics4j/gpu/spec/PlatformFilters::and → NO_COVERAGE
4. lambda$and$8 : removed call to java/util/stream/Stream::allMatch → NO_COVERAGE
5. lambda$and$8 : removed call to java/util/Arrays::stream → NO_COVERAGE
6. lambda$and$7 : removed call to java/util/function/Predicate::test → NO_COVERAGE
7. lambda$and$8 : replaced boolean return with false for net/bmahe/genetics4j/gpu/spec/PlatformFilters::lambda$and$8 → NO_COVERAGE
8. lambda$and$8 : replaced boolean return with true for net/bmahe/genetics4j/gpu/spec/PlatformFilters::lambda$and$8 → NO_COVERAGE
		return platform -> Arrays.stream(predicates).allMatch(predicate -> predicate.test(platform));
164
	}
165
166
	/**
167
	 * Creates a predicate that returns true only if all provided predicates return true (logical AND).
168
	 * 
169
	 * @param predicates collection of platform predicates to combine with AND logic
170
	 * @return predicate that returns true only if all input predicates return true
171
	 * @throws IllegalArgumentException if predicates is null or empty
172
	 */
173
	public static Predicate<Platform> and(final Collection<Predicate<Platform>> predicates) {
174
		Validate.notNull(predicates);
175
		Validate.isTrue(predicates.size() > 0);
176
177 8 1. lambda$and$9 : replaced boolean return with false for net/bmahe/genetics4j/gpu/spec/PlatformFilters::lambda$and$9 → NO_COVERAGE
2. lambda$and$9 : replaced boolean return with true for net/bmahe/genetics4j/gpu/spec/PlatformFilters::lambda$and$9 → NO_COVERAGE
3. lambda$and$10 : removed call to java/util/stream/Stream::allMatch → NO_COVERAGE
4. lambda$and$9 : removed call to java/util/function/Predicate::test → NO_COVERAGE
5. lambda$and$10 : replaced boolean return with true for net/bmahe/genetics4j/gpu/spec/PlatformFilters::lambda$and$10 → NO_COVERAGE
6. lambda$and$10 : removed call to java/util/Collection::stream → NO_COVERAGE
7. and : replaced return value with null for net/bmahe/genetics4j/gpu/spec/PlatformFilters::and → NO_COVERAGE
8. lambda$and$10 : replaced boolean return with false for net/bmahe/genetics4j/gpu/spec/PlatformFilters::lambda$and$10 → NO_COVERAGE
		return platform -> predicates.stream().allMatch(predicate -> predicate.test(platform));
178
	}
179
180
}

Mutations

95

1.1
Location : lambda$ofProfile$0
Killed by : none
removed call to net/bmahe/genetics4j/gpu/opencl/model/PlatformProfile::equals → NO_COVERAGE

2.2
Location : lambda$ofProfile$0
Killed by : none
replaced boolean return with false for net/bmahe/genetics4j/gpu/spec/PlatformFilters::lambda$ofProfile$0 → NO_COVERAGE

3.3
Location : lambda$ofProfile$0
Killed by : none
replaced boolean return with true for net/bmahe/genetics4j/gpu/spec/PlatformFilters::lambda$ofProfile$0 → NO_COVERAGE

4.4
Location : ofProfile
Killed by : none
replaced return value with null for net/bmahe/genetics4j/gpu/spec/PlatformFilters::ofProfile → NO_COVERAGE

5.5
Location : lambda$ofProfile$0
Killed by : none
removed call to net/bmahe/genetics4j/gpu/opencl/model/Platform::profile → NO_COVERAGE

108

1.1
Location : lambda$ofExtension$1
Killed by : none
removed call to java/util/Set::contains → NO_COVERAGE

2.2
Location : lambda$ofExtension$1
Killed by : none
removed call to net/bmahe/genetics4j/gpu/opencl/model/Platform::extensions → NO_COVERAGE

3.3
Location : lambda$ofExtension$1
Killed by : none
replaced boolean return with true for net/bmahe/genetics4j/gpu/spec/PlatformFilters::lambda$ofExtension$1 → NO_COVERAGE

4.4
Location : lambda$ofExtension$1
Killed by : none
replaced boolean return with false for net/bmahe/genetics4j/gpu/spec/PlatformFilters::lambda$ofExtension$1 → NO_COVERAGE

5.5
Location : ofExtension
Killed by : none
replaced return value with null for net/bmahe/genetics4j/gpu/spec/PlatformFilters::ofExtension → NO_COVERAGE

121

1.1
Location : lambda$ofExtensions$2
Killed by : none
replaced boolean return with false for net/bmahe/genetics4j/gpu/spec/PlatformFilters::lambda$ofExtensions$2 → NO_COVERAGE

2.2
Location : lambda$ofExtensions$2
Killed by : none
replaced boolean return with true for net/bmahe/genetics4j/gpu/spec/PlatformFilters::lambda$ofExtensions$2 → NO_COVERAGE

3.3
Location : ofExtensions
Killed by : none
replaced return value with null for net/bmahe/genetics4j/gpu/spec/PlatformFilters::ofExtensions → NO_COVERAGE

4.4
Location : lambda$ofExtensions$2
Killed by : none
removed call to org/apache/commons/collections4/CollectionUtils::containsAll → NO_COVERAGE

5.5
Location : lambda$ofExtensions$2
Killed by : none
removed call to net/bmahe/genetics4j/gpu/opencl/model/Platform::extensions → NO_COVERAGE

135

1.1
Location : lambda$or$4
Killed by : none
removed call to java/util/Arrays::stream → NO_COVERAGE

2.2
Location : lambda$or$3
Killed by : none
removed call to java/util/function/Predicate::test → NO_COVERAGE

3.3
Location : lambda$or$4
Killed by : none
replaced boolean return with false for net/bmahe/genetics4j/gpu/spec/PlatformFilters::lambda$or$4 → NO_COVERAGE

4.4
Location : lambda$or$4
Killed by : none
replaced boolean return with true for net/bmahe/genetics4j/gpu/spec/PlatformFilters::lambda$or$4 → NO_COVERAGE

5.5
Location : lambda$or$3
Killed by : none
replaced boolean return with true for net/bmahe/genetics4j/gpu/spec/PlatformFilters::lambda$or$3 → NO_COVERAGE

6.6
Location : or
Killed by : none
replaced return value with null for net/bmahe/genetics4j/gpu/spec/PlatformFilters::or → NO_COVERAGE

7.7
Location : lambda$or$4
Killed by : none
removed call to java/util/stream/Stream::anyMatch → NO_COVERAGE

8.8
Location : lambda$or$3
Killed by : none
replaced boolean return with false for net/bmahe/genetics4j/gpu/spec/PlatformFilters::lambda$or$3 → NO_COVERAGE

149

1.1
Location : lambda$or$6
Killed by : none
replaced boolean return with true for net/bmahe/genetics4j/gpu/spec/PlatformFilters::lambda$or$6 → NO_COVERAGE

2.2
Location : lambda$or$6
Killed by : none
replaced boolean return with false for net/bmahe/genetics4j/gpu/spec/PlatformFilters::lambda$or$6 → NO_COVERAGE

3.3
Location : lambda$or$6
Killed by : none
removed call to java/util/Collection::stream → NO_COVERAGE

4.4
Location : lambda$or$5
Killed by : none
removed call to java/util/function/Predicate::test → NO_COVERAGE

5.5
Location : lambda$or$5
Killed by : none
replaced boolean return with true for net/bmahe/genetics4j/gpu/spec/PlatformFilters::lambda$or$5 → NO_COVERAGE

6.6
Location : or
Killed by : none
replaced return value with null for net/bmahe/genetics4j/gpu/spec/PlatformFilters::or → NO_COVERAGE

7.7
Location : lambda$or$6
Killed by : none
removed call to java/util/stream/Stream::anyMatch → NO_COVERAGE

8.8
Location : lambda$or$5
Killed by : none
replaced boolean return with false for net/bmahe/genetics4j/gpu/spec/PlatformFilters::lambda$or$5 → NO_COVERAGE

163

1.1
Location : lambda$and$7
Killed by : none
replaced boolean return with true for net/bmahe/genetics4j/gpu/spec/PlatformFilters::lambda$and$7 → NO_COVERAGE

2.2
Location : lambda$and$7
Killed by : none
replaced boolean return with false for net/bmahe/genetics4j/gpu/spec/PlatformFilters::lambda$and$7 → NO_COVERAGE

3.3
Location : and
Killed by : none
replaced return value with null for net/bmahe/genetics4j/gpu/spec/PlatformFilters::and → NO_COVERAGE

4.4
Location : lambda$and$8
Killed by : none
removed call to java/util/stream/Stream::allMatch → NO_COVERAGE

5.5
Location : lambda$and$8
Killed by : none
removed call to java/util/Arrays::stream → NO_COVERAGE

6.6
Location : lambda$and$7
Killed by : none
removed call to java/util/function/Predicate::test → NO_COVERAGE

7.7
Location : lambda$and$8
Killed by : none
replaced boolean return with false for net/bmahe/genetics4j/gpu/spec/PlatformFilters::lambda$and$8 → NO_COVERAGE

8.8
Location : lambda$and$8
Killed by : none
replaced boolean return with true for net/bmahe/genetics4j/gpu/spec/PlatformFilters::lambda$and$8 → NO_COVERAGE

177

1.1
Location : lambda$and$9
Killed by : none
replaced boolean return with false for net/bmahe/genetics4j/gpu/spec/PlatformFilters::lambda$and$9 → NO_COVERAGE

2.2
Location : lambda$and$9
Killed by : none
replaced boolean return with true for net/bmahe/genetics4j/gpu/spec/PlatformFilters::lambda$and$9 → NO_COVERAGE

3.3
Location : lambda$and$10
Killed by : none
removed call to java/util/stream/Stream::allMatch → NO_COVERAGE

4.4
Location : lambda$and$9
Killed by : none
removed call to java/util/function/Predicate::test → NO_COVERAGE

5.5
Location : lambda$and$10
Killed by : none
replaced boolean return with true for net/bmahe/genetics4j/gpu/spec/PlatformFilters::lambda$and$10 → NO_COVERAGE

6.6
Location : lambda$and$10
Killed by : none
removed call to java/util/Collection::stream → NO_COVERAGE

7.7
Location : and
Killed by : none
replaced return value with null for net/bmahe/genetics4j/gpu/spec/PlatformFilters::and → NO_COVERAGE

8.8
Location : lambda$and$10
Killed by : none
replaced boolean return with false for net/bmahe/genetics4j/gpu/spec/PlatformFilters::lambda$and$10 → NO_COVERAGE

Active mutators

Tests examined


Report generated by PIT 1.20.3