Example usage for java.util List clear

List of usage examples for java.util List clear

Introduction

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

Prototype

void clear();

Source Link

Document

Removes all of the elements from this list (optional operation).

Usage

From source file:org.terasoluna.gfw.functionaltest.app.DBLog.java

private void writeLog(String sql, int sequenceNo, String subTitle, String tableName) {
    String evidenceFile = String.format("dblog_%03d%s-%s.log", sequenceNo, subTitle, tableName);
    List<Map<String, Object>> results = jdbcTemplate.queryForList(sql);
    try {//ww  w.  ja v  a2  s  . c  o  m
        FileUtils.writeLines(new File(evidenceSavingDirectory, evidenceFile), results);
    } catch (IOException e) {
        logger.error(e.toString());
    } finally {
        results.clear();
        results = null;
    }
}

From source file:com.epam.reportportal.apache.http.impl.execchain.RedirectExec.java

public CloseableHttpResponse execute(final HttpRoute route, final HttpRequestWrapper request,
        final HttpClientContext context, final HttpExecutionAware execAware) throws IOException, HttpException {
    Args.notNull(route, "HTTP route");
    Args.notNull(request, "HTTP request");
    Args.notNull(context, "HTTP context");

    final List<URI> redirectLocations = context.getRedirectLocations();
    if (redirectLocations != null) {
        redirectLocations.clear();
    }//from  w  w w  .  j  a va 2  s.com

    final RequestConfig config = context.getRequestConfig();
    final int maxRedirects = config.getMaxRedirects() > 0 ? config.getMaxRedirects() : 50;
    HttpRoute currentRoute = route;
    HttpRequestWrapper currentRequest = request;
    for (int redirectCount = 0;;) {
        final CloseableHttpResponse response = requestExecutor.execute(currentRoute, currentRequest, context,
                execAware);
        try {
            if (config.isRedirectsEnabled()
                    && this.redirectStrategy.isRedirected(currentRequest, response, context)) {

                if (redirectCount >= maxRedirects) {
                    throw new RedirectException("Maximum redirects (" + maxRedirects + ") exceeded");
                }
                redirectCount++;

                final HttpRequest redirect = this.redirectStrategy.getRedirect(currentRequest, response,
                        context);
                if (!redirect.headerIterator().hasNext()) {
                    final HttpRequest original = request.getOriginal();
                    redirect.setHeaders(original.getAllHeaders());
                }
                currentRequest = HttpRequestWrapper.wrap(redirect);

                if (currentRequest instanceof HttpEntityEnclosingRequest) {
                    Proxies.enhanceEntity((HttpEntityEnclosingRequest) currentRequest);
                }

                final URI uri = currentRequest.getURI();
                final HttpHost newTarget = URIUtils.extractHost(uri);
                if (newTarget == null) {
                    throw new ProtocolException("Redirect URI does not specify a valid host name: " + uri);
                }

                // Reset virtual host and auth states if redirecting to another host
                if (!currentRoute.getTargetHost().equals(newTarget)) {
                    final AuthState targetAuthState = context.getTargetAuthState();
                    if (targetAuthState != null) {
                        this.log.debug("Resetting target auth state");
                        targetAuthState.reset();
                    }
                    final AuthState proxyAuthState = context.getProxyAuthState();
                    if (proxyAuthState != null) {
                        final AuthScheme authScheme = proxyAuthState.getAuthScheme();
                        if (authScheme != null && authScheme.isConnectionBased()) {
                            this.log.debug("Resetting proxy auth state");
                            proxyAuthState.reset();
                        }
                    }
                }

                currentRoute = this.routePlanner.determineRoute(newTarget, currentRequest, context);
                if (this.log.isDebugEnabled()) {
                    this.log.debug("Redirecting to '" + uri + "' via " + currentRoute);
                }
                EntityUtils.consume(response.getEntity());
                response.close();
            } else {
                return response;
            }
        } catch (final RuntimeException ex) {
            response.close();
            throw ex;
        } catch (final IOException ex) {
            response.close();
            throw ex;
        } catch (final HttpException ex) {
            // Protocol exception related to a direct.
            // The underlying connection may still be salvaged.
            try {
                EntityUtils.consume(response.getEntity());
            } catch (final IOException ioex) {
                this.log.debug("I/O error while releasing connection", ioex);
            } finally {
                response.close();
            }
            throw ex;
        }
    }
}

From source file:org.balloon_project.overflight.task.importer.ImporterTask.java

private void bulksave(List<Triple> bulk, boolean force) {
    if (force || (bulk.size() >= configuration.getTripleBulkInsertSize())) {
        relationService.save(bulk);// ww w.  j av a  2  s. co m
        bulk.clear();
    }
}

From source file:com.espertech.esperio.regression.adapter.TestAdapterCoordinator.java

private void assertSizeAndReset(int size) {
    List<EventBean[]> list = listener.getNewDataList();
    assertEquals(size, list.size());/* w w  w .ja  va 2  s  . co m*/
    list.clear();
    listener.getAndClearIsInvoked();
}

From source file:com.haulmont.cuba.web.toolkit.ui.CubaSuggestionField.java

public void setPopupStyleName(String styleName) {
    if (Strings.isNullOrEmpty(styleName)) {
        getState().popupStylename = null;
        return;/*from  w  w w .  ja  v  a2 s  .  c  o m*/
    }

    if (getState().popupStylename == null) {
        getState().popupStylename = new ArrayList<>();
    }

    List<String> styles = getState().popupStylename;
    styles.clear();

    StringTokenizer tokenizer = new StringTokenizer(styleName, " ");
    while (tokenizer.hasMoreTokens()) {
        styles.add(tokenizer.nextToken());
    }
}

From source file:edu.uci.ics.hyracks.algebricks.rewriter.rules.PushSelectIntoJoinRule.java

private void pushOps(List<ILogicalOperator> opList, Mutable<ILogicalOperator> joinBranch,
        IOptimizationContext context) throws AlgebricksException {
    ILogicalOperator topOp = joinBranch.getValue();
    ListIterator<ILogicalOperator> iter = opList.listIterator(opList.size());
    while (iter.hasPrevious()) {
        ILogicalOperator op = iter.previous();
        List<Mutable<ILogicalOperator>> opInpList = op.getInputs();
        opInpList.clear();
        opInpList.add(new MutableObject<ILogicalOperator>(topOp));
        topOp = op;//from   w ww. j a v  a2  s.c om
        context.computeAndSetTypeEnvironmentForOperator(op);
    }
    joinBranch.setValue(topOp);
}

From source file:org.bedework.calsvc.scheduling.hosts.IscheduleOut.java

private void replaceHeader(final String name, final String val) {
    List<String> l = getFields(name.toLowerCase());

    if (Util.isEmpty(l)) {
        super.addHeader(name, val);
    } else {//from w w  w.  j a  va 2  s . c  o m
        l.clear();
        l.add(val);
    }
}

From source file:edu.arizona.kra.budget.distributionincome.CustomBudgetUnrecoveredFandAAuditRule.java

@SuppressWarnings("rawtypes")
@Override// w w w  .j  a v  a2 s . c o  m
public boolean processRunAuditBusinessRules(Document document) {

    Budget budget = ((BudgetDocument) document).getBudget();
    if (getAuditErrorMap().containsKey(BUDGET_UNRECOVERED_F_AND_A_ERROR_KEY)) {
        List auditErrors = ((AuditCluster) getAuditErrorMap().get(BUDGET_UNRECOVERED_F_AND_A_ERROR_KEY))
                .getAuditErrorList();
        auditErrors.clear();
    }

    // Returns if unrecovered f and a is not applicable
    if (!budget.isUnrecoveredFandAApplicable()) {
        return true;
    }

    List<BudgetUnrecoveredFandA> unrecoveredFandAs = budget.getBudgetUnrecoveredFandAs();
    boolean retval = true;

    // Forces full allocation of unrecovered f and a
    if (budget.getUnallocatedUnrecoveredFandA().isGreaterThan(BudgetDecimal.ZERO)
            && budget.isUnrecoveredFandAEnforced()) {
        retval = false;
        if (unrecoveredFandAs.size() == 0) {
            getAuditErrors().add(new AuditError("document.budget.budgetUnrecoveredFandA",
                    KeyConstants.AUDIT_ERROR_BUDGET_DISTRIBUTION_UNALLOCATED_NOT_ZERO,
                    Constants.BUDGET_DISTRIBUTION_AND_INCOME_PAGE + "."
                            + Constants.BUDGET_UNRECOVERED_F_AND_A_PANEL_ANCHOR,
                    params));

        }
        for (int i = 0; i < unrecoveredFandAs.size(); i++) {
            getAuditErrors().add(new AuditError("document.budget.budgetUnrecoveredFandA[" + i + "].amount",
                    KeyConstants.AUDIT_ERROR_BUDGET_DISTRIBUTION_UNALLOCATED_NOT_ZERO,
                    Constants.BUDGET_DISTRIBUTION_AND_INCOME_PAGE + "."
                            + Constants.BUDGET_UNRECOVERED_F_AND_A_PANEL_ANCHOR,
                    params));
        }
    }

    Integer fiscalYear = null;

    int i = 0;
    int j = 0;
    BudgetParent budgetParent = ((BudgetDocument) document).getParentDocument().getBudgetParent();
    Date projectStartDate = budgetParent.getRequestedStartDateInitial();
    Date projectEndDate = budgetParent.getRequestedEndDateInitial();

    // Forces inclusion of source account
    boolean duplicateEntryFound = false;
    for (BudgetUnrecoveredFandA unrecoveredFandA : unrecoveredFandAs) {

        fiscalYear = unrecoveredFandA.getFiscalYear();

        if (null == fiscalYear || fiscalYear.intValue() <= 0) {
            retval = false;
            getAuditErrors().add(new AuditError("document.budget.budgetUnrecoveredFandA[" + i + "].fiscalYear",
                    KeyConstants.AUDIT_ERROR_BUDGET_DISTRIBUTION_FISCALYEAR_MISSING,
                    Constants.BUDGET_DISTRIBUTION_AND_INCOME_PAGE + "."
                            + Constants.BUDGET_UNRECOVERED_F_AND_A_PANEL_ANCHOR,
                    params));
        }

        if (fiscalYear != null && (fiscalYear < projectStartDate.getYear() + YEAR_CONSTANT
                || fiscalYear > projectEndDate.getYear() + YEAR_CONSTANT)) {
            getAuditWarnings()
                    .add(new AuditError("document.budget.budgetUnrecoveredFandA[" + i + "].fiscalYear",
                            KeyConstants.AUDIT_WARNING_BUDGET_DISTRIBUTION_FISCALYEAR_INCONSISTENT,
                            Constants.BUDGET_DISTRIBUTION_AND_INCOME_PAGE + "."
                                    + Constants.BUDGET_UNRECOVERED_F_AND_A_PANEL_ANCHOR,
                            params));
        }

        if (!duplicateEntryFound) {
            j = 0;
            for (BudgetUnrecoveredFandA unrecoveredFandAForComparison : unrecoveredFandAs) {
                if (i != j && unrecoveredFandA.getFiscalYear() != null
                        && unrecoveredFandAForComparison.getFiscalYear() != null
                        && unrecoveredFandA.getFiscalYear().intValue() == unrecoveredFandAForComparison
                                .getFiscalYear().intValue()
                        && unrecoveredFandA.getApplicableRate()
                                .equals(unrecoveredFandAForComparison.getApplicableRate())
                        && unrecoveredFandA.getOnCampusFlag()
                                .equalsIgnoreCase(unrecoveredFandAForComparison.getOnCampusFlag())
                        && StringUtils.equalsIgnoreCase(unrecoveredFandA.getSourceAccount(),
                                unrecoveredFandAForComparison.getSourceAccount())
                        && unrecoveredFandA.getAmount().equals(unrecoveredFandAForComparison.getAmount())) {
                    retval = false;
                    getAuditErrors().add(new AuditError("document.budget.budgetUnrecoveredFandA[" + i + "]",
                            KeyConstants.AUDIT_ERROR_BUDGET_DISTRIBUTION_DUPLICATE_UNRECOVERED_FA,
                            Constants.BUDGET_DISTRIBUTION_AND_INCOME_PAGE + "."
                                    + Constants.BUDGET_UNRECOVERED_F_AND_A_PANEL_ANCHOR,
                            params));
                    duplicateEntryFound = true;
                    break;
                }
                j++;
            }
        }

        i++;
    }
    return retval;
}

From source file:hr.fer.spocc.grammar.BnfUtils.java

/**
 * Stvara pravila konteksno neovisne gramatike na temelju stringa koji
 * je u BNF notaciji./* w w w . j  av a2s .  com*/
 * Nezavrsni znakovi opisuju se regularnim izrazom: &lt;{znak}*&gt;<br>
 * Zavrsni znakovi opisuju se regularnim izrazom: {znak}<br>
 * Epsilon se opisuje regularnim izrazom: $<br>
 * Izbor se opisuje pipe operatorom: |<br>
 * Pridruzivanje se opisuje regularnim izrazom: ::=<br>
 * Pravila moraju biti razdvojena jednom od bjelina
 * <p>Primjeri:
 * &lt;BROJ&gt; ::= &lt;ZNAMENKA&gt;&lt;BROJ&gt; | &lt;ZNAMENKA&gt;<br>
 * &lt;ZNAMENKA&gt; ::= 0|1|2|3| 4  | 5|  6 |7|8|  9
 * </p>
 * 
 * @param bnfNotation
 * @return
 * @see BnfEscaper
 */
public static List<CfgProductionRule<Character>> createCfgProductionRules(String bnfNotation) {
    List<CfgProductionRule<Character>> rules = new ArrayList<CfgProductionRule<Character>>();

    // insert sentinel variable at the end, to make parsing easier
    bnfNotation += "<>";
    Set<Integer> unescapedIndexes = new HashSet<Integer>();
    String[] bnfRules = bnfNotation.split("::=");
    Validate.isTrue(bnfRules.length > 1 && bnfRules[0].charAt(0) == '<'
            && bnfRules[0].charAt(bnfRules[0].length() - 1) == '>', "Invalid first BNF rule");
    String leftSideVariable = bnfRules[0].substring(1, bnfRules[0].length() - 1);

    for (int ruleNumber = 1; ruleNumber < bnfRules.length; ++ruleNumber) {
        String unescapedBnf = BnfEscaper.getInstance().unescape(bnfRules[ruleNumber], unescapedIndexes);

        List<Symbol<Character>> rightSideSymbols = new ArrayList<Symbol<Character>>();
        StringBuilder rightSideVariable = new StringBuilder();
        String nextLeftSideVariable = null;
        boolean opened = false;
        for (int i = 0; i < unescapedBnf.length(); ++i) {
            boolean terminalOrVariablePart = false;
            char c = unescapedBnf.charAt(i);
            if (!unescapedIndexes.contains(i)) {
                switch (c) {
                case '<':
                    opened = true;
                    break;
                case '>':
                    rightSideSymbols.add(new Variable<Character>(rightSideVariable.toString()));
                    nextLeftSideVariable = rightSideVariable.toString();
                    StringBuilderUtils.clear(rightSideVariable);
                    opened = false;
                    break;
                case '|':
                    rules.add(new CfgProductionRule<Character>(new Variable<Character>(leftSideVariable),
                            rightSideSymbols));
                    rightSideSymbols.clear();
                    nextLeftSideVariable = null;
                    break;
                case '$':
                    Symbol<Character> epsilon = Symbols.epsilonSymbol();
                    rightSideSymbols.add(epsilon);
                    break;
                case ':':
                case '=':
                    break;
                default:
                    terminalOrVariablePart = true;
                }
            } else {
                terminalOrVariablePart = true;
            }

            if (terminalOrVariablePart) {
                if (opened)
                    rightSideVariable.append(c);
                else {
                    rightSideSymbols.add(new Terminal<Character>(c));
                }
            }
        }

        // pop left side variable
        Validate.isTrue(!rightSideSymbols.isEmpty(), "Right side of BNF rule #" + (ruleNumber + 1)
                + " or left side of BNF rule #" + (ruleNumber + 2) + " is invalid");
        rightSideSymbols.remove(rightSideSymbols.size() - 1);

        rules.add(
                new CfgProductionRule<Character>(new Variable<Character>(leftSideVariable), rightSideSymbols));

        Validate.notNull(nextLeftSideVariable, "Right side of BNF rule #" + (ruleNumber + 1)
                + " or left side of BNF rule #" + (ruleNumber + 2) + " is invalid");
        leftSideVariable = nextLeftSideVariable;
    }

    return rules;
}

From source file:fr.exanpe.t5.lib.components.ListSorter.java

/**
 * Reorder the element in the list, depending on the order of the JSONArray
 * //www  . j  a v a2s .c  o  m
 * @param destination the list to modify
 * @param array the ordering array
 */
private void reorder(List<T> destination, JSONArray array) {
    List<T> source = new ArrayList<T>(destination);

    destination.clear();

    for (int i = 0; i < array.length(); i++) {
        destination.add(source.get(array.getInt(i)));
    }
}