de.gematik.prepare.pooling.GroupMatcher Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of cucumber-test-combinations-maven-plugin Show documentation
Show all versions of cucumber-test-combinations-maven-plugin Show documentation
Fill cucumber scenarios examples tables with generated combinations of
specified values.
/*
* Copyright 2023 gematik GmbH
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package de.gematik.prepare.pooling;
import static de.gematik.prepare.pooling.strategies.MatchStrategy.MATCHING;
import de.gematik.combine.model.CombineItem;
import de.gematik.prepare.pooling.strategies.CaseInsensitiveExactStrategy;
import de.gematik.prepare.pooling.strategies.CaseInsensitiveStrategy;
import de.gematik.prepare.pooling.strategies.CaseSensitiveExactStrategy;
import de.gematik.prepare.pooling.strategies.CaseSensitiveStrategy;
import de.gematik.prepare.pooling.strategies.MatchStrategy;
import de.gematik.prepare.pooling.strategies.RegexStrategy;
import de.gematik.prepare.pooling.strategies.WildcardStrategy;
import java.util.Collection;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
import lombok.AllArgsConstructor;
@AllArgsConstructor
public class GroupMatcher {
private List groups;
private GroupMatchStrategyType strategyType;
public String order(CombineItem combineItem) {
return this.order(combineItem.getGroups());
}
public String order(Set groups) {
return getStrategy().match(groups);
}
public List getAllMatchingGroups(List matchingItems) {
return getAllMatchingGroups(
matchingItems.stream()
.map(CombineItem::getGroups)
.flatMap(Collection::stream)
.collect(Collectors.toSet()));
}
public List getAllMatchingGroups(Set groups) {
MatchStrategy strategy = getStrategy();
return groups.stream()
.filter(e -> strategy.match(Set.of(e)).equals(MATCHING))
.collect(Collectors.toList());
}
public List getAllItemsMatching(List allItems) {
return allItems.stream()
.filter(item -> this.order(item).equals(MATCHING))
.collect(Collectors.toList());
}
private MatchStrategy getStrategy() {
switch (strategyType) {
case CASE_INSENSITIVE:
return new CaseInsensitiveStrategy(groups);
case CASE_INSENSITIVE_EXACT:
return new CaseInsensitiveExactStrategy(groups);
case CASE_SENSITIVE:
return new CaseSensitiveStrategy(groups);
case CASE_SENSITIVE_EXACT:
return new CaseSensitiveExactStrategy(groups);
case REGEX:
return new RegexStrategy(groups);
default:
return new WildcardStrategy(groups);
}
}
}