Example usage for java.util HashMap clone

List of usage examples for java.util HashMap clone

Introduction

In this page you can find the example usage for java.util HashMap clone.

Prototype

@SuppressWarnings("unchecked")
@Override
public Object clone() 

Source Link

Document

Returns a shallow copy of this HashMap instance: the keys and values themselves are not cloned.

Usage

From source file:org.shareok.data.sagedata.SageSourceDataHandlerImpl.java

/**
 * Organize the raw data in order to retrieve the necessary information to
 * request the metadata Note: this method is closely depending on the excel
 * file format/*from  w ww  . j  a  v  a 2 s  .c  om*/
 */
@Override
public void processSourceData() {

    if (null == data || data.isEmpty()) {
        readSourceData();
        if (null == data || data.isEmpty()) {
            return;
        }
    }

    try {
        Set keys = data.keySet();
        Iterator it = keys.iterator();
        int rowPre = 0;

        HashMap articleData = new HashMap();

        while (it.hasNext()) {
            String key = (String) it.next();
            String value = (String) data.get(key);
            // the values is composed of "val--datatype": for example, Tom--Str or 0.50--num
            String[] values = value.split("--");
            if (null == values || values.length != 2) {
                continue;
            }

            value = values[0];
            String[] rowCol = key.split("-");
            if (null == rowCol || rowCol.length != 2) {
                throw new Exception("The row and column are not specifid!");
            }
            int row = Integer.parseInt(rowCol[0]);
            int col = Integer.parseInt(rowCol[1]);

            if (row != rowPre) {
                rowPre = row;
                if (null != articleData && !articleData.isEmpty()) {
                    if (null == itemData) {
                        itemData = new ArrayList<HashMap>();
                    }
                    Object articleDataCopy = articleData.clone();
                    itemData.add((HashMap) articleDataCopy);
                    articleData.clear();
                }
            }

            if (0 != row) {
                switch (col) {
                case 0:
                    articleData.put("journal", value);
                    break;
                case 2:
                    articleData.put("title", value);
                    break;
                case 3:
                    articleData.put("volume", value);
                    break;
                case 4:
                    articleData.put("issue", value);
                    break;
                case 5:
                    articleData.put("pages", value);
                    break;
                case 6:
                    articleData.put("year", value);
                    break;
                case 7:
                    articleData.put("citation", value);
                    break;
                case 8:
                    articleData.put("pubdate", value);
                    break;
                case 9:
                    articleData.put("doi", value);
                    break;
                case 10:
                    articleData.put("url", value);
                    break;
                default:
                    break;
                }
            }

        }

        // Put the last article into itemData:
        if (null != articleData && !articleData.isEmpty()) {
            if (null == itemData) {
                itemData = new ArrayList<HashMap>();
            }
            Object articleDataCopy = articleData.clone();
            itemData.add((HashMap) articleDataCopy);
            articleData.clear();
        }

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

}

From source file:com.hangum.tadpole.rdb.core.editors.objects.table.TableDirectEditorComposite.java

/**
 * ??  .//from   w w  w .  j  a  v a 2s  .c om
 * 
 * 1) ResultSetMetaData  ??  ? .
 * 
 * @param strWhere
 * @param strOrderBy
 */
private void runSQLSelect(String strWhere, String strOrderBy) throws Exception {
    String requestQuery = "SELECT "; //$NON-NLS-1$

    if (userDB.getDBDefine() == DBDefine.ORACLE_DEFAULT) {
        requestQuery += " rowid, "; //$NON-NLS-1$
    } else if (userDB.getDBDefine() == DBDefine.POSTGRE_DEFAULT) {
        requestQuery += " ctid, "; //$NON-NLS-1$
    }
    List<TableColumnDAO> tmpTableColumns = TadpoleObjectQuery.getTableColumns(userDB, tableDao);
    for (int i = 0; i < tmpTableColumns.size(); i++) {
        TableColumnDAO tabledao = tmpTableColumns.get(i);
        requestQuery += tabledao.getName();
        if (i < (tmpTableColumns.size() - 1))
            requestQuery += ","; //$NON-NLS-1$
    }

    requestQuery += " FROM " + SQLUtil.getTableName(userDB, tableDao);

    if (!"".equals(strWhere)) //$NON-NLS-1$
        requestQuery += " where " + strWhere; //$NON-NLS-1$
    if (!"".equals(strOrderBy)) //$NON-NLS-1$
        requestQuery += " order by " + strOrderBy; //$NON-NLS-1$
    if (logger.isDebugEnabled())
        logger.debug("Last query is " + requestQuery);

    ResultSet rs = null;
    java.sql.Connection javaConn = null;

    try {
        SqlMapClient client = TadpoleSQLManager.getInstance(userDB);
        javaConn = client.getDataSource().getConnection();

        PreparedStatement stmt = null;
        stmt = javaConn.prepareStatement(requestQuery);
        stmt.setMaxRows(GetPreferenceGeneral.getSelectLimitCount());

        rs = stmt.executeQuery();

        // table column? 
        ResultSetMetaData rsm = rs.getMetaData();
        int columnCount = rsm.getColumnCount();
        for (int i = 0; i < rsm.getColumnCount(); i++) {
            //            if(logger.isDebugEnabled()) logger.debug(i + "[type]" + rsm.getColumnClassName(i+1) ); //$NON-NLS-1$
            tableDataTypeList.put(i, rsm.getColumnClassName(i + 1));
        }

        // rs set? ?? 
        tableDataList = new ArrayList<Map<Integer, Object>>();
        originalDataList = new ArrayList<Map<Integer, Object>>();
        HashMap<Integer, Object> tmpRs = null;

        mapColumns = ResultSetUtils.getColumnName(rs);

        while (rs.next()) {
            tmpRs = new HashMap<Integer, Object>();

            /** column modify info */
            tmpRs.put(0, TbUtils.COLUMN_MOD_TYPE.NONE.toString());

            for (int i = 1; i < columnCount + 1; i++) {
                try {
                    String strValue = rs.getString(i) == null ? "" : rs.getString(i);
                    //                  System.out.println("ogiginal: "+ strValue);
                    //                  strValue = StringEscapeUtils.unescapeHtml(strValue);
                    //                  System.out.println("unescapeHtml: "+ strValue);
                    //                  strValue = StringEscapeUtils.unescapeXml(strValue);
                    //                  System.out.println("unescapeXml: "+ strValue);
                    strValue = StringEscapeUtils.escapeXml(strValue);

                    tmpRs.put(i, strValue); //$NON-NLS-1$
                } catch (Exception e) {
                    logger.error("ResutSet fetch error", e); //$NON-NLS-1$
                    tmpRs.put(i, ""); //$NON-NLS-1$
                }
            }

            tableDataList.add(tmpRs);
            // ??  update where  .
            Map<Integer, Object> clondRs = (Map<Integer, Object>) tmpRs.clone();
            originalDataList.add(clondRs);
        }

    } finally {
        try {
            rs.close();
        } catch (Exception e) {
        }
        try {
            javaConn.close();
        } catch (Exception e) {
        }
    }
}

From source file:no.abmu.finances.service.hibernate3.FinanceServiceHelperH3Impl.java

private SchemaList getSubReportDataForKkdInstitutionsBySchemaTypeAndVersion(SchemaList jasperReportDataSource,
        String schemaTypeName, String schemaVersion, String subSchemaName, String prefix) {

    SchemaList newJasperReportDataSource = new SchemaList();
    MainReportData mainReportData;/* ww w  . j  a  v a  2s  .  c  o  m*/

    HashMap report;
    Map subReport;
    String orgUnitName;
    String kommuneNr;
    List initiatives;

    SubReportData initiative = null;
    Integer iniativPriority;

    Iterator iterator = jasperReportDataSource.iterator();
    while (iterator.hasNext()) {
        report = (HashMap) iterator.next();
        orgUnitName = (String) report.get("name");
        kommuneNr = (String) report.get("kommuneNr");
        if (logger.isDebugEnabled()) {
            logger.debug("getSubReportDataBySchemaTypeAndVersion -- Starting on organisationUnit ["
                    + orgUnitName + "] with municipality number [" + kommuneNr + "]");
        }

        mainReportData = getMainReportData(report, schemaTypeName, schemaVersion);

        if (mainReportData == null) {
            if (logger.isDebugEnabled()) {
                logger.debug("getSubReportDataBySchemaTypeAndVersion "
                        + "-- No Report exist for organisationUnit [" + orgUnitName + "]");
            }
            continue;
        }

        timeStampReport(report);
        integerFromReportDataToJasperReport(report, mainReportData, 417, 417, prefix);

        initiatives = mainReportData.getSubReportDataList(subSchemaName);
        if (initiatives == null || initiatives.size() == 0) {
            iniativPriority = Integer.valueOf(1);
            subReport = (HashMap) report.clone();
            subReport.put("priority", iniativPriority);
            subReport.put("01", "Viderefring av driftstilskudd");
            subReport.put("05", Integer.valueOf(0));
            subReport.put("30", "Har ikke skt om kning i forhold til rets tilskudd.");

            if (logger.isDebugEnabled()) {
                logger.info("getSubReportDataBySchemaTypeAndVersion "
                        + "-- No Iniatives exist for organisationUnit [" + orgUnitName + "]");
            }
            newJasperReportDataSource.add(subReport);
            continue;
        }

        if (logger.isDebugEnabled()) {
            logger.debug("getSubReportDataBySchemaTypeAndVersion " + "-- organisationUnit [" + orgUnitName
                    + "] has [" + initiatives.size() + "]");
        }

        for (int index = 0; index < initiatives.size(); index++) {
            iniativPriority = new Integer(index + 1);
            initiative = (SubReportData) initiatives.get(index);
            subReport = (HashMap) report.clone();

            timeStampReport(subReport);
            subReport.put("priority", iniativPriority);

            subReport = fillInSubReportValues(subReport, initiative, subSchemaName, schemaVersion, prefix);
            if (logger.isDebugEnabled()) {
                logger.debug("Subreport schema size for iniativ priority [" + iniativPriority + "] is ["
                        + subReport.size() + "]");
            }
            newJasperReportDataSource.add(subReport);
        }
    }
    return newJasperReportDataSource;
}

From source file:org.talend.designer.core.model.process.DataProcess.java

private void copyElementParametersValue(IElement sourceElement, IElement targetElement) {
    for (IElementParameter sourceParam : sourceElement.getElementParameters()) {
        IElementParameter targetParam = targetElement.getElementParameter(sourceParam.getName());
        if (targetParam != null) {
            if (sourceParam.getName().equals(EParameterName.DB_TYPE.getName())
                    && sourceParam.getValue().toString().matches("^.*[a|A][c|C][c|C][e|E][s|S][s|S].*$")) {

                sourceElement.getElementParameter(EParameterName.DBNAME.getName()).setValue(
                        sourceElement.getElementParameter(EParameterName.DBFILE.getName()).getValue());
            }//from ww  w  . ja va2  s . co m

            targetParam.setContextMode(sourceParam.isContextMode());
            targetParam.setValue(sourceParam.getValue());
            if (sourceParam.getValue() instanceof List) {
                List sourceList = (List) sourceParam.getValue();
                List targetList = new ArrayList();
                // if HashMap in List ,need clone deeply
                for (Object map : sourceList) {
                    if (map instanceof HashMap) {
                        HashMap oldMap = (HashMap) map;
                        targetList.add(oldMap.clone());
                    }
                }
                if (targetList.size() > 0) {
                    targetParam.setValue(targetList);
                } else {
                    targetParam.setValue(new ArrayList(sourceList));
                }
            }
            if (targetParam.getFieldType() == EParameterFieldType.TABLE) {

                // targetParam.setValue( sourceParam.getValue());
                targetParam.setListItemsValue(ArrayUtils.clone(sourceParam.getListItemsValue()));
                targetParam.setListItemsDisplayCodeName(sourceParam.getListItemsDisplayCodeName());
            }
            for (String name : targetParam.getChildParameters().keySet()) {
                IElementParameter targetChildParam = targetParam.getChildParameters().get(name);
                if (sourceParam.getChildParameters() == null) {
                    continue;
                }
                IElementParameter sourceChildParam = sourceParam.getChildParameters().get(name);
                targetChildParam.setValue(sourceChildParam.getValue());
                if (targetChildParam.getFieldType() == EParameterFieldType.TABLE) {
                    targetChildParam.setListItemsValue(sourceChildParam.getListItemsValue());
                    targetChildParam
                            .setListItemsDisplayCodeName(sourceChildParam.getListItemsDisplayCodeName());
                }
            }
        } else { // for feature TDI-24448,we need the new parameter here,do not init() it in the Connnection
            ElementParameter newParam = (ElementParameter) sourceParam.getClone();
            List<IElementParameter> listParam = (List<IElementParameter>) targetElement.getElementParameters();
            listParam.add(newParam);
        }
    }
}

From source file:no.abmu.finances.service.hibernate3.FinanceServiceHelperH3Impl.java

private SchemaList getSubReportDataBySchemaTypeAndVersion(SchemaList jasperReportDataSource,
        String schemaTypeName, String schemaVersion, String subSchemaName, String prefix) {

    SchemaList newJasperReportDataSource = new SchemaList();
    MainReportData mainReportData;//from www. j  a  v a 2 s . c o  m

    HashMap report;
    Map subReport;
    String orgUnitName;
    String kommuneNr;
    List initiatives;

    SubReportData initiative = null;
    Integer iniativPriority;

    Iterator iterator = jasperReportDataSource.iterator();
    while (iterator.hasNext()) {
        report = (HashMap) iterator.next();
        orgUnitName = (String) report.get("name");
        kommuneNr = (String) report.get("kommuneNr");
        if (logger.isDebugEnabled()) {
            logger.debug("getSubReportDataBySchemaTypeAndVersion -- Starting on organisationUnit ["
                    + orgUnitName + "] with municipality number [" + kommuneNr + "]");
        }

        mainReportData = getMainReportData(report, schemaTypeName, schemaVersion);

        if (mainReportData == null) {
            if (logger.isDebugEnabled()) {
                logger.debug("getSubReportDataBySchemaTypeAndVersion "
                        + "-- No Report exist for organisationUnit [" + orgUnitName + "]");
            }
            continue;
        }

        timeStampReport(report);
        integerFromReportDataToJasperReport(report, mainReportData, 417, 417, prefix);

        initiatives = mainReportData.getSubReportDataList(subSchemaName);
        if (initiatives == null || initiatives.size() == 0) {
            if (logger.isDebugEnabled()) {
                logger.info("getSubReportDataBySchemaTypeAndVersion "
                        + "-- No Iniatives exist for organisationUnit [" + orgUnitName + "]");
            }
            continue;
        }

        if (logger.isDebugEnabled()) {
            logger.debug("getSubReportDataBySchemaTypeAndVersion " + "-- organisationUnit [" + orgUnitName
                    + "] has [" + initiatives.size() + "]");
        }

        for (int index = 0; index < initiatives.size(); index++) {
            iniativPriority = new Integer(index + 1);
            initiative = (SubReportData) initiatives.get(index);
            subReport = (HashMap) report.clone();

            subReport.put("priority", iniativPriority);

            subReport = fillInSubReportValues(subReport, initiative, subSchemaName, schemaVersion, prefix);
            if (logger.isDebugEnabled()) {
                logger.debug("Subreport schema size for iniativ priority [" + iniativPriority + "] is ["
                        + subReport.size() + "]");
            }
            newJasperReportDataSource.add(subReport);
        }
    }
    return newJasperReportDataSource;
}