當前位置: 首頁>>代碼示例>>Java>>正文


Java ClassUtils.primitiveToWrapper方法代碼示例

本文整理匯總了Java中org.apache.commons.lang.ClassUtils.primitiveToWrapper方法的典型用法代碼示例。如果您正苦於以下問題:Java ClassUtils.primitiveToWrapper方法的具體用法?Java ClassUtils.primitiveToWrapper怎麽用?Java ClassUtils.primitiveToWrapper使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.apache.commons.lang.ClassUtils的用法示例。


在下文中一共展示了ClassUtils.primitiveToWrapper方法的14個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: convert

import org.apache.commons.lang.ClassUtils; //導入方法依賴的package包/類
@Override
public Number convert(final Class<? extends Number> targetType, final String value) {
	if (StringUtils.isBlank(value)) {
		if (targetType.isPrimitive()) {
			return convert(targetType, "0");
		}
		return null;
	}
	if (targetType == Number.class) {
		return new Float(value);
	}
	final Class<? extends Number> wrapperType = targetType.isPrimitive() ? ClassUtils.primitiveToWrapper(targetType)
			: targetType;
	try {
		return wrapperType.getConstructor(String.class).newInstance(value);
	} catch (final InstantiationException | IllegalAccessException | InvocationTargetException
			| NoSuchMethodException e) {
		throw new IllegalArgumentException(e);
	}
}
 
開發者ID:liefke,項目名稱:org.fastnate,代碼行數:21,代碼來源:CsvNumberConverter.java

示例2: unmarshal

import org.apache.commons.lang.ClassUtils; //導入方法依賴的package包/類
/**
 * TODO: decide if this method should be marked @NotNull.
 * Basically the problem is with primitives. When parsed, they sometimes return null. The question is if it's correct.
 */
<T> T unmarshal(@NotNull XNode xnode, @NotNull Class<T> beanClass, @NotNull ParsingContext pc) throws SchemaException {
	T value = unmarshalInternal(xnode, beanClass, pc);
	if (PrismContextImpl.isExtraValidation() && value != null) {
		Class<?> requested = ClassUtils.primitiveToWrapper(beanClass);
		Class<?> actual = ClassUtils.primitiveToWrapper(value.getClass());
		if (!requested.isAssignableFrom(actual)) {
			throw new AssertionError("Postcondition fail: unmarshal returned a value of " + value + " ("
					+ actual + ") which is not of requested type (" + requested + ")");
		}
	}
	return value;
}
 
開發者ID:Pardus-Engerek,項目名稱:engerek,代碼行數:17,代碼來源:BeanUnmarshaller.java

示例3: isTypeCompliant

import org.apache.commons.lang.ClassUtils; //導入方法依賴的package包/類
public static <T> boolean isTypeCompliant(@Nullable T value, @Nullable Class<?> expectedClass) {
	if (value == null || expectedClass == null) {
		return true;
	}
	Class<?> wrapped = ClassUtils.primitiveToWrapper(expectedClass);
	return wrapped.isAssignableFrom(((Object) value).getClass());		// auto-boxing of primitive types

	// TODO PolyString vs String - should be treated here?
	// TODO int vs long vs ...
}
 
開發者ID:Pardus-Engerek,項目名稱:engerek,代碼行數:11,代碼來源:JavaTypeConverter.java

示例4: createTypedInputComponent

import org.apache.commons.lang.ClassUtils; //導入方法依賴的package包/類
private InputPanel createTypedInputComponent(String id, PrismPropertyDefinition definition) {
    QName valueType = definition.getTypeName();

    final String baseExpression = ACValueConstructionDto.F_VALUE;

    InputPanel panel;
    if (DOMUtil.XSD_DATETIME.equals(valueType)) {
        panel = new DatePanel(id, new PropertyModel<XMLGregorianCalendar>(getModel(), baseExpression));
    } else if (ProtectedStringType.COMPLEX_TYPE.equals(valueType)) {
        panel = new PasswordPanel(id, new PropertyModel<ProtectedStringType>(getModel(), baseExpression));
    } else if (DOMUtil.XSD_BOOLEAN.equals(valueType)) {
        panel = new TriStateComboPanel(id, new PropertyModel<Boolean>(getModel(), baseExpression));
    } else if (SchemaConstants.T_POLY_STRING_TYPE.equals(valueType)) {
        panel = new TextPanel<String>(id, new PropertyModel<String>(getModel(), baseExpression + ".orig"), String.class);
    } else {
        Class type = XsdTypeMapper.getXsdToJavaMapping(valueType);
        if (type != null && type.isPrimitive()) {
            type = ClassUtils.primitiveToWrapper(type);
        }
        panel = new TextPanel<String>(id, new PropertyModel<String>(getModel(), baseExpression),
                type);

        if (ObjectType.F_NAME.equals(definition.getName())) {
            panel.getBaseFormComponent().setRequired(true);
        }
    }

    return panel;
}
 
開發者ID:Pardus-Engerek,項目名稱:engerek,代碼行數:30,代碼來源:ACAttributeValuePanel.java

示例5: getKeyValue

import org.apache.commons.lang.ClassUtils; //導入方法依賴的package包/類
private Object getKeyValue(Number result, Class<?> returnType) {
    if (returnType.isPrimitive()) {
        returnType = ClassUtils.primitiveToWrapper(returnType);
    }
    if (result == null || returnType == void.class) {
        return null;
    }
    if (returnType == result.getClass()) {
        return result;
    }
    // 將結果轉成方法的返回類型
    if (returnType == Integer.class) {
        return result.intValue();
    } else if (returnType == Long.class) {
        return result.longValue();
    } else if (returnType == Boolean.class) {
        return result.intValue() > 0 ? Boolean.TRUE : Boolean.FALSE;
    } else if (returnType == Double.class) {
        return result.doubleValue();
    } else if (returnType == Float.class) {
        return result.floatValue();
    } else if (returnType == Number.class) {
        return result;
    } else if (returnType == String.class
            || returnType == CharSequence.class) {
        return String.valueOf(result);
    } else {
        return null;
    }
}
 
開發者ID:xuegongzi,項目名稱:rabbitframework,代碼行數:31,代碼來源:PreparedStatementHandler.java

示例6: isInstance

import org.apache.commons.lang.ClassUtils; //導入方法依賴的package包/類
/**
 * Returns if the given object is an instance of the specified class, handling primitives as objects
 */
public static boolean isInstance(Class<?> clazz, final Object object) {
    if (clazz.isPrimitive()) {
        clazz = ClassUtils.primitiveToWrapper(clazz);
    }
    return clazz.isInstance(object);
}
 
開發者ID:mateli,項目名稱:OpenCyclos,代碼行數:10,代碼來源:ClassHelper.java

示例7: getFromJavaType

import org.apache.commons.lang.ClassUtils; //導入方法依賴的package包/類
public static Type getFromJavaType(Class type)
{
  for (Type supportType : Type.values()) {
    if (supportType.getJavaType() == ClassUtils.primitiveToWrapper(type)) {
      return supportType;
    }
  }

  return OBJECT;
}
 
開發者ID:apache,項目名稱:apex-malhar,代碼行數:11,代碼來源:TupleSchemaRegistry.java

示例8: ToStringFieldHandler

import org.apache.commons.lang.ClassUtils; //導入方法依賴的package包/類
/**
 * Creates a new instance of this handler.
 *
 * @param type
 *            the class of the associated field
 * @throws NoSuchMethodException
 *             if the string constructor for the given type was not found
 */
public ToStringFieldHandler(final Class<T> type) throws NoSuchMethodException {
	Class<T> wrapper = ClassUtils.primitiveToWrapper(type);
	this.constructor = wrapper.getConstructor(String.class);
	Type elementType = null;
	while (wrapper != null && elementType == null) {
		elementType = TYPES.get(wrapper);
		wrapper = (Class<T>) wrapper.getSuperclass();
	}
	this.type = elementType == null ? Type.TEXT : elementType;
}
 
開發者ID:liefke,項目名稱:org.portletbeans,代碼行數:19,代碼來源:ToStringFieldHandler.java

示例9: getWrapper

import org.apache.commons.lang.ClassUtils; //導入方法依賴的package包/類
private Type getWrapper(Type t) {
    if (t instanceof Class) {
        if (((Class) t).isPrimitive()) {
            t = ClassUtils.primitiveToWrapper((Class) t);
        }
    }
    return t;
}
 
開發者ID:ggkochanski,項目名稱:itest,代碼行數:9,代碼來源:SimpleJsonFormatter.java

示例10: createConverter

import org.apache.commons.lang.ClassUtils; //導入方法依賴的package包/類
/**
 * Creates a converter for a primitive type.
 *
 * @param <T>
 *            the generic type
 * @param <E>
 *            the element type
 * @param attribute
 *            the accessor for the attribute that contains the value, not nessecarily of the target type
 * @param targetType
 *            the primitive type
 * @param mapKey
 *            indicates that the converter is for the key of a map
 * @return the converter or {@link UnsupportedTypeConverter} if no converter is available
 */
@SuppressWarnings("unchecked")
public static <T, E extends Enum<E>> ValueConverter<T> createConverter(final AttributeAccessor attribute,
		final Class<T> targetType, final boolean mapKey) {
	if (attribute.isAnnotationPresent(Lob.class)) {
		return (ValueConverter<T>) new LobConverter();
	}
	if (String.class == targetType) {
		return (ValueConverter<T>) new StringConverter(attribute, mapKey);
	}
	if (Date.class.isAssignableFrom(targetType)) {
		return (ValueConverter<T>) new DateConverter(attribute, mapKey);
	}
	if (Calendar.class.isAssignableFrom(targetType)) {
		return (ValueConverter<T>) new CalendarConverter(attribute, mapKey);
	}
	if (Enum.class.isAssignableFrom(targetType)) {
		return (ValueConverter<T>) new EnumConverter<>(attribute, (Class<E>) targetType, mapKey);
	}
	final Class<T> type = ClassUtils.primitiveToWrapper(targetType);
	if (Character.class == type) {
		return (ValueConverter<T>) new CharConverter();
	}
	if (Boolean.class == type) {
		return (ValueConverter<T>) new BooleanConverter();
	}
	if (Number.class.isAssignableFrom(type)) {
		return (ValueConverter<T>) new NumberConverter((Class<Number>) type);
	}
	if (Serializable.class.isAssignableFrom(type)) {
		return (ValueConverter<T>) new SerializableConverter();
	}
	return (ValueConverter<T>) new UnsupportedTypeConverter(attribute);
}
 
開發者ID:liefke,項目名稱:org.fastnate,代碼行數:49,代碼來源:PrimitiveProperty.java

示例11: translate

import org.apache.commons.lang.ClassUtils; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
@Override
public List<E> translate(SIFDataObject sifData, String zoneId) throws SifTranslationException {
    Class<?> wrappedSifClass = ClassUtils.primitiveToWrapper(sifData.getClass());

    if (!sifPrototype.equals(wrappedSifClass)) {
        throw new SifTranslationException("Unsupported SIF data type");
    }
    return doTranslate((T) sifData, zoneId);
}
 
開發者ID:inbloom,項目名稱:secure-data-service,代碼行數:11,代碼來源:AbstractTranslationTask.java

示例12: getWrapper

import org.apache.commons.lang.ClassUtils; //導入方法依賴的package包/類
public Class getWrapper(String premitive) throws ClassNotFoundException {
    return ClassUtils.primitiveToWrapper(ClassUtils.getClass(premitive));
}
 
開發者ID:jeddict,項目名稱:jeddict,代碼行數:4,代碼來源:VariableDefSnippet.java

示例13: checkValueType

import org.apache.commons.lang.ClassUtils; //導入方法依賴的package包/類
private Object checkValueType(Object value, ValueFilter filter) throws QueryException {

        Class expectedType = linkDefinition.getTargetDefinition().getJaxbClass();
        if (expectedType == null || value == null) {
            return value;   // nothing to check here
        }

        if (expectedType.isPrimitive()) {
            expectedType = ClassUtils.primitiveToWrapper(expectedType);
        }

        //todo remove after some time [lazyman]
        //attempt to fix value type for polystring (if it was string in filter we create polystring from it)
        if (PolyString.class.equals(expectedType) && (value instanceof String)) {
            LOGGER.debug("Trying to query PolyString value but filter contains String '{}'.", filter);
			String orig = (String) value;
			value = new PolyString(orig, context.getPrismContext().getDefaultPolyStringNormalizer().normalize(orig));
        }
        //attempt to fix value type for polystring (if it was polystringtype in filter we create polystring from it)
        if (PolyString.class.equals(expectedType) && (value instanceof PolyStringType)) {
            LOGGER.debug("Trying to query PolyString value but filter contains PolyStringType '{}'.", filter);
            PolyStringType type = (PolyStringType) value;
            value = new PolyString(type.getOrig(), type.getNorm());
        }

        if (String.class.equals(expectedType) && (value instanceof QName)) {
            //eg. shadow/objectClass
            value = RUtil.qnameToString((QName) value);
        }

        if (value instanceof RawType) {     // MID-3850: but it's quite a workaround. Maybe we should treat RawType's earlier than this.
            try {
                return ((RawType) value).getParsedRealValue(expectedType);
            } catch (SchemaException e) {
                throw new QueryException("Couldn't parse value " + value + " as " + expectedType + ": " + e.getMessage(), e);
            }
        }

        if (!expectedType.isAssignableFrom(value.getClass())) {
            throw new QueryException("Value should be type of '" + expectedType + "' but it's '"
                    + value.getClass() + "', filter '" + filter + "'.");
        }
        return value;
    }
 
開發者ID:Evolveum,項目名稱:midpoint,代碼行數:45,代碼來源:PropertyRestriction.java

示例14: getFields

import org.apache.commons.lang.ClassUtils; //導入方法依賴的package包/類
/**
 * Recupera todos os campos descobertos no relacionamento
 * @return
 */
public JRField[] getFields(){
	
	JRField[] keyFields = new JRDesignField[this.fields.size()];
	
	int i=0;
	for (JazzJRNavigableField jrField : this.fields) {
		
		String name = jrField.getName();
		JRDesignField jrDesignField = new JRDesignField();
		jrDesignField.setName(name);
		jrDesignField.setDescription(jrField.getDescription());
		
		Class<?> valueClass = jrField.getValueClass();
		valueClass = ClassUtils.primitiveToWrapper(valueClass);
		
		
		
		jrDesignField.setValueClass(valueClass);
		jrDesignField.setValueClassName(valueClass.getName());
		
		keyFields[i] = jrDesignField;
		
		
		//System.out.println("<field name=\""+name+"\" class=\""+valueClass.getName()+"\"/>");
		
		//<field name="exv_pk" class="java.lang.Long"/>
		
		i++;
	}
	
	return keyFields;
}
 
開發者ID:darciopacifico,項目名稱:omr,代碼行數:37,代碼來源:JazzJRDataSource.java


注:本文中的org.apache.commons.lang.ClassUtils.primitiveToWrapper方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。