cf2bce2dc6bed89ca00d0f06303b09381645266f
[mdsal.git] / binding / mdsal-binding-test-model / src / main / java / org / opendaylight / yang / gen / v1 / urn / opendaylight / params / xml / ns / yang / mdsal / test / bug / _6006 / rev160607 / UnionTypeBuilder.java
1 package org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.bug._6006.rev160607;
2
3 /**
4  * The purpose of generated class in src/main/java for Union types is to create new instances of unions from a string representation.
5  * In some cases it is very difficult to automate it since there can be unions such as (uint32 - uint16), or (string - uint32).
6  *
7  * The reason behind putting it under src/main/java is:
8  * This class is generated in form of a stub and needs to be finished by the user. This class is generated only once to prevent
9  * loss of user code.
10  *
11  */
12 public class UnionTypeBuilder {
13
14     public static UnionType getDefaultInstance(final java.lang.String defaultValue) {
15         if (defaultValue.equals("IdentOne")) {
16             return new UnionType(IdentOne.class);
17         }
18         if (defaultValue.equals("IdentTwo")) {
19             return new UnionType(IdentTwo.class);
20         }
21
22         try {
23             return new UnionType(Short.valueOf(defaultValue));
24         } catch (NumberFormatException e) {
25             /* do nothing */
26         }
27
28         throw new IllegalArgumentException("Unknown UnionType string " + defaultValue);
29     }
30
31 }