List of usage examples for org.apache.commons.lang3 ClassUtils isPrimitiveOrWrapper
public static boolean isPrimitiveOrWrapper(final Class<?> type)
From source file:org.apache.metron.profiler.bolt.KafkaDestinationHandler.java
/** * The result of a profile's triage expressions must be a string or primitive type. * * This ensures that the value can be easily serialized and appended to a message destined for Kafka. * * @param value The value of a triage expression. * @return True, if the type of the value is valid. *//* w ww. j ava 2s.c o m*/ private boolean isValidType(Object value) { return value != null && (value instanceof String || ClassUtils.isPrimitiveOrWrapper(value.getClass())); }
From source file:org.apache.syncope.client.console.wicket.markup.html.list.ConnConfPropertyListView.java
@Override @SuppressWarnings({ "unchecked", "rawtypes" }) protected void populateItem(final ListItem<ConnConfProperty> item) { final ConnConfProperty property = item.getModelObject(); final String label = StringUtils.isBlank(property.getSchema().getDisplayName()) ? property.getSchema().getName() : property.getSchema().getDisplayName(); final FieldPanel<? extends Serializable> field; boolean required = false; boolean isArray = false; if (property.getSchema().isConfidential() || Constants.GUARDED_STRING.equalsIgnoreCase(property.getSchema().getType()) || Constants.GUARDED_BYTE_ARRAY.equalsIgnoreCase(property.getSchema().getType())) { field = new AjaxPasswordFieldPanel("panel", label, new Model<>(), false); ((PasswordTextField) field.getField()).setResetPassword(false); required = property.getSchema().isRequired(); } else {/*from ww w . j a v a 2 s.c o m*/ Class<?> propertySchemaClass; try { propertySchemaClass = ClassUtils.getClass(property.getSchema().getType()); if (ClassUtils.isPrimitiveOrWrapper(propertySchemaClass)) { propertySchemaClass = org.apache.commons.lang3.ClassUtils .primitiveToWrapper(propertySchemaClass); } } catch (ClassNotFoundException e) { LOG.error("Error parsing attribute type", e); propertySchemaClass = String.class; } if (ClassUtils.isAssignable(Number.class, propertySchemaClass)) { @SuppressWarnings("unchecked") Class<Number> numberClass = (Class<Number>) propertySchemaClass; field = new AjaxSpinnerFieldPanel.Builder<>().build("panel", label, numberClass, new Model<>()); required = property.getSchema().isRequired(); } else if (ClassUtils.isAssignable(Boolean.class, propertySchemaClass)) { field = new AjaxCheckBoxPanel("panel", label, new Model<>()); } else { field = new AjaxTextFieldPanel("panel", label, new Model<>()); required = property.getSchema().isRequired(); } if (propertySchemaClass.isArray()) { isArray = true; } } field.setIndex(item.getIndex()); field.setTitle(property.getSchema().getHelpMessage(), true); final AbstractFieldPanel<? extends Serializable> fieldPanel; if (isArray) { final MultiFieldPanel multiFieldPanel = new MultiFieldPanel.Builder( new PropertyModel<>(property, "values")).setEventTemplate(true).build("panel", label, field); item.add(multiFieldPanel); fieldPanel = multiFieldPanel; } else { setNewFieldModel(field, property.getValues()); item.add(field); fieldPanel = field; } if (required) { fieldPanel.addRequiredLabel(); } if (withOverridable) { fieldPanel.showExternAction(addCheckboxToggle(property)); } }
From source file:org.craftercms.commons.jackson.mvc.AbstractCrafterPropertyFilter.java
protected boolean isPrimitive(final Class<?> clazz) { return Date.class.isAssignableFrom(clazz) || ClassUtils.isPrimitiveOrWrapper(clazz) || List.class.isAssignableFrom(clazz) || Map.class.isAssignableFrom(clazz); }
From source file:org.dcm4chee.archive.conf.DeepEquals.java
/** * Deeply compare to Arrays []. Both arrays must be of the same type, same length, and all * elements within the arrays must be deeply equal in order to return true. * @param array1 [] type (Object[], String[], etc.) * @param array2 [] type (Object[], String[], etc.) * @param stack add items to compare to the Stack (Stack versus recursion) * @param visited Set of objects already compared (prevents cycles) * @return true if the two arrays are the same length and contain deeply equivalent items. *//*from w w w .j a v a 2s.c o m*/ private static boolean compareArrays(Object array1, Object array2, LinkedList stack, Set visited) { // Same instance check already performed... int len = Array.getLength(array1); if (len != Array.getLength(array2)) { return false; } // try sorting if (len > 0) { if (Array.get(array1, 0) instanceof Comparable) { Class<?> c = Array.get(array1, 0).getClass(); if (ClassUtils.isPrimitiveOrWrapper(c)) { /* Arrays.sort(array1); Arrays.sort((Object[]) array2);*/ } else { Arrays.sort((Object[]) array1); Arrays.sort((Object[]) array2); } } } for (int i = 0; i < len; i++) { DualKey dk = new DualKey(Array.get(array1, i), Array.get(array2, i)); if (!visited.contains(dk)) { // push contents for further comparison stack.addFirst(dk); } } return true; }
From source file:org.evosuite.regression.ObjectFields.java
public static Map<String, Object> getObjectMap(Object o) { if (ClassUtils.isPrimitiveOrWrapper(o.getClass()) || (o instanceof String)) { Map<String, Object> objectMap = new HashMap<String, Object>(); objectMap.put("fake_var_" + o.getClass().getName().replace('.', '_'), o); return objectMap; } else {//from w ww .j a va 2s. co m return getAllVars(o, 0, ""); } }
From source file:org.evosuite.regression.ObjectFields.java
private static Map<String, Object> getAllVars(Object p, int counter, String prefix) { // TODO Auto-generated method stub // logger.warn("getting: " + ((p instanceof Field)?((Field) // p).getType():p.getClass()) + ", count:" + counter); Map<String, Object> values = new HashMap<String, Object>(); // if(((p instanceof Field)?((Field) p).getType():p.getClass()) == null) // return values; if (p == null) return values; Collection<Field> fields = getAllFields(p.getClass()); for (Field field : fields) { // String what_happened = ""; GenericClass gc = new GenericClass(field.getType()); if (ClassUtils.isPrimitiveOrWrapper(field.getType()) || gc.isString()) { // what_happened += ", " + field.getType() + " is primitive,"; if (field.getName().equals("serialVersionUID")) continue; values.put(prefix + field.getName(), getObjectValue(getFieldValue(field, p))); } else if (field.getType().equals(Object.class) || counter >= MAX_RECURSION) { values.put(prefix + field.getName(), (getObjectValue(getFieldValue(field, p)) != null)); // what_happened += ", " + field.getType() + ",reached end,"; } else if (field.getType().isArray()) { /*//from ww w . j av a2s. c om * values.put(prefix + field.getName(), Array * .getLength(getObjectValue(getFieldValue(field, p)))); */ // Object[] arr = (Object[]) getFieldValue(field, p); /* * for(Object o: arr){ values.putAll(getAllVars(o, counter + * 1,prefix + ((prefix.equals(""))?"":".")+field.getName())); } */ Object arr = getFieldValue(field, p); if (arr == null) return values; for (int n = 0; n < Array.getLength(arr); n++) { // values.putAll(getAllVars(Array.get(arr,n), counter + // 1,prefix + ((prefix.isEmpty())?"":".")+field.getName())); values.put(prefix + field.getName(), getAllVars(Array.get(arr, n), counter + 1, prefix + ((prefix.isEmpty()) ? "" : ".") + field.getName())); } } else { try { field.setAccessible(true); // values.putAll(getAllVars(field.get(p), counter + 1,prefix // + ((prefix.isEmpty())?"":".")+field.getName())); values.put(prefix + field.getName(), getAllVars(field.get(p), counter + 1, prefix + ((prefix.isEmpty()) ? "" : ".") + field.getName())); } catch (IllegalArgumentException e) { // TODO Auto-generated catch block return values; } catch (IllegalAccessException e) { // TODO Auto-generated catch block return values; } // what_happened += ", " + field.getType() + ",recursed,"; } // logger.warn(prefix + field.getName() + what_happened); } /* * if (ClassUtils.isPrimitiveOrWrapper(p.getClass())){ * * return null; } else { * * } */ return values; }
From source file:org.grouplens.grapht.annotation.AnnotationProxy.java
/** * Safe clone of an object. If the object is an array, it is copied; otherwise, it is * returned as-is. This object is only applicable to valid annotation value types, which * are all either arrays or immutable./*w w w. ja v a2 s . c o m*/ * @param o The annotation value. * @return A copy of the value. */ @SuppressWarnings("unchecked") static Object copyAnnotationValue(Object o) { if (o.getClass().isArray()) { // make a shallow copy of the array if (o instanceof boolean[]) { boolean[] a = (boolean[]) o; return Arrays.copyOf(a, a.length); } else if (o instanceof byte[]) { byte[] a = (byte[]) o; return Arrays.copyOf(a, a.length); } else if (o instanceof short[]) { short[] a = (short[]) o; return Arrays.copyOf(a, a.length); } else if (o instanceof int[]) { int[] a = (int[]) o; return Arrays.copyOf(a, a.length); } else if (o instanceof long[]) { long[] a = (long[]) o; return Arrays.copyOf(a, a.length); } else if (o instanceof char[]) { char[] a = (char[]) o; return Arrays.copyOf(a, a.length); } else if (o instanceof float[]) { float[] a = (float[]) o; return Arrays.copyOf(a, a.length); } else if (o instanceof double[]) { double[] a = (double[]) o; return Arrays.copyOf(a, a.length); } else { Object[] a = (Object[]) o; return Arrays.copyOf(a, a.length, (Class<? extends Object[]>) o.getClass()); } } else if (o instanceof String || o instanceof Annotation || ClassUtils.isPrimitiveOrWrapper(o.getClass()) || o instanceof Enum || o instanceof Class) { // the value is immutable and a copy is not necessary return o; } else { throw new IllegalArgumentException("not an annotation value"); } }
From source file:org.grouplens.lenskit.eval.graph.ComponentNodeBuilder.java
static String shortClassName(Class<?> type) { if (ClassUtils.isPrimitiveOrWrapper(type)) { if (!type.isPrimitive()) { type = ClassUtils.wrapperToPrimitive(type); }//from www .j a v a 2 s . c om return type.getName(); } else if (type.getPackage().equals(Package.getPackage("java.lang"))) { return type.getSimpleName(); } else { String[] words = type.getName().split(" "); String fullClassName = words[words.length - 1]; String[] path = fullClassName.split("\\."); int i = 0; while (!Character.isUpperCase(path[i + 1].charAt(0))) { path[i] = path[i].substring(0, 1); i++; } return StringUtils.join(path, "."); } }
From source file:org.kie.workbench.common.screens.datamodeller.backend.server.DataModelTestUtil.java
private Object getAnnotationValue(java.lang.annotation.Annotation anno) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException { Class annoClass = anno.annotationType(); Object valueObj = null;//from w ww . j ava 2s . c o m try { Method valueMethod = annoClass.getDeclaredMethod(VALUE_METHOD_NAME, NO_CLASS_PARAMETERS); // value should be accessible -- if not, there's something wrong with the anno, not with us! valueObj = valueMethod.invoke(anno, NO_PARAMETERS); } catch (NoSuchMethodException nsme) { // no-op -- no value in anno } // In this test, the DefaultJavaRoasterModelAnnotationDriver is being used // (instead of the DefaultJavaModelAnnotationDriver) // which means that annotation values are stored as strings if (valueObj != null) { if (!ClassUtils.isPrimitiveOrWrapper(valueObj.getClass()) && !(valueObj instanceof String)) { valueObj = valueObj.toString(); } } return valueObj; }
From source file:org.kuali.coeus.sys.framework.model.KcPersistableBusinessObjectBase.java
@Override public String toString() { class BusinessObjectToStringBuilder extends ReflectionToStringBuilder { private BusinessObjectToStringBuilder(Object object) { super(object); }// w ww .j a v a 2s . c o m public boolean accept(Field field) { if (String.class.isAssignableFrom(field.getType()) || ClassUtils.isPrimitiveOrWrapper(field.getType())) { return true; } else { return false; } } } ; ReflectionToStringBuilder toStringBuilder = new BusinessObjectToStringBuilder(this); return toStringBuilder.toString(); }