<commit_before>package dynamake.commands;

import java.util.ArrayList;
import java.util.List;

import dynamake.models.CanvasModel;
import dynamake.models.CompositeLocation;
import dynamake.models.Location;
import dynamake.models.Model;
import dynamake.models.ModelRootLocation;
import dynamake.models.PropogationContext;
import dynamake.models.RestorableModel;
import dynamake.transcription.Collector;
import dynamake.transcription.ExPendingCommandFactory;
import dynamake.transcription.Trigger;

public class PushForwardFromCommand implements ForwardableCommand<Model> {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	private Location locationOfSourceFromTarget;
	private int forwardCount;
	
	public PushForwardFromCommand(Location locationOfSourceFromTarget) {
		this.locationOfSourceFromTarget = locationOfSourceFromTarget;
		this.forwardCount = 1;
	}
	
	private PushForwardFromCommand(Location locationOfSourceFromTarget, int forwardCount) {
		this.locationOfSourceFromTarget = locationOfSourceFromTarget;
		this.forwardCount = forwardCount;
	}

	@Override
	public Object executeOn(PropogationContext propCtx, Model prevalentSystem, Collector<Model> collector, Location location) {
		Model target = (Model)location.getChild(prevalentSystem);
		Model source = (Model)locationOfSourceFromTarget.getChild(target);
		
		pushForward(source, target, collector, new ModelRootLocation());
		
//		ArrayList<CommandState<Model>> toForward = new ArrayList<CommandState<Model>>();
//		
//		@SuppressWarnings("unchecked")
//		List<CommandState<Model>> sourceCreation = (List<CommandState<Model>>)source.getProperty(RestorableModel.PROPERTY_CREATION);
//		
//		if(sourceCreation != null) {
//			toForward.addAll(sourceCreation);
//		}
//		
//		toForward.addAll(source.getLocalChanges());
//		
//		if(toForward.size() > 0) {
//			ArrayList<CommandState<Model>> forwardedCreation = new ArrayList<CommandState<Model>>();
//			for(CommandState<Model> creationPart: toForward) {
//				creationPart = creationPart.mapToReferenceLocation(source, target);
//				for(int i = 0; i < forwardCount; i++)
//					creationPart = creationPart.forForwarding();
//				creationPart.appendPendings(forwardedCreation);
//			}
//			
//			collector.execute(new SimpleExPendingCommandFactory2<Model>(target, forwardedCreation));
//		}

		return null;
	}
	
	private void pushForward(Model source, final Model targetRoot, Collector<Model> collector, final Location offsetFromSourceRoot) {		
		ArrayList<CommandState<Model>> toForward = new ArrayList<CommandState<Model>>();
		
		@SuppressWarnings("unchecked")
		List<CommandState<Model>> sourceCreation = (List<CommandState<Model>>)source.getProperty(RestorableModel.PROPERTY_CREATION);
		
		if(sourceCreation != null) {
			toForward.addAll(sourceCreation);
		}
		
		toForward.addAll(source.getLocalChanges());
		
		if(toForward.size() > 0) {
			Location forwardedOffsetFromTargetRoot = offsetFromSourceRoot;
			for(int i = 0; i < forwardCount; i++)
				forwardedOffsetFromTargetRoot = forwardedOffsetFromTargetRoot.forForwarding();
			
			ArrayList<CommandState<Model>> forwardedCreation = new ArrayList<CommandState<Model>>();
			for(CommandState<Model> creationPart: toForward) {
				creationPart = creationPart.mapToReferenceLocation(source, targetRoot);
				for(int i = 0; i < forwardCount; i++)
					creationPart = creationPart.forForwarding();
				creationPart = creationPart.offset(forwardedOffsetFromTargetRoot);
				creationPart.appendPendings(forwardedCreation);
			}
			
//			collector.execute(new SimpleExPendingCommandFactory<Model>(targetRoot, forwardedCreation));
			ExPendingCommandFactory.Util.sequenceEach(collector, targetRoot, forwardedCreation);
		}
		
		if(source instanceof CanvasModel) {
			final CanvasModel sourceCanvas = (CanvasModel)source;

			for(final Location locationInSource: sourceCanvas.getLocations()) {
				collector.execute(new Trigger<Model>() {<commit_msg>Replaced usages of ExPendingCommandFactory.Util.sequenceEach with usages of ExPendingCommandFactory2.Util.sequence.<commit_after>package dynamake.commands;

import java.util.ArrayList;
import java.util.List;

import dynamake.models.CanvasModel;
import dynamake.models.CompositeLocation;
import dynamake.models.Location;
import dynamake.models.Model;
import dynamake.models.ModelRootLocation;
import dynamake.models.PropogationContext;
import dynamake.models.RestorableModel;
import dynamake.transcription.Collector;
import dynamake.transcription.ExPendingCommandFactory;
import dynamake.transcription.ExPendingCommandFactory2;
import dynamake.transcription.Trigger;

public class PushForwardFromCommand implements ForwardableCommand<Model> {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	private Location locationOfSourceFromTarget;
	private int forwardCount;
	
	public PushForwardFromCommand(Location locationOfSourceFromTarget) {
		this.locationOfSourceFromTarget = locationOfSourceFromTarget;
		this.forwardCount = 1;
	}
	
	private PushForwardFromCommand(Location locationOfSourceFromTarget, int forwardCount) {
		this.locationOfSourceFromTarget = locationOfSourceFromTarget;
		this.forwardCount = forwardCount;
	}

	@Override
	public Object executeOn(PropogationContext propCtx, Model prevalentSystem, Collector<Model> collector, Location location) {
		Model target = (Model)location.getChild(prevalentSystem);
		Model source = (Model)locationOfSourceFromTarget.getChild(target);
		
		pushForward(source, target, collector, new ModelRootLocation());
		
//		ArrayList<CommandState<Model>> toForward = new ArrayList<CommandState<Model>>();
//		
//		@SuppressWarnings("unchecked")
//		List<CommandState<Model>> sourceCreation = (List<CommandState<Model>>)source.getProperty(RestorableModel.PROPERTY_CREATION);
//		
//		if(sourceCreation != null) {
//			toForward.addAll(sourceCreation);
//		}
//		
//		toForward.addAll(source.getLocalChanges());
//		
//		if(toForward.size() > 0) {
//			ArrayList<CommandState<Model>> forwardedCreation = new ArrayList<CommandState<Model>>();
//			for(CommandState<Model> creationPart: toForward) {
//				creationPart = creationPart.mapToReferenceLocation(source, target);
//				for(int i = 0; i < forwardCount; i++)
//					creationPart = creationPart.forForwarding();
//				creationPart.appendPendings(forwardedCreation);
//			}
//			
//			collector.execute(new SimpleExPendingCommandFactory2<Model>(target, forwardedCreation));
//		}

		return null;
	}
	
	private void pushForward(Model source, final Model targetRoot, Collector<Model> collector, final Location offsetFromSourceRoot) {		
		ArrayList<CommandState<Model>> toForward = new ArrayList<CommandState<Model>>();
		
		@SuppressWarnings("unchecked")
		List<CommandState<Model>> sourceCreation = (List<CommandState<Model>>)source.getProperty(RestorableModel.PROPERTY_CREATION);
		
		if(sourceCreation != null) {
			toForward.addAll(sourceCreation);
		}
		
		toForward.addAll(source.getLocalChanges());
		
		if(toForward.size() > 0) {
			Location forwardedOffsetFromTargetRoot = offsetFromSourceRoot;
			for(int i = 0; i < forwardCount; i++)
				forwardedOffsetFromTargetRoot = forwardedOffsetFromTargetRoot.forForwarding();
			
			ArrayList<CommandState<Model>> forwardedCreation = new ArrayList<CommandState<Model>>();
			for(CommandState<Model> creationPart: toForward) {
				creationPart = creationPart.mapToReferenceLocation(source, targetRoot);
				for(int i = 0; i < forwardCount; i++)
					creationPart = creationPart.forForwarding();
				creationPart = creationPart.offset(forwardedOffsetFromTargetRoot);
				creationPart.appendPendings(forwardedCreation);
			}
			
//			collector.execute(new SimpleExPendingCommandFactory<Model>(targetRoot, forwardedCreation));
			ExPendingCommandFactory2.Util.sequence(collector, targetRoot, forwardedCreation);
		}
		
		if(source instanceof CanvasModel) {
			final CanvasModel sourceCanvas = (CanvasModel)source;

			for(final Location locationInSource: sourceCanvas.getLocations()) {
				collector.execute(new Trigger<Model>() {
{'fraction_non_alphanumeric': 0.10774410774410774, 'fraction_numerical': 0.0023693727397431103, 'mean_word_length': 5.872322193658954, 'pattern_counts': {'":': 0, '<': 73, '<?xml version=': 0, '>': 71, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '933764', 'n_tokens_mistral': 2512, 'n_tokens_neox': 2245, 'n_words': 401}