From 97aa5896c4a09221e38dc7511ed14de760b1c5bf Mon Sep 17 00:00:00 2001 From: Deipher Date: Mon, 27 Oct 2014 16:15:45 +0100 Subject: [PATCH] Improved performances --- .../diff/inclusion/InclusionService.java | 161 +++++++++--------- 1 file changed, 82 insertions(+), 79 deletions(-) diff --git a/src/main/java/de/danielbechler/diff/inclusion/InclusionService.java b/src/main/java/de/danielbechler/diff/inclusion/InclusionService.java index 6f38044a..a014f7ce 100644 --- a/src/main/java/de/danielbechler/diff/inclusion/InclusionService.java +++ b/src/main/java/de/danielbechler/diff/inclusion/InclusionService.java @@ -44,6 +44,16 @@ public class InclusionService implements InclusionConfigurer, IsIgnoredResolver private final Map propertyNameInclusions = new HashMap(); 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) { @@ -60,26 +70,13 @@ 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)) - { + // Patched : Check if there are inclusions before browsing all included elements + if (hasInclusions()) { + if (node.isRootNode()) { return true; - } - else if (isIncludedByType(node)) - { + } else if (isIncludedByPath(node) || isIncludedByCategory(node)) { return true; - } - else if (isIncludedByPropertyName(node)) - { + } else if (isIncludedByType(node) || isIncludedByPropertyName(node)) { return true; } return false; @@ -89,104 +86,92 @@ else if (isIncludedByPropertyName(node)) private boolean isExcluded(final DiffNode node) { - if (hasInclusions(EXCLUDED)) - { - if (isExcludedByPath(node)) - { - return true; - } - else if (isExcludedByCategory(node)) - { - return true; - } - else if (isExcludedByType(node)) - { + // Patched : Check if there are exclusions before browsing all excluded elements + if (hasExclusions()) { + if (isExcludedByPath(node) || isExcludedByCategory(node)) { return true; - } - else if (isExcludedByPropertyName(node)) - { + } 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) - { + // Patched : First check if type inclusions have been configured + if (typeInclusion && typeInclusions.get(node.getValueType()) == INCLUDED) { return true; } -// else if (node.getParentNode() != null && typeInclusions.get(node.getParentNode().getValueType()) == INCLUDED) -// { -// return true; -// } return false; } private boolean isIncludedByPropertyName(final DiffNode node) { - if (isIncludedByOwnPropertyName(node)) - { - return true; - } - else if (isIncludedByParentPropertyName(node)) - { - return true; + // 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; + // 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) - { + // Patched : First check if type exclusions have been configured + if (typeExclusion && node.getValueType() != null) { return typeInclusions.get(node.getValueType()) == EXCLUDED; } return false; @@ -194,10 +179,12 @@ private boolean isExcludedByType(final DiffNode node) private boolean isExcludedByPropertyName(final DiffNode node) { - final String propertyName = node.getPropertyName(); - if (propertyName != null) - { - return propertyNameInclusions.get(propertyName) == EXCLUDED; + // 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; } @@ -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; } @@ -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; } @@ -325,4 +328,4 @@ public ToExclude exclude() return InclusionService.this.exclude(); } } -} \ No newline at end of file +}