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

de.citec.tcs.alignment.sequence.KeywordSpecification 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 specifies a keyword via its name and the type of its values. Further
 * specifications might be required by subclasses.
 *
 * @author Benjamin Paassen - [email protected]
 */
public abstract class KeywordSpecification {

	private final String keyword;
	private final ValueType type;

	/**
	 * Sets up a KeywordSpecification that defines a type for the given keyword.
	 *
	 * @param keyword a keyword.
	 * @param type the correct type for that keyword.
	 */
	public KeywordSpecification(@NonNull String keyword, @NonNull ValueType type) {
		this.keyword = keyword;
		this.type = type;
	}

	/**
	 * Returns the keyword.
	 *
	 * @return the keyword.
	 */
	public String getKeyword() {
		return keyword;
	}

	/**
	 * Returns the specified type for that keyword.
	 *
	 * @return the specified type for that keyword.
	 */
	public ValueType getType() {
		return type;
	}

	/**
	 * Returns true if the given value is in order according to this
	 * specification, meaning that it has the correct type or is null.
	 *
	 * @param value a value.
	 *
	 * @return true if the given value is in order according to this
	 * specification, meaning that it has the correct type or is null.
	 */
	public boolean validate(final Value value) {
		if (value == null) {
			return true;
		}
		return value.getType() == type;
	}

	@Override
	public int hashCode() {
		int hash = 3;
		hash = 53 * hash + (this.keyword != null ? this.keyword.hashCode() : 0);
		hash = 53 * hash + (this.type != null ? this.type.hashCode() : 0);
		return hash;
	}

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

	@Override
	public String toString() {
		return keyword + " : " + type;
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy