Example usage for java.lang Object getClass

List of usage examples for java.lang Object getClass

Introduction

In this page you can find the example usage for java.lang Object getClass.

Prototype

@HotSpotIntrinsicCandidate
public final native Class<?> getClass();

Source Link

Document

Returns the runtime class of this Object .

Usage

From source file:Main.java

public static final int getIntValue(Object classObject, String paramString, int paramInt) {
    setClass(classObject.getClass().getName());
    Field localField = getField(paramString);
    if (localField != null) {
        return paramInt;
    } else {/*from  w  ww  .  j  av a2s .c o m*/
        try {
            paramInt = localField.getInt(classObject);
            return paramInt;
        } catch (IllegalArgumentException var5) {
            return paramInt;
        } catch (IllegalAccessException var6) {
            return paramInt;
        }
    }
}

From source file:Main.java

private static List<Object> createParamsArray(Method m, List<Object> availableParams) {
    List<Object> params = new ArrayList<Object>();
    Class<?>[] paramTypes = m.getParameterTypes();

    for (Class<?> type : paramTypes) {
        for (Object param : availableParams) {
            if (param != null && type.isAssignableFrom(param.getClass())) {
                params.add(param);/*from   w  w w. j  ava 2s  .c om*/
            }
        }
    }

    return params;
}

From source file:Main.java

/**
 * Warn./*from   w  w w .ja v a2 s.  c o  m*/
 *
 * @param object the object
 * @param e      the e
 */
public static void warn(Object object, Throwable e) {
    warn(object.getClass().getSimpleName(), toStackTraceString(e));
}

From source file:io.appform.nautilus.funnel.utils.AttributeUtils.java

public static boolean isValid(Map<String, Object> attributes) {
    if (null == attributes) {
        return true;
    }/*  www  . j a  v a2 s  .c o  m*/
    final boolean[] valid = { true };
    attributes.entrySet().forEach(entry -> {
        if (!entry.getKey().equals("location")) {
            Object value = entry.getValue();
            final Class<?> clazz = value.getClass();
            valid[0] &= (!entry.getKey().matches(Constants.FIELD_REPLACEMENT_VALUE)
                    && !ClassUtils.isPrimitiveOrWrapper(clazz) && !(value instanceof String));
        }

    });
    return valid[0];
}

From source file:Main.java

/**
 * Gets the elements of received type within the received list.
 * /*  w  ww .  j ava2  s .c o  m*/
 * @param pList
 *            the list
 * @param pType
 *            the type to search for
 * 
 * @return the elements of the received type
 */
@SuppressWarnings("unchecked")
public static <C> List<C> getElementsOfType(final Collection<?> pList, final Class<C> pType) {
    final List<C> list = new ArrayList<C>();

    if (pList != null && pList.size() > 0) {
        synchronized (pList) {
            for (final Object obj : pList) {
                if (pType.isAssignableFrom(obj.getClass())) {
                    list.add((C) obj);
                }
            }
        }
    }

    return list;
}

From source file:Main.java

public static void callMethod(Object obj, String method, Object... params) {
    Method[] ms = obj.getClass().getMethods();
    for (Method m : ms) {
        if (!m.getName().equals(method))
            continue;
        // TODO check type args
        Class<?>[] types = m.getParameterTypes();
        if (params.length != types.length)
            continue;
        for (int i = 0; i < params.length; i++) {

        }//from  ww w .  j  a  v a  2s.c o  m
        // call
        try {
            m.invoke(obj, params);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
    throw new RuntimeException(obj + "." + method + "(" + params.length + ")");
}

From source file:Main.java

public static List<String> collectAsString(List<? extends Object> objects, String fieldName) {

    List<String> stringsAsAttribute = new ArrayList<String>();

    String getterName = "get" + Character.toUpperCase(fieldName.charAt(0))
            + fieldName.substring(1, fieldName.length());
    try {//from  w  w  w.  j  a  v a2  s .c  om

        for (Object object : objects) {
            Method getterMethod = object.getClass().getMethod(getterName);
            Object result = getterMethod.invoke(object);
            stringsAsAttribute.add(result.toString());
        }

    } catch (NoSuchMethodException e) {
        e.printStackTrace();
    } catch (IllegalArgumentException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IllegalAccessException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (InvocationTargetException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    return stringsAsAttribute;
}

From source file:FieldModification.java

/** 
 * Sets all int fields in an object to 0.
 *
 * @param obj The object to operate on.//  w  ww  .j a  v  a 2s .c o  m
 *
 * @throws RuntimeException If there is a reflection problem.
 */
public static void initPublicIntFields(final Object obj) {
    try {
        Field[] fields = obj.getClass().getFields();
        for (int idx = 0; idx < fields.length; idx++) {
            if (fields[idx].getType() == int.class) {
                fields[idx].setInt(obj, 0);
            }
        }
    } catch (final IllegalAccessException ex) {
        throw new RuntimeException(ex);
    }
}

From source file:Main.java

public static boolean isSerializable(Object obj) {
    Class<?> clz = obj.getClass();

    return clz.isPrimitive() || primitives.contains(clz) || obj instanceof String || obj instanceof Map
            || obj instanceof JSONArray || obj instanceof JSONObject;
}

From source file:Main.java

/**
 * Error.//from  ww  w.  j av  a 2  s.com
 *
 * @param object the object
 * @param e      the e
 */
public static void error(Object object, Throwable e) {
    error(object.getClass().getSimpleName(), toStackTraceString(e));
}