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.hellofyc.base.widget.BaseWebView.java
private Class<?> getClassFromJsonObject(Object obj) { Class<?> cls = obj.getClass(); // js??int boolean string? if (cls == Integer.class) { cls = Integer.TYPE;//from w w w. j a v a 2 s . com } else if (cls == Boolean.class) { cls = Boolean.TYPE; } else { cls = String.class; } return cls; }
From source file:net.sf.ehcache.config.BeanHandler.java
/** * Converts a string to an object of a particular class. *///from w w w . j a v a 2 s . com private static Object convert(final Class toClass, final String value) throws Exception { if (value == null) { return null; } if (toClass.isInstance(value)) { return value; } if (toClass == Long.class || toClass == Long.TYPE) { return Long.decode(value); } if (toClass == Integer.class || toClass == Integer.TYPE) { return Integer.decode(value); } if (toClass == Boolean.class || toClass == Boolean.TYPE) { return Boolean.valueOf(value); } throw new Exception("Cannot convert attribute value to class " + toClass.getName()); }
From source file:org.getobjects.appserver.publisher.GoJavaMethod.java
@SuppressWarnings("unchecked") public Object coerceFormValueToArgumentType(final Object[] _v, final Class<?> _argType) { // FIXME: All this isn't nice. Cleanup and do it properly. // FIXME: Cache all the dynamic lookup if (_v == null) return null; if (_argType.isAssignableFrom(_v.getClass())) return _v; int vCount = _v.length; /* check whether the argument is some array-ish thing */ if (_argType.isArray()) { final Class<?> itemType = _argType.getComponentType(); final Object typedArray = java.lang.reflect.Array.newInstance(itemType, vCount); for (int i = 0; i < vCount; i++) { Object[] v = { _v[i] }; Object sv = this.coerceFormValueToArgumentType(v, itemType); java.lang.reflect.Array.set(typedArray, i, sv); }//w ww.ja va2 s. c o m return typedArray; } if (_argType.isAssignableFrom(List.class)) return UList.asList(_v); if (_argType.isAssignableFrom(Set.class)) return new HashSet(UList.asList(_v)); if (_argType.isAssignableFrom(Collection.class)) return UList.asList(_v); /* empty assignment */ if (vCount == 0) { if (!_argType.isPrimitive()) return null; // all objects, return null if (_argType == Boolean.TYPE) return new Boolean(false); if (_argType == Integer.TYPE) return new Integer(-1); if (_argType == Double.TYPE) return new Double(-1.0); if (_argType == Float.TYPE) return new Float(-1.0); if (_argType == Short.TYPE) return new Integer(-1); if (_argType == Long.TYPE) return new Long(-1); log.error("Unexpected primitive arg type: " + _argType); return new GoInternalErrorException("Unexpected primitive type!"); } /* check whether it is a directly assignable type */ if (vCount == 1) { /* some type coercion. Can we reuse anything from KVC here? */ // Note: Go supports various Zope form value formats, e.g. 'age:int' // Check WOServletRequest for more. final Object v = _v[0]; if (_argType.isAssignableFrom(v.getClass())) return v; /* some basic coercion */ if (_argType.isPrimitive()) { if (_argType == Boolean.TYPE) return new Boolean(UObject.boolValue(v)); if (_argType == Integer.TYPE || _argType == Short.TYPE) return new Integer(UObject.intValue(v)); if (_argType == Long.TYPE) return new Long(UObject.intOrLongValue(v).longValue()); } else if (_argType.isAssignableFrom(String.class)) return v.toString(); return v; // might crash } /* error out, return exception as value */ log.error("Cannot convert form value to Java argument " + _argType + ": " + _v); return new GoInternalErrorException("Cannot convert form value to Java parameter"); }
From source file:RealFunctionValidation.java
public static Object readAndWritePrimitiveValue(final DataInputStream in, final DataOutputStream out, final Class<?> type) throws IOException { if (!type.isPrimitive()) { throw new IllegalArgumentException("type must be primitive"); }//from w ww . j av a 2 s. c om if (type.equals(Boolean.TYPE)) { final boolean x = in.readBoolean(); out.writeBoolean(x); return Boolean.valueOf(x); } else if (type.equals(Byte.TYPE)) { final byte x = in.readByte(); out.writeByte(x); return Byte.valueOf(x); } else if (type.equals(Character.TYPE)) { final char x = in.readChar(); out.writeChar(x); return Character.valueOf(x); } else if (type.equals(Double.TYPE)) { final double x = in.readDouble(); out.writeDouble(x); return Double.valueOf(x); } else if (type.equals(Float.TYPE)) { final float x = in.readFloat(); out.writeFloat(x); return Float.valueOf(x); } else if (type.equals(Integer.TYPE)) { final int x = in.readInt(); out.writeInt(x); return Integer.valueOf(x); } else if (type.equals(Long.TYPE)) { final long x = in.readLong(); out.writeLong(x); return Long.valueOf(x); } else if (type.equals(Short.TYPE)) { final short x = in.readShort(); out.writeShort(x); return Short.valueOf(x); } else { // This should never occur. throw new IllegalStateException(); } }
From source file:ca.sqlpower.sqlobject.BaseSQLObjectTestCase.java
/** * XXX This test should use the {@link GenericNewValueMaker} as it has it's own mini * version inside it. This test should also be using the annotations to decide which * setters can fire events./*from ww w . java 2s .co m*/ * * @throws IllegalArgumentException * @throws IllegalAccessException * @throws InvocationTargetException * @throws NoSuchMethodException * @throws SQLObjectException */ public void testAllSettersGenerateEvents() throws IllegalArgumentException, IllegalAccessException, InvocationTargetException, NoSuchMethodException, SQLObjectException { SQLObject so = getSQLObjectUnderTest(); so.populate(); propertiesToIgnoreForEventGeneration.addAll(getPropertiesToIgnoreForEvents()); //Ignored because we expect the object to be populated. propertiesToIgnoreForEventGeneration.add("exportedKeysPopulated"); propertiesToIgnoreForEventGeneration.add("importedKeysPopulated"); propertiesToIgnoreForEventGeneration.add("columnsPopulated"); propertiesToIgnoreForEventGeneration.add("indicesPopulated"); CountingSQLObjectListener listener = new CountingSQLObjectListener(); SQLPowerUtils.listenToHierarchy(so, listener); if (so instanceof SQLDatabase) { // should be handled in the Datasource propertiesToIgnoreForEventGeneration.add("name"); } List<PropertyDescriptor> settableProperties; settableProperties = Arrays.asList(PropertyUtils.getPropertyDescriptors(so.getClass())); for (PropertyDescriptor property : settableProperties) { Object oldVal; if (propertiesToIgnoreForEventGeneration.contains(property.getName())) continue; try { oldVal = PropertyUtils.getSimpleProperty(so, property.getName()); // check for a setter if (property.getWriteMethod() == null) { continue; } } catch (NoSuchMethodException e) { System.out.println( "Skipping non-settable property " + property.getName() + " on " + so.getClass().getName()); continue; } Object newVal; // don't init here so compiler can warn if the following code doesn't always give it a value if (property.getPropertyType() == Integer.TYPE || property.getPropertyType() == Integer.class) { if (oldVal != null) { newVal = ((Integer) oldVal) + 1; } else { newVal = 1; } } else if (property.getPropertyType() == String.class) { // make sure it's unique newVal = "new " + oldVal; } else if (property.getPropertyType() == Boolean.TYPE || property.getPropertyType() == Boolean.class) { if (oldVal == null) { newVal = Boolean.TRUE; } else { newVal = new Boolean(!((Boolean) oldVal).booleanValue()); } } else if (property.getPropertyType() == SQLCatalog.class) { newVal = new SQLCatalog(new SQLDatabase(), "This is a new catalog"); } else if (property.getPropertyType() == SPDataSource.class) { newVal = new JDBCDataSource(getPLIni()); ((SPDataSource) newVal).setName("test"); ((SPDataSource) newVal).setDisplayName("test"); ((JDBCDataSource) newVal).setUser("a"); ((JDBCDataSource) newVal).setPass("b"); ((JDBCDataSource) newVal).getParentType().setJdbcDriver(MockJDBCDriver.class.getName()); ((JDBCDataSource) newVal).setUrl("jdbc:mock:tables=tab1"); } else if (property.getPropertyType() == JDBCDataSource.class) { newVal = new JDBCDataSource(getPLIni()); ((SPDataSource) newVal).setName("test"); ((SPDataSource) newVal).setDisplayName("test"); ((JDBCDataSource) newVal).setUser("a"); ((JDBCDataSource) newVal).setPass("b"); ((JDBCDataSource) newVal).getParentType().setJdbcDriver(MockJDBCDriver.class.getName()); ((JDBCDataSource) newVal).setUrl("jdbc:mock:tables=tab1"); } else if (property.getPropertyType() == SQLTable.class) { newVal = new SQLTable(); } else if (property.getPropertyType() == SQLColumn.class) { newVal = new SQLColumn(); } else if (property.getPropertyType() == SQLIndex.class) { newVal = new SQLIndex(); } else if (property.getPropertyType() == SQLRelationship.SQLImportedKey.class) { SQLRelationship rel = new SQLRelationship(); newVal = rel.getForeignKey(); } else if (property.getPropertyType() == SQLRelationship.Deferrability.class) { if (oldVal == SQLRelationship.Deferrability.INITIALLY_DEFERRED) { newVal = SQLRelationship.Deferrability.NOT_DEFERRABLE; } else { newVal = SQLRelationship.Deferrability.INITIALLY_DEFERRED; } } else if (property.getPropertyType() == SQLRelationship.UpdateDeleteRule.class) { if (oldVal == SQLRelationship.UpdateDeleteRule.CASCADE) { newVal = SQLRelationship.UpdateDeleteRule.RESTRICT; } else { newVal = SQLRelationship.UpdateDeleteRule.CASCADE; } } else if (property.getPropertyType() == SQLIndex.AscendDescend.class) { if (oldVal == SQLIndex.AscendDescend.ASCENDING) { newVal = SQLIndex.AscendDescend.DESCENDING; } else { newVal = SQLIndex.AscendDescend.ASCENDING; } } else if (property.getPropertyType() == Throwable.class) { newVal = new Throwable(); } else if (property.getPropertyType() == BasicSQLType.class) { if (oldVal != BasicSQLType.OTHER) { newVal = BasicSQLType.OTHER; } else { newVal = BasicSQLType.TEXT; } } else if (property.getPropertyType() == UserDefinedSQLType.class) { newVal = new UserDefinedSQLType(); } else if (property.getPropertyType() == SQLTypeConstraint.class) { if (oldVal != SQLTypeConstraint.NONE) { newVal = SQLTypeConstraint.NONE; } else { newVal = SQLTypeConstraint.CHECK; } } else if (property.getPropertyType() == String[].class) { newVal = new String[3]; } else if (property.getPropertyType() == PropertyType.class) { if (oldVal != PropertyType.NOT_APPLICABLE) { newVal = PropertyType.NOT_APPLICABLE; } else { newVal = PropertyType.VARIABLE; } } else if (property.getPropertyType() == List.class) { newVal = Arrays.asList("one", "two"); } else { throw new RuntimeException("This test case lacks a value for " + property.getName() + " (type " + property.getPropertyType().getName() + ") from " + so.getClass() + " on property " + property.getDisplayName()); } int oldChangeCount = listener.getChangedCount(); try { System.out.println("Setting property '" + property.getName() + "' to '" + newVal + "' (" + newVal.getClass().getName() + ")"); BeanUtils.copyProperty(so, property.getName(), newVal); // some setters fire multiple events (they change more than one property) assertTrue( "Event for set " + property.getName() + " on " + so.getClass().getName() + " didn't fire!", listener.getChangedCount() > oldChangeCount); if (listener.getChangedCount() == oldChangeCount + 1) { assertEquals("Property name mismatch for " + property.getName() + " in " + so.getClass(), property.getName(), ((PropertyChangeEvent) listener.getLastEvent()).getPropertyName()); assertEquals("New value for " + property.getName() + " was wrong", newVal, ((PropertyChangeEvent) listener.getLastEvent()).getNewValue()); } } catch (InvocationTargetException e) { System.out.println("(non-fatal) Failed to write property '" + property.getName() + " to type " + so.getClass().getName()); } } }
From source file:org.commonreality.object.delta.DeltaTracker.java
@SuppressWarnings("unchecked") private boolean isActualChange(String keyName, Object newValue) { if (newValue != null) { if (!_actualObject.hasProperty(keyName)) return true; Object oldValue = null;// w w w .j a va2 s . c o m // if (checkOnlyActualObject) oldValue = _actualObject.getProperty(keyName); // else // oldValue = getProperty(keyName); if (newValue == oldValue) return false; if (newValue.equals(oldValue)) return false; /* * now we need to see if they are arrays */ Class newClass = newValue.getClass(); Class oldClass = Object.class; if (oldValue != null) oldClass = oldValue.getClass(); if (newClass != oldClass) return true; if (newClass.isArray() && oldClass.isArray()) { if (newClass.getComponentType() != oldClass.getComponentType()) return true; /* * now we have to check the elements */ if (newClass.getComponentType().isPrimitive()) { boolean rtn = true; if (newClass.getComponentType() == Float.TYPE) rtn = compareFloats((float[]) newValue, (float[]) oldValue); else if (newClass.getComponentType() == Double.TYPE) rtn = compareDoubles((double[]) newValue, (double[]) oldValue); else if (newClass.getComponentType() == Boolean.TYPE) rtn = compareBooleans((boolean[]) newValue, (boolean[]) oldValue); else if (newClass.getComponentType() == Integer.TYPE) rtn = compareInts((int[]) newValue, (int[]) oldValue); else if (LOGGER.isWarnEnabled()) LOGGER.warn("Cannot compare arrays of " + newClass.getComponentType().getName()); return rtn; } else { Object[] newArray = (Object[]) newValue; Object[] oldArray = (Object[]) oldValue; if (newArray.length != oldArray.length) return true; for (int i = 0; i < newArray.length; i++) if (!newArray[i].equals(oldArray[i])) return true; return false; } } } else // unsetting the property if (_actualObject.hasProperty(keyName)) return true; return true; }
From source file:au.com.addstar.cellblock.configuration.AutoConfig.java
@SuppressWarnings("unchecked") public boolean load() { FileConfiguration yml = new YamlConfiguration(); try {//from w w w . j a v a2 s .c om if (mFile.getParentFile().exists() || mFile.getParentFile().mkdirs()) {// Make sure the file exists if (mFile.exists() || mFile.createNewFile()) { // Parse the config yml.load(mFile); for (Field field : getClass().getDeclaredFields()) { ConfigField configField = field.getAnnotation(ConfigField.class); if (configField == null) continue; String optionName = configField.name(); if (optionName.isEmpty()) optionName = field.getName(); field.setAccessible(true); String path = (configField.category().isEmpty() ? "" : configField.category() + ".") //$NON-NLS-2$ + optionName; if (!yml.contains(path)) { if (field.get(this) == null) throw new InvalidConfigurationException( path + " is required to be set! Info:\n" + configField.comment()); } else { // Parse the value if (field.getType().isArray()) { // Integer if (field.getType().getComponentType().equals(Integer.TYPE)) field.set(this, yml.getIntegerList(path).toArray(new Integer[0])); // Float else if (field.getType().getComponentType().equals(Float.TYPE)) field.set(this, yml.getFloatList(path).toArray(new Float[0])); // Double else if (field.getType().getComponentType().equals(Double.TYPE)) field.set(this, yml.getDoubleList(path).toArray(new Double[0])); // Long else if (field.getType().getComponentType().equals(Long.TYPE)) field.set(this, yml.getLongList(path).toArray(new Long[0])); // Short else if (field.getType().getComponentType().equals(Short.TYPE)) field.set(this, yml.getShortList(path).toArray(new Short[0])); // Boolean else if (field.getType().getComponentType().equals(Boolean.TYPE)) field.set(this, yml.getBooleanList(path).toArray(new Boolean[0])); // String else if (field.getType().getComponentType().equals(String.class)) { field.set(this, yml.getStringList(path).toArray(new String[0])); } else throw new IllegalArgumentException("Cannot use type " + field.getType().getSimpleName() + " for AutoConfiguration"); //$NON-NLS-1$ } else if (List.class.isAssignableFrom(field.getType())) { if (field.getGenericType() == null) throw new IllegalArgumentException( "Cannot use type List without specifying generic type for AutoConfiguration"); Type type = ((ParameterizedType) field.getGenericType()) .getActualTypeArguments()[0]; if (type.equals(Integer.class)) field.set(this, newList((Class<? extends List<Integer>>) field.getType(), yml.getIntegerList(path))); else if (type.equals(Float.class)) field.set(this, newList((Class<? extends List<Float>>) field.getType(), yml.getFloatList(path))); else if (type.equals(Double.class)) field.set(this, newList((Class<? extends List<Double>>) field.getType(), yml.getDoubleList(path))); else if (type.equals(Long.class)) field.set(this, newList((Class<? extends List<Long>>) field.getType(), yml.getLongList(path))); else if (type.equals(Short.class)) field.set(this, newList((Class<? extends List<Short>>) field.getType(), yml.getShortList(path))); else if (type.equals(Boolean.class)) field.set(this, newList((Class<? extends List<Boolean>>) field.getType(), yml.getBooleanList(path))); else if (type.equals(String.class)) field.set(this, newList((Class<? extends List<String>>) field.getType(), yml.getStringList(path))); else throw new IllegalArgumentException( "Cannot use type " + field.getType().getSimpleName() + "<" //$NON-NLS-2$ + type.toString() + "> for AutoConfiguration"); } else if (Set.class.isAssignableFrom(field.getType())) { if (field.getGenericType() == null) throw new IllegalArgumentException( "Cannot use type set without specifying generic type for AytoConfiguration"); Type type = ((ParameterizedType) field.getGenericType()) .getActualTypeArguments()[0]; if (type.equals(Integer.class)) field.set(this, newSet((Class<? extends Set<Integer>>) field.getType(), yml.getIntegerList(path))); else if (type.equals(Float.class)) field.set(this, newSet((Class<? extends Set<Float>>) field.getType(), yml.getFloatList(path))); else if (type.equals(Double.class)) field.set(this, newSet((Class<? extends Set<Double>>) field.getType(), yml.getDoubleList(path))); else if (type.equals(Long.class)) field.set(this, newSet((Class<? extends Set<Long>>) field.getType(), yml.getLongList(path))); else if (type.equals(Short.class)) field.set(this, newSet((Class<? extends Set<Short>>) field.getType(), yml.getShortList(path))); else if (type.equals(Boolean.class)) field.set(this, newSet((Class<? extends Set<Boolean>>) field.getType(), yml.getBooleanList(path))); else if (type.equals(String.class)) field.set(this, newSet((Class<? extends Set<String>>) field.getType(), yml.getStringList(path))); else throw new IllegalArgumentException( "Cannot use type " + field.getType().getSimpleName() + "<" //$NON-NLS-2$ + type.toString() + "> for AutoConfiguration"); } else { // Integer if (field.getType().equals(Integer.TYPE)) field.setInt(this, yml.getInt(path)); // Float else if (field.getType().equals(Float.TYPE)) field.setFloat(this, (float) yml.getDouble(path)); // Double else if (field.getType().equals(Double.TYPE)) field.setDouble(this, yml.getDouble(path)); // Long else if (field.getType().equals(Long.TYPE)) field.setLong(this, yml.getLong(path)); // Short else if (field.getType().equals(Short.TYPE)) field.setShort(this, (short) yml.getInt(path)); // Boolean else if (field.getType().equals(Boolean.TYPE)) field.setBoolean(this, yml.getBoolean(path)); // ItemStack else if (field.getType().equals(ItemStack.class)) field.set(this, yml.getItemStack(path)); // String else if (field.getType().equals(String.class)) field.set(this, yml.getString(path)); else throw new IllegalArgumentException("Cannot use type " + field.getType().getSimpleName() + " for AutoConfiguration"); //$NON-NLS-1$ } } } onPostLoad(); } else { Bukkit.getLogger().log(Level.INFO, "Unable to create file: " + mFile.toString()); } } else { Bukkit.getLogger().log(Level.INFO, "Unable to create file: " + mFile.getParentFile().toString()); } return true; } catch (IOException | InvalidConfigurationException | IllegalAccessException | IllegalArgumentException e) { e.printStackTrace(); return false; } }
From source file:org.apache.struts.config.FormPropertyConfig.java
/** * Return a Class corresponds to the value specified for the * <code>type</code> property, taking into account the trailing "[]" for * arrays (as well as the ability to specify primitive Java types). *//*w w w . ja v a 2 s.c om*/ public Class getTypeClass() { // Identify the base class (in case an array was specified) String baseType = getType(); boolean indexed = false; if (baseType.endsWith("[]")) { baseType = baseType.substring(0, baseType.length() - 2); indexed = true; } // Construct an appropriate Class instance for the base class Class baseClass = null; if ("boolean".equals(baseType)) { baseClass = Boolean.TYPE; } else if ("byte".equals(baseType)) { baseClass = Byte.TYPE; } else if ("char".equals(baseType)) { baseClass = Character.TYPE; } else if ("double".equals(baseType)) { baseClass = Double.TYPE; } else if ("float".equals(baseType)) { baseClass = Float.TYPE; } else if ("int".equals(baseType)) { baseClass = Integer.TYPE; } else if ("long".equals(baseType)) { baseClass = Long.TYPE; } else if ("short".equals(baseType)) { baseClass = Short.TYPE; } else { ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); if (classLoader == null) { classLoader = this.getClass().getClassLoader(); } try { baseClass = classLoader.loadClass(baseType); } catch (ClassNotFoundException ex) { log.error("Class '" + baseType + "' not found for property '" + name + "'"); baseClass = null; } } // Return the base class or an array appropriately if (indexed) { return (Array.newInstance(baseClass, 0).getClass()); } else { return (baseClass); } }
From source file:org.apache.jackrabbit.core.persistence.bundle.Oracle9PersistenceManager.java
/** * Creates a temporary oracle.sql.BLOB instance via reflection and spools * the contents of the specified stream. *//*from w ww . j av a 2 s. c o m*/ protected Blob createTemporaryBlob(InputStream in) throws Exception { /* BLOB blob = BLOB.createTemporary(con, false, BLOB.DURATION_SESSION); blob.open(BLOB.MODE_READWRITE); OutputStream out = blob.getBinaryOutputStream(); ... out.flush(); out.close(); blob.close(); return blob; */ Method createTemporary = blobClass.getMethod("createTemporary", new Class[] { Connection.class, Boolean.TYPE, Integer.TYPE }); Object blob = createTemporary.invoke(null, new Object[] { connectionManager.getConnection(), Boolean.FALSE, duractionSessionConstant }); Method open = blobClass.getMethod("open", new Class[] { Integer.TYPE }); open.invoke(blob, new Object[] { modeReadWriteConstant }); Method getBinaryOutputStream = blobClass.getMethod("getBinaryOutputStream", new Class[0]); OutputStream out = (OutputStream) getBinaryOutputStream.invoke(blob, null); try { IOUtils.copy(in, out); } finally { try { out.flush(); } catch (IOException ioe) { } out.close(); } Method close = blobClass.getMethod("close", new Class[0]); close.invoke(blob, null); return (Blob) blob; }
From source file:org.broadleafcommerce.openadmin.server.dao.provider.metadata.AbstractFieldMetadataProvider.java
protected Class<?> getBasicJavaType(SupportedFieldType fieldType) { Class<?> response;/*w w w.j a va2s . com*/ switch (fieldType) { case BOOLEAN: response = Boolean.TYPE; break; case DATE: response = Date.class; break; case DECIMAL: response = BigDecimal.class; break; case MONEY: response = BigDecimal.class; break; case INTEGER: response = Integer.TYPE; break; case UNKNOWN: response = null; break; default: response = String.class; break; } return response; }