Example usage for java.util Set addAll

List of usage examples for java.util Set addAll

Introduction

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

Prototype

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

Source Link

Document

Adds all of the elements in the specified collection to this set if they're not already present (optional operation).

Usage

From source file:com.baidu.rigel.biplatform.tesseract.util.QueryRequestUtil.java

/**
 * /*from  w  w w  .jav  a2 s .c om*/
 * transQueryRequest2SqlQuery queryRequest->sqlQuery
 * 
 * @param query
 *            query
 * @return SqlQuery SqlQuery
 */
public static SqlQuery transQueryRequest2SqlQuery(QueryRequest query) {
    if (query == null || query.getWhere() == null) {
        throw new IllegalArgumentException();
    }

    SqlQuery result = new SqlQuery();
    // ?from
    if (query.getGroupBy() != null) {
        result.setGroupBy(query.getGroupBy().getGroups());
    }

    LinkedList<String> fromList = new LinkedList<String>();
    fromList.add(query.getFrom().getFrom());
    result.setFromList(fromList);
    // ?limit
    if (query.getLimit() != null) {
        result.setLimitMap(query.getLimit().getStart(), query.getLimit().getSize());
    }

    // ?select
    // getQueryProperties
    Set<String> selectList = Sets.newLinkedHashSet();
    if (query.getSelect() != null) {
        selectList.addAll(query.getSelect().getQueryProperties());
        if (CollectionUtils.isNotEmpty(query.getSelect().getQueryMeasures())) {
            for (QueryMeasure qm : query.getSelect().getQueryMeasures()) {
                selectList.add(qm.getProperties());
            }
        }
    }

    // ?where
    Map<String, List<String>> andCondition = transQueryRequestAndList2Map(query);
    List<String> whereList = new ArrayList<String>();
    for (String key : andCondition.keySet()) {
        selectList.add(key);
        StringBuilder sb = new StringBuilder();
        sb.append(key);
        sb.append(" in (");
        sb.append(StringUtils.join(transValue2SqlString(andCondition.get(key)), ","));
        sb.append(")");
        whereList.add(sb.toString());
    }
    result.setWhereList(whereList);
    result.getSelectList().addAll(selectList);
    return result;
}

From source file:delfos.dataset.util.DatasetPrinter.java

public static String printCompactRatingTable(Map<Integer, Map<Integer, Number>> ratings) {
    Set<Integer> users = new TreeSet<>(ratings.keySet());
    Set<Integer> items = new TreeSet<>();

    Map<Integer, Map<Integer, Rating>> ratings_r = new TreeMap<>();
    for (int idUser : ratings.keySet()) {
        items.addAll(ratings.get(idUser).keySet());
        ratings_r.put(idUser, new TreeMap<>());
        for (Map.Entry<Integer, Number> entry : ratings.get(idUser).entrySet()) {
            int idItem = entry.getKey();
            Number ratingValue = entry.getValue();
            ratings_r.get(idUser).put(idItem, new Rating(idUser, idItem, ratingValue));
        }//w  w w  . j  av a 2  s  .  c  o m

    }

    return printCompactRatingTable(new BothIndexRatingsDataset<>(ratings_r), new ArrayList<>(users),
            new ArrayList<>(items));
}

From source file:com.mirth.connect.client.core.api.util.OperationUtil.java

public static String[] getOperationNamesForPermission(String permissionName, Class<?> servletInterface,
        String... extraOperationNames) {
    Set<String> operationNames = new HashSet<String>();

    for (Class<?> coreServletInterface : new Reflections("com.mirth.connect.client.core.api.servlets")
            .getSubTypesOf(BaseServletInterface.class)) {
        addOperationName(permissionName, coreServletInterface, operationNames);
    }/*  w w w  . ja  v  a2  s .c o m*/

    if (servletInterface != null) {
        addOperationName(permissionName, servletInterface, operationNames);
    }

    if (ArrayUtils.isNotEmpty(extraOperationNames)) {
        operationNames.addAll(Arrays.asList(extraOperationNames));
    }

    return operationNames.toArray(new String[operationNames.size()]);
}

From source file:gov.nih.nci.caarray.dao.SampleDaoImpl.java

private static String generateJoinClause(boolean count,
        JoinableSortCriterion<? extends AbstractBioMaterial> sortCrit, Set<String> joins) {
    String[] orderByJoins = null;

    if (!count && sortCrit != null) {
        orderByJoins = sortCrit.getJoins();
    }//w  ww  .  j  av a 2 s  . c o  m

    Set<String> completeJoinsList = new LinkedHashSet<String>();
    completeJoinsList.addAll(joins);

    if (orderByJoins != null) {
        completeJoinsList.addAll(Arrays.asList(orderByJoins));
    }

    StringBuffer sb = new StringBuffer();
    for (String joinTable : completeJoinsList) {
        sb.append(LEFT_JOIN).append(joinTable.replace("this", "s"));
    }

    return sb.toString();

}

From source file:com.nesscomputing.service.discovery.announce.GalaxyAnnouncer.java

public static final Set<ServiceInformation> buildServices(final AnnouncementConfig announcementConfig,
        final GalaxyHttpServerConfig httpServerConfig, final GalaxyConfig galaxyConfig) {
    final Set<ServiceInformation> services = Sets.newHashSet();

    final String serviceName = announcementConfig.getServiceName();
    if (StringUtils.isBlank(serviceName)) {
        LOG.warn("No service name given, not announcing anything. This is not what you want!");
    } else {// ww w . ja  va 2 s . c  o m
        final String serviceType = announcementConfig.getServiceType();

        if (announcementConfig.isAnnounceInternal()) {
            LOG.debug("Internal services are announced");
            services.addAll(buildInternalServices(serviceName, serviceType, httpServerConfig, galaxyConfig));
        }
        if (announcementConfig.isAnnounceExternal()) {
            LOG.debug("External services are announced");
            services.addAll(buildExternalServices(serviceName, serviceType, httpServerConfig, galaxyConfig));
        }
    }

    LOG.debug("Total number of announcements: %d", services.size());
    return services;
}

From source file:com.evolveum.midpoint.util.MiscUtil.java

public static <T> Collection<T> union(Collection<T>... sets) {
    Set<T> resultSet = new HashSet<T>();
    for (Collection<T> set : sets) {
        if (set != null) {
            resultSet.addAll(set);
        }/* w  ww . j  av a  2 s  .  c  om*/
    }
    return resultSet;
}

From source file:com.github.gekoh.yagen.util.MappingUtils.java

public static Set<Field> getManyToManyRelations(EntityManagerFactory emf) throws Exception {
    Set<Field> manyToManyFiels = new HashSet<Field>();

    for (Class aClass : getEntityClasses(emf)) {
        manyToManyFiels.addAll(getFielsWith(ManyToMany.class, aClass));
    }//www. j  av  a  2  s  . co m

    return manyToManyFiels;
}

From source file:de.bund.bfr.knime.pmmlite.core.PmmUtils.java

public static List<Variable> getIndependentVariables(ModelFormula formula) {
    Set<Variable> variables = new LinkedHashSet<>();

    if (formula instanceof PrimaryModelFormula && ((PrimaryModelFormula) formula).getIndepVar() != null) {
        variables.add(((PrimaryModelFormula) formula).getIndepVar());
    } else if (formula instanceof SecondaryModelFormula) {
        variables.addAll(((SecondaryModelFormula) formula).getIndepVars());
    } else if (formula instanceof TertiaryModelFormula) {
        variables.addAll(((TertiaryModelFormula) formula).getIndepVars());
    }//from   w  w  w.ja v  a2 s . c o m

    return new ArrayList<>(variables);
}

From source file:com.alibaba.jstorm.ui.UIUtils.java

public static Set<String> getKeys(Collection<MetricInfo> metrics) {
    Set<String> ret = new TreeSet<String>();
    for (MetricInfo metric : metrics) {
        Set<String> oneKeys = metric.get_baseMetric().keySet();
        ret.addAll(oneKeys);
    }//from ww  w  .  jav a  2s. c om

    return ret;
}

From source file:com.wavemaker.json.JSONMarshaller.java

/**
 * Recursively write out maps and objects.
 * //from  ww w.j  av  a 2  s  .c  o m
 * @param writer
 * @throws IOException
 */
private static void handleObject(Object obj, Object root, JSONState js, Writer writer,
        Stack<Object> touchedObjects, Stack<String> propertyNames, boolean sort,
        FieldDefinition fieldDefinition, int arrayLevel, TypeState typeState, boolean prettyPrint, int level,
        Logger logger) throws IOException {

    if (fieldDefinition == null) {
        throw new NullArgumentException("fieldDefinition");
    }

    writer.write('{');
    boolean firstProperty = true;

    if (obj instanceof Map || fieldDefinition.getTypeDefinition() instanceof MapTypeDefinition) {
        Set<Entry<?, ?>> entries = null;
        if (sort) {
            Set<Entry<?, ?>> entriesTemp = new TreeSet<Entry<?, ?>>(new EntryComparator());
            entriesTemp.addAll(((Map<?, ?>) obj).entrySet());
            entries = entriesTemp;
        }

        for (Entry<?, ?> entry : entries == null ? ((Map<?, ?>) obj).entrySet() : entries) {
            String key = (String) entry.getKey();

            if (fieldDefinition.getTypeDefinition() != null
                    && fieldDefinition.getTypeDefinition() instanceof MapTypeDefinition) {
                fieldDefinition = ((MapTypeDefinition) fieldDefinition.getTypeDefinition())
                        .getValueFieldDefinition();
            } else {
                fieldDefinition = new GenericFieldDefinition();
            }

            firstProperty = handleObjectInternal(obj, root, key, entry.getValue(), firstProperty, js, writer,
                    touchedObjects, propertyNames, sort, fieldDefinition, arrayLevel, typeState, prettyPrint,
                    level + 1, logger);
        }

    } else if (fieldDefinition.getTypeDefinition() instanceof ObjectTypeDefinition) {
        ObjectReflectTypeDefinition otd = (ObjectReflectTypeDefinition) fieldDefinition.getTypeDefinition();
        if (otd.getKlass().isAssignableFrom(obj.getClass())) {
            for (Entry<String, FieldDefinition> entry : otd.getFields().entrySet()) {
                String name = entry.getKey();
                fieldDefinition = entry.getValue();

                Object value;
                try {
                    value = PropertyUtils.getProperty(obj, name);
                } catch (IllegalArgumentException e) {
                    throw new WMRuntimeException(MessageResource.ERROR_GETTING_PROPERTY, e, name, obj,
                            obj.getClass().getName());
                } catch (IllegalAccessException e) {
                    throw new WMRuntimeException(MessageResource.ERROR_GETTING_PROPERTY, e, name, obj,
                            obj.getClass().getName());
                } catch (InvocationTargetException e) {
                    throw new WMRuntimeException(MessageResource.ERROR_GETTING_PROPERTY, e, name, obj,
                            obj.getClass().getName());
                } catch (NoSuchMethodException e) {
                    logger.warn(MessageResource.JSON_NO_GETTER_IN_TYPE.getMessage(name, obj,
                            obj.getClass().getName()));
                    continue;
                }

                firstProperty = handleObjectInternal(obj, root, name, value, firstProperty, js, writer,
                        touchedObjects, propertyNames, sort, fieldDefinition, 0, typeState, prettyPrint,
                        level + 1, logger);
            }
        }
    } else {
        throw new WMRuntimeException(MessageResource.JSON_BAD_HANDLE_TYPE, fieldDefinition.getTypeDefinition());
    }

    if (prettyPrint) {
        writer.write("\n");
        writeIndents(writer, level);
    }
    writer.write('}');
}