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:org.spring4gwt.server.RpcHelper.java
private static String printTypeName(Class<?> type) { // Primitives ///*from w w w. j a v a 2 s . c o m*/ if (type.equals(Integer.TYPE)) { return "int"; } else if (type.equals(Long.TYPE)) { return "long"; } else if (type.equals(Short.TYPE)) { return "short"; } else if (type.equals(Byte.TYPE)) { return "byte"; } else if (type.equals(Character.TYPE)) { return "char"; } else if (type.equals(Boolean.TYPE)) { return "boolean"; } else if (type.equals(Float.TYPE)) { return "float"; } else if (type.equals(Double.TYPE)) { return "double"; } // Arrays // if (type.isArray()) { Class<?> componentType = type.getComponentType(); return printTypeName(componentType) + "[]"; } // Everything else // return type.getName().replace('$', '.'); }
From source file:org.rhq.core.domain.server.PersistenceUtility.java
@SuppressWarnings("unchecked") // used in hibernate.jsp public static Object cast(String value, Type hibernateType) { if (hibernateType instanceof PrimitiveType) { Class<?> type = ((PrimitiveType) hibernateType).getPrimitiveClass(); if (type.equals(Byte.TYPE)) { return Byte.valueOf(value); } else if (type.equals(Short.TYPE)) { return Short.valueOf(value); } else if (type.equals(Integer.TYPE)) { return Integer.valueOf(value); } else if (type.equals(Long.TYPE)) { return Long.valueOf(value); } else if (type.equals(Float.TYPE)) { return Float.valueOf(value); } else if (type.equals(Double.TYPE)) { return Double.valueOf(value); } else if (type.equals(Boolean.TYPE)) { return Boolean.valueOf(value); }//from www .j a va 2 s . co m } else if (hibernateType instanceof EntityType) { String entityName = ((EntityType) hibernateType).getAssociatedEntityName(); try { Class<?> entityClass = Class.forName(entityName); Object entity = entityClass.newInstance(); Field primaryKeyField = entityClass.getDeclaredField("id"); primaryKeyField.setAccessible(true); primaryKeyField.setInt(entity, Integer.valueOf(value)); return entity; } catch (Throwable t) { throw new IllegalArgumentException("Type[" + entityName + "] must have PK field named 'id'"); } } else if (hibernateType instanceof CustomType) { if (Enum.class.isAssignableFrom(hibernateType.getReturnedClass())) { Class<? extends Enum<?>> enumClass = hibernateType.getReturnedClass(); Enum<?>[] enumValues = enumClass.getEnumConstants(); try { int enumOrdinal = Integer.valueOf(value); try { return enumValues[enumOrdinal]; } catch (ArrayIndexOutOfBoundsException aioobe) { throw new IllegalArgumentException("There is no " + enumClass.getSimpleName() + " enum with ordinal '" + enumOrdinal + "'"); } } catch (NumberFormatException nfe) { String ucaseValue = value.toUpperCase(); for (Enum<?> nextEnum : enumValues) { if (nextEnum.name().toUpperCase().equals(ucaseValue)) { return nextEnum; } } throw new IllegalArgumentException( "There is no " + enumClass.getSimpleName() + " enum with name '" + value + "'"); } } } return value; }
From source file:org.acmsl.commons.utils.ConversionUtils.java
/** * Converts given String to boolean, if given value is not null. * @param value the value to convert.//w w w .j a v a2 s . co m * @return the converted value. */ @Nullable public Boolean toBooleanIfNotNull(@Nullable final String value) { Boolean result = null; @Nullable final Converter t_Converter = ConvertUtils.lookup(Boolean.TYPE); if (t_Converter != null) { @Nullable final Object t_Result = t_Converter.convert(Boolean.TYPE, value); if (t_Result instanceof Boolean) { result = (Boolean) t_Result; } } return result; }
From source file:io.nuun.plugin.configuration.common.ConfigurationMembersInjector.java
@Override public void injectMembers(T instance) { NuunProperty injectConfigAnnotation = null; // The annotation is actual NuunProperty.class if (clonedAnno.annotationType() == NuunProperty.class) { injectConfigAnnotation = field.getAnnotation(NuunProperty.class); } else { // The annotation has the NuunProperty annotation on it we proxy it injectConfigAnnotation = AssertUtils.annotationProxyOf(NuunProperty.class, clonedAnno); }/*from ww w .ja va 2s .c o m*/ String configurationParameterName = injectConfigAnnotation.value(); // Pre verification // if (StringUtils.isEmpty(configurationParameterName)) { log.error("Value for annotation {} on field {} can not be null or empty.", clonedAnno.annotationType(), field.toGenericString()); throw new PluginException("Value for annotation %s on field %s can not be null or empty.", clonedAnno.annotationType(), field.toGenericString()); } if (!configuration.containsKey(configurationParameterName) && injectConfigAnnotation.mandatory()) { throw new PluginException("\"%s\" must be in one properties file for field %s.", configurationParameterName, field.toGenericString()); } try { this.field.setAccessible(true); Class<?> type = field.getType(); if (type == Integer.TYPE) { if (configuration.containsKey(configurationParameterName)) { field.setInt(instance, configuration.getInt(configurationParameterName)); } else { log.debug(NO_PROPERTY_FOUND_LOG_MESSAGE, configurationParameterName); field.setInt(instance, injectConfigAnnotation.defaultIntValue()); } } else if (type == Integer.class) { if (configuration.containsKey(configurationParameterName)) { field.set(instance, new Integer(configuration.getInt(configurationParameterName))); } else { log.debug(NO_PROPERTY_FOUND_LOG_MESSAGE, configurationParameterName); field.set(instance, new Integer(injectConfigAnnotation.defaultIntValue())); } } else if (type == Boolean.TYPE) { if (configuration.containsKey(configurationParameterName)) { field.setBoolean(instance, configuration.getBoolean(configurationParameterName)); } else { log.debug(NO_PROPERTY_FOUND_LOG_MESSAGE, configurationParameterName); field.setBoolean(instance, injectConfigAnnotation.defaultBooleanValue()); } } else if (type == Boolean.class) { if (configuration.containsKey(configurationParameterName)) { field.set(instance, new Boolean(configuration.getBoolean(configurationParameterName))); } else { log.debug(NO_PROPERTY_FOUND_LOG_MESSAGE, configurationParameterName); field.set(instance, new Boolean(injectConfigAnnotation.defaultBooleanValue())); } } else if (type == Short.TYPE) { if (configuration.containsKey(configurationParameterName)) { field.setShort(instance, configuration.getShort(configurationParameterName)); } else { log.debug(NO_PROPERTY_FOUND_LOG_MESSAGE, configurationParameterName); field.setShort(instance, injectConfigAnnotation.defaultShortValue()); } } else if (type == Short.class) { if (configuration.containsKey(configurationParameterName)) { field.set(instance, new Short(configuration.getShort(configurationParameterName))); } else { log.debug(NO_PROPERTY_FOUND_LOG_MESSAGE, configurationParameterName); field.set(instance, new Short(injectConfigAnnotation.defaultShortValue())); } } else if (type == Byte.TYPE) { if (configuration.containsKey(configurationParameterName)) { field.setByte(instance, configuration.getByte(configurationParameterName)); } else { log.debug(NO_PROPERTY_FOUND_LOG_MESSAGE, configurationParameterName); field.setByte(instance, injectConfigAnnotation.defaultByteValue()); } } else if (type == Byte.class) { if (configuration.containsKey(configurationParameterName)) { field.set(instance, new Byte(configuration.getByte(configurationParameterName))); } else { log.debug(NO_PROPERTY_FOUND_LOG_MESSAGE, configurationParameterName); field.set(instance, new Byte(injectConfigAnnotation.defaultByteValue())); } } else if (type == Long.TYPE) { if (configuration.containsKey(configurationParameterName)) { field.setLong(instance, configuration.getLong(configurationParameterName)); } else { log.debug(NO_PROPERTY_FOUND_LOG_MESSAGE, configurationParameterName); field.setLong(instance, injectConfigAnnotation.defaultLongValue()); } } else if (type == Long.class) { if (configuration.containsKey(configurationParameterName)) { field.set(instance, new Long(configuration.getLong(configurationParameterName))); } else { log.debug(NO_PROPERTY_FOUND_LOG_MESSAGE, configurationParameterName); field.set(instance, new Long(injectConfigAnnotation.defaultLongValue())); } } else if (type == Float.TYPE) { if (configuration.containsKey(configurationParameterName)) { field.setFloat(instance, configuration.getFloat(configurationParameterName)); } else { log.debug(NO_PROPERTY_FOUND_LOG_MESSAGE, configurationParameterName); field.setFloat(instance, injectConfigAnnotation.defaultFloatValue()); } } else if (type == Float.class) { if (configuration.containsKey(configurationParameterName)) { field.set(instance, new Float(configuration.getFloat(configurationParameterName))); } else { log.debug(NO_PROPERTY_FOUND_LOG_MESSAGE, configurationParameterName); field.set(instance, new Float(injectConfigAnnotation.defaultFloatValue())); } } else if (type == Double.TYPE) { if (configuration.containsKey(configurationParameterName)) { field.setDouble(instance, configuration.getDouble(configurationParameterName)); } else { log.debug(NO_PROPERTY_FOUND_LOG_MESSAGE, configurationParameterName); field.setDouble(instance, injectConfigAnnotation.defaultDoubleValue()); } } else if (type == Double.class) { if (configuration.containsKey(configurationParameterName)) { field.set(instance, new Double(configuration.getDouble(configurationParameterName))); } else { log.debug(NO_PROPERTY_FOUND_LOG_MESSAGE, configurationParameterName); field.set(instance, new Double(injectConfigAnnotation.defaultDoubleValue())); } } else if (type == Character.TYPE) { if (configuration.containsKey(configurationParameterName)) { field.setChar(instance, configuration.getString(configurationParameterName).charAt(0)); } } else if (type == Character.class) { if (configuration.containsKey(configurationParameterName)) { field.set(instance, new Character(configuration.getString(configurationParameterName).charAt(0))); } } else { Object property = getProperty(configurationParameterName, injectConfigAnnotation); field.set(instance, property); } } catch (IllegalArgumentException ex) { log.error("Wrong argument or argument type during configuration injection", ex); } catch (IllegalAccessException ex) { log.error("Illegal access during configuration injection", ex); } catch (InstantiationException ex) { log.error("Impossible to instantiate value converter", ex); } finally { this.field.setAccessible(false); } }
From source file:org.hyperic.hq.plugin.jboss.MBeanUtil.java
private static void initConverters() { addConverter(Object.class, new Converter() { public Object convert(String param) { return param; }/*from w w w .ja v a2s . c om*/ }); addConverter(Short.class, new Converter() { public Object convert(String param) { return Short.valueOf(param); } }); addConverter(Integer.class, new Converter() { public Object convert(String param) { return Integer.valueOf(param); } }); addConverter(Long.class, new Converter() { public Object convert(String param) { return Long.valueOf(param); } }); addConverter(Double.class, new Converter() { public Object convert(String param) { return Double.valueOf(param); } }); addConverter(Boolean.class, new Converter() { public Object convert(String param) { return Boolean.valueOf(param); } }); addConverter(File.class, new Converter() { public Object convert(String param) { return new File(param); } }); addConverter(URL.class, new Converter() { public Object convert(String param) { try { return new URL(param); } catch (MalformedURLException e) { throw invalid(param, e); } } }); addConverter(ObjectName.class, new Converter() { public Object convert(String param) { try { return new ObjectName(param); } catch (MalformedObjectNameException e) { throw invalid(param, e); } } }); addConverter(List.class, new ListConverter() { public Object convert(String[] params) { return Arrays.asList(params); } }); addConverter(String[].class, new ListConverter() { public Object convert(String[] params) { return params; } }); Class[][] aliases = { { String.class, Object.class }, { Short.TYPE, Short.class }, { Integer.TYPE, Integer.class }, { Long.TYPE, Long.class }, { Double.TYPE, Double.class }, { Boolean.TYPE, Boolean.class }, }; for (int i = 0; i < aliases.length; i++) { addConverter(aliases[i][0], aliases[i][1]); } }
From source file:org.trianacode.taskgraph.tool.ClassLoaders.java
public static Class forName(String className) throws ClassNotFoundException { className = getTextClassName(className); boolean isArray = false; int dims = 0; if (className.endsWith("[]")) { isArray = true;// ww w . jav a 2 s .co m dims = className.substring(className.indexOf("[]"), className.length()).length() / 2; className = className.substring(0, className.indexOf("[]")); } Class cls; if (className.equals("boolean")) { cls = Boolean.TYPE; } else if (className.equals("char")) { cls = Character.TYPE; } else if (className.equals("byte")) { cls = Byte.TYPE; } else if (className.equals("short")) { cls = Short.TYPE; } else if (className.equals("int")) { cls = Integer.TYPE; } else if (className.equals("long")) { cls = Long.TYPE; } else if (className.equals("float")) { cls = Float.TYPE; } else if (className.equals("double")) { cls = Double.TYPE; } else if (className.equals("void")) { cls = void.class; } else { cls = loadClass(className); } if (isArray) { Object arr = Array.newInstance(cls, new int[dims]); cls = arr.getClass(); } return cls; }
From source file:org.apache.struts2.s1.DynaBeanPropertyAccessorTest.java
/** * Create and return a <code>DynaClass</code> instance for our test * <code>DynaBean</code>./*from www . j a va 2 s . c o m*/ */ protected DynaClass createDynaClass() { int intArray[] = new int[0]; String stringArray[] = new String[0]; DynaClass dynaClass = new BasicDynaClass("TestDynaClass", null, new DynaProperty[] { new DynaProperty("booleanProperty", Boolean.TYPE), new DynaProperty("booleanSecond", Boolean.TYPE), new DynaProperty("doubleProperty", Double.TYPE), new DynaProperty("floatProperty", Float.TYPE), new DynaProperty("intArray", intArray.getClass()), new DynaProperty("intIndexed", intArray.getClass()), new DynaProperty("intProperty", Integer.TYPE), new DynaProperty("listIndexed", List.class), new DynaProperty("longProperty", Long.TYPE), new DynaProperty("mappedProperty", Map.class), new DynaProperty("mappedIntProperty", Map.class), new DynaProperty("nullProperty", String.class), new DynaProperty("shortProperty", Short.TYPE), new DynaProperty("stringArray", stringArray.getClass()), new DynaProperty("stringIndexed", stringArray.getClass()), new DynaProperty("stringProperty", String.class), }); return (dynaClass); }
From source file:MethodHashing.java
static String getTypeString(Class cl) { if (cl == Byte.TYPE) { return "B"; } else if (cl == Character.TYPE) { return "C"; } else if (cl == Double.TYPE) { return "D"; } else if (cl == Float.TYPE) { return "F"; } else if (cl == Integer.TYPE) { return "I"; } else if (cl == Long.TYPE) { return "J"; } else if (cl == Short.TYPE) { return "S"; } else if (cl == Boolean.TYPE) { return "Z"; } else if (cl == Void.TYPE) { return "V"; } else if (cl.isArray()) { return "[" + getTypeString(cl.getComponentType()); } else {//from w ww.j av a2 s .com return "L" + cl.getName().replace('.', '/') + ";"; } }
From source file:org.wrml.runtime.schema.PropertyProtoSlot.java
PropertyProtoSlot(final Prototype prototype, final String slotName, final Property property) { super(prototype, slotName); if (property == null) { throw new NullPointerException( "Prototype (" + prototype + ") Slot (" + slotName + ") property cannot be null."); }/*from w ww .ja va2 s .co m*/ _Property = property; final Type heapValueType = getHeapValueType(); final SyntaxLoader syntaxLoader = getContext().getSyntaxLoader(); final DefaultValue defaultValue = getAnnotation(DefaultValue.class); if (defaultValue != null) { final String defaultValueString = defaultValue.value(); try { _DefaultValue = syntaxLoader.parseSyntacticText(defaultValueString, heapValueType); } catch (final Exception e) { throw new PrototypeException(prototype + " slot named \"" + slotName + "\" default value annotation's value could not be converted from text value \"" + defaultValueString + "\" to a Java " + heapValueType + ". Detail message: " + e.getMessage(), e, prototype, slotName); } } if (Boolean.TYPE.equals(heapValueType)) { if (_DefaultValue == null) { _DefaultValue = Boolean.FALSE; } } else if (TypeUtils.isAssignable(heapValueType, Enum.class)) { if (_DefaultValue == null) { // Enum's default to their first constant // Single selects default to the first choice @SuppressWarnings("unchecked") final Class<Enum<?>> enumValueType = (Class<Enum<?>>) heapValueType; if (enumValueType != null) { final Enum<?>[] enumChoices = enumValueType.getEnumConstants(); if (enumChoices != null && enumChoices.length > 0) { _DefaultValue = enumChoices[0]; } } } } else if (TypeUtils.isAssignable(heapValueType, Number.class) || Integer.TYPE.equals(heapValueType) || Long.TYPE.equals(heapValueType) || Double.TYPE.equals(heapValueType)) { if (_DefaultValue == null && Integer.TYPE.equals(heapValueType) || Long.TYPE.equals(heapValueType) || Double.TYPE.equals(heapValueType)) { _DefaultValue = getValueType().getDefaultValue(); } // isolate() { final MinimumValue minimumValue = getAnnotation(MinimumValue.class); if (minimumValue != null) { final String minimumValueString = minimumValue.value(); try { _MinimumValue = syntaxLoader.parseSyntacticText(minimumValueString, heapValueType); } catch (final Exception e) { throw new PrototypeException(prototype + " slot named \"" + slotName + "\" minimum value annotation's value could not be converted from text value \"" + minimumValueString + "\" to a Java " + heapValueType + ". Detail message: " + e.getMessage(), e, prototype, slotName); } _IsExclusiveMinimum = minimumValue.exclusive(); } } // isolate() { final MaximumValue maximumValue = getAnnotation(MaximumValue.class); if (maximumValue != null) { final String maximumValueString = maximumValue.value(); try { _MaximumValue = syntaxLoader.parseSyntacticText(maximumValueString, heapValueType); } catch (final Exception e) { throw new PrototypeException(prototype + " slot named \"" + slotName + "\" maximum value annotation's value could not be converted from text value \"" + maximumValueString + "\" to a Java " + heapValueType + ". Detail message: " + e.getMessage(), e, prototype, slotName); } _IsExclusiveMaximum = maximumValue.exclusive(); } } // isolate() { final DivisibleByValue divisibleByValue = getAnnotation(DivisibleByValue.class); if (divisibleByValue != null && // The "divisible by" constraint does not apply to doubles !Double.TYPE.equals(heapValueType) && !TypeUtils.isAssignable(heapValueType, Double.class)) { final String divisibleByValueString = divisibleByValue.value(); try { _DivisibleByValue = syntaxLoader.parseSyntacticText(divisibleByValueString, heapValueType); } catch (final Exception e) { throw new PrototypeException(prototype + " slot named \"" + slotName + "\" divisibleBy value annotation's value could not be converted from text value \"" + divisibleByValueString + "\" to a Java " + heapValueType + ". Detail message: " + e.getMessage(), e, prototype, slotName); } if (_DivisibleByValue.equals(0)) { throw new PrototypeException(prototype + " slot named \"" + slotName + "\" divisibleBy value annotation's value could not be converted from text value \"" + divisibleByValueString + "\" to a Java " + heapValueType + ". Detail message: " + "zero value", null, prototype, slotName); } } } // isolate() { final DisallowedValues disallowedValues = getAnnotation(DisallowedValues.class); if (disallowedValues != null) { final String[] disallowedValuesArray = disallowedValues.value(); if (disallowedValuesArray != null) { _DisallowedValues = new LinkedHashSet<>(disallowedValuesArray.length); for (final String disallowedValueString : disallowedValuesArray) { final Object disallowedValue = syntaxLoader.parseSyntacticText(disallowedValueString, heapValueType); _DisallowedValues.add(disallowedValue); } } } } } else if (String.class.equals(heapValueType)) { final MinimumLength minimumLength = getAnnotation(MinimumLength.class); if (minimumLength != null) { _MinimumLength = minimumLength.value(); } final MaximumLength maximumLength = getAnnotation(MaximumLength.class); if (maximumLength != null) { _MaximumLength = maximumLength.value(); } final Multiline multiline = getAnnotation(Multiline.class); if (multiline != null) { _IsMultiline = true; } final DisallowedValues disallowedValues = getAnnotation(DisallowedValues.class); if (disallowedValues != null) { final String[] disallowedValuesArray = disallowedValues.value(); if (disallowedValuesArray != null) { _DisallowedValues = new LinkedHashSet<>(disallowedValuesArray.length); _DisallowedValues.addAll(Arrays.asList(disallowedValuesArray)); } } } else if (TypeUtils.isAssignable(heapValueType, Collection.class)) { final MinimumSize minimumSize = getAnnotation(MinimumSize.class); if (minimumSize != null) { _MinimumSize = minimumSize.value(); } final MaximumSize maximumSize = getAnnotation(MaximumSize.class); if (maximumSize != null) { _MaximumSize = maximumSize.value(); } } final Searchable searchable = getAnnotation(Searchable.class); if (searchable != null) { _Searchable = true; } }
From source file:candr.yoclip.option.OptionField.java
/** * Indicates when an option is used a value must also be included. * * @return {@code true} is a value is required, {@code false} otherwise. *//*from ww w . ja v a 2s . co m*/ @Override public boolean hasValue() { boolean hasValue = false; // allow a boolean to be explicitly set true or false if (Boolean.TYPE.equals(getField().getType()) || Boolean.class.isAssignableFrom(getField().getType())) { hasValue = option.hasValue(); } else if (option.name().length > 0) { // arguments do not have names hasValue = true; } return hasValue; }