Fix CS warnings in cds-access-api and enable enforcement
[controller.git] / opendaylight / md-sal / cds-access-api / src / main / java / org / opendaylight / controller / cluster / access / concepts / FrontendType.java
index 806a7ad104c6881b43a728c08facf9c193331704..b58e24087484bca7616275a440e462a791f657d2 100644 (file)
@@ -20,7 +20,9 @@ import java.io.ObjectInput;
 import java.io.ObjectOutput;
 import java.nio.charset.StandardCharsets;
 import java.util.regex.Pattern;
+import javax.annotation.RegEx;
 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,11 +32,14 @@ import org.opendaylight.yangtools.concepts.Identifier;
  * @author Robert Varga
  */
 @Beta
-public final class FrontendType implements Comparable<FrontendType>, Identifier, WritableObject {
+public final class FrontendType implements Comparable<FrontendType>, 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
         }
@@ -61,7 +66,9 @@ public final class FrontendType implements Comparable<FrontendType>, Identifier,
         }
     }
 
-    private static final Pattern SIMPLE_STRING_PATTERN = Pattern.compile("^[a-zA-Z-_.*+:=,!~';]+$");
+    @RegEx
+    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 volatile byte[] serialized;
@@ -78,15 +85,17 @@ public final class FrontendType implements Comparable<FrontendType>, Identifier,
     /**
      * 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());
+        Preconditions.checkArgument(SIMPLE_STRING_PATTERN.matcher(name).matches(),
+            "Supplied name %s does not patch pattern %s", name, SIMPLE_STRING_REGEX);
         return new FrontendType(name);
     }
 
@@ -98,9 +107,9 @@ public final class FrontendType implements Comparable<FrontendType>, 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() {
@@ -113,13 +122,13 @@ public final class FrontendType implements Comparable<FrontendType>, Identifier,
     }
 
     @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