155cae65563941d34774540f69f5b36e2ae51aa4
[mdsal.git] / model / ietf / rfc6991-ietf-inet-types / src / main / java / org / opendaylight / yang / gen / v1 / urn / ietf / params / xml / ns / yang / ietf / inet / types / rev130715 / IpPrefixBuilder.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 package org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715;
9
10 import static com.google.common.base.Verify.verify;
11
12 import java.util.regex.Pattern;
13
14 /**
15  * Builder for {@link IpPrefix} instances.
16  */
17 public class IpPrefixBuilder {
18     private static final Pattern IPV4_PATTERN;
19
20     static {
21         verify(Ipv4Prefix.PATTERN_CONSTANTS.size() == 1);
22         IPV4_PATTERN = Pattern.compile(Ipv4Prefix.PATTERN_CONSTANTS.get(0));
23     }
24
25     private IpPrefixBuilder() {
26
27     }
28
29     public static IpPrefix getDefaultInstance(final String defaultValue) {
30         return IPV4_PATTERN.matcher(defaultValue).matches() ? new IpPrefix(new Ipv4Prefix(defaultValue))
31                 : new IpPrefix(new Ipv6Prefix(defaultValue));
32     }
33 }