List of usage examples for java.lang Class isArray
@HotSpotIntrinsicCandidate public native boolean isArray();
From source file:Main.java
/** * @return Null if class might be a bean; type String (that identifies * why it's not a bean) if not/*from w ww.ja v a 2 s . c o m*/ */ public static String canBeABeanType(Class<?> type) { // First: language constructs that ain't beans: if (type.isAnnotation()) { return "annotation"; } if (type.isArray()) { return "array"; } if (type.isEnum()) { return "enum"; } if (type.isPrimitive()) { return "primitive"; } // Anything else? Seems valid, then return null; }
From source file:com.nec.nsgui.model.biz.cifs.NSBeanUtil.java
/** * The bean members' type is limited to String and String[] *//*from ww w. ja v a2 s . co m*/ public static void setProperties(Object bean, String[] valueArray, String delimiter) throws Exception { if (bean == null || valueArray == null || valueArray.length == 0) { return; } Map map = new TreeMap(); for (int i = 0; i < valueArray.length; i++) { String keyAndValue = valueArray[i]; if (keyAndValue == null || keyAndValue.indexOf(KEY_VALUE_SPLITER) == -1) { continue; } else { String[] tmpArray = valueArray[i].split(KEY_VALUE_SPLITER, 2); String key = tmpArray[0].trim(); if (delimiter != null) { PropertyDescriptor descriptor = PropertyUtils.getPropertyDescriptor(bean, key); Class propertyType = descriptor.getPropertyType(); if (propertyType.isArray()) { String[] values = tmpArray[1].split(delimiter); map.put(key, values); continue; } } String value = tmpArray[1]; map.put(key, value); } } if (map.size() > 0) { BeanUtils.populate(bean, map); } return; }
From source file:Main.java
/** * Extracts the package name from the given class object *//*from www . j a v a 2 s . c o m*/ public static String getPackage(Class<?> cls) { // cls.getPackage() sometimes returns null, in which case fall back to string massaging. java.lang.Package pkg = cls.isArray() ? cls.getComponentType().getPackage() : cls.getPackage(); if (pkg == null) { int dotPos; int dolPos = cls.getName().indexOf('$'); if (dolPos > 0) { // we have nested classes, so adjust dotpos to before first $ dotPos = cls.getName().substring(0, dolPos).lastIndexOf('.'); } else { dotPos = cls.getName().lastIndexOf('.'); } if (dotPos > 0) { return cls.getName().substring(0, dotPos); } else { // must be default package. return ""; } } else { return pkg.getName(); } }
From source file:Main.java
/** * Returns a class name without "java.lang." and "java.util." prefix, also shows array types in a format like * {@code int[]}; useful for printing class names in error messages. * /*from ww w . j av a2 s .c o m*/ * @param pClass can be {@code null}, in which case the method returns {@code null}. * @param shortenFreeMarkerClasses if {@code true}, it will also shorten FreeMarker class names. The exact rules * aren't specified and might change over time, but right now, {@code freemarker.ext.beans.NumberModel} for * example becomes to {@code f.e.b.NumberModel}. * * @since 2.3.20 */ public static String getShortClassName(Class pClass, boolean shortenFreeMarkerClasses) { if (pClass == null) { return null; } else if (pClass.isArray()) { return getShortClassName(pClass.getComponentType()) + "[]"; } else { String cn = pClass.getName(); if (cn.startsWith("java.lang.") || cn.startsWith("java.util.")) { return cn.substring(10); } else { if (shortenFreeMarkerClasses) { if (cn.startsWith("freemarker.template.")) { return "f.t" + cn.substring(19); } else if (cn.startsWith("freemarker.ext.beans.")) { return "f.e.b" + cn.substring(20); } else if (cn.startsWith("freemarker.core.")) { return "f.c" + cn.substring(15); } else if (cn.startsWith("freemarker.ext.")) { return "f.e" + cn.substring(14); } else if (cn.startsWith("freemarker.")) { return "f" + cn.substring(10); } // Falls through } return cn; } } }
From source file:Main.java
public static String getDesc(Class<?> paramClass) { if (paramClass.isPrimitive()) { return getPrimitiveLetter(paramClass); }//from www .j a v a 2s .c om if (paramClass.isArray()) { return "[" + getDesc(paramClass.getComponentType()); } return "L" + getType(paramClass) + ";"; }
From source file:com.google.api.server.spi.ObjectMapperUtil.java
private static boolean isEmpty(Object value) { Class<?> clazz = value.getClass(); if (clazz.isArray()) { int len = Array.getLength(value); for (int i = 0; i < len; i++) { Object element = Array.get(value, i); if (element != null && !isEmpty(element)) { return false; }/*from w w w. j av a2 s.c o m*/ } return true; } else if (Collection.class.isAssignableFrom(clazz)) { Collection<?> c = (Collection<?>) value; for (Object element : c) { if (element != null && !isEmpty(element)) { return false; } } return true; } else if (Map.class.isAssignableFrom(clazz)) { Map<?, ?> m = (Map<?, ?>) value; for (Object entryValue : m.values()) { if (entryValue != null && !isEmpty(entryValue)) { return false; } } return true; } return false; }
From source file:ClassUtils.java
/** * Return the qualified name of the given class: usually simply * the class name, but component type class name + "[]" for arrays. * @param clazz the class/* w w w. j ava2 s .c o m*/ * @return the qualified name of the class */ public static String getQualifiedName(Class clazz) { if (clazz.isArray()) { return getQualifiedNameForArray(clazz); } return clazz.getName(); }
From source file:Main.java
/** * This method was added to address [JACKSON-53]: need to weed out * CGLib-injected "getCallbacks". /*from w ww . j av a2 s . co m*/ * At this point caller has detected a potential getter method * with name "getCallbacks" and we need to determine if it is * indeed injectect by Cglib. We do this by verifying that the * result type is "net.sf.cglib.proxy.Callback[]" *<p> * Also, see [JACKSON-177]; Hibernate may repackage cglib * it uses, so we better catch that too */ protected static boolean isCglibGetCallbacks(AnnotatedMethod am) { Class<?> rt = am.getRawType(); // Ok, first: must return an array type if (rt == null || !rt.isArray()) { return false; } /* And that type needs to be "net.sf.cglib.proxy.Callback". * Theoretically could just be a type that implements it, but * for now let's keep things simple, fix if need be. */ Class<?> compType = rt.getComponentType(); // Actually, let's just verify it's a "net.sf.cglib.*" class/interface Package pkg = compType.getPackage(); if (pkg != null) { String pname = pkg.getName(); if (pname.startsWith("net.sf.cglib") // also, as per [JACKSON-177] || pname.startsWith("org.hibernate.repackage.cglib")) { return true; } } return false; }
From source file:org.hdiv.web.servlet.tags.form.SelectTagHDIV.java
/** * Returns '<code>true</code>' for arrays, {@link Collection Collections} * and {@link Map Maps}./*from ww w . ja va2 s . c o m*/ */ private static boolean typeRequiresMultiple(Class type) { return (type.isArray() || Collection.class.isAssignableFrom(type) || Map.class.isAssignableFrom(type)); }
From source file:com.britesnow.snow.util.ObjectUtil.java
/** * <div class="notes"> <strong>Notes:</strong> * <ul>/* ww w . j av a 2s. com*/ * <li>So far does not safeguard any type conversion (will throw an runtime exception if parsing fail)</li> * </ul> * </div> * * @param <T> * @param values * String arrays of the value to be converted * @param cls * @param defaultValues * @return The typed array given a value of the String. */ public static final <T> T getValue(String[] values, Class<T> cls, T defaultValues) { if (values != null && cls.isArray()) { Class compCls = cls.getComponentType(); T resultArray = (T) Array.newInstance(compCls, values.length); int i = 0; for (String v : values) { Object r = getValue(v, compCls, null); Array.set(resultArray, i++, r); } return resultArray; } else { return defaultValues; } }