Returns COLUMN_ fields from contract obj. - Android android.accounts

Android examples for android.accounts:Account

Description

Returns COLUMN_ fields from contract obj.

Demo Code


//package com.java2s;

import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.util.ArrayList;
import java.util.List;

public class Main {
    /**/*from   w w w . j  av a2 s  .  co m*/
     * Returns COLUMN_ fields from contract obj.
     * @param contract Database contract class.
     */
    public static List<String> getColumns(Class contract) {
        List<String> columns = new ArrayList<>();
        Field[] allFields = contract.getFields();
        for (Field f : allFields) {
            final int m = f.getModifiers();
            if (Modifier.isPublic(m) && Modifier.isStatic(m)
                    && Modifier.isFinal(m)
                    && f.getName().startsWith("COLUMN_")) {
                try {
                    columns.add((String) f.get(contract));
                } catch (IllegalAccessException e) {
                    throw new IllegalStateException(e);
                }
            }
        }
        return columns;
    }
}

Related Tutorials