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 boolean isBroadcastFilter(Object filter) {
    return ReceiverList$receiver != null && BroadcastFilter.isAssignableFrom(filter.getClass());
}

From source file:Main.java

public static <T> T unsupported(final String op, final Object... a) {
    final StringBuilder msg = new StringBuilder(INITIAL_SIZE);
    msg.append("Nobody told me how to run ");
    msg.append(op);//  w w  w.  jav  a 2 s .  com
    if (a.length > 0) {
        msg.append(" with parameters of class: ");
        for (final Object o : a) {
            msg.append(o == null ? "null" : o.getClass().getSimpleName());
            msg.append(", ");
        }
        msg.delete(msg.length() - 2, msg.length());
        msg.append('.');
    }
    throw new UnsupportedOperationException(msg.toString());
}

From source file:Main.java

public static void setProperty(Object o, String field, Object value) {
    try {// www. j a va2s. co m
        Field f = o.getClass().getDeclaredField(field);
        f.setAccessible(true);
        f.set(o, value);
    } catch (Exception e) {
        e.printStackTrace();
    }

}

From source file:Main.java

public static boolean isString(Object object) {
    return isSubclassOf(object.getClass(), PRIMITIVE_TYPE_STRING);
}

From source file:org.openmrs.module.jmx.util.MBeanProxifier.java

/**
 * Finds the MBean interface of the given object by searching for the MXBean annotation
 * @param mbean the object//from  w ww .  j a  v a  2s. c om
 * @return the interface
 */
public static Class<?> getMBeanInterface(Object mbean) {
    Class<?>[] interfaces = mbean.getClass().getInterfaces();
    for (Class<?> intf : interfaces) {
        MXBean annotation = intf.getAnnotation(MXBean.class);
        if (annotation != null && annotation.value())
            return intf;
    }
    return null;
}

From source file:Main.java

public static Object readJavaObject(Connection conn, long id) throws Exception {
    PreparedStatement pstmt = conn.prepareStatement(READ_OBJECT_SQL);
    pstmt.setLong(1, id);//from  w ww .j  a  v a 2 s .co  m
    ResultSet rs = pstmt.executeQuery();
    rs.next();
    Object object = rs.getObject("object_value");
    String className = object.getClass().getName();
    rs.close();
    pstmt.close();
    return object;
}

From source file:Main.java

public static byte[] serializerBytes(Object xmlObj) throws JAXBException {
    JAXBContext context = JAXBContext.newInstance(xmlObj.getClass());
    Marshaller marshaller = context.createMarshaller();
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    marshaller.marshal(xmlObj, baos);//from   w ww.j  ava  2s.c o m
    return baos.toByteArray();
}

From source file:Main.java

/**
 * Returns a rounded off number. If the value class is not Double, the value
 * is returned unchanged./*from w  w w.ja v  a2s  .  com*/
 *
 * @param value the value to return and potentially round off.
 */
public static Object getRoundedObject(Object value) {
    return value != null && Double.class.equals(value.getClass()) ? getRounded((Double) value) : value;
}

From source file:Main.java

/**
 * Object to XML//from   www  .  j  a v a 2s  .c om
 * @param object
 * @return
 */
public static String convertToXML(Object object) {
    try {
        if (!mMap.containsKey(object.getClass())) {
            JAXBContext jaxbContext = JAXBContext.newInstance(object.getClass());
            Marshaller marshaller = jaxbContext.createMarshaller();
            marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
            mMap.put(object.getClass(), marshaller);
        }
        StringWriter stringWriter = new StringWriter();
        mMap.get(object.getClass()).marshal(object, stringWriter);
        return stringWriter.getBuffer().toString();
    } catch (JAXBException e) {
        e.printStackTrace();
    }
    return null;
}

From source file:Main.java

public static String shortClassName(Object obj) {
    if (obj == null)
        return "null";
    return shortClassName(obj.getClass());
}