9baeeef446001ec70213656052490355645e3063
[bgpcep.git] / bgp / concepts / src / main / java / org / opendaylight / yang / gen / v1 / urn / opendaylight / params / xml / ns / yang / bgp / types / rev130919 / RouteDistinguisherBuilder.java
1 /*
2  * Copyright (c) 2016 Cisco Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919;
9
10 import java.util.regex.Pattern;
11
12
13 /**
14  * The purpose of generated class in src/main/java for Union types is to create new instances of unions from a string representation.
15  * In some cases it is very difficult to automate it since there can be unions such as (uint32 - uint16), or (string - uint32).
16  *
17  * The reason behind putting it under src/main/java is:
18  * 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
19  * loss of user code.
20  *
21  */
22 public class RouteDistinguisherBuilder {
23
24     private static final Pattern RD_IPV4 =
25         Pattern.compile("((([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\\.){3}"
26             + "([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5]))"
27             + ":"
28             + "([0-9]|[1-9][0-9]|[1-9][0-9][0-9]|[1-9][0-9][0-9][0-9]|"
29             + "[1-5][0-9][0-9][0-9][0-9]|6[0-4][0-9][0-9][0-9]|"
30             + "65[0-4][0-9][0-9]|655[0-2][0-9]|6553[0-5])");
31
32     private static final Pattern RD_AS =
33         Pattern.compile("([0-9]|[1-9][0-9]|[1-9][0-9][0-9]|[1-9][0-9][0-9][0-9]|"
34             + "[1-9][0-9][0-9][0-9][0-9]|[1-9][0-9][0-9][0-9][0-9][0-9]|"
35             + "[1-9][0-9][0-9][0-9][0-9][0-9][0-9]|[1-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]|"
36             + "[1-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]|[1-3][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]|"
37             + "4[0-1][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]|42[0-8][0-9][0-9][0-9][0-9][0-9][0-9][0-9]|"
38             + "429[0-3][0-9][0-9][0-9][0-9][0-9][0-9]|4294[0-8][0-9][0-9][0-9][0-9][0-9]|"
39             + "42949[0-5][0-9][0-9][0-9][0-9]|429496[0-6][0-9][0-9][0-9]|4294967[0-1][0-9][0-9]|"
40             + "42949672[0-8][0-9]|429496729[0-5])"
41             + ":"
42             + "([0-9]|[1-9][0-9]|[1-9][0-9][0-9]|[1-9][0-9][0-9][0-9]|"
43             + "[1-5][0-9][0-9][0-9][0-9]|6[0-4][0-9][0-9][0-9]|"
44             + "65[0-4][0-9][0-9]|655[0-2][0-9]|6553[0-5])");
45
46     private RouteDistinguisherBuilder() {
47
48     }
49
50     public static RouteDistinguisher getDefaultInstance(final java.lang.String defaultValue) {
51         if (RD_IPV4.matcher(defaultValue).matches()) {
52             return new RouteDistinguisher(new RdIpv4(defaultValue));
53         } else if (RD_AS.matcher(defaultValue).matches()) {
54             return new RouteDistinguisher(new RdAs(defaultValue));
55         } else {
56             throw new IllegalArgumentException("Cannot create Route Distinguisher from " + defaultValue);
57         }
58     }
59
60 }