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.echocat.jemoni.jmx.support.CacheDynamicMBean.java
@Nonnull protected MBeanOperationInfo[] getOperations() { final List<MBeanOperationInfo> result = new ArrayList<>(); result.add(new MBeanOperationInfo("get", null, new MBeanParameterInfo[] { new MBeanParameterInfo("key", String.class.getName(), null) }, String.class.getName(), ACTION)); result.add(new MBeanOperationInfo("remove", null, new MBeanParameterInfo[] { new MBeanParameterInfo("key", String.class.getName(), null) }, Void.TYPE.getName(), ACTION)); result.add(new MBeanOperationInfo("contains", null, new MBeanParameterInfo[] { new MBeanParameterInfo("key", String.class.getName(), null) }, Boolean.TYPE.getName(), ACTION)); if (_cache instanceof KeysEnabledCache) { result.add(new MBeanOperationInfo("getKeys", null, new MBeanParameterInfo[] { new MBeanParameterInfo("limit", Integer.class.getName(), null) }, String.class.getName(), ACTION)); }//from w w w .j a v a2s .c om if (_cache instanceof ClearableCache) { result.add( new MBeanOperationInfo("clear", null, new MBeanParameterInfo[0], Void.TYPE.getName(), ACTION)); } if (_cache instanceof StatisticsEnabledCache) { result.add(new MBeanOperationInfo("resetStatistics", null, new MBeanParameterInfo[0], Void.TYPE.getName(), ACTION)); } if (_cache instanceof ListenerEnabledCache) { result.add(new MBeanOperationInfo("getListeners", null, new MBeanParameterInfo[0], String.class.getName(), ACTION)); } return result.toArray(new MBeanOperationInfo[result.size()]); }
From source file:com.sun.faces.el.impl.Coercions.java
/** * Coerces the given value to the specified class. *//*from w w w .ja v a 2 s . c om*/ public static Object coerce(Object pValue, Class pClass) throws ElException { if (pClass == String.class) { return coerceToString(pValue); } else if (isNumberClass(pClass)) { return coerceToPrimitiveNumber(pValue, pClass); } else if (pClass == Character.class || pClass == Character.TYPE) { return coerceToCharacter(pValue); } else if (pClass == Boolean.class || pClass == Boolean.TYPE) { return coerceToBoolean(pValue); } else { return coerceToObject(pValue, pClass); } }
From source file:org.yestech.jmlnitrate.transformation.inbound.BaseInboundTransformation.java
/** * Returns the Class Type for a Primitive type. * * @param classType Description of the Parameter * @return the Class Type//from w w w. j a v a2s . co m * @exception Exception Description of the Exception */ private Class getClass(String classType) throws Exception { TransformationParameter classParameter = TransformationParameter.getByName(classType); Class type = null; if (classParameter != null) { if (classParameter.equals(TransformationParameter.INT)) { //int type = Integer.TYPE; } else if (classParameter.equals(TransformationParameter.LONG)) { //long type = Long.TYPE; } else if (classParameter.equals(TransformationParameter.FLOAT)) { //float type = Float.TYPE; } else if (classParameter.equals(TransformationParameter.DOUBLE)) { //double type = Double.TYPE; } else if (classParameter.equals(TransformationParameter.BOOLEAN)) { //boolean type = Boolean.TYPE; } else if (classParameter.equals(TransformationParameter.CHAR)) { //char type = Character.TYPE; } else if (classParameter.equals(TransformationParameter.BYTE)) { //byte type = Byte.TYPE; } else { logger.error("Not a valid Class Type..."); throw new IllegalArgumentException("Not a valid Class Type..."); } } else { type = Clazz.getClass(classType); } return type; }
From source file:org.fhcrc.cpl.toolbox.filehandler.TabLoader.java
private void initColumnInfos(Class clazz) { PropertyDescriptor origDescriptors[] = PropertyUtils.getPropertyDescriptors(clazz); HashMap<String, PropertyDescriptor> mappedPropNames = new HashMap<String, PropertyDescriptor>(); for (PropertyDescriptor origDescriptor : origDescriptors) { if (origDescriptor.getName().equals("class")) continue; mappedPropNames.put(origDescriptor.getName().toLowerCase(), origDescriptor); }//from www . j av a2 s . c o m boolean isMapClass = java.util.Map.class.isAssignableFrom(clazz); for (ColumnDescriptor column : _columns) { PropertyDescriptor prop = mappedPropNames.get(column.name.toLowerCase()); if (null != prop) { column.name = prop.getName(); column.clazz = prop.getPropertyType(); column.isProperty = true; column.setter = prop.getWriteMethod(); if (column.clazz.isPrimitive()) { if (Float.TYPE.equals(column.clazz)) column.missingValues = 0.0F; else if (Double.TYPE.equals(column.clazz)) column.missingValues = 0.0; else if (Boolean.TYPE.equals(column.clazz)) column.missingValues = Boolean.FALSE; else column.missingValues = 0; //Will get converted. } } else if (isMapClass) { column.isProperty = false; } else { column.load = false; } } }
From source file:nl.strohalm.cyclos.controls.members.messages.SendMessageAction.java
private <T extends SendMessageDTO> BeanBinder<T> basicDataBinderFor(final Class<T> type) { final BeanBinder<T> binder = BeanBinder.instance(type); // The body is not read here, as it can be either plain text or html binder.registerBinder("category", PropertyBinder.instance(MessageCategory.class, "category")); binder.registerBinder("subject", PropertyBinder.instance(String.class, "subject")); binder.registerBinder("inReplyTo", PropertyBinder.instance(Message.class, "inReplyTo")); binder.registerBinder("html", PropertyBinder.instance(Boolean.TYPE, "html")); return binder; }
From source file:iing.uabc.edu.mx.persistencia.util.JSON.java
private static void stringifyObject(JsonGenerator generator, BeanManager manager) { String keyName;/* w w w .ja v a2 s. c om*/ Field[] fields = manager.getFields(); //Read every field and transform it to a json property string for (Field field : fields) { Class fieldType = manager.getType(field.getName()); keyName = field.getName(); Object value = manager.getProperty(keyName); System.out.println("KeyName: " + keyName); System.out.println("Valor " + keyName + ": " + value); if (value == null) { //Set to null the property generator.writeNull(keyName); continue; } //Is a String if (fieldType == String.class) { generator.write(keyName, String.valueOf(value)); } //Is a Date else if (fieldType == Date.class) { String date = DateFormatUtils.ISO_DATETIME_TIME_ZONE_FORMAT.format(value); generator.write(keyName, date); } //Is a integer else if (fieldType == Integer.class || fieldType == Integer.TYPE) { generator.write(keyName, (int) value); } //Is a double else if (fieldType == Double.class || fieldType == Double.TYPE) { generator.write(keyName, (double) value); } //Is boolean else if (fieldType == Boolean.class || fieldType == Boolean.TYPE) { generator.write(keyName, (boolean) value); } //Is a collection else if (value instanceof Collection) { Class elementClass = manager.getCollectionElementType(keyName); System.out.println("Nueva Colleccion [] de clase: " + elementClass.getSimpleName()); generator.writeStartArray(keyName); //Create new collection manager with the given class CollectionManager collectionManager = new CollectionManager((Collection) value, elementClass); stringifyArray(generator, collectionManager); generator.writeEnd(); } else { //Is a object... probably BeanManager objectManager = new BeanManager(value); System.out.println("Nuevo Objecto {}: " + value.getClass().getSimpleName()); generator.writeStartObject(keyName); stringifyObject(generator, objectManager); generator.writeEnd(); } } }
From source file:org.springframework.richclient.util.ClassUtils.java
private static Method getReadMethod(Class theClass, String propertyName) { // handle "embedded/dotted" properties if (propertyName.indexOf('.') > -1) { final int index = propertyName.indexOf('.'); final String firstPropertyName = propertyName.substring(0, index); final String restOfPropertyName = propertyName.substring(index + 1, propertyName.length()); final Class firstPropertyClass = getPropertyClass(theClass, firstPropertyName); return getReadMethod(firstPropertyClass, restOfPropertyName); }//from w w w . jav a 2s. co m final String getterName = "get" + propertyName.substring(0, 1).toUpperCase() + (propertyName.length() == 1 ? "" : propertyName.substring(1)); Method method = getMethod(theClass, getterName); if (method == null) { final String isserName = "is" + propertyName.substring(0, 1).toUpperCase() + (propertyName.length() == 1 ? "" : propertyName.substring(1)); method = getMethod(theClass, isserName); } if (method == null) { logger.info("There is not a getter for " + propertyName + " in " + theClass); return null; } if (!Modifier.isPublic(method.getModifiers())) { logger.warn("The getter for " + propertyName + " in " + theClass + " is not public: " + method); return null; } if (Void.TYPE.equals(method.getReturnType())) { logger.warn("The getter for " + propertyName + " in " + theClass + " returns void: " + method); return null; } if (method.getName().startsWith("is") && !(Boolean.class.equals(method.getReturnType()) || Boolean.TYPE.equals(method.getReturnType()))) { logger.warn("The getter for " + propertyName + " in " + theClass + " uses the boolean naming convention but is not boolean: " + method); return null; } return method; }
From source file:com.google.feedserver.util.BeanCliHelper.java
/** * For each class registered, we extract options based on the {@link Flag} * decorator set on each field in the bean. We use the help argument on the * decorator to set command line option usage text. * //from ww w . ja v a 2 s . c o m * Note: classes with identical flag field names will get overwritten with the * last one processed. TODO(rayc) support collision detection and use fully * qualified class name for flag option. * * see {@link Flag} for more info. * * @return Options all command-line options registered for parsing. */ private Options createOptions() { Options options = new Options(); options.addOption(new Option("help", false, "Print out usage.")); // Go through all registered beans. for (Object bean : beans) { // Go through all fields. for (Field field : bean.getClass().getDeclaredFields()) { Flag flag = field.getAnnotation(Flag.class); if (flag == null) { continue; // no decorator we move on. } // Check type we only support boolean, String and Integer. if ((field.getType() != Integer.class) && (field.getType() != Integer.TYPE) && (field.getType() != String.class) && (field.getType() != Boolean.class) && (field.getType() != Boolean.TYPE)) { throw new RuntimeException("Field: " + field.getName() + " flag type not supported"); } // Create options. String argName = field.getName(); if (field.getType().getName().equals(Boolean.class.getName()) || field.getType().getName().equals(Boolean.TYPE.getName())) { options.addOption(new Option(argName, false, flag.help())); options.addOption(new Option("no" + argName, false, flag.help())); } else { options.addOption(new Option(argName, true, flag.help())); } } } return options; }
From source file:com.initialxy.cordova.themeablebrowser.ThemeableBrowserUnmarshaller.java
/** * Gracefully convert given Object to given class given the precondition * that both are primitives or one of the classes associated with * primitives. eg. If val is of type Double and cls is of type int, return * Integer type with appropriate value truncation so that it can be assigned * to field with field.set()./*from ww w . ja va2s.c om*/ * * @param cls * @param val * @return * @throws com.initialxy.cordova.themeablebrowser.ThemeableBrowserUnmarshaller.TypeMismatchException */ private static Object convertToPrimitiveFieldObj(Object val, Class<?> cls) { Class<?> valClass = val.getClass(); Object result = null; try { Method getter = null; if (cls.isAssignableFrom(Byte.class) || cls.isAssignableFrom(Byte.TYPE)) { getter = valClass.getMethod("byteValue"); } else if (cls.isAssignableFrom(Short.class) || cls.isAssignableFrom(Short.TYPE)) { getter = valClass.getMethod("shortValue"); } else if (cls.isAssignableFrom(Integer.class) || cls.isAssignableFrom(Integer.TYPE)) { getter = valClass.getMethod("intValue"); } else if (cls.isAssignableFrom(Long.class) || cls.isAssignableFrom(Long.TYPE)) { getter = valClass.getMethod("longValue"); } else if (cls.isAssignableFrom(Float.class) || cls.isAssignableFrom(Float.TYPE)) { getter = valClass.getMethod("floatValue"); } else if (cls.isAssignableFrom(Double.class) || cls.isAssignableFrom(Double.TYPE)) { getter = valClass.getMethod("doubleValue"); } else if (cls.isAssignableFrom(Boolean.class) || cls.isAssignableFrom(Boolean.TYPE)) { if (val instanceof Boolean) { result = val; } else { throw new TypeMismatchException(cls, val.getClass()); } } else if (cls.isAssignableFrom(Character.class) || cls.isAssignableFrom(Character.TYPE)) { if (val instanceof String && ((String) val).length() == 1) { char c = ((String) val).charAt(0); result = Character.valueOf(c); } else if (val instanceof String) { throw new TypeMismatchException( "Expected Character, " + "but received String with length other than 1."); } else { throw new TypeMismatchException( String.format("Expected Character, accept String, but got %s.", val.getClass())); } } if (getter != null) { result = getter.invoke(val); } } catch (NoSuchMethodException e) { throw new TypeMismatchException(String.format("Cannot convert %s to %s.", val.getClass(), cls)); } catch (SecurityException e) { throw new TypeMismatchException(String.format("Cannot convert %s to %s.", val.getClass(), cls)); } catch (IllegalAccessException e) { throw new TypeMismatchException(String.format("Cannot convert %s to %s.", val.getClass(), cls)); } catch (InvocationTargetException e) { throw new TypeMismatchException(String.format("Cannot convert %s to %s.", val.getClass(), cls)); } return result; }
From source file:at.alladin.rmbt.shared.hstoreparser.HstoreParser.java
/** * get a specific key from json by preserving the fields type * @param json//from www . j ava 2 s .co m * @param key * @param toField * @return * @throws JSONException */ public static Object getFromJsonByField(JSONObject json, String key, Field toField) throws JSONException { final Object o = json.get(key); if (o != JSONObject.NULL) { if (toField.getType().equals(Integer.class) || toField.getType().equals(Integer.TYPE)) { return Integer.parseInt(String.valueOf(o)); } else if (toField.getType().equals(String.class)) { return o; } else if (toField.getType().equals(Long.class) || toField.getType().equals(Long.TYPE)) { return Long.parseLong(String.valueOf(o)); } else if (toField.getType().equals(Boolean.class) || toField.getType().equals(Boolean.TYPE)) { return Boolean.parseBoolean(String.valueOf(o)); } else if (toField.getType().equals(Float.class) || toField.getType().equals(Float.TYPE)) { return Float.parseFloat(String.valueOf(o)); } else if (toField.getType().equals(Double.class) || toField.getType().equals(Double.TYPE)) { return Double.parseDouble(String.valueOf(o)); } else { return o; } } return JSONObject.NULL; }