Example usage for java.util HashMap containsKey

List of usage examples for java.util HashMap containsKey

Introduction

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

Prototype

public boolean containsKey(Object key) 

Source Link

Document

Returns true if this map contains a mapping for the specified key.

Usage

From source file:com.propelics.pdfcreator.PdfcreatorModule.java

/**
 * @method generatePDFWithHTML/*from   w w  w  .  j  a  va 2s.  com*/
 * Generates a PDF with the given file name, based on a HTML file
 * @param {String} filename Name of the PDF file
 * @param {String} html String with the HTML
 * @param {String} [author] Author for metadata
 * Fires a "complete" event when the PDF is generated
 * Fires a "error" event when a error is presented
 */
@Kroll.method(runOnUiThread = true)
public void generatePDFWithHTML(final HashMap args) {
    Log.d(PROXY_NAME, "generatePDFWithHTML()");

    String html = "";
    String author = "";
    String filename = "";
    final float marginPt = 28.35f;//1cm == 28.35pt

    try {
        if (args.containsKey("filename")) {
            filename = (String) args.get("filename");
            Log.d(PROXY_NAME, "filename: " + filename);
        } else
            return;

        if (args.containsKey("html")) {
            html = (String) args.get("html");
            Log.d(PROXY_NAME, "html: " + html);
        } else
            return;

        if (args.containsKey("author")) {
            author = (String) args.get("author");
            Log.d(PROXY_NAME, "author: " + author);
        }

        //create a new document
        Document document = new Document(PageSize.LETTER, marginPt, marginPt, marginPt, 0);
        TiBaseFile file = TiFileFactory.createTitaniumFile(filename, true);

        // Parse to XHTML
        StringWriter xhtmlWriter = new StringWriter();
        Tidy tidy = new Tidy();

        // tidy.setXHTML(true);
        tidy.setXmlOut(true);
        tidy.parse(new StringReader(html), xhtmlWriter);
        String xhtml = xhtmlWriter.toString();

        //get Instance of the PDFWriter
        PdfWriter pdfWriter = PdfWriter.getInstance(document, file.getOutputStream());

        //document header attributes
        document.addAuthor(author);
        document.addCreationDate();
        document.setPageSize(PageSize.LETTER);

        //open document
        document.open();

        // From Stack Overflow lol

        MyFontFactory fontFactory = new MyFontFactory();
        FontFactory.setFontImp(fontFactory);

        // HtmlPipelineContext htmlContext = new HtmlPipelineContext(new CssAppliersImpl(fontFactory));
        HtmlPipelineContext htmlContext = new HtmlPipelineContext(null);
        htmlContext.setTagFactory(Tags.getHtmlTagProcessorFactory());
        CSSResolver cssResolver = XMLWorkerHelper.getInstance().getDefaultCssResolver(true);
        Pipeline<?> pipeline = new CssResolverPipeline(cssResolver,
                new HtmlPipeline(htmlContext, new PdfWriterPipeline(document, pdfWriter)));
        XMLWorker worker = new XMLWorker(pipeline, true);
        XMLParser p = new XMLParser(worker);
        p.parse(new StringReader(xhtml));

        // Finish SO c&P

        // Older code
        /*
        // Font Provider creation
        MyFontFactory fontProvider = new MyFontFactory();
        // fontProvider.register("/DroidSans.ttf");
                
        //get the XMLWorkerHelper Instance
        XMLWorkerHelper worker = XMLWorkerHelper.getInstance();
        //convert to PDF
        worker.parseXHtml(pdfWriter, document, new ByteArrayInputStream(xhtml.getBytes("UTF-8")), null, fontProvider); //Load xhtml
        */

        //close the document
        document.close();
        //close the writer
        pdfWriter.close();

        sendCompleteEvent(filename);

    } catch (Exception e) {
        sendErrorEvent(e);
    }
}

From source file:edu.umass.cs.gigapaxos.PaxosPacketBatcher.java

private boolean enqueueImpl(BatchedAccept bAccept) {
    assert (bAccept.getPaxosID() != null);
    if (!this.accepts.containsKey(bAccept.getPaxosID()))
        this.accepts.put(bAccept.getPaxosID(), new HashMap<Ballot, BatchedAccept>());
    HashMap<Ballot, BatchedAccept> aMap = this.accepts.get(bAccept.getPaxosID());
    boolean added = false;
    if (aMap.isEmpty())
        added = (aMap.put(bAccept.ballot, (bAccept)) != null);
    else if (aMap.containsKey(bAccept.ballot))
        added = aMap.get(bAccept.ballot).addBatchedAccept(bAccept);
    else/*from   w  ww  .ja  va 2s. c o  m*/
        added = (aMap.put(bAccept.ballot, (bAccept)) != null);

    return added;

}

From source file:com.krawler.spring.crm.spreadsheet.CrmSpreadsheetServiceImpl.java

private void getReportLinks(HashMap<String, Integer> reportsPermMap, JSONArray jarr, String module,
        Locale locale) throws ServiceException {
    if (Constants.moduleMap.containsKey(module)) {
        JSONArray arr = new JSONArray();
        switch (Constants.moduleMap.get(module)) {
        case 1: // Lead
            int reportPerm = reportsPermMap.containsKey(Constants.LEAD_REPORT_PERMNAME)
                    ? reportsPermMap.get(Constants.LEAD_REPORT_PERMNAME)
                    : 0;// w  w  w .  j  a  v a2  s .  c o  m
            jarr.put(crmdashboardHandler.getLeadsReportsLink(reportPerm, new ArrayList(), locale));
            break;
        case 2: // Opportunity
            reportPerm = reportsPermMap.containsKey(Constants.OPP_REPORT_PERMNAME)
                    ? reportsPermMap.get(Constants.OPP_REPORT_PERMNAME)
                    : 0;
            arr = crmdashboardHandler.getOpportunityReportsLink(reportPerm, new ArrayList(), locale);
            reportPerm = reportsPermMap.containsKey(Constants.SALES_REPORT_PERMNAME)
                    ? reportsPermMap.get(Constants.SALES_REPORT_PERMNAME)
                    : 0;
            JSONObject temp = crmdashboardHandler.getSalesReportsLink(reportPerm, new ArrayList(), locale);
            if (temp != null) {
                arr.put(temp);
            }
            jarr.put(arr);
            break;
        case 3: // Account
            reportPerm = reportsPermMap.containsKey(Constants.ACCOUNT_REPORT_PERMNAME)
                    ? reportsPermMap.get(Constants.ACCOUNT_REPORT_PERMNAME)
                    : 0;
            jarr.put(crmdashboardHandler.getAccountReportsLink(reportPerm, new ArrayList(), locale));
            break;
        case 4: // Contact
            reportPerm = reportsPermMap.containsKey(Constants.CONTACT_REPORT_PERMNAME)
                    ? reportsPermMap.get(Constants.CONTACT_REPORT_PERMNAME)
                    : 0;
            jarr.put(crmdashboardHandler.getContactReportsLink(reportPerm, new ArrayList(), locale));
            break;
        case 5: // Product
            reportPerm = reportsPermMap.containsKey(Constants.PRODUCT_REPORT_PERMNAME)
                    ? reportsPermMap.get(Constants.PRODUCT_REPORT_PERMNAME)
                    : 0;
            jarr.put(crmdashboardHandler.getProductReportsLink(reportPerm, new ArrayList(), locale));
            break;
        case 6: // Case
            reportPerm = reportsPermMap.containsKey(Constants.CASE_REPORT_PERMNAME)
                    ? reportsPermMap.get(Constants.CASE_REPORT_PERMNAME)
                    : 0;
            jarr.put(crmdashboardHandler.getCaseReportsLink(reportPerm, new ArrayList(), locale));
            break;
        case 7: // Activity
            reportPerm = reportsPermMap.containsKey(Constants.ACTIVITY_REPORT_PERMNAME)
                    ? reportsPermMap.get(Constants.ACTIVITY_REPORT_PERMNAME)
                    : 0;
            jarr.put(crmdashboardHandler.getActivityReportsLink(reportPerm, new ArrayList(), locale));
            break;
        case 8: // Campaign
            reportPerm = reportsPermMap.containsKey(Constants.CAMPAIGN_REPORT_PERMNAME)
                    ? reportsPermMap.get(Constants.CAMPAIGN_REPORT_PERMNAME)
                    : 0;
            jarr.put(crmdashboardHandler.getCampaignReportsLink(reportPerm, new ArrayList(), locale));
            break;
        }
    } else {
        if (module.endsWith("Activity")) {
            int reportPerm = reportsPermMap.containsKey(Constants.ACTIVITY_REPORT_PERMNAME)
                    ? reportsPermMap.get(Constants.ACTIVITY_REPORT_PERMNAME)
                    : 0;
            jarr.put(crmdashboardHandler.getActivityReportsLink(reportPerm, new ArrayList(), locale));
        } else {
            if (module.endsWith("Contact")) {
                int reportPerm = reportsPermMap.containsKey(Constants.CONTACT_REPORT_PERMNAME)
                        ? reportsPermMap.get(Constants.CONTACT_REPORT_PERMNAME)
                        : 0;
                jarr.put(crmdashboardHandler.getContactReportsLink(reportPerm, new ArrayList(), locale));
            }
        }
    }

}

From source file:GeneticAlgorithm.SystemToSolve.java

private boolean is_there_metabolites(HashMap data) {
    boolean is_it_there = false;
    int count = 0;
    for (Compound compound : Compounds) {
        if (compound.getBoundaryCondition() == false) {
            String compound_ID = compound.getID();
            if (data.containsKey(compound_ID)) {
                count++;/*w  w  w . j a  v  a  2s .co  m*/
            }
        }
    }
    if (count > 0) {
        is_it_there = true;
    }
    return is_it_there;
}

From source file:com.akop.bach.parser.PsnParser.java

protected ArrayList<HashMap<String, String>> parsePairsInSimpleXml(String document, String nodeName) {
    Pattern outerNode = Pattern.compile("<" + nodeName + "(?:\\s+[^>]*)?>(.*?)</" + nodeName + ">",
            Pattern.DOTALL);/*from w ww  .  jav  a2 s  . c  om*/
    Pattern innerNode = Pattern.compile("<(\\w+)[^>]*>([^<]*)</\\1>");

    ArrayList<HashMap<String, String>> kvpList = new ArrayList<HashMap<String, String>>();

    Matcher nodeMatcher = outerNode.matcher(document);
    while (nodeMatcher.find()) {
        String content = nodeMatcher.group(1);

        Matcher m = innerNode.matcher(content);
        HashMap<String, String> items = new HashMap<String, String>();

        while (m.find()) {
            String innerNodeName = m.group(1);
            if (items.containsKey(innerNodeName))
                continue;

            items.put(innerNodeName, m.group(2));
        }

        if (items.size() > 0)
            kvpList.add(items);
    }

    return kvpList;
}

From source file:com.example.camera360.ui.ImageDetailActivity.java

private void doFavoriteUsers() {

    HashMap<String, String> map = arrayList.get(currentIndex);

    if (map.containsKey("favoriteInfo")) {
        mImageDetailLoad.setVisibility(View.GONE);

        mImageDetailText.setText(map.get("favoriteInfo"));
    } else {//from  w  ww  .jav  a2s .c  o  m
        mImageDetailLoad.setVisibility(View.VISIBLE);

        mImageDetailText.setText(R.string.image_detail);

        List<NameValuePair> paramsList = new ArrayList<NameValuePair>();
        paramsList.add(new BasicNameValuePair("activityId", "526e399c8852d6ad68680fc3"));
        paramsList.add(new BasicNameValuePair("pid", arrayList.get(currentIndex).get("id")));
        Server.response = "post";

        new FavoriteUsersServer(BaseImages.SITE_URL + "activity/picture/favoriteUsers", paramsList,
                currentIndex);
    }
}

From source file:com.linkedin.pinot.tools.admin.command.GenerateDataCommand.java

private DataGeneratorSpec buildDataGeneratorSpec(Schema schema, List<String> columns,
        HashMap<String, DataType> dataTypes, HashMap<String, FieldType> fieldTypes,
        HashMap<String, TimeUnit> timeUnits, HashMap<String, Integer> cardinality,
        HashMap<String, IntRange> range) {
    for (final FieldSpec fs : schema.getAllFieldSpecs()) {
        String col = fs.getName();

        columns.add(col);//  w  w  w .  j  av a 2 s. co m
        dataTypes.put(col, fs.getDataType());
        fieldTypes.put(col, fs.getFieldType());

        switch (fs.getFieldType()) {
        case DIMENSION:
            if (cardinality.get(col) == null) {
                cardinality.put(col, 1000);
            }
            break;

        case METRIC:
            if (!range.containsKey(col)) {
                range.put(col, new IntRange(1, 1000));
            }
            break;

        case TIME:
            if (!range.containsKey(col)) {
                range.put(col, new IntRange(1, 1000));
            }
            TimeFieldSpec tfs = (TimeFieldSpec) fs;
            timeUnits.put(col, tfs.getIncomingGranularitySpec().getTimeType());
            break;

        default:
            throw new RuntimeException("Invalid field type.");
        }
    }

    return new DataGeneratorSpec(columns, cardinality, range, dataTypes, fieldTypes, timeUnits, FileFormat.AVRO,
            _outDir, _overwrite);
}

From source file:com.jaspersoft.studio.handlers.ResourcePage.java

/**
 * Read from the report the list of the resources that it use and show them into
 * a table. Search and identify also the conflicts between the resources
 *//*from   w  w w.j  av  a2 s  .co m*/
public void fillData() {
    resourceList = getResourceNames();
    HashMap<String, File> resourceMap = new HashMap<String, File>();
    List<String> conflicts = new ArrayList<String>();
    for (File actualResource : resourceList) {
        if (resourceMap.containsKey(actualResource.getName())) {
            File conflictFile = resourceMap.get(actualResource.getName());
            //Avoid to identify as a conflict the same resource used in different places
            if (!conflictFile.getAbsolutePath().equals(actualResource.getAbsolutePath())) {
                conflicts.add(actualResource.getAbsolutePath());
                conflicts.add(conflictFile.getAbsolutePath());
            }
        } else
            resourceMap.put(actualResource.getName(), actualResource);
    }

    List<File> exportedResource = new ArrayList<File>();
    exportedResource.add(reportFile.getLocation().toFile());
    exportedResource.addAll(resourceList);
    tableViewer.setInput(exportedResource);
    tableViewer.refresh();
    //If there are conflict show an error message and disable the next button
    if (conflicts.size() > 0) {
        conflictResources = true;
        createErrorMessage(conflicts);
    }
}

From source file:org.jmangos.realm.network.packet.wow.client.CMSG_REQUEST_ACCOUNT_DATA.java

@Override
protected void runImpl() {

    if (this.type > AccountDataType.NUM_ACCOUNT_DATA_TYPES.getValue()) {
        return;/*  w w w.j a  va2 s .c  o  m*/
    }
    final HashMap<Integer, AccountData> adata = new HashMap<Integer, AccountData>(); // getAccount().getAccountData();
                                                                                     // /*
                                                                                     // disabled
                                                                                     // by
                                                                                     // paalgyula
                                                                                     // */
    if (adata.containsKey(this.type)) {
        final Deflater compressor = new Deflater();
        final byte[] dataToCompress = adata.get(this.type).getData().getBytes(Charset.forName("UTF-8"));

        compressor.setInput(dataToCompress);
        compressor.finish();
        final ByteArrayOutputStream bos = new ByteArrayOutputStream(dataToCompress.length);

        final byte[] buf = new byte[1024];
        while (!compressor.finished()) {
            final int count = compressor.deflate(buf);
            bos.write(buf, 0, count);
        }
        try {
            bos.close();
        } catch (final IOException e) {
        }
        // FIXME NEED COMPLETE
        @SuppressWarnings("unused")
        final byte[] compressedData = bos.toByteArray();

    }
}

From source file:eu.tango.energymodeller.energypredictor.CpuAndBiModalAcceleratorEnergyPredictor.java

/**
 * This provides an average of the recent CPU utilisation for a given host,
 * based upon the CPU utilisation time window set for the energy predictor.
 *
 * @param host The host for which the average CPU utilisation over the last
 * n seconds will be calculated for./*from  w w  w  .  j  a v a2 s. co  m*/
 * @param accelerator The accelerator to get the information for
 * @param accUsage The representation of the accelerators workload
 * @return The average recent CPU utilisation based upon the energy
 * predictor's configured observation window.
 */
protected double getAcceleratorClockRate(Host host, Accelerator accelerator,
        HashMap<Accelerator, HashMap<String, Double>> accUsage) {
    double answer = 0.0;
    HashMap<String, Double> values;
    if (accUsage == null) {
        values = getAcceleratorUtilisation(host, null).get(accelerator);
    } else {
        values = accUsage.get(accelerator);
    }
    if (values.containsKey("clocks.current.sm [MHz]")) {
        answer = values.get("clocks.current.sm [MHz]");
    }
    return answer;
}