X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fcds-access-api%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fcluster%2Faccess%2Fconcepts%2FFrontendType.java;h=2a2a5b2b30af2d26bd4c39e75844401611d32129;hp=806a7ad104c6881b43a728c08facf9c193331704;hb=refs%2Fchanges%2F73%2F85373%2F8;hpb=a06a30a33507689464c736cb37c26445f232280e diff --git a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/concepts/FrontendType.java b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/concepts/FrontendType.java index 806a7ad104..2a2a5b2b30 100644 --- a/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/concepts/FrontendType.java +++ b/opendaylight/md-sal/cds-access-api/src/main/java/org/opendaylight/controller/cluster/access/concepts/FrontendType.java @@ -7,11 +7,14 @@ */ package org.opendaylight.controller.cluster.access.concepts; +import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.base.Verify.verifyNotNull; +import static java.util.Objects.requireNonNull; + import com.google.common.annotations.Beta; import com.google.common.base.MoreObjects; -import com.google.common.base.Preconditions; import com.google.common.base.Strings; -import com.google.common.base.Verify; +import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import java.io.DataInput; import java.io.DataOutput; import java.io.Externalizable; @@ -20,7 +23,9 @@ import java.io.ObjectInput; import java.io.ObjectOutput; import java.nio.charset.StandardCharsets; import java.util.regex.Pattern; +import org.eclipse.jdt.annotation.NonNull; import org.opendaylight.yangtools.concepts.Identifier; +import org.opendaylight.yangtools.concepts.WritableIdentifier; /** * An {@link Identifier} identifying a data store frontend type, which is able to access the data store backend. @@ -30,17 +35,20 @@ import org.opendaylight.yangtools.concepts.Identifier; * @author Robert Varga */ @Beta -public final class FrontendType implements Comparable, Identifier, WritableObject { +public final class FrontendType implements Comparable, WritableIdentifier { private static final class Proxy implements Externalizable { private static final long serialVersionUID = 1L; private byte[] serialized; + // checkstyle flags the public modifier as redundant however it is explicitly needed for Java serialization to + // be able to create instances via reflection. + @SuppressWarnings("checkstyle:RedundantModifier") public Proxy() { // For Externalizable } Proxy(final byte[] serialized) { - this.serialized = Preconditions.checkNotNull(serialized); + this.serialized = requireNonNull(serialized); } @Override @@ -61,36 +69,43 @@ public final class FrontendType implements Comparable, Identifier, } } - private static final Pattern SIMPLE_STRING_PATTERN = Pattern.compile("^[a-zA-Z-_.*+:=,!~';]+$"); + private static final String SIMPLE_STRING_REGEX = "^[a-zA-Z0-9-_.*+:=,!~';]+$"; + private static final Pattern SIMPLE_STRING_PATTERN = Pattern.compile(SIMPLE_STRING_REGEX); private static final long serialVersionUID = 1L; - private final String name; + + private final @NonNull String name; + + @SuppressFBWarnings(value = "VO_VOLATILE_REFERENCE_TO_ARRAY", + justification = "The array elements are non-volatile but we don't access them.") private volatile byte[] serialized; private FrontendType(final String name) { - this.name = Preconditions.checkNotNull(name); + this.name = requireNonNull(name); } FrontendType(final String name, final byte[] serialized) { this(name); - this.serialized = Verify.verifyNotNull(serialized); + this.serialized = verifyNotNull(serialized); } /** * Return a {@link FrontendType} corresponding to a string representation. Input string has constraints * on what characters it can contain. It may contain the following: - * - US-ASCII letters + * - US-ASCII letters and numbers * - special characters: -_.*+:=,!~'; * + * @param name the input name * @return A {@link FrontendType} instance * @throws IllegalArgumentException if the string is null, empty or contains invalid characters */ - public static FrontendType forName(final String name) { - Preconditions.checkArgument(!Strings.isNullOrEmpty(name)); - Preconditions.checkArgument(SIMPLE_STRING_PATTERN.matcher(name).matches()); + public static @NonNull FrontendType forName(final String name) { + checkArgument(!Strings.isNullOrEmpty(name)); + checkArgument(SIMPLE_STRING_PATTERN.matcher(name).matches(), + "Supplied name %s does not patch pattern %s", name, SIMPLE_STRING_REGEX); return new FrontendType(name); } - public static FrontendType readFrom(final DataInput in) throws IOException { + public static @NonNull FrontendType readFrom(final DataInput in) throws IOException { final byte[] serialized = new byte[in.readInt()]; in.readFully(serialized); return new FrontendType(new String(serialized, StandardCharsets.UTF_8)); @@ -98,28 +113,34 @@ public final class FrontendType implements Comparable, Identifier, @Override public void writeTo(final DataOutput out) throws IOException { - final byte[] serialized = getSerialized(); - out.writeInt(serialized.length); - out.write(serialized); + final byte[] local = getSerialized(); + out.writeInt(local.length); + out.write(local); } - public String getName() { + public @NonNull String getName() { return name; } + public org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.cds.types.rev191024 + . @NonNull FrontendType toYang() { + return new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.cds.types.rev191024 + .FrontendType(name); + } + @Override public int hashCode() { return name.hashCode(); } @Override - public boolean equals(final Object o) { - return this == o || (o instanceof FrontendType && name.equals(((FrontendType)o).name)); + public boolean equals(final Object obj) { + return this == obj || obj instanceof FrontendType && name.equals(((FrontendType)obj).name); } @Override - public int compareTo(final FrontendType o) { - return this == o ? 0 : name.compareTo(o.name); + public int compareTo(final FrontendType obj) { + return this == obj ? 0 : name.compareTo(obj.name); } @Override