本文整理汇总了Java中com.google.common.primitives.Primitives.isWrapperType方法的典型用法代码示例。如果您正苦于以下问题:Java Primitives.isWrapperType方法的具体用法?Java Primitives.isWrapperType怎么用?Java Primitives.isWrapperType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.common.primitives.Primitives
的用法示例。
在下文中一共展示了Primitives.isWrapperType方法的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: 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);
}
}
}
示例3: 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);
}
示例4: unwrap
import com.google.common.primitives.Primitives; //导入方法依赖的package包/类
@Override
public Object unwrap(Object bukkitHandle) {
if (bukkitHandle == null)
return null;
Class<?> type = bukkitHandle instanceof Class ? (Class<?>) bukkitHandle : bukkitHandle.getClass();
try {
if (Primitives.isWrapperType(type) || type.isPrimitive()) {
return type;
}
return unwrap(type, bukkitHandle);
} catch (Exception e) {
throw new RuntimeException("Failed to create/find a converter for: " + type.getCanonicalName(), e);
}
}
示例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: fromJson
import com.google.common.primitives.Primitives; //导入方法依赖的package包/类
/**
* Returns the {@code node} deserialized to an instance of <T> with the implementation of <T>
* being selected from the registered targets for the node's root key.
*
* @throws IllegalArgumentException if {@code node} does not contain a single root key
* @throws IllegalStateException if no target type has been registered for the {@code node}'s root
* key
* @throws RuntimeException if deserialization fails
*/
public static <T> T fromJson(JsonNode node) {
Preconditions.checkArgument(node.size() == 1, "The node must contain a single root key: %s",
node);
String rootKey = node.fieldNames().next();
@SuppressWarnings("unchecked")
Class<T> targetType = (Class<T>) targetTypes.get(rootKey);
if (targetType == null)
throw new IllegalStateException("No target type is registered for the root key " + rootKey);
if (targetType.isPrimitive() || Primitives.isWrapperType(targetType)) {
try {
return rootMapper.reader(targetType).readValue(node);
} catch (IOException e) {
throw Exceptions.uncheck(e, "Failed to deserialize json: {}", node);
}
} else {
T object = Injector.getInstance(targetType);
injectMembers(object, node);
return object;
}
}
示例7: parse
import com.google.common.primitives.Primitives; //导入方法依赖的package包/类
@Override
public Object parse(final TypeLiteral<?> type, final Context ctx) throws Throwable {
Class<?> beanType = type.getRawType();
if (Primitives.isWrapperType(Primitives.wrap(beanType))
|| CharSequence.class.isAssignableFrom(beanType)) {
return ctx.next();
}
return ctx.ifparams(map -> {
final Object bean;
if (List.class.isAssignableFrom(beanType)) {
bean = newBean(ctx.require(Request.class), ctx.require(Response.class),
ctx.require(Route.Chain.class), map, type);
} else if (beanType.isInterface()) {
bean = newBeanInterface(ctx.require(Request.class), ctx.require(Response.class),
ctx.require(Route.Chain.class), beanType);
} else {
bean = newBean(ctx.require(Request.class), ctx.require(Response.class),
ctx.require(Route.Chain.class), map, type);
}
return bean;
});
}
示例8: processPropertyType
import com.google.common.primitives.Primitives; //导入方法依赖的package包/类
/**
* Finds the appropriate constructor for the specified type that we will use to construct
* instances.
*/
private static void processPropertyType(final Class<?> propertyType)
throws NoSuchMethodException, SecurityException, IntrospectionException {
final Class<?> wrappedType = Primitives.wrap(propertyType);
if (CONSTRUCTORS.containsKey(wrappedType)) {
return;
}
// If the type is a primitive (or String type), we look for the constructor that takes a
// single String argument, which, for primitives, validates and converts from a String
// representation which is the form we get on ingress.
if (propertyType.isPrimitive() || Primitives.isWrapperType(propertyType) || propertyType.equals(String.class)) {
CONSTRUCTORS.put(wrappedType, propertyType.getConstructor(String.class));
} else {
// This must be a yang-defined type. We need to find the constructor that takes a
// primitive as the only argument. This will be used to construct instances to perform
// validation (eg range checking). The yang-generated types have a couple single-argument
// constructors but the one we want has the bean ConstructorProperties annotation.
for (final Constructor<?> ctor: propertyType.getConstructors()) {
final ConstructorProperties ctorPropsAnnotation = ctor.getAnnotation(ConstructorProperties.class);
if (ctor.getParameterTypes().length == 1 && ctorPropsAnnotation != null) {
findYangTypeGetter(propertyType, ctorPropsAnnotation.value()[0]);
CONSTRUCTORS.put(propertyType, ctor);
break;
}
}
}
}
示例9: getValue
import com.google.common.primitives.Primitives; //导入方法依赖的package包/类
/**
* Return the object o set by setValue(o) encoded as a JSON string. Return null if o is null
* or if o is neither a JsonObject nor a String nor a primitive type.
* @return the JSON string
*/
public String getValue() {
if (value == null) {
return null;
}
if (value instanceof JsonObject) {
return ((JsonObject) value).encode();
}
if (value instanceof String || value.getClass().isPrimitive() || Primitives.isWrapperType(value.getClass())) {
return Json.encode(value);
}
return null;
}
示例10: formatSetContents
import com.google.common.primitives.Primitives; //导入方法依赖的package包/类
/**
* Returns a formatted listing of Set contents, using a single line format if all elements are
* wrappers of primitive types or Strings, and a multiline (one object per line) format if they
* are not.
*/
private static String formatSetContents(Set<?> set) {
for (Object obj : set) {
if (!Primitives.isWrapperType(obj.getClass()) && !(obj instanceof String)) {
return "\n " + Joiner.on(",\n ").join(set);
}
}
return " " + set;
}
示例11: convert
import com.google.common.primitives.Primitives; //导入方法依赖的package包/类
/**
* Helper to convert value to string unless its a char-sequence or primitive/boxed-type.
*
* This is to help keep rendering JSON simple, and avoid side-effect with getter invocations when rendering.
*/
private Object convert(final Object value) {
if (value == null) {
return null;
}
if (value instanceof CharSequence) {
return value.toString();
}
if (value.getClass().isPrimitive() || Primitives.isWrapperType(value.getClass())) {
return value;
}
return String.valueOf(value);
}
示例12: bind
import com.google.common.primitives.Primitives; //导入方法依赖的package包/类
private void bind(Class<?> cls, Object value) {
if (value == null)
throw new SaltaException("Binding to null instances is not allowed. Use toProvider(Providers.of(null))");
config.creationPipeline.staticBindings.add(createBinding(cls, value));
if (Primitives.isWrapperType(cls)) {
config.creationPipeline.staticBindings.add(createBinding(Primitives.unwrap(cls), value));
}
}
示例13: isNotBasisType
import com.google.common.primitives.Primitives; //导入方法依赖的package包/类
private static boolean isNotBasisType(Type type) {
if (false == type instanceof Class)
return false;
if (type.getTypeName().equals("java"))
return false;
Class<?> classOf = (Class<?>) type;
if (Primitives.isWrapperType(classOf) || classOf.isPrimitive() || classOf.isAnonymousClass())
return false;
return true;
}
示例14: isSuitableForDefaultCompare
import com.google.common.primitives.Primitives; //导入方法依赖的package包/类
private static boolean isSuitableForDefaultCompare(Class<?> type) {
return type.isPrimitive()
|| Primitives.isWrapperType(type)
|| type == String.class
|| type == Class.class
|| (type.isArray() && isSuitableForDefaultCompare(type.getComponentType()));
}
示例15: Value
import com.google.common.primitives.Primitives; //导入方法依赖的package包/类
public Value(String type, Object value) {
if (value instanceof Type) {
type = "java.lang.Class";
value = ((Type) value).getClassName();
} else if (Primitives.isWrapperType(value.getClass())) {
type = Primitives.unwrap(value.getClass()).getCanonicalName();
}
this.type = type;
this.value = value;
}