Example usage for java.util ArrayList addAll

List of usage examples for java.util ArrayList addAll

Introduction

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

Prototype

public 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.

Usage

From source file:org.opendatakit.common.android.data.ColumnDefinition.java

/**
 * This must match the code in the javascript layer
 * //  ww w  . java2 s  .c om
 * See databaseUtils.markUnitOfRetention
 * 
 * Sweeps through the collection of ColumnDefinition objects and marks the
 * ones that exist in the actual database table.
 * 
 * @param defn
 */
private static void markUnitOfRetention(Map<String, ColumnDefinition> defn) {
    // for all arrays, mark all descendants of the array as not-retained
    // because they are all folded up into the json representation of the array
    for (String startKey : defn.keySet()) {
        ColumnDefinition colDefn = defn.get(startKey);
        if (!colDefn.isUnitOfRetention()) {
            // this has already been processed
            continue;
        }
        if (ElementDataType.array.name().equals(colDefn.getElementType())) {
            ArrayList<ColumnDefinition> descendantsOfArray = new ArrayList<ColumnDefinition>(
                    colDefn.getChildren());
            ArrayList<ColumnDefinition> scratchArray = new ArrayList<ColumnDefinition>();
            while (!descendantsOfArray.isEmpty()) {
                for (ColumnDefinition subDefn : descendantsOfArray) {
                    if (!subDefn.isUnitOfRetention()) {
                        // this has already been processed
                        continue;
                    }
                    subDefn.setNotUnitOfRetention();
                    scratchArray.addAll(subDefn.getChildren());
                }
                descendantsOfArray = scratchArray;
            }
        }
    }
    // and mark any non-arrays with multiple fields as not retained
    for (String startKey : defn.keySet()) {
        ColumnDefinition colDefn = defn.get(startKey);
        if (!colDefn.isUnitOfRetention()) {
            // this has already been processed
            continue;
        }
        if (!ElementDataType.array.name().equals(colDefn.getElementType())) {
            if (!colDefn.getChildren().isEmpty()) {
                colDefn.setNotUnitOfRetention();
            }
        }
    }
}

From source file:com.clustercontrol.jobmanagement.util.JobUtil.java

/**
 * ???????/*from w w w  . ja v  a2  s.  co  m*/
 * @param item
 * @param list
 * @return
 */
public static ArrayList<JobInfo> findReferJobNet(JobTreeItem item) {
    ArrayList<JobInfo> ret = new ArrayList<JobInfo>();
    if (item == null || item.getData() == null) {
        return ret;
    }
    //ID?
    m_log.trace("checkReferJobNet Id=" + item.getData().getId());
    JobInfo jobInfo = item.getData();
    if (jobInfo.getType() == JobConstant.TYPE_REFERJOBNET) {
        if (jobInfo.getReferJobUnitId() != null && jobInfo.getReferJobId() != null) {
            ret.add(item.getData());
            m_log.trace("JobId =" + jobInfo.getId() + ", UnitId =" + jobInfo.getReferJobUnitId()
                    + ", referJobId =" + jobInfo.getReferJobId());
        }
    }
    //?JobTreeItem?
    for (JobTreeItem child : item.getChildren()) {
        ret.addAll(findReferJobNet(child));
    }
    return ret;
}

From source file:de.mpg.mpdl.inge.transformation.Util.java

/**
 * Queries the CoNE service and transforms the result into a DOM node.
 * /*  w  w  w .  ja  va 2  s . co m*/
 * @param model The type of object (e.g. "persons")
 * @param name The query string.
 * @param ou Specialty for persons
 * @param coneSession A JSESSIONID to not produce a new session with each call.
 * @return A DOM node containing the results.
 */
public static Node queryConeExact(String model, String name, String ou) {
    DocumentBuilder documentBuilder;

    try {
        logger.info("queryConeExact: " + model + " name: " + name + " ou: " + ou);

        documentBuilder = DocumentBuilderFactoryImpl.newInstance().newDocumentBuilder();

        Document document = documentBuilder.newDocument();
        Element element = document.createElement("cone");
        document.appendChild(element);

        String queryUrl = PropertyReader.getProperty("escidoc.cone.service.url") + model
                + "/query?format=jquery&" + URLEncoder.encode("dc:title", "UTF-8") + "="
                + URLEncoder.encode("\"" + name + "\"", "UTF-8") + "&"
                + URLEncoder.encode("escidoc:position/eprints:affiliatedInstitution", "UTF-8") + "="
                + URLEncoder.encode("\"*" + ou + "*\"", "UTF-8");
        String detailsUrl = PropertyReader.getProperty("escidoc.cone.service.url") + model
                + "/resource/$1?format=rdf";
        HttpClient client = new HttpClient();
        client.getParams().setParameter(HttpClientParams.ALLOW_CIRCULAR_REDIRECTS, true);
        GetMethod method = new GetMethod(queryUrl);

        String coneSession = getConeSession();

        if (coneSession != null) {
            method.setRequestHeader("Cookie", "JSESSIONID=" + coneSession);
        }
        ProxyHelper.executeMethod(client, method);
        logger.info("CoNE query: " + queryUrl + " returned " + method.getResponseBodyAsString());
        if (method.getStatusCode() == 200) {
            ArrayList<String> results = new ArrayList<String>();
            results.addAll(Arrays.asList(method.getResponseBodyAsString().split("\n")));
            queryUrl = PropertyReader.getProperty("escidoc.cone.service.url") + model + "/query?format=jquery&"
                    + URLEncoder.encode("dcterms:alternative", "UTF-8") + "="
                    + URLEncoder.encode("\"" + name + "\"", "UTF-8") + "&"
                    + URLEncoder.encode("escidoc:position/eprints:affiliatedInstitution", "UTF-8") + "="
                    + URLEncoder.encode("\"*" + ou + "*\"", "UTF-8");
            client = new HttpClient();
            method = new GetMethod(queryUrl);
            if (coneSession != null) {
                method.setRequestHeader("Cookie", "JSESSIONID=" + coneSession);
            }
            ProxyHelper.executeMethod(client, method);
            logger.info("CoNE query: " + queryUrl + " returned " + method.getResponseBodyAsString());
            if (method.getStatusCode() == 200) {
                results.addAll(Arrays.asList(method.getResponseBodyAsString().split("\n")));
                Set<String> oldIds = new HashSet<String>();
                for (String result : results) {
                    if (!"".equals(result.trim())) {
                        String id = result.split("\\|")[1];
                        if (!oldIds.contains(id)) {
                            // TODO "&redirect=true" must be reinserted again
                            GetMethod detailMethod = new GetMethod(id + "?format=rdf&eSciDocUserHandle="
                                    + Base64.encode(AdminHelper.getAdminUserHandle().getBytes("UTF-8")));
                            detailMethod.setFollowRedirects(true);

                            ProxyHelper.setProxy(client, detailsUrl.replace("$1", id));
                            client.executeMethod(detailMethod);
                            // TODO "&redirect=true" must be reinserted again
                            logger.info("CoNE query: " + id + "?format=rdf&eSciDocUserHandle="
                                    + Base64.encode(AdminHelper.getAdminUserHandle().getBytes("UTF-8"))
                                    + " returned " + detailMethod.getResponseBodyAsString());
                            if (detailMethod.getStatusCode() == 200) {
                                Document details = documentBuilder
                                        .parse(detailMethod.getResponseBodyAsStream());
                                element.appendChild(document.importNode(details.getFirstChild(), true));
                            } else {
                                logger.error("Error querying CoNE: Status " + detailMethod.getStatusCode()
                                        + "\n" + detailMethod.getResponseBodyAsString());
                            }
                            oldIds.add(id);
                        }
                    }
                }
            }
        } else {
            logger.error("Error querying CoNE: Status " + method.getStatusCode() + "\n"
                    + method.getResponseBodyAsString());
        }
        return document;
    } catch (Exception e) {
        logger.error("Error querying CoNE service. This is normal during unit tests. "
                + "Otherwise it should be clarified if any measures have to be taken.", e);
        return null;
        // throw new RuntimeException(e);
    }
}

From source file:com.manydesigns.portofino.persistence.QueryUtils.java

/**
 * Merges a HQL query string with a {@link TableCriteria} object representing a search. The query string is
 * processed with an {@link OgnlSqlFormat}, so it can access values from the OGNL context, as well as from an
 * (optional) root object.//from  w w w.j  a  va  2 s  .  c  o m
 * 
 * @param queryString the base query
 * @param criteria the criteria to merge with the query
 * @param rootObject the OGNL root object (can be null)
 * @return the merged query
 */
public static QueryStringWithParameters mergeQuery(String queryString, @Nullable TableCriteria criteria,
        Object rootObject) {
    OgnlSqlFormat sqlFormat = OgnlSqlFormat.create(queryString);
    String formatString = sqlFormat.getFormatString();
    Object[] parameters = sqlFormat.evaluateOgnlExpressions(rootObject);

    CCJSqlParserManager parserManager = new CCJSqlParserManager();
    PlainSelect parsedQueryString;
    PlainSelect parsedCriteriaQuery;
    try {
        parsedQueryString = parseQuery(parserManager, formatString);
    } catch (JSQLParserException e) {
        throw new RuntimeException("Couldn't merge query", e);
    }

    String mainEntityAlias = null;
    if (criteria != null) {
        mainEntityAlias = getEntityAlias(criteria.getTable().getActualEntityName(), parsedQueryString);
    }

    QueryStringWithParameters criteriaQuery = getQueryStringWithParametersForCriteria(criteria,
            mainEntityAlias);
    String criteriaQueryString = criteriaQuery.getQueryString();
    Object[] criteriaParameters = criteriaQuery.getParameters();

    try {
        if (StringUtils.isEmpty(criteriaQueryString)) {
            parsedCriteriaQuery = new PlainSelect();
        } else {
            parsedCriteriaQuery = parseQuery(parserManager, criteriaQueryString);
        }
    } catch (JSQLParserException e) {
        throw new RuntimeException("Couldn't merge query", e);
    }

    Expression whereExpression;
    if (parsedQueryString.getWhere() != null) {
        if (parsedCriteriaQuery.getWhere() != null) {
            whereExpression = parsedQueryString.getWhere();
            if (!(whereExpression instanceof Parenthesis)) {
                whereExpression = new Parenthesis(whereExpression);
            }
            whereExpression = new AndExpression(whereExpression, parsedCriteriaQuery.getWhere());
        } else {
            whereExpression = parsedQueryString.getWhere();
        }
    } else {
        whereExpression = parsedCriteriaQuery.getWhere();
    }
    parsedQueryString.setWhere(whereExpression);
    if (criteria != null && criteria.getOrderBy() != null) {
        List orderByElements = new ArrayList();
        OrderByElement orderByElement = new OrderByElement();
        orderByElement.setAsc(criteria.getOrderBy().isAsc());
        String propertyName = criteria.getOrderBy().getPropertyAccessor().getName();
        if (mainEntityAlias != null) {
            propertyName = mainEntityAlias + "." + propertyName;
        }
        orderByElement.setExpression(
                new net.sf.jsqlparser.schema.Column(new net.sf.jsqlparser.schema.Table(), propertyName));
        orderByElements.add(orderByElement);
        if (parsedQueryString.getOrderByElements() != null) {
            for (Object el : parsedQueryString.getOrderByElements()) {
                OrderByElement toAdd = (OrderByElement) el;
                if (toAdd.getExpression() instanceof net.sf.jsqlparser.schema.Column) {
                    net.sf.jsqlparser.schema.Column column = (net.sf.jsqlparser.schema.Column) toAdd
                            .getExpression();
                    if (StringUtils.isEmpty(column.getTable().getName())
                            && propertyName.equals(column.getColumnName())) {
                        continue; // do not add
                    }
                }
                orderByElements.add(toAdd);
            }
        }
        parsedQueryString.setOrderByElements(orderByElements);
    }
    String fullQueryString = parsedQueryString.toString();
    if (fullQueryString.toLowerCase().startsWith(FAKE_SELECT_PREFIX)) {
        fullQueryString = fullQueryString.substring(FAKE_SELECT_PREFIX.length());
    }

    // merge the parameters
    ArrayList<Object> mergedParametersList = new ArrayList<Object>();
    mergedParametersList.addAll(Arrays.asList(parameters));
    mergedParametersList.addAll(Arrays.asList(criteriaParameters));
    Object[] mergedParameters = new Object[mergedParametersList.size()];
    mergedParametersList.toArray(mergedParameters);

    return new QueryStringWithParameters(fullQueryString, mergedParameters);
}

From source file:org.opendatakit.database.data.ColumnDefinition.java

/**
 * This must match the code in the javascript layer
 * <p>/*from  ww  w  .ja va  2s.  c  o  m*/
 * See databaseUtils.markUnitOfRetention
 * <p>
 * Sweeps through the collection of ColumnDefinition objects and marks the
 * ones that exist in the actual database table.
 *
 * @param defn the map of column definitions to mark
 */
private static void markUnitOfRetention(Map<String, ColumnDefinition> defn) {
    // for all arrays, mark all descendants of the array as not-retained
    // because they are all folded up into the json representation of the array
    for (Map.Entry<String, ColumnDefinition> stringColumnDefinitionEntry : defn.entrySet()) {
        ColumnDefinition colDefn = stringColumnDefinitionEntry.getValue();
        if (!colDefn.isUnitOfRetention()) {
            // this has already been processed
            continue;
        }
        ElementType type = colDefn.getType();
        if (ElementDataType.array == type.getDataType()) {
            ArrayList<ColumnDefinition> descendantsOfArray = new ArrayList<>(colDefn.getChildren());
            ArrayList<ColumnDefinition> scratchArray = new ArrayList<>();
            while (true) {
                for (ColumnDefinition subDefn : descendantsOfArray) {
                    if (!subDefn.isUnitOfRetention()) {
                        // this has already been processed
                        continue;
                    }
                    subDefn.setNotUnitOfRetention();
                    scratchArray.addAll(subDefn.getChildren());
                }

                descendantsOfArray.clear();
                descendantsOfArray.addAll(scratchArray);
                scratchArray.clear();
                if (descendantsOfArray.isEmpty()) {
                    break;
                }
            }
        }
    }
    // and mark any non-arrays with multiple fields as not retained
    for (Map.Entry<String, ColumnDefinition> stringColumnDefinitionEntry : defn.entrySet()) {
        ColumnDefinition colDefn = stringColumnDefinitionEntry.getValue();
        if (!colDefn.isUnitOfRetention()) {
            // this has already been processed
            continue;
        }
        ElementType type = colDefn.getType();
        if (ElementDataType.array != type.getDataType()) {
            if (!colDefn.getChildren().isEmpty()) {
                colDefn.setNotUnitOfRetention();
            }
        }
    }
}

From source file:de.cismet.cids.custom.objectrenderer.utils.alkis.AlkisUtils.java

/**
 * DOCUMENT ME!// www .ja v  a2 s . c om
 *
 * @param   blatt  DOCUMENT ME!
 *
 * @return  DOCUMENT ME!
 */
public static String getBuchungsartFromBuchungsblatt(final Buchungsblatt blatt) {
    final Buchungsstelle[] buchungsstellen = blatt.getBuchungsstellen();
    if ((buchungsstellen != null) && (buchungsstellen.length > 0)) {
        final ArrayList<Buchungsstelle> alleStellen = new ArrayList<Buchungsstelle>();
        alleStellen.addAll(Arrays.asList(buchungsstellen));
        if (isListOfSameBuchungsart(alleStellen)) {
            return alleStellen.get(0).getBuchungsart();
        } else {
            return "diverse";
        }
    }
    return "";
}

From source file:com.epam.ta.reportportal.core.widget.content.ActivityContentLoader.java

@Override
public Map<String, List<ChartObject>> loadContent(Filter filter, Sort sorting, int quantity,
        List<String> contentFields, List<String> metaDataFields, Map<String, List<String>> options) {

    ActivityDocumentHandler activityDocumentHandler = new ActivityDocumentHandler();

    ArrayList<String> fields = new ArrayList<>();
    fields.addAll(contentFields);
    fields.addAll(metaDataFields);//from w  w w.  j a  va 2  s.  co m

    activityRepository.loadWithCallback(filter, sorting, quantity, fields, activityDocumentHandler,
            COLLECTION_NAME);
    Map<String, List<ChartObject>> result = new HashMap<>();
    result.put("result", activityDocumentHandler.getResult());
    return result;
}

From source file:org.mifos.group.repository.InMemoryGroupDao.java

@Override
public List<Group> getAll() {
    ArrayList<Group> groupList = new ArrayList<Group>();
    groupList.addAll(groups.values());
    return groupList;
}

From source file:com.epam.ta.reportportal.core.widget.content.LaunchesTableContentLoader.java

@Override
public Map<String, List<ChartObject>> loadContent(Filter filter, Sort sorting, int quantity,
        List<String> contentFields, List<String> metaDataFields, Map<String, List<String>> options) {

    if (filter.getTarget().equals(TestItem.class)) {
        return new HashMap<>();
    }/* w ww  .j  ava 2 s. c  om*/

    ArrayList<String> fields = new ArrayList<>();

    fields.addAll(contentFields);
    fields.addAll(metaDataFields);

    LaunchesTableDocumentHandler launchesTableDocumentHandler = new LaunchesTableDocumentHandler(fields);
    launchRepository.loadWithCallback(filter, sorting, quantity, fields, launchesTableDocumentHandler,
            StatisticBasedContentLoader.getCollectionName(filter.getTarget()));
    return launchesTableDocumentHandler.getResult();
}

From source file:com.netcracker.financeapp.controller.type.TypeDeleteServlet.java

@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    ArrayList<String> typeList = typeService.getIncomeTypeNames();
    typeList.addAll(typeService.getSpendingTypeNames());
    request.setAttribute("typeList", typeList);

    request.setAttribute("clearType", "Select Type");
    request.getRequestDispatcher("type/typeDelete.jsp").forward(request, response);

}