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


Java Primitives.isWrapperType方法代码示例

本文整理汇总了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;
}
 
开发者ID:eduyayo,项目名称:gamesboard,代码行数:19,代码来源:ClassUtils.java

示例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);
        }
    }
}
 
开发者ID:asoem,项目名称:greyfish,代码行数:25,代码来源:ModelParameterTypeListener.java

示例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);
}
 
开发者ID:apache,项目名称:kylin,代码行数:25,代码来源:BuiltInFunctionTupleFilter.java

示例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);
    }
}
 
开发者ID:CaptainBern,项目名称:Reflection,代码行数:19,代码来源:BukkitUnwrapper.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: 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;
  }
}
 
开发者ID:openstack,项目名称:monasca-common,代码行数:32,代码来源:Serialization.java

示例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;
  });
}
 
开发者ID:jooby-project,项目名称:jooby,代码行数:24,代码来源:BeanParser.java

示例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;
            }
        }
    }
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:32,代码来源:DatastoreContextIntrospector.java

示例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;
}
 
开发者ID:folio-org,项目名称:raml-module-builder,代码行数:18,代码来源:UpdateSection.java

示例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;
}
 
开发者ID:google,项目名称:nomulus,代码行数:14,代码来源:DiffUtils.java

示例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);
}
 
开发者ID:sonatype,项目名称:nexus-public,代码行数:18,代码来源:DescriptionHelper.java

示例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));
    }
}
 
开发者ID:ruediste,项目名称:salta,代码行数:9,代码来源:StandardConstantBindingBuilder.java

示例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;
	}
 
开发者ID:dohbot,项目名称:knives,代码行数:14,代码来源:Classes.java

示例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()));
}
 
开发者ID:Whaka-project,项目名称:whakamatautau-util,代码行数:8,代码来源:ReflectiveComparisonPerformer.java

示例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;
}
 
开发者ID:killjoy1221,项目名称:Class2Json,代码行数:11,代码来源:AnnotationInstanceJson.java


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