Class DerivedString<T extends DerivedString<T>>
java.lang.Object
org.opendaylight.yangtools.yang.common.DerivedString<T>
- Type Parameters:
T
- derived string representation
- All Implemented Interfaces:
Serializable
,Comparable<T>
,Immutable
,CanonicalValue<T>
- Direct Known Subclasses:
CachingDerivedString
@Beta
@NonNullByDefault
public abstract class DerivedString<T extends DerivedString<T>>
extends Object
implements CanonicalValue<T>
Abstract base class for objects which are string-equivalent to canonical string representation specified
in a YANG model. Note that each subclass of
DerivedString
defines its own hashCode()
and
equals(Object)
contracts based on implementation particulars.
Given the following YANG snippet:
typedef foo { type string; pattern "[1-9]?[0-9]"; } typedef bar { type foo; patter "[1-9][0-9]"; } typedef baz { type foo; }it is obvious we could use a storage class with 'int' as the internal representation of all three types and define operations on top of it. In this case we would define:
public class FooDerivedString extends DerivedString<FooDerivedString>
, which implements all abstract methods ofDerivedString
as final methods. It will notably not overrideCanonicalValue.validator()
and must not be final.public final class FooDerivedStringSupport extends DerivedStringSupport<FooDerivedString>
, which forms the baseline validator and instantiation forFooDerivedString
. It should be a singleton class with a getInstance() method.public class BarDerivedString extends FooDerivedString
, which overridesCanonicalValue.validator()
to indicate its contents have been validated to conform to bar -- it does that by returning the singleton instance ofBarDerivedStringValidator
.public final class BarDerivedStringValidator extends DerivedStringValidator<FooDerivedString, BarDerivedString
. This method needs to notably implementCanonicalValueValidator.validateRepresentation(CanonicalValue)
to hand out BarDerivedString instances. This class needs to be a singleton with a getInstance() method, too.
baz
is not defining any new restrictions, all instances of FooDerivedString are valid for it and we
do not have to define any additional support.
It is important for DerivedString
subclasses not to be final because any YANG type can be further extended
and adding a final class in that hierarchy would prevent a proper class from being defined.
- Author:
- Robert Varga
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface org.opendaylight.yangtools.yang.common.CanonicalValue
support, toCanonicalString, validator
Methods inherited from interface java.lang.Comparable
compareTo