Skip to content

Commit

Permalink
FORGE-2316: Added excluded facets to Stack
Browse files Browse the repository at this point in the history
  • Loading branch information
gastaldi committed Jan 14, 2016
1 parent 793493a commit 3ade4a8
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,11 @@ public interface Stack
*/
default boolean supports(Class<? extends ProjectFacet> facet)
{
Set<Class<? extends ProjectFacet>> excludedFacets = getExcludedFacets();
return getIncludedFacets()
.stream()
.anyMatch((includedFacet) -> facet.isAssignableFrom(includedFacet));
.anyMatch((includedFacet) -> facet.isAssignableFrom(includedFacet)
&& !excludedFacets.contains(includedFacet));
}

/**
Expand All @@ -54,7 +56,7 @@ default boolean supports(Class<? extends ProjectFacet> facet)
*/
default boolean matches(Class<? extends ProjectFacet> facet)
{
return getIncludedFacets().contains(facet);
return getIncludedFacets().contains(facet) && !getExcludedFacets().contains(facet);
}

/**
Expand All @@ -64,8 +66,9 @@ default boolean matches(Class<? extends ProjectFacet> facet)
*/
default <T extends ProjectFacet> Set<T> filter(Class<T> type, Iterable<T> facets)
{
Set<Class<? extends ProjectFacet>> excludedFacets = getExcludedFacets();
Set<Class<? extends ProjectFacet>> sameTypeFacets = getIncludedFacets().stream()
.filter((f) -> type.isAssignableFrom(f))
.filter((f) -> type.isAssignableFrom(f) && !excludedFacets.contains(f))
.collect(Collectors.toSet());
Set<T> result = new LinkedHashSet<>();
for (T facet : facets)
Expand All @@ -88,4 +91,11 @@ default <T extends ProjectFacet> Set<T> filter(Class<T> type, Iterable<T> facets
* @return the facets included in this stack. Never <code>null</code>.
*/
Set<Class<? extends ProjectFacet>> getIncludedFacets();

/**
* This method is supposed to be used by the auxiliary methods.
*
* @return the facets excluded in this stack. Never <code>null</code>.
*/
Set<Class<? extends ProjectFacet>> getExcludedFacets();
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

package org.jboss.forge.addon.projects.stacks;

import java.util.LinkedHashSet;
import java.util.HashSet;
import java.util.Set;

import org.jboss.forge.addon.projects.ProjectFacet;
Expand All @@ -22,7 +22,8 @@
public class StackBuilder implements Stack
{
private final String name;
private Set<Class<? extends ProjectFacet>> facets = new LinkedHashSet<>();
private Set<Class<? extends ProjectFacet>> includedFacets = new HashSet<>();
private Set<Class<? extends ProjectFacet>> excludedFacets = new HashSet<>();

private StackBuilder(String name)
{
Expand All @@ -43,34 +44,40 @@ public String getName()

public StackBuilder includes(Class<? extends ProjectFacet> facet)
{
facets.add(facet);
includedFacets.add(facet);
return this;
}

public StackBuilder includes(Stack stack)
{
facets.addAll(stack.getIncludedFacets());
includedFacets.addAll(stack.getIncludedFacets());
excludedFacets.addAll(stack.getExcludedFacets());
return this;
}

public StackBuilder excludes(Class<? extends ProjectFacet> facet)
{
facets.remove(facet);
excludedFacets.add(facet);
return this;
}

@Override
public Set<Class<? extends ProjectFacet>> getIncludedFacets()
{
return facets;
return includedFacets;
}

@Override
public Set<Class<? extends ProjectFacet>> getExcludedFacets()
{
return excludedFacets;
}

@Override
public int hashCode()
{
final int prime = 31;
int result = 1;
result = prime * result + ((facets == null) ? 0 : facets.hashCode());
result = prime * result + ((name == null) ? 0 : name.hashCode());
return result;
}
Expand All @@ -85,13 +92,6 @@ public boolean equals(Object obj)
if (getClass() != obj.getClass())
return false;
StackBuilder other = (StackBuilder) obj;
if (facets == null)
{
if (other.facets != null)
return false;
}
else if (!facets.equals(other.facets))
return false;
if (name == null)
{
if (other.name != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,10 @@ public Set<Class<? extends ProjectFacet>> getIncludedFacets()
{
return Collections.emptySet();
}

@Override
public Set<Class<? extends ProjectFacet>> getExcludedFacets()
{
return Collections.emptySet();
}
}

0 comments on commit 3ade4a8

Please sign in to comment.