本文整理了Java中com.google.common.collect.Lists
类的一些代码示例,展示了Lists
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Lists
类的具体详情如下:
包路径:com.google.common.collect.Lists
类名称:Lists
[英]Static utility methods pertaining to List instances. Also see this class's counterparts Sets, Maps and Queues.
See the Guava User Guide article on Lists.
[中]与列表实例相关的静态实用程序方法。还可以查看此类的对应集合、映射和队列。
请参阅关于Lists的Guava用户指南文章。
代码示例来源:origin: google/guava
@Override
protected List<String> create(String[] elements) {
List<String> fromList = Lists.newArrayList();
for (String element : elements) {
fromList.add("q" + checkNotNull(element));
}
return Lists.transform(fromList, removeFirst);
}
})
代码示例来源:origin: google/guava
@Override
protected List<String> create(String[] elements) {
List<String> fromList = Lists.newLinkedList();
for (String element : elements) {
fromList.add("q" + checkNotNull(element));
}
return Lists.transform(fromList, removeFirst);
}
})
代码示例来源:origin: google/guava
@Override
protected ArrayList<LockGraphNode> initialValue() {
return Lists.<LockGraphNode>newArrayListWithCapacity(3);
}
};
代码示例来源:origin: google/guava
@Override
protected List<String> create(String[] elements) {
List<String> list = Lists.newLinkedList();
for (int i = elements.length - 1; i >= 0; i--) {
list.add(elements[i]);
}
return Lists.reverse(list);
}
})
代码示例来源:origin: apache/incubator-druid
private LookupEnabledTestExprMacroTable()
{
super(
Lists.newArrayList(
Iterables.concat(
TestExprMacroTable.INSTANCE.getMacros(),
Collections.singletonList(
new LookupExprMacro(createTestLookupReferencesManager(ImmutableMap.of("foo", "xfoo")))
)
)
)
);
}
代码示例来源:origin: apache/incubator-druid
.intervals(QueryRunnerTestHelper.fullOnIntervalSpec)
.aggregators(
Lists.newArrayList(
Iterables.concat(
commonAggregators,
Lists.newArrayList(
new DoubleMaxAggregatorFactory("maxIndex", "index"),
new DoubleMinAggregatorFactory("minIndex", "index")
new TopNResultValue(
Arrays.<Map<String, Object>>asList(
ImmutableMap.<String, Object>builder()
.put("market", "spot")
.put("rows", 837L)
.put("minIndex", 59.02102279663086D)
.build(),
ImmutableMap.<String, Object>builder()
.put("market", "total_market")
.put("rows", 186L)
.put("minIndex", 792.3260498046875D)
.build(),
ImmutableMap.<String, Object>builder()
.put("market", "upfront")
.put("rows", 186L)
代码示例来源:origin: apache/incubator-druid
Sets.newHashSet("1200", "1400", "1600"),
true
);
.intervals(QueryRunnerTestHelper.fullOnIntervalSpec)
.aggregators(
Lists.newArrayList(
Iterables.concat(
commonAggregators,
Lists.newArrayList(
new DoubleMaxAggregatorFactory("maxIndex", "index"),
new DoubleMinAggregatorFactory("minIndex", "index")
new TopNResultValue(
Arrays.<Map<String, Object>>asList(
ImmutableMap.<String, Object>builder()
.put("ql_alias", 1400L)
.put(QueryRunnerTestHelper.indexMetric, 217725.41940800005D)
.put("minIndex", 91.270553D)
.build(),
ImmutableMap.<String, Object>builder()
.put("ql_alias", 1600L)
.put(QueryRunnerTestHelper.indexMetric, 210865.67977600006D)
代码示例来源:origin: fabric8io/docker-maven-plugin
/**
* Split each element of an Iterable<String> at commas.
* @param input Iterable over strings.
* @return An Iterable over string which breaks down each input element at comma boundaries
*/
@Nonnull
public static List<String> splitAtCommasAndTrim(Iterable<String> input) {
if(input==null) {
return Collections.emptyList();
}
Iterable<String> nonEmptyInputs = Iterables.filter(input, Predicates.notNull());
return Lists.newArrayList(Iterables.concat(Iterables.transform(nonEmptyInputs, COMMA_SPLITTER)));
}
代码示例来源:origin: prestodb/presto
@Test
public void testStringStrideDictionary()
throws Exception
{
tester.testRoundTrip(VARCHAR, newArrayList(concat(ImmutableList.of("a"), nCopies(9999, "123"), ImmutableList.of("b"), nCopies(9999, "123"))));
}
代码示例来源:origin: apache/incubator-gobblin
@Test
public void testUnion() throws IOException {
Properties props = new Properties();
props.setProperty(CombineRetentionPolicy.RETENTION_POLICIES_PREFIX + "1",
ContainsARetentionPolicy.class.getCanonicalName());
props.setProperty(CombineRetentionPolicy.RETENTION_POLICIES_PREFIX + "2",
ContainsBRetentionPolicy.class.getCanonicalName());
props.setProperty(CombineRetentionPolicy.RETENTION_POLICIES_PREFIX + "3",
ContainsCRetentionPolicy.class.getCanonicalName());
props.setProperty(CombineRetentionPolicy.DELETE_SETS_COMBINE_OPERATION,
CombineRetentionPolicy.DeletableCombineOperation.UNION.name());
CombineRetentionPolicy policy = new CombineRetentionPolicy(props);
Collection<DatasetVersion> deletableVersions = policy.listDeletableVersions(Lists
.<DatasetVersion>newArrayList(new StringDatasetVersion("a", new Path("/")),
new StringDatasetVersion("abc", new Path("/")), new StringDatasetVersion("abcd", new Path("/")),
new StringDatasetVersion("bc", new Path("/")), new StringDatasetVersion("d", new Path("/"))));
Set<String> actualDeletableVersions = Sets
.newHashSet(Iterables.transform(deletableVersions, new Function<DatasetVersion, String>() {
@Nullable @Override public String apply(DatasetVersion input) {
return ((StringDatasetVersion) input).getVersion();
}
}));
Assert.assertEquals(deletableVersions.size(), 4);
Assert.assertEquals(actualDeletableVersions, Sets.newHashSet("abcd", "abc", "a", "bc"));
}
代码示例来源:origin: apache/incubator-druid
final Set<String> workerNodeIds = Sets.newHashSet(
workerConfig.getAutoScaler().ipToIdLookup(
Lists.newArrayList(
Iterables.transform(
runner.getLazyWorkers(),
new Function<Worker, String>()
.terminate(ImmutableList.copyOf(laziestWorkerIps));
if (terminated != null) {
currentlyTerminating.addAll(terminated.getNodeIds());
代码示例来源:origin: apache/incubator-druid
.intervals(QueryRunnerTestHelper.fullOnIntervalSpec)
.aggregators(
Lists.newArrayList(
Iterables.concat(
commonAggregators,
Lists.newArrayList(
new DoubleMaxAggregatorFactory("maxIndex", "index"),
new DoubleMinAggregatorFactory("minIndex", "index")
ImmutableList.of(
new ExpressionPostAggregator(
"dimPostAgg",
new TopNResultValue(
Arrays.<Map<String, Object>>asList(
ImmutableMap.<String, Object>builder()
.put(QueryRunnerTestHelper.marketDimension, "upfront")
.put("dimPostAgg", "upfrontx")
.put("minIndex", 545.9906005859375D)
.build(),
ImmutableMap.<String, Object>builder()
.put(QueryRunnerTestHelper.marketDimension, "total_market")
.put("dimPostAgg", "total_marketx")
代码示例来源:origin: prestodb/presto
public static RecordReader<?, ?> createRecordReader(Configuration configuration, Path path, long start, long length, Properties schema, List<HiveColumnHandle> columns)
List<HiveColumnHandle> readColumns = ImmutableList.copyOf(filter(columns, column -> column.getColumnType() == REGULAR));
List<Integer> readHiveColumnIndexes = ImmutableList.copyOf(transform(readColumns, HiveColumnHandle::getHiveColumnIndex));
List<String> codecs = newArrayList(Splitter.on(",").trimResults().omitEmptyStrings().split(jobConf.get("io.compression.codecs", "")));
if (!codecs.contains(LzoCodec.class.getName())) {
codecs.add(0, LzoCodec.class.getName());
代码示例来源:origin: apache/incubator-druid
dims = config.getParser().getParseSpec().getDimensionsSpec().getDimensionNames();
} else {
Set<String> dimSet = Sets.newHashSet(
Iterables.concat(
Iterables.transform(
segments,
new Function<WindowedDataSegment, Iterable<String>>()
dims = Lists.newArrayList(
Sets.difference(
dimSet,
config.getParser()
updatedIngestionSpec = updatedIngestionSpec.withMetrics(Lists.newArrayList(metrics));
代码示例来源:origin: jenkinsci/jenkins
private ImmutableList<IndexItem<?, Object>> loadSezpozIndices(ClassLoader classLoader) {
List<IndexItem<?,Object>> indices = Lists.newArrayList();
for (GuiceExtensionAnnotation<?> gea : extensionAnnotations.values()) {
Iterables.addAll(indices, Index.load(gea.annotationType, Object.class, classLoader));
}
return ImmutableList.copyOf(indices);
}
代码示例来源:origin: com.google.inject/guice
Element element = Iterables.getOnlyElement(baseElements);
if (element instanceof PrivateElements) {
PrivateElements privateElements = (PrivateElements) element;
Elements.getElements(
currentStage(),
ImmutableList.<Module>builder().addAll(overrides).add(scannersModule).build());
final Set<Key<?>> overriddenKeys = Sets.newHashSet();
final Map<Class<? extends Annotation>, ScopeBinding> overridesScopeAnnotations =
Maps.newHashMap();
final List<ScopeBinding> scopeBindings = Lists.newArrayList();
new ModuleWriter(binder) {
@Override
代码示例来源:origin: googleapis/google-cloud-java
@Test
public void testListLogEntriesEmpty() {
String cursor = "cursor";
EasyMock.replay(rpcFactoryMock);
logging = options.getService();
ListLogEntriesRequest request =
ListLogEntriesRequest.newBuilder().addProjectIds(PROJECT).build();
List<LogEntry> entriesList = ImmutableList.of();
ListLogEntriesResponse response =
ListLogEntriesResponse.newBuilder()
.setNextPageToken(cursor)
.addAllEntries(Lists.transform(entriesList, LogEntry.toPbFunction(PROJECT)))
.build();
ApiFuture<ListLogEntriesResponse> futureResponse = ApiFutures.immediateFuture(response);
EasyMock.expect(loggingRpcMock.list(request)).andReturn(futureResponse);
EasyMock.replay(loggingRpcMock);
Page<LogEntry> page = logging.listLogEntries();
assertEquals(cursor, page.getNextPageToken());
assertArrayEquals(entriesList.toArray(), Iterables.toArray(page.getValues(), LogEntry.class));
}
代码示例来源:origin: gchq/Gaffer
public Builder entities(final Iterable<Entity> entities) {
if (Iterables.isEmpty(entities)) {
return this;
}
if (Iterables.size(entities) == 1) {
return entity(entities.iterator().next());
}
if (distinct(Streams.toStream(entities).map(EntityId::getVertex).collect(toList()))) {
throw new IllegalArgumentException("Entities must all have the same vertex.");
}
final Entity entity = entities.iterator().next();
if (!edges.isEmpty()) {
final Object root = edges.getLast().stream().findAny().orElseThrow(RuntimeException::new).getAdjacentMatchedVertexValue();
verifyEntity(root, entity);
}
if (!this.entities.isEmpty()) {
final Entry<Object, Set<Entity>> entry = this.entities.getLast();
final Object root = entry.getKey();
verifyEntity(root, entity);
final Set<Entity> currentEntities = entry.getValue();
currentEntities.addAll(Lists.newArrayList(entities));
entry.setValue(currentEntities);
} else {
this.entities.push(new AbstractMap.SimpleEntry<>(entity.getVertex(), Sets.newHashSet(entities)));
}
return this;
}
代码示例来源:origin: google/guava
public void testLimit() {
Iterable<String> iterable = newArrayList("foo", "bar", "baz");
Iterable<String> limited = Iterables.limit(iterable, 2);
List<String> expected = ImmutableList.of("foo", "bar");
List<String> actual = newArrayList(limited);
assertEquals(expected, actual);
assertCanIterateAgain(limited);
assertEquals("[foo, bar]", limited.toString());
}
代码示例来源:origin: apache/incubator-druid
private static Sequence<Result<SearchResultValue>> makeReturnResult(
Segment segment,
int limit,
Object2IntRBTreeMap<SearchHit> retVal
)
{
Iterable<SearchHit> source = Iterables.transform(
retVal.object2IntEntrySet(), new Function<Object2IntMap.Entry<SearchHit>, SearchHit>()
{
@Override
public SearchHit apply(Object2IntMap.Entry<SearchHit> input)
{
SearchHit hit = input.getKey();
return new SearchHit(hit.getDimension(), hit.getValue(), input.getIntValue());
}
}
);
return Sequences.simple(
ImmutableList.of(
new Result<>(
segment.getDataInterval().getStart(),
new SearchResultValue(
Lists.newArrayList(new FunctionalIterable<>(source).limit(limit))
)
)
)
);
}
}
内容来源于网络,如有侵权,请联系作者删除!