Skip to content

Commit

Permalink
Filter with an OR opperation
Browse files Browse the repository at this point in the history
  • Loading branch information
alucas-nickel authored and mbouchenoire committed May 17, 2021
1 parent 77d0e2b commit 2e1649f
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 14 deletions.
8 changes: 5 additions & 3 deletions src/main/java/org/lowfer/domain/common/ComponentFilters.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,12 @@ public static Builder builder() {

@Override
public boolean test(SoftwareArchitecture architecture, SoftwareComponent component) {
if (!nameFilter.isSet() && !typeFilter.isSet() && !maintainerFilter.isSet() && !internalFilter.isSet()) return true;

return nameFilter.test(architecture, component)
&& typeFilter.test(architecture, component)
&& maintainerFilter.test(architecture, component)
&& internalFilter.test(architecture, component);
|| typeFilter.test(architecture, component)
|| maintainerFilter.test(architecture, component)
|| internalFilter.test(architecture, component);
}

public static class Builder {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,12 @@ public static ComponentMaintainerFilter ofText(String text) {
}

@Override
public boolean test(SoftwareArchitecture architecture, SoftwareComponent component) {
if (maintainerNames.isEmpty())
return true;
public boolean isSet() {
return !maintainerNames.isEmpty();
}

@Override
public boolean test(SoftwareArchitecture architecture, SoftwareComponent component) {
return maintainerNames.stream()
.anyMatch(maintainerName -> component.getMaintainers().stream()
.anyMatch(maintainer -> maintainer.getName().equals(maintainerName)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,12 @@ public static ComponentNameFilter ofText(String text) {
}

@Override
public boolean test(SoftwareArchitecture architecture, SoftwareComponent component) {
if (componentNames.isEmpty())
return true;
public boolean isSet() {
return !componentNames.isEmpty();
}

@Override
public boolean test(SoftwareArchitecture architecture, SoftwareComponent component) {
return componentNames.contains(component.getName());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,12 @@ public static ComponentTypeFilter ofText(String text) {
}

@Override
public boolean test(SoftwareArchitecture architecture, SoftwareComponent component) {
if (componentTypes.isEmpty())
return true;
public boolean isSet() {
return !componentTypes.isEmpty();
}

@Override
public boolean test(SoftwareArchitecture architecture, SoftwareComponent component) {
return componentTypes.contains(component.getType());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,14 @@ public InternalComponentFilter(boolean apply) {
this.apply = apply;
}

@Override
public boolean isSet() {
return apply;
}

@Override
public boolean test(SoftwareArchitecture architecture, SoftwareComponent component) {
return !component.isExternal() || !apply;
return !component.isExternal() && apply;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@

public interface SoftwareComponentFilter {

default boolean isSet() {
return false;
}

boolean test(SoftwareArchitecture architecture, SoftwareComponent component);

// TODO ?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ void testHideExternalComponent() {
final SoftwareArchitecture architecture =
new SoftwareArchitecture("architecture", Set.of(internal, external));

assertTrue(new InternalComponentFilter(false).test(architecture, external));
assertFalse(new InternalComponentFilter(false).test(architecture, external));
assertFalse(new InternalComponentFilter(true).test(architecture, external));
}
}

0 comments on commit 2e1649f

Please sign in to comment.