List of usage examples for java.util HashMap get
public V get(Object key)
From source file:com.semsaas.utils.anyurl.App.java
private static String[] processOption(String[] args, Properties props) { LongOpt[] options = new LongOpt[] { new LongOpt("output", LongOpt.REQUIRED_ARGUMENT, null, 'o') }; // Build auxilary structures HashMap<Integer, LongOpt> shortOptionMap = new HashMap<Integer, LongOpt>(); StringBuffer decl = new StringBuffer(); for (LongOpt o : options) { shortOptionMap.put(o.getVal(), o); decl.append((char) o.getVal()); if (o.getHasArg() == LongOpt.OPTIONAL_ARGUMENT) { decl.append("::"); } else if (o.getHasArg() == LongOpt.REQUIRED_ARGUMENT) { decl.append(":"); }//from ww w .java 2 s.com } Getopt g = new Getopt("anyurl", args, decl.toString(), options); int c = 0; while ((c = g.getopt()) != -1) { LongOpt opt = shortOptionMap.get(c); String optName = opt.getName(); String optVal = g.getOptarg(); props.put(optName, optVal); } // NB: Getopt moves non options to the end return Arrays.copyOfRange(args, g.getOptind(), args.length); }
From source file:utils.ChartUtils.java
/** * Update line chart/*from w w w .ja va2 s.c o m*/ * * @param nInstances Number of instances * @param cp CategoryPlot * @param labelsetsByFrequency Labelsets ordered by frequency */ public static void updateLineChart(int nInstances, CategoryPlot cp, HashMap<Integer, Integer> labelsetsByFrequency) { DefaultCategoryDataset data = new DefaultCategoryDataset(); double prob; int max = maxKey(labelsetsByFrequency); for (int i = 0; i <= max; i++) { int currentFreq = 0; if (labelsetsByFrequency.get(i) != null) { currentFreq = labelsetsByFrequency.get(i); } prob = currentFreq * 1.0 / nInstances; if (prob == 0.0) { data.setValue(0, "Label-Combination: ", Integer.toString(i)); } else { data.setValue(prob, "Label-Combination: ", Integer.toString(i)); } } cp.setDataset(data); if (max > 30) { cp.getDomainAxis().setTickLabelsVisible(false); } else { cp.getDomainAxis().setTickLabelsVisible(true); } }
From source file:com.mindcognition.mindraider.export.Atomizer.java
private static void fromOneLevel(ProgressDialogJFrame progressDialogJFrame, HashMap<String, Entry> entryByUri, String outlineUri, String parentNoteUri, List<Link> childrenLinks, OutlineResource activeOutlineResource) throws Exception { for (int i = 0; i < childrenLinks.size(); i++) { String href = childrenLinks.get(i).getHref().toString(); Entry entry = entryByUri.get(href); String annotationContentType = entry.getCategories(Atomizer.ATOM_CAT_ANNOTATION_TYPE).get(0).getTerm(); // get all categories: filter out flag, if it is there String commaSeparatedTags = null; String categoryTitle = null; List<Category> categories = entry.getCategories(Atomizer.ATOM_CAT_TAG); if (categories.size() > 0) { for (int j = 0; j < categories.size(); j++) { String term = categories.get(j).getTerm(); if (term.startsWith(MindRaiderConstants.MR_OWL_FLAG_NS)) { categoryTitle = categories.get(j).getLabel(); } else { if (commaSeparatedTags == null) { commaSeparatedTags = categories.get(j).getLabel(); } else { commaSeparatedTags += "," + categories.get(j).getLabel(); }//from w w w . java2 s . c o m } } } String template = null; List<Link> attachmentsList = entry.getLinks("attachment"); AttachmentResource[] attachments = null; if (attachmentsList.size() > 0) { attachments = new AttachmentResource[attachmentsList.size()]; for (int k = 0; k < attachmentsList.size(); k++) { attachments[k] = new AttachmentResource(attachmentsList.get(k).getTitle(), attachmentsList.get(k).getHref().toString().replace("%20", " ")); } } StatusBar.show("Creating concept '" + entry.getTitle() + "'..."); String noteUri = MindRaider.noteCustodian.create(activeOutlineResource, parentNoteUri, entry.getTitle(), MindRaiderVocabulary.getConceptUri(Utils.getNcNameFromUri(outlineUri), Utils.toNcName(entry.getTitle()) + "-atom-note-" + System.currentTimeMillis()), entry.getSummary(), false, annotationContentType, commaSeparatedTags, categoryTitle, template, attachments); if (progressDialogJFrame != null) { progressDialogJFrame.setProgressMessage(entry.getTitle()); } fromOneLevel(progressDialogJFrame, entryByUri, outlineUri, noteUri, entry.getLinks(Atomizer.ATOM_REL_CHILD_NOTE), activeOutlineResource); } }
From source file:com.jajja.jorm.Database.java
/** * Commits the thread local transaction for the given database name if it * has been opened.//from w w w .ja va 2 s. com * * @param database the name of the database. * @return the closed transaction or null for no active transaction. * @throws SQLException if a database access error occur */ public static Transaction commit(String database) throws SQLException { database = context(database).effectiveName(); HashMap<String, Transaction> transactions = instance.getTransactions(); Transaction transaction = transactions.get(database); if (transaction != null) { transaction.commit(); } else { ensureConfigured(database); } return transaction; }
From source file:com.jajja.jorm.Database.java
/** * Closes the thread local transaction for the given database name if it has * been opened. This method is idempotent when called from the same thread. * * @param database the name of the database. * @return the closed transaction or null for no active transaction. */// www .ja v a 2 s . c om public static Transaction close(String database) { database = context(database).effectiveName(); HashMap<String, Transaction> transactions = instance.getTransactions(); Transaction transaction = transactions.get(database); if (transaction != null) { transaction.close(); } else { ensureConfigured(database); } return transaction; }
From source file:it.acubelab.smaph.SmaphUtils.java
/** * Turns a list of pairs <b,r>, where b is a bold and r is the position in * which the bold occurred, to the list of bolds and the hashmap between a * position and the list of bolds occurring in that position. * // www . ja v a2s .com * @param boldAndRanks * a list of pairs <b,r>, where b is a bold and r is the position * in which the bold occurred. * @param positions * where to store the mapping between a position (rank) and all * bolds that appear in that position. * @param bolds * where to store the bolds. */ public static void mapRankToBoldsLC(List<Pair<String, Integer>> boldAndRanks, HashMap<Integer, HashSet<String>> positions, HashSet<String> bolds) { for (Pair<String, Integer> boldAndRank : boldAndRanks) { String spot = boldAndRank.first.toLowerCase(); int rank = boldAndRank.second; if (bolds != null) bolds.add(spot); if (positions != null) { if (!positions.containsKey(rank)) positions.put(rank, new HashSet<String>()); positions.get(rank).add(spot); } } }
From source file:frequencyanalysis.FrequencyAnalysis.java
public static List<Item> findAlphabetFreq(String input) { HashMap alphabetCount = new HashMap<Character, Integer>(); for (char c : input.toCharArray()) { if (!alphabetCount.containsKey(c)) { alphabetCount.put(c, 1);//from ww w.j a va 2 s.co m } else { int tempCount = (int) alphabetCount.get(c); tempCount++; alphabetCount.put(c, tempCount); } } return sortByValue(alphabetCount); }
From source file:jsave.Utils.java
private static HashMap<String, Object> read_tagdesc(RandomAccessFile raf) throws IOException { HashMap<String, Object> tagdesc = new HashMap<>(); tagdesc.put("offset", read_long(raf)); if ((int) tagdesc.get("offset") == -1) { tagdesc.put("offset", read_uint64(raf)); }/*from w w w. j a v a 2 s . c om*/ tagdesc.put("typecode", read_long(raf)); int tagflags = read_long(raf); tagdesc.put("array", (tagflags & 4) == 4); tagdesc.put("structure", (tagflags & 32) == 32); tagdesc.put("scalar", DTYPE_DICT.containsKey(tagdesc.get("typecode"))); // Assume '10'x is scalar return tagdesc; }
From source file:com.jajja.jorm.Database.java
/** * Opens a thread local transaction for the given database name. If an open * transaction already exists, it is reused. This method is idempotent when * called from the same thread.//from www. j av a2 s.c o m * * @param database the name of the database. * @return the open transaction. */ public static Transaction open(String database) { ensureConfigured(); database = context(database).effectiveName(); HashMap<String, Transaction> transactions = instance.getTransactions(); Transaction transaction = transactions.get(database); if (transaction == null) { DataSource dataSource = instance.getDataSource(database); if (dataSource == null) { ensureConfigured(database); // throws! } transaction = new Transaction(dataSource, database); transactions.put(database, transaction); } return transaction; }
From source file:edu.harvard.liblab.ecru.LoadCsvData.java
/** * @param rec A HashMap containing the values for the Reading record * @param sdoc The record from the solr db, if it already exists * @throws Exception//w w w .ja v a 2 s . c om * A reading minimally requires a course id, a title, and a status. * If the referenced course does not exist in the database, * or this reading does not already exist, the term, * start and end dates are also required. * * If the Display field is empty, this method will create one from existing * component fields. * * This method will also update the relevant Course's has_readings flag. * * This version of the loader assumes that, if the reading already exists in * the database, its data is being completely replaced by the incoming data, * */ private static void processReading(HashMap<String, String> rec, SolrDocument sdoc) throws Exception { String title = rec.get("Title"); String cId = rec.get("Course"); String errMsg = ""; if (needsPrefix) { cId = "c_" + cId; } if (cId.isEmpty()) { throw new Exception("Reading is missing a Course ID"); } String lib = rec.get("Library"); String term = rec.get("Term"); String startDateStr = rec.get("Start Date"); String endDateStr = rec.get("End Date"); String status = rec.get("Status"); Date startDate = null; Date endDate = null; boolean updateHasReadings = false; SolrDocument solrCourse = getDocFromSolr(cId); if (solrCourse != null) { // always take term, start/end dates from course! String cTerm = (String) solrCourse.get("term"); Date cstartDate = (Date) solrCourse.get("start_date"); Date cendDate = (Date) solrCourse.get("end_date"); term = cTerm; startDate = cstartDate; endDate = cendDate; updateHasReadings = ((Boolean) solrCourse.get("course.has_readings")).equals(Boolean.FALSE); } else { if (sdoc != null && sdoc.get("reading.course_id").equals(cId)) { // if the reading exists in the db, and it's for the same course, use that stuff if (term.isEmpty()) { term = (String) sdoc.get("term"); } if (startDateStr.isEmpty()) { startDate = (Date) sdoc.get("start_date"); } if (endDateStr.isEmpty()) { endDate = (Date) sdoc.get("end_date"); } } else { try { startDate = SIMPLE_DATE.parse(startDateStr); endDate = SIMPLE_DATE.parse(endDateStr); } catch (ParseException e) { } } } if (startDate == null) { errMsg = " bad or missing startDate"; } if (endDate == null) { errMsg += " bad or missing endDate"; } if (term.isEmpty()) { errMsg += " missing Term"; } if (title.isEmpty()) { errMsg += " missing title"; } if (errMsg.isEmpty()) { Date lectureDate = null; if (!rec.get("LectureDate").isEmpty()) { try { lectureDate = SIMPLE_DATE.parse(rec.get("LectureDate")); } catch (ParseException e) { } } String authorStr = rec.get("Author"); String[] authors = authorStr.split(";"); for (int i = 0; i < authors.length; i++) { authors[i] = authors[i].trim(); } String editorStr = rec.get("Editor"); String[] editors = editorStr.split(";"); for (int i = 0; i < editors.length; i++) { editors[i] = editors[i].trim(); } String display = rec.get("Display"); if (display.isEmpty()) { display = authorStr; if (!display.isEmpty()) { display += ". "; } if (!rec.get("Chapter").isEmpty()) { display += rec.get("Chapter") + "(chap.). "; } display += title + ". "; if (!editorStr.isEmpty()) { display += editorStr + " (ed.). "; } if (!rec.get("Journal").isEmpty()) { display += " in " + rec.get("Journal"); } } String id = (needsPrefix) ? "r_" + rec.get("ID") : rec.get("ID"); int order = -1; if (!rec.get("Order").isEmpty()) { try { order = new Integer((String) rec.get("Order")).intValue(); } catch (Exception e) { if (isVerbose) { System.err.println("Record #" + numRecs + " has a value for Order (" + rec.get("Order") + ") that can not be converted to an integer"); } } } boolean required = (rec.get("Required").toLowerCase().equals("Y")); /* * String id, String displayLabel, String annotation, List<String> authors, String availUrl, String sysId, String chapter, String courseId, String digUrl, String doiId, List<String> editors, Date endDate, String isbn, String issn, String journal, Date lectureDate, String library, int order, String pubmed, boolean required, String status, Date startDate, String system, String term, String title */ Reading r = new Reading(id, display, rec.get("Note"), Arrays.asList(authors), null, rec.get("SystemID"), rec.get("Chapter"), cId, rec.get("URL"), rec.get("DOI"), Arrays.asList(editors), endDate, rec.get("ISBN"), rec.get("ISSN"), rec.get("Journal"), lectureDate, lib, order, rec.get("PUBMED"), required, status, startDate, rec.get("System"), term, title); if (!authors[0].isEmpty()) { r.setFirstAuthor(authors[0]); } beans.add(r); if (updateHasReadings) { updateCourseHasReadings(cId); } } else { throw new Exception(errMsg); } }