Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Apache License 

import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.Locale;
import android.util.Log;

public class Main {
    private static Method getColumnSetMethod(Class<?> entityType, Field field, Class<?> typeClass, String suffix) {
        String fieldName = field.getName();
        Method setMethod = null;
        if (field.getType() == boolean.class) {
            setMethod = getBooleanColumnSetMethod(entityType, field, typeClass, suffix);
        }
        if (setMethod == null) {
            String methodName = "set" + fieldName.substring(0, 1).toUpperCase(Locale.getDefault())
                    + fieldName.substring(1) + suffix;
            try {
                setMethod = entityType.getDeclaredMethod(methodName, typeClass);
            } catch (NoSuchMethodException e) {
                Log.d("T", methodName + " not exist");
            }
        }
        return setMethod;
    }

    private static Method getBooleanColumnSetMethod(Class<?> entityType, Field field, Class<?> typeClass,
            String suffix) {
        String fieldName = field.getName();
        String methodName = null;
        if (isStartWithIs(field.getName())) {
            methodName = "set" + fieldName.substring(2, 3).toUpperCase(Locale.getDefault()) + fieldName.substring(3)
                    + suffix;
        } else {
            methodName = "set" + fieldName.substring(0, 1).toUpperCase(Locale.getDefault()) + fieldName.substring(1)
                    + suffix;
        }
        try {
            return entityType.getDeclaredMethod(methodName, typeClass);
        } catch (NoSuchMethodException e) {
            Log.d("L", methodName + " not exist");
        }
        return null;
    }

    private static boolean isStartWithIs(final String fieldName) {
        return fieldName != null && fieldName.startsWith("is");
    }
}