Remove DataContainer.getImplementedInterface()
[mdsal.git] / binding / mdsal-binding-spec-util / src / main / java / org / opendaylight / mdsal / binding / spec / naming / BindingMapping.java
index 118c6d374adcae2d843562d02a8a5b2ce81e1ac8..9b24225a4cd3082e56a5c01e1fcef41f14dc2b10 100644 (file)
@@ -24,6 +24,7 @@ import java.util.Set;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 import org.opendaylight.yangtools.yang.binding.Augmentable;
+import org.opendaylight.yangtools.yang.binding.DataContainer;
 import org.opendaylight.yangtools.yang.binding.Identifiable;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.common.QNameModule;
@@ -73,6 +74,26 @@ public final class BindingMapping {
      */
     public static final String IDENTIFIABLE_KEY_NAME = "key";
 
+    /**
+     * Name of {@link DataContainer#implementedInterface()}.
+     */
+    public static final String DATA_CONTAINER_IMPLEMENTED_INTERFACE_NAME = "implementedInterface";
+
+    /**
+     * Prefix for getter methods working on top of boolean.
+     */
+    public static final String BOOLEAN_GETTER_PREFIX = "is";
+
+    /**
+     * Prefix for normal getter methods.
+     */
+    public static final String GETTER_PREFIX = "get";
+
+    /**
+     * Prefix for non-null default wrapper methods. These methods always wrap a corresponding normal getter.
+     */
+    public static final String NONNULL_PREFIX = "nonnull";
+
     public static final String RPC_INPUT_SUFFIX = "Input";
     public static final String RPC_OUTPUT_SUFFIX = "Output";
 
@@ -185,6 +206,35 @@ public final class BindingMapping {
         return getMethodName(name.getLocalName());
     }
 
+    public static String getGetterPrefix(final boolean isBoolean) {
+        return isBoolean ? BOOLEAN_GETTER_PREFIX : GETTER_PREFIX;
+    }
+
+    public static String getGetterMethodName(final String localName, final boolean isBoolean) {
+        return getGetterPrefix(isBoolean) + toFirstUpper(getPropertyName(localName));
+    }
+
+    public static String getGetterMethodName(final QName name, final boolean isBoolean) {
+        return getGetterPrefix(isBoolean) + getGetterSuffix(name);
+    }
+
+    public static boolean isGetterMethodName(final String methodName) {
+        return methodName.startsWith(GETTER_PREFIX) || methodName.startsWith(BOOLEAN_GETTER_PREFIX);
+    }
+
+    public static String getGetterMethodForNonnull(final String methodName) {
+        checkArgument(isNonnullMethodName(methodName));
+        return GETTER_PREFIX + methodName.substring(NONNULL_PREFIX.length());
+    }
+
+    public static String getNonnullMethodName(final String localName) {
+        return NONNULL_PREFIX + toFirstUpper(getPropertyName(localName));
+    }
+
+    public static boolean isNonnullMethodName(final String methodName) {
+        return methodName.startsWith(NONNULL_PREFIX);
+    }
+
     public static String getGetterSuffix(final QName name) {
         checkArgument(name != null, "Name should not be null.");
         final String candidate = toFirstUpper(toCamelCase(name.getLocalName()));
@@ -213,12 +263,8 @@ public final class BindingMapping {
         if (rawString == null || rawString.isEmpty()) {
             return rawString;
         }
-        char firstChar = rawString.charAt(0);
-        if (firstChar >= '0' && firstChar <= '9') {
-            return "_" + rawString;
-        } else {
-            return rawString;
-        }
+        final char firstChar = rawString.charAt(0);
+        return firstChar >= '0' && firstChar <= '9' ? "_" + rawString : rawString;
     }
 
     /**