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:sim.util.media.chart.PieChartGenerator.java

HashMap convertIntoAmountsAndLabels(Object[] objs) {
    // Total the amounts
    HashMap map = new HashMap();
    for (int i = 0; i < objs.length; i++) {
        String label = "null";
        if (objs[i] != null)
            label = objs[i].toString();// w  w w.j ava2  s. c o m
        if (map.containsKey(label))
            map.put(label, new Double(((Double) (map.get(label))).doubleValue() + 1));
        else
            map.put(label, new Double(1));
    }
    return map;
}

From source file:luceneGazateer.EntryData.java

public ArrayList<EntryData> searchDocuments(String indexerPath, String inputRecord, DocType recordType)
        throws IOException {

    File indexfile = new File(indexerPath);
    indexDir = FSDirectory.open(indexfile.toPath());

    //inputRecord.replace(","," ");
    if (!DirectoryReader.indexExists(indexDir)) {
        LOG.log(Level.SEVERE, "No Lucene Index Dierctory Found, Invoke indexBuild() First !");
        System.out.println("No Lucene Index Dierctory Found, Invoke indexBuild() First !");
        System.exit(1);//from  www  . j  ava 2s. c  o m
    }

    IndexReader reader = DirectoryReader.open(indexDir);

    IndexSearcher searcher = new IndexSearcher(reader);

    Query q = null;

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

    if (!allCandidates.containsKey(inputRecord)) {
        try {
            ArrayList<ArrayList<String>> topHits = new ArrayList<ArrayList<String>>();
            //System.out.println("query is : "+inputRecord);
            q = new MultiFieldQueryParser(new String[] { "DATA" }, analyzer).parse(inputRecord);

            TopScoreDocCollector collector = TopScoreDocCollector.create(hitsPerPage);
            searcher.search(q, collector);
            ScoreDoc[] hits = collector.topDocs().scoreDocs;
            for (int i = 0; i < hits.length; ++i) {
                ArrayList<String> tmp1 = new ArrayList<String>();
                int docId = hits[i].doc;
                Document d;
                try {
                    d = searcher.doc(docId);
                    tmp1.add(d.get("ID"));
                    tmp1.add(d.get("DATA"));
                    tmp1.add(((Float) hits[i].score).toString());

                } catch (IOException e) {
                    e.printStackTrace();
                }
                topHits.add(tmp1);
            }
            allCandidates.put(inputRecord, topHits);
        } catch (org.apache.lucene.queryparser.classic.ParseException e) {
            e.printStackTrace();
        }
    }

    ArrayList<EntryData> resolvedEntities = new ArrayList<EntryData>();
    pickBestCandidates(resolvedEntities, allCandidates);
    reader.close();

    return resolvedEntities;

}

From source file:com.opengamma.integration.copier.snapshot.reader.FileSnapshotReader.java

private void buildCurves(HashMap<String, ManageableCurveSnapshot> curvesBuilder,
        Map<String, String> currentRow) {
    String name = currentRow.get(SnapshotColumns.NAME.get());

    if (!curvesBuilder.containsKey(name)) {
        ManageableCurveSnapshot curve = new ManageableCurveSnapshot();
        ManageableUnstructuredMarketDataSnapshot snapshot = new ManageableUnstructuredMarketDataSnapshot();

        curve.setValuationTime(Instant.parse(currentRow.get(SnapshotColumns.INSTANT.get())));
        snapshot.putValue(createExternalIdBundle(currentRow), currentRow.get(SnapshotColumns.VALUE_NAME.get()),
                createValueSnapshot(currentRow));
        curve.setValues(snapshot);// ww  w  .  j  a va2 s  .  co  m
        curvesBuilder.put(name, curve);
    } else {
        curvesBuilder.get(name).getValues().putValue(createExternalIdBundle(currentRow),
                currentRow.get(SnapshotColumns.VALUE_NAME.get()), createValueSnapshot(currentRow));
    }

}

From source file:com.manning.androidhacks.hack017.CreateAccountAdapter.java

private TextView createErrorView(String key) {
    TextView ret = new TextView(mContext);
    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT,
            LayoutParams.WRAP_CONTENT);//from www .  j a v  a2 s .c om
    params.topMargin = 10;
    params.bottomMargin = 10;
    ret.setLayoutParams(params);
    ret.setTextColor(Color.RED);
    ret.setTextSize(TypedValue.COMPLEX_UNIT_SP, 10);

    HashMap<String, String> errors = mAccount.getErrors();
    if (errors != null && errors.containsKey(key)) {
        ret.setText(errors.get(key));
        ret.setVisibility(View.VISIBLE);
    } else {
        ret.setVisibility(View.INVISIBLE);
    }

    return ret;
}

From source file:annis.gui.flatquerybuilder.SpanBox.java

@Override
public void textChange(FieldEvents.TextChangeEvent event) {
    String txt = event.getText();
    HashMap<Integer, Collection> levdistvals = new HashMap<Integer, Collection>();
    if (txt.length() > 1) {
        cb.removeAllItems();/*from w w w  .j  a  v a 2  s  .c  o m*/
        for (String s : annonames) {
            Integer d = StringUtils.getLevenshteinDistance(removeAccents(txt), removeAccents(s));
            if (levdistvals.containsKey(d)) {
                levdistvals.get(d).add(s);
            }
            if (!levdistvals.containsKey(d)) {
                Set<String> newc = new TreeSet<String>();
                newc.add(s);
                levdistvals.put(d, newc);
            }
        }
        SortedSet<Integer> keys = new TreeSet<Integer>(levdistvals.keySet());
        for (Integer k : keys.subSet(0, 5)) {
            List<String> values = new ArrayList(levdistvals.get(k));
            Collections.sort(values, String.CASE_INSENSITIVE_ORDER);
            for (String v : values) {
                cb.addItem(v);
            }
        }
    }
}

From source file:com.pablog178.pdfcreator.android.PdfcreatorModule.java

private void generateImageFunction(HashMap args) {
    if (args.containsKey("fileName")) {
        Object fileName = args.get("fileName");
        if (fileName instanceof String) {
            this.fileName = (String) fileName;
            Log.i(PROXY_NAME, "fileName: " + this.fileName);
        }// w w w  . j  a  v  a  2 s .co  m
    } else
        return;

    if (args.containsKey("view")) {
        Object viewObject = args.get("view");
        if (viewObject instanceof TiViewProxy) {
            TiViewProxy viewProxy = (TiViewProxy) viewObject;
            this.view = viewProxy.getOrCreateView();
            if (this.view == null) {
                Log.e(PROXY_NAME, "NO VIEW was created!!");
                return;
            }
            Log.i(PROXY_NAME, "view: " + this.view.toString());
        }
    } else
        return;

    TiBaseFile file = TiFileFactory.createTitaniumFile(this.fileName, true);
    Log.i(PROXY_NAME, "file full path: " + file.nativePath());
    try {
        final int PDF_WIDTH = 612;
        final int PDF_HEIGHT = 792;
        Resources appResources = app.getResources();
        OutputStream outputStream = file.getOutputStream();
        int viewWidth = 1600;
        int viewHeight = 1;

        WebView view = (WebView) this.view.getNativeView();

        if (TiApplication.isUIThread()) {

            viewWidth = view.capturePicture().getWidth();
            viewHeight = view.capturePicture().getHeight();

            if (viewWidth <= 0) {
                viewWidth = 1300;
            }

            if (viewHeight <= 0) {
                viewHeight = 2300;
            }

        } else {
            Log.e(PROXY_NAME, "NO UI THREAD");
        }

        Log.i(PROXY_NAME, "viewWidth: " + viewWidth);
        Log.i(PROXY_NAME, "viewHeight: " + viewHeight);

        Bitmap viewBitmap = Bitmap.createBitmap(viewWidth, viewHeight, Bitmap.Config.ARGB_8888);
        float density = appResources.getDisplayMetrics().density;

        Canvas canvas = new Canvas(viewBitmap);
        Matrix matrix = new Matrix();

        Drawable bgDrawable = view.getBackground();
        if (bgDrawable != null) {
            bgDrawable.draw(canvas);
        } else {
            canvas.drawColor(Color.WHITE);
        }
        view.draw(canvas);

        float scaleFactorWidth = 1 / ((float) viewWidth / (float) PDF_WIDTH);
        float scaleFactorHeight = 1 / ((float) viewHeight / (float) PDF_HEIGHT);

        Log.i(PROXY_NAME, "scaleFactorWidth: " + scaleFactorWidth);
        Log.i(PROXY_NAME, "scaleFactorHeight: " + scaleFactorHeight);

        matrix.setScale(scaleFactorWidth, scaleFactorWidth);

        Bitmap imageBitmap = Bitmap.createBitmap(PDF_WIDTH, PDF_HEIGHT, Bitmap.Config.ARGB_8888);
        Canvas imageCanvas = new Canvas(imageBitmap);
        imageCanvas.drawBitmap(viewBitmap, matrix, null);
        imageBitmap.compress(Bitmap.CompressFormat.JPEG, 100, outputStream);

        sendCompleteEvent();

    } catch (Exception exception) {
        Log.e(PROXY_NAME, "Error: " + exception.toString());
        sendErrorEvent(exception.toString());
    }
}

From source file:com.shouwy.series.web.control.admin.AdminEpisodeController.java

@RequestMapping(value = "/admin/episodes/list")
public ModelAndView list() {
    ModelAndView model = new ModelAndView("admin/episode/list");

    model.addObject("listType", Util.initModelHeader(typeDao));
    ArrayList<Episode> listEpisode = (ArrayList<Episode>) episodeDao.getAll();
    ArrayList<Series> listSeries = (ArrayList<Series>) seriesDao.getAll();
    ArrayList<Saison> listSaison = (ArrayList<Saison>) saisonDao.getAll();
    HashMap<Episode, HashMap<Saison, Series>> mapEpisode = new HashMap<Episode, HashMap<Saison, Series>>();

    for (Episode e : listEpisode) {
        Integer idSaison = e.getIdSaison();
        for (Saison sa : listSaison) {
            if (sa.getId().equals(idSaison)) {
                if (!mapEpisode.containsKey(e)) {
                    HashMap<Saison, Series> mapSaison = new HashMap<Saison, Series>();
                    mapEpisode.put(e, mapSaison);
                }/* w w w  . j  a  va 2 s .com*/
                for (Series se : listSeries) {
                    if (se.getId().equals(sa.getIdSerie())) {
                        mapEpisode.get(e).put(sa, se);
                    }
                }
            }
        }
    }

    model.addObject("listEpisode", mapEpisode);
    model.addObject("etat", etatPersoDao.getAll());

    return model;
}

From source file:hd3gtv.mydmam.useraction.fileoperation.UAFileOperationTrash.java

public void process(JobProgression progression, UserProfile userprofile, UAConfigurator user_configuration,
        HashMap<String, SourcePathIndexerElement> source_elements) throws Exception {
    String user_base_directory_name = userprofile.getBaseFileName_BasedOnEMail();

    if (trash_directory_name == null) {
        trash_directory_name = "Trash";
    }/*  www  . jav a 2 s  .  c  o  m*/

    Log2Dump dump = new Log2Dump();
    dump.add("user", userprofile.key);
    dump.add("trash_directory_name", trash_directory_name);
    dump.add("user_base_directory_name", user_base_directory_name);
    dump.add("source_elements", source_elements.values());
    Log2.log.debug("Prepare trash", dump);

    progression.update("Prepare trashs directories");

    File current_user_trash_dir;
    HashMap<String, File> trashs_dirs = new HashMap<String, File>();
    for (Map.Entry<String, SourcePathIndexerElement> entry : source_elements.entrySet()) {
        String storagename = entry.getValue().storagename;
        if (trashs_dirs.containsKey(storagename)) {
            continue;
        }
        File storage_dir = Explorer
                .getLocalBridgedElement(SourcePathIndexerElement.prepareStorageElement(storagename));
        current_user_trash_dir = new File(storage_dir.getPath() + File.separator + trash_directory_name
                + File.separator + user_base_directory_name);

        if (current_user_trash_dir.exists() == false) {
            FileUtils.forceMkdir(current_user_trash_dir);
        } else {
            CopyMove.checkExistsCanRead(current_user_trash_dir);
            CopyMove.checkIsWritable(current_user_trash_dir);
            CopyMove.checkIsDirectory(current_user_trash_dir);
        }
        trashs_dirs.put(storagename, current_user_trash_dir);

        if (stop) {
            return;
        }
    }

    progression.update("Move item(s) to trash(s) directorie(s)");
    progression.updateStep(1, source_elements.size());

    Date now = new Date();

    for (Map.Entry<String, SourcePathIndexerElement> entry : source_elements.entrySet()) {
        progression.incrStep();
        File current_element = Explorer.getLocalBridgedElement(entry.getValue());
        CopyMove.checkExistsCanRead(current_element);
        CopyMove.checkIsWritable(current_element);

        current_user_trash_dir = trashs_dirs.get(entry.getValue().storagename);

        File f_destination = new File(current_user_trash_dir.getPath() + File.separator
                + simpledateformat.format(now) + "_" + current_element.getName());

        if (current_element.isDirectory()) {
            FileUtils.moveDirectory(current_element, f_destination);
        } else {
            FileUtils.moveFile(current_element, f_destination);
        }

        if (stop) {
            return;
        }

        ContainerOperations.copyMoveMetadatas(entry.getValue(), entry.getValue().storagename,
                "/" + trash_directory_name + "/" + user_base_directory_name, false, this);

        ElasticsearchBulkOperation bulk = Elasticsearch.prepareBulk();
        explorer.deleteStoragePath(bulk, Arrays.asList(entry.getValue()));
        bulk.terminateBulk();

        if (stop) {
            return;
        }
    }

    ElasticsearchBulkOperation bulk = Elasticsearch.prepareBulk();
    ArrayList<SourcePathIndexerElement> spie_trashs_dirs = new ArrayList<SourcePathIndexerElement>();
    for (String storage_name : trashs_dirs.keySet()) {
        SourcePathIndexerElement root_trash_directory = SourcePathIndexerElement
                .prepareStorageElement(storage_name);
        root_trash_directory.parentpath = root_trash_directory.prepare_key();
        root_trash_directory.directory = true;
        root_trash_directory.currentpath = "/" + trash_directory_name;
        spie_trashs_dirs.add(root_trash_directory);
    }

    explorer.refreshStoragePath(bulk, spie_trashs_dirs, false);
    bulk.terminateBulk();
}

From source file:com.userweave.domain.service.impl.SurveyStatisticsServiceImpl.java

@Override
public Set<Entry<String, Integer>> evaluateSurveyExecutionsInLocales(List<SurveyExecution> surveyExecutions) {
    HashMap<String, Integer> map = new HashMap<String, Integer>();

    for (SurveyExecution exec : surveyExecutions) {
        if (exec.getLocale() != null && exec.getState() != SurveyExecutionState.INVALID
                && exec.getState() != SurveyExecutionState.NOT_STARTED) {
            String lang = exec.getLocale().getDisplayLanguage();

            if (map.containsKey(lang)) {
                map.put(lang, new Integer(map.get(lang) + 1));
            } else {
                map.put(lang, new Integer(1));
            }//  www . j a  v a2s.c o  m
        }
    }

    return map.entrySet();
}

From source file:edu.psu.citeseerx.misc.charts.CiteChartBuilderJFree.java

private XYDataset collectData(java.util.List<ThinDoc> docs) {

    Calendar now = Calendar.getInstance();
    int currentYear = now.get(Calendar.YEAR);

    HashMap<Integer, DataPoint> data = new HashMap<Integer, DataPoint>();
    for (ThinDoc doc : docs) {
        try {/*from www  .ja  v a  2s.com*/
            Integer year = new Integer(doc.getYear());
            if (year.intValue() < 1930 || year.intValue() > currentYear + 2) {
                continue;
            }
            DataPoint point;
            if (data.containsKey(year)) {
                point = data.get(year);
            } else {
                point = new DataPoint(year.intValue());
                data.put(year, point);
            }
            point.ncites++;
        } catch (Exception e) {
        }
    }
    XYSeries series = new XYSeries("Years");
    for (DataPoint point : data.values()) {
        System.out.println(point.year);
        System.out.println(point.ncites);
        series.add(point.year, point.ncites);
    }
    XYSeriesCollection dataset = new XYSeriesCollection();
    dataset.addSeries(series);
    return dataset;

}