當前位置: 首頁>>代碼示例>>Java>>正文


Java Iterables類代碼示例

本文整理匯總了Java中com.google.common.collect.Iterables的典型用法代碼示例。如果您正苦於以下問題:Java Iterables類的具體用法?Java Iterables怎麽用?Java Iterables使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Iterables類屬於com.google.common.collect包,在下文中一共展示了Iterables類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: testCorrectDataTypeMappingDate

import com.google.common.collect.Iterables; //導入依賴的package包/類
/**
 * Verify that the data type mapping is correct for date columns.
 */
@Test
public void testCorrectDataTypeMappingDate() throws SQLException {
  // Given
  final PreparedStatement statement = mock(PreparedStatement.class, RETURNS_SMART_NULLS);
  when(connection.prepareStatement(anyString())).thenReturn(statement);

  // This is the list of tables that's returned.
  when(statement.executeQuery()).thenAnswer(new ReturnTablesMockResultSet(1)).thenAnswer(new ReturnTablesWithDateColumnMockResultSet(2));

  // When
  final Schema oracleMetaDataProvider = oracle.openSchema(connection, "TESTDATABASE", "TESTSCHEMA");
  assertEquals("Table names", "[AREALTABLE]", oracleMetaDataProvider.tableNames().toString());
  Column dateColumn = Iterables.find(oracleMetaDataProvider.getTable("AREALTABLE").columns(), new Predicate<Column>() {

    @Override
    public boolean apply(Column input) {
      return "dateColumn".equalsIgnoreCase(input.getName());
    }
  });
  assertEquals("Date column type", dateColumn.getType(), DataType.DATE);
}
 
開發者ID:alfasoftware,項目名稱:morf,代碼行數:25,代碼來源:TestOracleMetaDataProvider.java

示例2: reloadResources

import com.google.common.collect.Iterables; //導入依賴的package包/類
public void reloadResources(List<IResourcePack> p_110541_1_)
{
    this.clearResources();
    logger.info("Reloading ResourceManager: " + joinerResourcePacks.join(Iterables.transform(p_110541_1_, new Function<IResourcePack, String>()
    {
        public String apply(IResourcePack p_apply_1_)
        {
            return p_apply_1_.getPackName();
        }
    })));

    for (IResourcePack iresourcepack : p_110541_1_)
    {
        this.reloadResourcePack(iresourcepack);
    }

    this.notifyReloadListeners();
}
 
開發者ID:Notoh,項目名稱:DecompiledMinecraft,代碼行數:19,代碼來源:SimpleReloadableResourceManager.java

示例3: visitSelect

import com.google.common.collect.Iterables; //導入依賴的package包/類
@Override
protected Void visitSelect(Select node, Integer indent) {
    append(indent, "SELECT");
    if (node.isDistinct()) {
        builder.append(" DISTINCT");
    }

    if (node.getSelectItems().size() > 1) {
        boolean first = true;
        for (SelectItem item : node.getSelectItems()) {
            builder.append("\n")
                    .append(indentString(indent))
                    .append(first ? "  " : ", ");

            process(item, indent);
            first = false;
        }
    }
    else {
        builder.append(' ');
        process(Iterables.getOnlyElement(node.getSelectItems()), indent);
    }

    builder.append('\n');
    return null;
}
 
開發者ID:baidu,項目名稱:Elasticsearch,代碼行數:27,代碼來源:SqlFormatter.java

示例4: attachTriggerToNotification

import com.google.common.collect.Iterables; //導入依賴的package包/類
@Test
  public void attachTriggerToNotification() throws Exception {
  	// ARRANGE
TriggerObject triggerObj = ImmutableTriggerObject.builder().alertId(LONG_ID).id(LONG_ID).notificationIds(LIST_OF_LONG_ID).build();
  	Response<TriggerObject> response = Response.success(triggerObj);
  	
  	// ACT
  	@SuppressWarnings("unchecked")
Call<NotificationObject>responseCall = mock(Call.class);
  	doReturn(response).when(responseCall).execute();
doReturn(request).when(responseCall).request();
doReturn(responseCall).when(svc).attachTriggerToNotification(any(), anyLong(), anyLong(), anyLong());
  	
  	// ASSERT
  	TriggerObject notification = argus.attachTriggerToNotification(LONG_ID, Iterables.getOnlyElement(LIST_OF_LONG_ID), LONG_ID);
  	assertThat(notification.alertId(), is(LONG_ID));
  	assertThat(notification.notificationIds(), equalTo(LIST_OF_LONG_ID));
  	assertThat(notification.id(), is(LONG_ID));
  }
 
開發者ID:salesforce,項目名稱:pyplyn,代碼行數:20,代碼來源:ArgusClientTest.java

示例5: writeViewPropertyDslMethods

import com.google.common.collect.Iterables; //導入依賴的package包/類
private void writeViewPropertyDslMethods(ClassVisitor visitor, Type generatedType, Collection<ModelProperty<?>> viewProperties, Class<?> viewClass) {
    boolean writable = Iterables.any(viewProperties, new Predicate<ModelProperty<?>>() {
        @Override
        public boolean apply(ModelProperty<?> viewProperty) {
            return viewProperty.isWritable();
        }
    });
    // TODO:LPTR Instead of the first view property, we should figure out these parameters from the actual property
    ModelProperty<?> firstProperty = viewProperties.iterator().next();

    writeConfigureMethod(visitor, generatedType, firstProperty, writable);
    writeSetMethod(visitor, generatedType, firstProperty);
    writeTypeConvertingSetter(visitor, generatedType, viewClass, firstProperty);

    // TODO - this should be applied to all methods, including delegating methods
    writeReadOnlySetter(visitor, viewClass, writable, firstProperty);
}
 
開發者ID:lxxlxx888,項目名稱:Reer,代碼行數:18,代碼來源:ManagedProxyClassGenerator.java

示例6: transform

import com.google.common.collect.Iterables; //導入依賴的package包/類
@Override
public List<ModelPath> transform(final ModelPath unavailable) {
    Iterable<Suggestion> suggestions = Iterables.transform(availablePaths, new Function<ModelPath, Suggestion>() {
        public Suggestion apply(ModelPath available) {
            int distance = StringUtils.getLevenshteinDistance(unavailable.toString(), available.toString());
            boolean suggest = distance <= Math.min(3, unavailable.toString().length() / 2);
            if (suggest) {
                return new Suggestion(distance, available);
            } else {
                // avoid excess creation of Suggestion objects
                return null;
            }
        }
    });

    suggestions = Iterables.filter(suggestions, REMOVE_NULLS);
    List<Suggestion> sortedSuggestions = CollectionUtils.sort(suggestions);
    return CollectionUtils.collect(sortedSuggestions, Suggestion.EXTRACT_PATH);
}
 
開發者ID:lxxlxx888,項目名稱:Reer,代碼行數:20,代碼來源:ModelPathSuggestionProvider.java

示例7: getSql

import com.google.common.collect.Iterables; //導入依賴的package包/類
/**
 * @return the sql
 */
public List<String> getSql() {
  List<String> results = Lists.newLinkedList();
  if (!sql.isEmpty() || !upgradeScriptAdditions.isEmpty())
    results.addAll(initialisationSql);

  results.addAll(sql);

  for (UpgradeScriptAddition addition : upgradeScriptAdditions) {
    Iterables.addAll(results, addition.sql());
  }

  if (!results.isEmpty())
    results.addAll(finalisationSql);

  return Collections.unmodifiableList(results);
}
 
開發者ID:alfasoftware,項目名稱:morf,代碼行數:20,代碼來源:UpgradePath.java

示例8: verifyFileStatuses

import com.google.common.collect.Iterables; //導入依賴的package包/類
public static void verifyFileStatuses(List<Path> expectedPaths,
    List<FileStatus> fetchedStatuses, final FileSystem localFs) {
  Assert.assertEquals(expectedPaths.size(), fetchedStatuses.size());

  Iterable<Path> fqExpectedPaths = Iterables.transform(expectedPaths,
      new Function<Path, Path>() {
        @Override
        public Path apply(Path input) {
          return localFs.makeQualified(input);
        }
      });

  Set<Path> expectedPathSet = Sets.newHashSet(fqExpectedPaths);
  for (FileStatus fileStatus : fetchedStatuses) {
    if (!expectedPathSet.remove(localFs.makeQualified(fileStatus.getPath()))) {
      Assert.fail("Found extra fetched status: " + fileStatus.getPath());
    }
  }
  Assert.assertEquals(
      "Not all expectedPaths matched: " + expectedPathSet.toString(), 0,
      expectedPathSet.size());
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:23,代碼來源:TestFileInputFormat.java

示例9: removeUnreadFields

import com.google.common.collect.Iterables; //導入依賴的package包/類
@Override
public Iterable<? extends Field> removeUnreadFields() {
    final List<Field> removedFields = Lists.newArrayList();
    Iterables.removeIf(fields, new Predicate<Field>() {
        @Override
        public boolean apply(Field field) {
            if (!field.isRead()) {
                removedFields.add(field);
                return true;
            } else if (field.hasSchema()) {
                Iterables.addAll(removedFields, field.getAssignedSchema().removeUnreadFields());
            }

            return false;
        }
    });
    return removedFields;
}
 
開發者ID:skhalifa,項目名稱:QDrill,代碼行數:19,代碼來源:ListSchema.java

示例10: ready

import com.google.common.collect.Iterables; //導入依賴的package包/類
public DOMStoreThreePhaseCommitCohort ready() {
    final Collection<AbstractProxyTransaction> toReady = ensureClosed();
    Preconditions.checkState(toReady != null, "Attempted to submit a closed transaction %s", this);

    toReady.forEach(AbstractProxyTransaction::seal);
    final AbstractTransactionCommitCohort cohort;
    switch (toReady.size()) {
        case 0:
            cohort = new EmptyTransactionCommitCohort(parent(), getIdentifier());
            break;
        case 1:
            cohort = new DirectTransactionCommitCohort(parent(), getIdentifier(),
                Iterables.getOnlyElement(toReady));
            break;
        default:
            cohort = new ClientTransactionCommitCohort(parent(), getIdentifier(), toReady);
            break;
    }

    return parent().onTransactionReady(this, cohort);
}
 
開發者ID:hashsdn,項目名稱:hashsdn-controller,代碼行數:22,代碼來源:ClientTransaction.java

示例11: render

import com.google.common.collect.Iterables; //導入依賴的package包/類
@Override
public FunctionRender render(FunctionRenderer renderer, RexCall call) {
  checkArity(call, 2);
  PredicateAnalyzer.checkForIncompatibleDateTimeOperands(call);

  RexNode o1 = call.getOperands().get(0);
  RexNode o2 = call.getOperands().get(1);

  FunctionRender op1 = o1.accept(renderer.getVisitor());
  FunctionRender op2 = o2.accept(renderer.getVisitor());

  boolean isTime1 = isTemporal(o1.getType());
  boolean isTime2 = isTemporal(o2.getType());

  if(isTime1 != isTime2){
    throw new RuntimeException("Can't do comparison between a date and a non-date field.");
  }

  // we need special handling in painless for temporal types and comparison other than equality/inequality.
  if(renderer.isUsingPainless() && isTime1 && type != Type.EQ && type != Type.NEQ){
    return handlePainlessTimeComparison(op1, op2);
  }

  String script = String.format("( %s %s %s )", op1.getScript(), elasticName, op2.getScript());
  return new FunctionRender(script, Iterables.concat(op1.getNulls(), op2.getNulls()));
}
 
開發者ID:dremio,項目名稱:dremio-oss,代碼行數:27,代碼來源:CompareFunction.java

示例12: terminated

import com.google.common.collect.Iterables; //導入依賴的package包/類
@Override public synchronized void terminated(State from) {
  assertEquals(from, Iterables.getLast(stateHistory, State.NEW));
  stateHistory.add(State.TERMINATED);
  assertEquals(State.TERMINATED, service.state());
  if (from == State.NEW) {
    try {
      service.awaitRunning();
      fail();
    } catch (IllegalStateException expected) {
      assertNull(expected.getCause());
      assertTrue(expected.getMessage().equals(
          "Expected the service " + service + " to be RUNNING, but was TERMINATED"));
    }
  }
  completionLatch.countDown();
}
 
開發者ID:paul-hammant,項目名稱:googles-monorepo-demo,代碼行數:17,代碼來源:AbstractServiceTest.java

示例13: 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:paul-hammant,項目名稱:googles-monorepo-demo,代碼行數:19,代碼來源:MultisetEntrySetTester.java

示例14: LanguageMap

import com.google.common.collect.Iterables; //導入依賴的package包/類
public LanguageMap()
{
    try
    {
        InputStream inputstream = LanguageMap.class.getResourceAsStream("/assets/minecraft/lang/en_us.lang");

        for (String s : IOUtils.readLines(inputstream, Charsets.UTF_8))
        {
            if (!s.isEmpty() && s.charAt(0) != 35)
            {
                String[] astring = (String[])Iterables.toArray(EQUAL_SIGN_SPLITTER.split(s), String.class);

                if (astring != null && astring.length == 2)
                {
                    String s1 = astring[0];
                    String s2 = NUMERIC_VARIABLE_PATTERN.matcher(astring[1]).replaceAll("%$1s");
                    this.languageList.put(s1, s2);
                }
            }
        }

        this.lastUpdateTimeInMilliseconds = System.currentTimeMillis();
    }
    catch (IOException var7)
    {
        ;
    }
}
 
開發者ID:sudofox,項目名稱:Backmemed,代碼行數:29,代碼來源:LanguageMap.java

示例15: getCollectors

import com.google.common.collect.Iterables; //導入依賴的package包/類
@Override
public Collection<CrateCollector> getCollectors(CollectPhase collectPhase,
                                                RowReceiver downstream,
                                                JobCollectContext jobCollectContext) {
    TableFunctionCollectPhase phase = (TableFunctionCollectPhase) collectPhase;
    TableFunctionImplementation tableFunctionSafe = functions.getTableFunctionSafe(phase.functionName());
    TableInfo tableInfo = tableFunctionSafe.createTableInfo(clusterService, Symbols.extractTypes(phase.arguments()));
    //noinspection unchecked  Only literals can be passed to table functions. Anything else is invalid SQL
    List<Input<?>> inputs = (List<Input<?>>) (List) phase.arguments();

    final Context context = new Context(new ArrayList<>(tableInfo.columns()));
    List<Input<?>> topLevelInputs = new ArrayList<>(phase.toCollect().size());
    for (Symbol symbol : phase.toCollect()) {
        topLevelInputs.add(implementationVisitor.process(symbol, context));
    }
    Iterable<Row> rows = Iterables.transform(
            tableFunctionSafe.execute(inputs),
            InputRow.toInputRowFunction(topLevelInputs, context.collectExpressions));
    OrderBy orderBy = phase.orderBy();
    if (orderBy != null) {
        rows = SystemCollectSource.sortRows(Iterables.transform(rows, Row.MATERIALIZE), phase);
    }
    RowsCollector rowsCollector = new RowsCollector(downstream, rows);
    return Collections.<CrateCollector>singletonList(rowsCollector);
}
 
開發者ID:baidu,項目名稱:Elasticsearch,代碼行數:26,代碼來源:TableFunctionCollectSource.java


注:本文中的com.google.common.collect.Iterables類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。