Java Code Examples for java.util.Collection.add()

The following are Jave code examples for showing how to use add() of the java.util.Collection class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: MMORPG_Prototype   File: SkeletonLootGenerator.java   View Source Code Vote up 6 votes
@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;
}
 
Example 2
Project: nifi-nars   File: StandardMongoClientService.java   View Source Code Vote up 6 votes
@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;
}
 
Example 3
Project: loom   File: SimpleStitcherSession.java   View Source Code Vote up 6 votes
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;
}
 
Example 4
Project: spring-data-ebean   File: StringQuery.java   View Source Code Vote up 6 votes
@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;
}
 
Example 5
Project: googles-monorepo-demo   File: DerivedGoogleCollectionGenerators.java   View Source Code Vote up 6 votes
@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();
}
 
Example 6
Project: cas-server-4.2.1   File: DefaultLdapRegisteredServiceMapper.java   View Source Code Vote up 6 votes
@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);
    }
}
 
Example 7
Project: Lagerta   File: ActiveCacheStore.java   View Source Code Vote up 5 votes
/** {@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);
}
 
Example 8
Project: WordnetLoom   File: PanelWorkbench.java   View Source Code Vote up 5 votes
/**
 * 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;
}
 
Example 9
Project: spring-cloud-docker-microservice-book-code   File: WebSecurityConfig.java   View Source Code Vote up 5 votes
@Override
public Collection<? extends GrantedAuthority> getAuthorities() {
  Collection<GrantedAuthority> authorities = new ArrayList<GrantedAuthority>();
  SimpleGrantedAuthority authority = new SimpleGrantedAuthority(this.role);
  authorities.add(authority);
  return authorities;
}
 
Example 10
Project: neoscada   File: UpdateTypeItemProvider.java   View Source Code Vote up 5 votes
/**
 * 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 () ) );
}
 
Example 11
Project: incubator-netbeans   File: TryCatchFinally.java   View Source Code Vote up 5 votes
@Override
public Void visitBreak(BreakTree node, Collection<TreePath> trees) {
    if (!analyzeThrows && !seenTrees.contains(info.getTreeUtilities().getBreakContinueTarget(getCurrentPath()))) {
        trees.add(getCurrentPath());
    }
    return null;
}
 
Example 12
Project: cactoos   File: Joined.java   View Source Code Vote up 5 votes
/**
 * 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);
    });
}
 
Example 13
Project: Lagerta   File: KafkaWritingEntryProcessor.java   View Source Code Vote up 5 votes
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;
}
 
Example 14
Project: gitplex-mit   File: NewRequestPage.java   View Source Code Vote up 5 votes
@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;
}
 
Example 15
Project: neoscada   File: XYContainerItemProvider.java   View Source Code Vote up 5 votes
/**
 * 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 () ) );
}
 
Example 16
Project: Reer   File: DefaultCacheAccess.java   View Source Code Vote up 5 votes
private void checkCompatibleValueSerializer(Collection<String> faultMessages, Serializer valueSerializer) {
    if (!Objects.equal(valueSerializer.getClass(), parameters.getValueSerializer().getClass())) {
        faultMessages.add(
            String.format(" * Requested value serializer type (%s) doesn't match current cache type (%s)",
                valueSerializer.getClass().getCanonicalName(),
                parameters.getValueSerializer().getClass().getCanonicalName()));
    }
}
 
Example 17
Project: fresco_floodlight   File: StaticFlowEntryPusher.java   View Source Code Vote up 5 votes
@Override
public Collection<Class<? extends IFloodlightService>> getModuleDependencies() {
	Collection<Class<? extends IFloodlightService>> l =
			new ArrayList<Class<? extends IFloodlightService>>();
	l.add(IFloodlightProviderService.class);
	l.add(IOFSwitchService.class);
	l.add(IStorageSourceService.class);
	l.add(IRestApiService.class);
	return l;
}
 
Example 18
Project: guava-mock   File: SetEqualsTester.java   View Source Code Vote up 5 votes
@CollectionSize.Require(absent = CollectionSize.ZERO)
@CollectionFeature.Require(ALLOWS_NULL_VALUES)
public void testEquals_containingNull() {
  Collection<E> elements = getSampleElements(getNumElements() - 1);
  elements.add(null);

  collection = getSubjectGenerator().create(elements.toArray());
  assertTrue(
      "A Set should equal any other Set containing the same elements,"
          + " even if some elements are null.",
      getSet().equals(MinimalSet.from(elements)));
}
 
Example 19
Project: alevin-svn2   File: GraphMLImporter.java   View Source Code Vote up 5 votes
public static void main(String[] args) throws ParserConfigurationException, SAXException, IOException {
	SubstrateNetworkFactory snetfactory = new SubstrateNetworkFactory(false);
	VirtualNetworkFactory vnetfactory = new VirtualNetworkFactory(false);
	
	boolean occupyWithoutMapping = false;
	
	Collection<VirtualNetwork> vNets = new LinkedList<VirtualNetwork>();
	vNets.add(doImport(vnetfactory, null, "/home/beck/v1.graphml", occupyWithoutMapping));
	
	SubstrateNetwork sNet = doImport(snetfactory, vNets, "/home/beck/sNet.graphml", occupyWithoutMapping);
	System.out.println(sNet);
}
 
Example 20
Project: OCCI-Studio   File: StorageItemProvider.java   View Source Code Vote up 4 votes
/**
 * 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
			(OCCIPackage.Literals.ENTITY__PARTS,
			 InfrastructureFactory.eINSTANCE.createIpnetwork()));

	newChildDescriptors.add
		(createChildParameter
			(OCCIPackage.Literals.ENTITY__PARTS,
			 InfrastructureFactory.eINSTANCE.createIpnetworkinterface()));

	newChildDescriptors.add
		(createChildParameter
			(OCCIPackage.Literals.ENTITY__PARTS,
			 InfrastructureFactory.eINSTANCE.createOs_tpl()));

	newChildDescriptors.add
		(createChildParameter
			(OCCIPackage.Literals.ENTITY__PARTS,
			 InfrastructureFactory.eINSTANCE.createResource_tpl()));

	newChildDescriptors.add
		(createChildParameter
			(OCCIPackage.Literals.ENTITY__PARTS,
			 InfrastructureFactory.eINSTANCE.createSsh_key()));

	newChildDescriptors.add
		(createChildParameter
			(OCCIPackage.Literals.ENTITY__PARTS,
			 InfrastructureFactory.eINSTANCE.createUser_data()));

	newChildDescriptors.add
		(createChildParameter
			(OCCIPackage.Literals.RESOURCE__LINKS,
			 InfrastructureFactory.eINSTANCE.createStoragelink()));

	newChildDescriptors.add
		(createChildParameter
			(OCCIPackage.Literals.RESOURCE__LINKS,
			 InfrastructureFactory.eINSTANCE.createNetworkinterface()));
}