Example usage for java.util List addAll

List of usage examples for java.util List addAll

Introduction

In this page you can find the example usage for java.util List addAll.

Prototype

boolean addAll(Collection<? extends E> c);

Source Link

Document

Appends all of the elements in the specified collection to the end of this list, in the order that they are returned by the specified collection's iterator (optional operation).

Usage

From source file:Main.java

/**
 * Recursive method used to find all classes in a given directory and subdirs.
 *
 * @param directory   The base directory
 * @param packageName The package name for classes found inside the base directory
 * @return The classes/*from  w  w  w .  j ava  2  s  .c o m*/
 * @throws ClassNotFoundException
 */
private static List findClasses(File directory, String packageName) throws ClassNotFoundException {
    List classes = new ArrayList();
    if (!directory.exists()) {
        return classes;
    }
    File[] files = directory.listFiles();
    for (File file : files) {
        if (file.isDirectory()) {
            assert !file.getName().contains(".");
            classes.addAll(findClasses(file, packageName + "." + file.getName()));
        } else if (file.getName().endsWith(".class") && !file.getName().contains("$")
                && !file.getName().endsWith("Test.class")) {
            classes.add(file.getName().substring(0, file.getName().length() - 6));
        }
    }
    return classes;
}

From source file:com.spotify.heroic.suggest.TagSuggest.java

public static Collector<TagSuggest, TagSuggest> reduce(final OptionalLimit limit) {
    return groups -> {
        final List<RequestError> errors1 = new ArrayList<>();
        final Map<Pair<String, String>, Float> suggestions1 = new HashMap<>();

        for (final TagSuggest g : groups) {
            errors1.addAll(g.errors);

            for (final Suggestion s : g.suggestions) {
                final Pair<String, String> key = Pair.of(s.getKey(), s.getValue());
                final Float old = suggestions1.put(key, s.getScore());

                // prefer higher score if available.
                if (old != null && s.score < old) {
                    suggestions1.put(key, old);
                }//from   w ww  .  j av a  2s.co  m
            }
        }

        final List<Suggestion> values = ImmutableList.copyOf(ImmutableSortedSet.copyOf(suggestions1.entrySet()
                .stream().map(e -> new Suggestion(e.getValue(), e.getKey().getLeft(), e.getKey().getRight()))
                .iterator()));

        return new TagSuggest(errors1, limit.limitList(values));
    };
}

From source file:megan.remote.client.RemoteServiceManager.java

public static void setupDefaultService() {
    final String remoteServices = ProgramProperties.get("RemoteServers", "");
    if (!remoteServices.contains(DEFAULT_MEGAN_SERVER)) {
        final String user = "guest";
        final String encodedPassword = Base64.encodeBase64String("guest".getBytes());

        if (remoteServices.length() == 0)
            ProgramProperties.put("RemoteServers", DEFAULT_MEGAN_SERVER);
        else// ww  w.  jav a 2 s.c  om
            ProgramProperties.put("RemoteServers", remoteServices + "%%%" + DEFAULT_MEGAN_SERVER);

        final List<String> credentials = new LinkedList<>();
        credentials.addAll(Arrays.asList(ProgramProperties.get("MeganServerCredentials", new String[0])));
        credentials.add(DEFAULT_MEGAN_SERVER + "::" + user + "::" + encodedPassword);
        ProgramProperties.put("MeganServerCredentials", credentials.toArray(new String[credentials.size()]));
    }
}

From source file:eu.annocultor.converters.europeana.RecordCompletenessRanking.java

/**
 * Utility function: extract words from field values.
 *//*w  w  w  .j  ava  2 s.  c  o m*/
static Collection<String> extractWordsFromFields(Collection<String> fields) {

    List<String> words = new ArrayList<String>();
    for (String field : fields) {
        if (!StringUtils.isEmpty(field)) {
            words.addAll(extractWordsFromField(field));
        }
    }
    return words;
}

From source file:eu.crisis_economics.configuration.CommaListExpression.java

private static List<ConfigurationExpression> initGuard(TypeDeclarationExpression typeExpression,
        List<ArgumentAssignmentExpression> assignmentExpressions) {
    if (assignmentExpressions == null || typeExpression == null)
        throw new NullArgumentException();
    List<ConfigurationExpression> result = new ArrayList<ConfigurationExpression>();
    result.add(typeExpression);/*from   w w w.  j a  v  a  2  s .  com*/
    result.addAll(assignmentExpressions);
    return result;
}

From source file:com.reactivetechnologies.platform.utils.EntityFinder.java

/**
 * Scans for JAX RS classes under given (comma delimited) packages
 * @param basePkg//w  w  w  .j  a v a 2 s .  c  o m
 * @return
 * @throws ClassNotFoundException
 * @throws IllegalAccessException
 */
public static List<Class<?>> findJaxRsClasses(String basePkg)
        throws ClassNotFoundException, IllegalAccessException {
    if (basePkg.contains(",")) {
        List<Class<?>> allPkgClasses = new ArrayList<>();
        String[] pkgs = basePkg.split(",");
        for (String pkg : pkgs) {
            allPkgClasses.addAll(findJaxRsClasses(pkg));
        }
        return allPkgClasses;
    }
    ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(
            false);
    provider.addIncludeFilter(new TypeFilter() {

        @Override
        public boolean match(MetadataReader metadataReader, MetadataReaderFactory metadataReaderFactory)
                throws IOException {
            AnnotationMetadata aMeta = metadataReader.getAnnotationMetadata();
            return aMeta.hasAnnotation(Path.class.getName()) || (aMeta.hasAnnotatedMethods(GET.class.getName())
                    || aMeta.hasAnnotatedMethods(POST.class.getName())
                    || aMeta.hasAnnotatedMethods(DELETE.class.getName())
                    || aMeta.hasAnnotatedMethods(Path.class.getName()));
        }
    });

    Set<BeanDefinition> beans = null;
    try {
        beans = provider.findCandidateComponents(StringUtils.hasText(basePkg) ? basePkg
                : EntityFinder.class.getName().substring(0, EntityFinder.class.getName().lastIndexOf(".")));
    } catch (Exception e) {
        throw new BeanInitializationException("Unable to scan for JAX-RS annotated classes under base package",
                e);
    }
    List<Class<?>> classes = new ArrayList<Class<?>>();
    if (beans != null && !beans.isEmpty()) {
        Class<?> restletClass;
        for (BeanDefinition bd : beans) {
            restletClass = Class.forName(bd.getBeanClassName());
            classes.add(restletClass);
        }
    } else {
        log.warn("** Did not find any JAX-RS annotated classes under the given base scan package [" + basePkg
                + "]. No REST requests will be served **");
    }
    return classes;

}

From source file:fi.aluesarjat.prototype.DataService.java

public static List<String> splitDatasetDef(String datasetDef) {
    int idx = datasetDef.indexOf(".px");
    if (idx > -1) {
        String path = datasetDef.substring(0, idx + 3);
        String[] rest = datasetDef.substring(idx + 3).trim().split("\\s+");
        List<String> elements = new ArrayList<String>(rest.length + 1);
        elements.add(path);/*from   w  w  w.  j  a va  2 s. co  m*/
        elements.addAll(Arrays.asList(rest));
        return elements;
    } else {
        return Collections.emptyList();
    }
}

From source file:com.zxy.commons.lang.utils.StringsUtils.java

/**
 * List??//from w w  w . j a v  a 2s.  c o  m
 * 
 * @param arrList ?
 * @return ????
 */
public static List<String> removeDuplicate(List<String> arrList) {
    if (arrList == null || arrList.isEmpty()) {
        return new ArrayList<String>();
    }
    LinkedHashSet<String> hSet = new LinkedHashSet<String>(arrList);
    List<String> tmp = new ArrayList<String>(hSet.size());
    tmp.addAll(hSet);
    return tmp;
}

From source file:de.ovgu.featureide.core.typecheck.helper.FujiWrapper.java

/**
 * Iterates a abstract syntax tree, searching for ASTNodes of the specific
 * type//from w  w  w  .j a  v a  2  s.  c  o  m
 * 
 * @param node
 *            the current node
 * @param type
 *            the node type to look for
 * @return a list of nodes of the given type
 */
@SuppressWarnings("rawtypes")
public static <T> List<T> getChildNodesByType(ASTNode node, Class<T> type) {
    List<T> list = new ArrayList<T>();
    for (int i = 0; i < node.getNumChild(); i++) {
        ASTNode c = node.getChild(i);
        if (type.isInstance(c)) {
            list.add(type.cast(c));
        }
        list.addAll(getChildNodesByType(c, type));
    }
    return list;
}

From source file:eu.h2020.symbiote.ontology.validation.ValidationHelper.java

public static List<String> checkCardinalityViolations(Resource instance, OntModel pim, Model instanceData) {
    List<String> result = new ArrayList<>();
    pim.addSubModel(instanceData);/*from   w  ww  .ja  v  a 2  s  .c  o  m*/
    result.addAll(ModelHelper
            .executeSelectAsList(pim, setResourceUri(QUERY_CARDINALITY_EXACTLY_DATA_PROPERTY, instance))
            .stream().map(x -> "exact cardinaility for data property violated - " + x)
            .collect(Collectors.toList()));
    result.addAll(ModelHelper
            .executeSelectAsList(pim, setResourceUri(QUERY_CARDINALITY_EXACTLY_OBJECT_PROPERTY, instance))
            .stream().map(x -> "exact cardinaility for object property violated - " + x)
            .collect(Collectors.toList()));
    result.addAll(ModelHelper
            .executeSelectAsList(pim, setResourceUri(QUERY_CARDINALITY_MIN_DATA_PROPERTY, instance)).stream()
            .map(x -> "min cardinaility for data property violated - " + x).collect(Collectors.toList()));
    result.addAll(ModelHelper
            .executeSelectAsList(pim, setResourceUri(QUERY_CARDINALITY_MIN_OBJECT_PROPERTY, instance)).stream()
            .map(x -> "min cardinaility for object property violated - " + x).collect(Collectors.toList()));
    result.addAll(ModelHelper
            .executeSelectAsList(pim, setResourceUri(QUERY_CARDINALITY_MAX_DATA_PROPERTY, instance)).stream()
            .map(x -> "max cardinaility for data property violated - " + x).collect(Collectors.toList()));
    result.addAll(ModelHelper
            .executeSelectAsList(pim, setResourceUri(QUERY_CARDINALITY_MAX_OBJECT_PROPERTY, instance)).stream()
            .map(x -> "max cardinaility for object property violated - " + x).collect(Collectors.toList()));
    pim.removeSubModel(instanceData);
    return result;
}