Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Copyright 2014 Daniel Bechler
   *
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
   * http://www.apache.org/licenses/LICENSE-2.0
   *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
 
 package de.danielbechler.diff.differ;
 
Used to find differences between objects that were not handled by one of the other (specialized) Differ.

Author(s):
Daniel Bechler
 
 public final class BeanDiffer implements Differ
 {
 
 	public BeanDiffer(final DifferDispatcher differDispatcher,
 					  final IsIntrospectableResolver introspectableResolver,
 					  final IsReturnableResolver returnableResolver,
 					  final ComparisonStrategyResolver comparisonStrategyResolver,
 					  final TypeInfoResolver typeInfoResolver)
 	{
 		Assert.notNull(differDispatcher"differDispatcher");
 		this. = differDispatcher;
 
 		Assert.notNull(introspectableResolver"introspectableResolver");
 		this. = introspectableResolver;
 
 		Assert.notNull(returnableResolver"returnableResolver");
 		this. = returnableResolver;
 
 		Assert.notNull(comparisonStrategyResolver"comparisonStrategyResolver");
 		this. = comparisonStrategyResolver;
 
 		Assert.notNull(typeInfoResolver"typeInfoResolver");
 		this. = typeInfoResolver;
 	}
 
 	public boolean accepts(final Class<?> type)
 	{
 		return !type.isPrimitive() && !type.isArray();
 	}
 
 	public final DiffNode compare(final DiffNode parentNodefinal Instances instances)
 	{
 		final DiffNode beanNode = new DiffNode(parentNodeinstances.getSourceAccessor(), instances.getType());
 		if (instances.areNull() || instances.areSame())
 		{
 		}
 		else if (instances.hasBeenAdded())
 		{
 			compareUsingAppropriateMethod(beanNodeinstances);
 		}
 		else if (instances.hasBeenRemoved())
 		{
 			compareUsingAppropriateMethod(beanNodeinstances);
 		}
 		else
 		{
 			compareUsingAppropriateMethod(beanNodeinstances);
 		}
 		return beanNode;
 	}
 
 	private void compareUsingAppropriateMethod(final DiffNode beanNodefinal Instances instances)
 	{
 		if (comparisonStrategy != null)
 		{
			comparisonStrategy.compare(beanNodeinstances.getType(), instances.getWorking(), instances.getBase());
		}
		{
			compareUsingIntrospection(beanNodeinstances);
		}
	}
	private void compareUsingIntrospection(final DiffNode beanNodefinal Instances beanInstances)
	{
		final TypeInfo typeInfo = .typeInfoForNode(beanNode);
		beanNode.setValueTypeInfo(typeInfo);
		for (final PropertyAwareAccessor propertyAccessor : typeInfo.getAccessors())
		{
			final DiffNode propertyNode = .dispatch(beanNodebeanInstancespropertyAccessor);
			{
				beanNode.addChild(propertyNode);
			}
		}
	}
New to GrepCode? Check out our FAQ X