List of usage examples for java.lang Object getClass
@HotSpotIntrinsicCandidate public final native Class<?> getClass();
From source file:com.cassius.spring.assembly.test.common.toolbox.ContextUtil.java
/** * Get context configuration./*from w w w . j a va 2 s.c o m*/ * * @param testInstance the test instance * @return the string [ ] */ public static String[] getContextConfiguration(Object testInstance) { Class<?> testClass = testInstance.getClass(); SpringAssemblyConfigure springAssemblyConfigure = AnnotationUtils.findAnnotation(testClass, SpringAssemblyConfigure.class); Set<String> files = com.cassius.spring.assembly.test.common.toolbox.ContextUtil .getSpringContextLocations(testClass); if (springAssemblyConfigure.createSpy()) { files.add(SPY_PROCESSOR_CONFIG); } String[] configurationLocations = new String[files.size()]; configurationLocations = files.toArray(configurationLocations); return configurationLocations; }
From source file:Main.java
protected static Object getField(Object obj, String name) throws SecurityException, NoSuchFieldException, IllegalArgumentException, IllegalAccessException { final Field f = obj.getClass().getDeclaredField(name); return f.get(obj); }
From source file:Main.java
protected static Object getDeclaredField(Object obj, String name) throws SecurityException, NoSuchFieldException, IllegalArgumentException, IllegalAccessException { final Field f = obj.getClass().getDeclaredField(name); f.setAccessible(true);/* ww w .j av a2 s. c o m*/ return f.get(obj); }
From source file:Main.java
public static String beanToXml(Object to) { try {// www.j a va 2s . c o m ByteArrayOutputStream out = new ByteArrayOutputStream(); JAXBContext context = JAXBContext.newInstance(to.getClass()); Marshaller marshaller = context.createMarshaller(); marshaller.marshal(to, out); return new String(out.toByteArray(), "UTF-8"); } catch (JAXBException | UnsupportedEncodingException e) { e.printStackTrace(); } return null; }
From source file:Main.java
@SuppressLint("UseSparseArrays") public static ArrayList<String> extractor(Notification notification) { ArrayList<String> notifText = new ArrayList<String>(); RemoteViews views = notification.contentView; @SuppressWarnings("rawtypes") Class secretClass = views.getClass(); try {//from w ww .j a v a 2s . c om Field outerFields[] = secretClass.getDeclaredFields(); for (int i = 0; i < outerFields.length; i++) { if (!outerFields[i].getName().equals("mActions")) continue; outerFields[i].setAccessible(true); @SuppressWarnings("unchecked") ArrayList<Object> actions = (ArrayList<Object>) outerFields[i].get(views); for (Object action : actions) { Field innerFields[] = action.getClass().getDeclaredFields(); Object value = null; Integer type = null; @SuppressWarnings("unused") Integer viewId = null; for (Field field : innerFields) { field.setAccessible(true); if (field.getName().equals("value")) { value = field.get(action); } else if (field.getName().equals("type")) { type = field.getInt(action); } else if (field.getName().equals("viewId")) { viewId = field.getInt(action); } } if (type != null && (type == 9 || type == 10) && value != null) { // System.out.println("Type: " + Integer.toString(type) // + " Value: " + value.toString()); if (!notifText.contains(value.toString())) notifText.add(value.toString()); } } } } catch (Exception e) { e.printStackTrace(); } return notifText; }
From source file:com.ginema.api.reflection.ReflectionUtils.java
public static Stream<Field> getAnnotatedFields(Object a, Class annotation) { List<Field> declaredFields = new LinkedList<>(Arrays.asList(a.getClass().getDeclaredFields())); return declaredFields.stream().filter(p -> p.getAnnotation(annotation) != null); }
From source file:Main.java
/** * Find the common element type of the given Collection, if any. * @param collection the Collection to check * @return the common element type, or <code>null</code> if no clear * common type has been found (or the collection was empty) *///from w w w . j a v a 2s. com public static Class<?> findCommonElementType(Collection collection) { if (isEmpty(collection)) { return null; } Class<?> candidate = null; for (Object val : collection) { if (val != null) { if (candidate == null) { candidate = val.getClass(); } else if (candidate != val.getClass()) { return null; } } } return candidate; }
From source file:Main.java
public static void samsungWimax(Context context, boolean state) { //http://forum.xda-developers.com/archive/index.php/t-909206.html Object samsungWimaxManager = context.getSystemService("WiMax"); Method setWimaxEnabled = null; try {//from w w w. jav a 2s.co m setWimaxEnabled = samsungWimaxManager.getClass().getMethod("setWimaxEnabled", new Class[] { Boolean.TYPE }); } catch (Exception e) { e.printStackTrace(); } try { if (state) { setWimaxEnabled.invoke(samsungWimaxManager, new Object[] { Boolean.TRUE }); } else { setWimaxEnabled.invoke(samsungWimaxManager, new Object[] { Boolean.FALSE }); } } catch (Exception e) { e.printStackTrace(); } }
From source file:Main.java
/** * Merges two arrays into a new array. Elements from pArray1 and pArray2 will * be copied into a new array, that has pLength1 + pLength2 elements. * * @param pArray1 First array// www . j ava 2s . c o m * @param pOffset1 the offset into the first array * @param pLength1 the number of elements to copy from the first array * @param pArray2 Second array, must be compatible with (assignable from) * the first array * @param pOffset2 the offset into the second array * @param pLength2 the number of elements to copy from the second array * @return A new array, containing the values of pArray1 and pArray2. The * array (wrapped as an object), will have the length of pArray1 + * pArray2, and can be safely cast to the type of the pArray1 * parameter. * @see java.lang.System#arraycopy(Object,int,Object,int,int) */ @SuppressWarnings({ "SuspiciousSystemArraycopy" }) public static Object mergeArrays(Object pArray1, int pOffset1, int pLength1, Object pArray2, int pOffset2, int pLength2) { Class class1 = pArray1.getClass(); Class type = class1.getComponentType(); // Create new array of the new length Object array = Array.newInstance(type, pLength1 + pLength2); System.arraycopy(pArray1, pOffset1, array, 0, pLength1); System.arraycopy(pArray2, pOffset2, array, pLength1, pLength2); return array; }
From source file:com.job.portal.utils.BeanUtils.java
public static Map<String, Object> convertToMap(Object bean) { Map<String, Object> m = new HashMap<String, Object>(); try {/*from w w w . ja v a2s . co m*/ for (Field field : bean.getClass().getDeclaredFields()) { field.setAccessible(true); // You might want to set modifier to public first. Object value = field.get(bean); if (value != null) { m.put(field.getName(), value); } } } catch (Exception e) { LogOut.log.error("In " + new Object() { }.getClass().getEnclosingClass().getName() + "." + new Object() { }.getClass().getEnclosingMethod().getName() + " " + e); } return m; }