当前位置: 首页>>代码示例>>Java>>正文


Java ClassUtils.wrapperToPrimitive方法代码示例

本文整理汇总了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;
}
 
开发者ID:rogerxaic,项目名称:gestock,代码行数:27,代码来源:MemberUtils.java

示例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;
}
 
开发者ID:Sukelluskello,项目名称:VectorAttackScanner,代码行数:26,代码来源:MemberUtils.java

示例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);
}
 
开发者ID:Javalbert,项目名称:faster-than-reflection,代码行数:15,代码来源:ClassAccessFactory.java

示例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;
}
 
开发者ID:apache,项目名称:apex-core,代码行数:37,代码来源:AppDataPushAgent.java

示例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);
}
 
开发者ID:EvoSuite,项目名称:evosuite,代码行数:37,代码来源:TestCodeVisitor.java

示例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);
}
 
开发者ID:EvoSuite,项目名称:evosuite,代码行数:39,代码来源:TestFactory.java

示例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();
   }
}
 
开发者ID:oaplatform,项目名称:oap,代码行数:13,代码来源:DictionaryMojo.java

示例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;
}
 
开发者ID:drinkwater-io,项目名称:drinkwater-java,代码行数:7,代码来源:ReflectHelper.java


注:本文中的org.apache.commons.lang3.ClassUtils.wrapperToPrimitive方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。