T
- derived string representation@Beta @NonNullByDefault @ThreadSafe public abstract class DerivedString<T extends DerivedString<T>> extends Object implements CanonicalValue<T>
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 of DerivedString
as final methods. It will notably not override CanonicalValue.validator()
and
must not be final.public final class FooDerivedStringSupport extends DerivedStringSupport<FooDerivedString>
, which
forms the baseline validator and instantiation for FooDerivedString
. It should be a singleton class
with a getInstance() method.public class BarDerivedString extends FooDerivedString
, which overrides CanonicalValue.validator()
to
indicate its contents have been validated to conform to bar -- it does that by returning the singleton
instance of BarDerivedStringValidator
.public final class BarDerivedStringValidator extends DerivedStringValidator<FooDerivedString,
BarDerivedString
. This method needs to notably implement
CanonicalValueValidator.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.
Constructor and Description |
---|
DerivedString() |
Modifier and Type | Method and Description |
---|---|
abstract boolean |
equals(@Nullable Object obj) |
abstract int |
hashCode() |
String |
toString() |
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
support, toCanonicalString, validator
compareTo
Copyright © 2019 OpenDaylight. All rights reserved.