/** * This applies the KeywordSpecification validation and additionally checks * whether the given value is part of the Alphabet. * * {@inheritDoc } */ @Override public boolean validate(Value value) { return value == null || (super.validate(value) && ((SymbolicValue) value).getAlphabet().equals(alphabet)); }
/** * This applies the KeywordSpecification validation and additionally checks * whether the given value has the correct length. * * {@inheritDoc } */ @Override public boolean validate(Value value) { return value == null || (super.validate(value) && ((VectorialValue) value).getVector().length == length); }
/** * Sets the value for the given keyword. * * @param keyword a keyword. * @param value a value with the correct type. * * @throws UnsupportedOperationException is thrown if the given keyword is * not supported by the NodeSpecification or if the given value has the * wrong type. */ public void setValue(@NonNull final String keyword, final Value value) throws UnsupportedOperationException { if (!sequence.getNodeSpecification().hasKeyword(keyword)) { throw new UnsupportedOperationException("The given keyword is not defined in the sequence!"); } setValue(sequence.getNodeSpecification().getKeywordIndex(keyword), value); }
public V extractValue(@NonNull Node node) { final Value val = node.getValue(keyword); if (val == null) { return null; } switch (type) { case STRING: return (V) ((StringValue) val).getString(); case SYMBOLIC: return (V) ((SymbolicValue) val).getSymbol(); case VECTOR: return (V) ((VectorialValue) val).getVector(); default: throw new IllegalArgumentException("Unsupported ValueType: " + type); } }
/** * Returns the specification for the given keyword. * * @param keyword a keyword. * * @return the specification for the given keyword. */ public KeywordSpecification getKeywordSpecification(@NonNull final String keyword) { return getKeywordSpecification(getKeywordIndex(keyword)); }
public Node(@NonNull Sequence sequence) { this.sequence = sequence; valueMap = new Value[sequence.getNodeSpecification().size()]; }
@Override public int range() { return alphabet.size(); }
@Override public String toString() { if (size() == 0) { return "<empty NodeSpecification>"; } final StringBuilder builder = new StringBuilder(); for (int k = 0; k < size(); k++) { builder.append(keywordSpecs[k].toString()); builder.append("\n"); } builder.delete(builder.length() - 1, builder.length()); return builder.toString(); }
private static String[] extractKeywords(@NonNull KeywordSpecification[] keywordSpecs) { final String[] out = new String[keywordSpecs.length]; for (int i = 0; i < out.length; i++) { out[i] = keywordSpecs[i].getKeyword(); } return out; }
@Override public int hashCode() { int hash = 7; hash = 67 * hash + (this.type != null ? this.type.hashCode() : 0); return hash; }
@Override public int hashCode() { int hash = 7; hash = 59 * hash + super.hashCode(); hash = 59 * hash + this.length; return hash; }
/** * This is equivalent to "getKeyword" * * @param index an index. * @return the symbol for this index. */ public String getSymbol(int index) { return getKeyword(index); }
/** * This is equivalent to "getKeywords" * * @return the symbols that are contained in this Alphabet. */ public String[] getSymbols() { return getKeywords(); }
/** * 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; }
/** * Sets the actual vector. * * @param convertibleObject an object that can be converted to a double * array or a double scalar. */ public void setVector(@NonNull Object convertibleObject) { this.vector = mapToDoubleVector(convertibleObject); }
/** * This is equivalent to "hasKeyword". * * @param symbol the actual symbol. * @return true if this symbol is contained in the Alphabet and false * otherwise. */ public boolean hasSymbol(@NonNull String symbol) { return hasKeyword(symbol); }
/** * This is equivalent to "getKeywordIndex" * * @param symbol a symbol in this Alphabet. * @return the index for that symbol. */ public int getSymbolIndex(@NonNull String symbol) { return getKeywordIndex(symbol); }
@Override public int hashCode() { int hash = 5; hash = 71 * hash + super.hashCode(); hash = 71 * hash + Arrays.deepHashCode(this.keywordSpecs); return hash; }
@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; }