Example usage for java.lang.reflect Modifier isFinal

List of usage examples for java.lang.reflect Modifier isFinal

Introduction

In this page you can find the example usage for java.lang.reflect Modifier isFinal.

Prototype

public static boolean isFinal(int mod) 

Source Link

Document

Return true if the integer argument includes the final modifier, false otherwise.

Usage

From source file:Main.java

public static <T> ArrayList<HashMap<String, String>> prepareDataToSave(

        ArrayList<T> source, Class<T> classType)
        throws NoSuchMethodException, SecurityException, IllegalArgumentException, IllegalAccessException {

    ArrayList<HashMap<String, String>> destination = new ArrayList<HashMap<String, String>>();
    ArrayList<Field> savedFieds = new ArrayList<Field>();
    Field[] fields;//from   ww w . j  a  v  a  2  s.c  o  m
    Object value = null;
    HashMap<String, String> aux;
    Field auxField;

    fields = classType.getDeclaredFields();

    for (int j = 0; j < fields.length; j++) {

        Class<?> type = fields[j].getType();

        if (!(Modifier.isStatic(fields[j].getModifiers()) || Modifier.isFinal(fields[j].getModifiers())
                || type.isArray() || Collection.class.isAssignableFrom(type))) {

            savedFieds.add(fields[j]);

        }
    }

    if (classType == null || fields == null) {
        return null;
    }

    for (int i = 0; i < source.size(); i++) {
        aux = new HashMap<String, String>();

        for (int j = 0; j < savedFieds.size(); j++) {

            auxField = savedFieds.get(j);
            auxField.setAccessible(true);
            value = auxField.get(source.get(i));
            aux.put(auxField.getName(), value.toString());

        }

        destination.add(aux);
    }

    return destination;

}

From source file:SampleModifier.java

public static void printModifiers(Object o) {
    Class c = o.getClass();/*  w  w w  . j  av a 2  s  .c o m*/
    int m = c.getModifiers();
    if (Modifier.isPublic(m))
        System.out.println("public");
    if (Modifier.isAbstract(m))
        System.out.println("abstract");
    if (Modifier.isFinal(m))
        System.out.println("final");
}

From source file:org.force66.vobase.ValueObjectUtils.java

protected static void copyAllFields(Object source, Object target) {
    Validate.notNull(source, "Null source object fields can't be copied");
    Validate.notNull(target, "Null target object fields can't be copied");
    Validate.isTrue(ClassUtils.isAssignable(target.getClass(), source.getClass()),
            "Source and target classes must be assignable");

    Object value = null;//from w  ww  .  j a  va 2s .c o m
    for (Field field : FieldUtils.getAllFields(source.getClass())) {
        if (!Modifier.isFinal(field.getModifiers())) {
            value = copyField(source, target, value, field);
        }
    }
}

From source file:ReflectionUtils.java

/**
 * Determine whether the given field is a "public static final" constant.
 * @param field the field to check//from w w  w.  ja  va  2s.  c om
 */
public static boolean isPublicStaticFinal(Field field) {
    int modifiers = field.getModifiers();
    return (Modifier.isPublic(modifiers) && Modifier.isStatic(modifiers) && Modifier.isFinal(modifiers));
}

From source file:org.rhq.coregui.server.gwt.ObjectFilter.java

public static <T> T filterFields(T object, Set<String> goodFields) {
    try {//from   ww w  .  j  a  v a2 s .  c om
        Field[] fields = Resource.class.getDeclaredFields();
        for (Field f : fields) {
            if (!Modifier.isFinal(f.getModifiers())) {
                if (!goodFields.contains(f.getName())) {
                    // Only clearing objects, no point in clearing primitives as it
                    // doesn't save any space on the stream
                    if (!f.getType().isPrimitive()) {
                        if (log.isDebugEnabled()) {
                            log.debug("Clearing " + f.getName() + "...");
                        }
                        f.setAccessible(true);
                        f.set(object, null);
                    } else {
                        if (log.isDebugEnabled()) {
                            log.debug("Can't do " + f.getType());
                        }
                    }
                }
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }

    return object;
}

From source file:com.lucidtechnics.blackboard.TargetConstructor.java

public static final boolean canConstructTarget(Class _class) {
    boolean isFinal = Modifier.isFinal(_class.getModifiers());
    boolean isArray = _class.isArray();
    boolean isEnum = _class.isEnum();

    return (isFinal == false && isArray == false && isEnum == false);
}

From source file:Main.java

/**
 * Converts a color into a string. If the color is equal to one of the defined
 * constant colors, that name is returned instead. Otherwise the color is
 * returned as hex-string./*from  www.  j  ava 2 s .co m*/
 * 
 * @param c
 *          the color.
 * @return the string for this color.
 */
public static String colorToString(final Color c) {
    try {
        final Field[] fields = Color.class.getFields();
        for (int i = 0; i < fields.length; i++) {
            final Field f = fields[i];
            if (Modifier.isPublic(f.getModifiers()) && Modifier.isFinal(f.getModifiers())
                    && Modifier.isStatic(f.getModifiers())) {
                final String name = f.getName();
                final Object oColor = f.get(null);
                if (oColor instanceof Color) {
                    if (c.equals(oColor)) {
                        return name;
                    }
                }
            }
        }
    } catch (Exception e) {
        //
    }

    // no defined constant color, so this must be a user defined color
    final String color = Integer.toHexString(c.getRGB() & 0x00ffffff);
    final StringBuffer retval = new StringBuffer(7);
    retval.append("#");

    final int fillUp = 6 - color.length();
    for (int i = 0; i < fillUp; i++) {
        retval.append("0");
    }

    retval.append(color);
    return retval.toString();
}

From source file:org.jiemamy.utils.reflect.ModifierUtil.java

/**
 * {@code final}???????/* w w w .jav  a2s  .  c  om*/
 * 
 * @param member 
 * @return {@code final}????{@code true}?????????{@code false}
 * @throws IllegalArgumentException ?{@code null}???
 */
public static boolean isFinal(Member member) {
    Validate.notNull(member);
    return Modifier.isFinal(member.getModifiers());
}

From source file:org.lanternpowered.server.util.ReflectionHelper.java

public static void setField(Field field, @Nullable Object target, @Nullable Object object) throws Exception {
    final int modifiers = field.getModifiers();
    if (Modifier.isFinal(modifiers)) {
        MODIFIERS_FIELD.set(field, modifiers & ~Modifier.FINAL);
    }//from  w ww  .ja va2 s  .c om
    field.setAccessible(true);
    field.set(target, object);
}

From source file:de.codesourcery.eve.apiclient.cache.FilesystemResponseCacheTest.java

private static Method findMethod(Class<?> clasz, String name) {
    for (Method m : clasz.getDeclaredMethods()) {
        final int mods = m.getModifiers();

        if (Modifier.isStatic(mods) || Modifier.isFinal(mods)) {
            continue;
        }/*www.  j av  a  2  s .  co m*/

        if (m.getName().equals(name)) {
            return m;
        }
    }
    return null;
}