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

de.citec.tcs.alignment.sequence.SymbolicValue Maven / Gradle / Ivy

Go to download

This module contains the sequence datastructure of the TCS Alignment Toolbox. It defines the possible value sets in the ValueType enum as well as the different KeywordSpecification classes, namely: 1.) StringKeywordSpecification for string type values. 2.) SymbolicKeywordSpecification for values from a discrete alphabet (also refer to the Alphabet class) 3.) VectorialKeywordSpecification for vectors of some length (or for scalars) A NodeSpecification is a vector of such KeywordSpecifications and defines the order of value sets. A node, then, is defined as a vector of values from these value sets (also refer to the Value interface as well as the StringValue, SymbolicValue and VectorialValue classes). Finally a sequence is defined as a list of such nodes.

There is a newer version: 3.1.1
Show newest version
/* 
 * TCS Alignment Toolbox Version 3
 * 
 * Copyright (C) 2016
 * Benjamin Paaßen
 * AG Theoretical Computer Science
 * Centre of Excellence Cognitive Interaction Technology (CITEC)
 * University of Bielefeld
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 * 
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see .
 */

package de.citec.tcs.alignment.sequence;

import lombok.NonNull;

/**
 * This is a special value class that is restricted to a finite list of values
 * defined by an alphabet.
 *
 * @author Benjamin Paassen - [email protected]
 */
public class SymbolicValue extends AbstractValue {

	private final Alphabet alphabet;
	private String symbol;

	public SymbolicValue(@NonNull Alphabet alphabet) {
		super(ValueType.SYMBOLIC);
		this.alphabet = alphabet;
	}

	public SymbolicValue(@NonNull Alphabet alphabet, @NonNull String symbol) {
		super(ValueType.SYMBOLIC);
		this.alphabet = alphabet;
		this.symbol = symbol;
		if (!alphabet.hasSymbol(symbol)) {
			throw new UnsupportedOperationException(
					"The given alphabet does not support the given symbol!");
		}
	}

	/**
	 * Returns the Alphabet that defines which symbols are allowed for this
	 * keyword.
	 *
	 * @return the Alphabet that defines which symbols are allowed for this
	 * keyword.
	 */
	public Alphabet getAlphabet() {
		return alphabet;
	}

	/**
	 * Returns this actual symbol.
	 *
	 * @return this actual symbol.
	 */
	public String getSymbol() {
		return symbol;
	}

	/**
	 * Sets the actual symbol.
	 *
	 * @param symbol the actual symbol.
	 */
	public void setSymbol(@NonNull String symbol) {
		if (alphabet.hasKeyword(symbol)) {
			this.symbol = symbol;
		} else {
			throw new UnsupportedOperationException(
					"The given alphabet does not support the given symbol!");
		}
	}

	@Override
	public String toString() {
		return symbol;
	}

	@Override
	public int hashCode() {
		int hash = 7;
		hash = 97 * hash + (this.symbol != null ? this.symbol.hashCode() : 0);
		return hash;
	}

	@Override
	public boolean equals(Object obj) {
		if (obj == null) {
			return false;
		}
		if (getClass() != obj.getClass()) {
			return false;
		}
		final SymbolicValue other = (SymbolicValue) obj;
		if ((this.symbol == null) ? (other.symbol != null) : !this.symbol.equals(other.symbol)) {
			return false;
		}
		return true;
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy