List of usage examples for java.lang.reflect Modifier isStatic
public static boolean isStatic(int mod)
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 w ww. jav a 2s . 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:Main.java
public static boolean isStatic(int modifier) { return Modifier.isStatic(modifier); }
From source file:Util.java
private static void fillSetterMethods(Class<?> pojoClass, Map<String, Method> baseMap) { if (pojoClass.getSuperclass() != Object.class) fillSetterMethods(pojoClass.getSuperclass(), baseMap); Method[] methods = pojoClass.getDeclaredMethods(); for (int i = 0; i < methods.length; i++) { Method m = methods[i];/*from www. j ava2s . c o m*/ if (!Modifier.isStatic(m.getModifiers()) && m.getParameterTypes().length == 1 && m.getName().startsWith(SET) && Modifier.isPublic(m.getModifiers())) { baseMap.put(toProperty(SET.length(), m.getName()), m); } } }
From source file:Util.java
private static void fillGetterMethods(Class<?> pojoClass, Map<String, Method> baseMap) { if (pojoClass.getSuperclass() != Object.class) fillGetterMethods(pojoClass.getSuperclass(), baseMap); Method[] methods = pojoClass.getDeclaredMethods(); for (int i = 0; i < methods.length; i++) { Method m = methods[i];//from w w w.j a v a 2 s .c om if (!Modifier.isStatic(m.getModifiers()) && m.getParameterTypes().length == 0 && m.getReturnType() != null && Modifier.isPublic(m.getModifiers())) { String name = m.getName(); if (name.startsWith(IS)) baseMap.put(toProperty(IS.length(), name), m); else if (name.startsWith(GET)) baseMap.put(toProperty(GET.length(), name), m); } } }
From source file:edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.EditConfigurationConstants.java
public static Map<String, String> exportConstants() { Map<String, String> constants = new HashMap<String, String>(); java.lang.reflect.Field[] fields = EditConfigurationConstants.class.getDeclaredFields(); for (java.lang.reflect.Field f : fields) { if (Modifier.isStatic(f.getModifiers()) && Modifier.isPublic(f.getModifiers())) { try { constants.put(f.getName(), f.get(null).toString()); } catch (Exception ex) { log.error("An exception occurred in trying to retrieve this field ", ex); }//from w w w. j a v a 2 s . co m } } return constants; }
From source file:Main.java
/** * Returns the Jarvis Api Version or -1 if it is not supported * @return api version//from www.ja v a 2s. c o m */ public static int getJarvisApiVersion() { Field[] declaredFields = Build.class.getDeclaredFields(); for (Field field : declaredFields) { if (Modifier.isStatic(field.getModifiers()) && field.getName().equals("JARVIS_VERSION")) { try { return field.getInt(null); } catch (IllegalAccessException ex) { ex.printStackTrace(); } catch (IllegalArgumentException ex) { ex.printStackTrace(); } } } return -1; }
From source file:DeclarationInfoDemo.java
public static void printModifiers(final Class dataType) { final int modifiers = dataType.getModifiers(); if (Modifier.isPrivate(modifiers)) { System.out.print("private "); }//from ww w . j a v a 2s . c o m if (Modifier.isPrivate(modifiers)) { System.out.print("private "); } if (Modifier.isPublic(modifiers)) { System.out.print("private "); } if (Modifier.isAbstract(modifiers)) { System.out.print("abstract "); } if (Modifier.isFinal(modifiers)) { System.out.print("final "); } if (Modifier.isNative(modifiers)) { System.out.print("native "); } if (Modifier.isInterface(modifiers)) { System.out.print("interface "); } if (Modifier.isStatic(modifiers)) { System.out.print("static "); } if (Modifier.isStrict(modifiers)) { System.out.print("strict "); } if (Modifier.isSynchronized(modifiers)) { System.out.print("synchronized "); } if (Modifier.isTransient(modifiers)) { System.out.print("transient "); } if (Modifier.isVolatile(modifiers)) { System.out.print("volatile "); } System.out.println(dataType.getName()); }
From source file:Main.java
private static Set<Method> findMethodsCompatibleWith(boolean staticMethod, Set<Method> methods, String methodName, Class<?>[] argTypes) { final Set<Method> list = new HashSet<Method>(methods); for (final Iterator<Method> it = list.iterator(); it.hasNext();) { final Method method = it.next(); if (!methodName.equals(method.getName())) { it.remove();/* w ww . j a v a 2 s . co m*/ continue; } if (argTypes.length != method.getParameterTypes().length) { it.remove(); continue; } if (Modifier.isAbstract(method.getModifiers()) || Modifier.isStatic(method.getModifiers()) != staticMethod) { it.remove(); continue; } if (!isMethodArgCompatible(method, argTypes)) { it.remove(); continue; } } return list; }
From source file:Main.java
public static int hashCode(Object target) { if (target == null) return 0; final int prime = 31; int result = 1; Class<?> current = target.getClass(); do {//from ww w . ja v a 2 s. c o m for (Field f : current.getDeclaredFields()) { if (Modifier.isStatic(f.getModifiers()) || Modifier.isTransient(f.getModifiers()) || f.isSynthetic()) { continue; } Object self; try { f.setAccessible(true); self = f.get(target); } catch (IllegalAccessException e) { throw new IllegalStateException(e); } if (self == null) { result = prime * result + 0; } else if (self.getClass().isArray()) { if (self.getClass().equals(boolean[].class)) { result = prime * result + Arrays.hashCode((boolean[]) self); } else if (self.getClass().equals(char[].class)) { result = prime * result + Arrays.hashCode((char[]) self); } else if (self.getClass().equals(byte[].class)) { result = prime * result + Arrays.hashCode((byte[]) self); } else if (self.getClass().equals(short[].class)) { result = prime * result + Arrays.hashCode((short[]) self); } else if (self.getClass().equals(int[].class)) { result = prime * result + Arrays.hashCode((int[]) self); } else if (self.getClass().equals(long[].class)) { result = prime * result + Arrays.hashCode((long[]) self); } else if (self.getClass().equals(float[].class)) { result = prime * result + Arrays.hashCode((float[]) self); } else if (self.getClass().equals(double[].class)) { result = prime * result + Arrays.hashCode((double[]) self); } else { result = prime * result + Arrays.hashCode((Object[]) self); } } else { result = prime * result + self.hashCode(); } System.out.println(f.getName() + ": " + result); } current = current.getSuperclass(); } while (!Object.class.equals(current)); return result; }
From source file:Main.java
/** * @since 1.9//from ww w .ja v a2 s .com */ public static String isLocalType(Class<?> type, boolean allowNonStatic) { /* As per [JACKSON-187], GAE seems to throw SecurityExceptions * here and there... and GAE itself has a bug, too * (see []). Bah. So we need to catch some wayward exceptions on GAE */ try { // one more: method locals, anonymous, are not good: if (type.getEnclosingMethod() != null) { return "local/anonymous"; } /* But how about non-static inner classes? Can't construct * easily (theoretically, we could try to check if parent * happens to be enclosing... but that gets convoluted) */ if (!allowNonStatic) { if (type.getEnclosingClass() != null) { if (!Modifier.isStatic(type.getModifiers())) { return "non-static member class"; } } } } catch (SecurityException e) { } catch (NullPointerException e) { } return null; }