Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
209 changes: 106 additions & 103 deletions src/main/java/de/danielbechler/diff/inclusion/InclusionService.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,16 @@ public class InclusionService implements InclusionConfigurer, IsIgnoredResolver
private final Map<String, Inclusion> propertyNameInclusions = new HashMap<String, Inclusion>();
private final ToInclude includeAndReturn = new ToIncludeAndReturnImpl();
private final ToExclude excludeAndReturn = new ToExcludeAndReturnImpl();
// Patched : Inclusion boolean properties
private boolean categoryInclusion = false;
private boolean propertyNameInclusion = false;
private boolean nodePathInclusion = false;
private boolean typeInclusion = false;
// Patched : Exclusion boolean properties
private boolean categoryExclusion = false;
private boolean nodePathExclusion = false;
private boolean propertyNameExclusion = false;
private boolean typeExclusion = false;

public InclusionService(final CategoryResolver categoryResolver, final ObjectDifferBuilder rootConfiguration)
{
Expand All @@ -60,146 +70,123 @@ public boolean isIgnored(final DiffNode node)

private boolean isIncluded(final DiffNode node)
{
if (hasInclusions(INCLUDED))
{
if (node.isRootNode())
{
return true;
}
else if (isIncludedByPath(node))
{
return true;
}
else if (isIncludedByCategory(node))
{
return true;
}
else if (isIncludedByType(node))
{
return true;
}
else if (isIncludedByPropertyName(node))
{
return true;
}
return false;
}
return true;
// Patched : Check if there are inclusions before browsing all included elements
if (hasInclusions()) {
if (node.isRootNode()) {
return true;
} else if (isIncludedByPath(node) || isIncludedByCategory(node)) {
return true;
} else if (isIncludedByType(node) || isIncludedByPropertyName(node)) {
return true;
}
return false;
}
return true;
}

private boolean isExcluded(final DiffNode node)
{
if (hasInclusions(EXCLUDED))
{
if (isExcludedByPath(node))
{
return true;
}
else if (isExcludedByCategory(node))
{
return true;
}
else if (isExcludedByType(node))
{
return true;
}
else if (isExcludedByPropertyName(node))
{
return true;
}
}
return false;
// Patched : Check if there are exclusions before browsing all excluded elements
if (hasExclusions()) {
if (isExcludedByPath(node) || isExcludedByCategory(node)) {
return true;
} else if (isExcludedByType(node) || isExcludedByPropertyName(node)) {
return true;
}
}
return false;
}

private boolean hasInclusions(final Inclusion inclusion)
{
if (nodeInclusions.containsValue(inclusion))
{
return true;
}
if (typeInclusions.containsValue(inclusion))
{
return true;
}
if (categoryInclusions.containsValue(inclusion))
{
return true;
}
if (propertyNameInclusions.containsValue(inclusion))
{
return true;
}
return false;
private boolean hasInclusions() {
// Patched : Now return if inclusions have been configured
return nodePathInclusion || categoryInclusion || typeInclusion || propertyNameInclusion;
}

private boolean hasExclusions() {
// Patched (New method) : Now return if exclusions have been configured
return nodePathExclusion || categoryExclusion || typeExclusion || propertyNameExclusion;
}

private boolean isIncludedByPath(final DiffNode node)
{
return nodeInclusions.getNodeForPath(node.getPath()).isIncluded();
// Patched : First check if nodePath inclusions have been configured
if (nodePathInclusion && nodeInclusions.getNodeForPath(node.getPath()).isIncluded()) {
return true;
}
return false;
}

private boolean isIncludedByCategory(final DiffNode node)
{
return hasCategoryWithInclusion(node, INCLUDED);
// Patched : First check if category inclusions have been configured
if (categoryInclusion && hasCategoryWithInclusion(node, INCLUDED)) {
return true;
}
return false;
}

private boolean isIncludedByType(final DiffNode node)
{
if (typeInclusions.get(node.getValueType()) == INCLUDED)
{
return true;
}
// else if (node.getParentNode() != null && typeInclusions.get(node.getParentNode().getValueType()) == INCLUDED)
// {
// return true;
// }
return false;
// Patched : First check if type inclusions have been configured
if (typeInclusion && typeInclusions.get(node.getValueType()) == INCLUDED) {
return true;
}
return false;
}

private boolean isIncludedByPropertyName(final DiffNode node)
{
if (isIncludedByOwnPropertyName(node))
{
return true;
}
else if (isIncludedByParentPropertyName(node))
{
return true;
}
return false;
// Patched : First check if property name inclusions have been configured
if (propertyNameInclusion) {
if (isIncludedByOwnPropertyName(node)) {
return true;
} else if (isIncludedByParentPropertyName(node)) {
return true;
}
}
return false;
}

private boolean isExcludedByPath(final DiffNode node)
{
final InclusionNode valueNode = nodeInclusions.getNodeForPath(node.getPath());
if (valueNode.isExcluded() && !valueNode.containsValue(INCLUDED))
{
return true;
}
return false;
// Patched : First check if node path exclusions have been configured
if (nodePathExclusion) {
final InclusionNode valueNode = nodeInclusions.getNodeForPath(node.getPath());
if (valueNode.isExcluded() && !valueNode.containsValue(INCLUDED)) {
return true;
}
}
return false;
}

private boolean isExcludedByCategory(final DiffNode node)
{
return hasCategoryWithInclusion(node, EXCLUDED);
// Patched : First check if category exclusions have been configured
if (categoryExclusion && hasCategoryWithInclusion(node, EXCLUDED)) {
return true;
}
return false;
}

private boolean isExcludedByType(final DiffNode node)
{
if (node.getValueType() != null)
{
return typeInclusions.get(node.getValueType()) == EXCLUDED;
}
return false;
// Patched : First check if type exclusions have been configured
if (typeExclusion && node.getValueType() != null) {
return typeInclusions.get(node.getValueType()) == EXCLUDED;
}
return false;
}

private boolean isExcludedByPropertyName(final DiffNode node)
{
final String propertyName = node.getPropertyName();
if (propertyName != null)
{
return propertyNameInclusions.get(propertyName) == EXCLUDED;
}
return false;
// Patched : First check if property name exclusions have been configured
if (propertyNameExclusion) {
final String propertyName = node.getPropertyName();
if (propertyName != null) {
return propertyNameInclusions.get(propertyName) == EXCLUDED;
}
}
return false;
}

private boolean hasCategoryWithInclusion(final DiffNode node, final Inclusion inclusion)
Expand Down Expand Up @@ -261,24 +248,32 @@ public ObjectDifferBuilder and()

public ToExcludeAndReturn category(final String category)
{
// Patched : Indicates that there are category exclusions
categoryExclusion = true;
categoryInclusions.put(category, EXCLUDED);
return this;
}

public ToExcludeAndReturn type(final Class<?> type)
{
// Patched : Indicates that there are type exclusions
typeExclusion = true;
typeInclusions.put(type, EXCLUDED);
return this;
}

public ToExcludeAndReturn node(final NodePath nodePath)
{
// Patched : Indicates that there are nodePath exclusions
nodePathExclusion = true;
nodeInclusions.getNodeForPath(nodePath).setValue(EXCLUDED);
return this;
}

public ToExcludeAndReturn propertyName(final String propertyName)
{
// Patched : Indicates that there are property name exclusions
propertyNameExclusion = true;
propertyNameInclusions.put(propertyName, EXCLUDED);
return this;
}
Expand All @@ -298,24 +293,32 @@ public ObjectDifferBuilder and()

public ToIncludeAndReturn category(final String category)
{
// Patched : Indicates that there are category inclusions
categoryInclusion = true;
categoryInclusions.put(category, INCLUDED);
return this;
}

public ToIncludeAndReturn type(final Class<?> type)
{
// Patched : Indicates that there are type inclusions
typeInclusion = true;
typeInclusions.put(type, INCLUDED);
return this;
}

public ToIncludeAndReturn node(final NodePath nodePath)
{
// Patched : Indicates that there are nodePath inclusions
nodePathInclusion = true;
nodeInclusions.getNodeForPath(nodePath).setValue(INCLUDED);
return this;
}

public ToIncludeAndReturn propertyName(final String propertyName)
{
// Patched : Indicates that there are property name inclusions
propertyNameInclusion = true;
propertyNameInclusions.put(propertyName, INCLUDED);
return this;
}
Expand All @@ -325,4 +328,4 @@ public ToExclude exclude()
return InclusionService.this.exclude();
}
}
}
}
8 changes: 5 additions & 3 deletions src/main/java/de/danielbechler/util/Collections.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,18 +88,20 @@ public static <T> int indexOf(final Iterable<? extends T> haystack, final T need
public static <T> Collection<? extends T> filteredCopyOf(final Collection<? extends T> source,
final Collection<? extends T> filter)
{
// Patched : Replaces collection and arrayList by HashSet to improve the removeAll performance using the
// implementation of contains() of the hashset
final Collection<T> copy;
if (source != null)
{
copy = new LinkedList<T>(source);
copy = new HashSet<T>(source);
}
else
{
copy = new LinkedList<T>();
copy = new HashSet<T>();
}
if (filter != null)
{
copy.removeAll(new ArrayList<T>(filter));
copy.removeAll(new HashSet<T>(filter));
}
return copy;
}
Expand Down