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


Java Iterables.getOnlyElement方法代码示例

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


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

示例1: visitClassOrInterface

import com.google.common.collect.Iterables; //导入方法依赖的package包/类
@Override
protected boolean visitClassOrInterface(FunctionType type) {
  Type currentJavaType = getCurrentJavaType();
  List<TypeReference> generics = convertTypeParametersDefinition(type);

  currentJavaType.getTypeParameters().addAll(generics);

  // If the type is an external type and have extension point, we need to retrofit the generics on
  // the extension type as well
  if (currentJavaType.isExtern()
      && getJavaTypeRegistry().containsExtensionType(currentJavaType)) {
    Type extensionType = getJavaTypeRegistry().getExtensionType(currentJavaType);
    extensionType.getTypeParameters().addAll(generics);
    // parametrize the extension clause
    TypeReference currentExtensionReference =
        Iterables.getOnlyElement(extensionType.getInheritedTypes());
    checkState(currentExtensionReference instanceof JavaTypeReference);
    extensionType.getInheritedTypes().clear();
    extensionType
        .getInheritedTypes()
        .add(new ParametrizedTypeReference(currentExtensionReference, generics));
  }

  return true;
}
 
开发者ID:google,项目名称:jsinterop-generator,代码行数:26,代码来源:TypeParameterCollector.java

示例2: testEntryReflectsIteratorRemove

import com.google.common.collect.Iterables; //导入方法依赖的package包/类
@CollectionSize.Require(SEVERAL)
@CollectionFeature.Require(SUPPORTS_ITERATOR_REMOVE)
@MultisetFeature.Require(ENTRIES_ARE_VIEWS)
public void testEntryReflectsIteratorRemove() {
  initThreeCopies();
  assertEquals(3, getMultiset().count(e0()));
  Multiset.Entry<E> entry = Iterables.getOnlyElement(getMultiset().entrySet());
  assertEquals(3, entry.getCount());
  Iterator<E> itr = getMultiset().iterator();
  itr.next();
  itr.remove();
  assertEquals(2, entry.getCount());
  itr.next();
  itr.remove();
  itr.next();
  itr.remove();
  assertEquals(0, entry.getCount());
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:19,代码来源:MultisetEntrySetTester.java

示例3: testWildcardedListListener

import com.google.common.collect.Iterables; //导入方法依赖的package包/类
@Test
public void testWildcardedListListener() throws Exception {
    final EventCapturingListener<TopLevelList> listener = new EventCapturingListener<>();
    final DataTreeIdentifier<TopLevelList> wildcard = new DataTreeIdentifier<>(LogicalDatastoreType.OPERATIONAL, TOP_PATH.child(TopLevelList.class));
    dataBrokerImpl.registerDataTreeChangeListener(wildcard, listener);

    putTx(TOP_PATH, TOP_INITIAL_DATA).submit().checkedGet();

    final DataTreeModification<TopLevelList> fooWriteEvent = Iterables.getOnlyElement(listener.nextEvent());
    assertEquals(FOO_PATH, fooWriteEvent.getRootPath().getRootIdentifier());
    verifyModification(fooWriteEvent.getRootNode(), FOO_ARGUMENT, ModificationType.WRITE);

    putTx(BAR_PATH, BAR_DATA).submit().checkedGet();
    final DataTreeModification<TopLevelList> barWriteEvent = Iterables.getOnlyElement(listener.nextEvent());
    assertEquals(BAR_PATH, barWriteEvent.getRootPath().getRootIdentifier());
    verifyModification(barWriteEvent.getRootNode(), BAR_ARGUMENT, ModificationType.WRITE);

    deleteTx(BAR_PATH).submit().checkedGet();
    final DataTreeModification<TopLevelList> barDeleteEvent = Iterables.getOnlyElement(listener.nextEvent());
    assertEquals(BAR_PATH, barDeleteEvent.getRootPath().getRootIdentifier());
    verifyModification(barDeleteEvent.getRootNode(), BAR_ARGUMENT, ModificationType.DELETE);
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:23,代码来源:DataTreeChangeListenerTest.java

示例4: testWriteThroughEntry

import com.google.common.collect.Iterables; //导入方法依赖的package包/类
public void testWriteThroughEntry() {
  for (LoadingCache<Object, Object> cache : caches()) {
    cache.getUnchecked(1);
    Entry<Object, Object> entry = Iterables.getOnlyElement(cache.asMap().entrySet());

    cache.invalidate(1);
    assertEquals(0, cache.size());

    entry.setValue(3);
    assertEquals(1, cache.size());
    assertEquals(3, cache.getIfPresent(1));
    checkValidState(cache);

    try {
      entry.setValue(null);
      fail();
    } catch (NullPointerException expected) {
    }
    checkValidState(cache);
  }
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:22,代码来源:PopulatedCachesTest.java

示例5: testForwardingObject

import com.google.common.collect.Iterables; //导入方法依赖的package包/类
/**
 * Ensures that all interface methods of {@code forwarderClass} are forwarded to the
 * {@link ForwardingObject#delegate}. {@code forwarderClass} is assumed to only implement one
 * interface.
 */
static <T extends ForwardingObject> void testForwardingObject(final Class<T> forwarderClass) {
  @SuppressWarnings("unchecked") // super interface type of T
  Class<? super T> interfaceType = (Class<? super T>)
      Iterables.getOnlyElement(Arrays.asList(forwarderClass.getInterfaces()));
  new ForwardingWrapperTester()
      .testForwarding(
          interfaceType,
          new Function<Object, T>() {
            @Override
            public T apply(Object delegate) {
              T mock = mock(forwarderClass, CALLS_REAL_METHODS.get());
              try {
                T stubber = doReturn(delegate).when(mock);
                DELEGATE_METHOD.invoke(stubber);
              } catch (Exception e) {
                throw new RuntimeException(e);
              }
              return mock;
            }
          });
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:27,代码来源:ForwardingObjectTester.java

示例6: visitSingleMemberAnnotation

import com.google.common.collect.Iterables; //导入方法依赖的package包/类
boolean visitSingleMemberAnnotation(AnnotationTree node) {
    if (node.getArguments().size() != 1) {
        return false;
    }
    ExpressionTree value = Iterables.getOnlyElement(node.getArguments());
    if (value.getKind() == ASSIGNMENT) {
        return false;
    }
    boolean isArrayInitializer = value.getKind() == NEW_ARRAY;
    builder.open(isArrayInitializer ? ZERO : plusFour);
    token("@");
    scan(node.getAnnotationType(), null);
    token("(");
    if (!isArrayInitializer) {
        builder.breakOp();
    }
    scan(value, null);
    builder.close();
    token(")");
    return true;
}
 
开发者ID:tranleduy2000,项目名称:javaide,代码行数:22,代码来源:JavaInputAstVisitor.java

示例7: invoke

import com.google.common.collect.Iterables; //导入方法依赖的package包/类
/**
 * When a factory method is invoked, we create a child injector that binds all parameters, then
 * use that to get an instance of the return type.
 */
@Override
public Object invoke(Object proxy, final Method method, final Object[] args) throws Throwable {
    if (method.getDeclaringClass() == Object.class) {
        return method.invoke(this, args);
    }

    Provider<?> provider = getBindingFromNewInjector(method, args).getProvider();
    try {
        return provider.get();
    } catch (ProvisionException e) {
        // if this is an exception declared by the factory method, throw it as-is
        if (e.getErrorMessages().size() == 1) {
            Message onlyError = Iterables.getOnlyElement(e.getErrorMessages());
            Throwable cause = onlyError.getCause();
            if (cause != null && canRethrow(method, cause)) {
                throw cause;
            }
        }
        throw e;
    }
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:26,代码来源:FactoryProvider2.java

示例8: determineManagedPropertyType

import com.google.common.collect.Iterables; //导入方法依赖的package包/类
private static ModelType<?> determineManagedPropertyType(StructBindingExtractionContext<?> extractionContext, String propertyName, Multimap<PropertyAccessorType, StructMethodBinding> accessorBindings) {
    Collection<StructMethodBinding> isGetter = accessorBindings.get(IS_GETTER);
    for (StructMethodBinding isGetterBinding : isGetter) {
        if (!((ManagedPropertyMethodBinding) isGetterBinding).getDeclaredPropertyType().equals(ModelType.of(Boolean.TYPE))) {
            WeaklyTypeReferencingMethod<?, ?> isGetterMethod = isGetterBinding.getViewMethod();
            extractionContext.add(isGetterMethod, String.format("it should either return 'boolean', or its name should be '%s()'",
                "get" + isGetterMethod.getName().substring(2)));
        }
    }
    Set<ModelType<?>> potentialPropertyTypes = Sets.newLinkedHashSet();
    for (StructMethodBinding binding : accessorBindings.values()) {
        if (binding.getAccessorType() == SETTER) {
            continue;
        }
        ManagedPropertyMethodBinding propertyBinding = (ManagedPropertyMethodBinding) binding;
        potentialPropertyTypes.add(propertyBinding.getDeclaredPropertyType());
    }
    Collection<ModelType<?>> convergingPropertyTypes = findConvergingTypes(potentialPropertyTypes);
    if (convergingPropertyTypes.size() != 1) {
        extractionContext.add(propertyName, String.format("it must have a consistent type, but it's defined as %s",
            Joiner.on(", ").join(ModelTypes.getDisplayNames(convergingPropertyTypes))));
        return convergingPropertyTypes.iterator().next();
    }
    ModelType<?> propertyType = Iterables.getOnlyElement(convergingPropertyTypes);

    for (StructMethodBinding setterBinding : accessorBindings.get(SETTER)) {
        ManagedPropertyMethodBinding propertySetterBinding = (ManagedPropertyMethodBinding) setterBinding;
        ModelType<?> declaredSetterType = propertySetterBinding.getDeclaredPropertyType();
        if (!declaredSetterType.equals(propertyType)) {
            extractionContext.add(setterBinding.getViewMethod(), String.format("it should take parameter with type '%s'",
                propertyType.getDisplayName()));
        }
    }
    return propertyType;
}
 
开发者ID:lxxlxx888,项目名称:Reer,代码行数:36,代码来源:DefaultStructBindingsStore.java

示例9: parseUnit

import com.google.common.collect.Iterables; //导入方法依赖的package包/类
private Unit parseUnit(String templateText) throws Exception {
  ParsingResult<Object> result = new ReportingParseRunner<>(parser.Unit()).run(templateText);

  if (result.hasErrors()) {
    String errors = ErrorUtils.printParseErrors(result.parseErrors);
    throw new Exception(errors);
  }

  return (Unit) Iterables.getOnlyElement(result.valueStack);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:11,代码来源:Processor.java

示例10: getThriftServiceAnnotation

import com.google.common.collect.Iterables; //导入方法依赖的package包/类
public static ThriftService getThriftServiceAnnotation(Class<?> serviceClass)
{
    Set<ThriftService> serviceAnnotations = getEffectiveClassAnnotations(serviceClass, ThriftService.class);
    checkArgument(!serviceAnnotations.isEmpty(), "Service class %s is not annotated with @ThriftService", serviceClass.getName());
    checkArgument(serviceAnnotations.size() == 1, "Service class %s has multiple conflicting @ThriftService annotations: %s", serviceClass.getName(), serviceAnnotations);

    return Iterables.getOnlyElement(serviceAnnotations);
}
 
开发者ID:airlift,项目名称:drift,代码行数:9,代码来源:ThriftServiceMetadata.java

示例11: testEntryViewReflectsRemove

import com.google.common.collect.Iterables; //导入方法依赖的package包/类
@CollectionSize.Require(SEVERAL)
@CollectionFeature.Require(SUPPORTS_REMOVE)
@MultisetFeature.Require(ENTRIES_ARE_VIEWS)
public void testEntryViewReflectsRemove() {
  initThreeCopies();
  assertEquals(3, getMultiset().count(e0()));
  Multiset.Entry<E> entry = Iterables.getOnlyElement(getMultiset().entrySet());
  assertEquals(3, entry.getCount());
  assertTrue(getMultiset().remove(e0()));
  assertEquals(2, entry.getCount());
  assertTrue(getMultiset().elementSet().remove(e0()));
  assertEquals(0, entry.getCount());
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:14,代码来源:MultisetEntrySetTester.java

示例12: testEntryReflectsClear

import com.google.common.collect.Iterables; //导入方法依赖的package包/类
@CollectionSize.Require(SEVERAL)
@CollectionFeature.Require(SUPPORTS_REMOVE)
@MultisetFeature.Require(ENTRIES_ARE_VIEWS)
public void testEntryReflectsClear() {
  initThreeCopies();
  assertEquals(3, getMultiset().count(e0()));
  Multiset.Entry<E> entry = Iterables.getOnlyElement(getMultiset().entrySet());
  assertEquals(3, entry.getCount());
  getMultiset().clear();
  assertEquals(0, entry.getCount());
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:12,代码来源:MultisetEntrySetTester.java

示例13: createAndVerifyTop

import com.google.common.collect.Iterables; //导入方法依赖的package包/类
private void createAndVerifyTop(final EventCapturingListener<Top> listener) throws Exception {
    putTx(TOP_PATH,TOP_INITIAL_DATA).submit().checkedGet();
    final Collection<DataTreeModification<Top>> events = listener.nextEvent();

    assertFalse("Non empty collection should be received.",events.isEmpty());
    final DataTreeModification<Top> initialWrite = Iterables.getOnlyElement(events);
    final DataObjectModification<? extends DataObject> initialNode = initialWrite.getRootNode();
    verifyModification(initialNode,TOP_PATH.getPathArguments().iterator().next(),ModificationType.WRITE);
    assertEquals(TOP_INITIAL_DATA, initialNode.getDataAfter());
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:11,代码来源:DataTreeChangeListenerTest.java

示例14: getField

import com.google.common.collect.Iterables; //导入方法依赖的package包/类
@Override
public Field getField(String fieldName, int index) {
    Field field;
    if (isSingleTyped()) {
        field = Iterables.getOnlyElement(fields, null);
    } else {
        field = index < fields.size() ? fields.get(index) : null;
    }

    return field;
}
 
开发者ID:skhalifa,项目名称:QDrill,代码行数:12,代码来源:ListSchema.java

示例15: testAsMapEntrySetRemovePropagatesToMultimap

import com.google.common.collect.Iterables; //导入方法依赖的package包/类
@CollectionSize.Require(SEVERAL)
@MapFeature.Require({SUPPORTS_PUT, SUPPORTS_REMOVE})
public void testAsMapEntrySetRemovePropagatesToMultimap() {
  resetContainer(Helpers.mapEntry(k0(), v0()), Helpers.mapEntry(k0(), v3()));
  Set<Entry<K, Collection<V>>> asMapEntrySet = multimap().asMap().entrySet();
  Entry<K, Collection<V>> asMapEntry0 = Iterables.getOnlyElement(asMapEntrySet);
  assertTrue(multimap().put(k1(), v4()));
  assertTrue(asMapEntrySet.remove(asMapEntry0));
  assertEquals(1, multimap().size());
  assertContentsInOrder(multimap().keySet(), k1());
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:12,代码来源:MultimapAsMapTester.java


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