4d63a3588eba953a9e9240d3f31bd875c9840aa7
[mdsal.git] / model / ietf / ietf-inet-types-2013-07-15 / src / main / java / org / opendaylight / yang / gen / v1 / urn / ietf / params / xml / ns / yang / ietf / inet / types / rev130715 / IpAddressNoZoneBuilder.java
1 /*
2  * Copyright (c) 2015 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
9 package org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715;
10
11 import java.util.regex.Matcher;
12 import java.util.regex.Pattern;
13
14
15 /**
16  */
17 public class IpAddressNoZoneBuilder {
18
19     private static final Pattern IPV4_NO_ZONE_PATTERN =
20         Pattern.compile("[0-9\\.]*");
21     private static final Pattern IPV6_NO_ZONE_PATTERN1 =
22         Pattern.compile("[0-9a-fA-F:\\.]*");
23
24
25     public static IpAddressNoZone getDefaultInstance(final String defaultValue) {
26         final Matcher ipv4NoZoneMatcher = IPV4_NO_ZONE_PATTERN.matcher(defaultValue);
27
28         if (ipv4NoZoneMatcher.matches()) {
29             if (IPV6_NO_ZONE_PATTERN1.matcher(defaultValue).matches()) {
30                 throw new IllegalArgumentException(
31                     String.format("Cannot create IpNoZoneAddress from \"%s\", matches both %s and %s",
32                         defaultValue, Ipv4AddressNoZone.class.getSimpleName(), Ipv6AddressNoZone.class.getSimpleName()));
33
34             }
35             return new IpAddressNoZone((new Ipv4AddressNoZone(defaultValue)));
36         } else if (IPV6_NO_ZONE_PATTERN1.matcher(defaultValue).matches()) {
37             return new IpAddressNoZone((new Ipv6AddressNoZone(defaultValue)));
38         } else {
39             throw new IllegalArgumentException("Cannot create IpAddress from " + defaultValue);
40         }
41     }
42
43 }