本文整理汇总了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);
}
示例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();
}
示例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;
}
示例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));
}
示例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);
}
示例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);
}
示例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);
}
示例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());
}
示例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;
}
示例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);
}
示例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()));
}
示例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();
}
示例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());
}
示例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)
{
;
}
}
示例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);
}