List of usage examples for java.lang Integer TYPE
Class TYPE
To view the source code for java.lang Integer TYPE.
Click Source Link
From source file:com.xwtec.xwserver.util.json.JSONArray.java
/** * Creates a JSONArray.<br>//w ww .java 2s.com * Inspects the object type to call the correct JSONArray factory method. * Accepts JSON formatted strings, arrays, Collections and Enums. * * @param object * @throws JSONException if the object can not be converted to a proper * JSONArray. */ public static JSONArray fromObject(Object object, JsonConfig jsonConfig) { if (object instanceof JSONString) { return _fromJSONString((JSONString) object, jsonConfig); } else if (object instanceof JSONArray) { return _fromJSONArray((JSONArray) object, jsonConfig); } else if (object instanceof Collection) { return _fromCollection((Collection) object, jsonConfig); } else if (object instanceof JSONTokener) { return _fromJSONTokener((JSONTokener) object, jsonConfig); } else if (object instanceof String) { return _fromString((String) object, jsonConfig); } else if (object != null && object.getClass().isArray()) { Class type = object.getClass().getComponentType(); if (!type.isPrimitive()) { return _fromArray((Object[]) object, jsonConfig); } else { if (type == Boolean.TYPE) { return _fromArray((boolean[]) object, jsonConfig); } else if (type == Byte.TYPE) { return _fromArray((byte[]) object, jsonConfig); } else if (type == Short.TYPE) { return _fromArray((short[]) object, jsonConfig); } else if (type == Integer.TYPE) { return _fromArray((int[]) object, jsonConfig); } else if (type == Long.TYPE) { return _fromArray((long[]) object, jsonConfig); } else if (type == Float.TYPE) { return _fromArray((float[]) object, jsonConfig); } else if (type == Double.TYPE) { return _fromArray((double[]) object, jsonConfig); } else if (type == Character.TYPE) { return _fromArray((char[]) object, jsonConfig); } else { throw new JSONException("Unsupported type"); } } } else if (JSONUtils.isBoolean(object) || JSONUtils.isFunction(object) || JSONUtils.isNumber(object) || JSONUtils.isNull(object) || JSONUtils.isString(object) || object instanceof JSON) { fireArrayStartEvent(jsonConfig); JSONArray jsonArray = new JSONArray().element(object, jsonConfig); fireElementAddedEvent(0, jsonArray.get(0), jsonConfig); fireArrayStartEvent(jsonConfig); return jsonArray; } else if (object instanceof Enum) { return _fromArray((Enum) object, jsonConfig); } else if (object instanceof Annotation || (object != null && object.getClass().isAnnotation())) { throw new JSONException("Unsupported type"); } else if (JSONUtils.isObject(object)) { fireArrayStartEvent(jsonConfig); JSONArray jsonArray = new JSONArray().element(JSONObject.fromObject(object, jsonConfig)); fireElementAddedEvent(0, jsonArray.get(0), jsonConfig); fireArrayStartEvent(jsonConfig); return jsonArray; } else { throw new JSONException("Unsupported type"); } }
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;/* ww w .j a v a2 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:me.crime.loader.DataBaseLoader.java
private void saveData(String method, String data, Object obj) throws SAXException { Method getMethod = getMethod("get" + method, obj); Method setMethod = getMethod("set" + method, obj); try {//from w w w . ja v a2 s . c o m Object args[] = new Object[1]; if (getMethod.getGenericReturnType() == Integer.TYPE) { args[0] = new Integer(data); } else if (getMethod.getGenericReturnType() == String.class) { args[0] = data; } else if (getMethod.getGenericReturnType() == Double.TYPE) { args[0] = new Double(data); } else if (getMethod.getGenericReturnType() == Long.TYPE) { args[0] = new Long(data); } else if (getMethod.getGenericReturnType() == Calendar.class) { String[] dt = data.split(":"); Calendar cal = Calendar.getInstance(); cal.set(Calendar.YEAR, Integer.parseInt(dt[0])); cal.set(Calendar.MONTH, Integer.parseInt(dt[1])); cal.set(Calendar.DAY_OF_MONTH, Integer.parseInt(dt[2])); cal.set(Calendar.HOUR_OF_DAY, Integer.parseInt(dt[3])); cal.set(Calendar.MINUTE, Integer.parseInt(dt[4])); cal.set(Calendar.SECOND, Integer.parseInt(dt[5])); cal.set(Calendar.MILLISECOND, Integer.parseInt(dt[5])); if (cal.get(Calendar.YEAR) < 10) { cal.set(Calendar.YEAR, 2000 + cal.get(Calendar.YEAR)); } args[0] = cal; } setMethod.invoke(obj, args); } catch (Exception e) { DataBaseLoader.log_.error("saveData: " + method, e); throw new SAXException("saveData:", e); } }
From source file:org.evosuite.testcase.fm.MethodDescriptor.java
public Object executeMatcher(int i) throws IllegalArgumentException { if (i < 0 || i >= getNumberOfInputParameters()) { throw new IllegalArgumentException("Invalid index: " + i); }/* w w w . j a va 2s . c o m*/ Type[] types = method.getParameterTypes(); Type type = types[i]; try { if (type.equals(Integer.TYPE) || type.equals(Integer.class)) { return Mockito.anyInt(); } else if (type.equals(Long.TYPE) || type.equals(Long.class)) { return Mockito.anyLong(); } else if (type.equals(Boolean.TYPE) || type.equals(Boolean.class)) { return Mockito.anyBoolean(); } else if (type.equals(Double.TYPE) || type.equals(Double.class)) { return Mockito.anyDouble(); } else if (type.equals(Float.TYPE) || type.equals(Float.class)) { return Mockito.anyFloat(); } else if (type.equals(Short.TYPE) || type.equals(Short.class)) { return Mockito.anyShort(); } else if (type.equals(Character.TYPE) || type.equals(Character.class)) { return Mockito.anyChar(); } else if (type.equals(String.class)) { return Mockito.anyString(); } else { return Mockito.any(type.getClass()); } } catch (Exception e) { logger.error("Failed to executed Mockito matcher n{} of type {} in {}.{}: {}", i, type, className, methodName, e.getMessage()); throw new EvosuiteError(e); } }
From source file:info.guardianproject.netcipher.web.WebkitProxy.java
private static boolean setWebkitProxyICS(Context ctx, String host, int port) { // PSIPHON: added support for Android 4.x WebView proxy try {/* ww w . j a v a 2 s . co m*/ Class webViewCoreClass = Class.forName("android.webkit.WebViewCore"); Class proxyPropertiesClass = Class.forName("android.net.ProxyProperties"); if (webViewCoreClass != null && proxyPropertiesClass != null) { Method m = webViewCoreClass.getDeclaredMethod("sendStaticMessage", Integer.TYPE, Object.class); Constructor c = proxyPropertiesClass.getConstructor(String.class, Integer.TYPE, String.class); if (m != null && c != null) { m.setAccessible(true); c.setAccessible(true); Object properties = c.newInstance(host, port, null); // android.webkit.WebViewCore.EventHub.PROXY_CHANGED = 193; m.invoke(null, 193, properties); return true; } } } catch (Exception e) { Log.e("ProxySettings", "Exception setting WebKit proxy through android.net.ProxyProperties: " + e.toString()); } catch (Error e) { Log.e("ProxySettings", "Exception setting WebKit proxy through android.webkit.Network: " + e.toString()); } return false; }
From source file:org.broadleafcommerce.openadmin.server.dao.provider.metadata.AbstractFieldMetadataProvider.java
protected Class<?> getBasicJavaType(SupportedFieldType fieldType) { Class<?> response;/* www . ja v a2 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 = BigDecimal.class; break; case INTEGER: response = Integer.TYPE; break; case UNKNOWN: response = null; break; default: response = String.class; break; } return response; }
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). *//*from w ww.j av a 2s . com*/ 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:com.projity.util.ClassUtils.java
/** * Get the corresponding object class from a primitive class * @param clazz primitive class//from w w w . j av a 2s . co m * @return Object class. * @throws ClassCastException if class is unknown primitive */ public static Class primitiveToObjectClass(Class clazz) { // return MethodUtils.toNonPrimitiveClass(clazz); if (clazz == Boolean.TYPE) return Boolean.class; else if (clazz == Character.TYPE) return Character.class; else if (clazz == Byte.TYPE) return Byte.class; else if (clazz == Short.TYPE) return Short.class; else if (clazz == Integer.TYPE) return Integer.class; else if (clazz == Long.TYPE) return Long.class; else if (clazz == Float.TYPE) return Float.class; else if (clazz == Double.TYPE) return Double.class; throw new ClassCastException("Cannot convert class" + clazz + " to an object class"); }
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 .ja v a2s . c o m*/ 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:org.apache.jcs.config.PropertySetter.java
/** * Convert <code>val</code> a String parameter to an object of a given * type.// w ww . j a v a2 s .c om * @param val * @param type * @return Object */ protected Object convertArg(String val, Class type) { if (val == null) { return null; } String v = val.trim(); if (String.class.isAssignableFrom(type)) { return val; } else if (Integer.TYPE.isAssignableFrom(type)) { return new Integer(v); } else if (Long.TYPE.isAssignableFrom(type)) { return new Long(v); } else if (Boolean.TYPE.isAssignableFrom(type)) { if ("true".equalsIgnoreCase(v)) { return Boolean.TRUE; } else if ("false".equalsIgnoreCase(v)) { return Boolean.FALSE; } } return null; }