Simplify exception instantiation 91/86091/4
authorRobert Varga <robert.varga@pantheon.tech>
Mon, 2 Dec 2019 01:49:07 +0000 (02:49 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Mon, 2 Dec 2019 11:20:08 +0000 (12:20 +0100)
There is no point in splitting message format, turn a static utility
method to a direct constructor.

Change-Id: I630fa4742f717abe4be021f86d8d78ff76679ef4
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
library/impl/src/main/java/org/opendaylight/ovsdb/lib/error/ColumnSchemaNotFoundException.java
library/impl/src/main/java/org/opendaylight/ovsdb/lib/error/TableSchemaNotFoundException.java
library/impl/src/main/java/org/opendaylight/ovsdb/lib/schema/typed/TypedRowInvocationHandler.java

index 7a19226193245943f7b9612469a49cb048589296..ba8a05da85dcc61203251cc8dbab185878e3c5d0 100644 (file)
@@ -17,11 +17,11 @@ public class ColumnSchemaNotFoundException extends RuntimeException {
         super(message);
     }
 
-    public ColumnSchemaNotFoundException(final String message, final Throwable cause) {
-        super(message, cause);
+    public ColumnSchemaNotFoundException(final String columnName, final String tableName) {
+        this("Unable to locate ColumnSchema for " +  columnName + " in " + tableName);
     }
 
-    public static String createMessage(final String columnName, final String tableName) {
-        return "Unable to locate ColumnSchema for " +  columnName + " in " + tableName;
+    public ColumnSchemaNotFoundException(final String message, final Throwable cause) {
+        super(message, cause);
     }
 }
index 1b817ca1640c1b5d80eb78d024d24a55b9336885..7c05ccd84cae466af4741e673a06faad79a5f5b4 100644 (file)
@@ -17,11 +17,11 @@ public class TableSchemaNotFoundException extends RuntimeException {
         super(message);
     }
 
-    public TableSchemaNotFoundException(final String message, final Throwable cause) {
-        super(message, cause);
+    public TableSchemaNotFoundException(final String tableName, final String schemaName) {
+        this("Unable to locate TableSchema for " +  tableName + " in " + schemaName);
     }
 
-    public static String createMessage(final String tableName, final String schemaName) {
-        return "Unable to locate TableSchema for " +  tableName + " in " + schemaName;
+    public TableSchemaNotFoundException(final String message, final Throwable cause) {
+        super(message, cause);
     }
 }
index 27f1d4f44b00fe9ce3f8dd0b70067109c417e3d8..f8b96a6d10db4a131ab8d9cc2a08b57f196d093f 100644 (file)
@@ -48,15 +48,12 @@ final class TypedRowInvocationHandler implements InvocationHandler {
         }
         GenericTableSchema tableSchema = TyperUtils.getTableSchema(dbSchema, target);
         if (tableSchema == null) {
-            String message = TableSchemaNotFoundException.createMessage(TypedReflections.getTableName(target),
-                        dbSchema.getName());
-            throw new TableSchemaNotFoundException(message);
+            throw new TableSchemaNotFoundException(TypedReflections.getTableName(target), dbSchema.getName());
         }
         ColumnSchema<GenericTableSchema, Object> columnSchema =
                 TyperUtils.getColumnSchema(tableSchema, columnName, (Class<Object>) method.getReturnType());
         if (columnSchema == null) {
-            String message = ColumnSchemaNotFoundException.createMessage(columnName, tableSchema.getName());
-            throw new ColumnSchemaNotFoundException(message);
+            throw new ColumnSchemaNotFoundException(columnName, tableSchema.getName());
         }
         if (row == null || row.getColumn(columnSchema) == null) {
             return null;
@@ -76,15 +73,12 @@ final class TypedRowInvocationHandler implements InvocationHandler {
         }
         GenericTableSchema tableSchema = TyperUtils.getTableSchema(dbSchema, target);
         if (tableSchema == null) {
-            String message = TableSchemaNotFoundException.createMessage(TypedReflections.getTableName(target),
-                dbSchema.getName());
-            throw new TableSchemaNotFoundException(message);
+            throw new TableSchemaNotFoundException(TypedReflections.getTableName(target), dbSchema.getName());
         }
         ColumnSchema<GenericTableSchema, Object> columnSchema =
                 TyperUtils.getColumnSchema(tableSchema, columnName, (Class<Object>) method.getReturnType());
         if (columnSchema == null) {
-            String message = ColumnSchemaNotFoundException.createMessage(columnName, tableSchema.getName());
-            throw new ColumnSchemaNotFoundException(message);
+            throw new ColumnSchemaNotFoundException(columnName, tableSchema.getName());
         }
         // When the row is null, that might indicate that the user maybe interested
         // only in the ColumnSchema and not on the Data.