本文整理汇总了Java中com.google.common.collect.Iterables.transform方法的典型用法代码示例。如果您正苦于以下问题:Java Iterables.transform方法的具体用法?Java Iterables.transform怎么用?Java Iterables.transform使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.common.collect.Iterables
的用法示例。
在下文中一共展示了Iterables.transform方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: buildCartesianProduct
import com.google.common.collect.Iterables; //导入方法依赖的package包/类
/**
* Sets.cartesianProduct doesn't allow sets that contain null, but we want null to mean
* "don't call the associated CacheBuilder method" - that is, get the default CacheBuilder
* behavior. This method wraps the elements in the input sets (which may contain null) as
* Optionals, calls Sets.cartesianProduct with those, then transforms the result to unwrap
* the Optionals.
*/
private Iterable<List<Object>> buildCartesianProduct(Set<?>... sets) {
List<Set<Optional<?>>> optionalSets = Lists.newArrayListWithExpectedSize(sets.length);
for (Set<?> set : sets) {
Set<Optional<?>> optionalSet =
Sets.newLinkedHashSet(Iterables.transform(set, NULLABLE_TO_OPTIONAL));
optionalSets.add(optionalSet);
}
Set<List<Optional<?>>> cartesianProduct = Sets.cartesianProduct(optionalSets);
return Iterables.transform(cartesianProduct,
new Function<List<Optional<?>>, List<Object>>() {
@Override public List<Object> apply(List<Optional<?>> objs) {
return Lists.transform(objs, OPTIONAL_TO_NULLABLE);
}
});
}
示例2: buildAllPermutations
import com.google.common.collect.Iterables; //导入方法依赖的package包/类
Iterable<CacheBuilder<Object, Object>> buildAllPermutations() {
@SuppressWarnings("unchecked")
Iterable<List<Object>> combinations = buildCartesianProduct(concurrencyLevels,
initialCapacities, maximumSizes, expireAfterWrites, expireAfterAccesses, refreshes,
keyStrengths, valueStrengths);
return Iterables.transform(combinations,
new Function<List<Object>, CacheBuilder<Object, Object>>() {
@Override public CacheBuilder<Object, Object> apply(List<Object> combination) {
return createCacheBuilder(
(Integer) combination.get(0),
(Integer) combination.get(1),
(Integer) combination.get(2),
(DurationSpec) combination.get(3),
(DurationSpec) combination.get(4),
(DurationSpec) combination.get(5),
(Strength) combination.get(6),
(Strength) combination.get(7));
}
});
}
示例3: getUpdateStatementSetFieldSql
import com.google.common.collect.Iterables; //导入方法依赖的package包/类
/**
* Returns the SET statement for an SQL UPDATE statement based on the
* {@link List} of {@link AliasedField}s provided.
*
* @param fields The {@link List} of {@link AliasedField}s to create the SET
* statement from
* @return The SET statement as a string
*/
protected String getUpdateStatementSetFieldSql(final List<AliasedField> fields) {
StringBuilder sqlBuilder = new StringBuilder();
sqlBuilder.append(" SET ");
Iterable<String> setStatements = Iterables.transform(fields, new com.google.common.base.Function<AliasedField, String>() {
@Override
public String apply(AliasedField field) {
return field.getAlias() + " = " + getSqlFrom(field);
}
});
sqlBuilder.append(Joiner.on(", ").join(setStatements));
return sqlBuilder.toString();
}
示例4: 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);
}
示例5: getAllVariantNames
import com.google.common.collect.Iterables; //导入方法依赖的package包/类
public Iterable<String> getAllVariantNames() {
synchronized (lock) {
return aPrj != null
? Iterables.transform(
aPrj.getVariants(),
new Function<Variant, String>() {
@Override
public String apply(Variant f) {
return f.getName();
}
})
: Collections.<String>emptyList();
}
}
示例6: iterate
import com.google.common.collect.Iterables; //导入方法依赖的package包/类
@Override
public Iterable<Pair<String, V>> iterate(final String keyPrefixFilter)
{
Iterable<CachedValue> iterable = new BatchingIterator<CachedValue>()
{
private static final int BATCH_SIZE = 200;
@Override
protected Iterator<CachedValue> getMore(Optional<CachedValue> lastObj)
{
long startId = lastObj.isPresent() ? lastObj.get().getId() : 1;
return dao.getBatch(cacheId, keyPrefixFilter, startId, BATCH_SIZE).iterator();
}
};
return Iterables.transform(iterable, new Function<CachedValue, Pair<String, V>>()
{
@Override
@Nullable
public Pair<String, V> apply(@Nullable CachedValue input)
{
@SuppressWarnings("unchecked")
V v = (V) PluginAwareObjectInputStream.fromBytes(input.getValue());
return new Pair<>(input.getKey(), v);
}
});
}
示例7: upgrade
import com.google.common.collect.Iterables; //导入方法依赖的package包/类
@Override
public void upgrade(UpgradeContext context) {
final NamespaceService namespaceService = new NamespaceServiceImpl(context.getKVStoreProvider().get());
try {
for (SourceConfig source : namespaceService.getSources()) {
if (source.getType() == SourceType.HIVE) {
for (NamespaceKey datasetPath : namespaceService.getAllDatasets(new NamespaceKey(source.getName()))) {
final DatasetConfig datasetConfig = namespaceService.getDataset(datasetPath);
// drop the metadata and splits
if (datasetConfig.getReadDefinition() != null) {
Iterable<DatasetSplitId> splitIdList = Iterables.transform(
namespaceService.findSplits(DatasetSplitId.getAllSplitsRange(datasetConfig)),
new Function<Entry<DatasetSplitId, DatasetSplit>, DatasetSplitId>() {
@Override
public DatasetSplitId apply(Entry<DatasetSplitId, DatasetSplit> input) {
return input.getKey();
}
});
namespaceService.deleteSplits(splitIdList);
}
datasetConfig.setReadDefinition(null);
namespaceService.addOrUpdateDataset(datasetPath, datasetConfig);
}
}
}
} catch (NamespaceException e) {
throw new RuntimeException("FixHiveMetadata failed", e);
}
}
示例8: getInstitutionSessions
import com.google.common.collect.Iterables; //导入方法依赖的package包/类
@Override
public Iterable<UserSessionTimestamp> getInstitutionSessions()
{
final Iterable<Pair<String, UserSessionTimestamp>> usts = allSessions.iterate("");
return Iterables.transform(usts, new Function<Pair<String, UserSessionTimestamp>, UserSessionTimestamp>()
{
@Override
@Nullable
public UserSessionTimestamp apply(@Nullable Pair<String, UserSessionTimestamp> input)
{
return input.getSecond();
}
});
}
示例9: getListOfStringsMatchingLastWord
import com.google.common.collect.Iterables; //导入方法依赖的package包/类
public static List<String> getListOfStringsMatchingLastWord(String[] p_175762_0_, Collection<?> p_175762_1_)
{
String s = p_175762_0_[p_175762_0_.length - 1];
List<String> list = Lists.<String>newArrayList();
if (!p_175762_1_.isEmpty())
{
for (String s1 : Iterables.transform(p_175762_1_, Functions.toStringFunction()))
{
if (doesStringStartWith(s, s1))
{
list.add(s1);
}
}
if (list.isEmpty())
{
for (Object object : p_175762_1_)
{
if (object instanceof ResourceLocation && doesStringStartWith(s, ((ResourceLocation)object).getResourcePath()))
{
list.add(String.valueOf(object));
}
}
}
}
return list;
}
示例10: find
import com.google.common.collect.Iterables; //导入方法依赖的package包/类
@Override
public Iterable<Map.Entry<KVStoreTuple<KEY>, KVStoreTuple<VALUE>>> find() {
return Iterables.transform(rawStore.find(), new Function<Map.Entry<byte[], byte[]>, Map.Entry<KVStoreTuple<KEY>, KVStoreTuple<VALUE>>>() {
public Map.Entry<KVStoreTuple<KEY>, KVStoreTuple<VALUE>> apply(final Map.Entry<byte[], byte[]> input) {
return new CoreKVStoreEntry(input);
}
});
}
示例11: parametersFromColumns
import com.google.common.collect.Iterables; //导入方法依赖的package包/类
/**
* Generates an iterable of parameters from columns.
*
* @param columns table columns.
* @return parameters matching these columns.
*/
public static Iterable<SqlParameter> parametersFromColumns(Iterable<Column> columns) {
return Iterables.transform(columns, new Function<Column, SqlParameter>() {
@Override
public SqlParameter apply(Column column) {
return new SqlParameter(column);
}
});
}
示例12: createEqualsSqlForFields
import com.google.common.collect.Iterables; //导入方法依赖的package包/类
/**
* Transforms the entries of a list of Aliased Fields so that each entry
* become a String: "fieldName = selectAlias.fieldName".
*
* @param aliasedFields an iterable of aliased fields.
* @param selectAlias the alias of the source select of the merge statement
* @return an iterable containing strings
*/
private Iterable<String> createEqualsSqlForFields(final Iterable<AliasedField> aliasedFields, final String selectAlias,
final String targetTableName) {
return Iterables.transform(aliasedFields, new com.google.common.base.Function<AliasedField, String>() {
@Override
public String apply(AliasedField field) {
return String.format("%s.%s = %s.%s", targetTableName, field.getImpliedName(), selectAlias, field.getImpliedName());
}
});
}
示例13: getAllElements
import com.google.common.collect.Iterables; //导入方法依赖的package包/类
@Override
public Iterable<IEObjectDescription> getAllElements() {
Iterable<IEObjectDescription> parent = super.getAllElements();
return Iterables.transform(parent, new Function<IEObjectDescription, IEObjectDescription>() {
@Override
public IEObjectDescription apply(IEObjectDescription input) {
return resolve(input);
}
});
}
示例14: caches
import com.google.common.collect.Iterables; //导入方法依赖的package包/类
/**
* Most of the tests in this class run against every one of these caches.
*/
private Iterable<LoadingCache<Object, Object>> caches() {
// lots of different ways to configure a LoadingCache
CacheBuilderFactory factory = cacheFactory();
return Iterables.transform(factory.buildAllPermutations(),
new Function<CacheBuilder<Object, Object>, LoadingCache<Object, Object>>() {
@Override public LoadingCache<Object, Object> apply(
CacheBuilder<Object, Object> builder) {
return builder.recordStats().build(identityLoader());
}
});
}
示例15: cacheTables
import com.google.common.collect.Iterables; //导入方法依赖的package包/类
private void cacheTables(Iterable<Table> newTables) {
// Create disconnected copies of the tables in case we run across connections/data sources
Iterable<Table> copies = Iterables.transform(newTables, new CopyTables());
tables.putAll(Maps.uniqueIndex(copies, new Function<Table, String>() {
@Override
public String apply(Table table) {
return table.getName().toUpperCase();
}
}));
tablesLoaded = true;
}