Android Open Source - simpleprovider Utils






From Project

Back to project page simpleprovider.

License

The source code is released under:

MIT License

If you think the Android project simpleprovider listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package de.triplet.simpleprovider;
//from  w  w  w  . j av  a2  s  .c o  m
import android.text.TextUtils;

import java.lang.reflect.Field;

final class Utils {

    private Utils() {
        /* Utility classes must not have a public constructor */
    }

    static String getTableName(Class<?> clazz, Table table) {
        String value = table.value();
        if (TextUtils.isEmpty(value)) {
            return pluralize(clazz.getSimpleName());
        } else {
            return value;
        }
    }

    static String pluralize(String string) {
        string = string.toLowerCase();

        if (string.endsWith("s")) {
            return string;
        } else if (string.endsWith("ay")) {
            return string.replaceAll("ay$", "ays");
        } else if (string.endsWith("ey")) {
            return string.replaceAll("ey$", "eys");
        } else if (string.endsWith("oy")) {
            return string.replaceAll("oy$", "oys");
        } else if (string.endsWith("uy")) {
            return string.replaceAll("uy$", "uys");
        } else if (string.endsWith("y")) {
            return string.replaceAll("y$", "ies");
        } else {
            return string + "s";
        }
    }

    static String getColumnConstraint(Field field, Column column) throws IllegalAccessException {
        return field.get(null) + " " + column.value()
                + (column.primaryKey() ? " PRIMARY KEY" : "")
                + (column.notNull() ? " NOT NULL" : "")
                + (column.unique() ? " UNIQUE" : "");
    }

}




Java Source Code List

de.triplet.simpleprovider.AbstractProvider.java
de.triplet.simpleprovider.Column.java
de.triplet.simpleprovider.SelectionBuilder.java
de.triplet.simpleprovider.SimpleSQLHelper.java
de.triplet.simpleprovider.Table.java
de.triplet.simpleprovider.Utils.java
de.triplet.simpleprovider.sample.BlogProvider.java
de.triplet.simpleprovider.sample.MainActivity.java