Skip to content

Commit

Permalink
Revert "[no tests yet] add GroupConstraint.union() and implementation…
Browse files Browse the repository at this point in the history
… GroupConstraintImpl.union()"

This reverts commit 139ef24.
  • Loading branch information
alexdunnjpl committed May 1, 2023
1 parent a805f2a commit badc29b
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 61 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,4 @@ public interface GroupConstraint {
* Group.
*/
public Map<String, List<String>> mustNot();

/**
* Return the union of this GroupConstraint and another. Equivalent to taking the union of both FILTER sets, the union of both MUST sets, and the union of both MUSTNOT sets
*/

public GroupConstraint union(GroupConstraint otherConstraint);
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,13 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

import com.google.errorprone.annotations.Immutable;

import gov.nasa.pds.api.registry.GroupConstraint;
import gov.nasa.pds.api.registry.search.SearchRequestFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@Immutable
public class GroupConstraintImpl implements GroupConstraint {

private static final Logger log = LoggerFactory.getLogger(GroupConstraintImpl.class);

final private Map<String, List<String>> filter;
final private Map<String, List<String>> must;
final private Map<String, List<String>> mustNot;
Expand All @@ -43,54 +36,6 @@ public Map<String, List<String>> mustNot() {
return mustNot;
}


/**
* Perform a union on a pair of a single constraint type (filter, must or mustNot)
*/
private Map<String, List<String>> performConstraintUnion(Map<String, List<String>> constraint1, Map<String, List<String>> constraint2) {
Map<String, List<String>> unionConstraint = new HashMap<>(constraint1);
constraint2.forEach(
(key, value) -> {
if (unionConstraint.containsKey(key)) {
unionConstraint.get(key).addAll(value);
List<String> deduplicatedValue = List.copyOf(Set.copyOf(unionConstraint.get(key)));
unionConstraint.put(key, deduplicatedValue);
} else {
unionConstraint.put(key, List.copyOf(value));
}
});

return unionConstraint;
}

private void logMutuallyExclusiveMustConditions(Map<String, List<String>> mustConditions) {
mustConditions.forEach(
(key, value) -> {
if (value.size() > 1) {
log.warn(
"Multiple values for 'must' condition are mutually-exclusive and will always fail: property='"
+ key
+ "', values=['"
+ String.join("', '", value)
+ "']");
}
});
}

@Override
public GroupConstraint union(GroupConstraint otherGroupConstraint) {
Map<String, List<String>> unionFilter =
performConstraintUnion(this.filter, otherGroupConstraint.filter());
Map<String, List<String>> unionMust =
performConstraintUnion(this.must, otherGroupConstraint.must());
Map<String, List<String>> unionMustNot =
performConstraintUnion(this.mustNot, otherGroupConstraint.mustNot());

logMutuallyExclusiveMustConditions(unionMust);

return new GroupConstraintImpl(unionMust, unionFilter, unionMustNot);
}

final private static Map<String, List<String>> EMPTY = new HashMap<String, List<String>>();

public static GroupConstraint empty() {
Expand Down

0 comments on commit badc29b

Please sign in to comment.