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:com.github.jinahya.io.bit.BitIoTests.java

static int valueIntUnsigned(final Collection<Integer> lengths) {

    final int length = lengthIntUnsigned();
    lengths.add(length);

    return valueIntUnsigned(length);
}

From source file:com.github.jinahya.io.bit.BitIoTests.java

static long valueLongUnsigned(final Collection<Integer> lengths) {

    final int length = lengthLongUnsigned();
    lengths.add(length);

    return valueLongUnsigned(length);
}

From source file:Main.java

@SuppressWarnings("unchecked")
public static <T> void addAll(Collection<T> dest, Collection<? super T> src, Class<? extends T> type) {
    if (dest == null || src == null || type == null) {
        throw new IllegalArgumentException("Arguments must not be null.");
    }//from w  w  w  .ja va  2  s. c o  m
    for (Object element : src) {
        if (element != null && type.isAssignableFrom(element.getClass())) {
            dest.add((T) element);
        }
    }
}

From source file:net.ostis.scpdev.editors.SequenceRule.java

public static void collectStartsParts(String[] words, Collection<Character> starts,
        Collection<Character> parts) {
    Assert.isNotNull(starts);/*from  w ww  . j  av a  2 s. c o m*/

    for (String word : words) {
        Assert.isTrue(StringUtils.isNotEmpty(word));

        if (starts != null)
            starts.add(word.charAt(0));

        if (parts != null)
            for (int i = 1; i < word.length(); i++)
                parts.add(word.charAt(i));
    }
}

From source file:Main.java

/**
 * Get all child elements with the provided name that are direct children
 * the provided element.//ww w . j av  a 2  s .co  m
 * 
 * @param parent
 *            The parent element
 * @param name
 *            The name of the child elements to find
 * @return The list with child elements, empty list if no matching children
 */
public static Collection<Element> getChildElementsByName(Element parent, String name) {
    assertNotNull(parent);
    Collection<Element> childList = new ArrayList<Element>();

    NodeList children = parent.getChildNodes();
    Node node;
    for (int i = 0; i < children.getLength(); i++) {
        node = children.item(i);
        if (node.getNodeType() == Node.ELEMENT_NODE && node.getNodeName().equals(name)) {
            childList.add((Element) node);
        }
    }

    return childList;
}

From source file:Main.java

/**
 * Get all child elements with the provided local name that are direct
 * children the provided element.//  www . ja  v a  2  s. c o m
 * 
 * @param parent
 *            The parent element
 * @param name
 *            The local name of the child elements to find
 * @return The list with child elements, empty list if no matching children
 */
public static Collection<Element> getChildElementsByLocalName(Element parent, String name) {
    assertNotNull(parent);
    Collection<Element> childList = new ArrayList<Element>();

    NodeList children = parent.getChildNodes();
    Node node;
    for (int i = 0; i < children.getLength(); i++) {
        node = children.item(i);
        if (node.getNodeType() == Node.ELEMENT_NODE && node.getLocalName().equals(name)) {
            childList.add((Element) node);
        }
    }

    return childList;
}

From source file:ch.systemsx.cisd.openbis.generic.shared.translator.ExternalDataTranslator.java

public static ExternalData translate(ExternalDataPE externalDataPE, String defaultDataStoreBaseURL,
        String baseIndexURL, boolean loadSampleProperties, final LoadableFields... withExperimentFields) {
    SamplePE sampleOrNull = externalDataPE.tryGetSample();
    ExperimentPE experiment = externalDataPE.getExperiment();
    ExternalData externalData = new ExternalData();
    externalData.setId(HibernateUtils.getId(externalDataPE));
    externalData.setCode(StringEscapeUtils.escapeHtml(externalDataPE.getCode()));
    externalData.setComplete(BooleanOrUnknown.tryToResolve(externalDataPE.getComplete()));
    externalData.setDataProducerCode(StringEscapeUtils.escapeHtml(externalDataPE.getDataProducerCode()));
    externalData.setDataSetType(DataSetTypeTranslator.translate(externalDataPE.getDataSetType(),
            new HashMap<PropertyTypePE, PropertyType>()));
    externalData.setDerived(externalDataPE.isDerived());
    externalData.setFileFormatType(TypeTranslator.translate(externalDataPE.getFileFormatType()));
    externalData.setInvalidation(tryToGetInvalidation(sampleOrNull, experiment));
    externalData.setLocation(StringEscapeUtils.escapeHtml(externalDataPE.getLocation()));
    externalData.setLocatorType(TypeTranslator.translate(externalDataPE.getLocatorType()));
    final Collection<ExternalData> parents = new HashSet<ExternalData>();
    externalData.setParents(parents);/*ww  w .j  a v a  2s . c o  m*/
    for (DataPE parentPE : externalDataPE.getParents()) {
        parents.add(fillExternalData(new ExternalData(), parentPE));
    }
    setChildren(externalDataPE, externalData);
    externalData.setProductionDate(externalDataPE.getProductionDate());
    externalData.setModificationDate(externalDataPE.getModificationDate());
    externalData.setRegistrationDate(externalDataPE.getRegistrationDate());
    externalData.setSample(
            sampleOrNull == null ? null : fillSample(new Sample(), sampleOrNull, loadSampleProperties));
    externalData.setDataStore(
            DataStoreTranslator.translate(externalDataPE.getDataStore(), defaultDataStoreBaseURL));
    externalData.setPermlink(PermlinkUtilities.createPermlinkURL(baseIndexURL, EntityKind.DATA_SET,
            externalData.getIdentifier()));
    setProperties(externalDataPE, externalData);
    externalData.setExperiment(ExperimentTranslator.translate(experiment, baseIndexURL, withExperimentFields));
    return externalData;
}

From source file:com.yodlee.sampleapps.helper.OpenSamlHelper.java

/**
 * THIS FUNCTION HAS NOT BEEN TEST.  DO NOT USE.
 * @return SAMLRequest object/* w  ww .  j  ava 2  s . c o m*/
 * @throws Exception
 */
public static SAMLRequest generateArtifactRequest(String artifactId) throws Exception {
    SAMLRequest request = null;
    ArrayList al = new ArrayList();
    al.add(artifactId);
    request = new SAMLRequest();

    Collection dsa_certs = new ArrayList();
    for (int i = 0; i < OpenSamlHelper.certs.length; i++)
        dsa_certs.add(OpenSamlHelper.certs[i]);
    request.sign(XMLSignature.ALGO_ID_SIGNATURE_RSA, OpenSamlHelper.privateKey, dsa_certs);

    request.toStream(System.out);
    return request;
}

From source file:com.haulmont.cuba.gui.data.impl.EntityCopyUtils.java

public static void copyCompositions(Entity source, Entity dest) {
    Preconditions.checkNotNullArgument(source, "source is null");
    Preconditions.checkNotNullArgument(dest, "dest is null");

    if (source instanceof BaseDbGeneratedIdEntity && dest instanceof BaseDbGeneratedIdEntity) {
        ((BaseDbGeneratedIdEntity) dest).setId(((BaseDbGeneratedIdEntity) source).getId());
    }//from ww w  .j av a2s  .c o m

    for (MetaProperty srcProperty : source.getMetaClass().getProperties()) {
        String name = srcProperty.getName();
        MetaProperty dstProperty = dest.getMetaClass().getProperty(name);
        if (dstProperty != null && !dstProperty.isReadOnly()) {
            try {
                Object value = source.getValue(name);

                if (value != null && srcProperty.getRange().getCardinality().isMany()
                        && srcProperty.getType() == MetaProperty.Type.COMPOSITION) {
                    //noinspection unchecked
                    Collection<Entity> srcCollection = (Collection) value;

                    // Copy first to a Set to remove duplicates that could be created on repeated editing newly
                    // added items
                    Collection<Entity> tmpCollection = new LinkedHashSet<>();
                    for (Entity item : srcCollection) {
                        Entity copy = copyCompositions(item);
                        tmpCollection.add(copy);
                    }

                    Collection<Entity> dstCollection;
                    if (value instanceof List)
                        dstCollection = new ArrayList<>(tmpCollection);
                    else
                        dstCollection = tmpCollection;
                    dest.setValue(name, dstCollection);

                } else {
                    dest.setValue(name, source.getValue(name));
                }
            } catch (RuntimeException e) {
                Throwable cause = ExceptionUtils.getRootCause(e);
                if (cause == null)
                    cause = e;
                // ignore exception on copy for not loaded fields
                if (!isNotLoadedAttributeException(cause))
                    throw e;
            }
        }
    }
    if (source instanceof BaseGenericIdEntity && dest instanceof BaseGenericIdEntity) {
        BaseGenericIdEntity destGenericEntity = (BaseGenericIdEntity) dest;
        BaseGenericIdEntity<?> sourceGenericEntity = (BaseGenericIdEntity<?>) source;

        BaseEntityInternalAccess.setDetached(destGenericEntity,
                BaseEntityInternalAccess.isDetached(sourceGenericEntity));
        BaseEntityInternalAccess.setNew(destGenericEntity, BaseEntityInternalAccess.isNew(sourceGenericEntity));
        destGenericEntity.setDynamicAttributes(sourceGenericEntity.getDynamicAttributes());
    }
}

From source file:com.opensymphony.xwork2.util.AnnotationUtils.java

/**
 * For the given <code>Class</code> get a collection of the the {@link AnnotatedElement}s 
 * that match the given <code>annotation</code>s or if no <code>annotation</code>s are 
 * specified then return all of the annotated elements of the given <code>Class</code>. 
 * Includes only the method level annotations.
 * /*from  w w w .  j a v a  2s  . c  o  m*/
 * @param clazz The {@link Class} to inspect
 * @param annotation the {@link Annotation}s to find
 * @return A {@link Collection}&lt;{@link AnnotatedElement}&gt; containing all of the
 *  method {@link AnnotatedElement}s matching the specified {@link Annotation}s
 */
public static Collection<Method> getAnnotatedMethods(Class clazz, Class<? extends Annotation>... annotation) {
    Collection<Method> toReturn = new HashSet<>();

    for (Method m : clazz.getMethods()) {
        if (ArrayUtils.isNotEmpty(annotation) && isAnnotatedBy(m, annotation)) {
            toReturn.add(m);
        } else if (ArrayUtils.isEmpty(annotation) && ArrayUtils.isNotEmpty(m.getAnnotations())) {
            toReturn.add(m);
        }
    }

    return toReturn;
}