List of usage examples for java.lang Boolean TYPE
Class TYPE
To view the source code for java.lang Boolean TYPE.
Click Source Link
From source file:net.sf.json.JSONDynaBean.java
/** * DOCUMENT ME!//ww w. ja v a 2 s . com * * @param dest DOCUMENT ME! * @param src DOCUMENT ME! * * @return DOCUMENT ME! */ protected boolean isDynaAssignable(Class dest, Class src) { boolean assignable = dest.isAssignableFrom(src); assignable = ((dest == Boolean.TYPE) && (src == Boolean.class)) ? true : assignable; assignable = ((dest == Byte.TYPE) && (src == Byte.class)) ? true : assignable; assignable = ((dest == Character.TYPE) && (src == Character.class)) ? true : assignable; assignable = ((dest == Short.TYPE) && (src == Short.class)) ? true : assignable; assignable = ((dest == Integer.TYPE) && (src == Integer.class)) ? true : assignable; assignable = ((dest == Long.TYPE) && (src == Long.class)) ? true : assignable; assignable = ((dest == Float.TYPE) && (src == Float.class)) ? true : assignable; assignable = ((dest == Double.TYPE) && (src == Double.class)) ? true : assignable; if ((src == Double.TYPE) || Double.class.isAssignableFrom(src)) { assignable = (isByte(dest) || isShort(dest) || isInteger(dest) || isLong(dest) || isFloat(dest)) ? true : assignable; } if ((src == Float.TYPE) || Float.class.isAssignableFrom(src)) { assignable = (isByte(dest) || isShort(dest) || isInteger(dest) || isLong(dest)) ? true : assignable; } if ((src == Long.TYPE) || Long.class.isAssignableFrom(src)) { assignable = (isByte(dest) || isShort(dest) || isInteger(dest)) ? true : assignable; } if ((src == Integer.TYPE) || Integer.class.isAssignableFrom(src)) { assignable = (isByte(dest) || isShort(dest)) ? true : assignable; } if ((src == Short.TYPE) || Short.class.isAssignableFrom(src)) { assignable = (isByte(dest)) ? true : assignable; } return assignable; }
From source file:org.wisdom.template.thymeleaf.OgnlOpsByReflectionTest.java
@Test public void testConvertValue() throws Exception { Class[] classes = new Class[] { Object.class, Class.class }; // Null value assertThat(invoke("convertValue", classes, null, Long.TYPE)).isEqualTo(0l); assertThat(invoke("convertValue", classes, null, String.class)).isNull(); // Primitive/*from w ww .ja va2 s .co m*/ assertThat(invoke("convertValue", classes, "42", Integer.class)).isEqualTo(42); assertThat(invoke("convertValue", classes, "42", Integer.TYPE)).isEqualTo(42); assertThat(invoke("convertValue", classes, "42", Byte.class)).isEqualTo(Byte.valueOf("42")); assertThat(invoke("convertValue", classes, "42", Byte.TYPE)).isEqualTo(Byte.valueOf("42")); assertThat(invoke("convertValue", classes, "42", Short.class)).isEqualTo(Short.valueOf("42")); assertThat(invoke("convertValue", classes, "42", Short.TYPE)).isEqualTo(Short.valueOf("42")); assertThat(invoke("convertValue", classes, String.valueOf((int) 'c'), Character.class)).isEqualTo('c'); assertThat(invoke("convertValue", classes, String.valueOf((int) 'c'), Character.TYPE)).isEqualTo('c'); assertThat(invoke("convertValue", classes, "42", Long.class)).isEqualTo(42l); assertThat(invoke("convertValue", classes, "42", Long.TYPE)).isEqualTo(42l); assertThat(invoke("convertValue", classes, "true", Boolean.class)).isEqualTo(true); assertThat(invoke("convertValue", classes, "true", Boolean.TYPE)).isEqualTo(true); assertThat(invoke("convertValue", classes, "42", Double.class)).isEqualTo(42.0); assertThat(invoke("convertValue", classes, "42", Double.TYPE)).isEqualTo(42.0); assertThat(invoke("convertValue", classes, "42", Float.class)).isEqualTo(42.0f); assertThat(invoke("convertValue", classes, "42", Float.TYPE)).isEqualTo(42.0f); // BigInteger, BigDecimal and String assertThat(invoke("convertValue", classes, "42", BigDecimal.class)).isEqualTo(new BigDecimal("42")); assertThat(invoke("convertValue", classes, "42", BigInteger.class)).isEqualTo(new BigInteger("42")); assertThat(invoke("convertValue", classes, "42", String.class)).isEqualTo("42"); //Array assertThat(invoke("convertValue", classes, new Object[] { 1, 2, 3 }, (new int[0]).getClass())).isNotNull(); }
From source file:de.knightsoftnet.validators.rebind.GwtSpecificValidatorCreator.java
/** * Finds the type that a constraint validator will check. * * <p>//from w ww. j a v a 2 s . c om * This type comes from the first parameter of the isValid() method on the constraint validator. * However, this is a bit tricky because ConstraintValidator has a parameterized type. When using * Java reflection, we will see multiple isValid() methods, including one that checks * java.lang.Object. * </p> * * <p> * Strategy: for now, assume there are at most two isValid() methods. If there are two, assume one * of them has a type that is assignable from the other. (Most likely, one of them will be * java.lang.Object.) * </p> * * @throws IllegalStateException if there isn't any isValid() method or there are more than two. */ static <T extends Annotation> Class<?> getTypeOfConstraintValidator( final Class<? extends ConstraintValidator<T, ?>> constraintClass) { int candidateCount = 0; Class<?> result = null; for (final Method method : constraintClass.getMethods()) { if (method.getName().equals("isValid") && method.getParameterTypes().length == 2 && method.getReturnType().isAssignableFrom(Boolean.TYPE)) { final Class<?> firstArgType = method.getParameterTypes()[0]; if (result == null || result.isAssignableFrom(firstArgType)) { result = firstArgType; } candidateCount++; } } if (candidateCount == 0) { throw new IllegalStateException("ConstraintValidators must have a isValid method"); } else if (candidateCount > 2) { throw new IllegalStateException("ConstraintValidators must have no more than two isValid methods"); } return result; }
From source file:org.assertj.assertions.generator.util.ClassUtil.java
public static boolean isPredicate(Method method) { return isValidPredicateName(method.getName()) && (Boolean.TYPE.equals(method.getReturnType()) || Boolean.class.equals(method.getReturnType())) && method.getParameterTypes().length == 0; }
From source file:com.icesoft.faces.renderkit.dom_html_basic.MenuRenderer.java
protected Object convertArray(FacesContext facesContext, UISelectMany uiSelectMany, Class componentType, String[] newSubmittedValues) throws ConverterException { // component type of String means no conversion is necessary if (componentType.equals(String.class)) { return newSubmittedValues; }//w w w . j a v a 2s.c o m // if newSubmittedValue is null return zero-length array if (newSubmittedValues == null) { return Array.newInstance(componentType, 0); } // create the array with specified component length int numberOfValues = newSubmittedValues.length; Object convertedValues = Array.newInstance(componentType, numberOfValues); // Determine if a converter is explicitly registered with the component Converter converter = uiSelectMany.getConverter(); if (converter == null) { // Determine if there is a default converter for the class converter = getConverterForClass(componentType); } if (converter == null) { // we don't need to convert base Object types if (componentType.equals(Object.class)) { return newSubmittedValues; } else { throw new ConverterException("Converter is null"); } } for (int index = 0; index < numberOfValues; index++) { // convert the next element Object nextConvertedElement = converter.getAsObject(facesContext, uiSelectMany, newSubmittedValues[index]); if (!componentType.isPrimitive()) { Array.set(convertedValues, index, nextConvertedElement); } else if (componentType.equals(Boolean.TYPE)) { Array.setBoolean(convertedValues, index, ((Boolean) nextConvertedElement).booleanValue()); } else if (componentType.equals(Integer.TYPE)) { Array.setInt(convertedValues, index, ((Integer) nextConvertedElement).intValue()); } else if (componentType.equals(Long.TYPE)) { Array.setLong(convertedValues, index, ((Long) nextConvertedElement).longValue()); } else if (componentType.equals(Short.TYPE)) { Array.setShort(convertedValues, index, ((Short) nextConvertedElement).shortValue()); } else if (componentType.equals(Byte.TYPE)) { Array.setByte(convertedValues, index, ((Byte) nextConvertedElement).byteValue()); } else if (componentType.equals(Float.TYPE)) { Array.setFloat(convertedValues, index, ((Float) nextConvertedElement).floatValue()); } else if (componentType.equals(Double.TYPE)) { Array.setDouble(convertedValues, index, ((Double) nextConvertedElement).doubleValue()); } else if (componentType.equals(Character.TYPE)) { Array.setChar(convertedValues, index, ((Character) nextConvertedElement).charValue()); } } return convertedValues; }
From source file:org.sparkcommerce.openadmin.server.service.persistence.module.BasicPersistenceModule.java
protected Class<?> getBasicSparkType(SupportedFieldType fieldType) { Class<?> response;/* ww w.j a va2 s. c o m*/ switch (fieldType) { case BOOLEAN: response = Boolean.TYPE; break; case DATE: response = Date.class; break; case DECIMAL: response = BigDecimal.class; break; case MONEY: response = Money.class; break; case INTEGER: response = Integer.TYPE; break; case UNKNOWN: response = null; break; default: response = String.class; break; } return response; }
From source file:com.desno365.mods.Activities.MainActivity.java
@Override public boolean onPrepareOptionsPanel(View view, Menu menu) { //add icons near menu items if (menu != null) { if (menu.getClass().getSimpleName().equals("MenuBuilder")) { try { Method m = menu.getClass().getDeclaredMethod("setOptionalIconsVisible", Boolean.TYPE); m.setAccessible(true);/*from w w w .j a v a2 s . com*/ m.invoke(menu, true); } catch (NoSuchMethodException e) { Log.e(TAG, "onMenuOpened", e); } catch (Exception e) { throw new RuntimeException(e); } } } return super.onPrepareOptionsPanel(view, menu); }
From source file:com.jaliansystems.activeMQLite.impl.ObjectRepository.java
private boolean paramMatches(Method method, Object[] params) { Class<?>[] parameterTypes = method.getParameterTypes(); if (params != null && parameterTypes.length != params.length || params == null && parameterTypes.length != 0) return false; for (int i = 0; i < parameterTypes.length; i++) { Class<?> class1 = parameterTypes[i]; if (!class1.isPrimitive() && params[i] == null) continue; if (params[i] instanceof ObjectHandle) { params[i] = getObject(((ObjectHandle) params[i])); }/* w ww . j ava 2 s .com*/ if (class1.isPrimitive()) { if (params[i] instanceof Boolean && class1 != Boolean.TYPE) return false; if (params[i] instanceof Integer && class1 != Integer.TYPE) return false; if (params[i] instanceof Long && class1 != Long.TYPE) return false; if (params[i] instanceof Short && class1 != Short.TYPE) return false; if (params[i] instanceof Float && class1 != Float.TYPE) return false; if (params[i] instanceof Double && class1 != Double.TYPE) return false; if (params[i] instanceof Byte && class1 != Byte.TYPE) return false; } else if (!class1.isInstance(params[i])) return false; } return true; }
From source file:com.mawujun.util.AnnotationUtils.java
/** * Helper method for comparing two objects of an array type. * * @param componentType the component type of the array * @param o1 the first object//from w w w .j ava2s . c o m * @param o2 the second object * @return a flag whether these objects are equal */ private static boolean arrayMemberEquals(Class<?> componentType, Object o1, Object o2) { if (componentType.isAnnotation()) { return annotationArrayMemberEquals((Annotation[]) o1, (Annotation[]) o2); } if (componentType.equals(Byte.TYPE)) { return Arrays.equals((byte[]) o1, (byte[]) o2); } if (componentType.equals(Short.TYPE)) { return Arrays.equals((short[]) o1, (short[]) o2); } if (componentType.equals(Integer.TYPE)) { return Arrays.equals((int[]) o1, (int[]) o2); } if (componentType.equals(Character.TYPE)) { return Arrays.equals((char[]) o1, (char[]) o2); } if (componentType.equals(Long.TYPE)) { return Arrays.equals((long[]) o1, (long[]) o2); } if (componentType.equals(Float.TYPE)) { return Arrays.equals((float[]) o1, (float[]) o2); } if (componentType.equals(Double.TYPE)) { return Arrays.equals((double[]) o1, (double[]) o2); } if (componentType.equals(Boolean.TYPE)) { return Arrays.equals((boolean[]) o1, (boolean[]) o2); } return Arrays.equals((Object[]) o1, (Object[]) o2); }
From source file:com.haulmont.restapi.service.QueriesControllerManager.java
protected Object toObject(Class clazz, String value) throws ParseException { if (clazz.isArray()) { Class componentType = clazz.getComponentType(); JsonParser jsonParser = new JsonParser(); JsonArray jsonArray = jsonParser.parse(value).getAsJsonArray(); List result = new ArrayList(); for (JsonElement jsonElement : jsonArray) { String stringValue = (jsonElement.isJsonPrimitive() && jsonElement.getAsJsonPrimitive().isString()) ? jsonElement.getAsJsonPrimitive().getAsString() : jsonElement.toString(); Object arrayElementValue = toObject(componentType, stringValue); result.add(arrayElementValue); }/*from w w w. java 2s . c o m*/ return result; } if (String.class == clazz) return value; if (Integer.class == clazz || Integer.TYPE == clazz || Byte.class == clazz || Byte.TYPE == clazz || Short.class == clazz || Short.TYPE == clazz) return Datatypes.getNN(Integer.class).parse(value); if (Date.class == clazz) { try { return Datatypes.getNN(Date.class).parse(value); } catch (ParseException e) { try { return Datatypes.getNN(java.sql.Date.class).parse(value); } catch (ParseException e1) { return Datatypes.getNN(Time.class).parse(value); } } } if (BigDecimal.class == clazz) return Datatypes.getNN(BigDecimal.class).parse(value); if (Boolean.class == clazz || Boolean.TYPE == clazz) return Datatypes.getNN(Boolean.class).parse(value); if (Long.class == clazz || Long.TYPE == clazz) return Datatypes.getNN(Long.class).parse(value); if (Double.class == clazz || Double.TYPE == clazz || Float.class == clazz || Float.TYPE == clazz) return Datatypes.getNN(Double.class).parse(value); if (UUID.class == clazz) return UUID.fromString(value); throw new IllegalArgumentException("Parameters of type " + clazz.getName() + " are not supported"); }