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:com.sf.ddao.orm.RSMapperFactoryRegistry.java
public static RowMapperFactory getScalarRowMapperFactory(final Type itemType, final String name, boolean req) { if (itemType == String.class) { return new ScalarRMF() { public Object map(ResultSet rs) throws SQLException { return rs.getString(name); }//from w w w .jav a2 s .c o m }; } if (itemType == Integer.class || itemType == Integer.TYPE) { return new ScalarRMF() { public Object map(ResultSet rs) throws SQLException { return rs.getInt(name); } }; } if (itemType == URL.class) { return new ScalarRMF() { public Object map(ResultSet rs) throws SQLException { return rs.getURL(name); } }; } if (itemType == BigInteger.class) { return new ScalarRMF() { public Object map(ResultSet rs) throws SQLException { final BigDecimal res = rs.getBigDecimal(name); return res == null ? null : res.toBigInteger(); } }; } if (itemType == BigDecimal.class) { return new ScalarRMF() { public Object map(ResultSet rs) throws SQLException { return rs.getBigDecimal(name); } }; } if (itemType == InputStream.class) { return new ScalarRMF() { public Object map(ResultSet rs) throws SQLException { return rs.getBinaryStream(name); } }; } if (itemType == Boolean.class || itemType == Boolean.TYPE) { return new ScalarRMF() { public Object map(ResultSet rs) throws SQLException { return rs.getBoolean(name); } }; } if (itemType == Blob.class) { return new ScalarRMF() { public Object map(ResultSet rs) throws SQLException { return rs.getBlob(name); } }; } if (itemType == java.sql.Date.class || itemType == java.util.Date.class) { return new ScalarRMF() { public Object map(ResultSet rs) throws SQLException { return rs.getTimestamp(name); } }; } if (itemType instanceof Class) { final Class itemClass = (Class) itemType; final ColumnMapper columnMapper = ColumnMapperRegistry.lookup(itemClass); if (columnMapper != null) { return new ScalarRMF() { public Object map(ResultSet rs) throws SQLException { return columnMapper.map(rs, name); } }; } final Converter converter = ConvertUtils.lookup(itemClass); if (converter != null) { return new ScalarRMF() { public Object map(ResultSet rs) throws SQLException { String s = rs.getString(name); if (s == null) { return null; } return converter.convert(itemClass, s); } }; } if (Enum.class.isAssignableFrom((Class<?>) itemType)) { return new ScalarRMF() { public Object map(ResultSet rs) throws SQLException { String s = rs.getString(name); if (s == null) { return null; } //noinspection unchecked return Enum.valueOf((Class<Enum>) itemType, s); } }; } } if (req) { throw new IllegalArgumentException("no mapping defined for " + itemType); } return null; }
From source file:org.lunarray.model.descriptor.converter.def.AbstractDefaultConverterTool.java
/** * Populates the simple converters./*from w w w . j a v a 2 s .c o m*/ */ private void populateSimpleConverters() { // Primitives. this.converters.put(Integer.TYPE, new IntegerConverter()); this.converters.put(Double.TYPE, new DoubleConverter()); this.converters.put(Float.TYPE, new FloatConverter()); this.converters.put(Long.TYPE, new LongConverter()); this.converters.put(Byte.TYPE, new ByteConverter()); this.converters.put(Short.TYPE, new ShortConverter()); this.converters.put(Character.TYPE, new CharacterConverter()); this.converters.put(Boolean.TYPE, new BooleanConverter()); // Date types. this.addConverter(new CalendarConverter()); this.addConverter(new DateConverter()); // SQL Date types. this.addConverter(new SqlDateConverter()); this.addConverter(new SqlTimeConverter()); this.addConverter(new SqlTimestampConverter()); // String. this.addConverter(new IdempotentConverter()); // Numbers. this.addConverter(new IntegerConverter()); this.addConverter(new DoubleConverter()); this.addConverter(new FloatConverter()); this.addConverter(new LongConverter()); this.addConverter(new ByteConverter()); this.addConverter(new ShortConverter()); // Character. this.addConverter(new CharacterConverter()); // Math types. this.addConverter(new BigDecimalConverter()); this.addConverter(new BigIntegerConverter()); // Boolean. this.addConverter(new BooleanConverter()); }
From source file:ca.sqlpower.architect.swingui.TestPlayPenComponent.java
/** * Returns a new value that is not equal to oldVal. The * returned object will be a new instance compatible with oldVal. * /* w w w . j ava 2 s.co m*/ * @param property The property that should be modified. * @param oldVal The existing value of the property to modify. The returned value * will not equal this one at the time this method was first called. */ private Object getNewDifferentValue(PropertyDescriptor property, Object oldVal) throws SQLObjectException { Object newVal; // don't init here so compiler can warn if the // following code doesn't always give it a value if (property.getPropertyType() == String.class) { newVal = "new " + oldVal; } else if (property.getPropertyType() == Boolean.class || property.getPropertyType() == Boolean.TYPE) { if (oldVal == null) { newVal = new Boolean(false); } else { newVal = new Boolean(!((Boolean) oldVal).booleanValue()); } } else if (property.getPropertyType() == Integer.class || property.getPropertyType() == Integer.TYPE) { if (oldVal == null) { newVal = new Integer(0); } else { newVal = new Integer(((Integer) oldVal).intValue() + 1); } } else if (property.getPropertyType() == Double.class || property.getPropertyType() == Double.TYPE) { if (oldVal == null) { newVal = new Double(0); } else { newVal = new Double(((Double) oldVal).doubleValue() + 1); } } else if (property.getPropertyType() == Color.class) { if (oldVal == null) { newVal = new Color(0xFAC157); } else { Color oldColor = (Color) oldVal; newVal = new Color((oldColor.getRGB() + 0xF00) % 0x1000000); } } else if (property.getPropertyType() == Font.class) { if (oldVal == null) { newVal = FontManager.getDefaultPhysicalFont(); } else { Font oldFont = (Font) oldVal; newVal = new Font(oldFont.getFontName(), oldFont.getSize() + 2, oldFont.getStyle()); } } else if (property.getPropertyType() == Point.class) { if (oldVal == null) { newVal = new Point(); } else { Point oldPoint = (Point) oldVal; newVal = new Point(oldPoint.x + 10, oldPoint.y + 10); } } else if (property.getPropertyType() == Insets.class) { if (oldVal == null) { newVal = new Insets(0, 0, 0, 0); } else { Insets oldInsets = (Insets) oldVal; newVal = new Insets(oldInsets.top + 10, oldInsets.left + 10, oldInsets.bottom + 10, oldInsets.right + 10); } } else if (property.getPropertyType() == Set.class) { newVal = new HashSet(); if (property.getName().equals("hiddenColumns")) { ((Set) newVal).add(new SQLColumn()); } else { ((Set) newVal).add("Test"); } } else if (property.getPropertyType() == List.class) { newVal = new ArrayList(); if (property.getName().equals("selectedColumns")) { ((List) newVal).add(new SQLColumn()); } else { ((List) newVal).add("Test"); } } else if (property.getPropertyType() == TablePane.class) { SQLTable t = new SQLTable(); t.initFolders(true); newVal = new TablePane(t, pp.getContentPane()); } else if (property.getPropertyType() == SQLTable.class) { newVal = new SQLTable(); ((SQLTable) newVal).initFolders(true); } else if (property.getPropertyType() == Dimension.class) { newVal = new Dimension(); if (oldVal != null) { ((Dimension) newVal).width = ((Dimension) oldVal).width + 1; } } else { throw new RuntimeException("This test case lacks a value for " + property.getName() + " (type " + property.getPropertyType().getName() + ") in getNewDifferentValue()"); } return newVal; }
From source file:org.nuxeo.ecm.automation.io.services.codec.ObjectCodecService.java
protected final void writeGenericObject(JsonGenerator jg, Class<?> clazz, Object object) throws IOException { jg.writeStartObject();//from www . j ava 2 s.c o m if (clazz.isPrimitive()) { if (clazz == Boolean.TYPE) { jg.writeStringField("entity-type", "boolean"); jg.writeBooleanField("value", (Boolean) object); } else if (clazz == Double.TYPE || clazz == Float.TYPE) { jg.writeStringField("entity-type", "number"); jg.writeNumberField("value", ((Number) object).doubleValue()); } else if (clazz == Integer.TYPE || clazz == Long.TYPE || clazz == Short.TYPE || clazz == Byte.TYPE) { jg.writeStringField("entity-type", "number"); jg.writeNumberField("value", ((Number) object).longValue()); } else if (clazz == Character.TYPE) { jg.writeStringField("entity-type", "string"); jg.writeStringField("value", object.toString()); } return; } if (jg.getCodec() == null) { jg.setCodec(new ObjectMapper()); } if (object instanceof Iterable && clazz.getName().startsWith("java.")) { jg.writeStringField("entity-type", "list"); } else if (object instanceof Map && clazz.getName().startsWith("java.")) { if (object instanceof LinkedHashMap) { jg.writeStringField("entity-type", "orderedMap"); } else { jg.writeStringField("entity-type", "map"); } } else { jg.writeStringField("entity-type", clazz.getName()); } jg.writeObjectField("value", object); jg.writeEndObject(); }
From source file:nl.strohalm.cyclos.controls.customization.fields.EditCustomFieldAction.java
@SuppressWarnings("unchecked") public DataBinder<MemberRecordCustomField> getMemberRecordCustomFieldBinder() { final BeanBinder<MemberRecordCustomField> memberRecordFieldBinder = (BeanBinder<MemberRecordCustomField>) getBasicDataBinder( CustomField.Nature.MEMBER_RECORD); memberRecordFieldBinder.registerBinder("memberRecordType", PropertyBinder.instance(MemberRecordType.class, "memberRecordType")); memberRecordFieldBinder.registerBinder("showInSearch", PropertyBinder.instance(Boolean.TYPE, "showInSearch")); memberRecordFieldBinder.registerBinder("showInList", PropertyBinder.instance(Boolean.TYPE, "showInList")); memberRecordFieldBinder.registerBinder("brokerAccess", PropertyBinder.instance(MemberRecordCustomField.Access.class, "brokerAccess")); return memberRecordFieldBinder; }
From source file:com.sun.faces.renderkit.html_basic.MenuRenderer.java
protected Object handleArrayCase(FacesContext context, UISelectMany uiSelectMany, Class arrayClass, String[] newValues) throws ConverterException { Object result = null;//from www.ja v a 2 s .c om Class elementType = null; Converter converter = null; int i = 0, len = (null != newValues ? newValues.length : 0); elementType = arrayClass.getComponentType(); // Optimization: If the elementType is String, we don't need // conversion. Just return newValues. if (elementType.equals(String.class)) { return newValues; } try { result = Array.newInstance(elementType, len); } catch (Exception e) { throw new ConverterException(e); } // bail out now if we have no new values, returning our // oh-so-useful zero-length array. if (null == newValues) { return result; } // obtain a converter. // attached converter takes priority if (null == (converter = uiSelectMany.getConverter())) { // Otherwise, look for a by-type converter if (null == (converter = Util.getConverterForClass(elementType, context))) { // if that fails, and the attached values are of Object type, // we don't need conversion. if (elementType.equals(Object.class)) { return newValues; } String valueStr = ""; for (i = 0; i < newValues.length; i++) { valueStr = valueStr + " " + newValues[i]; } Object[] params = { valueStr, "null Converter" }; throw new ConverterException(Util.getExceptionMessage(Util.CONVERSION_ERROR_MESSAGE_ID, params)); } } Util.doAssert(null != result); if (elementType.isPrimitive()) { for (i = 0; i < len; i++) { if (elementType.equals(Boolean.TYPE)) { Array.setBoolean(result, i, ((Boolean) converter.getAsObject(context, uiSelectMany, newValues[i])).booleanValue()); } else if (elementType.equals(Byte.TYPE)) { Array.setByte(result, i, ((Byte) converter.getAsObject(context, uiSelectMany, newValues[i])).byteValue()); } else if (elementType.equals(Double.TYPE)) { Array.setDouble(result, i, ((Double) converter.getAsObject(context, uiSelectMany, newValues[i])).doubleValue()); } else if (elementType.equals(Float.TYPE)) { Array.setFloat(result, i, ((Float) converter.getAsObject(context, uiSelectMany, newValues[i])).floatValue()); } else if (elementType.equals(Integer.TYPE)) { Array.setInt(result, i, ((Integer) converter.getAsObject(context, uiSelectMany, newValues[i])).intValue()); } else if (elementType.equals(Character.TYPE)) { Array.setChar(result, i, ((Character) converter.getAsObject(context, uiSelectMany, newValues[i])).charValue()); } else if (elementType.equals(Short.TYPE)) { Array.setShort(result, i, ((Short) converter.getAsObject(context, uiSelectMany, newValues[i])).shortValue()); } else if (elementType.equals(Long.TYPE)) { Array.setLong(result, i, ((Long) converter.getAsObject(context, uiSelectMany, newValues[i])).longValue()); } } } else { for (i = 0; i < len; i++) { if (log.isDebugEnabled()) { Object converted = converter.getAsObject(context, uiSelectMany, newValues[i]); log.debug("String value: " + newValues[i] + " converts to : " + converted.toString()); } Array.set(result, i, converter.getAsObject(context, uiSelectMany, newValues[i])); } } return result; }
From source file:org.openlegacy.db.mvc.rest.DefaultDbRestController.java
private static Object toObject(Class<?> clazz, String value) { if (Boolean.class == clazz || Boolean.TYPE == clazz) { return Boolean.parseBoolean(value); }// w w w .ja va 2s. c om if (Byte.class == clazz || Byte.TYPE == clazz) { return Byte.parseByte(value); } if (Short.class == clazz || Short.TYPE == clazz) { return Short.parseShort(value); } if (Integer.class == clazz || Integer.TYPE == clazz) { return Integer.parseInt(value); } if (Long.class == clazz || Long.TYPE == clazz) { return Long.parseLong(value); } if (Float.class == clazz || Float.TYPE == clazz) { return Float.parseFloat(value); } if (Double.class == clazz || Double.TYPE == clazz) { return Double.parseDouble(value); } return value; }
From source file:nl.strohalm.cyclos.controls.admins.mailPreferences.MailPreferencesAction.java
private DataBinder<AdminNotificationPreference> getDataBinder() { if (dataBinder == null) { final BeanBinder<SystemAlertNotificationPreference> systemAlertBinder = BeanBinder .instance(SystemAlertNotificationPreference.class); systemAlertBinder.registerBinder("type", PropertyBinder.instance(SystemAlert.Alerts.class, "type")); final BeanBinder<MemberAlertNotificationPreference> memberAlertBinder = BeanBinder .instance(MemberAlertNotificationPreference.class); memberAlertBinder.registerBinder("type", PropertyBinder.instance(MemberAlert.Alerts.class, "type")); final BeanBinder<AdminNotificationPreference> binder = BeanBinder .instance(AdminNotificationPreference.class); binder.registerBinder("transferTypes", SimpleCollectionBinder.instance(TransferType.class, Set.class, "transferTypes")); binder.registerBinder("newPendingPayments", SimpleCollectionBinder.instance(TransferType.class, Set.class, "newPendingPayments")); binder.registerBinder("messageCategories", SimpleCollectionBinder.instance(MessageCategory.class, Set.class, "messageCategories")); binder.registerBinder("guaranteeTypes", SimpleCollectionBinder.instance(GuaranteeType.class, Set.class, "guaranteeTypes")); binder.registerBinder("newMembers", SimpleCollectionBinder.instance(MemberGroup.class, Set.class, "newMembers")); binder.registerBinder("systemAlerts", BeanCollectionBinder.instance(systemAlertBinder, "systemAlerts")); binder.registerBinder("memberAlerts", BeanCollectionBinder.instance(memberAlertBinder, "memberAlerts")); binder.registerBinder("applicationErrors", PropertyBinder.instance(Boolean.TYPE, "applicationErrors")); binder.registerBinder("systemInvoices", PropertyBinder.instance(Boolean.TYPE, "systemInvoices")); dataBinder = binder;//from w w w .j av a2 s . c o m } return dataBinder; }
From source file:android.reflect.ClazzLoader.java
/** * ????// ww w. j a va 2 s. c om */ public static <O, V> void setFieldValue(O o, Field field, V v) { if (field != null) { try { field.setAccessible(true); if (v == null) { field.set(o, null); } else { Class<?> vType = v.getClass(); if (vType == Integer.TYPE) { field.setInt(o, (Integer) v); } else if (vType == Long.TYPE) { field.setLong(o, (Long) v); } else if (vType == Boolean.TYPE) { field.setBoolean(o, (Boolean) v); } else if (vType == Float.TYPE) { field.setFloat(o, (Float) v); } else if (vType == Short.TYPE) { field.setShort(o, (Short) v); } else if (vType == Byte.TYPE) { field.setByte(o, (Byte) v); } else if (vType == Double.TYPE) { field.setDouble(o, (Double) v); } else if (vType == Character.TYPE) { field.setChar(o, (Character) v); } else { field.set(o, v); } } } catch (Throwable t) { Log.e(TAG, t); } } }
From source file:org.openamf.io.AMFSerializer.java
protected Object[] convertPrimitiveArrayToObjectArray(Object array) throws IOException { Class componentType = array.getClass().getComponentType(); Object[] result = null;/*from w w w . j a v a 2 s.c o m*/ if (componentType == null) { throw new NullPointerException("componentType is null"); } else if (componentType == Character.TYPE) { char[] carray = (char[]) array; result = new Object[carray.length]; for (int i = 0; i < carray.length; i++) { result[i] = new Character(carray[i]); } } else if (componentType == Byte.TYPE) { byte[] barray = (byte[]) array; result = new Object[barray.length]; for (int i = 0; i < barray.length; i++) { result[i] = new Byte(barray[i]); } } else if (componentType == Short.TYPE) { short[] sarray = (short[]) array; result = new Object[sarray.length]; for (int i = 0; i < sarray.length; i++) { result[i] = new Short(sarray[i]); } } else if (componentType == Integer.TYPE) { int[] iarray = (int[]) array; result = new Object[iarray.length]; for (int i = 0; i < iarray.length; i++) { result[i] = new Integer(iarray[i]); } } else if (componentType == Long.TYPE) { long[] larray = (long[]) array; result = new Object[larray.length]; for (int i = 0; i < larray.length; i++) { result[i] = new Long(larray[i]); } } else if (componentType == Double.TYPE) { double[] darray = (double[]) array; result = new Object[darray.length]; for (int i = 0; i < darray.length; i++) { result[i] = new Double(darray[i]); } } else if (componentType == Float.TYPE) { float[] farray = (float[]) array; result = new Object[farray.length]; for (int i = 0; i < farray.length; i++) { result[i] = new Float(farray[i]); } } else if (componentType == Boolean.TYPE) { boolean[] barray = (boolean[]) array; result = new Object[barray.length]; for (int i = 0; i < barray.length; i++) { result[i] = new Boolean(barray[i]); } } else { throw new IllegalArgumentException("unexpected component type: " + componentType.getClass().getName()); } return result; }