本文整理汇总了Java中org.apache.commons.lang3.ClassUtils.wrapperToPrimitive方法的典型用法代码示例。如果您正苦于以下问题:Java ClassUtils.wrapperToPrimitive方法的具体用法?Java ClassUtils.wrapperToPrimitive怎么用?Java ClassUtils.wrapperToPrimitive使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.lang3.ClassUtils
的用法示例。
在下文中一共展示了ClassUtils.wrapperToPrimitive方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getPrimitivePromotionCost
import org.apache.commons.lang3.ClassUtils; //导入方法依赖的package包/类
/**
* Gets the number of steps required to promote a primitive number to another
* type.
*
* @param srcClass the (primitive) source class
* @param destClass the (primitive) destination class
* @return The cost of promoting the primitive
*/
private static float getPrimitivePromotionCost(final Class<?> srcClass, final Class<?> destClass) {
float cost = 0.0f;
Class<?> cls = srcClass;
if (!cls.isPrimitive()) {
// slight unwrapping penalty
cost += 0.1f;
cls = ClassUtils.wrapperToPrimitive(cls);
}
for (int i = 0; cls != destClass && i < ORDERED_PRIMITIVE_TYPES.length; i++) {
if (cls == ORDERED_PRIMITIVE_TYPES[i]) {
cost += 0.1f;
if (i < ORDERED_PRIMITIVE_TYPES.length - 1) {
cls = ORDERED_PRIMITIVE_TYPES[i + 1];
}
}
}
return cost;
}
示例2: getPrimitivePromotionCost
import org.apache.commons.lang3.ClassUtils; //导入方法依赖的package包/类
/**
* Gets the number of steps required to promote a primitive number to another
* type.
* @param srcClass the (primitive) source class
* @param destClass the (primitive) destination class
* @return The cost of promoting the primitive
*/
private static float getPrimitivePromotionCost(final Class<?> srcClass, final Class<?> destClass) {
float cost = 0.0f;
Class<?> cls = srcClass;
if (!cls.isPrimitive()) {
// slight unwrapping penalty
cost += 0.1f;
cls = ClassUtils.wrapperToPrimitive(cls);
}
for (int i = 0; cls != destClass && i < ORDERED_PRIMITIVE_TYPES.length; i++) {
if (cls == ORDERED_PRIMITIVE_TYPES[i]) {
cost += 0.1f;
if (i < ORDERED_PRIMITIVE_TYPES.length - 1) {
cls = ORDERED_PRIMITIVE_TYPES[i + 1];
}
}
}
return cost;
}
示例3: forPrimitiveWrapper
import org.apache.commons.lang3.ClassUtils; //导入方法依赖的package包/类
private static AccessInfo forPrimitiveWrapper(String memberType, Class<?> clazz) {
Class<?> primitiveClass = ClassUtils.wrapperToPrimitive(clazz);
String camelCaseClassName = WordUtils.capitalize(primitiveClass.getName());
String capitalizedMemberType = WordUtils.capitalize(memberType);
return new AccessInfo(
memberType,
"getBoxed" + camelCaseClassName + capitalizedMemberType,
"setBoxed" + camelCaseClassName + capitalizedMemberType,
clazz.getName(),
Type.getDescriptor(clazz),
ALOAD,
ARETURN);
}
示例4: newInstanceOf
import org.apache.commons.lang3.ClassUtils; //导入方法依赖的package包/类
private Object newInstanceOf(Class<?> clazz) {
if (clazz.isPrimitive()) {
return newPrimitiveOf(clazz);
}
Class<?> wrappedPrimitive = ClassUtils.wrapperToPrimitive(clazz);
if (wrappedPrimitive != null) {
Object value = newPrimitiveOf(wrappedPrimitive);
return newWrappedPrimitive(clazz, value instanceof Number ? value.toString() : value);
}
return newObjectOfType(clazz);
}
开发者ID:Enterprise-Content-Management,项目名称:infoarchive-sip-sdk,代码行数:12,代码来源:WhenTransferringDataUsingObjects.java
示例5: getMetricsSchemaData
import org.apache.commons.lang3.ClassUtils; //导入方法依赖的package包/类
private JSONObject getMetricsSchemaData(LogicalPlan.OperatorMeta operatorMeta, Map<String, Object> aggregates)
{
JSONObject result = new JSONObject();
try {
result.put("type", METRICS_SCHEMA);
result.put("version", METRICS_SCHEMA_VERSION);
result.put("appUser", appContext.getUser());
result.put("appName", dnmgr.getApplicationAttributes().get(DAGContext.APPLICATION_NAME));
result.put("logicalOperatorName", operatorMeta.getName());
MetricAggregatorMeta metricAggregatorMeta = operatorMeta.getMetricAggregatorMeta();
JSONArray valueSchemas = new JSONArray();
for (Map.Entry<String, Object> entry : aggregates.entrySet()) {
String metricName = entry.getKey();
Object metricValue = entry.getValue();
JSONObject valueSchema = new JSONObject();
valueSchema.put("name", metricName);
Class<?> type = ClassUtils.wrapperToPrimitive(metricValue.getClass());
valueSchema.put("type", type == null ? metricValue.getClass().getCanonicalName() : type);
String[] dimensionAggregators = metricAggregatorMeta.getDimensionAggregatorsFor(metricName);
if (dimensionAggregators != null) {
valueSchema.put("dimensionAggregators", Arrays.asList(dimensionAggregators));
}
valueSchemas.put(valueSchema);
}
result.put("values", valueSchemas);
String[] timeBuckets = metricAggregatorMeta.getTimeBuckets();
if (timeBuckets != null) {
result.put("timeBuckets", Arrays.asList(timeBuckets));
}
} catch (JSONException ex) {
throw new RuntimeException(ex);
}
return result;
}
示例6: visitAssignmentStatement
import org.apache.commons.lang3.ClassUtils; //导入方法依赖的package包/类
/** {@inheritDoc} */
@Override
public void visitAssignmentStatement(AssignmentStatement statement) {
String cast = "";
VariableReference retval = statement.getReturnValue();
VariableReference parameter = statement.getValue();
if (!retval.getVariableClass().equals(parameter.getVariableClass())) {
if (retval.isWrapperType() && parameter.isPrimitive()) {
cast = "(" + getTypeName(retval.getType()) + ") ";
if(!ClassUtils.primitiveToWrapper(parameter.getVariableClass()).equals(retval.getVariableClass())) {
cast += "(" + ClassUtils.wrapperToPrimitive(retval.getVariableClass()) + ")";
}
} else if (retval.isPrimitive()
&& parameter.isWrapperType()) {
cast = "(" + getTypeName(retval.getType()) + ") ";
if(!ClassUtils.primitiveToWrapper(retval.getVariableClass()).equals(parameter.getVariableClass())) {
cast += "(" + ClassUtils.wrapperToPrimitive(parameter.getVariableClass()) + ")";
}
} else if (retval.isWrapperType()
&& parameter.isWrapperType()) {
cast = "(" + getTypeName(retval.getType()) + ") ";
// Unbox first to make cast work
if(!ClassUtils.primitiveToWrapper(parameter.getVariableClass()).equals(retval.getVariableClass())) {
cast += "(" + ClassUtils.wrapperToPrimitive(retval.getVariableClass()) + ")";
}
} else {
cast = "(" + getClassName(retval) + ") ";
}
}
testCode += getVariableName(retval) + " = " + cast + getVariableName(parameter)
+ ";" + NEWLINE;
addAssertions(statement);
}
示例7: assignArray
import org.apache.commons.lang3.ClassUtils; //导入方法依赖的package包/类
/**
* Assign a value to an array index
*
* @param test
* @param array
* @param arrayIndex
* @param position
* @throws ConstructionFailedException
*/
public void assignArray(TestCase test, VariableReference array, int arrayIndex,
int position) throws ConstructionFailedException {
List<VariableReference> objects = test.getObjects(array.getComponentType(),
position);
Iterator<VariableReference> iterator = objects.iterator();
GenericClass componentClass = new GenericClass(array.getComponentType());
// Remove assignments from the same array
while (iterator.hasNext()) {
VariableReference var = iterator.next();
if (var instanceof ArrayIndex) {
if (((ArrayIndex) var).getArray().equals(array))
iterator.remove();
// Do not assign values of same type as array to elements
// This may e.g. happen if we have Object[], we could otherwise assign Object[] as values
else if (((ArrayIndex) var).getArray().getType().equals(array.getType()))
iterator.remove();
}
if (componentClass.isWrapperType()) {
Class<?> rawClass = ClassUtils.wrapperToPrimitive(componentClass.getRawClass());
if (!var.getVariableClass().equals(rawClass)
&& !var.getVariableClass().equals(componentClass.getRawClass())) {
iterator.remove();
}
}
}
logger.debug("Reusable objects: " + objects);
assignArray(test, array, arrayIndex, position, objects);
}
示例8: propertyType
import org.apache.commons.lang3.ClassUtils; //导入方法依赖的package包/类
private String propertyType( String property, Map<String, Boolean> optional, Map<String, Class<?>> types ) {
final Boolean opt = optional.get( property );
Class<?> clazz = types.get( property );
if( clazz.equals( ArrayList.class ) ) clazz = List.class;
if( opt ) return "Optional<" + clazz.getSimpleName() + ">";
else {
final Class<?> aClass = ClassUtils.wrapperToPrimitive( clazz );
if( aClass == null ) return clazz.getSimpleName();
return aClass.getSimpleName();
}
}
示例9: isPrimitive
import org.apache.commons.lang3.ClassUtils; //导入方法依赖的package包/类
public static boolean isPrimitive(Class clazz) {
boolean isPrimitiveOrWrapped =
clazz.isPrimitive() || ClassUtils.wrapperToPrimitive(clazz) != null;
return isPrimitiveOrWrapped;
}