List of usage examples for java.lang Object getClass
@HotSpotIntrinsicCandidate public final native Class<?> getClass();
From source file:Main.java
public static int untetherIface(Context context, String iface) { int returnCode = -1; Object connectivityManager = context.getSystemService(Context.CONNECTIVITY_SERVICE); Method untether = null;/*from w ww. j ava 2s . co m*/ try { untether = connectivityManager.getClass().getMethod("untether", new Class[] { String.class }); } catch (Exception e) { e.printStackTrace(); } try { returnCode = (Integer) untether.invoke(connectivityManager, new Object[] { iface }); } catch (Exception e) { e.printStackTrace(); } return returnCode; }
From source file:ArrayExpander.java
public static Object expand(Object array, int newSize) { if (array == null) { return null; }/*from www . j a v a 2 s . c om*/ Class c = array.getClass(); if (c.isArray()) { int len = Array.getLength(array); if (len >= newSize) { return array; } else { Class cc = c.getComponentType(); Object newArray = Array.newInstance(cc, newSize); System.arraycopy(array, 0, newArray, 0, len); return newArray; } } else { throw new ClassCastException("need array"); } }
From source file:ArrayExpander.java
public static Object expandAtHead(Object array, int newSize) { if (array == null) { return null; }// w w w .j a v a2 s . co m Class c = array.getClass(); if (c.isArray()) { int len = Array.getLength(array); if (len >= newSize) { return array; } else { Class cc = c.getComponentType(); Object newArray = Array.newInstance(cc, newSize); System.arraycopy(array, 0, newArray, newSize - len, len); return newArray; } } else { throw new ClassCastException("need array"); } }
From source file:Main.java
/** Constructs a JButton with an icon from the given file id. */ public static JButton makeButton(final Object owner, final String id, final String altText, final int wpad, final int hpad) { final URL url = owner.getClass().getResource(id); ImageIcon icon = null;/*from ww w .j av a 2 s . c o m*/ if (url != null) icon = new ImageIcon(url); JButton button; if (icon == null) button = new JButton(altText); else { button = new JButton(icon); button.setPreferredSize(new Dimension(icon.getIconWidth() + wpad, icon.getIconHeight() + hpad)); } return button; }
From source file:ch.algotrader.util.FieldUtil.java
/** * copies all field values by direct field access. *//* ww w . j ava2 s .co m*/ public static void copyAllFields(Object source, Object target) { for (Field field : FieldUtil.getAllFields(target.getClass())) { try { Object targetValue = FieldUtils.readField(field, source, true); FieldUtils.writeField(field, target, targetValue, true); } catch (IllegalAccessException e) { LOGGER.error("problem copying field", e); } } }
From source file:edu.cornell.mannlib.vitro.webapp.utils.logging.ToString.java
public static boolean isVitroClass(Object o) { return (o == null) ? false : o.getClass().getName().startsWith("edu.cornell"); }
From source file:io.neba.core.util.JsonUtil.java
private static String toJson(Object value) { if (value == null) { return "\"\""; }// w ww.java2s . c o m if (!value.getClass().isArray() && (value.getClass().isPrimitive() || wrapperToPrimitive(value.getClass()) != null)) { return Objects.toString(value); } if (value instanceof String) { return '"' + ((String) value).replaceAll("\"", "\\\\\"") + '"'; } if (value instanceof Collection) { return toJson((Collection) value); } if (value instanceof Map) { return toJson((Map<?, ?>) value); } throw new IllegalArgumentException("Cannot convert value " + value + " to JSON."); }
From source file:me.hurel.hqlbuilder.internal.ProxyUtil.java
public static boolean usePrimitive(Object o) { return boolean.class.equals(o.getClass()) || o instanceof Boolean || o instanceof Date; }
From source file:Main.java
public static <I, P extends I> Method findMethod(final Object obj, final String name, final P param, final Class<I> type) throws NoSuchMethodException { Class<?> c = obj.getClass(); while (c != null && c != Object.class) { try {/*from w w w . j a v a 2 s. co m*/ return c.getDeclaredMethod(name, type); } catch (final Exception e) { } c = c.getSuperclass(); } throw new NoSuchMethodException(); }
From source file:Main.java
/** * Print class name and its parent name of an object * * @param obj/* w w w . ja v a 2s . c om*/ */ public final static String getClassInheritence(Object obj) { if (obj == null) { return null; } StringBuilder stb = new StringBuilder(); Class<?> cls = obj.getClass(); String name = cls.getSimpleName(); stb.append("["); stb.append(String.valueOf(obj)); stb.append(":"); while (!name.toLowerCase().equals("object")) { stb.append(name); stb.append("<-"); cls = cls.getSuperclass(); name = cls.getSimpleName(); } stb.append("]"); return stb.toString(); }