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


Java Primitives.unwrap方法代码示例

本文整理汇总了Java中com.google.common.primitives.Primitives.unwrap方法的典型用法代码示例。如果您正苦于以下问题:Java Primitives.unwrap方法的具体用法?Java Primitives.unwrap怎么用?Java Primitives.unwrap使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.google.common.primitives.Primitives的用法示例。


在下文中一共展示了Primitives.unwrap方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: findMethod

import com.google.common.primitives.Primitives; //导入方法依赖的package包/类
public static final Method findMethod(Class<?> clazz, InvocationParametersBean invocation) throws NoSuchMethodException {
    Method ret = null;
    Class<?>[] types = getParameterTypes(invocation);
    try {
        ret = clazz.getMethod(invocation.getMethodName(), types);
    } catch (NoSuchMethodException e) {
    }
    if (ret == null && types != null) {
        int max = types.length;
        for (int i = 0; i < max; i++) {
            if (Primitives.isWrapperType(types[i])) {
                types[i] = Primitives.unwrap(types[i]);
            }
        }
        ret = clazz.getMethod(invocation.getMethodName(), types);
    }
    return ret;
}
 
开发者ID:eduyayo,项目名称:gamesboard,代码行数:19,代码来源:ClassUtils.java

示例2: doUnwrap

import com.google.common.primitives.Primitives; //导入方法依赖的package包/类
private static <T> Object doUnwrap(Exchanging<T> exch, T... target) {
	if (null == target) {
		return null;
	}
	
	Class<?> clazz = Primitives.unwrap(target.getClass().getComponentType());
	Object r = Array.newInstance(clazz, target.length);
	if (0 == target.length) {
		return r;
	}
	
	T el = null;
	Object defaultVal = Defaults.defaultValue(clazz);
	for (int i = 0; i < target.length; i++) {
		Array.set(r, i, (null == (el = target[i])) ? defaultVal : exch.unwraps(el));
	}
	
	return r;
}
 
开发者ID:jronrun,项目名称:benayn,代码行数:20,代码来源:Arrays2.java

示例3: validateProcedure

import com.google.common.primitives.Primitives; //导入方法依赖的package包/类
private static void validateProcedure(Procedure procedure)
{
    List<Class<?>> parameters = procedure.getMethodHandle().type().parameterList().stream()
            .filter(type -> !ConnectorSession.class.isAssignableFrom(type))
            .collect(toList());
    for (int i = 0; i < procedure.getArguments().size(); i++) {
        Argument argument = procedure.getArguments().get(i);
        Class<?> argumentType = Primitives.unwrap(parameters.get(i));
        Class<?> expectedType = getObjectType(argument.getType());
        checkArgument(expectedType.equals(argumentType),
                "Argument '%s' has invalid type %s (expected %s)",
                argument.getName(),
                argumentType.getName(),
                expectedType.getName());
    }
}
 
开发者ID:y-lan,项目名称:presto,代码行数:17,代码来源:ProcedureRegistry.java

示例4: typeForMagicLiteral

import com.google.common.primitives.Primitives; //导入方法依赖的package包/类
public static Type typeForMagicLiteral(Type type)
{
    Class<?> clazz = type.getJavaType();
    clazz = Primitives.unwrap(clazz);

    if (clazz == long.class) {
        return BIGINT;
    }
    if (clazz == double.class) {
        return DOUBLE;
    }
    if (!clazz.isPrimitive()) {
        if (type.equals(VARCHAR)) {
            return VARCHAR;
        }
        else {
            return VARBINARY;
        }
    }
    if (clazz == boolean.class) {
        return BOOLEAN;
    }
    throw new IllegalArgumentException("Unhandled Java type: " + clazz.getName());
}
 
开发者ID:y-lan,项目名称:presto,代码行数:25,代码来源:FunctionRegistry.java

示例5: checkParameterTypes

import com.google.common.primitives.Primitives; //导入方法依赖的package包/类
private static boolean checkParameterTypes(Type[] parameterTypes, Object[] args) {
    for (int i = 0; i < args.length; i++) {
        Object object = args[i];
        Type parameterType = parameterTypes[i];
        if (object != null) {
            Class<?> objectType = object.getClass();
            Class<?> unWrapPrimitive = null;
            if (Primitives.isWrapperType(objectType)) {
                unWrapPrimitive = Primitives.unwrap(objectType);
            }
            if (!(((Class<?>) parameterType).isAssignableFrom(
                    objectType) || (unWrapPrimitive != null && ((Class<?>) parameterType).isAssignableFrom(
                    unWrapPrimitive)))) {
                return false;
            }
        }
    }
    return true;
}
 
开发者ID:seedstack,项目名称:business,代码行数:20,代码来源:MethodMatcher.java

示例6: serialize

import com.google.common.primitives.Primitives; //导入方法依赖的package包/类
@Override
public Object serialize(Object java, Annotation[] annotations) {
    Time annotation = null;
    for (Annotation declaredAnnotation : annotations) {
        if (declaredAnnotation instanceof Time) {
            annotation = (Time) declaredAnnotation;
            break;
        }
    }
    if (annotation == null) throw new RuntimeException("Unable to serialize types not annotated with @Time");
    Class seraizlieTo = java.getClass();
    seraizlieTo = Primitives.unwrap(seraizlieTo);
    long millis = seraizlieTo == int.class ? (Integer) java : (Long) java;
    TimeUnit defaultUnit = annotation.value();
    return toString(millis, defaultUnit);
}
 
开发者ID:TechzoneMC,项目名称:TechUtils,代码行数:17,代码来源:TimeSerializer.java

示例7: StackObject

import com.google.common.primitives.Primitives; //导入方法依赖的package包/类
public StackObject(Class<?> type, Frame value, String desc) {
    if (Primitives.unwrap(type) != type) {
        throw new IllegalArgumentException();
    }
    this.type = type;
    this.value = value;
    this.initType = desc;
    if (type == Object.class && desc == null) {
        throw new IllegalArgumentException();
    }
}
 
开发者ID:java-deobfuscator,项目名称:deobfuscator,代码行数:12,代码来源:MethodAnalyzer.java

示例8: as

import com.google.common.primitives.Primitives; //导入方法依赖的package包/类
public <T> T as(Class<T> clazz) {
    if (Primitives.unwrap(clazz) != clazz) {
        throw new ExecutionException("Cannot call as(Class<T> clazz) with a primitive class");
    }
    if (value() instanceof Character && clazz == char.class) {
        return (T) value();
    }
    if (value() instanceof Integer && clazz == boolean.class) {
        return (T) Boolean.valueOf(intValue() != 0 ? true : false);
    }
    if (value() instanceof Byte && clazz == char.class) {
        return (T) Character.valueOf((char) ((JavaByte) this).byteValue());
    }
    return clazz.cast(value());
}
 
开发者ID:java-deobfuscator,项目名称:deobfuscator,代码行数:16,代码来源:JavaValue.java

示例9: diffBranchObject

import com.google.common.primitives.Primitives; //导入方法依赖的package包/类
private Object diffBranchObject(Tree tree, Object o1, Object o2) throws Exception {
	Class<?> type = Primitives.unwrap(o1.getClass());
	if (isBasicType(type)) {
		if (!o1.equals(o2)) {
			saveDiff(tree, o1, o2);
		}
	} else if (shouldVisit(tree, o1)) {
		for (Field field : getAllField(o1.getClass())) {
			diffField(tree, field, o1, o2);
		}
	}
	return o1;
}
 
开发者ID:BenoitRonflette,项目名称:FreeYourCode,代码行数:14,代码来源:DeepDiff.java

示例10: revertDiffBranchObject

import com.google.common.primitives.Primitives; //导入方法依赖的package包/类
private void revertDiffBranchObject(Tree tree, Object o) throws Exception {
	Class<?> type = Primitives.unwrap(o.getClass());
	if (!isBasicType(type) && shouldVisit(o)) {
		for (Field field : getAllField(o.getClass())) {
			revertDiffField(tree, field, o);
		}
	}
}
 
开发者ID:BenoitRonflette,项目名称:FreeYourCode,代码行数:9,代码来源:DeepDiffReverter.java

示例11: resolveInBranchObject

import com.google.common.primitives.Primitives; //导入方法依赖的package包/类
private Object resolveInBranchObject(Tree tree, String path, Object o) throws Exception {
	Class<?> type = Primitives.unwrap(o.getClass());
	if (!isBasicType(type) && shouldVisit(o)) {
		for (Field field : getAllField(o.getClass())) {
			Object response = resolveInField(tree, path, field, o);
			if (response != null) {
				return response;
			}
		}
	}
	return null;
}
 
开发者ID:BenoitRonflette,项目名称:FreeYourCode,代码行数:13,代码来源:DeepResolver.java

示例12: findInBranchObject

import com.google.common.primitives.Primitives; //导入方法依赖的package包/类
private String findInBranchObject(Tree tree, Object searchedObject, Object o) throws Exception {
	Class<?> type = Primitives.unwrap(o.getClass());
	if (!isBasicType(type) && shouldVisit(o)) {
		for (Field field : getAllField(o.getClass())) {
			String response = findInField(tree, searchedObject, field, o);
			if (response != null) {
				return response;
			}
		}
	}
	return null;
}
 
开发者ID:BenoitRonflette,项目名称:FreeYourCode,代码行数:13,代码来源:DeepFinder.java

示例13: getDefaultPrimitiveValue

import com.google.common.primitives.Primitives; //导入方法依赖的package包/类
/**
 *
 * @param type
 * @return the default primitive value as a String.  Returns null if unable to determine default value
   */
private String getDefaultPrimitiveValue(TypeName type) {
  String valueString = null;
  try {
    Class<?> primitiveClass = Primitives.unwrap(Class.forName(type.box().toString()));
    if (primitiveClass != null) {
      Object defaultValue = Defaults.defaultValue(primitiveClass);
      if (defaultValue != null) {
        valueString = defaultValue.toString();
        if (!Strings.isNullOrEmpty(valueString)) {
          switch (type.toString()) {
            case "double":
              valueString = valueString + "d";
              break;
            case "float":
              valueString = valueString + "f";
              break;
            case "long":
              valueString = valueString + "L";
              break;
            case "char":
              valueString = "'" + valueString + "'";
              break;
          }
        }
      }
    }
  } catch (ClassNotFoundException ignored) {
    //Swallow and return null
  }

  return valueString;
}
 
开发者ID:rharter,项目名称:auto-value-gson,代码行数:38,代码来源:AutoValueGsonExtension.java

示例14: unboxPrimitiveIfNecessary

import com.google.common.primitives.Primitives; //导入方法依赖的package包/类
public static BytecodeBlock unboxPrimitiveIfNecessary(Scope scope, Class<?> boxedType)
{
    BytecodeBlock block = new BytecodeBlock();
    LabelNode end = new LabelNode("end");
    Class<?> unboxedType = Primitives.unwrap(boxedType);
    Variable wasNull = scope.getVariable("wasNull");

    if (unboxedType == void.class) {
        block.pop(boxedType)
                .append(wasNull.set(constantTrue()));
    }
    else if (unboxedType.isPrimitive()) {
        LabelNode notNull = new LabelNode("notNull");
        block.dup(boxedType)
                .ifNotNullGoto(notNull)
                .append(wasNull.set(constantTrue()))
                .comment("swap boxed null with unboxed default")
                .pop(boxedType)
                .pushJavaDefault(unboxedType)
                .gotoLabel(end)
                .visitLabel(notNull)
                .append(unboxPrimitive(unboxedType));
    }
    else {
        block.dup(boxedType)
                .ifNotNullGoto(end)
                .append(wasNull.set(constantTrue()));
    }
    block.visitLabel(end);

    return block;
}
 
开发者ID:y-lan,项目名称:presto,代码行数:33,代码来源:BytecodeUtils.java

示例15: objectsToClassArray

import com.google.common.primitives.Primitives; //导入方法依赖的package包/类
public static Class<?>[] objectsToClassArray(Object[] objects) {
    Class<?>[] classes = new Class[objects.length];
    for (int i = 0; i < objects.length; i++) {
        Class<?> clazz = objects[i].getClass();
        // due to how java works, we have to convert to primitives. Guava makes this easy
        if (Primitives.isWrapperType(clazz)) {
            clazz = Primitives.unwrap(clazz);
        }
        classes[i] = clazz;
    }
    return classes;
}
 
开发者ID:BurnGames,项目名称:BGDCore,代码行数:13,代码来源:Reflection.java


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