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


Java Defaults类代码示例

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


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

示例1: testInvokeAfterAppDelete

import com.google.common.base.Defaults; //导入依赖的package包/类
@Test
public void testInvokeAfterAppDelete() throws Exception {
  FirebaseApp app = FirebaseApp.initializeApp(firebaseOptions, "testInvokeAfterAppDelete");
  FirebaseAuth auth = FirebaseAuth.getInstance(app);
  assertNotNull(auth);
  app.delete();

  for (Method method : auth.getClass().getDeclaredMethods()) {
    int modifiers = method.getModifiers();
    if (!Modifier.isPublic(modifiers) || Modifier.isStatic(modifiers)) {
      continue;
    }

    List<Object> parameters = new ArrayList<>(method.getParameterTypes().length);
    for (Class<?> parameterType : method.getParameterTypes()) {
      parameters.add(Defaults.defaultValue(parameterType));
    }
    try {
      method.invoke(auth, parameters.toArray());
      fail("No error thrown when invoking auth after deleting app; method: " + method.getName());
    } catch (InvocationTargetException expected) {
      String message = "FirebaseAuth instance is no longer alive. This happens when "
          + "the parent FirebaseApp instance has been deleted.";
      Throwable cause = expected.getCause();
      assertTrue(cause instanceof IllegalStateException);
      assertEquals(message, cause.getMessage());
    }
  }
}
 
开发者ID:firebase,项目名称:firebase-admin-java,代码行数:30,代码来源:FirebaseAuthTest.java

示例2: unsafeCreate

import com.google.common.base.Defaults; //导入依赖的package包/类
/**
 * Creates an instance of the given using Unsafe. It also initialize all fields into default values.
 */
private static <T> T unsafeCreate(Class<T> clz) throws InvocationTargetException, IllegalAccessException {
  T instance = (T) UNSAFE_NEW_INSTANCE.invoke(UNSAFE, clz);

  for (TypeToken<?> type : TypeToken.of(clz).getTypes().classes()) {
    if (Object.class.equals(type.getRawType())) {
      break;
    }
    for (Field field : type.getRawType().getDeclaredFields()) {
      if (Modifier.isStatic(field.getModifiers())) {
        continue;
      }
      if (!field.isAccessible()) {
        field.setAccessible(true);
      }
      field.set(instance, Defaults.defaultValue(field.getType()));
    }
  }

  return instance;
}
 
开发者ID:apache,项目名称:twill,代码行数:24,代码来源:Instances.java

示例3: newPartitionContextTest

import com.google.common.base.Defaults; //导入依赖的package包/类
public static <S> PartitionContextValidator<S> newPartitionContextTest(final Class<S> ifc, final Class<? extends S> impl) {
    final PartitionContextSupplier supplier = new AnnotationPartitionContextSupplier(ifc, impl);
    return new PartitionContextValidator<S>() {
        @Override
        public S expect(final PartitionContext expected) {
            return Reflection.newProxy(ifc, new AbstractInvocationHandler() {
                @Override
                protected Object handleInvocation(Object proxy, Method method, Object[] args) throws Throwable {
                    PartitionContext actual = supplier.forCall(method, args);
                    assertEquals(actual, expected, "Expected=" + expected.asMap() + ", Actual=" + actual.asMap());
                    return Defaults.defaultValue(method.getReturnType());
                }
            });
        }
    };
}
 
开发者ID:bazaarvoice,项目名称:emodb,代码行数:17,代码来源:OstrichAccessors.java

示例4: 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

示例5: resolveArguments

import com.google.common.base.Defaults; //导入依赖的package包/类
public static ArrayList<SupplierRecipe> resolveArguments(StandardInjectorConfiguration config,
        TypeToken<?> typeToken, RecipeCreationContext ctx, Constructor<?> constructor) {
    ArrayList<SupplierRecipe> args = new ArrayList<>();

    Parameter[] parameters = constructor.getParameters();
    for (int i = 0; i < parameters.length; i++) {
        Parameter parameter = parameters[i];
        @SuppressWarnings({ "unchecked", "rawtypes" })
        CoreDependencyKey<Object> dependency = new InjectionPoint(
                typeToken.resolveType(parameter.getParameterizedType()), constructor, parameter, i);
        Optional<SupplierRecipe> argRecipe = ctx.tryGetRecipe(dependency);
        if (argRecipe.isPresent())
            args.add(argRecipe.get());
        else {
            if (config.isInjectionOptional(parameter)) {
                args.add(new SupplierRecipeImpl(() -> Defaults.defaultValue(parameter.getType())));
            } else {
                throw new SaltaException(
                        "Cannot resolve constructor parameter of " + constructor + ":\n" + parameter);
            }
        }
    }
    return args;
}
 
开发者ID:ruediste,项目名称:salta,代码行数:25,代码来源:DefaultFixedConstructorInstantiationRule.java

示例6: 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

示例7: 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

示例8: 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

示例9: 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

示例10: 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

示例11: _get

import com.google.common.base.Defaults; //导入依赖的package包/类
/**
 * Returns the currently assigned value for the given Property or null if the property currently isn't set
 *
 * @param property to get value from
 * @return value of the property or null if the property isn't set. Might return null if the property is computed
 *         and the computer returns null
 */
@SuppressWarnings( "unchecked" )
private Object _get( ParameterProperty property )
{
    if ( property.isComputed() )
    {
        // if this property is computed we need to calculate the value for it
        return property.getComputer().compute( proxy );
    }
    else
    {
        String name = property.getMongoName();
        // add default value, in case nothing has been set yet
        if ( !data.containsKey( name ) && property.isPrimitiveType() )
        {
            data.put( name, Defaults.defaultValue( Primitives.unwrap( property.getType() ) ) );
        }
        return data.get( name );
    }
}
 
开发者ID:cherimojava,项目名称:cherimodata,代码行数:27,代码来源:EntityInvocationHandler.java

示例12: 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

示例13: invokePublicInstanceMethodWithDefaultValues

import com.google.common.base.Defaults; //导入依赖的package包/类
private static void invokePublicInstanceMethodWithDefaultValues(Object instance, Method method)
    throws InvocationTargetException, IllegalAccessException {
  List<Object> parameters = new ArrayList<>(method.getParameterTypes().length);
  for (Class<?> parameterType : method.getParameterTypes()) {
    parameters.add(Defaults.defaultValue(parameterType));
  }
  method.invoke(instance, parameters.toArray());
}
 
开发者ID:firebase,项目名称:firebase-admin-java,代码行数:9,代码来源:FirebaseAppTest.java

示例14: 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

示例15: validateField

import com.google.common.base.Defaults; //导入依赖的package包/类
private static void validateField(
    String name,
    Object object,
    Field field,
    Set<Field> ignoredFields) {

  try {
    field.setAccessible(true);
    String fullName = name + "." + field.getName();
    Object fieldValue = field.get(object);
    boolean mustBeSet = !ignoredFields.contains(field);
    if (mustBeSet) {
      assertNotNull(fullName + " is null", fieldValue);
    }
    if (fieldValue != null) {
      if (Primitives.isWrapperType(fieldValue.getClass())) {
        // Special-case the mutable hash code field.
        if (mustBeSet && !fullName.endsWith("cachedHashCode")) {
          assertNotEquals(
              "Primitive value must not be default: " + fullName,
              Defaults.defaultValue(Primitives.unwrap(fieldValue.getClass())),
              fieldValue);
        }
      } else {
        assertFullyPopulated(fullName, fieldValue, ignoredFields);
      }
    }
  } catch (IllegalAccessException e) {
    throw Throwables.propagate(e);
  }
}
 
开发者ID:PacktPublishing,项目名称:Mastering-Mesos,代码行数:32,代码来源:StorageEntityUtil.java


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