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 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.
Since 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 Details

    • DerivedString

      public DerivedString()
  • Method Details

    • hashCode

      public abstract int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public abstract boolean equals(@Nullable Object obj)
      Overrides:
      equals in class Object
    • toString

      public final String toString()
      Overrides:
      toString in class Object