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:com.dtstack.jlogstash.decoder.MultilineDecoder.java

private Map<String, Object> flush(String identify) {

    List<String> buffer = bufferMap.get(identify);

    if (buffer == null || buffer.size() == 0) {
        return null;
    }/* w w w  . j  av  a 2 s .  c  o m*/

    String msg = StringUtils.join(buffer, customLineDelimiter);
    Map<String, Object> event = new HashMap<String, Object>();
    event.put("message", msg);
    buffer.clear();
    readSizeMap.remove(identify);
    lastFlushMap.put(identify, System.currentTimeMillis());
    return event;
}

From source file:com.agiletec.plugins.jpcrowdsourcing.aps.system.services.ideainstance.ApiIdeaInstanceInterface.java

/**
 * GET http://localhost:8080/<portal>/api/rs/en/ideaInstances?id=1
 * @param properties/* www  . j  a v a2  s . c o m*/
 * @return
 * @throws Throwable
 */
public JAXBIdeaInstance getIdeaInstanceForApi(Properties properties) throws Throwable {
    JAXBIdeaInstance jaxbIdeaInstance = null;
    try {
        String codeParam = properties.getProperty("code");
        if (StringUtils.isNotBlank(codeParam))
            codeParam = URLDecoder.decode(codeParam, "UTF-8");

        UserDetails user = (UserDetails) properties.get(SystemConstants.API_USER_PARAMETER);
        //TODO CREATE ROLE
        List<Integer> ideaStateFilter = new ArrayList<Integer>();
        ideaStateFilter.add(IIdea.STATUS_APPROVED);

        if (null != user && !this.getAuthorizationManager().isAuthOnPermission(user, Permission.SUPERUSER)) {
            ideaStateFilter.clear();
        }
        IdeaInstance ideaInstance = this.getIdeaInstanceManager().getIdeaInstance(codeParam, ideaStateFilter);
        if (null == ideaInstance) {
            throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR,
                    "IdeaInstance with code '" + codeParam + "' does not exist", Response.Status.CONFLICT);
        }
        if (!isAuthOnInstance(user, ideaInstance)) {
            _logger.warn("the current user is not granted to any group required by instance {}", codeParam);
            throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR,
                    "IdeaInstance with code '" + codeParam + "' does not exist", Response.Status.CONFLICT);
        }
        jaxbIdeaInstance = new JAXBIdeaInstance(ideaInstance);
    } catch (ApiException ae) {
        throw ae;
    } catch (Throwable t) {
        _logger.error("Error extracting ideaInstance", t);
        throw new ApsSystemException("Error extracting idea instance", t);
    }
    return jaxbIdeaInstance;
}

From source file:com.jaspersoft.studio.server.wizard.find.FindResourcePage.java

public void setFilterTypes(String[] in, String[] excl) {
    this.itypes = in;
    this.etypes = excl;

    List<String> tps = finderUI.getTypes();
    tps.clear();
    if (itypes != null)
        for (String t : itypes)
            tps.add(t);//  w  ww  .  j  av a 2  s  .c  o m
    if (etypes != null)
        for (String t : etypes)
            if (tps.contains(t))
                tps.remove(t);
}

From source file:de.tudarmstadt.lt.nlkg.DT.java

void queryDT(String word, int max_results) {

    try {//w  w w .  j a  v a  2s  .  c o m
        // Class.forName(_mysql_driver).newInstance();
        Connection _mysql_conn = DriverManager.getConnection(
                _mysql_url() + "?useUnicode=true&characterEncoding=UTF-8", _mysql_userName, _mysql_password);
        System.out.println("Connected to the database");
        String query = String.format("SELECT * FROM `dt` WHERE word1 = '%s' ORDER BY count DESC LIMIT 1,%d;",
                word, max_results);
        Statement st = _mysql_conn.createStatement();
        ResultSet rs = st.executeQuery(query);

        // System.out.println(rs.getMetaData().getColumnCount());
        // System.out.println(rs.getFetchSize());
        int nc = rs.getMetaData().getColumnCount();
        String format_str = new String(new char[nc + 1]).replace("\0", "%-20s\t") + "%n";
        // System.out.println(format_str);

        List<String> values = new ArrayList<String>();
        // header
        values.add("row");
        for (int i = 1; i <= nc; i++)
            values.add(rs.getMetaData().getColumnName(i));
        System.out.format(format_str, values.toArray());

        // data
        while (rs.next()) {
            values.clear();
            values.add(String.valueOf(rs.getRow()));
            for (int i = 1; i <= rs.getMetaData().getColumnCount(); i++)
                values.add(rs.getString(i));
            System.out.format(format_str, values.toArray());
        }

        st.close();
        _mysql_conn.close();

    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:com.example.karspoolingapp.RouteByHitchhikerCar.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.routebyhitchhiker);

    Intent intent = getIntent();/*from   w  ww.  j a  v  a 2s  .c om*/
    Bundle bundle = intent.getExtras();
    new_license_number = bundle.getString("pre_end_point");
    //session_username = session.getUsername();
    System.out.println("nayaaa licnse number" + new_license_number);
    StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();

    StrictMode.setThreadPolicy(policy);

    // code for dynamic radio button generation
    final RadioButton[] rb = new RadioButton[100];
    rl = (RelativeLayout) findViewById(R.id.rl);
    rg = new RadioGroup(this);

    // Building Parameters
    List<NameValuePair> params = new ArrayList<NameValuePair>();
    params.add(new BasicNameValuePair("car_number", new_license_number));
    System.out.println(params);
    json = jsonParser.makeHttpRequest(READ_COMMENTS_URL2, "POST", params);
    params.clear();
    System.out.println(json);

    try {
        jsonTripDetails = json.getJSONArray("route");
        System.out.println(jsonTripDetails);
        int k = jsonTripDetails.length();
        if (k > 0) {
            for (int i = 0; i < jsonTripDetails.length(); i++) {
                JSONObject c = jsonTripDetails.getJSONObject(i);

                String parent_username_str = c.getString("username");
                String route = c.getString("route");
                String timing = c.getString("timing");
                String seating = c.getString("seating_capacity");
                rb[i] = new RadioButton(this);
                rg.addView(rb[i]);
                rb[i].setText(parent_username_str + "," + route + "," + timing + "," + seating);
                params.clear();

            }
            rl.addView(rg);
            rl.setPadding(50, 50, 50, 50);
        } else {
            Toast.makeText(RouteByHitchhikerCar.this, "No Trip available on these routes", Toast.LENGTH_LONG)
                    .show();
        }

    } catch (JSONException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();

    }

    addListenerOnButton();

}

From source file:be.apsu.extremon.probes.tsp.TSPProbe.java

public void probe_forever() {
    double start = 0, end = 0;
    BigInteger requestNonce;//from  ww w. j  a  va  2  s .c om
    byte[] requestHashedMessage = new byte[20];
    List<String> comments = new ArrayList<String>();
    STATE result = STATE.OK;

    log("running");

    this.running = true;
    while (this.running) {
        comments.clear();
        this.random.nextBytes(requestHashedMessage);
        requestNonce = new BigInteger(512, this.random);
        TimeStampRequest request = requestGenerator.generate(TSPAlgorithms.SHA1, requestHashedMessage,
                requestNonce);

        end = 0;
        start = System.currentTimeMillis();

        try {
            TimeStampResponse response = probe(request);

            switch (response.getStatus()) {
            case PKIStatus.GRANTED:
                comments.add("granted");
                result = STATE.OK;
                break;
            case PKIStatus.GRANTED_WITH_MODS:
                comments.add("granted with modifications");
                result = STATE.WARNING;
                break;
            case PKIStatus.REJECTION:
                comments.add("rejected");
                result = STATE.ALERT;
                break;
            case PKIStatus.WAITING:
                comments.add("waiting");
                result = STATE.ALERT;
                break;
            case PKIStatus.REVOCATION_WARNING:
                comments.add("revocation warning");
                result = STATE.WARNING;
                break;
            case PKIStatus.REVOCATION_NOTIFICATION:
                comments.add("revocation notification");
                result = STATE.ALERT;
                break;
            default:
                comments.add("response outside RFC3161");
                result = STATE.ALERT;
                break;
            }

            if (response.getStatus() >= 2)
                comments.add(response.getFailInfo() != null ? response.getFailInfo().getString()
                        : "(missing failinfo)");

            if (response.getStatusString() != null)
                comments.add(response.getStatusString());

            end = System.currentTimeMillis();
            TimeStampToken timestampToken = response.getTimeStampToken();

            timestampToken.validate(this.signerVerifier);
            comments.add("validated");

            AttributeTable table = timestampToken.getSignedAttributes();
            TimeStampTokenInfo tokenInfo = timestampToken.getTimeStampInfo();
            BigInteger responseNonce = tokenInfo.getNonce();
            byte[] responseHashedMessage = tokenInfo.getMessageImprintDigest();
            long genTimeSeconds = (tokenInfo.getGenTime().getTime()) / 1000;
            long currentTimeSeconds = (long) (start + ((end - start) / 2)) / 1000;

            put("clockskew", (genTimeSeconds - currentTimeSeconds) * 1000);

            if (Math.abs((genTimeSeconds - currentTimeSeconds)) > 1) {
                comments.add("clock skew > 1s");
                result = STATE.ALERT;
            }

            Store responseCertificatesStore = timestampToken.toCMSSignedData().getCertificates();
            @SuppressWarnings("unchecked")
            Collection<X509CertificateHolder> certs = responseCertificatesStore.getMatches(null);
            for (X509CertificateHolder certificate : certs) {
                AlgorithmIdentifier sigalg = certificate.getSignatureAlgorithm();
                if (!(oidsAllowed.contains(sigalg.getAlgorithm().getId()))) {
                    String cleanDn = certificate.getSubject().toString().replace("=", ":");
                    comments.add("signature cert \"" + cleanDn + "\" signed using "
                            + getName(sigalg.getAlgorithm().getId()));
                    result = STATE.ALERT;
                }
            }

            if (!responseNonce.equals(requestNonce)) {
                comments.add("nonce modified");
                result = STATE.ALERT;
            }

            if (!Arrays.equals(responseHashedMessage, requestHashedMessage)) {
                comments.add("hashed message modified");
                result = STATE.ALERT;
            }

            if (table.get(PKCSObjectIdentifiers.id_aa_signingCertificate) == null) {
                comments.add("signingcertificate missing");
                result = STATE.ALERT;
            }
        } catch (TSPException tspEx) {
            comments.add("validation failed");
            comments.add("tspexception-" + tspEx.getMessage().toLowerCase());
            result = STATE.ALERT;
        } catch (IOException iox) {
            comments.add("unable to obtain response");
            comments.add("ioexception-" + iox.getMessage().toLowerCase());
            result = STATE.ALERT;
        } catch (Exception ex) {
            comments.add("unhandled exception");
            result = STATE.ALERT;
        } finally {
            if (end == 0)
                end = System.currentTimeMillis();
        }

        put(RESULT_SUFFIX, result);
        put(RESULT_COMMENT_SUFFIX, StringUtils.join(comments, "|"));
        put("responsetime", (end - start));

        try {
            Thread.sleep(this.delay);
        } catch (InterruptedException ex) {
            log("interrupted");
        }
    }
}

From source file:de.fhg.iais.cortex.search.IndexerImpl.java

@Override
public List<String> deleteByIds(List<String> ids) {
    List<String> subList = Lists.newArrayList();
    for (int i = 0; i < ids.size(); i++) {
        if (i % DELETE_BATCH_SIZE == 0 && !subList.isEmpty()) {
            deleteListOfItems(subList);//from ww  w .java2  s.  c  o m
            subList.clear();
        }
        subList.add(ids.get(i));
    }
    deleteListOfItems(subList);

    return ids;
}

From source file:de.tudarmstadt.ukp.lmf.transform.germanet.LexicalEntryGenerator.java

/**
 * This method consumes a list of RelatedForms and removes
 * all duplicates from the consumed list
 * @param relatedForms {@link List} of RelatedForm objects from which duplicates should be removed
 * @see {@link RelatedForm}//from   w ww . j  a  va2s  .  co  m
 * @since UBY 0.1.0
 */
private void removeDuplicateRelatedForms(List<RelatedForm> relatedForms) {
    if (relatedForms.isEmpty())
        return;

    HashSet<RelatedForm> temp = new HashSet<RelatedForm>();
    temp.addAll(relatedForms);
    relatedForms.clear();
    relatedForms.addAll(temp);
}

From source file:org.mule.module.magento.automation.testcases.MagentoTestParent.java

public String createOrderShipment(String orderId, List<OrderItemIdQty> quantities) throws Exception {
    initializeTestRunMessage("orderId", orderId);

    // A workaround for Magento's internal bug
    // To remove this if statement once the bug is fixed
    if (quantities.size() > 0) {
        quantities.clear();
    }/*from  w w  w .j av  a 2  s.co m*/

    upsertOnTestRunMessage("itemsQuantitiesRef", quantities);

    return runFlowAndGetPayload("create-order-shipment");
}

From source file:eu.esdihumboldt.hale.common.core.io.HaleIO.java

/**
 * Find the content types that match the given file name and/or input.
 * //ww  w.ja v a2 s.c o m
 * NOTE: The implementation should try to restrict the result to one content
 * type and only use the input supplier if absolutely needed.
 * 
 * @param types the types to match
 * @param in the input supplier to use for testing, may be <code>null</code>
 *            if the file name is not <code>null</code>
 * @param filename the file name, may be <code>null</code> if the input
 *            supplier is not <code>null</code>
 * @return the matched content types
 */
public static List<IContentType> findContentTypesFor(Collection<IContentType> types,
        InputSupplier<? extends InputStream> in, String filename) {
    Preconditions.checkArgument(filename != null || in != null,
            "At least one of input supplier and file name must not be null");

    List<IContentType> results = new ArrayList<IContentType>();

    if (filename != null) {
        // test file extension
        for (IContentType type : types) {
            String ext = FilenameUtils.getExtension(filename);
            if (ext != null && !ext.isEmpty()) {
                String[] extensions = type.getFileSpecs(IContentType.FILE_EXTENSION_SPEC);
                boolean match = false;
                for (int i = 0; i < extensions.length && !match; i++) {
                    if (extensions[i].equalsIgnoreCase(ext)) {
                        match = true;
                    }
                }
                if (match) {
                    results.add(type);
                }
            }
        }
    }

    if ((results.isEmpty() || results.size() > 1) && in != null) {
        // clear results because only an ambiguous result was found
        results.clear();
        // use input stream to make a better test
        IContentTypeManager ctm = Platform.getContentTypeManager();
        try {
            InputStream is = in.getInput();

            /*
             * XXX IContentTypeManager.findContentTypes seems to return all
             * kind of content types that match in any way, but ordered by
             * relevance - so if all but the allowed types are removed, the
             * remaining types may be very irrelevant and not a match that
             * actually was determined based on the input stream.
             * 
             * XXX thus findContentTypesFor should not be used or only
             * relied upon the single best match that is returned
             */
            //            IContentType[] candidates = ctm.findContentTypesFor(is, filename);
            //
            //            for (IContentType candidate : candidates) {
            //               if (types.contains(candidate)) {
            //                  results.add(candidate);
            //               }
            //            }
            // instead use findContentTypeFor
            IContentType candidate = ctm.findContentTypeFor(is, null);
            if (types.contains(candidate)) {
                results.add(candidate);
            }

            is.close();
        } catch (IOException e) {
            log.warn("Could not read input to determine content type", e);
        }
    }

    return results;
}