本文整理匯總了Java中com.google.common.collect.Lists類的典型用法代碼示例。如果您正苦於以下問題:Java Lists類的具體用法?Java Lists怎麽用?Java Lists使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
Lists類屬於com.google.common.collect包,在下文中一共展示了Lists類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: execute
import com.google.common.collect.Lists; //導入依賴的package包/類
@Override
protected void execute() {
ClusterService service = get(ClusterService.class);
MastershipService mastershipService = get(MastershipService.class);
List<ControllerNode> nodes = newArrayList(service.getNodes());
Collections.sort(nodes, Comparators.NODE_COMPARATOR);
if (outputJson()) {
print("%s", json(service, mastershipService, nodes));
} else {
for (ControllerNode node : nodes) {
List<DeviceId> ids = Lists.newArrayList(mastershipService.getDevicesOf(node.id()));
Collections.sort(ids, Comparators.ELEMENT_ID_COMPARATOR);
print("%s: %d devices", node.id(), ids.size());
for (DeviceId deviceId : ids) {
print(" %s", deviceId);
}
}
}
}
示例2: findKeysBefore
import com.google.common.collect.Lists; //導入依賴的package包/類
/** Returns a list of all ECKeys created after the given UNIX time. */
public List<ECKey> findKeysBefore(long timeSecs) {
lock.lock();
try {
List<ECKey> results = Lists.newLinkedList();
for (ECKey key : hashToKeys.values()) {
final long keyTime = key.getCreationTimeSeconds();
if (keyTime < timeSecs) {
results.add(key);
}
}
return results;
} finally {
lock.unlock();
}
}
示例3: testSelectOrderByNullsFirstAscNullsFirstDesc
import com.google.common.collect.Lists; //導入依賴的package包/類
/**
* Tests the select order by statement (with nulls last) against all {@linkplain SqlDialect}s
*
* @throws SQLException in case of error.
*/
@Test
public void testSelectOrderByNullsFirstAscNullsFirstDesc() throws SQLException {
SelectStatement selectOrderByNullsLastStat = select( field("field1"), field("field2")).from(tableRef("OrderByNullsLastTable")).orderBy(field("field1").nullsFirst(),field("field2").desc().nullsFirst());
String sql = convertStatementToSQL(selectOrderByNullsLastStat);
sqlScriptExecutorProvider.get().executeQuery(sql, new ResultSetProcessor<Void>() {
@Override
public Void process(ResultSet resultSet) throws SQLException {
List<String> expectedResultField1 = Lists.newArrayList(null,null,"1", "1","3","3");
List<String> expectedResultField2 = Lists.newArrayList(null,"3", null,"2","4","3");
int count = 0;
while (resultSet.next()) {
assertEquals("count:"+count,expectedResultField1.get(count), resultSet.getString(1));
assertEquals("count:"+count,expectedResultField2.get(count), resultSet.getString(2));
count++;
}
return null;
};
});
}
示例4: doEdits
import com.google.common.collect.Lists; //導入依賴的package包/類
@Override
public void doEdits(SectionInfo info)
{
final RoleSelectorWebControlModel model = getModel(info);
if( model.getSelectedRoles() != null )
{
final List<String> controlValues = storageControl.getValues();
controlValues.clear();
controlValues.addAll(Lists.transform(model.getSelectedRoles(), new Function<SelectedRole, String>()
{
@Override
public String apply(SelectedRole role)
{
return role.getUuid();
}
}));
}
}
示例5: evaluateCorrect
import com.google.common.collect.Lists; //導入依賴的package包/類
@Test
public void evaluateCorrect() {
// given
ExpressionBean bean = new ExpressionBean();
List<Response> responses = Lists.newArrayList(correctResponse(), correctResponse(), correctResponse(), correctResponse(), correctResponse());
bean.setTemplate("'0'+'2'+'3'='1'+'4'");
bean.getResponses().addAll(responses);
Multiset<Multiset<String>> correctAnswerMultiSet = HashMultiset.create(Lists.<Multiset<String>>newArrayList(
HashMultiset.create(Lists.newArrayList("answer_1", "answer_4")),
HashMultiset.create(Lists.newArrayList("answer_0", "answer_2", "answer_3")),
HashMultiset.create(Lists.newArrayList("answer_0", "answer_2", "answer_3", "answer_1", "answer_4"))));
bean.setCorectResponses(correctAnswerMultiSet);
// when
boolean result = testObj.evaluate(bean);
// then
assertThat(result, equalTo(true));
}
示例6: getPropCols
import com.google.common.collect.Lists; //導入依賴的package包/類
private List<String> getPropCols(String propertyString, boolean lowercase) {
if (StringUtils.isEmpty(propertyString)) {
logger.warn("Property is empty. property name:" + propertyString);
return null;
}
List<String> propList = Lists.newArrayList();
String[] propCols = propertyString.split(",");
for (int i = 0; i < propCols.length; i++) {
String prop = propCols[i].split("/")[0].trim();
if (lowercase) {
prop = prop.toLowerCase();
}
propList.add(prop);
}
return propList;
}
示例7: next_imageBonus_random
import com.google.common.collect.Lists; //導入依賴的package包/類
@Test
public void next_imageBonus_random() {
// given
final String asset1 = "bonus1";
final String asset2 = "bonus2.png";
final Size size = new Size(1, 2);
BonusResource bonusResource = createBonus(asset2, size, IMAGE);
ArrayList<BonusResource> bonuses = Lists.newArrayList(createBonus(asset1, size, SWIFFY), bonusResource);
BonusAction action = createMockAction(bonuses);
when(bonusConfig.getActions()).thenReturn(Lists.newArrayList(action));
when(randomWrapper.nextInt(2)).thenReturn(1);
BonusWithAsset expected = mock(BonusWithAsset.class);
when(bonusFactory.createBonus(eq(bonusResource))).thenReturn(expected);
// when
Bonus result = bonusProvider.next();
// then
verify(bonusFactory).createBonus(bonusResource);
assertThat(result).isEqualTo(expected);
}
示例8: token
import com.google.common.collect.Lists; //導入依賴的package包/類
@Override
public LinkedList<MynlpTerm> token(char[] text) {
// 處理為空的特殊情況
if (text.length == 0) {
return Lists.newLinkedList();
}
//構建一個空的Wordnet對象
final Wordnet wordnet = initEmptyWordNet(text);
wordnetInitializer.initialize(wordnet);
//選擇一個路徑出來(第一次不嚴謹的分詞結果)
Wordpath wordPath = bestPathComputer.select(wordnet);
for (WordpathProcessor xProcessor : wordPathProcessors) {
wordPath = xProcessor.process(wordPath);
}
return path2TermList(wordPath);
}
示例9: appendBatch
import com.google.common.collect.Lists; //導入依賴的package包/類
@Override
public Status appendBatch(List<ThriftFlumeEvent> events) throws TException {
sourceCounter.incrementAppendBatchReceivedCount();
sourceCounter.addToEventReceivedCount(events.size());
List<Event> flumeEvents = Lists.newArrayList();
for (ThriftFlumeEvent event : events) {
flumeEvents.add(EventBuilder.withBody(event.getBody(), event.getHeaders()));
}
try {
getChannelProcessor().processEventBatch(flumeEvents);
} catch (ChannelException ex) {
logger.warn("Thrift source %s could not append events to the channel.", getName());
return Status.FAILED;
}
sourceCounter.incrementAppendBatchAcceptedCount();
sourceCounter.addToEventAcceptedCount(events.size());
return Status.OK;
}
示例10: trigger
import com.google.common.collect.Lists; //導入依賴的package包/類
/**
* Trigger.
*
* @param player the player
*/
public void trigger(EntityPlayerMP player) {
List<ICriterionTrigger.Listener<CustomTrigger.Instance>> list = null;
for (ICriterionTrigger.Listener<CustomTrigger.Instance> listener : this.listeners) {
if (listener.getCriterionInstance().test()) {
if (list == null) {
list = Lists.newArrayList();
}
list.add(listener);
}
}
if (list != null) {
for (ICriterionTrigger.Listener listener1 : list) {
listener1.grantCriterion(this.playerAdvancements);
}
}
}
示例11: createNewStore
import com.google.common.collect.Lists; //導入依賴的package包/類
/**
* Create a new store for the given {@link org.creativecoinj.core.NetworkParameters}.
* @param params The network.
* @throws BlockStoreException If the store couldn't be created.
*/
private void createNewStore(NetworkParameters params) throws BlockStoreException {
try {
// Set up the genesis block. When we start out fresh, it is by
// definition the top of the chain.
StoredBlock storedGenesisHeader = new StoredBlock(params.getGenesisBlock().cloneAsHeader(), params.getGenesisBlock().getWork(), 0);
// The coinbase in the genesis block is not spendable. This is because of how Bitcoin Core inits
// its database - the genesis transaction isn't actually in the db so its spent flags can never be updated.
List<Transaction> genesisTransactions = Lists.newLinkedList();
StoredUndoableBlock storedGenesis = new StoredUndoableBlock(params.getGenesisBlock().getHash(), genesisTransactions);
put(storedGenesisHeader, storedGenesis);
setChainHead(storedGenesisHeader);
setVerifiedChainHead(storedGenesisHeader);
} catch (VerificationException e) {
throw new RuntimeException(e); // Cannot happen.
}
}
示例12: testFindLatestActiveReleaseWithReleaseNotFound
import com.google.common.collect.Lists; //導入依賴的package包/類
@Test
public void testFindLatestActiveReleaseWithReleaseNotFound() throws Exception {
when(releaseMessageService.findLatestReleaseMessageForMessages(Lists.newArrayList(someKey))).thenReturn(null);
when(releaseService.findLatestActiveRelease(someAppId, someClusterName, someNamespaceName)).thenReturn(null);
Release release = configServiceWithCache.findLatestActiveRelease(someAppId, someClusterName, someNamespaceName,
someNotificationMessages);
Release anotherRelease = configServiceWithCache.findLatestActiveRelease(someAppId, someClusterName,
someNamespaceName, someNotificationMessages);
int retryTimes = 100;
for (int i = 0; i < retryTimes; i++) {
configServiceWithCache.findLatestActiveRelease(someAppId, someClusterName,
someNamespaceName, someNotificationMessages);
}
assertNull(release);
assertNull(anotherRelease);
verify(releaseMessageService, times(1)).findLatestReleaseMessageForMessages(Lists.newArrayList(someKey));
verify(releaseService, times(1)).findLatestActiveRelease(someAppId, someClusterName, someNamespaceName);
}
示例13: getIdFields
import com.google.common.collect.Lists; //導入依賴的package包/類
private List<Map<String, Object>> getIdFields(RecordSchema schema) {
List<Map<String, Object>> list = Lists.newArrayList();
for (Field f : schema.getFields()) {
if (f.isRemoved()) {
continue;
}
boolean isIdField = SchemaNameUtils.isIdSchema(schema.getName()) || f.isIdField();
if (!isIdField) {
continue;
}
Map<String, Object> fm = Maps.newHashMap();
fm.put("name", f.getName());
fm.put("isIdField", isIdField);
list.add(fm);
}
return list;
}
示例14: parseFile
import com.google.common.collect.Lists; //導入依賴的package包/類
private List<Include> parseFile(File file) {
List<Include> includes = Lists.newArrayList();
try {
BufferedReader bf = new BufferedReader(new PreprocessingReader(new BufferedReader(new FileReader(file))));
try {
String line;
while ((line = bf.readLine()) != null) {
Matcher m = includePattern.matcher(line.trim());
if (m.matches()) {
boolean isImport = "import".equals(m.group(1));
String value = m.group(2);
includes.add(DefaultInclude.parse(value, isImport));
}
}
} finally {
IOUtils.closeQuietly(bf);
}
} catch (IOException e) {
throw new UncheckedIOException(e);
}
return includes;
}
示例15: assertResponsesMapped
import com.google.common.collect.Lists; //導入依賴的package包/類
private void assertResponsesMapped(int responsesExpected, CompletableFuture<SmtpClientResponse> future) throws Exception {
List<SmtpResponse> responses = Lists.newArrayList();
for (int i = 0; i < responsesExpected; i++) {
responses.add(new DefaultSmtpResponse(250 + i, "OK " + i));
}
responseFuture.complete(responses);
verify(responseHandler).createResponseFuture(eq(responsesExpected), any());
assertThat(future.isDone()).isTrue();
assertThat(future.get().getResponses().size()).isEqualTo(responses.size());
for (int i = 0; i < responsesExpected; i++) {
assertThat(future.get().getSession()).isEqualTo(session);
assertThat(future.get().getResponses().get(i).code()).isEqualTo(responses.get(i).code());
assertThat(future.get().getResponses().get(i).details()).isEqualTo(responses.get(i).details());
}
}