ai.vespa.validation.StringWrapper Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of vespajlib Show documentation
Show all versions of vespajlib Show documentation
Library for use in Java components of Vespa. Shared code which do
not fit anywhere else.
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package ai.vespa.validation;
import static java.util.Objects.requireNonNull;
/**
* Abstract wrapper for glorified strings, to ease adding new such wrappers.
*
*
* What's in a name?
* That which we call a String
* by any other name would smell as foul.
* No? 'Tis not sooth?
* No ... I see it now!
* Baptiz'd a-new, the String—
* no more a String,
* no less a {@link #value}—
* it bringeth counsel
* and is proof against their enmity.
*
* @param child type
*
* @author jonmv
*/
public abstract class StringWrapper> implements Comparable {
private final String value;
protected StringWrapper(String value) {
this.value = requireNonNull(value);
}
public final String value() { return value; }
@Override
public int compareTo(T other) {
return value().compareTo(other.value());
}
@Override
public final boolean equals(Object o) {
return this
==
( o) || (o ) instanceof StringWrapper
< ?>
w && ( value.equals(w.value));
}
@Override
public final int hashCode() {
return value.hashCode();
}
@Override
public String toString() {
return value;
}
}