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


Java Primitives.wrap方法代码示例

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


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

示例1: getValueOfMethodFrom

import com.google.common.primitives.Primitives; //导入方法依赖的package包/类
public static Method getValueOfMethodFrom(Class returnClass) {
    val existsMethod = valueOfMethodCache.get(returnClass);
    if (existsMethod != null) return existsMethod.orNull();

    val clazz = Primitives.wrap(returnClass);
    try {
        val valueOfMethod = clazz.getMethod("valueOf", String.class);
        if (isPublicStatic(clazz, valueOfMethod)) {
            valueOfMethodCache.put(returnClass, Optional.of(valueOfMethod));
            return valueOfMethod;
        }
    } catch (Exception e) {
        valueOfMethodCache.put(returnClass, Optional.<Method>absent());
    }

    return null;
}
 
开发者ID:bingoohuang,项目名称:excel2javabeans,代码行数:18,代码来源:ValueOfs.java

示例2: reAssignContainers

import com.google.common.primitives.Primitives; //导入方法依赖的package包/类
static String reAssignContainers(Class<?>[] paramTypes) {
	StringBuilder stringBuilder = new StringBuilder();
	int i = 0;
	for (Class<?> c : paramTypes) {
		stringBuilder.append("param").append(i).append(" = (");
		if (c.isPrimitive()) {
			Class<?> wrapped = Primitives.wrap(c);
			stringBuilder
					.append("(").append(wrapped.getCanonicalName()).append(") $mArgs[").append(i).append("]).")
					.append(c.getCanonicalName()).append("Value();\n");// <-- This feels so cheaty
		} else {
			stringBuilder.append(c.getCanonicalName()).append(") $mArgs[").append(i).append("];\n");
		}
		i++;
	}
	return stringBuilder.toString();
}
 
开发者ID:InventivetalentDev,项目名称:CompactNPCLib,代码行数:18,代码来源:ClassGenerator.java

示例3: itemFromString

import com.google.common.primitives.Primitives; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
protected static <X> X itemFromString(String value, Class<X> clazz, Flag flag)
    throws FlagException {
  // In case we get a primitive type (e.g. from Scala), get the boxed version to know
  // how to serialize.
  clazz = Primitives.wrap(clazz);
  if (Number.class.isAssignableFrom(clazz)) {
    return clazz.cast(PrimitiveFlagField.NumberFlagField.fromString(value, clazz, flag));
  } else if (Boolean.class.isAssignableFrom(clazz)) {
    return clazz.cast(Boolean.valueOf(value));
  } else if (String.class.isAssignableFrom(clazz)) {
    return clazz.cast(value);
  } else if (clazz.isEnum()) {
    return (X) PrimitiveFlagField.EnumFlagField.fromString(value, (Class<Enum>) clazz, flag);
  }
  throw new FlagException.UnsupportedType(flag, clazz);
}
 
开发者ID:mwitkow,项目名称:java-flagz,代码行数:18,代码来源:ContainerFlagField.java

示例4: get

import com.google.common.primitives.Primitives; //导入方法依赖的package包/类
/**
 * Retrieves the {@link ColumnType} for specified {@link EntityColumn}.
 *
 * <p>By default, this method returns the {@link ColumnType} for the
 * {@linkplain EntityColumn column's} {@linkplain EntityColumn#getType() type}.
 *
 * <p>If the {@link ColumnType} was not found by the {@code class} of the {@link EntityColumn},
 * its superclasses are checked one by one until a {@link ColumnType} is found or until
 * the look up reaches the class representing {@link Object}.
 *
 * <p>If no {@link ColumnType} is found, an {@link IllegalStateException} is thrown.
 *
 * @param field the {@link EntityColumn} to get type conversion strategy for
 * @return the {@link ColumnType} for the given {@link EntityColumn}
 */
public C get(EntityColumn field) {
    checkNotNull(field);

    Class javaType = field.getType();
    javaType = Primitives.wrap(javaType);
    C type = null;

    while (type == null && javaType != null) {
        type = columnTypeMap.get(javaType);
        javaType = javaType.getSuperclass();
    }

    checkState(type != null,
               "Could not find storage type for %s.",
               field.getType());
    return type;
}
 
开发者ID:SpineEventEngine,项目名称:core-java,代码行数:33,代码来源:ColumnTypeRegistry.java

示例5: convertInputString

import com.google.common.primitives.Primitives; //导入方法依赖的package包/类
private Object convertInputString(final String s, final Class<?> type) {
    if (type == String.class) {
        return s;
    } else if (type.isPrimitive() || Primitives.isWrapperType(type)) {
        final Class<?> wrapperClass = Primitives.wrap(type);
        try {
            final Method valueOf = wrapperClass.getMethod("valueOf", String.class);
            return valueOf.invoke(wrapperClass, s);
        } catch (Exception e) {
            final String message = "Failed to convert String "
                    + s + " into type " + wrapperClass
                    + ".\nCaused by: " + e;
            throw new AssertionError(message);
        }
    } else {
        final ExpressionFactory expressionFactory = expressionFactoryResolver.apply(s);
        if (expressionFactory != null) {
            final Expression expression = expressionFactory.compile(s);
            return expression.evaluate().get();
        } else {
            throw new UnsupportedOperationException("No rule implemented to convert type String to type " + type);
        }
    }
}
 
开发者ID:asoem,项目名称:greyfish,代码行数:25,代码来源:ModelParameterTypeListener.java

示例6: isAssignmentCompatible

import com.google.common.primitives.Primitives; //导入方法依赖的package包/类
static boolean isAssignmentCompatible(Class<?> a, Class<?> b) {
	if (a == b)
		return true;

	// Wrap primitive type
	a = Primitives.wrap(a);

	// Check primitive type assignment compatibility
	if (b.isPrimitive()) {
		b = Primitives.wrap(b);

		float distance = calculateDistancePrimitive(a, b);
		return distance >= 0;

	} else {
		return b.isInstance(b);
	}
}
 
开发者ID:NOVA-Team,项目名称:NOVA-Core,代码行数:19,代码来源:ReflectionUtil.java

示例7: findMsaSupportType

import com.google.common.primitives.Primitives; //导入方法依赖的package包/类
public static Class<? extends MsaValidator> findMsaSupportType(
        AsmConstraint asmConstraint, Class<?> type
) {
    Class<?> wrap = Primitives.wrap(type);
    for (val msa : asmConstraint.validateBy()) {
        val arg = findSuperActualTypeArg(msa, MsaValidator.class, 1);
        if (arg == null) {
            continue;
        }
        if (arg.isAssignableFrom(wrap)) {
            return msa;
        }
    }

    return null;
}
 
开发者ID:bingoohuang,项目名称:asmvalidator,代码行数:17,代码来源:MethodGeneratorUtils.java

示例8: addChild

import com.google.common.primitives.Primitives; //导入方法依赖的package包/类
@Override
public void addChild(TupleFilter child) {
    if (child instanceof ColumnTupleFilter || child instanceof BuiltInFunctionTupleFilter) {
        columnContainerFilter = child;
        colPosition = methodParams.size();
        methodParams.add(null);
    } else if (child instanceof ConstantTupleFilter) {
        this.constantTupleFilter = (ConstantTupleFilter) child;
        Serializable constVal = (Serializable) child.getValues().iterator().next();
        try {
            constantPosition = methodParams.size();
            Class<?> clazz = Primitives.wrap(method.getParameterTypes()[methodParams.size()]);
            if (!Primitives.isWrapperType(clazz))
                methodParams.add(constVal);
            else
                methodParams.add((Serializable) clazz
                        .cast(clazz.getDeclaredMethod("valueOf", String.class).invoke(null, constVal)));
        } catch (Exception e) {
            logger.warn("Reflection failed for methodParams. ", e);
            isValidFunc = false;
        }
    }
    super.addChild(child);
}
 
开发者ID:apache,项目名称:kylin,代码行数:25,代码来源:BuiltInFunctionTupleFilter.java

示例9: getParameterType

import com.google.common.primitives.Primitives; //导入方法依赖的package包/类
protected static ParameterType getParameterType(Class<?> javaClass) {
    javaClass = Primitives.wrap(javaClass);

    if (javaClass.equals(Byte.class)) {
        return ParameterType.BYTE;
    } else if (javaClass.equals(Short.class)) {
        return ParameterType.SHORT;
    } else if (javaClass.equals(Integer.class)) {
        return ParameterType.INT;
    } else if (javaClass.equals(Long.class)) {
        return ParameterType.LONG;
    } else if (javaClass.equals(Float.class)) {
        return ParameterType.FLOAT;
    } else if (javaClass.equals(Double.class)) {
        return ParameterType.DOUBLE;
    } else if (javaClass.equals(Boolean.class)) {
        return ParameterType.BOOLEAN;
    } else if (javaClass.equals(Character.class)) {
        return ParameterType.CHAR;
    } else {
        // string or null
        return ParameterType.EXPRESSION;
    }
}
 
开发者ID:SETTE-Testing,项目名称:sette-tool,代码行数:25,代码来源:RunResultParser.java

示例10: getDefaultParameterValue

import com.google.common.primitives.Primitives; //导入方法依赖的package包/类
public static Object getDefaultParameterValue(Class<?> javaClass) {
    javaClass = Primitives.wrap(javaClass);

    if (javaClass.equals(Byte.class)) {
        return (byte) 1;
    } else if (javaClass.equals(Short.class)) {
        return (short) 1;
    } else if (javaClass.equals(Integer.class)) {
        return (int) 1;
    } else if (javaClass.equals(Long.class)) {
        return 1L;
    } else if (javaClass.equals(Float.class)) {
        return 1.0f;
    } else if (javaClass.equals(Double.class)) {
        return 1.0;
    } else if (javaClass.equals(Boolean.class)) {
        return false;
    } else if (javaClass.equals(Character.class)) {
        return ' ';
    } else {
        // string or null
        return null;
    }
}
 
开发者ID:SETTE-Testing,项目名称:sette-tool,代码行数:25,代码来源:RunResultParser.java

示例11: getDefaultParameterValueString

import com.google.common.primitives.Primitives; //导入方法依赖的package包/类
public static String getDefaultParameterValueString(Class<?> javaClass) {
    javaClass = Primitives.wrap(javaClass);

    if (javaClass.equals(Byte.class)) {
        return "1";
    } else if (javaClass.equals(Short.class)) {
        return "1";
    } else if (javaClass.equals(Integer.class)) {
        return "1";
    } else if (javaClass.equals(Long.class)) {
        return "1";
    } else if (javaClass.equals(Float.class)) {
        return "1.0";
    } else if (javaClass.equals(Double.class)) {
        return "1.0";
    } else if (javaClass.equals(Boolean.class)) {
        return "false";
    } else if (javaClass.equals(Character.class)) {
        return " ";
    } else {
        // string or null
        return "null";
    }
}
 
开发者ID:SETTE-Testing,项目名称:sette-tool,代码行数:25,代码来源:RunResultParser.java

示例12: getParameterLiteral

import com.google.common.primitives.Primitives; //导入方法依赖的package包/类
static String getParameterLiteral(Class<?> javaClass) {
    javaClass = Primitives.wrap(javaClass);

    if (javaClass.equals(Byte.class)) {
        return "(byte) 1";
    } else if (javaClass.equals(Short.class)) {
        return "(short) 1";
    } else if (javaClass.equals(Integer.class)) {
        return "1";
    } else if (javaClass.equals(Long.class)) {
        return "1L";
    } else if (javaClass.equals(Float.class)) {
        return "1.0f";
    } else if (javaClass.equals(Double.class)) {
        return "1.0";
    } else if (javaClass.equals(Boolean.class)) {
        return "false";
    } else if (javaClass.equals(Character.class)) {
        return "' '";
    } else {
        return "null";
    }
}
 
开发者ID:SETTE-Testing,项目名称:sette-tool,代码行数:24,代码来源:SpfGenerator.java

示例13: createCatgRead

import com.google.common.primitives.Primitives; //导入方法依赖的package包/类
private static String createCatgRead(Class<?> javaClass) {
    javaClass = Primitives.wrap(javaClass);

    if (javaClass.equals(Byte.class)) {
        return "catg.CATG.readByte((byte) 1)";
    } else if (javaClass.equals(Short.class)) {
        return "catg.CATG.readShort((short) 1)";
    } else if (javaClass.equals(Integer.class)) {
        return "catg.CATG.readInt(1)";
    } else if (javaClass.equals(Long.class)) {
        return "catg.CATG.readLong(1L)";
    } else if (javaClass.equals(Boolean.class)) {
        return "catg.CATG.readBool(false)";
    } else if (javaClass.equals(Character.class)) {
        return "catg.CATG.readChar(' ')";
    } else if (javaClass.equals(String.class)) {
        return "catg.CATG.readString(\"\")";
    } else {
        return null;
    }
}
 
开发者ID:SETTE-Testing,项目名称:sette-tool,代码行数:22,代码来源:CatgGenerator.java

示例14: assertCasts

import com.google.common.primitives.Primitives; //导入方法依赖的package包/类
public void assertCasts(Field toField, Field fromField) {
	Class<?> toFieldClass = Primitives.wrap(toField.getType());
	Class<?> fromFieldClass = Primitives.wrap(fromField.getType());
	
	if( !toFieldClass.isAssignableFrom(fromFieldClass)) {
		if( !fromFieldClass.isAssignableFrom(toFieldClass)) {
		
			throw new RuntimeException(String.format(
				"The @In-field %s (%s) in %s is not of the same type as in the parent scope (%s, %s)!",
				toField.getName(), toFieldClass.getName(), 
				toField.getDeclaringClass().getName(), 
				fromField.getDeclaringClass().getName(),
				fromFieldClass.getName()));
		} else {
			warn(String.format(
				"The @In-field %s (%s) in %s cannot be guaranteed to be of the same type as in the parent scope (%s, %s)."
				+"\nAn unchecked typecast from %s to %s will be performed at run time!",
				toField.getName(), toFieldClass.getName(), 
				toField.getDeclaringClass().getName(), 
				fromField.getDeclaringClass().getName(),
				fromFieldClass.getName(),
				fromFieldClass.getSimpleName(),
				toFieldClass.getSimpleName()));
		}
	}
}
 
开发者ID:cupmanager,项目名称:jangular,代码行数:27,代码来源:CompilerSession.java

示例15: convert

import com.google.common.primitives.Primitives; //导入方法依赖的package包/类
/**
 * @param result     orient record
 * @param targetType target conversion type
 * @param converter  converter object
 * @param <T>        target conversion type
 * @return converted object
 * @throws ResultConversionException if conversion is impossible
 */
@SuppressWarnings("unchecked")
public <T> T convert(final Object result, final Class<T> targetType, final ResultConverter converter) {
    // wrap primitive, because result will always be object
    final Class<T> target = Primitives.wrap(targetType);
    // do manual conversion to other types if required (usually this will be done automatically by connection
    // object, but async and live callbacks will always return documents)
    T res = tryConversion(result, target);
    if (res != null) {
        return res;
    }

    // use converter
    final ResultDescriptor desc = new ResultDescriptor();
    // support void case for more universal usage
    desc.returnType = target.equals(Void.class) ? ResultType.VOID : ResultType.PLAIN;
    desc.entityType = target;
    desc.expectType = target;
    desc.entityDbType = ORecord.class.isAssignableFrom(target) ? DbType.DOCUMENT : DbType.UNKNOWN;
    res = (T) converter.convert(desc, result);
    ResultUtils.check(res, target);
    return res;
}
 
开发者ID:xvik,项目名称:guice-persist-orient,代码行数:31,代码来源:RecordConverter.java


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