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.ask.hive.hbase.HBaseTimeSerDe.java

/**
 * Parses the HBase columns mapping to identify the column families, qualifiers
 * and also caches the byte arrays corresponding to them. One of the Hive table
 * columns maps to the HBase row key, by default the first column.
 *
 * @param columnMapping - the column mapping specification to be parsed
 * @param colFamilies - the list of HBase column family names
 * @param colFamiliesBytes - the corresponding byte array
 * @param colQualifiers - the list of HBase column qualifier names
 * @param colQualifiersBytes - the corresponding byte array
 * @return the row key index in the column names list
 * @throws org.apache.hadoop.hive.serde2.SerDeException
 *///from  w  ww  .j  a  v  a2 s  .c om
public static int parseColumnMapping(String columnMapping, List<String> colFamilies,
        List<byte[]> colFamiliesBytes, List<String> colQualifiers, List<byte[]> colQualifiersBytes)
        throws SerDeException {

    int rowKeyIndex = -1;

    if (colFamilies == null || colQualifiers == null) {
        throw new SerDeException(
                "Error: caller must pass in lists for the column families " + "and qualifiers.");
    }

    colFamilies.clear();
    colQualifiers.clear();

    if (columnMapping == null) {
        throw new SerDeException("Error: hbase.columns.mapping missing for this HBase table.");
    }

    if (columnMapping.equals("") || columnMapping.equals(HBASE_KEY_COL)) {
        throw new SerDeException("Error: hbase.columns.mapping specifies only the HBase table"
                + " row key. A valid Hive-HBase table must specify at least one additional column.");
    }

    String[] mapping = columnMapping.split(",");

    for (int i = 0; i < mapping.length; i++) {
        String elem = mapping[i];
        int idxFirst = elem.indexOf(":");
        int idxLast = elem.lastIndexOf(":");

        if (idxFirst < 0 || !(idxFirst == idxLast)) {
            throw new SerDeException("Error: the HBase columns mapping contains a badly formed "
                    + "column family, column qualifier specification.");
        }

        if (elem.equals(HBASE_KEY_COL)) {
            rowKeyIndex = i;
            colFamilies.add(elem);
            colQualifiers.add(null);
        } else {
            String[] parts = elem.split(":");
            assert (parts.length > 0 && parts.length <= 2);
            colFamilies.add(parts[0]);

            if (parts.length == 2) {
                colQualifiers.add(parts[1]);
            } else {
                colQualifiers.add(null);
            }
        }
    }

    if (rowKeyIndex == -1) {
        colFamilies.add(0, HBASE_KEY_COL);
        colQualifiers.add(0, null);
        rowKeyIndex = 0;
    }

    if (colFamilies.size() != colQualifiers.size()) {
        throw new SerDeException("Error in parsing the hbase columns mapping.");
    }

    // populate the corresponding byte [] if the client has passed in a non-null list
    if (colFamiliesBytes != null) {
        colFamiliesBytes.clear();

        for (String fam : colFamilies) {
            colFamiliesBytes.add(Bytes.toBytes(fam));
        }
    }

    if (colQualifiersBytes != null) {
        colQualifiersBytes.clear();

        for (String qual : colQualifiers) {
            if (qual == null) {
                colQualifiersBytes.add(null);
            } else {
                colQualifiersBytes.add(Bytes.toBytes(qual));
            }
        }
    }

    if (colFamiliesBytes != null && colQualifiersBytes != null) {
        if (colFamiliesBytes.size() != colQualifiersBytes.size()) {
            throw new SerDeException(
                    "Error in caching the bytes for the hbase column families " + "and qualifiers.");
        }
    }

    return rowKeyIndex;
}

From source file:it.govpay.web.utils.Utils.java

public static List<Long> getIdsFromAcls(List<Acl> listaAcl, Tipo tipo, Servizio servizio) {
    List<Long> lst = new ArrayList<Long>();
    for (Acl acl : listaAcl) {
        if (acl.getServizio().equals(servizio) && acl.getTipo().equals(tipo)) {
            if (tipo.equals(Tipo.DOMINIO)) {
                if (acl.getIdDominio() == null) {
                    lst.clear();
                    lst.add(-1L);//www  . j ava  2  s . c o  m
                    break;
                } else
                    lst.add(acl.getIdDominio());
            } else {
                if (acl.getIdTributo() == null) {
                    lst.clear();
                    lst.add(-1L);
                    break;
                } else
                    lst.add(acl.getIdTributo());
            }
        }
    }
    return lst;
}

From source file:grails.plugin.searchable.internal.compass.mapping.SearchableGrailsDomainClassCompassMappingUtils.java

/**
 * Merges the given property mappings, overriding parent mappings with child mappings
 * @param mappedProperties//from  ww  w  .  j av a  2 s .  c o m
 * @param parentClassPropertyMappings
 */
public static void mergePropertyMappings(List mappedProperties, List parentClassPropertyMappings) {
    if (parentClassPropertyMappings == null) {
        return;
    }
    Assert.notNull(mappedProperties, "mappedProperties cannot be null");
    List temp = new ArrayList(parentClassPropertyMappings);
    temp.addAll(mappedProperties);
    for (Iterator citer = mappedProperties.iterator(); citer.hasNext();) {
        CompassClassPropertyMapping cmapping = (CompassClassPropertyMapping) citer.next();
        for (Iterator piter = parentClassPropertyMappings.iterator(); piter.hasNext();) {
            CompassClassPropertyMapping pmapping = (CompassClassPropertyMapping) piter.next();
            if (cmapping.getPropertyName().equals(pmapping.getPropertyName())) {
                temp.remove(pmapping);
            }
        }
    }
    mappedProperties.clear();
    mappedProperties.addAll(temp);
}

From source file:com.evolveum.midpoint.schema.util.WfContextUtil.java

public static void computeAssignees(List<ObjectReferenceType> newAssignees,
        List<ObjectReferenceType> delegatedTo, List<ObjectReferenceType> delegates,
        WorkItemDelegationMethodType method, AbstractWorkItemType workItem) {
    newAssignees.clear();
    delegatedTo.clear();/* www.ja v  a 2s. co  m*/
    switch (method) {
    case ADD_ASSIGNEES:
        newAssignees.addAll(CloneUtil.cloneCollectionMembers(workItem.getAssigneeRef()));
        break;
    case REPLACE_ASSIGNEES:
        break;
    default:
        throw new UnsupportedOperationException("Delegation method " + method + " is not supported yet.");
    }
    for (ObjectReferenceType delegate : delegates) {
        if (delegate.getType() != null && !QNameUtil.match(UserType.COMPLEX_TYPE, delegate.getType())) {
            throw new IllegalArgumentException("Couldn't use non-user object as a delegate: " + delegate);
        }
        if (delegate.getOid() == null) {
            throw new IllegalArgumentException("Couldn't use no-OID reference as a delegate: " + delegate);
        }
        if (!ObjectTypeUtil.containsOid(newAssignees, delegate.getOid())) {
            newAssignees.add(delegate.clone());
            delegatedTo.add(delegate.clone());
        }
    }
}

From source file:AbstractAmazonKinesisFirehoseDelivery.java

/**
 * Method to put records in the specified delivery stream by reading
 * contents from sample input file using PutRecordBatch API.
 *
 * @throws IOException/*from   w  w  w .j  a  v  a  2  s.  c  om*/
 */
protected static void putRecordBatchIntoDeliveryStream() throws IOException {
    try (InputStream inputStream = Thread.currentThread().getContextClassLoader()
            .getResourceAsStream(BATCH_PUT_STREAM_SOURCE)) {
        if (inputStream == null) {
            throw new FileNotFoundException("Could not find file " + BATCH_PUT_STREAM_SOURCE);
        }

        List<Record> recordList = new ArrayList<Record>();
        int batchSize = 0;
        try (BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream))) {
            String line = null;
            while ((line = reader.readLine()) != null) {
                String data = line + "\n";
                Record record = createRecord(data);
                recordList.add(record);
                batchSize++;

                if (batchSize == BATCH_PUT_MAX_SIZE) {
                    putRecordBatch(recordList);

                    recordList.clear();
                    batchSize = 0;
                }
            }

            if (batchSize > 0) {
                putRecordBatch(recordList);
            }
        }
    }
}

From source file:com.mycompany.asyncreq.Main.java

public static void ObjToCsv(Root tRoot, String reg) throws IOException {
    List<Tdataset> arForms = tRoot.dataset;
    List<ArrayList<String>> tradeDatas = new ArrayList<ArrayList<String>>();

    int count = 0;
    for (Iterator<Tdataset> j = arForms.iterator(); j.hasNext();) {

        Tdataset tmp = j.next();//w  w w  .  j  a va 2s.c o  m
        DateFormat format = new SimpleDateFormat("yyyyMM");
        try {
            Date date = format.parse(tmp.getperiod());
            Ttradedata trade = new Ttradedata(tmp.getrtCode(), tmp.getptCode(), tmp.getrgCode(),
                    tmp.getqtCode(), tmp.getestCode(), date, tmp.getTradeQuantity(), tmp.getNetWeight(),
                    tmp.getTradeValue(), tmp.getcmdCode());

            tradeDatas.add(trade.setString());
            if (tradeDatas.size() % 10000 == 0) {
                writeToCSV(tradeDatas,
                        "data/" + tRoot.dataset.get(0).getptCode() + "_" + count + "_" + reg + ".csv");
                count++;
                tradeDatas.clear();
            }
        } catch (Exception e) {
            System.out.println(e.toString());
        }
    }

    writeToCSV(tradeDatas, "data/" + tRoot.dataset.get(0).getptCode() + "_" + reg + ".csv");
    tradeDatas.clear();
    System.out.println("ok!");

}

From source file:backup.namenode.NameNodeBackupBlockCheckProcessor.java

private static void backupAll(BackupReportWriter writer, ExtendedBlockEnum<Addresses> nnEnum,
        int backupRequestBatchSize, DataNodeBackupRPCLookup rpcLookup) throws Exception {
    writer.startBackupAll();/*  ww  w .  jav a2 s.  c  o  m*/
    List<ExtendedBlockWithAddress> batch = new ArrayList<>();
    if (nnEnum.current() != null) {
        backupBlock(writer, batch, nnEnum, backupRequestBatchSize, rpcLookup);
    }
    while (nnEnum.next() != null) {
        backupBlock(writer, batch, nnEnum, backupRequestBatchSize, rpcLookup);
    }
    if (batch.size() > 0) {
        writer.backupRequestBatch(batch);
        writeBackupRequests(writer, batch, rpcLookup);
        batch.clear();
    }
    writer.completeBackupAll();
}

From source file:edu.ku.brc.helpers.EMailHelper.java

/**
 * Retrieves a list of all the available messages. For POP3 it checks the local mailbox and downloads any on the server.
 *  For IMAP it returns any in the INBOX.
 * @param msgList the list to be filled/*from w  w  w.j  ava2 s. c o  m*/
 * @return true if not erros, false if an error occurred.
 */
public static boolean getAvailableMsgs(java.util.List<javax.mail.Message> msgList) {
    boolean status = false; // assume it will fail

    msgList.clear();

    try {
        String usernameStr = AppPreferences.getRemote().get("settings.email.username", null); //$NON-NLS-1$
        String passwordStr = Encryption
                .decrypt(AppPreferences.getRemote().get("settings.email.password", null)); //$NON-NLS-1$
        String emailStr = AppPreferences.getRemote().get("settings.email.email", null); //$NON-NLS-1$
        String smtpStr = AppPreferences.getRemote().get("settings.email.smtp", null); //$NON-NLS-1$
        String serverNameStr = AppPreferences.getRemote().get("settings.email.servername", null); //$NON-NLS-1$
        String acctTypeStr = AppPreferences.getRemote().get("settings.email.accounttype", null); //$NON-NLS-1$
        String localMailBoxStr = AppPreferences.getRemote().get("settings.email.localmailbox", null); //$NON-NLS-1$

        EMailHelper.AccountType acctType = EMailHelper.getAccountType(acctTypeStr);

        if (!hasEMailSettings(usernameStr, passwordStr, emailStr, smtpStr, serverNameStr, acctTypeStr,
                localMailBoxStr)) {
            JOptionPane.showMessageDialog(UIRegistry.getMostRecentWindow(),
                    getResourceString("EMailHelper.EMAIL_SET_NOT_VALID")); //$NON-NLS-1$
        }

        // Open Local Box if POP
        if (acctTypeStr.equals(getResourceString("EMailHelper.POP3"))) //$NON-NLS-1$
        {
            try {
                Properties props = new Properties();
                Session session = Session.getDefaultInstance(props);

                Store store = session.getStore(new URLName("mstor:" + localMailBoxStr)); //$NON-NLS-1$
                store.connect();
                status = getMessagesFromInbox(store, msgList); // closes everything

            } catch (Exception ex) {
                edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount();
                edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(EMailHelper.class, ex);

                instance.lastErrorMsg = ex.toString();
                ex.printStackTrace();
                status = false;
            }
        } else {
            throw new RuntimeException("Unknown Account Type [" + acctTypeStr + "] must be POP3 or IMAP"); // XXX FIXME //$NON-NLS-1$ //$NON-NLS-2$
        }

        // Try to download message from pop account
        try {
            Properties props = System.getProperties();
            Session session = Session.getInstance(props, null);

            if (acctType == AccountType.POP3) {
                Store store = session.getStore("pop3"); //$NON-NLS-1$
                store.connect(serverNameStr, usernameStr, passwordStr);
                status = getMessagesFromInbox(store, msgList); // closes everything

            } else if (acctType == AccountType.IMAP) {
                Store store = session.getStore("imap"); //$NON-NLS-1$
                store.connect(serverNameStr, usernameStr, passwordStr);
                status = getMessagesFromInbox(store, msgList); // closes everything

            } else {
                String msgStr = getResourceString("EMailHelper.UNKNOWN_ACCT_TYPE")// //$NON-NLS-1$
                        + acctTypeStr + getResourceString("EMailHelper.ACCT_TYPE_MUST_BE"); // XXX// //$NON-NLS-2$

                instance.lastErrorMsg = msgStr;
                throw new RuntimeException(msgStr); // XXX FIXME
            }
        } catch (Exception ex) {
            edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount();
            edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(EMailHelper.class, ex);
            instance.lastErrorMsg = ex.toString();
            status = false;
        }

    } catch (Exception ex) {
        edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount();
        edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(EMailHelper.class, ex);
        instance.lastErrorMsg = ex.toString();
        status = false;
    }
    return status;
}

From source file:org.cbio.portal.pipelines.foundation.CnaDataWriter.java

@Override
public void write(List<? extends String> items) throws Exception {
    writeList.clear();
    List<String> writeList = new ArrayList<String>();
    for (String result : items) {
        writeList.add(result);//from   w ww  .  j a v  a 2 s .c o m
    }
    flatFileItemWriter.write(writeList);
}

From source file:org.cbio.portal.pipelines.foundation.ClinicalDataWriter.java

@Override
public void write(List<? extends CompositeResultBean> items) throws Exception {
    writeList.clear();
    List<String> writeList = new ArrayList<>();
    for (CompositeResultBean result : items) {
        writeList.add(result.getClinicalDataResult());
    }//from   w  ww.  j  a va2  s  . co  m
    flatFileItemWriter.write(writeList);
}