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:com.github.helenusdriver.driver.impl.DataDecoder.java
/** * Gets an element decoder that can be used to convert a Cassandra * returned data type into another data type based on special supported * combinations./* w w w .j av a2s . co m*/ * * @author paouelle * * @param eclass the non-<code>null</code> element class to decode to * @param reclass the non-<code>null</code> row's element class * @return a non-<code>null</code> element decoder for the provided combination * @throws IllegalArgumentException if the combination is not supported */ @SuppressWarnings("rawtypes") static ElementConverter getConverter(final Class eclass, Class reclass) { if (Enum.class.isAssignableFrom(eclass) && (String.class == reclass)) { return new ElementConverter() { @SuppressWarnings("unchecked") @Override public Object convert(Object re) { return Enum.valueOf(eclass, (String) re); } }; } else if (Locale.class.isAssignableFrom(eclass) && (String.class == reclass)) { return new ElementConverter() { @Override public Object convert(Object re) { return LocaleUtils.toLocale((String) re); } }; } else if (ZoneId.class.isAssignableFrom(eclass) && (String.class == reclass)) { return new ElementConverter() { @Override public Object convert(Object re) { try { return ZoneId.of((String) re); } catch (DateTimeException e) { throw new IllegalArgumentException(e); } } }; } else if (eclass.isArray() && (Byte.TYPE == eclass.getComponentType()) && ByteBuffer.class.isAssignableFrom(reclass)) { return new ElementConverter() { @Override public Object convert(Object re) { return Bytes.getArray((ByteBuffer) re); } }; } else if ((Long.class == eclass) && Date.class.isAssignableFrom(reclass)) { return new ElementConverter() { @Override public Object convert(Object re) { return ((Date) re).getTime(); } }; } else if ((Instant.class == eclass) && Date.class.isAssignableFrom(reclass)) { return new ElementConverter() { @Override public Object convert(Object re) { return ((Date) re).toInstant(); } }; } else if (eclass == reclass) { // special case for maps return new ElementConverter() { @Override public Object convert(Object re) { return re; } }; } throw new IllegalArgumentException( "unsupported element conversion from: " + reclass.getName() + " to: " + eclass.getName()); }
From source file:org.apache.maven.plugin.javadoc.AbstractFixJavadocMojo.java
/** * Add a default Javadoc for the given field, i.e.: * <br/>//from ww w. j av a 2s. c o m * <code> * <font color="#808080">1</font> <font color="#ffffff"> </font> * <font color="#3f5fbf">/** Constant </font><font color="#7f7f9f"><code></font> * <font color="#3f5fbf">MY_STRING_CONSTANT="value"</font> * <font color="#7f7f9f"></code> </font><font color="#3f5fbf">*/</font><br /> * <font color="#808080">2</font> <font color="#ffffff"> </font> * <font color="#7f0055"><b>public static final </b></font> * <font color="#000000">String MY_STRING_CONSTANT = </font> * <font color="#2a00ff">"value"</font><font color="#000000">;</font> * </code> * * @param stringWriter not null * @param field not null * @param indent not null * @throws IOException if any */ private void addDefaultFieldComment(final StringWriter stringWriter, final JavaField field, final String indent) throws IOException { StringBuilder sb = new StringBuilder(); sb.append(indent).append(START_JAVADOC).append(" "); sb.append("Constant <code>").append(field.getName()); if (StringUtils.isNotEmpty(field.getInitializationExpression())) { String qualifiedName = field.getType().getJavaClass().getFullyQualifiedName(); if (qualifiedName.equals(Byte.TYPE.toString()) || qualifiedName.equals(Short.TYPE.toString()) || qualifiedName.equals(Integer.TYPE.toString()) || qualifiedName.equals(Long.TYPE.toString()) || qualifiedName.equals(Float.TYPE.toString()) || qualifiedName.equals(Double.TYPE.toString()) || qualifiedName.equals(Boolean.TYPE.toString()) || qualifiedName.equals(Character.TYPE.toString())) { sb.append("="); sb.append(field.getInitializationExpression().trim()); } if (qualifiedName.equals(String.class.getName())) { StringBuilder value = new StringBuilder(); String[] lines = getLines(field.getInitializationExpression()); for (String line : lines) { StringTokenizer token = new StringTokenizer(line.trim(), "\"\n\r"); while (token.hasMoreTokens()) { String s = token.nextToken(); if (s.trim().equals("+")) { continue; } if (s.trim().endsWith("\\")) { s += "\""; } value.append(s); } } sb.append("=\""); // reduce the size if (value.length() < 40) { sb.append(value.toString()).append("\""); } else { sb.append(value.toString().substring(0, 39)).append("\"{trunked}"); } } } sb.append("</code> ").append(END_JAVADOC); sb.append(EOL); stringWriter.write(sb.toString()); }
From source file:cn.sinobest.jzpt.framework.utils.string.StringUtils.java
/** * obj isArrayJoin//from www. jav a2 s.c o m * * @Title: join * @return String * @throws */ public static String join(Object obj, String dchar) { Assert.notNull(obj); if (!obj.getClass().isArray()) { throw new IllegalArgumentException("The input object to join must be a Array and not null."); } Class<?> priType = obj.getClass().getComponentType(); if (priType == Boolean.TYPE) { return join((boolean[]) obj, dchar); } else if (priType == Byte.TYPE) { return join((byte[]) obj, dchar); } else if (priType == Character.TYPE) { return join((char[]) obj, dchar); } else if (priType == Integer.TYPE) { return join((int[]) obj, dchar); } else if (priType == Long.TYPE) { return join((long[]) obj, dchar); } else if (priType == Float.TYPE) { return join((float[]) obj, dchar); } else if (priType == Double.TYPE) { return join((double[]) obj, dchar); } else if (priType == Short.TYPE) { return join((short[]) obj, dchar); } else { return join((Object[]) obj, dchar); } }
From source file:com.taobao.adfs.util.Utilities.java
public static String getSqlTypeForJavaType(Class<?> type) throws IOException { if (type == null) throw new IOException("type is null"); if (type.equals(Byte.TYPE) || type.equals(Byte.class)) return "TINYINT"; if (type.equals(Short.TYPE) || type.equals(Short.class)) return "SMALLINT"; if (type.equals(Integer.TYPE) || type.equals(Integer.class)) return "INT"; if (type.equals(Long.TYPE) || type.equals(Long.class)) return "BIGINT"; if (type.equals(Float.TYPE) || type.equals(Float.class)) return "FLOAT"; if (type.equals(Double.TYPE) || type.equals(Double.class)) return "DOUBLE"; if (type.equals(String.class)) return "VARCHAR"; else//w ww. j a v a 2 s . c o m throw new IOException("unsupportted type=" + type.getSimpleName()); }
From source file:alice.tuprolog.lib.OOLibrary.java
/** * /*from ww w. j a va2 s.com*/ * parsing 'as' operator, which makes it possible to define the specific * class of an argument * */ private boolean parse_as(Object[] values, Class<?>[] types, int i, PTerm castWhat, PTerm castTo) { try { if (!(castWhat instanceof Number)) { String castTo_name = alice.util.Tools.removeApices(((Struct) castTo).getName()); String castWhat_name = alice.util.Tools.removeApices(castWhat.getTerm().toString()); // System.out.println(castWhat_name+" "+castTo_name); if (castTo_name.equals("java.lang.String") && castWhat_name.equals("true")) { values[i] = "true"; types[i] = String.class; return true; } else if (castTo_name.equals("java.lang.String") && castWhat_name.equals("false")) { values[i] = "false"; types[i] = String.class; return true; } else if (castTo_name.endsWith("[]")) { switch (castTo_name) { case "boolean[]": castTo_name = "[Z"; break; case "byte[]": castTo_name = "[B"; break; case "short[]": castTo_name = "[S"; break; case "char[]": castTo_name = "[C"; break; case "int[]": castTo_name = "[I"; break; case "long[]": castTo_name = "[L"; break; case "float[]": castTo_name = "[F"; break; case "double[]": castTo_name = "[D"; break; default: castTo_name = "[L" + castTo_name.substring(0, castTo_name.length() - 2) + ';'; break; } } if (!castWhat_name.equals("null")) { Object obj_to_cast = currentObjects.get(castWhat_name); if (obj_to_cast == null) { if (castTo_name.equals("boolean")) { switch (castWhat_name) { case "true": values[i] = new Boolean(true); break; case "false": values[i] = new Boolean(false); break; default: return false; } types[i] = Boolean.TYPE; } else { // conversion to array return false; } } else { values[i] = obj_to_cast; try { types[i] = Class.forName(castTo_name, true, dynamicLoader); } catch (ClassNotFoundException ex) { getEngine().logger.warn("Java class not found: " + castTo_name); return false; } } } else { values[i] = null; switch (castTo_name) { case "byte": types[i] = Byte.TYPE; break; case "short": types[i] = Short.TYPE; break; case "char": types[i] = Character.TYPE; break; case "int": types[i] = Integer.TYPE; break; case "long": types[i] = java.lang.Long.TYPE; break; case "float": types[i] = java.lang.Float.TYPE; break; case "double": types[i] = java.lang.Double.TYPE; break; case "boolean": types[i] = Boolean.TYPE; break; default: try { types[i] = Class.forName(castTo_name, true, dynamicLoader); } catch (ClassNotFoundException ex) { getEngine().logger.warn("Java class not found: " + castTo_name); return false; } break; } } } else { Number num = (Number) castWhat; String castTo_name = ((Struct) castTo).getName(); switch (castTo_name) { case "byte": values[i] = new Byte((byte) num.intValue()); types[i] = Byte.TYPE; break; case "short": values[i] = new Short((short) num.intValue()); types[i] = Short.TYPE; break; case "int": values[i] = new Integer(num.intValue()); types[i] = Integer.TYPE; break; case "long": values[i] = new java.lang.Long(num.longValue()); types[i] = java.lang.Long.TYPE; break; case "float": values[i] = new java.lang.Float(num.floatValue()); types[i] = java.lang.Float.TYPE; break; case "double": values[i] = new java.lang.Double(num.doubleValue()); types[i] = java.lang.Double.TYPE; break; default: return false; } } } catch (Exception ex) { getEngine().logger.warn("Casting " + castWhat + " to " + castTo + " failed"); return false; } return true; }
From source file:org.structr.core.entity.AbstractNode.java
private Object convert(Object value, Class type) { Object convertedObject = null; if (type.equals(String.class)) { // strings can be returned immediately return value.toString(); } else if (value instanceof Number) { Number number = (Number) value; if (type.equals(Integer.class) || type.equals(Integer.TYPE)) { return number.intValue(); } else if (type.equals(Long.class) || type.equals(Long.TYPE)) { return number.longValue(); } else if (type.equals(Double.class) || type.equals(Double.TYPE)) { return number.doubleValue(); } else if (type.equals(Float.class) || type.equals(Float.TYPE)) { return number.floatValue(); } else if (type.equals(Short.class) || type.equals(Integer.TYPE)) { return number.shortValue(); } else if (type.equals(Byte.class) || type.equals(Byte.TYPE)) { return number.byteValue(); }//from w w w. ja v a 2 s. com } else if (value instanceof List) { return value; } else if (value instanceof Map) { return value; } // fallback try { Method valueOf = type.getMethod("valueOf", String.class); if (valueOf != null) { convertedObject = valueOf.invoke(null, value.toString()); } else { logger.log(Level.WARNING, "Unable to find static valueOf method for type {0}", type); } } catch (Throwable t) { logger.log(Level.WARNING, "Unable to deserialize value {0} of type {1}, Class has no static valueOf method.", new Object[] { value, type }); } return convertedObject; }
From source file:org.evosuite.testcase.TestCodeVisitor.java
private String getParameterStringForFMthatReturnPrimitive(Class<?> returnType, List<VariableReference> parameters) { assert returnType.isPrimitive(); String parameterString = ""; for (int i = 0; i < parameters.size(); i++) { if (i > 0) { parameterString += ", "; }//from w w w .j a v a 2 s .c om String name = getVariableName(parameters.get(i)); Class<?> parameterType = parameters.get(i).getVariableClass(); if (returnType.equals(parameterType)) { parameterString += name; continue; } GenericClass parameterClass = new GenericClass(parameterType); if (parameterClass.isWrapperType()) { boolean isRightWrapper = false; if (Integer.class.equals(parameterClass.getRawClass())) { isRightWrapper = returnType.equals(Integer.TYPE); } else if (Character.class.equals(parameterClass.getRawClass())) { isRightWrapper = returnType.equals(Character.TYPE); } else if (Boolean.class.equals(parameterClass.getRawClass())) { isRightWrapper = returnType.equals(Boolean.TYPE); } else if (Float.class.equals(parameterClass.getRawClass())) { isRightWrapper = returnType.equals(Float.TYPE); } else if (Double.class.equals(parameterClass.getRawClass())) { isRightWrapper = returnType.equals(Double.TYPE); } else if (Long.class.equals(parameterClass.getRawClass())) { isRightWrapper = returnType.equals(Long.TYPE); } else if (Short.class.equals(parameterClass.getRawClass())) { isRightWrapper = returnType.equals(Short.TYPE); } else if (Byte.class.equals(parameterClass.getRawClass())) { isRightWrapper = returnType.equals(Byte.TYPE); } if (isRightWrapper) { parameterString += name; continue; } } //if we arrive here, it means types are different and not a right wrapper (eg Integer for int) parameterString += "(" + returnType.getName() + ")" + name; if (parameterClass.isWrapperType()) { if (Integer.class.equals(parameterClass.getRawClass())) { parameterString += ".intValue()"; } else if (Character.class.equals(parameterClass.getRawClass())) { parameterString += ".charValue()"; } else if (Boolean.class.equals(parameterClass.getRawClass())) { parameterString += ".booleanValue()"; } else if (Float.class.equals(parameterClass.getRawClass())) { parameterString += ".floatValue()"; } else if (Double.class.equals(parameterClass.getRawClass())) { parameterString += ".doubleValue()"; } else if (Long.class.equals(parameterClass.getRawClass())) { parameterString += ".longValue()"; } else if (Short.class.equals(parameterClass.getRawClass())) { parameterString += ".shortValue()"; } else if (Byte.class.equals(parameterClass.getRawClass())) { parameterString += ".byteValue()"; } } } return parameterString; }
From source file:org.apache.openjpa.meta.FieldMetaData.java
/** * @return The results of unboxing {@code sourceType} following Java Language Specification, 3rd Ed, s5.1.8 *///w ww .j a v a2 s . co m private Class<?> unbox(Class<?> sourceType) { if (sourceType == java.lang.Boolean.class) { return java.lang.Boolean.TYPE; } else if (sourceType == java.lang.Byte.class) { return java.lang.Byte.TYPE; } else if (sourceType == java.lang.Short.class) { return java.lang.Short.TYPE; } else if (sourceType == java.lang.Character.class) { return java.lang.Character.TYPE; } else if (sourceType == java.lang.Integer.class) { return java.lang.Integer.TYPE; } else if (sourceType == java.lang.Long.class) { return java.lang.Long.TYPE; } else if (sourceType == java.lang.Float.class) { return java.lang.Float.TYPE; } else if (sourceType == java.lang.Double.class) { return java.lang.Double.TYPE; } else { return null; } }
From source file:org.apache.openjpa.meta.FieldMetaData.java
/** * @return The results of unboxing {@code sourceType} following Java Language Specification, 3rd Ed, s5.1.7 *//*from ww w .j a v a 2 s . com*/ private Class<?> box(Class<?> sourceType) { if (sourceType.isPrimitive()) { if (sourceType == java.lang.Boolean.TYPE) { return java.lang.Boolean.class; } else if (sourceType == java.lang.Byte.TYPE) { return java.lang.Byte.class; } else if (sourceType == java.lang.Short.TYPE) { return java.lang.Short.class; } else if (sourceType == java.lang.Character.TYPE) { return java.lang.Character.class; } else if (sourceType == java.lang.Integer.TYPE) { return java.lang.Integer.class; } else if (sourceType == java.lang.Long.TYPE) { return java.lang.Long.class; } else if (sourceType == java.lang.Float.TYPE) { return java.lang.Float.class; } else if (sourceType == java.lang.Double.TYPE) { return java.lang.Double.class; } return null; // Should never be reached because all primitives are accounted for above. } else { throw new IllegalArgumentException("Cannot box a type that is not a primitive."); } }
From source file:org.apache.openjpa.meta.FieldMetaData.java
/** * @return true iff {@sourceType} can be converted by a widening primitive conversion * following Java Language Specification, 3rd Ed, s5.1.2 *///from w w w . ja va 2s .c o m private boolean isConvertibleToByWideningPrimitive(Class<?> sourceType, Class<?> destType) { // Widening conversion following Java Language Specification, s5.1.2. if (sourceType == java.lang.Byte.TYPE) { return destType == java.lang.Short.TYPE || destType == java.lang.Integer.TYPE || destType == java.lang.Long.TYPE || destType == java.lang.Float.TYPE || destType == java.lang.Double.TYPE; } else if (sourceType == java.lang.Short.TYPE) { return destType == java.lang.Integer.TYPE || destType == java.lang.Long.TYPE || destType == java.lang.Float.TYPE || destType == java.lang.Double.TYPE; } else if (sourceType == java.lang.Character.TYPE) { return destType == java.lang.Integer.TYPE || destType == java.lang.Long.TYPE || destType == java.lang.Float.TYPE || destType == java.lang.Double.TYPE; } else if (sourceType == java.lang.Integer.TYPE) { return destType == java.lang.Long.TYPE || destType == java.lang.Float.TYPE || destType == java.lang.Double.TYPE; } else if (sourceType == java.lang.Long.TYPE) { return destType == java.lang.Float.TYPE || destType == java.lang.Double.TYPE; } else if (sourceType == java.lang.Float.TYPE) { return destType == java.lang.Double.TYPE; } return false; }