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.kordamp.ezmorph.bean.MorphDynaBean.java
protected boolean isDynaAssignable(Class dest, Class src) { boolean assignable = dest.isAssignableFrom(src); if (assignable) { return true; }//from www . jav a2s. c o m assignable = (dest == Boolean.TYPE && src == Boolean.class) || assignable; assignable = (dest == Byte.TYPE && src == Byte.class) || assignable; assignable = (dest == Character.TYPE && src == Character.class) || assignable; assignable = (dest == Short.TYPE && src == Short.class) || assignable; assignable = (dest == Integer.TYPE && src == Integer.class) || assignable; assignable = (dest == Long.TYPE && src == Long.class) || assignable; assignable = (dest == Float.TYPE && src == Float.class) || assignable; assignable = (dest == Double.TYPE && src == Double.class) || assignable; if (src == Double.TYPE || Double.class.isAssignableFrom(src)) { assignable = (isByte(dest) || isShort(dest) || isInteger(dest) || isLong(dest) || isFloat(dest)) || assignable; } if (src == Float.TYPE || Float.class.isAssignableFrom(src)) { assignable = (isByte(dest) || isShort(dest) || isInteger(dest) || isLong(dest)) || assignable; } if (src == Long.TYPE || Long.class.isAssignableFrom(src)) { assignable = (isByte(dest) || isShort(dest) || isInteger(dest)) || assignable; } if (src == Integer.TYPE || Integer.class.isAssignableFrom(src)) assignable = (isByte(dest) || isShort(dest)) || assignable; if (src == Short.TYPE || Short.class.isAssignableFrom(src)) { assignable = (isByte(dest)) || assignable; } return assignable; }
From source file:org.romaframework.core.schema.SchemaHelper.java
public static Object assignDefaultValueToLiteral(SchemaClass type) { Object value;/*from ww w.jav a 2s .c o m*/ if (type.isOfType(Integer.TYPE)) { value = Integer.valueOf(0); } else if (type.isOfType(Long.TYPE)) { value = Long.valueOf(0); } else if (type.isOfType(Short.TYPE)) { value = Short.valueOf((short) 0); } else if (type.isOfType(Byte.TYPE)) { value = Byte.valueOf((byte) 0); } else if (type.isOfType(Float.TYPE)) { value = Float.valueOf(0); } else if (type.isOfType(Double.TYPE)) { value = Double.valueOf(0); } else { value = null; } return value; }
From source file:org.apache.struts.action.DynaActionForm.java
/** * <p>Return the value of a simple property with the specified name.</p> * * @param name Name of the property whose value is to be retrieved * @return The value of a simple property with the specified name. * @throws IllegalArgumentException if there is no property of the * specified name * @throws NullPointerException if the type specified for the property * is invalid *//*from w w w . j a v a 2 s . c o m*/ public Object get(String name) { // Return any non-null value for the specified property Object value = dynaValues.get(name); if (value != null) { return (value); } // Return a null value for a non-primitive property Class type = getDynaProperty(name).getType(); if (type == null) { throw new NullPointerException("The type for property " + name + " is invalid"); } if (!type.isPrimitive()) { return (value); } // Manufacture default values for primitive properties if (type == Boolean.TYPE) { return (Boolean.FALSE); } else if (type == Byte.TYPE) { return (new Byte((byte) 0)); } else if (type == Character.TYPE) { return (new Character((char) 0)); } else if (type == Double.TYPE) { return (new Double(0.0)); } else if (type == Float.TYPE) { return (new Float((float) 0.0)); } else if (type == Integer.TYPE) { return (new Integer(0)); } else if (type == Long.TYPE) { return (new Long(0)); } else if (type == Short.TYPE) { return (new Short((short) 0)); } else { return (null); } }
From source file:org.exolab.castor.xml.EndElementProcessor.java
public void compute(String name) throws org.xml.sax.SAXException { if (LOG.isTraceEnabled()) { String trace = MessageFormat.format(resourceBundle.getString("unmarshalHandler.log.trace.endElement"), new Object[] { name }); LOG.trace(trace);/*w w w .ja v a 2 s .c om*/ } // -- If we are skipping elements that have appeared in the XML but for // -- which we have no mapping, decrease the ignore depth counter and // return if (_unmarshalHandler.getStrictElementHandler().skipEndElement()) { return; } // -- Do delagation if necessary if (_unmarshalHandler.getAnyNodeHandler().hasAnyUnmarshaller()) { _unmarshalHandler.getAnyNodeHandler().endElement(name); // we are back to the starting node if (_unmarshalHandler.getAnyNodeHandler().isStartingNode()) { _unmarshalHandler.setAnyNode(_unmarshalHandler.getAnyNodeHandler().getStartingNode()); } else return; } if (_unmarshalHandler.getStateStack().isEmpty()) { String err = MessageFormat.format( resourceBundle.getString("unmarshalHandler.error.missing.startElement"), new Object[] { name }); throw new SAXException(err); } // -- * Begin Namespace Handling // -- XXX Note: This code will change when we update the XML event API int idx = name.indexOf(':'); if (idx >= 0) { name = name.substring(idx + 1); } // -- * End Namespace Handling UnmarshalState state = _unmarshalHandler.getStateStack().removeLastState(); // -- make sure we have the correct closing tag XMLFieldDescriptor descriptor = state.getFieldDescriptor(); if (!state.getElementName().equals(name)) { // maybe there is still a container to end if (descriptor.isContainer()) { _unmarshalHandler.getStateStack().pushState(state); // -- check for possible characters added to // -- the container's state that should // -- really belong to the parent state StringBuffer tmpBuffer = null; if (state.getBuffer() != null) { if (!UnmarshalHandler.isWhitespace(state.getBuffer())) { if (state.getClassDescriptor().getContentDescriptor() == null) { tmpBuffer = state.getBuffer(); state.setBuffer(null); } } } // -- end container _unmarshalHandler.endElement(state.getElementName()); if (tmpBuffer != null) { state = _unmarshalHandler.getStateStack().getLastState(); if (state.getBuffer() == null) state.setBuffer(tmpBuffer); else state.getBuffer().append(tmpBuffer.toString()); } _unmarshalHandler.endElement(name); return; } String err = MessageFormat.format( resourceBundle.getString("unmarshalHandler.error.different.endElement.expected"), new Object[] { state.getElementName(), name }); throw new SAXException(err); } // -- clean up current Object Class<?> type = state.getType(); if (type == null) { if (!state.isWrapper()) { // -- this message will only show up if debug // -- is turned on...how should we handle this case? // -- should it be a fatal error? String info = MessageFormat.format( resourceBundle.getString("unmarshalHandler.log.info.no.Descriptor.found"), new Object[] { state.getElementName() }); LOG.info(info); } // -- handle possible location text content // -- TODO: cleanup location path support. // -- the following code needs to be improved as // -- for searching descriptors in this manner can // -- be slow StringBuffer tmpBuffer = null; if (state.getBuffer() != null) { if (!UnmarshalHandler.isWhitespace(state.getBuffer())) { tmpBuffer = state.getBuffer(); state.setBuffer(null); } } if (tmpBuffer != null) { UnmarshalState targetState = state; String locPath = targetState.getElementName(); while ((targetState = targetState.getParent()) != null) { if ((targetState.isWrapper()) || (targetState.getClassDescriptor() == null)) { locPath = targetState.getElementName() + "/" + locPath; continue; } XMLFieldDescriptor tmpDesc = targetState.getClassDescriptor().getContentDescriptor(); if (tmpDesc != null && locPath.equals(tmpDesc.getLocationPath())) { if (targetState.getBuffer() == null) targetState.setBuffer(tmpBuffer); else targetState.getBuffer().append(tmpBuffer.toString()); } } } // -- remove current namespace scoping _unmarshalHandler.getNamespaceHandling().removeCurrentNamespaceInstance(); return; } // -- check for special cases boolean byteArray = false; if (type.isArray()) { byteArray = (type.getComponentType() == Byte.TYPE); } // -- If we don't have an instance object and the Class type // -- is not a primitive or a byte[] we must simply return if ((state.getObject() == null) && (!state.isPrimitiveOrImmutable())) { // -- remove current namespace scoping _unmarshalHandler.getNamespaceHandling().removeCurrentNamespaceInstance(); return; } // / DEBUG System.out.println("end: " + name); if (state.isPrimitiveOrImmutable()) { String str = null; if (state.getBuffer() != null) { str = state.getBuffer().toString(); state.getBuffer().setLength(0); } if (type == String.class && !((XMLFieldDescriptorImpl) descriptor).isDerivedFromXSList()) { if (str != null) state.setObject(str); else if (state.isNil()) { state.setObject(null); } else { state.setObject(""); } } // -- special handling for byte[] else if (byteArray && !descriptor.isDerivedFromXSList()) { if (str == null) state.setObject(new byte[0]); else { state.setObject(_unmarshalHandler.decodeBinaryData(descriptor, str)); } } else if (state.getConstructorArguments() != null) { state.setObject(_unmarshalHandler.createInstance(state.getType(), state.getConstructorArguments())); } else if (descriptor.isMultivalued() && descriptor.getSchemaType() != null && descriptor.getSchemaType().equals("list") && ((XMLFieldDescriptorImpl) descriptor).isDerivedFromXSList()) { StringTokenizer attrValueTokenizer = new StringTokenizer(str); List<Object> primitives = new ArrayList<Object>(); while (attrValueTokenizer.hasMoreTokens()) { String tokenValue = attrValueTokenizer.nextToken(); if (MarshalFramework.isPrimitive(descriptor.getFieldType())) { primitives.add( _unmarshalHandler.toPrimitiveObject(type, tokenValue, state.getFieldDescriptor())); } else { Class<?> valueType = descriptor.getFieldType(); // -- handle base64/hexBinary if (valueType.isArray() && (valueType.getComponentType() == Byte.TYPE)) { primitives.add(_unmarshalHandler.decodeBinaryData(descriptor, tokenValue)); } } } state.setObject(primitives); } else { if (state.isNil()) { state.setObject(null); } else { state.setObject(_unmarshalHandler.toPrimitiveObject(type, str, state.getFieldDescriptor())); } } } else if (ArrayHandler.class.isAssignableFrom(state.getType())) { state.setObject(((ArrayHandler) state.getObject()).getObject()); state.setType(state.getObject().getClass()); } // -- check for character content if ((state.getBuffer() != null) && (state.getBuffer().length() > 0) && (state.getClassDescriptor() != null)) { XMLFieldDescriptor cdesc = state.getClassDescriptor().getContentDescriptor(); if (cdesc != null) { Object value = state.getBuffer().toString(); if (MarshalFramework.isPrimitive(cdesc.getFieldType())) value = _unmarshalHandler.toPrimitiveObject(cdesc.getFieldType(), (String) value, state.getFieldDescriptor()); else { Class<?> valueType = cdesc.getFieldType(); // -- handle base64/hexBinary if (valueType.isArray() && (valueType.getComponentType() == Byte.TYPE)) { value = _unmarshalHandler.decodeBinaryData(descriptor, (String) value); } } try { FieldHandler handler = cdesc.getHandler(); boolean addObject = true; if (_unmarshalHandler.isReuseObjects()) { // -- check to see if we need to // -- add the object or not Object tmp = handler.getValue(state.getObject()); if (tmp != null) { // -- Do not add object if values // -- are equal addObject = (!tmp.equals(value)); } } if (addObject) handler.setValue(state.getObject(), value); } catch (java.lang.IllegalStateException ise) { String err = MessageFormat.format( resourceBundle.getString("unmarshalHandler.error.unable.add.text"), new Object[] { descriptor.getXMLName(), ise.toString() }); throw new SAXException(err, ise); } } // -- Handle references else if (descriptor.isReference()) { UnmarshalState pState = _unmarshalHandler.getStateStack().getLastState(); _unmarshalHandler.processIDREF(state.getBuffer().toString(), descriptor, pState.getObject()); _unmarshalHandler.getNamespaceHandling().removeCurrentNamespaceInstance(); return; } else { // -- check for non-whitespace...and report error if (!UnmarshalHandler.isWhitespace(state.getBuffer())) { String err = MessageFormat.format( resourceBundle.getString("unmarshalHandler.error.illegal.text"), new Object[] { name, state.getBuffer() }); throw new SAXException(err); } } } // -- We're finished processing the object, so notify the // -- Listener (if any). Object stateObject = state.getObject(); Object parentObject = (state.getParent() == null) ? null : state.getParent().getObject(); _unmarshalHandler.getDelegateUnmarshalListener().unmarshalled(stateObject, parentObject); // -- if we are at root....just validate and we are done if (_unmarshalHandler.getStateStack().isEmpty()) { if (_unmarshalHandler.isValidating()) { ValidationException first = null; ValidationException last = null; // -- check unresolved references if (_unmarshalHandler.getResolveTable() != null && !_unmarshalHandler.getInternalContext().getLenientIdValidation()) { Enumeration enumeration = _unmarshalHandler.getResolveTable().keys(); while (enumeration.hasMoreElements()) { Object ref = enumeration.nextElement(); // if // (ref.toString().startsWith(MapItem.class.getName())) // continue; String msg = "unable to resolve reference: " + ref; if (first == null) { first = new ValidationException(msg); last = first; } else { last.setNext(new ValidationException(msg)); last = last.getNext(); } } } try { Validator validator = new Validator(); ValidationContext context = new ValidationContext(); context.setInternalContext(_unmarshalHandler.getInternalContext()); validator.validate(state.getObject(), context); if (!_unmarshalHandler.getInternalContext().getLenientIdValidation()) { validator.checkUnresolvedIdrefs(context); } context.cleanup(); } catch (ValidationException vEx) { if (first == null) first = vEx; else last.setNext(vEx); } if (first != null) { throw new SAXException(first); } } return; } // -- Add object to parent if necessary if (descriptor.isIncremental()) { // -- remove current namespace scoping _unmarshalHandler.getNamespaceHandling().removeCurrentNamespaceInstance(); return; // -- already added } Object val = state.getObject(); // --special code for AnyNode handling if (_unmarshalHandler.getAnyNode() != null) { val = _unmarshalHandler.getAnyNode(); _unmarshalHandler.setAnyNode(null); } // -- save fieldState UnmarshalState fieldState = state; // -- have we seen this object before? boolean firstOccurance = false; // -- get target object state = _unmarshalHandler.getStateStack().getLastState(); if (state.isWrapper()) { state = fieldState.getTargetState(); } // -- check to see if we have already read in // -- an element of this type. // -- (Q: if we have a container, do we possibly need to // -- also check the container's multivalued status?) if (!descriptor.isMultivalued()) { if (state.isUsed(descriptor)) { String location = name; while (!_unmarshalHandler.getStateStack().isEmpty()) { UnmarshalState tmpState = _unmarshalHandler.getStateStack().removeLastState(); if (!tmpState.isWrapper()) { if (tmpState.getFieldDescriptor().isContainer()) continue; } location = state.getElementName() + "/" + location; } String err = MessageFormat.format( resourceBundle.getString("unmarshalHandler.error.element.occurs.more.than.once"), new Object[] { name, state.getType().getName(), location }); ValidationException vx = new ValidationException(err); throw new SAXException(vx); } state.markAsUsed(descriptor); // -- if this is the identity then save id if (state.getClassDescriptor().getIdentity() == descriptor) { state.setKey(val); } } else { // -- check occurance of descriptor if (!state.isUsed(descriptor)) { firstOccurance = true; } // -- record usage of descriptor state.markAsUsed(descriptor); } try { FieldHandler handler = descriptor.getHandler(); // check if the value is a QName that needs to // be resolved (ns:value -> {URI}value) String valueType = descriptor.getSchemaType(); if ((valueType != null) && (valueType.equals(MarshalFramework.QNAME_NAME))) { val = _unmarshalHandler.getNamespaceHandling().resolveNamespace(val); } boolean addObject = true; if (_unmarshalHandler.isReuseObjects() && fieldState.isPrimitiveOrImmutable()) { // -- check to see if we need to // -- add the object or not Object tmp = handler.getValue(state.getObject()); if (tmp != null) { // -- Do not add object if values // -- are equal addObject = (!tmp.equals(val)); } } // -- special handling for mapped objects if (descriptor.isMapped()) { if (!(val instanceof MapItem)) { MapItem mapItem = new MapItem(fieldState.getKey(), val); val = mapItem; } else { // -- make sure value exists (could be a reference) MapItem mapItem = (MapItem) val; if (mapItem.getValue() == null) { // -- save for later... addObject = false; _unmarshalHandler.addReference(mapItem.toString(), state.getObject(), descriptor); } } } if (addObject) { // -- clear any collections if necessary if (firstOccurance && _unmarshalHandler.isClearCollections()) { handler.resetValue(state.getObject()); } if (descriptor.isMultivalued() && descriptor.getSchemaType() != null && descriptor.getSchemaType().equals("list") && ((XMLFieldDescriptorImpl) descriptor).isDerivedFromXSList()) { List<Object> values = (List<Object>) val; for (Object value : values) { // -- finally set the value!! handler.setValue(state.getObject(), value); // If there is a parent for this object, pass along // a notification that we've finished adding a child _unmarshalHandler.getDelegateUnmarshalListener().fieldAdded(descriptor.getFieldName(), state.getObject(), fieldState.getObject()); } } else { // -- finally set the value!! handler.setValue(state.getObject(), val); // If there is a parent for this object, pass along // a notification that we've finished adding a child _unmarshalHandler.getDelegateUnmarshalListener().fieldAdded(descriptor.getFieldName(), state.getObject(), fieldState.getObject()); } } } /* * catch(java.lang.reflect.InvocationTargetException itx) { * * Throwable toss = itx.getTargetException(); if (toss == null) toss = itx; * * String err = "unable to add '" + name + "' to <"; err += state.descriptor.getXMLName(); err * += "> due to the following exception: " + toss; throw new SAXException(err); } */ catch (Exception ex) { StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); ex.printStackTrace(pw); pw.flush(); String err = MessageFormat.format(resourceBundle.getString("unmarshalHandler.error.unable.add.element"), new Object[] { name, state.getFieldDescriptor().getXMLName(), sw.toString() }); throw new SAXException(err, ex); } // -- remove current namespace scoping _unmarshalHandler.getNamespaceHandling().removeCurrentNamespaceInstance(); // remove additional (artifical aka container) state introduced for // single-valued (iow maxOccurs="1") choices. if (state.getFieldDescriptor().isContainer() && state.getClassDescriptor().isChoice() && !state.getFieldDescriptor().isMultivalued()) { _unmarshalHandler.endElement(state.getElementName()); } }
From source file:jp.terasoluna.fw.web.struts.reset.ResetterImpl.java
/** * ANVtH?[wv?peBZbg?B/* w ww . j a v a2 s .c o m*/ * v?peB^boolean^?ABoolean^??false??B * v~eBu^bp?[^???A0??B * v?peB^bp?[^OObject^??null??B<br> * ??A?entrynulln?B * * @param form ?NGXggpANVtH?[ * @param entry Zbg?v?peB?lGg * @throws PropertyAccessException v?peBl?s?? */ protected void resetValue(FormEx form, Entry<String, Object> entry) { if (log.isDebugEnabled()) { log.debug("resetValue(" + form + ", " + entry.getKey() + ") called."); } String propName = entry.getKey(); try { Object value = entry.getValue(); if (value == null) { return; } Class type = null; type = value.getClass(); if (type != null) { // ^???B if (type == Boolean.TYPE || type == Boolean.class) { BeanUtil.setBeanProperty(form, propName, Boolean.FALSE); } else if (type == Byte.TYPE || type == Byte.class) { BeanUtil.setBeanProperty(form, propName, new Byte((byte) 0)); } else if (type == Character.TYPE || type == Character.class) { BeanUtil.setBeanProperty(form, propName, new Character((char) 0)); } else if (type == Double.TYPE || type == Double.class) { BeanUtil.setBeanProperty(form, propName, new Double(0.0)); } else if (type == Float.TYPE || type == Float.class) { BeanUtil.setBeanProperty(form, propName, new Float((float) 0.0)); } else if (type == Integer.TYPE || type == Integer.class) { BeanUtil.setBeanProperty(form, propName, new Integer(0)); } else if (type == Long.TYPE || type == Long.class) { BeanUtil.setBeanProperty(form, propName, new Long(0)); } else if (type == Short.TYPE || type == Short.class) { BeanUtil.setBeanProperty(form, propName, new Short((short) 0)); } else { // v~eBu^?Abp?[^??null? BeanUtil.setBeanProperty(form, propName, null); } } } catch (PropertyAccessException e) { log.error("cannot access property " + form + "." + propName, e); } }
From source file:org.apache.mina.statemachine.transition.MethodTransition.java
@SuppressWarnings("unchecked") private boolean match(Class<?> paramType, Object arg, Class argType) { if (paramType.isPrimitive()) { if (paramType.equals(Boolean.TYPE)) { return arg instanceof Boolean; }/*from ww w. j ava2s . c om*/ if (paramType.equals(Integer.TYPE)) { return arg instanceof Integer; } if (paramType.equals(Long.TYPE)) { return arg instanceof Long; } if (paramType.equals(Short.TYPE)) { return arg instanceof Short; } if (paramType.equals(Byte.TYPE)) { return arg instanceof Byte; } if (paramType.equals(Double.TYPE)) { return arg instanceof Double; } if (paramType.equals(Float.TYPE)) { return arg instanceof Float; } if (paramType.equals(Character.TYPE)) { return arg instanceof Character; } } return argType.isAssignableFrom(paramType) && paramType.isAssignableFrom(arg.getClass()); }
From source file:org.openTwoFactor.clientExt.net.sf.ezmorph.bean.MorphDynaBean.java
protected boolean isDynaAssignable(Class dest, Class src) { boolean assignable = dest.isAssignableFrom(src); if (assignable) { return true; }/*w w w .java2 s . c o m*/ assignable = (dest == Boolean.TYPE && src == Boolean.class) ? true : assignable; assignable = (dest == Byte.TYPE && src == Byte.class) ? true : assignable; assignable = (dest == Character.TYPE && src == Character.class) ? true : assignable; assignable = (dest == Short.TYPE && src == Short.class) ? true : assignable; assignable = (dest == Integer.TYPE && src == Integer.class) ? true : assignable; assignable = (dest == Long.TYPE && src == Long.class) ? true : assignable; assignable = (dest == Float.TYPE && src == Float.class) ? true : assignable; assignable = (dest == Double.TYPE && src == Double.class) ? true : assignable; if (src == Double.TYPE || Double.class.isAssignableFrom(src)) { assignable = (isByte(dest) || isShort(dest) || isInteger(dest) || isLong(dest) || isFloat(dest)) ? true : assignable; } if (src == Float.TYPE || Float.class.isAssignableFrom(src)) { assignable = (isByte(dest) || isShort(dest) || isInteger(dest) || isLong(dest)) ? true : assignable; } if (src == Long.TYPE || Long.class.isAssignableFrom(src)) { assignable = (isByte(dest) || isShort(dest) || isInteger(dest)) ? true : assignable; } if (src == Integer.TYPE || Integer.class.isAssignableFrom(src)) { assignable = (isByte(dest) || isShort(dest)) ? true : assignable; } if (src == Short.TYPE || Short.class.isAssignableFrom(src)) { assignable = (isByte(dest)) ? true : assignable; } return assignable; }
From source file:com.adobe.acs.commons.data.Variant.java
@SuppressWarnings("squid:S3776") public <T> T asType(Class<T> type) { if (type == Byte.TYPE || type == Byte.class) { return (T) apply(toLong(), Long::byteValue); } else if (type == Integer.TYPE || type == Integer.class) { return (T) apply(toLong(), Long::intValue); } else if (type == Long.TYPE || type == Long.class) { return (T) toLong(); } else if (type == Short.TYPE || type == Short.class) { return (T) apply(toLong(), Long::shortValue); } else if (type == Float.TYPE || type == Float.class) { return (T) apply(toDouble(), Double::floatValue); } else if (type == Double.TYPE || type == Double.class) { return (T) toDouble(); } else if (type == Boolean.TYPE || type == Boolean.class) { return (T) toBoolean(); } else if (type == String.class) { return (T) toString(); } else if (type == Date.class) { return (T) toDate(); } else if (type == Instant.class) { return (T) toDate().toInstant(); } else if (type == Calendar.class) { Calendar c = Calendar.getInstance(); c.setTime(toDate());/*from www. j a v a2 s . c om*/ return (T) c; } else { return null; } }
From source file:javadz.beanutils.ConvertUtilsBean.java
/** * Sets the default value for Byte conversions. * @param newDefaultByte The default Byte value * @deprecated Register replacement converters for Byte.TYPE and * Byte.class instead//w w w. jav a 2 s. c o m */ public void setDefaultByte(byte newDefaultByte) { defaultByte = new Byte(newDefaultByte); register(new ByteConverter(defaultByte), Byte.TYPE); register(new ByteConverter(defaultByte), Byte.class); }
From source file:org.wisdom.template.thymeleaf.OgnlOpsByReflectionTest.java
@Test public void testConvertValue() throws Exception { Class[] classes = new Class[] { Object.class, Class.class }; // Null value assertThat(invoke("convertValue", classes, null, Long.TYPE)).isEqualTo(0l); assertThat(invoke("convertValue", classes, null, String.class)).isNull(); // Primitive//from www.ja v a 2 s. co m assertThat(invoke("convertValue", classes, "42", Integer.class)).isEqualTo(42); assertThat(invoke("convertValue", classes, "42", Integer.TYPE)).isEqualTo(42); assertThat(invoke("convertValue", classes, "42", Byte.class)).isEqualTo(Byte.valueOf("42")); assertThat(invoke("convertValue", classes, "42", Byte.TYPE)).isEqualTo(Byte.valueOf("42")); assertThat(invoke("convertValue", classes, "42", Short.class)).isEqualTo(Short.valueOf("42")); assertThat(invoke("convertValue", classes, "42", Short.TYPE)).isEqualTo(Short.valueOf("42")); assertThat(invoke("convertValue", classes, String.valueOf((int) 'c'), Character.class)).isEqualTo('c'); assertThat(invoke("convertValue", classes, String.valueOf((int) 'c'), Character.TYPE)).isEqualTo('c'); assertThat(invoke("convertValue", classes, "42", Long.class)).isEqualTo(42l); assertThat(invoke("convertValue", classes, "42", Long.TYPE)).isEqualTo(42l); assertThat(invoke("convertValue", classes, "true", Boolean.class)).isEqualTo(true); assertThat(invoke("convertValue", classes, "true", Boolean.TYPE)).isEqualTo(true); assertThat(invoke("convertValue", classes, "42", Double.class)).isEqualTo(42.0); assertThat(invoke("convertValue", classes, "42", Double.TYPE)).isEqualTo(42.0); assertThat(invoke("convertValue", classes, "42", Float.class)).isEqualTo(42.0f); assertThat(invoke("convertValue", classes, "42", Float.TYPE)).isEqualTo(42.0f); // BigInteger, BigDecimal and String assertThat(invoke("convertValue", classes, "42", BigDecimal.class)).isEqualTo(new BigDecimal("42")); assertThat(invoke("convertValue", classes, "42", BigInteger.class)).isEqualTo(new BigInteger("42")); assertThat(invoke("convertValue", classes, "42", String.class)).isEqualTo("42"); //Array assertThat(invoke("convertValue", classes, new Object[] { 1, 2, 3 }, (new int[0]).getClass())).isNotNull(); }