Remove useless UnsupportedOperationExceptions
[bgpcep.git] / bgp / openconfig-api / src / main / java / org / opendaylight / yang / gen / v1 / http / openconfig / net / yang / network / instance / types / rev151018 / 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.http.openconfig.net.yang.network.instance.types.rev151018;
9
10 import java.util.regex.Pattern;
11 import org.opendaylight.yangtools.yang.binding.CodeHelpers;
12
13 /**
14  * Helper builder utility for {@code RouteDistinguisher} union type.
15  */
16 public final class RouteDistinguisherBuilder {
17     private static final Pattern[] PATTERNS = CodeHelpers.compilePatterns(RouteDistinguisher.PATTERN_CONSTANTS);
18
19     private RouteDistinguisherBuilder() {
20         // Hidden on purpose
21     }
22
23     public static RouteDistinguisher getDefaultInstance(final String defaultValue) {
24         if (anyMatch(defaultValue)) {
25             return new RouteDistinguisher(defaultValue);
26         }
27         throw new IllegalArgumentException("Cannot create RouteDistinguisher from " + defaultValue);
28     }
29
30     private static boolean anyMatch(final String defaultValue) {
31         for (final Pattern pattern : PATTERNS) {
32             if (pattern.matcher(defaultValue).matches()) {
33                 return true;
34             }
35         }
36         return false;
37     }
38
39 }