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

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

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

import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;


public class SynonymGroup {

	//These correspond to paths read from the input document - they can either be used as values in the output or as part of conditions
	//if this list is empty then we are in a set-to situation - the condition will be used to derive the correct value
	private final List synonymValues;
	//these are conditions that must all be true in order for the value to be set
	//or set-to values to be used in place of an input
	private final List conditions;
	//This is the name of a custom mapper class.  In the synonym definition, a custom mapper can be specified by name, which is run
	//as the final step of the ingestion parse and map.  Used to support difficult use cases, and avoid making the grammar or logic 
	//over-complicated for the general use cases.
	private final String mapperName;
	
	private final String formatString;
	private final String patternMatcher;
	private final String patternReplace;
	private final boolean removeHtml;
	
	public SynonymGroup(List synonymValues, List conditions, String mapperName, String formatString, String patternMatcher, String patternReplace, boolean removeHtml) {
		this.synonymValues = synonymValues;
		this.conditions = conditions;
		this.mapperName = mapperName;
		this.formatString = formatString;
		this.patternMatcher = patternMatcher;
		this.patternReplace = patternReplace;
		this.removeHtml = removeHtml;
	}	
	
	public SynonymGroup(List conditions) {
		this.synonymValues = Collections.emptyList();
		this.conditions = conditions;
		this.mapperName = null;
		this.formatString = null;
		this.patternMatcher = null;
		this.patternReplace = null;
		this.removeHtml = false;
	}
	
	public List getSynonymValues() {
		return synonymValues;
	}

	public List getConditions() {
		return conditions;
	}

	public String getMapperName() {
		return mapperName;
	}
	
	public String getFormatString() {
		return formatString;
	}

	public String getPatternMatcher() {
		return patternMatcher;
	}

	public String getPatternReplace() {
		return patternReplace;
	}

	public boolean isRemoveHtml() {
		return removeHtml;
	}
	
	@Override
	public String toString() {
		return String.format("SG[values=%s conditions=%s mapperName=%s, format=%s, pattern=%s/%s, removeHtml=%s]", synonymValues, conditions, mapperName, formatString, patternMatcher, patternReplace, removeHtml);
	}
	
	public String toPathsString() {
		return synonymValues.stream().map(sv->sv.toPathString()).collect(Collectors.joining(", ")) +
				conditions.stream().map(c->c.toString()).collect(Collectors.joining(","));
	}
	
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((conditions == null) ? 0 : conditions.hashCode());
		result = prime * result + ((formatString == null) ? 0 : formatString.hashCode());
		result = prime * result + ((mapperName == null) ? 0 : mapperName.hashCode());
		result = prime * result + ((patternMatcher == null) ? 0 : patternMatcher.hashCode());
		result = prime * result + ((patternReplace == null) ? 0 : patternReplace.hashCode());
		result = prime * result + (removeHtml ? 1231 : 1237);
		result = prime * result + ((synonymValues == null) ? 0 : synonymValues.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;
		SynonymGroup other = (SynonymGroup) obj;
		if (conditions == null) {
			if (other.conditions != null)
				return false;
		} else if (!conditions.equals(other.conditions))
			return false;
		if (formatString == null) {
			if (other.formatString != null)
				return false;
		} else if (!formatString.equals(other.formatString))
			return false;
		if (mapperName == null) {
			if (other.mapperName != null)
				return false;
		} else if (!mapperName.equals(other.mapperName))
			return false;
		if (patternMatcher == null) {
			if (other.patternMatcher != null)
				return false;
		} else if (!patternMatcher.equals(other.patternMatcher))
			return false;
		if (patternReplace == null) {
			if (other.patternReplace != null)
				return false;
		} else if (!patternReplace.equals(other.patternReplace))
			return false;
		if (removeHtml != other.removeHtml)
			return false;
		if (synonymValues == null) {
			if (other.synonymValues != null)
				return false;
		} else if (!synonymValues.equals(other.synonymValues))
			return false;
		return true;
	}

	public long hashForGeneration() {
		long result = 0;
		for (SynonymCondition cond : conditions) {
			result = result * 8191 + cond.hashCode();
		}
		for (SynonymValue val : synonymValues) {
			result = result * 8191 + val.getMapsTo();
			result = result * 8191 + val.toPathString().hashCode();
		}
		if (mapperName!=null) {
			result = result * 8191 + mapperName.hashCode();
		}
		if (patternMatcher!=null) {
			result = result * 8191 + patternMatcher.hashCode();
		}
		if (patternReplace!=null) {
			result = result * 8191 + patternReplace.hashCode();
		}
		result = result * 8191 + (removeHtml ? 1231 : 1237);
		return result;
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy