b660787c6dca3a6c564fc73b2be49354847d7bb0
[ccsdk/features.git] /
1 package org.opendaylight.yang.gen.v1.http.org.openroadm.pm.types.rev191129;
2
3 import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder;
4 import java.lang.reflect.Constructor;
5 import java.lang.reflect.InvocationTargetException;
6 import java.math.BigDecimal;
7 import java.math.BigInteger;
8 import java.util.Optional;
9 import org.opendaylight.yangtools.yang.common.Uint64;
10
11 /**
12  * The purpose of generated class in src/main/java for Union types is to create new instances of unions from a string
13  * representation. In some cases it is very difficult to automate it since there can be unions such as (uint32 -
14  * uint16), or (string - uint32).
15  *
16  * The reason behind putting it under src/main/java is: This class is generated in form of a stub and needs to be
17  * finished by the user. This class is generated only once to prevent loss of user code.
18  *
19  */
20 @JsonPOJOBuilder(buildMethodName = "build", withPrefix = "with")
21 public class PmDataTypeBuilder {
22     private Uint64 _uint64;
23     private BigInteger _unint64;
24     private Long _int64;
25     private BigDecimal _decimal64;
26
27     public PmDataTypeBuilder() {
28         System.out.println("--  Builder");
29     }
30
31     public PmDataTypeBuilder setUnint64(String v) {
32         _unint64 = new BigInteger(v);
33         return this;
34     }
35
36     public PmDataTypeBuilder setUint64(String v) {
37         _uint64 = Uint64.valueOf(v);
38         return this;
39     }
40
41     public PmDataTypeBuilder setInt64(String v) {
42         _int64 = new Long(v);
43         return this;
44     }
45
46     public PmDataTypeBuilder setDecimal64(String v) {
47         _decimal64 = new BigDecimal(v);
48         return this;
49     }
50
51     public PmDataType build() {
52         Optional<Constructor<PmDataType>> cons1;
53         try {
54             cons1 = Optional.of(PmDataType.class.getConstructor(BigInteger.class));
55         } catch (NoSuchMethodException | SecurityException e) {
56             cons1 = Optional.empty();
57         }
58         Optional<Constructor<PmDataType>> cons2;
59         try {
60             cons2 = Optional.of(PmDataType.class.getConstructor(Uint64.class));
61         } catch (NoSuchMethodException | SecurityException e) {
62             cons2 = Optional.empty();
63         }
64
65         try {
66             if (_unint64 != null) {
67                 return cons1.get().newInstance(_unint64);
68             } else if (_uint64 != null) {
69                 return cons2.get().newInstance(_uint64);
70             } else if (_int64 != null) {
71                 return new PmDataType(_int64);
72             } else {
73                 return new PmDataType(_decimal64);
74             }
75         } catch (InstantiationException | IllegalAccessException | IllegalArgumentException
76                 | InvocationTargetException e) {
77             throw new IllegalArgumentException("Wrong stuff");
78         }
79     }
80
81     public static PmDataType getDefaultInstance(String defaultValue) {
82         return new PmDataTypeBuilder().setInt64("-1").build();
83     }
84
85 }