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.node;
This visitor generates the same output as the PrintingVisitor, but instead of printing it to System.out, it will store the messages in a Map, identified by the property path of the visited node. The java.util.Map can later be accessed via getMessages() to provide a way to post-process the collected information.

Author(s):
Daniel Bechler (SQiShER)
Mayank Kumar (mayankk)
public class ToMapPrintingVisitor extends PrintingVisitor
	private final Map<NodePathStringmessages = new LinkedHashMap<NodePathString>();
	public ToMapPrintingVisitor(final Object workingfinal Object base)
	{
		super(workingbase);
	}
	protected void print(final String text)
	{
	}
	protected String differenceToString(final DiffNode nodefinal Object basefinal Object modified)
	{
		final String text = super.differenceToString(nodebasemodified);
		.put(node.getPath(), text);
		return text;
	}
	public void clear()
	{
	}
	{
		return ;
	}
	public String getMessage(final NodePath path)
	{
		return .get(path);
	}
	public boolean hasMessages()
	{
		return !.isEmpty();
	}
	{
		final StringBuilder sb = new StringBuilder();
		for (final String message : .values())
		{
			sb.append(message).append('\n');
		}
		return sb.toString();
	}
	public String toString()
	{
	}
New to GrepCode? Check out our FAQ X