Tutorial

		  
	module SimpleClient {
		requires com.betterdiff.api;
		requires com.betterdiff.core;
		requires com.betterdiff.core.utils;
		requires com.betterdiff.core.modules;
	}
	
	/*******************************************************/

	package com.betterdiff.example.simpleClient;

	import java.util.ArrayList;
	import java.util.List;
	import java.util.logging.Level;
	import java.util.stream.Collectors;

	import com.betterdiff.api.Callback;
	import com.betterdiff.api.alignment.AlignmentProcessor;
	import com.betterdiff.api.evidence.Evidence;
	import com.betterdiff.api.evidence.Witness;
	import com.betterdiff.api.identification.IdentificationProcessor;
	import com.betterdiff.api.pairing.PairingProcessor;
	import com.betterdiff.api.preparation.PreparationProcessor;
	import com.betterdiff.api.protocol.instruction.Mutation;
	import com.betterdiff.core.CoreCallback;
	import com.betterdiff.core.alignment.CoreAlignmentProcessor;
	import com.betterdiff.core.evidence.CoreEvidence;
	import com.betterdiff.core.evidence.CoreWitness;
	import com.betterdiff.core.identification.CoreIdentificationProcessor;
	import com.betterdiff.core.modules.lyrics.pairing.LCSPairing;
	import com.betterdiff.core.modules.lyrics.preparation.LinesPreparation;
	import com.betterdiff.core.protocol.CoreMutationType;
	import com.betterdiff.core.utils.output.XMLOutputBuilder;
	import com.betterdiff.core.utils.output.builder.AlignmentOutputBuilder;
	import com.betterdiff.core.utils.output.builder.MutationOutputBuilder;
	import com.betterdiff.core.utils.printer.simpleConsolePrinter.OutputFilter;
	import com.betterdiff.core.utils.printer.simpleConsolePrinter.PrinterMode;
	import com.betterdiff.core.utils.printer.simpleConsolePrinter.SimpleConsolePrinter;
	import com.betterdiff.core.utils.printer.simpleConsolePrinter.SimpleConsolePrinterParameters;

	public class SimpleClient {

		private class EmptyCallback extends CoreCallback {
			public EmptyCallback() {
				super();
			}
			
			@Override
			protected void log(Level level, String message) {
				// nothing - you can add some logging here
			}
		}
		
		public static void main(String[] args) {
			// Input strings as if they were read from external source (file / stream / user input...).
			String file1 = "AAA\nBBB\nFFF";
			String file2 = "BBB\nFFF";
			String file3 = "AAA\nCBB\nFFF";
			
			// Create empty callback. Callback is useful for debugging or logging.
			SimpleClient simpleClient = new SimpleClient();
			Callback callback = simpleClient.new EmptyCallback();
			
			// Collecting evidence
			List<Witness> witnesses = new ArrayList<>();
			witnesses.add(new CoreWitness(file1));
			witnesses.add(new CoreWitness(file2));
			witnesses.add(new CoreWitness(file3));
			Evidence evidence = new CoreEvidence(witnesses);
			
			// Preparation phase
			PreparationProcessor preparation = new LinesPreparation(evidence, callback);
			preparation.process();
			
			// Pairing phase
			PairingProcessor pairing = new LCSPairing(evidence, preparation.getChunks(), callback, 50);
			pairing.process();
			
			// Alignment phase
			AlignmentProcessor alignment = new CoreAlignmentProcessor(pairing.getPairedChunks(), callback);
			alignment.process();
			
			// Identification phase
			IdentificationProcessor identification = new CoreIdentificationProcessor(evidence, alignment.getAlignedChunks(), callback);
			identification.process();
			
			// Register all elements to the output object
			XMLOutputBuilder betterDiffOutput = new XMLOutputBuilder(callback);
			AlignmentOutputBuilder alignmentOutputBuilder = new AlignmentOutputBuilder(callback);
			alignmentOutputBuilder.registerAlignedChunks(evidence, alignment.getAlignedChunks());
			betterDiffOutput.registerAlignment(alignmentOutputBuilder.constructAlignmentOutput());
			// Filter out equalities as they are not important in this example
			List<Mutation> mutationsToRegister = identification.getMutations().stream().filter(e ->
				e.getMutationType() != CoreMutationType.EQUALITY
			).collect(Collectors.toList());
			MutationOutputBuilder mutationOutputBuilder = new MutationOutputBuilder(callback);
			mutationOutputBuilder.registerMutations(mutationsToRegister, alignment.getAlignedChunks());
			betterDiffOutput.registerMutations(mutationOutputBuilder.constructMutationOutput());
			
			// Create a printer and print out the result
			SimpleConsolePrinterParameters parameters = new SimpleConsolePrinterParameters(
					PrinterMode.SIDE_BY_SIDE,
					SimpleConsolePrinter.DEFAULT_OUTPUT_DIMENSIONS,
					false,
					OutputFilter.MAIN_ALIGNMENT);
			SimpleConsolePrinter spc = new SimpleConsolePrinter(parameters, callback);
			spc.process(betterDiffOutput);
		}

	}
	
	/*******************************************************/
	
	Output:
	
	1|AAA    [2+] |               | 1|AAA    [2+]
	2|BBB    [3o] | 1|BBB    [3o] | 2|CBB [1o,2o]
	3|FFF         | 2|FFF         | 3|FFF