package org.opendaylight.ovsdb.lib.schema.typed;
+import com.google.common.base.Preconditions;
+import com.google.common.reflect.Reflection;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;
-
import org.opendaylight.ovsdb.lib.error.ColumnSchemaNotFoundException;
import org.opendaylight.ovsdb.lib.error.SchemaVersionMismatchException;
import org.opendaylight.ovsdb.lib.error.TableSchemaNotFoundException;
import org.opendaylight.ovsdb.lib.schema.GenericTableSchema;
import org.opendaylight.ovsdb.lib.schema.TableSchema;
-import com.google.common.base.Preconditions;
-import com.google.common.reflect.Reflection;
-
public class TyperUtils {
+
private static final String GET_STARTS_WITH = "get";
private static final String SET_STARTS_WITH = "set";
private static final String GETCOLUMN_ENDS_WITH = "Column";
}
/**
- * This method returns a Typed Proxy implementation for the klazz passed as a parameter.
+ * Returns a Typed Proxy implementation for the klazz passed as a parameter.
* Per design choice, the Typed Proxy implementation is just a Wrapper on top of the actual
* Row which is untyped.
- * Being just a wrapper, it is state-less and more of a convenience functionality to
+ *
+ * <p>Being just a wrapper, it is state-less and more of a convenience functionality to
* provide a type-safe infrastructure for the applications to built on top of.
* And this Typed infra is completely optional.
*
- * It is the applications responsibility to pass on the raw Row parameter and this method will
+ * <p>It is the applications responsibility to pass on the raw Row parameter and this method will
* return the appropriate Proxy wrapper for the passed klazz Type.
* The raw Row parameter may be null if the caller is interested in just the ColumnSchema.
* But that is not a very common use-case.
*
* @param dbSchema DatabaseSchema as learnt from a OVSDB connection
* @param klazz Typed Class that represents a Table
- * @return
*/
public static <T> T getTypedRowWrapper(final DatabaseSchema dbSchema, final Class<T> klazz) {
return getTypedRowWrapper(dbSchema, klazz,new Row<GenericTableSchema>());
}
/**
- * This method returns a Typed Proxy implementation for the klazz passed as a parameter.
+ * Returns a Typed Proxy implementation for the klazz passed as a parameter.
* Per design choice, the Typed Proxy implementation is just a Wrapper on top of the actual
* Row which is untyped.
- * Being just a wrapper, it is state-less and more of a convenience functionality
+ *
+ * <p>Being just a wrapper, it is state-less and more of a convenience functionality
* to provide a type-safe infrastructure for the applications to built on top of.
* And this Typed infra is completely optional.
*
- * It is the applications responsibility to pass on the raw Row parameter and this method
+ * <p>It is the applications responsibility to pass on the raw Row parameter and this method
* will return the appropriate Proxy wrapper for the passed klazz Type.
* The raw Row parameter may be null if the caller is interested in just the
* ColumnSchema. But that is not a very common use-case.
* @param klazz Typed Class that represents a Table
* @param row The actual Row that the wrapper is operating on. It can be null if the caller
* is just interested in getting ColumnSchema.
- * @return
*/
public static <T> T getTypedRowWrapper(final DatabaseSchema dbSchema, final Class<T> klazz,
final Row<GenericTableSchema> row) {
private Boolean isHashCodeMethod(Method method, Object[] args) {
return (args == null || args.length == 0) && method.getName().equals("hashCode");
}
+
private Boolean isEqualsMethod(Method method, Object[] args) {
return (args != null
&& args.length == 1
&& method.getName().equals("equals")
&& Object.class.equals(method.getParameterTypes()[0]));
}
+
private Boolean isToStringMethod(Method method, Object[] args) {
return (args == null || args.length == 0) && method.getName().equals("toString");
}
+
@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
if (isGetTableSchema(method)) {
/**
* This method extracts all row updates of Class<T> klazz from a TableUpdates
- * that correspond to old version of rows of type klazz that have been updated
+ * that correspond to old version of rows of type klazz that have been updated.
* Example:
* <code>
* Map<UUID,Bridge> oldBridges = extractRowsOld(Bridge.class,updates,dbSchema)
* @param dbSchema Dbschema for the TableUpdates
* @return Map<UUID,T> for the type of things being sought
*/
- public static <T> Map<UUID,T> extractRowsOld(Class<T> klazz,TableUpdates updates,DatabaseSchema dbSchema) {
+ public static <T> Map<UUID, T> extractRowsOld(Class<T> klazz, TableUpdates updates, DatabaseSchema dbSchema) {
Preconditions.checkNotNull(klazz);
Preconditions.checkNotNull(updates);
Preconditions.checkNotNull(dbSchema);