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


Java Defaults.defaultValue方法代码示例

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


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

示例1: handleInvocation

import com.google.common.base.Defaults; //导入方法依赖的package包/类
@Override
protected Object handleInvocation(List<String> path, Method method) throws Throwable
{
    if (method.getName().equals("values"))
    {
        return path.isEmpty()
            ? values
            : nextImmutable.getInPath(values, path);
    }

    final List<String> pathWithMethod = pathWith(method);
    final Class<?> returnType = method.getReturnType();

    final Object value = nextImmutable.getInPath(values, pathWithMethod);
    final Object returnValue = value == null
        ? Defaults.defaultValue(returnType)
        : value;
    final boolean isCastable = returnValue == null || isAssignable(returnValue.getClass(), returnType);

    return isCastable
        ? returnValue
        : immutableFor(returnType, pathWithMethod);
}
 
开发者ID:davherrmann,项目名称:immutable,代码行数:24,代码来源:Immutable.java

示例2: doUnwrap

import com.google.common.base.Defaults; //导入方法依赖的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: invoke

import com.google.common.base.Defaults; //导入方法依赖的package包/类
public Object invoke(final Object proxy,
                     final Method m,
                     final Object[] args) throws Throwable {
    Object result = null;
    try {
        result = m.invoke(target,
                          args);
    } catch (Exception e) {
        if (errorCallBack != null) {
            errorCallBack.error(result,
                                e);
        }
        if (m.getReturnType().isPrimitive()) {
            return Defaults.defaultValue(m.getReturnType());
        } else {
            return result;
        }
    }
    if (successCallBack != null) {
        successCallBack.callback(result);
    }
    return result;
}
 
开发者ID:kiegroup,项目名称:appformer,代码行数:24,代码来源:CallerProxy.java

示例4: resetTransientValues

import com.google.common.base.Defaults; //导入方法依赖的package包/类
/**
 * this nullifies and resets transient values that are supposed not to be stored
 *
 * @param zeObject The object where non transient fields will be nullified.
 */
void resetTransientValues(@Nullable Object zeObject) {
    if (zeObject != null) {
        Field[] fields = zeObject.getClass().getDeclaredFields();
        for (Field field : fields) {
            // ignore jacoco injected field
            if (Modifier.isTransient(field.getModifiers()) && !field.getName().endsWith("jacocoData")) { //$NON-NLS-1$
                Object defaultValue = Defaults.defaultValue(field.getType());
                field.setAccessible(true);
                try {
                    field.set(zeObject, defaultValue);
                } catch (IllegalArgumentException | IllegalAccessException e) {
                    LOG.error("failed to reset the transient field [" + field + "] before storage", e);
                }
            }
        }
    } // else null so do nothing
}
 
开发者ID:Talend,项目名称:data-prep,代码行数:23,代码来源:InMemoryDataSetMetadataRepository.java

示例5: allBuilderMethodsForwarded

import com.google.common.base.Defaults; //导入方法依赖的package包/类
@Test
public void allBuilderMethodsForwarded() throws Exception {
  for (Method method : ManagedChannelBuilder.class.getDeclaredMethods()) {
    if (Modifier.isStatic(method.getModifiers()) || Modifier.isPrivate(method.getModifiers())) {
      continue;
    }
    Class<?>[] argTypes = method.getParameterTypes();
    Object[] args = new Object[argTypes.length];
    for (int i = 0; i < argTypes.length; i++) {
      args[i] = Defaults.defaultValue(argTypes[i]);
    }

    method.invoke(testChannelBuilder, args);
    method.invoke(verify(mockDelegate), args);
  }
}
 
开发者ID:grpc,项目名称:grpc-java,代码行数:17,代码来源:ForwardingChannelBuilderTest.java

示例6: allBuilderMethodsReturnThis

import com.google.common.base.Defaults; //导入方法依赖的package包/类
@Test
public void allBuilderMethodsReturnThis() throws Exception {
  for (Method method : ManagedChannelBuilder.class.getDeclaredMethods()) {
    if (Modifier.isStatic(method.getModifiers()) || Modifier.isPrivate(method.getModifiers())) {
      continue;
    }
    if (method.getName().equals("build")) {
      continue;
    }
    Class<?>[] argTypes = method.getParameterTypes();
    Object[] args = new Object[argTypes.length];
    for (int i = 0; i < argTypes.length; i++) {
      args[i] = Defaults.defaultValue(argTypes[i]);
    }

    Object returnedValue = method.invoke(testChannelBuilder, args);

    assertThat(returnedValue).isSameAs(testChannelBuilder);
  }
}
 
开发者ID:grpc,项目名称:grpc-java,代码行数:21,代码来源:ForwardingChannelBuilderTest.java

示例7: invoke

import com.google.common.base.Defaults; //导入方法依赖的package包/类
@Override
public Object invoke( Object proxy, Method method, Object[] args )
    throws Throwable
{
    ParameterProperty curProperty = properties.getProperty( method );
    if ( properties.getIdProperty() == curProperty )
    {
        // for primitives we need to return something, so return default
        if ( curProperty.isPrimitiveType() )
        {
            return Defaults.defaultValue( Primitives.unwrap( curProperty.getType() ) );
        }
        else
        {
            return null;
        }
    }
    else
    {
        throw new IllegalArgumentException(
            "Only can perform nested query on id field, but was " + curProperty );
    }
}
 
开发者ID:cherimojava,项目名称:cherimodata,代码行数:24,代码来源:QueryInvocationHandler.java

示例8: createDefaultParamValue

import com.google.common.base.Defaults; //导入方法依赖的package包/类
private Object createDefaultParamValue(Class<?> clazz)
{
	if (clazz.isPrimitive())
		return Defaults.defaultValue(clazz);
	if (byte[].class.equals(clazz))
		return "FOO".getBytes();
	return null;
}
 
开发者ID:olavloite,项目名称:spanner-jdbc,代码行数:9,代码来源:AbstractCloudSpannerResultSetTest.java

示例9: getDefaultPrimitiveValue

import com.google.common.base.Defaults; //导入方法依赖的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

示例10: getDefaultValue

import com.google.common.base.Defaults; //导入方法依赖的package包/类
@Nullable
private Object getDefaultValue(@NotNull Class<?> type) {
    if (type == Optional.class) {
        // If it's Guava optional then handle it as an absent value
        return Optional.absent();
    } else if (type.isPrimitive()) {
        // If parameter is a primitive set the appropriate default value
        return Defaults.defaultValue(type);
    }
    return null;
}
 
开发者ID:arteam,项目名称:simple-json-rpc,代码行数:12,代码来源:JsonRpcServer.java

示例11: getProxy

import com.google.common.base.Defaults; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
public <T> T getProxy(TypeToken<T> type) {
    Class<? super T> cls = type.getRawType();

    if (isTerminal(type)) {
        return (T) Defaults.defaultValue(cls);
    }

    Enhancer e = new Enhancer();
    if (Enhancer.isEnhanced(cls)) {
        e.setSuperclass(cls.getSuperclass());
        e.setInterfaces(cls.getInterfaces());
    } else {
        e.setSuperclass(cls);
    }
    e.setCallbackFilter(FINALIZE_FILTER);
    e.setCallbacks(new Callback[] { NoOp.INSTANCE, new MethodInterceptor() {

        @Override
        public Object intercept(Object obj, Method method, Object[] args, MethodProxy proxy) throws Throwable {
            invocations.add(new MethodInvocation<Object>(type, method, Arrays.asList(args)));

            return getProxy(type.resolveType(method.getGenericReturnType()));
        }

    } });

    try {
        return (T) e.create();
    } catch (Exception ex) {
        throw new RuntimeException("Error while creating proxy of " + type, ex);
    }
}
 
开发者ID:ruediste,项目名称:c3java,代码行数:34,代码来源:MethodInvocationRecorder.java

示例12: coerce

import com.google.common.base.Defaults; //导入方法依赖的package包/类
@Override
public Object coerce(Object obj, Type type) {
    if (obj == null) return Defaults.defaultValue(clazzFor(type));

    Class<? extends Object> wrappedType = Primitives.wrap(clazzFor(type));
    Coercer coercer = primitiveCoercers.get(wrappedType);
    return coercer.coerce(obj, wrappedType);
}
 
开发者ID:viltgroup,项目名称:minium,代码行数:9,代码来源:PrimitiveTypeCoercer.java

示例13: getDefault

import com.google.common.base.Defaults; //导入方法依赖的package包/类
/**
 * Returns a default value for the method based upon {@code @Default} metadata on the getter
 * to return values. If there is no {@code @Default} annotation on the getter, then a <a
 * href="https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html">default</a> as
 * per the Java Language Specification for the expected return type is returned.
 *
 * @param proxy The proxy object for which we are attempting to get the default.
 * @param method The getter method that was invoked.
 * @return The default value from an {@link Default} annotation if present, otherwise a default
 *         value as per the Java Language Specification.
 */
@SuppressWarnings({"unchecked", "rawtypes"})
private Object getDefault(PipelineOptions proxy, Method method) {
  if (method.getReturnType().equals(RuntimeValueProvider.class)) {
    throw new RuntimeException(String.format(
      "Method %s should not have return type "
      + "RuntimeValueProvider, use ValueProvider instead.", method.getName()));
  }
  if (method.getReturnType().equals(StaticValueProvider.class)) {
    throw new RuntimeException(String.format(
      "Method %s should not have return type "
      + "StaticValueProvider, use ValueProvider instead.", method.getName()));
  }
  @Nullable Object defaultObject = null;
  for (Annotation annotation : method.getAnnotations()) {
    defaultObject = returnDefaultHelper(annotation, proxy, method);
    if (defaultObject != null) {
      break;
    }
  }
  if (method.getReturnType().equals(ValueProvider.class)) {
    String propertyName = gettersToPropertyNames.get(method.getName());
    return defaultObject == null
      ? new RuntimeValueProvider(
        method.getName(), propertyName,
        (Class<? extends PipelineOptions>) method.getDeclaringClass(),
        proxy.getOptionsId())
      : new RuntimeValueProvider(
        method.getName(), propertyName,
        (Class<? extends PipelineOptions>) method.getDeclaringClass(),
        defaultObject, proxy.getOptionsId());
  } else if (defaultObject != null) {
    return defaultObject;
  }

  /*
   * We need to make sure that we return something appropriate for the return type. Thus we return
   * a default value as defined by the JLS.
   */
  return Defaults.defaultValue(method.getReturnType());
}
 
开发者ID:apache,项目名称:beam,代码行数:52,代码来源:ProxyInvocationHandler.java

示例14: primitiveIf

import com.google.common.base.Defaults; //导入方法依赖的package包/类
@Override protected Object primitiveIf() {
	return Defaults.defaultValue(this.clazz);
}
 
开发者ID:jronrun,项目名称:benayn,代码行数:4,代码来源:Me3Test.java

示例15: eightWrapIf

import com.google.common.base.Defaults; //导入方法依赖的package包/类
@Override protected Object eightWrapIf() {
	return Defaults.defaultValue(Primitives.unwrap(this.clazz));
}
 
开发者ID:jronrun,项目名称:benayn,代码行数:4,代码来源:Me3Test.java


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