T - the implementation subclass of this classpublic abstract class TypedString<T extends TypedString<T>> extends Object implements Named, Comparable<T>, Serializable
The purpose of TypedString is to provide a Java type to a concept
that might otherwise be represented as a string.
It could be thought of as a way to provide a type alias for a string.
The string wrapped by this type must not be empty.
Subclasses must be written as follows:
public final class FooType
extends TypedString<FooType> {
private static final long serialVersionUID = 1L;
@FromString
public static FooType of(String name) {
return new FooType(name);
}
private FooType(String name) {
super(name);
}
}
The net result is that an API can be written with methods taking
FooType as a method parameter instead of String.
| Modifier | Constructor and Description |
|---|---|
protected |
TypedString(String name)
Creates an instance.
|
protected |
TypedString(String name,
CharMatcher matcher,
String msg)
Creates an instance, validating the name against a matcher.
|
protected |
TypedString(String name,
Pattern pattern,
String msg)
Creates an instance, validating the name against a regex.
|
| Modifier and Type | Method and Description |
|---|---|
int |
compareTo(T other)
Compares this type to another.
|
boolean |
equals(Object obj)
Checks if this type equals another.
|
String |
getName()
Gets the name.
|
int |
hashCode()
Returns a suitable hash code.
|
String |
toString()
Returns the name.
|
protected TypedString(String name)
name - the name, not emptyprotected TypedString(String name, Pattern pattern, String msg)
In most cases, a CharMatcher will be faster than a regex Pattern,
typically by over an order of magnitude.
name - the name, not emptypattern - the regex pattern for validating the namemsg - the message to use to explain validation failureprotected TypedString(String name, CharMatcher matcher, String msg)
In most cases, a CharMatcher will be faster than a regex Pattern,
typically by over an order of magnitude.
name - the name, not emptymatcher - the matcher for validating the namemsg - the message to use to explain validation failurepublic String getName()
public final int compareTo(T other)
Instances are compared in alphabetical order based on the name.
compareTo in interface Comparable<T extends TypedString<T>>other - the object to compare topublic final boolean equals(Object obj)
Instances are compared based on the name.
public final int hashCode()
Copyright 2009-Present by OpenGamma Inc. and individual contributors
Apache v2 licensed
Additional documentation can be found at strata.opengamma.io.