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 boolean equals(Object obj) { if (obj == null) { return false; } if (getClass() != obj.getClass()) { return false; } final VectorialKeywordSpecification other = (VectorialKeywordSpecification) obj; if (!super.equals(obj)) { return false; } if (this.length != other.length) { return false; } return true; } }
@Override public int hashCode() { int hash = 7; hash = 59 * hash + super.hashCode(); hash = 59 * hash + this.length; return hash; }
/** * Returns a sensible default comparator for the given KeywordSpecification. * * @param keywordSpec some KeywordSpecification. * * @return a sensible default comparator for the given KeywordSpecification. */ public static ValueComparator getDefaultComparator(@NonNull KeywordSpecification keywordSpec) { switch (keywordSpec.getType()) { case STRING: { return new DerivableStringComparatorWrapper(keywordSpec.getKeyword(), new CharStatComparator()); } case SYMBOLIC: { final Alphabet alphabet = ((SymbolicKeywordSpecification) keywordSpec).getAlphabet(); final DerivableComparator<String, String> comp = new SquareReplacementMatrixComparator<>( new IndexingAlphabetWrapper(alphabet)); return new DerivableSymbolicComparatorWrapper(keywordSpec.getKeyword(), comp); } case VECTOR: { final int dimensions = ((VectorialKeywordSpecification) keywordSpec).getLength(); final DerivableComparator<double[], double[]> comp = new NormalizedL1Comparator(dimensions); return new DerivableVectorialComparatorWrapper(keywordSpec.getKeyword(), comp); } default: throw new IllegalArgumentException( "No defaults defined for value type: " + keywordSpec.getType()); } }
/** * Sets the comparator for a given keyword. * * @param index a keyword index that is used in this Alignment. * @param comparator a fitting Comparator that defines a local normalized * distance on the values for the given keyword. */ public void setComparator(final int index, @NonNull final ValueComparator comparator) { if (nodeSpecification.getKeywordSpecification(getOriginalIndex(index)).getType() != comparator.getType()) { throw new RuntimeException("The given comparator has not the correct type!"); } comparators[index] = comparator; }
/** * 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); }
@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(); }
if (keywordSpec.getType() != comparators[k].getType()) { throw new RuntimeException("The comparator given for keyword " + keywords[k] + " has the wrong type!");
/** * 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)); }
if (keywordSpec.getType() != comparators[k].getType()) { throw new RuntimeException("The comparator given for keyword " + keywords[k] + " has the wrong type!");
/** * Sets the value for the given keyword. * * @param index a keyword index. * @param value a value with the correct type. * * @throws UnsupportedOperationException is thrown if the given value has * the wrong type. * @throws ArrayIndexOutOfBoundsException is thrown if the given index is * too large or too small. */ public void setValue(final int index, final Value value) throws UnsupportedOperationException, ArrayIndexOutOfBoundsException { if (!sequence.getNodeSpecification().getKeywordSpecification(index).validate(value)) { throw new UnsupportedOperationException("The given value " + value + " does not meet the given specification for the keyword!"); } valueMap[index] = value; }
@Override public int hashCode() { int hash = 5; hash = 97 * hash + super.hashCode(); hash = 97 * hash + (this.alphabet != null ? this.alphabet.hashCode() : 0); return hash; }
@Override public boolean equals(Object obj) { if (obj == null) { return false; } if (getClass() != obj.getClass()) { return false; } final SymbolicKeywordSpecification other = (SymbolicKeywordSpecification) obj; if (!super.equals(obj)) { return false; } if (this.alphabet != other.alphabet && (this.alphabet == null || !this.alphabet.equals(other.alphabet))) { return false; } return true; } }