List of usage examples for java.lang Class isArray
@HotSpotIntrinsicCandidate public native boolean isArray();
From source file:jef.tools.ArrayUtils.java
/** * ?//from w w w. j a v a 2 s. c om * * @param obj * @param containerType * @return */ @SuppressWarnings("unchecked") public static <T> T[] toObject(Object obj, Class<T> containerType) { Class<?> c = obj.getClass(); Assert.isTrue(c.isArray()); Class<?> priType = c.getComponentType(); if (priType == containerType) { return (T[]) obj; } return cast(toObject(obj), containerType); }
From source file:jef.tools.ArrayUtils.java
/** * ??//w w w .j a v a2 s . c o m * * @param objs * @return */ public static Object toPrimitive(Object[] obj) { Class<?> c = obj.getClass(); Assert.isTrue(c.isArray()); Class<?> objType = c.getComponentType(); if (objType == Boolean.class) { return toPrimitive((Boolean[]) obj); } else if (objType == Byte.class) { return toPrimitive((Byte[]) obj); } else if (objType == Character.class) { return toPrimitive((Character[]) obj); } else if (objType == Integer.class) { return toPrimitive((Integer[]) obj); } else if (objType == Long.class) { return toPrimitive((Long[]) obj); } else if (objType == Float.class) { return toPrimitive((Float[]) obj); } else if (objType == Double.class) { return toPrimitive((Double[]) obj); } else if (objType == Short.class) { return toPrimitive((Short[]) obj); } else { throw new IllegalArgumentException(); } }
From source file:jef.tools.ArrayUtils.java
/** * ?//from w ww .j ava 2s. c om * * @param obj * @return */ public static Object[] toObject(Object obj) { Class<?> c = obj.getClass(); Assert.isTrue(c.isArray()); Class<?> priType = c.getComponentType(); if (!priType.isPrimitive()) return (Object[]) obj; if (priType == Boolean.TYPE) { return toObject((boolean[]) obj); } else if (priType == Byte.TYPE) { return toObject((byte[]) obj); } else if (priType == Character.TYPE) { return toObject((char[]) obj); } else if (priType == Integer.TYPE) { return toObject((int[]) obj); } else if (priType == Long.TYPE) { return toObject((long[]) obj); } else if (priType == Float.TYPE) { return toObject((float[]) obj); } else if (priType == Double.TYPE) { return toObject((double[]) obj); } else if (priType == Short.TYPE) { return toObject((short[]) obj); } throw new IllegalArgumentException(); }
From source file:com.astamuse.asta4d.web.initialization.SimplePropertyFileInitializer.java
@SuppressWarnings("rawtypes") protected void fillConfiguration(WebApplicationConfiguration conf, BeanUtilsBean beanUtil, String key, String value) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException { Class cls = PropertyUtils.getPropertyType(conf, key); if (cls.isArray()) { String[] values = value.split(","); beanUtil.setProperty(conf, key, values); } else {// w w w.j a v a 2 s. c om beanUtil.setProperty(conf, key, value); } }
From source file:adalid.core.XS1.java
private static boolean isRestrictedFieldType(Class<?> fieldType) { int modifiers = fieldType.getModifiers(); boolean b = fieldType.isPrimitive(); b |= Modifier.isAbstract(modifiers) || !Modifier.isPublic(modifiers); b |= fieldType.isAnnotation();/*from w w w. j a v a2 s. c o m*/ b |= fieldType.isAnonymousClass(); b |= fieldType.isArray(); b |= fieldType.isEnum(); b |= fieldType.isLocalClass(); b |= fieldType.isInterface(); return b; }
From source file:com.github.helenusdriver.driver.tools.Tool.java
/** * Finds an initial objects factory method and its dependent classes from the * specified object creator class.// w w w . j av a 2 s. co m * * @author paouelle * * @param clazz the non-<code>null</code> object creator class * @return the initial objects factory method and its set of dependenc classes * or <code>null</code> if none configured * @throws IllegalArgumentException if the initial objects method is not * properly defined */ private static Pair<Method, Class<?>[]> findInitial(Class<?> clazz) { final InitialObjects io = clazz.getAnnotation(InitialObjects.class); if (io != null) { final String mname = io.staticMethod(); try { Method m; try { // first look for one with a map for suffixes m = clazz.getMethod(mname, Map.class); // validate that if suffixes are defined, the method expects a Map<String, String> // to provide the values for the suffixes when initializing objects final Class<?>[] cparms = m.getParameterTypes(); // should always be 1 as we used only 1 class in getMethod() if (cparms.length != 1) { throw new IllegalArgumentException( "expecting one Map<String, String> parameter for initial objects method '" + mname + "' in class: " + clazz.getSimpleName()); } // should always be a map as we used a Map to find the method if (!Map.class.isAssignableFrom(cparms[0])) { throw new IllegalArgumentException("expecting parameter for initial objects method '" + mname + "' to be of type Map<String, String> in class: " + clazz.getSimpleName()); } final Type[] tparms = m.getGenericParameterTypes(); // should always be 1 as we used only 1 class in getMethod() if (tparms.length != 1) { // should always be 1 as it was already tested above throw new IllegalArgumentException( "expecting one Map<String, String> parameter for initial objects method '" + mname + "' in class: " + clazz.getSimpleName()); } if (tparms[0] instanceof ParameterizedType) { final ParameterizedType ptype = (ParameterizedType) tparms[0]; // maps will always have 2 arguments for (final Type atype : ptype.getActualTypeArguments()) { final Class<?> aclazz = ReflectionUtils.getRawClass(atype); if (String.class != aclazz) { throw new IllegalArgumentException( "expecting a Map<String, String> parameter for initial objects method '" + mname + "' in class: " + clazz.getSimpleName()); } } } else { throw new IllegalArgumentException( "expecting a Map<String, String> parameter for initial objects method '" + mname + "' in class: " + clazz.getSimpleName()); } } catch (NoSuchMethodException e) { // fallback to one with no map m = clazz.getMethod(mname); } // validate the method is static if (!Modifier.isStatic(m.getModifiers())) { throw new IllegalArgumentException("initial objects method '" + mname + "' is not static in class: " + clazz.getSimpleName()); } // validate the return type is an array final Class<?> type = m.getReturnType(); if (!type.isArray()) { throw new IllegalArgumentException("initial objects method '" + mname + "' doesn't return an array in class: " + clazz.getSimpleName()); } return Pair.of(m, io.dependsOn()); } catch (NoSuchMethodException e) { throw new IllegalArgumentException( "missing initial objects method '" + mname + "' in class: " + clazz.getSimpleName(), e); } } return null; }
From source file:com.glaf.core.util.ReflectUtils.java
public static boolean isPrimitives(Class<?> cls) { if (cls.isArray()) { return isPrimitive(cls.getComponentType()); }/*from ww w . j a v a 2s. c o m*/ return isPrimitive(cls); }
From source file:io.wcm.config.core.impl.ParameterOverrideProviderBridge.java
private String toJsonValue(String value, Class type) { if (type.isArray()) { return "[" + toJsonValue(value, type.getComponentType()) + "]"; } else if (type == String.class) { return JSONObject.quote(value); } else if (type == int.class) { return Integer.toString(NumberUtils.toInt(value)); } else if (type == long.class) { return Long.toString(NumberUtils.toLong(value)); } else if (type == double.class) { return Double.toString(NumberUtils.toDouble(value)); } else if (type == boolean.class) { return Boolean.toString(BooleanUtils.toBoolean(value)); } else {// w w w . j av a2 s .c o m throw new IllegalArgumentException("Illegal value type: " + type.getName()); } }
From source file:springfox.documentation.spring.web.readers.parameter.ParameterMultiplesReader.java
@Override public void apply(ParameterContext context) { MethodParameter methodParameter = context.methodParameter(); Boolean allowMultiple;/*from www .java 2s . co m*/ Class<?> parameterType = methodParameter.getParameterType(); if (parameterType != null) { allowMultiple = parameterType.isArray() || Iterable.class.isAssignableFrom(parameterType); context.parameterBuilder().allowMultiple(allowMultiple); } }
From source file:com.nfwork.dbfound.json.converter.NumberArrayConverter.java
protected int getDimensions(Class arrayClass) { if (arrayClass == null || !arrayClass.isArray()) { return 0; }//from w ww. j a va 2 s.c o m return 1 + getDimensions(arrayClass.getComponentType()); }