Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
titleGenerated java files
File: MyBinary.java
package org.onosproject.yang.gen.v1.http.huawei.com.rev20160718.test;
import java.util.Objects;
import com.google.common.base.MoreObjects;
import java.util.Base64;
/**
 * Represents the implementation of myBinary.
 */
public final class MyBinary {
   private byte[] binary;

   /**
   * Creates an instance of myBinary.
   */
   private MyBinary() {
   }

   /**
   * Creates an instance of myBinaryForTypeBinary.
   *
   * @param value value of myBinaryForTypeBinary
   */
   public MyBinary(byte[] value) {
      this.binary = value;
   }
 
   /**
   * Returns the object of myBinaryForTypeBinary.
   *
   * @param value value of myBinaryForTypeBinary
   * @return Object of myBinaryForTypeBinary
   */
   public static MyBinary of(byte[] value) {
      return new MyBinary(value);
   }
 
   /**
   * Returns the attribute binary.
   *
   * @return value of binary
   */
   public byte[] binary() {
      return binary;
   }
 
   @Override
   public int hashCode() {
      return Objects.hash(binary);
   }
 
   @Override
   public boolean equals(Object obj) {
      if (this == obj) {
         return true;
      }
      if (obj instanceof MyBinary) {
         MyBinary other = (MyBinary) obj;
         return Objects.equals(binary, other.binary);
      }
      return false;
   }
 
   @Override
   public String toString() {
      return Base64.getEncoder().encodeToString(binary);
   }
 
   /**
   * Returns the object of myBinary fromString input String.
   *
   * @param valInString input String
   * @return Object of myBinary
   */
   public static MyBinary fromString(String valInString) {
      try {
         byte[] tmpVal = Base64.getDecoder().decode(valInString);
         return of(tmpVal);
      } catch (Exception e) {
      }
      return null;
   }
}

 


decimal64 

Overview

The decimal64 type represents a subset of the real numbers, which can be represented by decimal numerals.

...

A decimal64 type can be restricted with the "range" statement. 

The "fraction-digits" statement, which is a substatement to the "type" statement, MUST be present if the type is "decimal64".  It takes as an argument an integer between 1 and 18, inclusively. It controls the size of the minimum difference between values of a decimal64 type.

The Minimum and Maximum decimal64 value table for each fraction-digit value.

fraction-digitminmax
1-922337203685477580.8922337203685477580.7
2-92233720368547758.0892233720368547758.07
3-9223372036854775.8089223372036854775.807
4-922337203685477.5808922337203685477.5807
5-92233720368547.7580892233720368547.75807
6-9223372036854.7758089223372036854.775807
7-922337203685.4775808922337203685.4775807
8-92233720368.

...

5477580892233720368.54775807
9-9223372036.8547758089223372036.854775807
10-922337203.6854775808922337203.6854775807
11-92233720.3685477580892233720.36854775807
12-9223372.0368547758089223372.036854775807
13-922337.2036854775808922337.2036854775807
14-92233.7203685477580892233.72036854775807
15-9223.3720368547758089223.372036854775807
16-922.3372036854775808922.3372036854775807
17-92.2337203685477580892.23372036854775807
18-9.2233720368547758089.223372036854775807
Java mapping

BigDecimal is used to store decimal64 value during code generation.

Example

 

Code Block
titleinput YANG file
File : test.yang

module Test {
    yang-version 1;
    namespace http://huawei.com;
    prefix Ant;

    typedef MyDecimal {
        type decimal64 {
            fraction-digits 2;
            range "1 .. 3.14 | 10 | 20..max";
        }
    }
}
Code Block
titleGenerated java files
File: MyDecimal.java
 package org.onosproject.yang.gen.v1.http.huawei.com.rev20160718.test; import java.math.BigDecimal; import java.util.Objects; import com.google.common.base.MoreObjects; /** * Represents the implementation of myDecimal. */ public final class MyDecimal { private BigDecimal decimal64; /** * Creates an instance of myDecimal. */ private MyDecimal() { } /** * Creates an instance of myDecimalForTypeDecimal64. * * @param value value of myDecimalForTypeDecimal64 */ public MyDecimal(BigDecimal value) { this.decimal64 = value; } /** * Returns the object of myDecimalForTypeDecimal64. * * @param value value of myDecimalForTypeDecimal64 * @return Object of myDecimalForTypeDecimal64 */ public static MyDecimal of(BigDecimal value) { return new MyDecimal(value); } /** * Returns the attribute decimal64. * * @return value of decimal64 */ public BigDecimal decimal64() { return decimal64; } @Override public int hashCode() { return Objects.hash(decimal64); } @Override public boolean equals(Object obj) { if (this == obj) { return true; } if (obj instanceof MyDecimal) { MyDecimal other = (MyDecimal) obj; return Objects.equals(decimal64, other.decimal64); } return false; } @Override public String toString() { return MoreObjects.toStringHelper(getClass()) .add("decimal64", decimal64) .toString(); } /** * Returns the object of myDecimal fromString input String. * * @param valInString input String * @return Object of myDecimal */ public static MyDecimal fromString(String valInString) { try { BigDecimal tmpVal = new BigDecimal(valInString); return of(tmpVal); } catch (Exception e) { } return null; } }

 


Golden Eye Demo 

Link: https://www.youtube.com/watch?v=ipbu0x0LcDk

Presentation: YANG Demo.pptx

References

RFC6020 - https://tools.ietf.org/html/rfc6020

 

NameOrganizationEmail
Adarsh MHuawei Technologiesadarsh.m@huawei.com
Bharat SaraswalHuawei Technologiesbharat.saraswal@huawei.com

Golden Eye Demo 

Link: https://www.youtube.com/watch?v=ipbu0x0LcDk

Presentation: YANG Demo.pptx

References

...