public abstract class AbstractImmutableVocabulary<T extends ImmutableTerm> extends Object implements Vocabulary
ImmutableTerms.
private static class CustomVocabulary extends
AbstractImmutableVocabulary<ImmutableTerm> {
private static final String NAMESPACE = "http://www.example.org/vocab";
private static final String PREFERRED_PREFIX = "test";
private static final String TERM_THREE = "termThree";
private static final String TERM_TWO = "termTwo";
private static final String TERM_ONE = "termOne";
public CustomVocabulary() {
super(ImmutableTerm.class, NAMESPACE, PREFERRED_PREFIX);
}
private static final CustomVocabulary VOCABULARY;
private static final Term ONE;
private static final Term TWO;
private static final Term THREE;
static {
VOCABULARY = new CustomVocabulary();
ONE = new ImmutableTerm(VOCABULARY, TERM_ONE);
TWO = new ImmutableTerm(VOCABULARY, TERM_TWO);
THREE = new ImmutableTerm(VOCABULARY, TERM_THREE);
VOCABULARY.initialize();
}
}
Term related operations will fail with a IllegalStateException if
they are used before the vocabulary is initialized properly.ImmutableTerm,
Serialized Form| Constructor and Description |
|---|
AbstractImmutableVocabulary(Class<T> clazz,
String namespace,
String prefix)
Create a new instance with a term class, a namespace, and a preferred
prefix.
|
| Modifier and Type | Method and Description |
|---|---|
T |
fromName(String name)
Returns the vocabulary term with the specified name.
|
T |
fromOrdinal(int ordinal)
Returns the vocabulary term specified in a given position.
|
<V> T |
fromValue(V value)
Returns the vocabulary term that matches the specified value.
|
UUID |
getId()
Get the unique identifier of the vocabulary.
|
String |
getNamespace()
Get the namespace of the vocabulary.
|
String |
getPreferredPrefix()
Get the preferred prefix for the vocabulary namespace.
|
Iterator<Term> |
iterator() |
int |
size()
Get the number of terms defined in the vocabulary.
|
T[] |
terms()
Get the terms defined in the vocabulary.
|
public AbstractImmutableVocabulary(Class<T> clazz, String namespace, String prefix)
clazz - the type of terms held by the vocabulary.namespace - the namespace of the vocabulary.prefix - the preferred prefix of the vocabulary.NullPointerException - if any of the parameters is null.public final UUID getId()
UUIDpublic final String getNamespace()
getNamespace in interface Vocabularynull
nor empty.public final String getPreferredPrefix()
getPreferredPrefix in interface Vocabularynull nor empty.public final T[] terms()
terms in interface Vocabularypublic final int size()
size in interface Vocabulary0 if no term is defined.public final T fromName(String name)
fromName in interface Vocabularyname - the name of the term to returnpublic T fromOrdinal(int ordinal)
fromOrdinal in interface Vocabularyordinal - the position in which the desired term was declared.public final <V> T fromValue(V value)
fromValue in interface Vocabularyvalue - a value to determine the desired term.value.Term.as(Class)
Copyright (C) 2014-2016, Center for Open Middleware