From 0394a10ec34b2ff14217116700371e7f69da2c06 Mon Sep 17 00:00:00 2001 From: Deipher Date: Mon, 27 Oct 2014 11:39:35 +0100 Subject: [PATCH 1/4] Update InclusionService.java Exclusions and inclusions are only checked if they have been set. --- .../diff/inclusion/InclusionService.java | 573 +++++++++--------- 1 file changed, 273 insertions(+), 300 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..0a1a5d53 100644 --- a/src/main/java/de/danielbechler/diff/inclusion/InclusionService.java +++ b/src/main/java/de/danielbechler/diff/inclusion/InclusionService.java @@ -16,6 +16,13 @@ package de.danielbechler.diff.inclusion; +import static de.danielbechler.diff.inclusion.Inclusion.EXCLUDED; +import static de.danielbechler.diff.inclusion.Inclusion.INCLUDED; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + import de.danielbechler.diff.ObjectDifferBuilder; import de.danielbechler.diff.category.CategoryResolver; import de.danielbechler.diff.node.DiffNode; @@ -24,305 +31,271 @@ import de.danielbechler.diff.selector.ElementSelector; import de.danielbechler.util.Assert; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import static de.danielbechler.diff.inclusion.Inclusion.EXCLUDED; -import static de.danielbechler.diff.inclusion.Inclusion.INCLUDED; - /** - * + * Service to manage inclusions and exclusions + * + * @author Frédéric Toublanc */ -public class InclusionService implements InclusionConfigurer, IsIgnoredResolver -{ - private final CategoryResolver categoryResolver; - private final ObjectDifferBuilder rootConfiguration; - private final InclusionNode nodeInclusions = new InclusionNode(); - private final Map, Inclusion> typeInclusions = new HashMap, Inclusion>(); - private final Map categoryInclusions = new HashMap(); - private final Map propertyNameInclusions = new HashMap(); - private final ToInclude includeAndReturn = new ToIncludeAndReturnImpl(); - private final ToExclude excludeAndReturn = new ToExcludeAndReturnImpl(); - - public InclusionService(final CategoryResolver categoryResolver, final ObjectDifferBuilder rootConfiguration) - { - Assert.notNull(categoryResolver, "categoryResolver"); - Assert.notNull(rootConfiguration, "rootConfiguration"); - this.categoryResolver = categoryResolver; - this.rootConfiguration = rootConfiguration; - } - - public boolean isIgnored(final DiffNode node) - { - return node.isExcluded() || !isIncluded(node) || isExcluded(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; - } - - 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; - } - - 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 isIncludedByPath(final DiffNode node) - { - return nodeInclusions.getNodeForPath(node.getPath()).isIncluded(); - } - - private boolean isIncludedByCategory(final DiffNode node) - { - return hasCategoryWithInclusion(node, INCLUDED); - } - - 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; - } - - private boolean isIncludedByPropertyName(final DiffNode node) - { - 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; - } - - private boolean isExcludedByCategory(final DiffNode node) - { - return hasCategoryWithInclusion(node, EXCLUDED); - } - - private boolean isExcludedByType(final DiffNode node) - { - if (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; - } - - private boolean hasCategoryWithInclusion(final DiffNode node, final Inclusion inclusion) - { - for (final String category : categoryResolver.resolveCategories(node)) - { - if (categoryInclusions.get(category) == inclusion) - { - return true; - } - } - return false; - } - - private boolean isIncludedByOwnPropertyName(final DiffNode node) - { - final String propertyName = node.getPropertyName(); - if (propertyName != null) - { - return propertyNameInclusions.get(propertyName) == INCLUDED; - } - return false; - } - - private boolean isIncludedByParentPropertyName(final DiffNode node) - { - final List pathElementSelectors = node.getPath().getElementSelectors(); - for (final ElementSelector elementSelector : pathElementSelectors) - { - if (elementSelector instanceof BeanPropertyElementSelector) - { - final BeanPropertyElementSelector beanPropertyElement = (BeanPropertyElementSelector) elementSelector; - final String propertyName = beanPropertyElement.getPropertyName(); - if (propertyName != null && propertyNameInclusions.get(propertyName) == INCLUDED) - { - return true; - } - } - } - return false; - } - - public ToInclude include() - { - return includeAndReturn; - } - - public ToExclude exclude() - { - return excludeAndReturn; - } - - private class ToExcludeAndReturnImpl implements ToExcludeAndReturn - { - public ObjectDifferBuilder and() - { - return rootConfiguration; - } - - public ToExcludeAndReturn category(final String category) - { - categoryInclusions.put(category, EXCLUDED); - return this; - } - - public ToExcludeAndReturn type(final Class type) - { - typeInclusions.put(type, EXCLUDED); - return this; - } - - public ToExcludeAndReturn node(final NodePath nodePath) - { - nodeInclusions.getNodeForPath(nodePath).setValue(EXCLUDED); - return this; - } - - public ToExcludeAndReturn propertyName(final String propertyName) - { - propertyNameInclusions.put(propertyName, EXCLUDED); - return this; - } - - public ToInclude include() - { - return InclusionService.this.include(); - } - } - - private class ToIncludeAndReturnImpl implements ToIncludeAndReturn - { - public ObjectDifferBuilder and() - { - return rootConfiguration; - } - - public ToIncludeAndReturn category(final String category) - { - categoryInclusions.put(category, INCLUDED); - return this; - } - - public ToIncludeAndReturn type(final Class type) - { - typeInclusions.put(type, INCLUDED); - return this; - } - - public ToIncludeAndReturn node(final NodePath nodePath) - { - nodeInclusions.getNodeForPath(nodePath).setValue(INCLUDED); - return this; - } - - public ToIncludeAndReturn propertyName(final String propertyName) - { - propertyNameInclusions.put(propertyName, INCLUDED); - return this; - } - - public ToExclude exclude() - { - return InclusionService.this.exclude(); - } - } -} \ No newline at end of file +public class InclusionService implements InclusionConfigurer, IsIgnoredResolver { + private final CategoryResolver categoryResolver; + private final ObjectDifferBuilder rootConfiguration; + private final InclusionNode nodeInclusions = new InclusionNode(); + private final Map, Inclusion> typeInclusions = new HashMap, Inclusion>(); + private final Map categoryInclusions = new HashMap(); + 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; + + /** + * Initialize the service with the category resolve and root configuration + * + * @param categoryResolver - The category resolver + * @param rootConfiguration - The root oject differ builder + */ + public InclusionService(final CategoryResolver categoryResolver, final ObjectDifferBuilder rootConfiguration) { + Assert.notNull(categoryResolver, "categoryResolver"); + Assert.notNull(rootConfiguration, "rootConfiguration"); + this.categoryResolver = categoryResolver; + this.rootConfiguration = rootConfiguration; + } + + public boolean isIgnored(final DiffNode node) { + return node.isExcluded() || !isIncluded(node) || isExcluded(node); + } + + private boolean isIncluded(final DiffNode node) { + // 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) { + // 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() { + // 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) { + // 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) { + // Patched : First check if category inclusions have been configured + if (categoryInclusion && hasCategoryWithInclusion(node, INCLUDED)) { + return true; + } + return false; + } + + private boolean isIncludedByType(final DiffNode node) { + // 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) { + // 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) { + // 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) { + // Patched : First check if category exclusions have been configured + if (categoryExclusion && hasCategoryWithInclusion(node, EXCLUDED)) { + return true; + } + return false; + } + + private boolean isExcludedByType(final DiffNode node) { + // 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) { + // 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) { + for (final String category : categoryResolver.resolveCategories(node)) { + if (categoryInclusions.get(category) == inclusion) { + return true; + } + } + return false; + } + + private boolean isIncludedByOwnPropertyName(final DiffNode node) { + final String propertyName = node.getPropertyName(); + if (propertyName != null) { + return propertyNameInclusions.get(propertyName) == INCLUDED; + } + return false; + } + + private boolean isIncludedByParentPropertyName(final DiffNode node) { + final List pathElementSelectors = node.getPath().getElementSelectors(); + for (final ElementSelector elementSelector : pathElementSelectors) { + if (elementSelector instanceof BeanPropertyElementSelector) { + final BeanPropertyElementSelector beanPropertyElement = (BeanPropertyElementSelector) elementSelector; + final String propertyName = beanPropertyElement.getPropertyName(); + if (propertyName != null && propertyNameInclusions.get(propertyName) == INCLUDED) { + return true; + } + } + } + return false; + } + + public ToInclude include() { + return includeAndReturn; + } + + public ToExclude exclude() { + return excludeAndReturn; + } + + private class ToExcludeAndReturnImpl implements ToExcludeAndReturn { + public ObjectDifferBuilder and() { + return rootConfiguration; + } + + 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; + } + + public ToInclude include() { + return InclusionService.this.include(); + } + } + + private class ToIncludeAndReturnImpl implements ToIncludeAndReturn { + public ObjectDifferBuilder and() { + return rootConfiguration; + } + + 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; + } + + public ToExclude exclude() { + return InclusionService.this.exclude(); + } + } +} From 2aecb7456b817c4e4e1c56c340c481d892fd3f77 Mon Sep 17 00:00:00 2001 From: Deipher Date: Mon, 27 Oct 2014 14:58:21 +0100 Subject: [PATCH 2/4] Update InclusionService.java --- .../diff/inclusion/InclusionService.java | 348 ++++++++++-------- 1 file changed, 189 insertions(+), 159 deletions(-) diff --git a/src/main/java/de/danielbechler/diff/inclusion/InclusionService.java b/src/main/java/de/danielbechler/diff/inclusion/InclusionService.java index 0a1a5d53..5c4545c9 100644 --- a/src/main/java/de/danielbechler/diff/inclusion/InclusionService.java +++ b/src/main/java/de/danielbechler/diff/inclusion/InclusionService.java @@ -16,13 +16,6 @@ package de.danielbechler.diff.inclusion; -import static de.danielbechler.diff.inclusion.Inclusion.EXCLUDED; -import static de.danielbechler.diff.inclusion.Inclusion.INCLUDED; - -import java.util.HashMap; -import java.util.List; -import java.util.Map; - import de.danielbechler.diff.ObjectDifferBuilder; import de.danielbechler.diff.category.CategoryResolver; import de.danielbechler.diff.node.DiffNode; @@ -31,21 +24,27 @@ import de.danielbechler.diff.selector.ElementSelector; import de.danielbechler.util.Assert; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import static de.danielbechler.diff.inclusion.Inclusion.EXCLUDED; +import static de.danielbechler.diff.inclusion.Inclusion.INCLUDED; + /** - * Service to manage inclusions and exclusions - * - * @author Frédéric Toublanc + * */ -public class InclusionService implements InclusionConfigurer, IsIgnoredResolver { - private final CategoryResolver categoryResolver; - private final ObjectDifferBuilder rootConfiguration; - private final InclusionNode nodeInclusions = new InclusionNode(); - private final Map, Inclusion> typeInclusions = new HashMap, Inclusion>(); - private final Map categoryInclusions = new HashMap(); - private final Map propertyNameInclusions = new HashMap(); - private final ToInclude includeAndReturn = new ToIncludeAndReturnImpl(); - private final ToExclude excludeAndReturn = new ToExcludeAndReturnImpl(); - // Patched : Inclusion boolean properties +public class InclusionService implements InclusionConfigurer, IsIgnoredResolver +{ + private final CategoryResolver categoryResolver; + private final ObjectDifferBuilder rootConfiguration; + private final InclusionNode nodeInclusions = new InclusionNode(); + private final Map, Inclusion> typeInclusions = new HashMap, Inclusion>(); + private final Map categoryInclusions = new HashMap(); + 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; @@ -56,24 +55,21 @@ public class InclusionService implements InclusionConfigurer, IsIgnoredResolver private boolean propertyNameExclusion = false; private boolean typeExclusion = false; - /** - * Initialize the service with the category resolve and root configuration - * - * @param categoryResolver - The category resolver - * @param rootConfiguration - The root oject differ builder - */ - public InclusionService(final CategoryResolver categoryResolver, final ObjectDifferBuilder rootConfiguration) { - Assert.notNull(categoryResolver, "categoryResolver"); - Assert.notNull(rootConfiguration, "rootConfiguration"); - this.categoryResolver = categoryResolver; - this.rootConfiguration = rootConfiguration; - } - - public boolean isIgnored(final DiffNode node) { - return node.isExcluded() || !isIncluded(node) || isExcluded(node); - } - - private boolean isIncluded(final DiffNode node) { + public InclusionService(final CategoryResolver categoryResolver, final ObjectDifferBuilder rootConfiguration) + { + Assert.notNull(categoryResolver, "categoryResolver"); + Assert.notNull(rootConfiguration, "rootConfiguration"); + this.categoryResolver = categoryResolver; + this.rootConfiguration = rootConfiguration; + } + + public boolean isIgnored(final DiffNode node) + { + return node.isExcluded() || !isIncluded(node) || isExcluded(node); + } + + private boolean isIncluded(final DiffNode node) + { // Patched : Check if there are inclusions before browsing all included elements if (hasInclusions()) { if (node.isRootNode()) { @@ -86,9 +82,10 @@ private boolean isIncluded(final DiffNode node) { return false; } return true; - } + } - private boolean isExcluded(final DiffNode node) { + private boolean isExcluded(final DiffNode node) + { // Patched : Check if there are exclusions before browsing all excluded elements if (hasExclusions()) { if (isExcludedByPath(node) || isExcludedByCategory(node)) { @@ -98,7 +95,7 @@ private boolean isExcluded(final DiffNode node) { } } return false; - } + } private boolean hasInclusions() { // Patched : Now return if inclusions have been configured @@ -110,31 +107,35 @@ private boolean hasExclusions() { return nodePathExclusion || categoryExclusion || typeExclusion || propertyNameExclusion; } - private boolean isIncludedByPath(final DiffNode node) { + private boolean isIncludedByPath(final DiffNode node) + { // 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) { + private boolean isIncludedByCategory(final DiffNode node) + { // Patched : First check if category inclusions have been configured if (categoryInclusion && hasCategoryWithInclusion(node, INCLUDED)) { return true; } return false; - } + } - private boolean isIncludedByType(final DiffNode node) { + private boolean isIncludedByType(final DiffNode node) + { // 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) { + private boolean isIncludedByPropertyName(final DiffNode node) + { // Patched : First check if property name inclusions have been configured if (propertyNameInclusion) { if (isIncludedByOwnPropertyName(node)) { @@ -144,9 +145,10 @@ private boolean isIncludedByPropertyName(final DiffNode node) { } } return false; - } + } - private boolean isExcludedByPath(final DiffNode node) { + private boolean isExcludedByPath(final DiffNode node) + { // Patched : First check if node path exclusions have been configured if (nodePathExclusion) { final InclusionNode valueNode = nodeInclusions.getNodeForPath(node.getPath()); @@ -155,25 +157,28 @@ private boolean isExcludedByPath(final DiffNode node) { } } return false; - } + } - private boolean isExcludedByCategory(final DiffNode node) { + private boolean isExcludedByCategory(final DiffNode node) + { // Patched : First check if category exclusions have been configured if (categoryExclusion && hasCategoryWithInclusion(node, EXCLUDED)) { return true; } return false; - } + } - private boolean isExcludedByType(final DiffNode node) { + private boolean isExcludedByType(final DiffNode node) + { // Patched : First check if type exclusions have been configured if (typeExclusion && node.getValueType() != null) { return typeInclusions.get(node.getValueType()) == EXCLUDED; } - return false; - } + return false;; + } - private boolean isExcludedByPropertyName(final DiffNode node) { + private boolean isExcludedByPropertyName(final DiffNode node) + { // Patched : First check if property name exclusions have been configured if (propertyNameExclusion) { final String propertyName = node.getPropertyName(); @@ -182,120 +187,145 @@ private boolean isExcludedByPropertyName(final DiffNode node) { } } return false; - } - - private boolean hasCategoryWithInclusion(final DiffNode node, final Inclusion inclusion) { - for (final String category : categoryResolver.resolveCategories(node)) { - if (categoryInclusions.get(category) == inclusion) { - return true; - } - } - return false; - } - - private boolean isIncludedByOwnPropertyName(final DiffNode node) { - final String propertyName = node.getPropertyName(); - if (propertyName != null) { - return propertyNameInclusions.get(propertyName) == INCLUDED; - } - return false; - } - - private boolean isIncludedByParentPropertyName(final DiffNode node) { - final List pathElementSelectors = node.getPath().getElementSelectors(); - for (final ElementSelector elementSelector : pathElementSelectors) { - if (elementSelector instanceof BeanPropertyElementSelector) { - final BeanPropertyElementSelector beanPropertyElement = (BeanPropertyElementSelector) elementSelector; - final String propertyName = beanPropertyElement.getPropertyName(); - if (propertyName != null && propertyNameInclusions.get(propertyName) == INCLUDED) { - return true; - } - } - } - return false; - } - - public ToInclude include() { - return includeAndReturn; - } - - public ToExclude exclude() { - return excludeAndReturn; - } - - private class ToExcludeAndReturnImpl implements ToExcludeAndReturn { - public ObjectDifferBuilder and() { - return rootConfiguration; - } - - public ToExcludeAndReturn category(final String category) { - // Patched : Indicates that there are category exclusions + } + + private boolean hasCategoryWithInclusion(final DiffNode node, final Inclusion inclusion) + { + for (final String category : categoryResolver.resolveCategories(node)) + { + if (categoryInclusions.get(category) == inclusion) + { + return true; + } + } + return false; + } + + private boolean isIncludedByOwnPropertyName(final DiffNode node) + { + final String propertyName = node.getPropertyName(); + if (propertyName != null) + { + return propertyNameInclusions.get(propertyName) == INCLUDED; + } + return false; + } + + private boolean isIncludedByParentPropertyName(final DiffNode node) + { + final List pathElementSelectors = node.getPath().getElementSelectors(); + for (final ElementSelector elementSelector : pathElementSelectors) + { + if (elementSelector instanceof BeanPropertyElementSelector) + { + final BeanPropertyElementSelector beanPropertyElement = (BeanPropertyElementSelector) elementSelector; + final String propertyName = beanPropertyElement.getPropertyName(); + if (propertyName != null && propertyNameInclusions.get(propertyName) == INCLUDED) + { + return true; + } + } + } + return false; + } + + public ToInclude include() + { + return includeAndReturn; + } + + public ToExclude exclude() + { + return excludeAndReturn; + } + + private class ToExcludeAndReturnImpl implements ToExcludeAndReturn + { + public ObjectDifferBuilder and() + { + return rootConfiguration; + } + + public ToExcludeAndReturn category(final String category) + { + // Patched : Indicates that there are category exclusions categoryExclusion = true; - categoryInclusions.put(category, EXCLUDED); - return this; - } + categoryInclusions.put(category, EXCLUDED); + return this; + } - public ToExcludeAndReturn type(final Class type) { - // Patched : Indicates that there are type exclusions + public ToExcludeAndReturn type(final Class type) + { + // Patched : Indicates that there are type exclusions typeExclusion = true; - typeInclusions.put(type, EXCLUDED); - return this; - } + typeInclusions.put(type, EXCLUDED); + return this; + } - public ToExcludeAndReturn node(final NodePath nodePath) { - // Patched : Indicates that there are nodePath exclusions + public ToExcludeAndReturn node(final NodePath nodePath) + { + // Patched : Indicates that there are nodePath exclusions nodePathExclusion = true; - nodeInclusions.getNodeForPath(nodePath).setValue(EXCLUDED); - return this; - } + nodeInclusions.getNodeForPath(nodePath).setValue(EXCLUDED); + return this; + } - public ToExcludeAndReturn propertyName(final String propertyName) { - // Patched : Indicates that there are property name exclusions + public ToExcludeAndReturn propertyName(final String propertyName) + { + // Patched : Indicates that there are property name exclusions propertyNameExclusion = true; - propertyNameInclusions.put(propertyName, EXCLUDED); - return this; - } - - public ToInclude include() { - return InclusionService.this.include(); - } - } - - private class ToIncludeAndReturnImpl implements ToIncludeAndReturn { - public ObjectDifferBuilder and() { - return rootConfiguration; - } - - public ToIncludeAndReturn category(final String category) { - // Patched : Indicates that there are category inclusions + propertyNameInclusions.put(propertyName, EXCLUDED); + return this; + } + + public ToInclude include() + { + return InclusionService.this.include(); + } + } + + private class ToIncludeAndReturnImpl implements ToIncludeAndReturn + { + public ObjectDifferBuilder and() + { + return rootConfiguration; + } + + public ToIncludeAndReturn category(final String category) + { + // Patched : Indicates that there are category inclusions categoryInclusion = true; - categoryInclusions.put(category, INCLUDED); - return this; - } + categoryInclusions.put(category, INCLUDED); + return this; + } - public ToIncludeAndReturn type(final Class type) { - // Patched : Indicates that there are type inclusions + public ToIncludeAndReturn type(final Class type) + { + // Patched : Indicates that there are type inclusions typeInclusion = true; - typeInclusions.put(type, INCLUDED); - return this; - } + typeInclusions.put(type, INCLUDED); + return this; + } - public ToIncludeAndReturn node(final NodePath nodePath) { - // Patched : Indicates that there are nodePath inclusions + public ToIncludeAndReturn node(final NodePath nodePath) + { + // Patched : Indicates that there are nodePath inclusions nodePathInclusion = true; - nodeInclusions.getNodeForPath(nodePath).setValue(INCLUDED); - return this; - } + nodeInclusions.getNodeForPath(nodePath).setValue(INCLUDED); + return this; + } - public ToIncludeAndReturn propertyName(final String propertyName) { - // Patched : Indicates that there are property name inclusions + public ToIncludeAndReturn propertyName(final String propertyName) + { + // Patched : Indicates that there are property name inclusions propertyNameInclusion = true; - propertyNameInclusions.put(propertyName, INCLUDED); - return this; - } - - public ToExclude exclude() { - return InclusionService.this.exclude(); - } - } + propertyNameInclusions.put(propertyName, INCLUDED); + return this; + } + + public ToExclude exclude() + { + return InclusionService.this.exclude(); + } + } } From 224a1f9eaeb0f8062a75ec36f76c50484e0b32c3 Mon Sep 17 00:00:00 2001 From: Deipher Date: Mon, 27 Oct 2014 15:05:28 +0100 Subject: [PATCH 3/4] Update InclusionService.java --- .../diff/inclusion/InclusionService.java | 194 +++++++++--------- 1 file changed, 97 insertions(+), 97 deletions(-) diff --git a/src/main/java/de/danielbechler/diff/inclusion/InclusionService.java b/src/main/java/de/danielbechler/diff/inclusion/InclusionService.java index 5c4545c9..db8a0996 100644 --- a/src/main/java/de/danielbechler/diff/inclusion/InclusionService.java +++ b/src/main/java/de/danielbechler/diff/inclusion/InclusionService.java @@ -45,15 +45,15 @@ public class InclusionService implements InclusionConfigurer, IsIgnoredResolver 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; + 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) { @@ -70,123 +70,123 @@ public boolean isIgnored(final DiffNode node) private boolean isIncluded(final DiffNode node) { - // 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; + // 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) { - // 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; + // 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() { - // 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 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) { - // Patched : First check if nodePath inclusions have been configured - if (nodePathInclusion && nodeInclusions.getNodeForPath(node.getPath()).isIncluded()) { - return true; - } - return false; + // 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) { - // Patched : First check if category inclusions have been configured - if (categoryInclusion && hasCategoryWithInclusion(node, INCLUDED)) { - return true; - } - return false; + // Patched : First check if category inclusions have been configured + if (categoryInclusion && hasCategoryWithInclusion(node, INCLUDED)) { + return true; + } + return false; } private boolean isIncludedByType(final DiffNode node) { - // Patched : First check if type inclusions have been configured - if (typeInclusion && typeInclusions.get(node.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) { - // 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; + // 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) { - // 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; + // 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) { - // Patched : First check if category exclusions have been configured - if (categoryExclusion && hasCategoryWithInclusion(node, EXCLUDED)) { - return true; - } - return false; + // Patched : First check if category exclusions have been configured + if (categoryExclusion && hasCategoryWithInclusion(node, EXCLUDED)) { + return true; + } + return false; } private boolean isExcludedByType(final DiffNode node) { - // Patched : First check if type exclusions have been configured - if (typeExclusion && 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) { - // 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; + // 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) @@ -249,7 +249,7 @@ public ObjectDifferBuilder and() public ToExcludeAndReturn category(final String category) { // Patched : Indicates that there are category exclusions - categoryExclusion = true; + categoryExclusion = true; categoryInclusions.put(category, EXCLUDED); return this; } @@ -257,7 +257,7 @@ public ToExcludeAndReturn category(final String category) public ToExcludeAndReturn type(final Class type) { // Patched : Indicates that there are type exclusions - typeExclusion = true; + typeExclusion = true; typeInclusions.put(type, EXCLUDED); return this; } @@ -265,7 +265,7 @@ public ToExcludeAndReturn type(final Class type) public ToExcludeAndReturn node(final NodePath nodePath) { // Patched : Indicates that there are nodePath exclusions - nodePathExclusion = true; + nodePathExclusion = true; nodeInclusions.getNodeForPath(nodePath).setValue(EXCLUDED); return this; } @@ -273,7 +273,7 @@ public ToExcludeAndReturn node(final NodePath nodePath) public ToExcludeAndReturn propertyName(final String propertyName) { // Patched : Indicates that there are property name exclusions - propertyNameExclusion = true; + propertyNameExclusion = true; propertyNameInclusions.put(propertyName, EXCLUDED); return this; } @@ -294,7 +294,7 @@ public ObjectDifferBuilder and() public ToIncludeAndReturn category(final String category) { // Patched : Indicates that there are category inclusions - categoryInclusion = true; + categoryInclusion = true; categoryInclusions.put(category, INCLUDED); return this; } @@ -302,7 +302,7 @@ public ToIncludeAndReturn category(final String category) public ToIncludeAndReturn type(final Class type) { // Patched : Indicates that there are type inclusions - typeInclusion = true; + typeInclusion = true; typeInclusions.put(type, INCLUDED); return this; } @@ -310,7 +310,7 @@ public ToIncludeAndReturn type(final Class type) public ToIncludeAndReturn node(final NodePath nodePath) { // Patched : Indicates that there are nodePath inclusions - nodePathInclusion = true; + nodePathInclusion = true; nodeInclusions.getNodeForPath(nodePath).setValue(INCLUDED); return this; } @@ -318,7 +318,7 @@ public ToIncludeAndReturn node(final NodePath nodePath) public ToIncludeAndReturn propertyName(final String propertyName) { // Patched : Indicates that there are property name inclusions - propertyNameInclusion = true; + propertyNameInclusion = true; propertyNameInclusions.put(propertyName, INCLUDED); return this; } From 143f8f1e6ab9600cf2c3115ef55eb929103dbec0 Mon Sep 17 00:00:00 2001 From: Deipher Date: Mon, 27 Oct 2014 15:12:13 +0100 Subject: [PATCH 4/4] Update Collections.java Just a suggestion : But using HashSet.removeAll has better performances than ArrayList.removeAll() --- src/main/java/de/danielbechler/util/Collections.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/main/java/de/danielbechler/util/Collections.java b/src/main/java/de/danielbechler/util/Collections.java index b34666fe..b1141962 100644 --- a/src/main/java/de/danielbechler/util/Collections.java +++ b/src/main/java/de/danielbechler/util/Collections.java @@ -88,18 +88,20 @@ public static int indexOf(final Iterable haystack, final T need public static Collection filteredCopyOf(final Collection source, final Collection filter) { + // Patched : Replaces collection and arrayList by HashSet to improve the removeAll performance using the + // implementation of contains() of the hashset final Collection copy; if (source != null) { - copy = new LinkedList(source); + copy = new HashSet(source); } else { - copy = new LinkedList(); + copy = new HashSet(); } if (filter != null) { - copy.removeAll(new ArrayList(filter)); + copy.removeAll(new HashSet(filter)); } return copy; }