All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.regnosys.rosetta.translate.synonymmap.SynonymBinaryTest Maven / Gradle / Ivy

There is a newer version: 11.25.1
Show newest version
package com.regnosys.rosetta.translate.synonymmap;

import com.regnosys.rosetta.rosetta.expression.RosettaBinaryOperation;
import com.regnosys.rosetta.rosetta.expression.RosettaExpression;
import com.regnosys.rosetta.rosetta.RosettaMapPathValue;
import com.regnosys.rosetta.rosetta.RosettaMapTestEqualityOperation;
import com.regnosys.rosetta.rosetta.RosettaMapTestExpression;

import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class SynonymBinaryTest implements SynonymTest {

	private final SynonymValue leftPath;
	private final SynonymValue rightPath;
	private final RosettaMapTestExpression leftLiteral;
	private final RosettaMapTestExpression rightLiteral;
	private final String operator;
	
	public SynonymBinaryTest(RosettaMapTestEqualityOperation op) {
		if (op.getLeft() instanceof RosettaMapPathValue)
		{
			leftPath = new SynonymValue(Element.toElementList(((RosettaMapPathValue)op.getLeft()).getPath()), 1, false);
			leftLiteral = null;
		} else {
			leftLiteral = op.getLeft();
			leftPath = null;
		}
		if (op.getRight() instanceof RosettaMapPathValue)
		{
			rightPath = new SynonymValue(Element.toElementList(((RosettaMapPathValue)op.getRight()).getPath()), 1, false);
			rightLiteral = null;
		} else {
			rightLiteral = op.getRight();
			rightPath = null;
		}
		operator = op.getOperator();
	}

    @Override
    public TestPriority priority() {
        return TestPriority.Middle;
    }
	
	@Override
	public List getPaths() {
		return Stream.of(leftPath, rightPath).filter(Objects::nonNull).collect(Collectors.toList());
	}
	
	public SynonymValue getLeftPath() {
		return leftPath;
	}

	public SynonymValue getRightPath() {
		return rightPath;
	}

	public RosettaMapTestExpression getLeftLiteral() {
		return leftLiteral;
	}

	public RosettaMapTestExpression getRightLiteral() {
		return rightLiteral;
	}

	public String getOperator() {
		return operator;
	}

	@Override
	public String toString() {
		return (leftPath==null?SynonymTest.toString(leftLiteral):leftPath.toPathString()) + operator + 
				(rightPath==null?SynonymTest.toString(rightLiteral):rightPath.toPathString());
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((leftLiteral == null) ? 0 : leftLiteral.hashCode());
		result = prime * result + ((leftPath == null) ? 0 : leftPath.hashCode());
		result = prime * result + ((operator == null) ? 0 : operator.hashCode());
		result = prime * result + ((rightLiteral == null) ? 0 : rightLiteral.hashCode());
		result = prime * result + ((rightPath == null) ? 0 : rightPath.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		SynonymBinaryTest other = (SynonymBinaryTest) obj;
		if (leftLiteral == null) {
			if (other.leftLiteral != null)
				return false;
		} else if (!leftLiteral.equals(other.leftLiteral))
			return false;
		if (leftPath == null) {
			if (other.leftPath != null)
				return false;
		} else if (!leftPath.equals(other.leftPath))
			return false;
		if (operator == null) {
			if (other.operator != null)
				return false;
		} else if (!operator.equals(other.operator))
			return false;
		if (rightLiteral == null) {
			if (other.rightLiteral != null)
				return false;
		} else if (!rightLiteral.equals(other.rightLiteral))
			return false;
		if (rightPath == null) {
			if (other.rightPath != null)
				return false;
		} else if (!rightPath.equals(other.rightPath))
			return false;
		return true;
	}
	
	

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy