<commit_before>package nodePackage;

import java.util.HashMap;

import javax.script.ScriptEngine;
import javax.script.ScriptException;


import factValuePackage.*;
import ruleParser.Tokens;


public class ComparisonLine extends Node{
	
	private String operator;
	
	public ComparisonLine(String childText, Tokens tokens)
	{
		super(childText, tokens);
		
	}
	
	@Override
	public void initialisation(String childText, Tokens tokens) {

		/*
		 * this line pattern is as (^U)([ML]+)(O)([MLNoDaDeHaUrlId]*$)
		 */
		StringBuilder sb = new StringBuilder();
		tokens.tokensList.subList(1, tokens.tokensList.size()).stream().forEachOrdered((s)->sb.append(s+" "));
		this.nodeName = childText;
		
		int operatorIndex = tokens.tokensStringList.indexOf("O");
		sb.setLength(0);
		tokens.tokensList.subList(1, operatorIndex).stream().forEachOrdered((s)-> sb.append(s+" "));
		this.variableName = sb.toString().trim();	
		/*
		 * In javascript engine '=' operator means assigning a value, hence if the operator is '=' then it needs to be replaced with '=='. 
		 */
		this.operator = tokens.tokensList.get(operatorIndex).matches("=")?"==":tokens.tokensList.get(operatorIndex);
		
		
		int tokensStringListSize = tokens.tokensStringList.size();
		String lastToken = tokens.tokensList.get(tokensStringListSize-1);
		String lastTokenString = tokens.tokensStringList.get(tokensStringListSize-1);
		this.setValue(lastTokenString, lastToken);
		
		
	}

	
	
	public String getRuleName()
	{
		return this.nodeName;
	}
	
	@Override
	public LineType getLineType()
	{
		return LineType.COMPARISON;
	}
	
	@Override
	public FactValue selfEvaluate(HashMap<String, FactValue> workingMemory, ScriptEngine nashorn, int nodeOption)
	{
		
		/*
		 * Negation type can only be used for this line type
		 * 
		 */		
		
		FactValue workingMemoryLhsValue = workingMemory.get(this.variableName);
		FactValue workingMemoryRhsValue = workingMemory.get(this.getFactValue().getValue().toString());
		
		String script = "";
		
		/*
		 * There will NOT be the case of that workingMemoryRhsValue is null because the node must be in following format;
		 * - A = 12231 (int or double)
		 * - A = <NAME> (String)<commit_msg>made change for future matter in ComparisonLine<commit_after>package nodePackage;

import java.util.HashMap;

import javax.script.ScriptEngine;
import javax.script.ScriptException;


import factValuePackage.*;
import ruleParser.Tokens;


public class ComparisonLine extends Node{
	
	private String operator;
	private String lhs;
	private FactValue rhs;
	
	public ComparisonLine(String childText, Tokens tokens)
	{
		super(childText, tokens);
		
	}
	
	@Override
	public void initialisation(String childText, Tokens tokens) {

		/*
		 * this line pattern is as (^U)([ML]+)(O)([MLNoDaDeHaUrlId]*$)
		 */
		StringBuilder sb = new StringBuilder();
		tokens.tokensList.subList(1, tokens.tokensList.size()).stream().forEachOrdered((s)->sb.append(s+" "));
		this.nodeName = childText;
		
		int operatorIndex = tokens.tokensStringList.indexOf("O");
		sb.setLength(0);
		tokens.tokensList.subList(1, operatorIndex).stream().forEachOrdered((s)-> sb.append(s+" "));
		this.variableName = sb.toString().trim();	
		this.lhs = variableName;
		/*
		 * In javascript engine '=' operator means assigning a value, hence if the operator is '=' then it needs to be replaced with '=='. 
		 */
		this.operator = tokens.tokensList.get(operatorIndex).matches("=")?"==":tokens.tokensList.get(operatorIndex);
		
		
		int tokensStringListSize = tokens.tokensStringList.size();
		String lastToken = tokens.tokensList.get(tokensStringListSize-1);
		String lastTokenString = tokens.tokensStringList.get(tokensStringListSize-1);
		this.setValue(lastTokenString, lastToken);
		this.rhs = this.value;
		
		
	}

	
	
	public String getRuleName()
	{
		return this.nodeName;
	}
	
	public String getLHS()
	{
		return this.lhs;
	}
	
	public FactValue getRHS()
	{
		return this.rhs;
	}
	
	@Override
	public LineType getLineType()
	{
		return LineType.COMPARISON;
	}
	
	@Override
	public FactValue selfEvaluate(HashMap<String, FactValue> workingMemory, ScriptEngine nashorn, int nodeOption)
	{
		
		/*
		 * Negation type can only be used for this line type
		 * 
		 */		
		
		FactValue workingMemoryLhsValue = workingMemory.get(this.variableName);
		FactValue workingMemoryRhsValue = workingMemory.get(this.getFactValue().getValue().toString());
		
		String script = "";
		
		/*
		 * There will NOT be the case of that workingMemoryRhsValue is null because the node must be in following format;
		 * - A = 12231 (int or double)
		 * - A = <NAME> (String)
{'fraction_non_alphanumeric': 0.12009590235396687, 'fraction_numerical': 0.004359197907585004, 'mean_word_length': 4.238584474885845, 'pattern_counts': {'":': 2, '<': 7, '<?xml version=': 0, '>': 11, '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': '230664', 'n_tokens_mistral': 1561, 'n_tokens_neox': 1360, 'n_words': 337}