Example usage for java.util Hashtable containsValue

List of usage examples for java.util Hashtable containsValue

Introduction

In this page you can find the example usage for java.util Hashtable containsValue.

Prototype

public boolean containsValue(Object value) 

Source Link

Document

Returns true if this hashtable maps one or more keys to this value.

Usage

From source file:Main.java

public static void main(String args[]) {
    Hashtable<Integer, String> htable = new Hashtable<Integer, String>();

    // put values into the table
    htable.put(1, "A");
    htable.put(2, "B");
    htable.put(3, "C");
    htable.put(4, "from java2s.com");

    // check if table contains value "C"
    boolean isavailable = htable.containsValue("C");

    // display search result
    System.out.println("Hash table contains value 'C': " + isavailable);
}

From source file:com.krawler.esp.servlets.exportExcel.java

public void exportexcel(HttpServletResponse response, JSONObject jobj, java.util.Hashtable ht,
        String sheetTitle, String fileName, JSONArray hdr, JSONArray xlshdr, String heading, String[] xtypeArr,
        com.krawler.spring.exportFunctionality.exportDAOImpl exportDao) throws ServletException, IOException {
    try {// www  .  ja v a2  s  .  c om
        response.setContentType("application/vnd.ms-excel");
        if (!StringUtil.isNullOrEmpty(heading)) {
            fileName = heading + fileName;
        }
        response.setHeader("Content-Disposition", "attachement; filename=" + fileName + ".xls");
        HSSFSheet sheet = wb.createSheet(sheetTitle);
        CellStyle cs = wb.createCellStyle();
        cs.setWrapText(true);

        HSSFHeader hh = sheet.getHeader();
        int j = 1;
        int width = 0;
        int maxrowno = 0;
        HSSFRow row1 = sheet.createRow((short) maxrowno);
        HashMap hm = extractData(jobj);
        JSONArray jarr = (JSONArray) hm.get("data");
        JSONObject tempObj;
        for (int k = 0; k < jarr.length(); k++) {
            tempObj = jarr.getJSONObject(k);
            HSSFRow row = sheet.createRow((short) j);
            int cellcount = 0;
            for (int i = 0; i < hdr.length(); i++) {
                Object str = tempObj.optString(hdr.getString(i), "");
                try {
                    if (xtypeArr.length > 0) {
                        str = convertValue(tempObj.optString(hdr.getString(i), ""), xtypeArr[i]);
                    }
                } catch (Exception e) {

                }
                if (ht.containsValue(hdr.getString(i))) {
                    if (j == maxrowno + 1) {
                        HSSFCell cell1 = row1.createCell(cellcount);
                        cell1.setCellStyle(cs);

                        width = xlshdr.getString(i).length() * 325;
                        if (width > sheet.getColumnWidth(cellcount)) {
                            sheet.setColumnWidth(cellcount, width);
                        }
                        HSSFFont font = wb.createFont();
                        font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
                        HSSFRichTextString hst = new HSSFRichTextString(xlshdr.getString(i));
                        hst.applyFont(font);
                        cell1.setCellValue(hst);

                    }
                    HSSFCell cell = row.createCell(cellcount);
                    cell.setCellStyle(cs);

                    if (str instanceof Date) {
                        cal.setTime((Date) str);
                        cell.setCellValue(cal);
                        cell.setCellStyle(this.dateCellStyle);
                        width = 4500;
                    } else if (str instanceof Number) {
                        cell.setCellValue(((Number) str).doubleValue());
                        width = 4500;
                    } else {
                        String colvalue = str.toString();
                        cell.setCellValue(new HSSFRichTextString(colvalue));
                        width = colvalue.length() * 325;
                    }

                    width = Math.min(width, MAX_CELL_WIDTH);

                    if (width > sheet.getColumnWidth(cellcount)) {
                        sheet.setColumnWidth(cellcount, width);
                    }

                    cellcount++;
                }
            }
            j++;

        }

        ConfigReader cr = ConfigReader.getinstance();
        String dirpath = cr.get("store");
        String path = dirpath + "baitheader.png";

        //                this.addimage(path,HSSFWorkbook.PICTURE_TYPE_PNG, wb, sheet,0,0,0,0,0,0,12,4);
        if (true) {
            OutputStream out = response.getOutputStream();
            wb.write(out);
            out.close();
        }
    } catch (JSONException ex) {
        Logger.getLogger(exportExcel.class.getName()).log(Level.SEVERE, null, ex);
    } catch (Exception ex) {
        Logger.getLogger(exportExcel.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:io.github.msdk.features.ransacaligner.RansacAlignerMethod.java

private Hashtable<FeatureTableRow, FeatureTableRow> getAlignmentMap(FeatureTable featureTable) {

    // Create a table of mappings for best scores
    Hashtable<FeatureTableRow, FeatureTableRow> alignmentMapping = new Hashtable<FeatureTableRow, FeatureTableRow>();

    // Create a sorted set of scores matching
    TreeSet<RowVsRowScore> scoreSet = new TreeSet<RowVsRowScore>();

    // RANSAC algorithm
    List<AlignStructMol> list = ransacPeakLists(result, featureTable);
    PolynomialFunction function = this.getPolynomialFunction(list);

    List<FeatureTableRow> allRows = featureTable.getRows();

    for (FeatureTableRow row : allRows) {
        // Calculate limits for a row with which the row can be aligned
        Range<Double> mzRange = mzTolerance.getToleranceRange(row.getMz());

        double rt;
        try {/* ww  w  .j  av a2  s .  co  m*/
            rt = function.value(row.getChromatographyInfo().getRetentionTime());
        } catch (NullPointerException e) {
            rt = row.getChromatographyInfo().getRetentionTime();
        }
        if (Double.isNaN(rt) || rt == -1) {
            rt = row.getChromatographyInfo().getRetentionTime();
        }

        Range<Double> rtRange = rtToleranceAfterCorrection.getToleranceRange(rt);

        // Get all rows of the aligned feature table within the m/z and
        // RT limits
        List<FeatureTableRow> candidateRows = result.getRowsInsideRange(rtRange, mzRange);

        for (FeatureTableRow candidateRow : candidateRows) {
            RowVsRowScore score;
            if (requireSameCharge) {
                FeatureTableColumn<Integer> chargeColumn1 = featureTable.getColumn(ColumnName.CHARGE, null);
                FeatureTableColumn<Integer> chargeColumn2 = result.getColumn(ColumnName.CHARGE, null);
                Integer charge1 = row.getData(chargeColumn1);
                Integer charge2 = candidateRow.getData(chargeColumn2);
                if (!charge1.equals(charge2))
                    continue;
            }

            // Check ion annotation
            if (requireSameAnnotation) {
                FeatureTableColumn<List<IonAnnotation>> ionAnnotationColumn1 = featureTable
                        .getColumn(ColumnName.IONANNOTATION, null);
                FeatureTableColumn<List<IonAnnotation>> ionAnnotationColumn2 = result
                        .getColumn(ColumnName.IONANNOTATION, null);
                List<IonAnnotation> ionAnnotations1 = row.getData(ionAnnotationColumn1);
                List<IonAnnotation> ionAnnotations2 = candidateRow.getData(ionAnnotationColumn2);

                // Check that all ion annotations in first row are in
                // the candidate row
                boolean equalIons = false;
                if (ionAnnotations1 != null && ionAnnotations2 != null) {
                    for (IonAnnotation ionAnnotation : ionAnnotations1) {
                        for (IonAnnotation targetIonAnnotation : ionAnnotations2) {
                            if (targetIonAnnotation.compareTo(ionAnnotation) == 0)
                                equalIons = true;
                        }
                    }
                }
                if (!equalIons)
                    continue;

            }

            try {
                double mzLength = mzRange.upperEndpoint() - mzRange.lowerEndpoint();
                double rtLength = rtRange.upperEndpoint() - rtRange.lowerEndpoint();
                score = new RowVsRowScore(row, candidateRow, mzLength, rtLength, new Float(rt));

                scoreSet.add(score);

            } catch (Exception e) {
                return null;
            }
        }
    }

    // Iterate scores by descending order
    Iterator<RowVsRowScore> scoreIterator = scoreSet.iterator();
    while (scoreIterator.hasNext()) {

        RowVsRowScore score = scoreIterator.next();

        // Check if the row is already mapped
        if (alignmentMapping.containsKey(score.getFeatureTableRow())) {
            continue;
        }

        // Check if the aligned row is already filled
        if (alignmentMapping.containsValue(score.getAlignedRow())) {
            continue;
        }

        alignmentMapping.put(score.getFeatureTableRow(), score.getAlignedRow());

    }

    return alignmentMapping;
}

From source file:org.apache.axis2.description.AxisService.java

/**
 * A quick private sub routine to insert the names
 * /* w  w  w  . j  a va  2 s .c  o  m*/
 * @param nameTable
 * @param s
 */
private void insertIntoNameTable(Hashtable nameTable, XmlSchema s, Hashtable sourceURIToNewLocationMap,
        boolean overrideAbsoluteAddress) {
    String sourceURI = s.getSourceURI();
    // check whether the sourece uri is an absolute one and are
    // we allowed to override it.
    // if the absolute uri overriding is not allowed the use the
    // original sourceURI as new one
    if (sourceURI.startsWith("http") && !overrideAbsoluteAddress) {
        nameTable.put(s, sourceURI);
        sourceURIToNewLocationMap.put(sourceURI, sourceURI);
    } else {
        String newURI = sourceURI.substring(sourceURI.lastIndexOf('/') + 1);
        if (newURI.endsWith(".xsd")) {
            // remove the .xsd extention
            newURI = newURI.substring(0, newURI.lastIndexOf("."));
        } else {
            newURI = "xsd" + count++;
        }

        newURI = customSchemaNameSuffix != null ? newURI + customSchemaNameSuffix : newURI;
        // make it unique
        while (nameTable.containsValue(newURI)) {
            newURI = newURI + count++;
        }

        nameTable.put(s, newURI);
        sourceURIToNewLocationMap.put(sourceURI, newURI);
    }

}