Example usage for java.util Collection add

List of usage examples for java.util Collection add

Introduction

In this page you can find the example usage for java.util Collection add.

Prototype

boolean add(E e);

Source Link

Document

Ensures that this collection contains the specified element (optional operation).

Usage

From source file:Main.java

private static void collectResults(Element element, String[] path, int index, Collection destination) {
    // If we matched all the way to the leaf of the path, add the element to the destination....
    String elemName = element.getNodeName();
    int lastColon = elemName.lastIndexOf(':');
    if (lastColon > 0) {
        elemName = elemName.substring(0, lastColon);
    }//w w  w . jav a2  s.c  o  m
    if (!elemName.equals(path[index]))
        return; // No match in this subtree

    if (index >= path.length - 1) {
        destination.add(element);
        return;
    }

    // OK, we have a match on the path so far, now check rest of the path (possibly none)
    Node child = element.getFirstChild();
    while (child != null) {
        if (child.getNodeType() == Node.ELEMENT_NODE) {
            // Recursive step, try t
            collectResults((Element) child, path, index + 1, destination);
        }
        child = child.getNextSibling();
    }
}

From source file:net.netheos.pcsapi.providers.StorageProviderFactory.java

/**
 * Instantiate provider storage for given name, and add it to values collection.
 *
 * A single application must exist for this provider in application repository. A single user must exist for this
 * application in user credentials repository.
 *
 * @param values destination (for unit test constructors)
 * @param providerName name of provider for which storage must be created.
 * @param optHttpClient if not null, client to use for the provider. If null default client is used.
 *///from  ww  w. j a  va  2  s. c o m
private static void addProvider(Collection<Object[]> values, String providerName, HttpClient optHttpClient) {
    StorageBuilder builder = StorageFacade.forProvider(providerName)
            .setAppInfoRepository(appRepo, appRepo.get(providerName).getAppName())
            .setUserCredentialsRepository(credRepo, null);

    if (optHttpClient != null) {
        builder.setHttpClient(optHttpClient);
    }

    values.add(new Object[] { builder.build() });
}

From source file:com.oltpbenchmark.util.CollectionUtil.java

/**
 * Add all the items in the Enumeration into a Collection
 * @param <T>//from   w w  w  .  ja  va  2 s  .  co m
 * @param data
 * @param items
 */
public static <T> Collection<T> addAll(Collection<T> data, Enumeration<T> items) {
    while (items.hasMoreElements()) {
        data.add(items.nextElement());
    } // WHILE
    return (data);
}

From source file:com.datascience.gal.scripts.MainClient.java

private static Collection<CorrectLabel> loadGoldLabels(String correctfile) {
    Collection<CorrectLabel> out = new HashSet<CorrectLabel>();
    String[] lines = Utils.getFile(correctfile).split("\n");
    for (String line : lines) {
        String[] parts = line.split("\t");
        if (parts.length < 2) {
            System.err.println("invalid correct label: " + line);
            continue;
        }/*from w  w w .  ja  v a 2 s  .  c  o  m*/
        out.add(new CorrectLabel(parts[0], parts[1]));
    }

    return out;
}

From source file:com.netflix.spinnaker.clouddriver.kubernetes.v2.caching.agent.KubernetesCacheDataConverter.java

static Map<String, Collection<String>> ownerReferenceRelationships(String account, String namespace,
        List<KubernetesManifest.OwnerReference> references) {
    Map<String, Collection<String>> relationships = new HashMap<>();
    references = references == null ? new ArrayList<>() : references;
    for (KubernetesManifest.OwnerReference reference : references) {
        KubernetesKind kind = reference.getKind();
        String name = reference.getName();
        Collection<String> keys = relationships.get(kind.toString());
        if (keys == null) {
            keys = new ArrayList<>();
        }//w  ww  .  ja va  2  s . com

        keys.add(Keys.infrastructure(kind, account, namespace, name));
        relationships.put(kind.toString(), keys);
    }

    return relationships;
}

From source file:com.wcs.base.util.CollectionUtils.java

/**
 * Merge the given array into the given Collection.
 * @param array the array to merge (may be <code>null</code>)
 * @param collection the target Collection to merge the array into
 *//*from w  ww  .  ja  va  2s  .c o  m*/
@SuppressWarnings("unchecked")
public static void mergeArrayIntoCollection(Object array, Collection collection) {
    if (collection == null) {
        throw new IllegalArgumentException("Collection must not be null");
    }
    Object[] arr = ObjectUtils.toObjectArray(array);
    for (Object elem : arr) {
        collection.add(elem);
    }
}

From source file:com.netflix.spinnaker.clouddriver.kubernetes.v2.caching.agent.KubernetesCacheDataConverter.java

static Map<String, Collection<String>> implicitRelationships(KubernetesManifest source, String account,
        List<KubernetesManifest> manifests) {
    String namespace = source.getNamespace();
    Map<String, Collection<String>> relationships = new HashMap<>();
    manifests = manifests == null ? new ArrayList<>() : manifests;
    logMalformedManifests(() -> "Determining implicit relationships for " + source + " in " + account,
            manifests);//from w  w  w  .  j  a  v a  2  s  .c om
    for (KubernetesManifest manifest : manifests) {
        KubernetesKind kind = manifest.getKind();
        String name = manifest.getName();
        Collection<String> keys = relationships.get(kind.toString());
        if (keys == null) {
            keys = new ArrayList<>();
        }

        keys.add(Keys.infrastructure(kind, account, namespace, name));
        relationships.put(kind.toString(), keys);
    }

    return relationships;
}

From source file:com.nuvolect.deepdive.util.OmniFileFilter.java

/**
 * Finds files within a given directory (and optionally its
 * subdirectories). All files found are filtered by an IOFileFilter.
 *
 * @param files                 the collection of files found.
 * @param directory             the directory to search in.
 * @param filter                the filter to apply to files and directories.
 * @param includeSubDirectories indicates if will include the subdirectories themselves
 *//*from   w w  w  .ja  v  a 2 s .  c  o m*/
private static void innerListFiles(final Collection<OmniFile> files, final OmniFile directory,
        final IOFileFilter filter, final boolean includeSubDirectories) {

    final OmniFile[] found = directory.listFiles((FileFilter) filter);

    if (found != null) {
        for (final OmniFile file : found) {
            if (file.isDirectory()) {
                if (includeSubDirectories) {
                    files.add(file);
                }
                innerListFiles(files, file, filter, includeSubDirectories);
            } else {
                files.add(file);
            }
        }
    }
}

From source file:com.amazonaws.services.kinesis.aggregators.StreamAggregatorUtils.java

/**
 * Get a list of all Open shards ordered by their start hash
 * /* w  w w.j  av a  2  s . com*/
 * @param streamName
 * @return A Map of only Open Shards indexed by the Shard ID
 */
public static Map<String, Shard> getOpenShards(AmazonKinesisClient kinesisClient, String streamName)
        throws Exception {
    Map<String, Shard> shardMap = new LinkedHashMap<>();
    final int BACKOFF_MILLIS = 10;
    final int MAX_DESCRIBE_ATTEMPTS = 10;
    int describeAttempts = 0;
    StreamDescription stream = null;
    try {
        do {
            try {
                stream = kinesisClient.describeStream(streamName).getStreamDescription();
            } catch (LimitExceededException e) {
                Thread.sleep(2 ^ describeAttempts * BACKOFF_MILLIS);
                describeAttempts++;
            }
        } while (stream == null && describeAttempts < MAX_DESCRIBE_ATTEMPTS);
    } catch (InterruptedException e) {
        LOG.error(e);
        throw e;
    }

    if (stream == null) {
        throw new Exception(
                String.format("Unable to describe Stream after %s attempts", MAX_DESCRIBE_ATTEMPTS));
    }
    Collection<String> openShardNames = new ArrayList<String>();

    // load all the shards on the stream
    for (Shard shard : stream.getShards()) {
        openShardNames.add(shard.getShardId());
        shardMap.put(shard.getShardId(), shard);

        // remove this shard's parents from the set of active shards -
        // we
        // can't do anything to them
        if (shard.getParentShardId() != null) {
            openShardNames.remove(shard.getParentShardId());
        }
        if (shard.getAdjacentParentShardId() != null) {
            openShardNames.remove(shard.getAdjacentParentShardId());
        }
    }

    // create a List of Open shards for sorting
    List<Shard> shards = new ArrayList<Shard>();
    for (String s : openShardNames) {
        shards.add(shardMap.get(s));
    }

    // sort the list into lowest start hash order
    Collections.sort(shards, new Comparator<Shard>() {
        public int compare(Shard o1, Shard o2) {
            return new BigInteger(o1.getHashKeyRange().getStartingHashKey())
                    .compareTo(new BigInteger(o2.getHashKeyRange().getStartingHashKey()));
        }
    });

    // rebuild the shard map into the correct order
    shardMap.clear();
    for (Shard s : shards) {
        shardMap.put(s.getShardId(), s);
    }

    return shardMap;

}

From source file:apm.common.utils.StringUtils.java

public static Collection<Long> getLongCollectionByString(String collectionType, String sourceString,
        String splitString) {// w w  w .j av a 2 s .c om
    Collection<Long> collection = null;
    if ("set".equalsIgnoreCase(collectionType)) {
        collection = new HashSet<Long>();
    } else if ("list".equals(collectionType)) {
        collection = new ArrayList<Long>();
    }
    for (String str : sourceString.split(splitString)) {
        collection.add(Long.valueOf(str));
    }
    return collection;
}