本文整理汇总了Java中java.util.Collection.add方法的典型用法代码示例。如果您正苦于以下问题:Java Collection.add方法的具体用法?Java Collection.add怎么用?Java Collection.add使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.Collection
的用法示例。
在下文中一共展示了Collection.add方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getItemLootInfo
import java.util.Collection; //导入方法依赖的package包/类
@Override
public Collection<ItemLootInfo> getItemLootInfo()
{
Collection<ItemLootInfo> itemLoot = new LinkedList<>();
itemLoot.add(new ItemLootInfo.Builder()
.itemIdentifier(ItemIdentifiers.SMALL_HP_POTION)
.chancesOfDropping(0.5f)
.itemNumberRange(Range.between(1, 2))
.build());
itemLoot.add(new ItemLootInfo.Builder()
.itemIdentifier(ItemIdentifiers.SMALL_MP_POTION)
.chancesOfDropping(0.5f)
.itemNumberRange(Range.between(2, 3))
.build());
itemLoot.add(new ItemLootInfo.Builder()
.itemIdentifier(ItemIdentifiers.FISH)
.chancesOfDropping(1.0f)
.itemNumberRange(Range.between(2, 3))
.build());
return itemLoot;
}
示例2: customValidate
import java.util.Collection; //导入方法依赖的package包/类
@Override
protected Collection<ValidationResult> customValidate(final ValidationContext context) {
final Collection<ValidationResult> results = new ArrayList<>();
PropertyValue usernameProperty = context.getProperty(USERNAME);
PropertyValue passwordProperty = context.getProperty(PASSWORD);
PropertyValue authDatabaseProperty = context.getProperty(AUTH_DATABASE);
boolean valid = true;
if (usernameProperty.isSet() || passwordProperty.isSet() || authDatabaseProperty.isSet()) {
valid = usernameProperty.isSet() && passwordProperty.isSet() && authDatabaseProperty.isSet();
}
results.add(new ValidationResult.Builder()
.explanation("Using authentication requires Username, Password, and the Authentication Database")
.valid(valid)
.subject("Mongo Authentication")
.build());
return results;
}
示例3: removeItemsByTypeIdAndProviderId
import java.util.Collection; //导入方法依赖的package包/类
Collection<Item> removeItemsByTypeIdAndProviderId(final String typeId, final String providerId,
final Collection<Item> items) {
Map<String, Collection<Item>> itemsForTypeId = itemIndex.get(typeId);
if (itemsForTypeId == null) {
return Collections.emptyList(); // Immutable
}
Collection<Item> allItemsForProvider = itemsForTypeId.get(providerId);
if (allItemsForProvider == null) {
return Collections.emptyList(); // Immutable
}
Collection<Item> actuallyRemoved = new ArrayList<Item>(items.size());
for (Item item : items) {
if (allItemsForProvider.remove(item)) {
actuallyRemoved.add(item);
}
}
return actuallyRemoved;
}
示例4: prepare
import java.util.Collection; //导入方法依赖的package包/类
@Override
public Object prepare(Object value) {
if (!ObjectUtils.isArray(value)) {
return value;
}
int length = Array.getLength(value);
Collection<Object> result = new ArrayList<Object>(length);
for (int i = 0; i < length; i++) {
result.add(Array.get(value, i));
}
return result;
}
示例5: create
import java.util.Collection; //导入方法依赖的package包/类
@Override
public Set<V> create(Object... elements) {
@SuppressWarnings("unchecked")
V[] valuesArray = (V[]) elements;
// Start with a suitably shaped collection of entries
Collection<Map.Entry<K, V>> originalEntries = mapGenerator.getSampleElements(elements.length);
// Create a copy of that, with the desired value for each value
Collection<Map.Entry<K, V>> entries = new ArrayList<Entry<K, V>>(elements.length);
int i = 0;
for (Map.Entry<K, V> entry : originalEntries) {
entries.add(Helpers.mapEntry(entry.getKey(), valuesArray[i++]));
}
return mapGenerator.create(entries.toArray()).values();
}
示例6: mapFromRegisteredService
import java.util.Collection; //导入方法依赖的package包/类
@Override
public LdapEntry mapFromRegisteredService(final String dn, final RegisteredService svc) {
try {
if (svc.getId() == RegisteredService.INITIAL_IDENTIFIER_VALUE) {
((AbstractRegisteredService) svc).setId(System.nanoTime());
}
final String newDn = getDnForRegisteredService(dn, svc);
LOGGER.debug("Creating entry {}", newDn);
final Collection<LdapAttribute> attrs = new ArrayList<>();
attrs.add(new LdapAttribute(this.idAttribute, String.valueOf(svc.getId())));
final StringWriter writer = new StringWriter();
this.jsonSerializer.toJson(writer, svc);
attrs.add(new LdapAttribute(this.serviceDefinitionAttribute, writer.toString()));
attrs.add(new LdapAttribute(LdapUtils.OBJECTCLASS_ATTRIBUTE, "top", this.objectClass));
return new LdapEntry(newDn, attrs);
} catch (final Exception e) {
throw new RuntimeException(e);
}
}
示例7: deleteAll
import java.util.Collection; //导入方法依赖的package包/类
/** {@inheritDoc} */
@Override public void deleteAll(Collection<?> keys) throws CacheWriterException {
Collection<Cache.Entry<?, ?>> deletes = new ArrayList<>();
for (Object key : keys) {
deletes.add(new CacheEntryImpl<Object, Object>(key, TOMBSTONE));
}
putAll(deletes);
}
示例8: loadPlugins
import java.util.Collection; //导入方法依赖的package包/类
/**
* odczytanie pluginów z pliku konfiguracyjnego
*
* @param fileName - nazwa pliku konfiguracyjnego
* @return kolekcja pluginow
*/
private Collection<Plugin> loadPlugins(String fileName) {
Collection<Plugin> list = new ArrayList<>();
// odczytanie pliku z listą pluginów
try {
BufferedReader in = new BufferedReader(new InputStreamReader(PanelWorkbench.class.getClassLoader().getResourceAsStream(fileName)));
while (true) {
String line = in.readLine();
if (line == null) {
break;
}
if (line.startsWith("#")) {
continue;
}
// mamy nazwe klasy, trzeba ja utworzyć
try {
Class<?> pluginClass = Class.forName(line);
if (pluginClass != null) {
list.add((Plugin) pluginClass.newInstance());
}
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException e) {
logger().error("While loading class plugins:", e);
}
}
} catch (IOException ex) {
logger().error("While openning file:", ex);
}
return list;
}
示例9: getAuthorities
import java.util.Collection; //导入方法依赖的package包/类
@Override
public Collection<? extends GrantedAuthority> getAuthorities() {
Collection<GrantedAuthority> authorities = new ArrayList<GrantedAuthority>();
SimpleGrantedAuthority authority = new SimpleGrantedAuthority(this.role);
authorities.add(authority);
return authorities;
}
示例10: collectNewChildDescriptors
import java.util.Collection; //导入方法依赖的package包/类
/**
* This adds {@link org.eclipse.emf.edit.command.CommandParameter}s describing the children
* that can be created under this object.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
@Override
protected void collectNewChildDescriptors ( Collection<Object> newChildDescriptors, Object object )
{
super.collectNewChildDescriptors ( newChildDescriptors, object );
newChildDescriptors.add
( createChildParameter
( ConfigurationPackage.Literals.UPDATE_TYPE__MAPPING,
ConfigurationFactory.eINSTANCE.createUpdateMappingType () ) );
}
示例11: visitBreak
import java.util.Collection; //导入方法依赖的package包/类
@Override
public Void visitBreak(BreakTree node, Collection<TreePath> trees) {
if (!analyzeThrows && !seenTrees.contains(info.getTreeUtilities().getBreakContinueTarget(getCurrentPath()))) {
trees.add(getCurrentPath());
}
return null;
}
示例12: Joined
import java.util.Collection; //导入方法依赖的package包/类
/**
* Ctor.
* @param items Items to concatenate
*/
public Joined(final Iterable<Iterable<T>> items) {
super(() -> {
final Collection<Iterator<T>> iterators = new LinkedList<>();
for (final Iterable<T> item : items) {
iterators.add(item.iterator());
}
return () -> new org.cactoos.iterator.Joined<>(iterators);
});
}
示例13: txDataToCacheUpdates
import java.util.Collection; //导入方法依赖的package包/类
private static Collection<Cache.Entry<?, ?>> txDataToCacheUpdates(Map<?, ?> txDataEntries) {
Collection<Cache.Entry<?, ?>> updates = new ArrayList<>();
for (Object value : txDataEntries.values()) {
TransactionData txData = (TransactionData)value;
AccountTransactionKey txKey = new AccountTransactionKey(txData.getTransactionId(),
txData.getPartition());
AccountTransaction accountTx = new AccountTransaction(
txKey,
txData.getFromAccountId(),
txData.getToAccountId(),
txData.getMoneyAmount()
);
AccountKey toAccountKey = new AccountKey(txData.getToAccountId(), txData.getPartition());
AccountKey fromAccountKey = new AccountKey(txData.getFromAccountId(), txData.getPartition());
Account toAccount = new Account(toAccountKey);
Account fromAccount = new Account(fromAccountKey);
long timestamp = System.currentTimeMillis();
fromAccount.addTransaction(timestamp, txKey);
toAccount.addTransaction(timestamp, txKey);
updates.add(new CacheEntryImpl<>(txKey, accountTx));
updates.add(new CacheEntryImpl<>(toAccountKey, toAccount));
updates.add(new CacheEntryImpl<>(fromAccountKey, fromAccount));
}
return updates;
}
示例14: getWebSocketRegions
import java.util.Collection; //导入方法依赖的package包/类
@Override
public Collection<WebSocketRegion> getWebSocketRegions() {
Collection<WebSocketRegion> regions = super.getWebSocketRegions();
PullRequest request = getPullRequest();
if (request != null) {
regions.add(new CommitIndexedRegion(request.getBaseCommit()));
regions.add(new CommitIndexedRegion(request.getHeadCommit()));
}
return regions;
}
示例15: collectNewChildDescriptors
import java.util.Collection; //导入方法依赖的package包/类
/**
* This adds {@link org.eclipse.emf.edit.command.CommandParameter}s describing the children
* that can be created under this object.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
@Override
protected void collectNewChildDescriptors ( Collection<Object> newChildDescriptors, Object object )
{
super.collectNewChildDescriptors ( newChildDescriptors, object );
newChildDescriptors.add ( createChildParameter ( VisualInterfacePackage.Literals.XY_CONTAINER__CHILDREN, VisualInterfaceFactory.eINSTANCE.createXYChild () ) );
}