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;
Careful: This class has not yet been tested very thoroughly and serves more as an example for your own implementations.

Author(s):
Daniel Bechler
@SuppressWarnings("UnusedDeclaration")
public final class ObjectMerger
	private final ObjectDiffer objectDiffer;
	public ObjectMerger()
	{
		this. = ObjectDifferBuilder.buildDefault();
	}
	public ObjectMerger(final ObjectDiffer objectDiffer)
	{
		this. = objectDiffer;
	}
	@SuppressWarnings({"unchecked"})
	public <T> T merge(final T modifiedfinal T basefinal T head)
	{
		final DiffNode.Visitor visitor = new MergingDifferenceVisitor<T>(headmodified);
		final DiffNode difference = .compare(modifiedbase);
		difference.visit(visitor);
		return head;
	}
	private static final class MergingDifferenceVisitor<T> implements DiffNode.Visitor
	{
		private final T head;
		private final T modified;
		public MergingDifferenceVisitor(final T headfinal T modified)
		{
			this. = head;
			this. = modified;
		}
		public void node(final DiffNode nodefinal Visit visit)
		{
			if (node.getState() == ..)
			{
			}
			else if (node.getState() == ..)
			{
			}
			else if (node.getState() == ..)
			{
				if (node.hasChildren())
				{
					node.visitChildren(this);
					visit.dontGoDeeper();
				}
				else
				{
				}
			}
		}
	}
New to GrepCode? Check out our FAQ X