本文整理汇总了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;
}
示例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;
}
示例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());
}
}
示例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());
}
示例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;
}
示例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);
}
示例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();
}
}
示例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());
}
示例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;
}
示例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);
}
}
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}