List of usage examples for java.lang Byte TYPE
Class TYPE
To view the source code for java.lang Byte TYPE.
Click Source Link
From source file:org.impalaframework.spring.service.proxy.ServiceEndpointInterceptor.java
public Object invokeDummy(MethodInvocation invocation) throws Throwable { log.debug("Calling method " + invocation); Class<?> returnType = invocation.getMethod().getReturnType(); if (Void.TYPE.equals(returnType)) return null; if (Byte.TYPE.equals(returnType)) return (byte) 0; if (Short.TYPE.equals(returnType)) return (short) 0; if (Integer.TYPE.equals(returnType)) return (int) 0; if (Long.TYPE.equals(returnType)) return 0L; if (Float.TYPE.equals(returnType)) return 0f; if (Double.TYPE.equals(returnType)) return 0d; if (Boolean.TYPE.equals(returnType)) return false; return null;//w w w. j av a2 s.c o m }
From source file:net.sf.json.JSONUtils.java
/** * Tests if obj is a primitive number or wrapper.<br> *//*from w w w . j a v a2 s . c o m*/ public static boolean isNumber(Object obj) { if (((obj != null) && (obj.getClass() == Byte.TYPE)) || ((obj != null) && (obj.getClass() == Short.TYPE)) || ((obj != null) && (obj.getClass() == Integer.TYPE)) || ((obj != null) && (obj.getClass() == Long.TYPE)) || ((obj != null) && (obj.getClass() == Float.TYPE)) || ((obj != null) && (obj.getClass() == Double.TYPE))) { return true; } if ((obj instanceof Byte) || (obj instanceof Short) || (obj instanceof Integer) || (obj instanceof Long) || (obj instanceof Float) || (obj instanceof Double)) { return true; } return false; }
From source file:org.gradle.internal.reflect.JavaReflectionUtil.java
public static Class<?> getWrapperTypeForPrimitiveType(Class<?> type) { if (type == Character.TYPE) { return Character.class; } else if (type == Boolean.TYPE) { return Boolean.class; } else if (type == Long.TYPE) { return Long.class; } else if (type == Integer.TYPE) { return Integer.class; } else if (type == Short.TYPE) { return Short.class; } else if (type == Byte.TYPE) { return Byte.class; } else if (type == Float.TYPE) { return Float.class; } else if (type == Double.TYPE) { return Double.class; }/*from w w w . jav a2 s. co m*/ throw new IllegalArgumentException( String.format("Don't know the wrapper type for primitive type %s.", type)); }
From source file:org.openflexo.antar.binding.TypeUtils.java
public static boolean isByte(Type type) { if (type == null) { return false; }/*from w ww. j a va2s .c o m*/ return type.equals(Byte.class) || type.equals(Byte.TYPE); }
From source file:com.link_intersystems.lang.Conversions.java
/** * char to byte or short/*from www. j a v a 2s . com*/ */ private static boolean isPrimitiveCharacterNarrowing(Class<?> to) { boolean isNarrowing = false; isNarrowing |= isIdentity(to, Byte.TYPE); isNarrowing |= isIdentity(to, Short.TYPE); return isNarrowing; }
From source file:com.cyclopsgroup.waterview.utils.TypeUtils.java
private static synchronized Map getTypeMap() { if (typeMap == null) { typeMap = new Hashtable(); typeMap.put("boolean", Boolean.TYPE); typeMap.put("byte", Byte.TYPE); typeMap.put("char", Character.TYPE); typeMap.put("short", Short.TYPE); typeMap.put("int", Integer.TYPE); typeMap.put("long", Long.TYPE); typeMap.put("float", Float.TYPE); typeMap.put("double", Double.TYPE); typeMap.put("string", String.class); typeMap.put("date", Date.class); }/*from w w w. ja v a 2s . c o m*/ return typeMap; }
From source file:com.xwtec.xwserver.util.json.JSONArray.java
/** * Creates a JSONArray.<br>//from ww w.j a va2s .c o m * 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: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"); }// w w w . j a v a 2 s .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.primeframework.mvc.parameter.convert.converters.NumberConverterTest.java
/** * Test the conversion from Strings./*from ww w .j a v a 2s. co m*/ */ @Test public void toStrings() { GlobalConverter converter = new NumberConverter(new MockConfiguration()); String str = converter.convertToString(Integer.class, null, "testExpr", null); assertNull(str); str = converter.convertToString(Byte.class, null, "testExpr", (byte) 42); assertEquals(str, "42"); str = converter.convertToString(Byte.TYPE, null, "testExpr", (byte) 42); assertEquals(str, "42"); str = converter.convertToString(Short.class, null, "testExpr", (short) 42); assertEquals(str, "42"); str = converter.convertToString(Short.TYPE, null, "testExpr", (short) 42); assertEquals(str, "42"); str = converter.convertToString(Integer.class, null, "testExpr", 42); assertEquals(str, "42"); str = converter.convertToString(Integer.class, null, "testExpr", 42); assertEquals(str, "42"); str = converter.convertToString(Long.class, null, "testExpr", 42l); assertEquals(str, "42"); str = converter.convertToString(Long.TYPE, null, "testExpr", 42l); assertEquals(str, "42"); str = converter.convertToString(Float.class, null, "testExpr", 42f); assertEquals(str, "42.0"); str = converter.convertToString(Float.TYPE, null, "testExpr", 42f); assertEquals(str, "42.0"); str = converter.convertToString(Double.class, null, "testExpr", 42.0); assertEquals(str, "42.0"); str = converter.convertToString(Double.TYPE, null, "testExpr", 42.0); assertEquals(str, "42.0"); }
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 ww . j a v a2 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); } }