List of usage examples for java.util TreeMap containsKey
public boolean containsKey(Object key)
From source file:jp.zippyzip.impl.GeneratorServiceImpl.java
public void updateZips() { Date timestamp = getLzhDao().getZipInfo().getTimestamp(); LinkedList<Pref> prefs = getPrefs(); TreeMap<String, TreeSet<String>> zips = new TreeMap<String, TreeSet<String>>(); int cnt = 0;/*from w ww .j av a2 s . co m*/ try { for (Pref pref : prefs) { ParentChild data = getParentChildDao().get("pre" + pref.getCode()); if (data != null) { for (String json : data.getChildren()) { JSONArray ja = new JSONArray(json); for (int i = 0; i < ja.length(); ++i) { JSONObject jo = ja.getJSONObject(i); String zip = jo.optString("zip", ""); String key = jo.optString("key", ""); if (!zips.containsKey(zip)) { zips.put(zip, new TreeSet<String>()); } zips.get(zip).add(key); } } } } ParentChild data = null; LinkedList<String> zip1s = new LinkedList<String>(); String prev = null; for (String code : zips.keySet()) { String zip1 = code.substring(0, 3); String zip2 = code.substring(3); if (!zip1.equals(prev)) { if (data != null) { getParentChildDao().store(data); } LinkedList<String> parents = new LinkedList<String>(); parents.add(zip1); data = new ParentChild(zip1, timestamp, parents); zip1s.add(new JSONStringer().object().key("zip1").value(zip1).endObject().toString()); prev = zip1; } for (String key : zips.get(code)) { data.getChildren().add(new JSONStringer().object().key("zip2").value(zip2).key("key").value(key) .endObject().toString()); ++cnt; } } if (data != null) { getParentChildDao().store(data); } getParentChildDao().store(new ParentChild("zip1s", timestamp, new LinkedList<String>(), zip1s)); log.info("count:" + cnt); } catch (JSONException e) { log.log(Level.WARNING, "", e); } return; }
From source file:ca.myewb.frame.servlet.GraphServlet.java
private JFreeChart getListMemberships(Session s, int groupId, UserModel currentUser) { final int NUM_MONTHS = 6; Logger log = Logger.getLogger(this.getClass()); JFreeChart chart;//from www . j a v a 2s .c om Date startDate; TreeMap<Day, Integer> memberChange = new TreeMap<Day, Integer>(); GroupModel g = (GroupModel) s.get(GroupModel.class, groupId); if (g == null) { log.warn("Someone requested chapter stats with a bad group id"); } else if (!Permissions.canAdministerGroupMembership(currentUser, g)) { log.warn(currentUser.getUsername() + "tried to access list memberships graph!"); } Calendar cal = GregorianCalendar.getInstance(); Date now = cal.getTime(); cal.set(Calendar.HOUR, 0); cal.set(Calendar.MINUTE, 0); cal.set(Calendar.SECOND, 0); cal.set(Calendar.MILLISECOND, 1); cal.add(Calendar.MONTH, -NUM_MONTHS); startDate = cal.getTime(); //Set Initial Number of Members int initMembers = g.getNumMembers() + g.getNumRecipients(); //Pull a list of all of the membership start dates List starts = s.createQuery("SELECT rm.start, count(*) " + "FROM RoleModel as rm " + "WHERE rm.group = :group " + "AND (rm.level = 'r' OR rm.level = 'm') " + "AND rm.start > :startDate " + "GROUP BY rm.start ").setEntity("group", g) .setDate("startDate", startDate).list(); for (Object o : starts) { Day date = new Day((Date) (((Object[]) o)[0])); int change = ((Long) (((Object[]) o)[1])).intValue(); memberChange.put(date, change); initMembers -= change; } //Pull a list of all of the membership end dates List ends = s.createQuery("SELECT rm.end, count(*) " + "FROM RoleModel as rm " + "WHERE rm.group = :group " + "AND (rm.level = 'r' OR rm.level = 'm') " + "AND rm.end > :startDate " + "GROUP BY rm.end ") .setEntity("group", g).setDate("startDate", startDate).list(); for (Object o : ends) { Day date = new Day((Date) (((Object[]) o)[0])); int change = ((Long) (((Object[]) o)[1])).intValue(); if (memberChange.containsKey(date)) { memberChange.put(date, memberChange.get(date) - change); } else { memberChange.put(date, -change); } initMembers += change; } TimeSeriesCollection theData = new TimeSeriesCollection(); TimeSeries signups = new TimeSeries("List Membership", Day.class); theData.addSeries(signups); while (startDate.before(now)) { Day d = new Day(startDate); if (memberChange.containsKey(d)) { initMembers += memberChange.get(d); } signups.add(d, initMembers); cal.add(Calendar.DATE, 1); startDate = cal.getTime(); } chart = ChartFactory.createTimeSeriesChart("List Members", "Day", "Number of Members", theData, true, true, true); XYPlot plot = (XYPlot) chart.getPlot(); XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer(); renderer.setSeriesStroke(0, new BasicStroke(2.0f)); return chart; }
From source file:it.imtech.metadata.MetaUtility.java
private void metadata_reader_metadatas(Element iENode, TreeMap<Object, Metadata> metadatas, boolean forceAdd, TreeMap forceAddMID, String sLang) { try {/*from w ww. j a v a2 s . c om*/ if (iENode.getTagName().equals("metadatas")) { NodeList nList = iENode.getChildNodes(); for (int s = 0; s < nList.getLength(); s++) { if (nList.item(s).getNodeType() == Node.ELEMENT_NODE) { Element iInnerNode = (Element) nList.item(s); if (iInnerNode.getTagName().equals("metadata")) { String MID = iInnerNode.getAttribute("ID"); //Se hidden rimuovo l'elemento dai forzati String hidden = "0"; if (iInnerNode.hasAttribute("hidden")) { hidden = iInnerNode.getAttribute("hidden"); forceAddMID.remove(iInnerNode.getAttribute("ID")); } if (forceAddMID.containsKey(MID)) { forceAdd = true; } String MID_parent = iInnerNode.getAttribute("mid_parent"); String mandatory = iInnerNode.getAttribute("mandatory"); String datatype = iInnerNode.getAttribute("datatype"); String editable = iInnerNode.getAttribute("editable"); String foxmlname = iInnerNode.getAttribute("forxmlname"); String sequence = iInnerNode.getAttribute("sequence"); String sequencemulti = ""; if (MID_parent.equals("22") || MID_parent.equals("45")) { Node searchparent = iInnerNode; boolean found = false; while (!found) { Element x = (Element) searchparent.getParentNode(); if (x.getAttribute("ID").equals("22")) { sequencemulti = x.getAttribute("sequence"); found = true; } else { searchparent = searchparent.getParentNode(); } } } //Add contributors management if (MID_parent.equals("11") || MID_parent.equals("13")) { Node searchparent = iInnerNode; boolean found = false; while (!found) { Element x = (Element) searchparent.getParentNode(); if (x.getAttribute("ID").equals("11")) { sequencemulti = x.getAttribute("sequence"); found = true; } else { searchparent = searchparent.getParentNode(); } } } if (MID.equals("11")) { Element x = (Element) iInnerNode; sequencemulti = x.getAttribute("sequence"); } String foxmlnamespace = iInnerNode.getAttribute("fornamespace"); if (!metadata_namespaces.containsValue(foxmlnamespace)) { int count = metadata_namespaces.size(); count++; metadata_namespaces.put("ns" + count, foxmlnamespace); } String description = null; String DESCRIPTION_DE = null; TreeMap<Object, Metadata> submetadatas = new TreeMap<Object, Metadata>(); NodeList innerList = iInnerNode.getChildNodes(); for (int z = 0; z < innerList.getLength(); z++) { if (innerList.item(z).getNodeType() == Node.ELEMENT_NODE) { Element iDescrNode = (Element) innerList.item(z); if (iDescrNode.getAttribute("isocode").equals(sLang)) { description = iDescrNode.getTextContent(); } else if (iDescrNode.getAttribute("isocode").equals("de")) { DESCRIPTION_DE = iDescrNode.getTextContent(); } if (iDescrNode.getTagName().equals("metadatas")) { if (MID.equals("98")) { metadata_reader_metadatas(iDescrNode, submetadatas, true, forceAddMID, sLang); } else { metadata_reader_metadatas(iDescrNode, submetadatas, false, forceAddMID, sLang); } } } } //Fallback DE if (description == null) { description = DESCRIPTION_DE; } if (description == null && !iInnerNode.getTagName().equals("metadata")) { throw new Exception( "Can't find description for metadata " + iInnerNode.getTagName()); } if ((mandatory.equals("Y") || forceAdd == true)) { int mid_parent = 0; if (!MID_parent.equals("")) { mid_parent = Integer.parseInt(MID_parent); } Metadata t = new Metadata(Integer.parseInt(MID), mid_parent, description, datatype, editable, foxmlname, null, foxmlnamespace, mandatory, hidden, sequencemulti); t.submetadatas = submetadatas; String index = sequence; if (index == null || index.equals("")) { index = MID; } int param = Integer.parseInt(index); metadatas.put(param, t); } if (forceAddMID.containsKey(MID.toString())) { forceAdd = false; } } } } } } catch (Exception ex) { logger.error(ex.getMessage()); } }
From source file:org.ecocean.Encounter.java
public String getDynamicPropertyValue(String name) { if (dynamicProperties != null) { name = name.replaceAll("%20", " "); //let's create a TreeMap of the properties TreeMap<String, String> tm = new TreeMap<String, String>(); StringTokenizer st = new StringTokenizer(dynamicProperties, ";"); while (st.hasMoreTokens()) { String token = st.nextToken(); int equalPlace = token.indexOf("="); tm.put(token.substring(0, equalPlace), token.substring(equalPlace + 1)); }//from w w w. j a va2 s .com if (tm.containsKey(name)) { return tm.get(name); } } return null; }
From source file:org.ecocean.Encounter.java
public void removeDynamicProperty(String name) { name = name.replaceAll(";", "_").trim().replaceAll("%20", " "); if (dynamicProperties != null) { //let's create a TreeMap of the properties TreeMap<String, String> tm = new TreeMap<String, String>(); StringTokenizer st = new StringTokenizer(dynamicProperties, ";"); while (st.hasMoreTokens()) { String token = st.nextToken(); int equalPlace = token.indexOf("="); tm.put(token.substring(0, (equalPlace)), token.substring(equalPlace + 1)); }/*w ww . jav a 2s . co m*/ if (tm.containsKey(name)) { tm.remove(name); //now let's recreate the dynamicProperties String String newProps = tm.toString(); int stringSize = newProps.length(); dynamicProperties = newProps.substring(1, (stringSize - 1)).replaceAll(", ", ";") + ";"; } } }
From source file:crawler.HackerEarthCrawler.java
@Override public void crawl() { int flag = 0; //set of urls which should be crawled TreeSet<String> linksset = new TreeSet<String>(); TreeSet<String> tempset = new TreeSet<String>(); TreeSet<String> tutorialset = new TreeSet<String>(); //final set of problem urls TreeSet<String> problemset = new TreeSet<String>(); //visited for maintaing status of if url is already crawled or not TreeMap<String, Integer> visited = new TreeMap<String, Integer>(); //add base url linksset.add(baseUrl);/*w w w.ja v a 2 s . c o m*/ //mark base url as not crawled visited.put(baseUrl, 0); try { while (true) { flag = 0; tempset.clear(); for (String str : linksset) { //check if url is already crawled or not and it has valid domain name if ((visited.get(str) == 0) && (str.startsWith("https://www.hackerearth.com/"))) { System.out.println("crawling " + str); //retriving response of current url as document Document doc = Jsoup.connect(str).timeout(0).userAgent( "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:25.0) Gecko/20100101 Firefox/25.0") .referrer("http://www.google.com").ignoreHttpErrors(true).get(); //retriving all urls from current page Elements links = doc.select("a[href]"); //mark url as crawled visited.put(str, 1); //mark flag as url is crawled flag = 1; //retrive all urls for (Element link : links) { if (link.absUrl("href").endsWith("/tutorial/")) { tutorialset.add(link.absUrl("href")); } //check if url is problem url then add it in problemurlset if (link.absUrl("href").startsWith("https://www.hackerearth.com/") && isProblemUrl(link.absUrl("href"))) { problemset.add(link.absUrl("href")); } //check if url has valid domain and it has problem urls or not if (link.absUrl("href").contains(("https://www.hackerearth.com/")) && isCrawlable(link.absUrl("href"))) { //if link is not visited then mark it as uncrawled if (!visited.containsKey(link.absUrl("href"))) { visited.put(link.absUrl("href"), 0); } //add it in tempsetorary set tempset.add(link.absUrl("href")); //System.out.println("\n base: "+str+" ::: link : " + link.absUrl("href")); } } } } //if nothing is left to crawl break the loop if (flag == 0) { break; } //add all retrieved links to linksset linksset.addAll(tempset); } System.out.println("\n\ntotal problem urls " + problemset.size()); int i = 0; for (String str : problemset) { System.out.println("link " + i + " : " + str); i++; } } catch (IOException ex) { Logger.getLogger(HackerEarthCrawler.class.getName()).log(Level.SEVERE, null, ex); } //scrap and store into database //for every problem url scrap problem page for (String problemUrl : problemset) { System.out.println("problemUrl :" + problemUrl); try { //create problem class to store in database Problem problem = new Problem(); String problemSIOC = "", problemIOC = ""; String problemTitle = "", problemStatement = "", problemInput = "", problemOutput = "", problemConstraints = ""; String sampleInput = "", sampleOutput = ""; String problemExplanation = ""; //set default timelimit to 1 second double problemTimeLimit = 1.0; ArrayList<String> tags = new ArrayList<String>(); //get response for given problem url Response response = Jsoup.connect(problemUrl).execute(); Document doc = response.parse(); //retrieve problem title from page Element elementTitle = doc.getElementsByTag("title").first(); StringTokenizer stTitle = new StringTokenizer(elementTitle.text(), "|"); problemTitle = stTitle.nextToken().trim(); Element content = doc.getElementsByClass("starwars-lab").first(); problemSIOC = content.text(); Elements e = content.children(); //to find problem statement String breakloop[] = { "input", "input:", "input :", "input format:", "input format :", "input format", "Input and output", "constraints :", "constraints:", "constraints", "$$Input :$$" }; flag = 0; for (Element p : e) { String tempStatement = ""; for (Element pp : p.getAllElements()) { for (String strbreak : breakloop) { if (StringUtils.equalsIgnoreCase(pp.ownText(), strbreak)) { //System.out.println("strbreak :"+strbreak); tempStatement = p.text().substring(0, p.text().toLowerCase().indexOf(strbreak.toLowerCase())); // System.out.println("temp "+tempStatement); flag = 1; break; } } } if (flag == 1) { problemStatement += tempStatement; //remove extra space at end if (tempStatement.length() == 0) { problemStatement = problemStatement.substring(0, problemStatement.length() - 1); } break; } problemStatement += p.text() + " "; } System.out.println("problemSIOC :" + problemSIOC); System.out.println("problemStatement :" + problemStatement); if (problemStatement.length() <= problemSIOC.length()) { //remove problem statement from whole text and remove extra spaces at the beginning and the end problemIOC = problemSIOC.substring(problemStatement.length()).trim(); } else { problemIOC = ""; } System.out.println("problemIOC :" + problemIOC); //keywords for identifying input String decideInput[] = { "Input format :", "Input format:", "Input format", "inputformat:", "inputformat :", "inputformat", "input and output", "input :", "input:", "input" }; //keywords for identifying output String decideOutput[] = { "output format :", "output format:", "Output format", "outputformat:", "outputformat :", "outputformat", "output :", "output:", "output" }; //keywords for identifying constraint String decideConstraint[] = { "constraints:", "constraints :", "constraints", "Constraints :", "constraint:", "constraint :", "constraint", "Contraints :" }; int posin = 0, posoutput = 0, poscon = 0, idxin, idxout, idxcon, flaginput = 0, flagoutput = 0, flagcon = 0, inlen = 0, outlen = 0, conlen = 0; //find inputformat position,length of keyword for (idxin = 0; idxin < decideInput.length; idxin++) { if (StringUtils.containsIgnoreCase(problemIOC, decideInput[idxin])) { posin = problemIOC.toLowerCase().indexOf(decideInput[idxin].toLowerCase()); flaginput = 1; inlen = decideInput[idxin].length(); //decide it is keyowrd for actucal input or it is "sample input" if (StringUtils.containsIgnoreCase(problemIOC, "sample input")) { if (posin > problemIOC.toLowerCase().indexOf("sample input")) { flaginput = 0; inlen = 0; } else { break; } } else { break; } } } //find outputformat position,length of keyword for (idxout = 0; idxout < decideOutput.length; idxout++) { if (StringUtils.containsIgnoreCase(problemIOC, decideOutput[idxout])) { posoutput = problemIOC.toLowerCase().indexOf(decideOutput[idxout].toLowerCase()); flagoutput = 1; outlen = decideOutput[idxout].length(); break; } } //find constraint position,length of keyword for (idxcon = 0; idxcon < decideConstraint.length; idxcon++) { if (StringUtils.containsIgnoreCase(problemIOC, decideConstraint[idxcon])) { poscon = problemIOC.toLowerCase().indexOf(decideConstraint[idxcon].toLowerCase()); flagcon = 1; conlen = decideConstraint[idxcon].length(); break; } } System.out.println("input " + flaginput + " " + inlen + " " + posin); System.out.println("output " + flagoutput + " " + outlen + " " + posoutput); System.out.println("constraint " + flagcon + " " + conlen + " " + poscon); //retrieve problem input and output if present in problem page //if input format is present if (flaginput == 1) { //if input keyword is "input and output" and contraint is present in problem page if (idxin == 6 && flagcon == 1) { problemInput = problemIOC.substring(inlen, poscon); } //if input keyword is "input and output" and contraint is not present in problem page else if (idxin == 6 && flagcon == 0) { problemInput = problemIOC.substring(inlen); } //if output format and constraint is present else if (flagoutput == 1 && flagcon == 1) { //if constraint is present before input format if (poscon < posin) { problemInput = problemIOC.substring(posin + inlen, posoutput); problemOutput = problemIOC.substring(posoutput + outlen); } //if constraint is present before sample else if (poscon < posoutput) { problemInput = problemIOC.substring(inlen, poscon); problemOutput = problemIOC.substring(posoutput + outlen); } else { problemInput = problemIOC.substring(inlen, posoutput); problemOutput = problemIOC.substring(posoutput + outlen, poscon); } } //if constraint is not present else if (flagoutput == 1 && flagcon == 0) { problemInput = problemIOC.substring(inlen, posoutput); problemOutput = problemIOC.substring(posoutput + outlen); } else if (flagoutput == 0 && flagcon == 1) { if (poscon < posin) { problemInput = problemIOC.substring(posin + inlen); } else { problemInput = problemIOC.substring(poscon + conlen, posin); } problemOutput = ""; } else { problemInput = problemIOC.substring(inlen); problemOutput = ""; } } //if input format and output format is not present else { problemInput = ""; problemOutput = ""; } //if constraint is present if (flagcon == 1) { //if constraint is present before input format if (poscon < posin) { problemConstraints = problemIOC.substring(0, posin); } //if constraint is present before output format else if (poscon < posoutput) { problemConstraints = problemIOC.substring(poscon + conlen, posoutput); } else { problemConstraints = problemIOC.substring(poscon + conlen); } } System.out.println("problemInput :" + problemInput); System.out.println("problemOutput :" + problemOutput); System.out.println("problemConstraints :" + problemConstraints); //retrieve problem tags from problem page Element elementtag = doc.getElementsByClass("problem-tags").first().child(1); StringTokenizer st = new StringTokenizer(elementtag.text(), ","); while (st.hasMoreTokens()) { tags.add(st.nextToken().trim()); } //retrieve sample input sample output if present Element elementSIO = doc.getElementsByClass("input-output-container").first(); //if sample input output is present if (elementSIO != null) { //find position of sample output int soutpos = elementSIO.text().indexOf("SAMPLE OUTPUT"); sampleInput = elementSIO.text().substring(12, soutpos); sampleOutput = elementSIO.text().substring(soutpos + 13); System.out.println("Sample input :\n" + sampleInput + "\n\n\n"); System.out.println("Sample Output :\n" + sampleOutput); } else { sampleInput = ""; sampleOutput = ""; } //retrieve problem explanation from problem page if present Element elementExplanation = doc.getElementsByClass("standard-margin").first().child(0); if (elementExplanation.text().toLowerCase().contains("explanation")) { problemExplanation = elementExplanation.nextElementSibling().text(); } System.out.println("Explanation :" + problemExplanation); //retrieve timelimit Element elementTL = doc.getElementsByClass("problem-guidelines").first().child(0).child(1); StringTokenizer stTL = new StringTokenizer(elementTL.ownText(), " "); problemTimeLimit = Double.parseDouble(stTL.nextToken()); //System.out.println("problemTimeLimit :"+problemTimeLimit); //set all retrieved information to problem class problem.setProblemUrl(problemUrl); if (problemTitle.length() == 0) { problemTitle = null; } if (problemStatement.length() == 0) { problemStatement = null; } if (problemInput.length() == 0) { problemInput = null; } if (problemOutput.length() == 0) { problemOutput = null; } if (problemExplanation.length() == 0) { problemExplanation = null; } if (problemConstraints.length() == 0) { problemConstraints = null; } problem.setTitle(problemTitle); problem.setProblemUrl(problemUrl); problem.setProblemStatement(problemStatement); problem.setInputFormat(problemInput); problem.setOutputFormat(problemOutput); problem.setTimeLimit(problemTimeLimit); problem.setExplanation(problemExplanation); problem.setConstraints(problemConstraints); //set sample input output to problem class SampleInputOutput sampleInputOutput = new SampleInputOutput(problem, sampleInput, sampleOutput); problem.getSampleInputOutputs().add(sampleInputOutput); //set platform as hackerearth problem.setPlatform(Platform.HackerEarth); for (String strtag : tags) { problem.getTags().add(strtag); } //store in database Session session = null; Transaction transaction = null; try { //start session session = HibernateUtil.getSessionFactory().openSession(); transaction = session.beginTransaction(); //check if problem is already stored in database String hql = "FROM Problem p where p.problemUrl = :problem_url"; Problem oldProblem = (Problem) session.createQuery(hql).setString("problem_url", problemUrl) .uniqueResult(); String task; //if problem is present in database if (oldProblem != null) { //update the old problem task = "updated"; //retrieve id of old problem problem.setId(oldProblem.getId()); session.delete(oldProblem); session.flush(); session.save(problem); } else { task = "saved"; session.save(problem); } transaction.commit(); //log the info to console Logger.getLogger(CodeForcesCrawler.class.getName()).log(Level.INFO, "{0} {1}", new Object[] { task, problem.getProblemUrl() }); } catch (HibernateException ee) { if (transaction != null) { transaction.rollback(); } Logger.getLogger(CodeForcesCrawler.class.getName()).log(Level.SEVERE, "Cannot Insert/Update problem into databse: " + problemUrl, e); } finally { //close the session if (session != null) { session.close(); } } } catch (Exception ee) { System.out.println(ee.toString()); } } System.out.println("\n\n\n\ntutorial urls\n\n"); try { for (String tutorialurl : tutorialset) { //System.out.println(tutorialurl+"\n\n"); Response tutorialres = Jsoup.connect(tutorialurl).execute(); Document doc = tutorialres.parse(); Tutorial tutorial = new Tutorial(); tutorial.setContent(doc.getElementsByClass("tutorial").first().text()); tutorial.setName(baseUrl); tutorialurl = tutorialurl.substring(0, tutorialurl.length() - 10); StringTokenizer tutorialtok = new StringTokenizer(tutorialurl, "/"); String tempstr = ""; while (tutorialtok.hasMoreTokens()) { tempstr = tutorialtok.nextToken(); } Session session = null; Transaction transaction = null; try { //start session session = HibernateUtil.getSessionFactory().openSession(); transaction = session.beginTransaction(); //check if problem is already stored in database String hql = "FROM Tutorial p where p.name = :name"; Tutorial oldProblem = (Tutorial) session.createQuery(hql).setString("name", tempstr) .uniqueResult(); String task; //if problem is present in database if (oldProblem != null) { //update the old problem task = "updated"; //retrieve id of old problem tutorial.setName(oldProblem.getName()); session.delete(oldProblem); session.flush(); session.save(tutorial); } else { task = "saved"; tutorial.setName(tempstr); session.save(tutorial); } transaction.commit(); //log the info to console Logger.getLogger(CodeForcesCrawler.class.getName()).log(Level.INFO, "{0} {1}", new Object[] { task, tutorial.getName() }); } catch (HibernateException ee) { if (transaction != null) { transaction.rollback(); } Logger.getLogger(CodeForcesCrawler.class.getName()).log(Level.SEVERE, "Cannot Insert/Update problem into databse: " + tempstr, ee); } finally { //close the session if (session != null) { session.close(); } } } } catch (Exception e) { System.out.println(e.getMessage()); } }
From source file:org.apache.hadoop.hbase.backup.util.RestoreTool.java
/** * Calculate region boundaries and add all the column families to the table descriptor * @param regionDirList region dir list/*from w w w . j a v a 2 s.c om*/ * @return a set of keys to store the boundaries */ byte[][] generateBoundaryKeys(ArrayList<Path> regionDirList) throws FileNotFoundException, IOException { TreeMap<byte[], Integer> map = new TreeMap<byte[], Integer>(Bytes.BYTES_COMPARATOR); // Build a set of keys to store the boundaries // calculate region boundaries and add all the column families to the table descriptor for (Path regionDir : regionDirList) { LOG.debug("Parsing region dir: " + regionDir); Path hfofDir = regionDir; if (!fs.exists(hfofDir)) { LOG.warn("HFileOutputFormat dir " + hfofDir + " not found"); } FileStatus[] familyDirStatuses = fs.listStatus(hfofDir); if (familyDirStatuses == null) { throw new IOException("No families found in " + hfofDir); } for (FileStatus stat : familyDirStatuses) { if (!stat.isDirectory()) { LOG.warn("Skipping non-directory " + stat.getPath()); continue; } boolean isIgnore = false; String pathName = stat.getPath().getName(); for (String ignore : ignoreDirs) { if (pathName.contains(ignore)) { LOG.warn("Skipping non-family directory" + pathName); isIgnore = true; break; } } if (isIgnore) { continue; } Path familyDir = stat.getPath(); LOG.debug("Parsing family dir [" + familyDir.toString() + " in region [" + regionDir + "]"); // Skip _logs, etc if (familyDir.getName().startsWith("_") || familyDir.getName().startsWith(".")) { continue; } // start to parse hfile inside one family dir Path[] hfiles = FileUtil.stat2Paths(fs.listStatus(familyDir)); for (Path hfile : hfiles) { if (hfile.getName().startsWith("_") || hfile.getName().startsWith(".") || StoreFileInfo.isReference(hfile.getName()) || HFileLink.isHFileLink(hfile.getName())) { continue; } HFile.Reader reader = HFile.createReader(fs, hfile, conf); final byte[] first, last; try { reader.loadFileInfo(); first = reader.getFirstRowKey(); last = reader.getLastRowKey(); LOG.debug("Trying to figure out region boundaries hfile=" + hfile + " first=" + Bytes.toStringBinary(first) + " last=" + Bytes.toStringBinary(last)); // To eventually infer start key-end key boundaries Integer value = map.containsKey(first) ? (Integer) map.get(first) : 0; map.put(first, value + 1); value = map.containsKey(last) ? (Integer) map.get(last) : 0; map.put(last, value - 1); } finally { reader.close(); } } } } return LoadIncrementalHFiles.inferBoundaries(map); }
From source file:org.dllearner.reasoning.SPARQLReasoner.java
@Override public DatatypePropertyHierarchy prepareDatatypePropertyHierarchy() throws ReasoningMethodUnsupportedException { logger.info("Preparing data property subsumption hierarchy ..."); long startTime = System.currentTimeMillis(); TreeMap<OWLDataProperty, SortedSet<OWLDataProperty>> subsumptionHierarchyUp = new TreeMap<>(); TreeMap<OWLDataProperty, SortedSet<OWLDataProperty>> subsumptionHierarchyDown = new TreeMap<>(); String query = "SELECT * WHERE {" + "?sub a <http://www.w3.org/2002/07/owl#DatatypeProperty> . " + "OPTIONAL {" + "?sub <http://www.w3.org/2000/01/rdf-schema#subPropertyOf> ?sup ." + "?sup a <http://www.w3.org/2002/07/owl#DatatypeProperty> . " + "FILTER(?sup != ?sub && ?sup != <http://www.w3.org/2002/07/owl#topDatatypeProperty> )" + "}" + "FILTER(?sub != <http://www.w3.org/2002/07/owl#topDatatypeProperty> && ?sub != <http://www.w3.org/2002/07/owl#bottomDatatypeProperty>)" + "}"; ResultSet rs = executeSelectQuery(query); while (rs.hasNext()) { QuerySolution qs = rs.next();/* w w w.j a v a 2 s . co m*/ if (qs.get("sub").isURIResource()) { OWLDataProperty sub = df.getOWLDataProperty(IRI.create(qs.get("sub").asResource().getURI())); // add sub properties entry if (!subsumptionHierarchyDown.containsKey(sub)) { subsumptionHierarchyDown.put(sub, new TreeSet<>()); } // add super properties entry if (!subsumptionHierarchyUp.containsKey(sub)) { subsumptionHierarchyUp.put(sub, new TreeSet<>()); } // if there is a super property if (qs.get("sup") != null && qs.get("sup").isURIResource()) { OWLDataProperty sup = df.getOWLDataProperty(IRI.create(qs.get("sup").asResource().getURI())); // add sub properties entry if (!subsumptionHierarchyDown.containsKey(sup)) { subsumptionHierarchyDown.put(sup, new TreeSet<>()); } // add super properties entry if (!subsumptionHierarchyUp.containsKey(sup)) { subsumptionHierarchyUp.put(sup, new TreeSet<>()); } // add super properties entry SortedSet<OWLDataProperty> superClasses = subsumptionHierarchyUp.get(sub); if (superClasses == null) { superClasses = new TreeSet<>(); subsumptionHierarchyUp.put(sub, superClasses); } superClasses.add(sup); // add sub properties entry SortedSet<OWLDataProperty> subProperties = subsumptionHierarchyDown.get(sup); if (subProperties == null) { subProperties = new TreeSet<>(); subsumptionHierarchyDown.put(sup, subProperties); } subProperties.add(sub); } } } logger.info("... done in {}ms", (System.currentTimeMillis() - startTime)); datatypePropertyHierarchy = new DatatypePropertyHierarchy(subsumptionHierarchyUp, subsumptionHierarchyDown); return datatypePropertyHierarchy; }
From source file:org.ecocean.Encounter.java
public void setDynamicProperty(String name, String value) { name = name.replaceAll(";", "_").trim().replaceAll("%20", " "); value = value.replaceAll(";", "_").trim(); if (dynamicProperties == null) { dynamicProperties = name + "=" + value + ";"; } else {// ww w. j a v a 2s. c o m //let's create a TreeMap of the properties TreeMap<String, String> tm = new TreeMap<String, String>(); StringTokenizer st = new StringTokenizer(dynamicProperties, ";"); while (st.hasMoreTokens()) { String token = st.nextToken(); int equalPlace = token.indexOf("="); try { tm.put(token.substring(0, equalPlace), token.substring(equalPlace + 1)); } catch (java.lang.StringIndexOutOfBoundsException soe) { //this is a badly formatted pair that should be ignored } } if (tm.containsKey(name)) { tm.remove(name); tm.put(name, value); //now let's recreate the dynamicProperties String String newProps = tm.toString(); int stringSize = newProps.length(); dynamicProperties = newProps.substring(1, (stringSize - 1)).replaceAll(", ", ";") + ";"; } else { dynamicProperties = dynamicProperties + name + "=" + value + ";"; } } }
From source file:architecture.user.spring.controller.SecureUserMgmtDataController.java
@RequestMapping(value = "/mgmt/permissions/list.json", method = { RequestMethod.POST }) @ResponseBody/* www . j a v a 2s .c o m*/ public Map<String, Object> listAllPermissions(@RequestBody PermsSetForm permsSetGroup) { User currentUser = SecurityHelper.getUser(); List<PermSet> list1 = new ArrayList<PermSet>(); List<PermSet> list2 = new ArrayList<PermSet>(); List<UserPermSet> list3 = new ArrayList<UserPermSet>(); List<GroupPermSet> list4 = new ArrayList<GroupPermSet>(); TreeMap<User, UserPermSet> tree1 = new TreeMap<User, UserPermSet>(new Comparator<User>() { public int compare(User o1, User o2) { return o1.getUsername().toLowerCase().compareTo(o2.getUsername().toLowerCase()); } }); TreeMap<Group, GroupPermSet> tree2 = new TreeMap<Group, GroupPermSet>(new Comparator<Group>() { public int compare(Group o1, Group o2) { return o1.getName().toLowerCase().compareTo(o2.getName().toLowerCase()); } }); PermissionsManagerHelper helper = getPermissionsManagerHelper(permsSetGroup.getObjectType(), permsSetGroup.getObjectId()); for (String permissionName : permsSetGroup.getPerms()) { long permission = Permissions.PermissionAtom.valueOf(permissionName).getAtomId(); if (Permissions.PermissionAtom.valueOf(permissionName) != null) permission = Permissions.PermissionAtom.valueOf(permissionName).getAtomId(); else permission = permissionsManager.getPermissionMask(permissionName); log.debug("permission:" + permissionName + "(" + permission + ")"); // anonymous PermSet p1 = new PermSet(permissionName); p1.setAdditive(helper.anonymousUserHasPermission(PermissionType.ADDITIVE, permission)); p1.setNegative(helper.anonymousUserHasPermission(PermissionType.NEGATIVE, permission)); p1.setInherited(false); list1.add(p1); // member PermSet p2 = new PermSet(permissionName); p2.setAdditive(helper.registeredUserHasPermission(PermissionType.ADDITIVE, permission)); p2.setNegative(helper.registeredUserHasPermission(PermissionType.NEGATIVE, permission)); p2.setInherited(false); list2.add(p2); // users log.debug("user : " + helper.usersWithPermissionCount(PermissionType.ADDITIVE, permission)); for (User user : helper.usersWithPermission(PermissionType.ADDITIVE, permission)) { if (tree1.containsKey(user)) { UserPermSet up = tree1.get(user); up.getPermSet(permissionName, true).setAdditive(true); } else { UserPermSet up = new UserPermSet(user); up.getPermSet(permissionName, true).setAdditive(true); tree1.put(user, up); } } for (User user : helper.usersWithPermission(PermissionType.NEGATIVE, permission)) { if (tree1.containsKey(user)) { UserPermSet up = tree1.get(user); up.getPermSet(permissionName, true).setNegative(true); } else { UserPermSet up = new UserPermSet(user); up.getPermSet(permissionName, true).setNegative(true); tree1.put(user, up); } } // groups log.debug("group : " + helper.groupsWithPermissionCount(PermissionType.ADDITIVE, permission)); for (Group group : helper.groupsWithPermission(PermissionType.ADDITIVE, permission)) { if (tree1.containsKey(group)) { GroupPermSet gp = tree2.get(group); gp.getPermSet(permissionName, true).setAdditive(true); } else { GroupPermSet gp = new GroupPermSet(group); gp.getPermSet(permissionName, true).setAdditive(true); tree2.put(group, gp); } } for (Group group : helper.groupsWithPermission(PermissionType.NEGATIVE, permission)) { if (tree1.containsKey(group)) { GroupPermSet gp = tree2.get(group); gp.getPermSet(permissionName, true).setNegative(true); } else { GroupPermSet gp = new GroupPermSet(group); gp.getPermSet(permissionName, true).setNegative(true); tree2.put(group, gp); } } } list3.addAll(tree1.values()); list4.addAll(tree2.values()); Map<String, Object> map = new HashMap<String, Object>(); map.put("anonymous", list1); map.put("member", list2); map.put("users", list3); map.put("groups", list4); return map; }