* terms of the Eclipse Public License v1.0 which accompanies this distribution,
* and is available at http://www.eclipse.org/legal/epl-v10.html
*/
-
package org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.policy.rev151009;
-import com.google.common.primitives.UnsignedInts;
-import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.policy.rev151009.BgpSetMedType.Enumeration;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
- * The purpose of generated class in src/main/java for Union types is to create new instances of unions from a string representation.
- * In some cases it is very difficult to automate it since there can be unions such as (uint32 - uint16), or (string - uint32).
- *
- * The reason behind putting it under src/main/java is:
- * 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
- * loss of user code.
- *
+ * Customized handler for instantiating {@link BgpSetMedType} from a String.
*/
-public class BgpSetMedTypeBuilder {
+public final class BgpSetMedTypeBuilder {
+ private static final Logger LOG = LoggerFactory.getLogger(BgpSetMedTypeBuilder.class);
+ private static final Pattern MED_TYPE_STRING_PATTERN = Pattern.compile("^[+-][0-9]+$");
- private static final Pattern MED_TYPE_STRING_PATTERN = Pattern.compile("^^[+-][0-9]+$");
-
- public static BgpSetMedType getDefaultInstance(final java.lang.String defaultValue) {
- final Matcher ipv4Matcher = MED_TYPE_STRING_PATTERN.matcher(defaultValue);
+ private BgpSetMedTypeBuilder() {
+ // Hidden
+ }
- if (ipv4Matcher.matches()) {
+ public static BgpSetMedType getDefaultInstance(final String defaultValue) {
+ if (MED_TYPE_STRING_PATTERN.matcher(defaultValue).matches()) {
return new BgpSetMedType(defaultValue);
- } else {
- try {
- final long parseUnsignedInt = UnsignedInts.parseUnsignedInt(defaultValue);
- return new BgpSetMedType(parseUnsignedInt);
- } catch (final NumberFormatException e) {
- try {
- final Enumeration medTypeEnum = BgpSetMedType.Enumeration.valueOf(defaultValue.toUpperCase());
- return new BgpSetMedType(medTypeEnum);
- } catch(final IllegalArgumentException e1) {
- throw new IllegalArgumentException("Cannot create BgpSetMedType from " + defaultValue);
- }
- }
}
- }
+ try {
+ return new BgpSetMedType(Integer.toUnsignedLong(Integer.parseUnsignedInt(defaultValue)));
+ } catch (final NumberFormatException e) {
+ LOG.debug("Could not interpret \"{}\" as an unsinged integer", defaultValue, e);
+ }
+
+ return new BgpSetMedType(Enumeration.forName(defaultValue.toUpperCase())
+ .orElseThrow(() -> new IllegalArgumentException("Invalid BgpSetMedType " + defaultValue)));
+ }
}
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
* and is available at http://www.eclipse.org/legal/epl-v10.html
*/
-
package org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.types.rev151009;
-import com.google.common.primitives.UnsignedInts;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
/**
- * The purpose of generated class in src/main/java for Union types is to create new instances of unions from a string representation.
- * In some cases it is very difficult to automate it since there can be unions such as (uint32 - uint16), or (string - uint32).
- *
- * The reason behind putting it under src/main/java is:
- * 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
- * loss of user code.
- *
+ * Customized handler for instantiating {@link BgpStdCommunityType} from a String.
*/
-public class BgpStdCommunityTypeBuilder {
-
- private static final Pattern COMM_TYPE_PATTERN = Pattern.compile("^([0-9]+:[0-9]+)$");
-
- public static BgpStdCommunityType getDefaultInstance(final java.lang.String defaultValue) {
- final Matcher commMatcher = COMM_TYPE_PATTERN.matcher(defaultValue);
+public final class BgpStdCommunityTypeBuilder {
+ private BgpStdCommunityTypeBuilder() {
+ // Hidden
+ }
- if (commMatcher.matches()) {
+ public static BgpStdCommunityType getDefaultInstance(final String defaultValue) {
+ // uints cannot have a ':', which is allowed for four-octets
+ if (defaultValue.indexOf(':') != -1) {
return new BgpStdCommunityType(defaultValue);
- } else {
- try {
- final long parseUnsignedInt = UnsignedInts.parseUnsignedInt(defaultValue);
- return new BgpStdCommunityType(parseUnsignedInt);
- } catch (final NumberFormatException e) {
- throw new IllegalArgumentException("Cannot create BgpStdCommunityType from " + defaultValue);
- }
}
- }
+ try {
+ return new BgpStdCommunityType(Integer.toUnsignedLong(Integer.parseUnsignedInt(defaultValue)));
+ } catch (final NumberFormatException e) {
+ throw new IllegalArgumentException("Cannot create BgpStdCommunityType from " + defaultValue, e);
+ }
+ }
}
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
* and is available at http://www.eclipse.org/legal/epl-v10.html
*/
-
-
package org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.types.rev151009;
-import com.google.common.primitives.UnsignedInts;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
/**
- * The purpose of generated class in src/main/java for Union types is to create new instances of unions from a string representation.
- * In some cases it is very difficult to automate it since there can be unions such as (uint32 - uint16), or (string - uint32).
- *
- * The reason behind putting it under src/main/java is:
- * 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
- * loss of user code.
- *
+ * Customized handler for instantiating {@link RrClusterIdType} from a String.
*/
-public class RrClusterIdTypeBuilder {
-
- private static final Pattern IPV4_PATTERN = Pattern.compile("^(([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\\.){3}([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])(%[\\p{N}\\p{L}]+)?$");
+public final class RrClusterIdTypeBuilder {
+ private RrClusterIdTypeBuilder() {
+ // Hidden
+ }
- public static RrClusterIdType getDefaultInstance(final java.lang.String defaultValue) {
- final Matcher ipv4Matcher = IPV4_PATTERN.matcher(defaultValue);
- if (ipv4Matcher.matches()) {
+ public static RrClusterIdType getDefaultInstance(final String defaultValue) {
+ // IPv4 has to have a dot in it
+ if (defaultValue.indexOf('.') != -1) {
return new RrClusterIdType(new Ipv4Address(defaultValue));
- } else {
- try {
- final long parseUnsignedInt = UnsignedInts.parseUnsignedInt(defaultValue);
- return new RrClusterIdType(parseUnsignedInt);
- } catch (final NumberFormatException e) {
- throw new IllegalArgumentException("Cannot create RrClusterIdType from " + defaultValue);
- }
}
- }
+ try {
+ return new RrClusterIdType(Integer.toUnsignedLong(Integer.parseUnsignedInt(defaultValue)));
+ } catch (final NumberFormatException e) {
+ throw new IllegalArgumentException("Cannot create RrClusterIdType from " + defaultValue, e);
+ }
+ }
}
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
* and is available at http://www.eclipse.org/legal/epl-v10.html
*/
-
package org.opendaylight.yang.gen.v1.http.openconfig.net.yang.network.instance.types.rev151018;
import java.util.regex.Pattern;
+import org.opendaylight.yangtools.yang.binding.CodeHelpers;
/**
- *
* Helper builder utility for {@code RouteDistinguisher} union type.
- *
*/
public final class RouteDistinguisherBuilder {
+ private static final Pattern[] PATTERNS = CodeHelpers.compilePatterns(RouteDistinguisher.PATTERN_CONSTANTS);
private RouteDistinguisherBuilder() {
throw new UnsupportedOperationException();
}
- private static final Pattern[] PATTERNS;
-
- static {
- final Pattern a[] = new Pattern[RouteDistinguisher.PATTERN_CONSTANTS.size()];
- int i = 0;
- for (final String regEx : RouteDistinguisher.PATTERN_CONSTANTS) {
- a[i++] = Pattern.compile(regEx);
- }
-
- PATTERNS = a;
- }
-
public static RouteDistinguisher getDefaultInstance(final String defaultValue) {
if (anyMatch(defaultValue)) {
return new RouteDistinguisher(defaultValue);
- } else {
- throw new IllegalArgumentException("Cannot create RouteDistinguisher from " + defaultValue);
}
+ throw new IllegalArgumentException("Cannot create RouteDistinguisher from " + defaultValue);
}
private static boolean anyMatch(final String defaultValue) {