當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。