001/**
002 * #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=#
003 *   This file is part of the LDP4j Project:
004 *     http://www.ldp4j.org/
005 *
006 *   Center for Open Middleware
007 *     http://www.centeropenmiddleware.com/
008 * #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=#
009 *   Copyright (C) 2014-2016 Center for Open Middleware.
010 * #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=#
011 *   Licensed under the Apache License, Version 2.0 (the "License");
012 *   you may not use this file except in compliance with the License.
013 *   You may obtain a copy of the License at
014 *
015 *             http://www.apache.org/licenses/LICENSE-2.0
016 *
017 *   Unless required by applicable law or agreed to in writing, software
018 *   distributed under the License is distributed on an "AS IS" BASIS,
019 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
020 *   See the License for the specific language governing permissions and
021 *   limitations under the License.
022 * #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=#
023 *   Artifact    : org.ldp4j.framework:ldp4j-application-api:0.2.2
024 *   Bundle      : ldp4j-application-api-0.2.2.jar
025 * #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=#
026 */
027package org.ldp4j.application.vocabulary;
028
029import java.io.Serializable;
030
031
032/**
033 * The class represents the terms of a vocabulary. The class includes different
034 * mechanisms for identifying the term as well as utility methods for
035 * transforming the term into different types.
036 *
037 * @version 1.0
038 * @since 1.0.0
039 * @author Miguel Esteban Gutiérrez
040 * @see Vocabulary
041 */
042public interface Term extends Comparable<Term>, Serializable {
043
044  /**
045   * Returns the ordinal of this term (its position in its vocabulary
046   * declaration, where the initial constant is assigned an ordinal of zero).
047   *
048   * @return the ordinal of this term
049   */
050  int ordinal();
051
052  /**
053   * Returns the name of this term constant, exactly as declared in its
054   * vocabulary declaration.
055   *
056   * <b>Most programmers should use the {@link Object#toString} method in preference
057   * to this one, as the toString method may return a more user-friendly
058   * name.</b> This method is designed primarily for use in specialized
059   * situations where correctness depends on getting the exact name, which
060   * will not vary from release to release.
061   *
062   * @return the name of this term
063   */
064  String name();
065
066  /**
067   * Get the simple name of the entity of the vocabulary identified by this
068   * term constant.
069   *
070   * @return the entity name
071   */
072  String entityName();
073
074  /**
075   * Get the qualified name of the entity of the vocabulary identified by
076   * this term constant.
077   *
078   * @return the qualified name
079   */
080  String qualifiedEntityName();
081
082  /**
083   * Returns the Vocabulary object corresponding to this term constant's
084   * vocabulary type. Two term constants e1 and e2 are of the same vocabulary
085   * type if and only if
086   * {@code e1.getDeclaringVocabulary() == e2.getDeclaringVocabulary()}.
087   *
088   * @return the Vocabulary object corresponding to this term constant's
089   *         vocabulary type
090   */
091  Vocabulary getDeclaringVocabulary();
092
093  /**
094   * Transform the term to an instance of the specified type.
095   *
096   * @param <T> the type of object to be returned
097   * @param type
098   *            The type to which the term is to be transformed to.
099   * @return An instance of the specified type that represents this term.
100   * @throws UnsupportedOperationException
101   *             if the term cannot be transformed to the specified type.
102   */
103  <T> T as(Class<? extends T> type);
104
105}