List of usage examples for java.util TreeMap get
public V get(Object key)
From source file:module.entities.NameFinder.RegexNameFinder.java
public static String getSignatureFromParagraphs(Elements paragraphs) { String signature = ""; String signName = "", roleName = ""; int signIdx = 0, roleIdx = 0; int row = 0;/* w ww . ja va 2s .co m*/ TreeMap<Integer, String> roles = new TreeMap<Integer, String>(); for (Element n : paragraphs) { row++; String formatedText = Normalizer.normalize(n.text().toUpperCase(locale), Normalizer.Form.NFD) .replaceAll("\\p{M}", ""); if (formatedText.contains(" ") && !formatedText.matches(".*[0-9].*")) { // if (formatedText.contains("<br>")) { // formatedText = formatedText.replaceAll("<br\\s*/>", " "); // } String[] splitedText = formatedText.split(" "); // System.out.println(splitedText.length); if (splitedText.length < 7) { boolean isSign = false; String text = ""; for (int z = 0; z < splitedText.length; z++) { String splText = splitedText[z].replaceAll("[\\s.]", "").replaceAll("\u00a0", "") .replaceAll("", "").replaceAll(",", ""); if (names.contains(splText) || surnames.contains(splText)) { signName += splText + " "; signIdx = row; isSign = true; } text += splText + " "; // if (z == splitedText.length-1){ // System.out.println(signName.trim()); // } } if (!isSign) { roleIdx = row; if (!text.contains(" ") && !text.contains("")) { roles.put(roleIdx, text.trim()); } } } } } for (Integer roleRow : roles.keySet()) { // if (signName.length() == 0) { if (Math.abs(signIdx - roleRow) < 4) { roleName += roles.get(roleRow) + " "; } } if (signName.length() > 0) { signature = signName + "#" + roleName; } return signature; }
From source file:com.sfs.whichdoctor.beans.PersonBean.java
/** * Gets the accreditation total./*from w ww . ja v a 2 s . c o m*/ * * @param committee the committee * @param trainingTypes the training types * * @return the accreditation total */ public final String getAccreditationTotal(final String committee, final Collection<String> trainingTypes) { int totalCore = 0; int totalNonCore = 0; if (committee != null) { for (String type : trainingTypes) { TreeMap<String, AccreditationBean[]> accreds = this.getTrainingSummary(type); if (accreds != null) { for (String key : accreds.keySet()) { AccreditationBean[] details = accreds.get(key); AccreditationBean core = details[0]; AccreditationBean nonCore = details[0]; if (StringUtils.equalsIgnoreCase(committee, core.getSpecialtyType())) { totalCore += core.getWeeksCertified(); totalNonCore += nonCore.getWeeksCertified(); } } } } } return Formatter.getWholeMonths(totalCore) + " (" + Formatter.getWholeMonths(totalNonCore) + ")"; }
From source file:org.squale.squaleweb.applicationlayer.action.export.ppt.AuditReportPPTData.java
/** * Add array of results for the application in a slide * /*from www .ja v a2 s.c o m*/ * @param slideToSet slide to set * @param where place to add results * @throws IOException if error * @throws PPTGeneratorException */ public void setApplicationQualityResults(Slide slideToSet, Rectangle where) throws IOException, PPTGeneratorException { log.info("AuditReturn - setApplicationQualityResults"); // Create map for fill table TreeMap factorsMap = new TreeMap(); for (int i = 0; i < projectReports.size(); i++) { log.info("AuditReturn - setApplicationQualityResults Project n" + i); ProjectReportDTO curProject = (ProjectReportDTO) projectReports.get(i); for (int j = 0; j < curProject.getQualityResults().size(); j++) { QualityReportDTO factor = (QualityReportDTO) curProject.getQualityResults().get(j); String factorName = WebMessages.getString(request, factor.getRule().getName()); TreeMap results = (TreeMap) factorsMap.get(factorName); if (results == null) { results = new TreeMap(); } results.put(curProject.getName(), new Float[] { new Float(factor.getMeanMark()), new Float(factor.getPreviousScore()) }); factorsMap.put(factorName, results); } } // create table and add it to the slide in function of the map previously created createApplicationResultsTable(slideToSet, where, factorsMap); log.info("AuditReturn - setApplicationQualityResults done"); }
From source file:org.apache.nutch.crawl.CrawlDbReader.java
private TreeMap<String, Writable> processStatJobHelper(String crawlDb, Configuration config, boolean sort) throws IOException, InterruptedException, ClassNotFoundException { Path tmpFolder = new Path(crawlDb, "stat_tmp" + System.currentTimeMillis()); Job job = NutchJob.getInstance(config); config = job.getConfiguration();// w w w . jav a 2 s . c om job.setJobName("stats " + crawlDb); config.setBoolean("db.reader.stats.sort", sort); FileInputFormat.addInputPath(job, new Path(crawlDb, CrawlDb.CURRENT_NAME)); job.setInputFormatClass(SequenceFileInputFormat.class); job.setJarByClass(CrawlDbReader.class); job.setMapperClass(CrawlDbStatMapper.class); job.setCombinerClass(CrawlDbStatReducer.class); job.setReducerClass(CrawlDbStatReducer.class); FileOutputFormat.setOutputPath(job, tmpFolder); job.setOutputFormatClass(SequenceFileOutputFormat.class); job.setOutputKeyClass(Text.class); job.setOutputValueClass(NutchWritable.class); // https://issues.apache.org/jira/browse/NUTCH-1029 config.setBoolean("mapreduce.fileoutputcommitter.marksuccessfuljobs", false); FileSystem fileSystem = tmpFolder.getFileSystem(config); try { boolean success = job.waitForCompletion(true); if (!success) { String message = "CrawlDbReader job did not succeed, job status:" + job.getStatus().getState() + ", reason: " + job.getStatus().getFailureInfo(); LOG.error(message); fileSystem.delete(tmpFolder, true); throw new RuntimeException(message); } } catch (IOException | InterruptedException | ClassNotFoundException e) { LOG.error(StringUtils.stringifyException(e)); fileSystem.delete(tmpFolder, true); throw e; } // reading the result SequenceFile.Reader[] readers = SegmentReaderUtil.getReaders(tmpFolder, config); Text key = new Text(); NutchWritable value = new NutchWritable(); TreeMap<String, Writable> stats = new TreeMap<>(); for (int i = 0; i < readers.length; i++) { SequenceFile.Reader reader = readers[i]; while (reader.next(key, value)) { String k = key.toString(); Writable val = stats.get(k); if (val == null) { stats.put(k, value.get()); continue; } if (k.equals("sc")) { float min = Float.MAX_VALUE; float max = Float.MIN_VALUE; if (stats.containsKey("scn")) { min = ((FloatWritable) stats.get("scn")).get(); } else { min = ((FloatWritable) stats.get("sc")).get(); } if (stats.containsKey("scx")) { max = ((FloatWritable) stats.get("scx")).get(); } else { max = ((FloatWritable) stats.get("sc")).get(); } float fvalue = ((FloatWritable) value.get()).get(); if (min > fvalue) { min = fvalue; } if (max < fvalue) { max = fvalue; } stats.put("scn", new FloatWritable(min)); stats.put("scx", new FloatWritable(max)); } else if (k.equals("ft") || k.equals("fi")) { long min = Long.MAX_VALUE; long max = Long.MIN_VALUE; String minKey = k + "n"; String maxKey = k + "x"; if (stats.containsKey(minKey)) { min = ((LongWritable) stats.get(minKey)).get(); } else if (stats.containsKey(k)) { min = ((LongWritable) stats.get(k)).get(); } if (stats.containsKey(maxKey)) { max = ((LongWritable) stats.get(maxKey)).get(); } else if (stats.containsKey(k)) { max = ((LongWritable) stats.get(k)).get(); } long lvalue = ((LongWritable) value.get()).get(); if (min > lvalue) { min = lvalue; } if (max < lvalue) { max = lvalue; } stats.put(k + "n", new LongWritable(min)); stats.put(k + "x", new LongWritable(max)); } else if (k.equals("sct")) { FloatWritable fvalue = (FloatWritable) value.get(); ((FloatWritable) val).set(((FloatWritable) val).get() + fvalue.get()); } else if (k.equals("scd")) { MergingDigest tdigest = null; MergingDigest tdig = MergingDigest .fromBytes(ByteBuffer.wrap(((BytesWritable) value.get()).getBytes())); if (val instanceof BytesWritable) { tdigest = MergingDigest.fromBytes(ByteBuffer.wrap(((BytesWritable) val).getBytes())); tdigest.add(tdig); } else { tdigest = tdig; } ByteBuffer tdigestBytes = ByteBuffer.allocate(tdigest.smallByteSize()); tdigest.asSmallBytes(tdigestBytes); stats.put(k, new BytesWritable(tdigestBytes.array())); } else { LongWritable lvalue = (LongWritable) value.get(); ((LongWritable) val).set(((LongWritable) val).get() + lvalue.get()); } } reader.close(); } // remove score, fetch interval, and fetch time // (used for min/max calculation) stats.remove("sc"); stats.remove("fi"); stats.remove("ft"); // removing the tmp folder fileSystem.delete(tmpFolder, true); return stats; }
From source file:org.apache.nutch.crawl.CrawlDbReader.java
public void processStatJob(String crawlDb, Configuration config, boolean sort) throws IOException, InterruptedException, ClassNotFoundException { double quantiles[] = { .01, .05, .1, .2, .25, .3, .4, .5, .6, .7, .75, .8, .9, .95, .99 }; if (config.get("db.stats.score.quantiles") != null) { List<Double> qs = new ArrayList<>(); for (String s : config.getStrings("db.stats.score.quantiles")) { try { double d = Double.parseDouble(s); if (d >= 0.0 && d <= 1.0) { qs.add(d);/*from w w w . ja va 2s .c o m*/ } else { LOG.warn("Skipping quantile {} not in range in db.stats.score.quantiles: {}", s); } } catch (NumberFormatException e) { LOG.warn("Skipping bad floating point number {} in db.stats.score.quantiles: {}", s, e.getMessage()); } quantiles = new double[qs.size()]; int i = 0; for (Double q : qs) { quantiles[i++] = q; } Arrays.sort(quantiles); } } if (LOG.isInfoEnabled()) { LOG.info("CrawlDb statistics start: " + crawlDb); } TreeMap<String, Writable> stats = processStatJobHelper(crawlDb, config, sort); if (LOG.isInfoEnabled()) { LOG.info("Statistics for CrawlDb: " + crawlDb); LongWritable totalCnt = new LongWritable(0); if (stats.containsKey("T")) { totalCnt = ((LongWritable) stats.get("T")); stats.remove("T"); } LOG.info("TOTAL urls:\t" + totalCnt.get()); for (Map.Entry<String, Writable> entry : stats.entrySet()) { String k = entry.getKey(); long value = 0; double fvalue = 0.0; byte[] bytesValue = null; Writable val = entry.getValue(); if (val instanceof LongWritable) { value = ((LongWritable) val).get(); } else if (val instanceof FloatWritable) { fvalue = ((FloatWritable) val).get(); } else if (val instanceof BytesWritable) { bytesValue = ((BytesWritable) val).getBytes(); } if (k.equals("scn")) { LOG.info("min score:\t" + fvalue); } else if (k.equals("scx")) { LOG.info("max score:\t" + fvalue); } else if (k.equals("sct")) { LOG.info("avg score:\t" + (fvalue / totalCnt.get())); } else if (k.equals("scNaN")) { LOG.info("score == NaN:\t" + value); } else if (k.equals("ftn")) { LOG.info("earliest fetch time:\t" + new Date(1000 * 60 * value)); } else if (k.equals("ftx")) { LOG.info("latest fetch time:\t" + new Date(1000 * 60 * value)); } else if (k.equals("ftt")) { LOG.info("avg of fetch times:\t" + new Date(1000 * 60 * (value / totalCnt.get()))); } else if (k.equals("fin")) { LOG.info("shortest fetch interval:\t{}", TimingUtil.secondsToDaysHMS(value)); } else if (k.equals("fix")) { LOG.info("longest fetch interval:\t{}", TimingUtil.secondsToDaysHMS(value)); } else if (k.equals("fit")) { LOG.info("avg fetch interval:\t{}", TimingUtil.secondsToDaysHMS(value / totalCnt.get())); } else if (k.startsWith("status")) { String[] st = k.split(" "); int code = Integer.parseInt(st[1]); if (st.length > 2) LOG.info(" " + st[2] + " :\t" + val); else LOG.info(st[0] + " " + code + " (" + CrawlDatum.getStatusName((byte) code) + "):\t" + val); } else if (k.equals("scd")) { MergingDigest tdigest = MergingDigest.fromBytes(ByteBuffer.wrap(bytesValue)); for (double q : quantiles) { LOG.info("score quantile {}:\t{}", q, tdigest.quantile(q)); } } else { LOG.info(k + ":\t" + val); } } } if (LOG.isInfoEnabled()) { LOG.info("CrawlDb statistics: done"); } }
From source file:net.opentsdb.tree.Tree.java
/** * Retrieves a single rule from the rule set given a level and order * @param level The level where the rule resides * @param order The order in the level where the rule resides * @return The rule if found, null if not found *//*from w ww . j a v a 2s . c o m*/ public TreeRule getRule(final int level, final int order) { if (rules == null || rules.isEmpty()) { return null; } TreeMap<Integer, TreeRule> rule_level = rules.get(level); if (rule_level == null || rule_level.isEmpty()) { return null; } return rule_level.get(order); }
From source file:io.mapzone.arena.analytics.graph.SingleSourceNodeGraphFunction.java
@Override public void createContents(final MdToolkit tk, final Composite parent, final Graph graph) { try {/*ww w . ja v a 2 s . co m*/ super.createContents(tk, parent, graph); final FeaturePropertySelectorUI sourcePropertiesUI = new FeaturePropertySelectorUI(tk, parent, prop -> { this.selectedSourcePropertyDescriptor = prop; EventManager.instance().publish(new GraphFunctionConfigurationChangedEvent( SingleSourceNodeGraphFunction.this, "sourcePropertyDescriptor", prop)); }); final FeatureSourceSelectorUI sourceFeaturesUI = new FeatureSourceSelectorUI(tk, parent, fs -> { this.selectedSourceFeatureSource = fs; EventManager.instance().publish(new GraphFunctionConfigurationChangedEvent( SingleSourceNodeGraphFunction.this, "sourceFeatureSource", fs)); sourcePropertiesUI.setFeatureSource(fs); }); final TreeMap<String, EdgeFunction> edgeFunctions = Maps.newTreeMap(); for (Class<EdgeFunction> cl : availableFunctions) { try { EdgeFunction function = cl.newInstance(); function.init(this); edgeFunctions.put(function.title(), function); } catch (Exception e) { throw new RuntimeException(e); } } final Composite edgeFunctionContainer = tk.createComposite(parent, SWT.NONE); edgeFunctionContainer.setLayout(FormLayoutFactory.defaults().create()); final ComboViewer edgeFunctionsUI = new ComboViewer(parent, SWT.SINGLE | SWT.BORDER | SWT.DROP_DOWN | SWT.READ_ONLY); edgeFunctionsUI.setContentProvider(new ArrayContentProvider()); edgeFunctionsUI.setInput(edgeFunctions.keySet()); edgeFunctionsUI.addSelectionChangedListener(ev -> { String selected = SelectionAdapter.on(ev.getSelection()).first(String.class).get(); EdgeFunction function = edgeFunctions.get(selected); // FormDataFactory.on( edgeFunctionContainer ).top( // edgeFunctionsUI.getCombo(), 4 ) // .height( function.preferredHeight() ).left( COLUMN_2 ).right( 100 // ); FormDataFactory.on(edgeFunctionContainer).height(function.preferredHeight()); UIUtils.disposeChildren(edgeFunctionContainer); // create panel function.createContents(tk, edgeFunctionContainer, selectedSourceFeatureSource); // FormDataFactory.on( edgeFunctionContainer ).fill(); // resize also the top container // XXX depends on the parent structure ((FormData) parent.getParent().getParent().getLayoutData()).height = preferredHeight() + function.preferredHeight(); parent.getParent().getParent().getParent().layout(); this.selectedEdgeFunction = function; }); final Label selectSourceTableLabel = tk.createLabel(parent, i18n.get("selectSourceTable"), SWT.NONE); FormDataFactory.on(selectSourceTableLabel).top(15).left(1); FormDataFactory.on(sourceFeaturesUI.control()).top(selectSourceTableLabel, 2).left(1); final Label selectSourcePropertiesLabel = tk.createLabel(parent, i18n.get("selectSourceProperties"), SWT.NONE); FormDataFactory.on(selectSourcePropertiesLabel).top(sourceFeaturesUI.control(), 4).left(COLUMN_2); FormDataFactory.on(sourcePropertiesUI.control()).top(selectSourcePropertiesLabel, 2).left(COLUMN_2); final Label selectEdgeFunctionLabel = tk.createLabel(parent, i18n.get("selectEdgeFunction"), SWT.NONE); FormDataFactory.on(selectEdgeFunctionLabel).top(sourcePropertiesUI.control(), 6).left(1); FormDataFactory.on(edgeFunctionsUI.getCombo()).top(selectEdgeFunctionLabel, 2).left(1); FormDataFactory.on(edgeFunctionContainer).fill().top(edgeFunctionsUI.getCombo(), 4).left(COLUMN_2); // event listener EventManager.instance().subscribe(this, ifType(EdgeFunctionConfigurationDoneEvent.class, ev -> ev.status.get() == Boolean.TRUE && ev.getSource().equals(selectedEdgeFunction))); EventManager.instance().subscribe(this, ifType(GraphFunctionConfigurationChangedEvent.class, ev -> ev.getSource().equals(SingleSourceNodeGraphFunction.this))); } catch (Exception e) { StatusDispatcher.handleError("", e); } }
From source file:org.alfresco.repo.content.cleanup.ContentStoreCleaner.java
/** * /*from w w w. j a va 2 s . com*/ * @param maxTimeExclusive the max orphan time (exclusive) * @param batchSize the maximum number of orphans to process * @return Returns the last processed orphan ID or <tt>null</tt> if nothing was processed */ private Long cleanBatch(final long maxTimeExclusive, final int batchSize) { // Get a bunch of cleanable URLs final TreeMap<Long, String> urlsById = new TreeMap<Long, String>(); ContentUrlHandler contentUrlHandler = new ContentUrlHandler() { @Override public void handle(Long id, String contentUrl, Long orphanTime) { urlsById.put(id, contentUrl); } }; // Get a bunch of cleanable URLs contentDataDAO.getContentUrlsOrphaned(contentUrlHandler, maxTimeExclusive, batchSize); // Shortcut, if necessary if (urlsById.size() == 0) { return null; } // Compile list of IDs and do a mass delete, recording the IDs to find the largest Long lastId = urlsById.lastKey(); List<Long> ids = new ArrayList<Long>(urlsById.keySet()); contentDataDAO.deleteContentUrls(ids); // No problems, so far (ALF-1998: contentStoreCleanerJob leads to foreign key exception) // Now attempt to physically delete the URLs for (Long id : ids) { String contentUrl = urlsById.get(id); // Handle failures boolean deleted = eagerContentStoreCleaner.deleteFromStores(contentUrl); if (!deleted) { switch (deletionFailureAction) { case KEEP_URL: // Keep the URL, but with an orphan time of 0 so that it is recorded contentDataDAO.createContentUrlOrphaned(contentUrl, new Date(0L)); case IGNORE: break; default: throw new IllegalStateException("Unknown deletion failure action: " + deletionFailureAction); } } } // Done return lastId; }
From source file:com.sfs.whichdoctor.beans.BulkEmailBean.java
/** * Gets the ordered email recipients./* ww w . j av a 2 s . c o m*/ * * @return the ordered email recipients */ public final Collection<EmailRecipientBean> getOrderedEmailRecipients() { if (this.orderedEmailRecipients == null) { this.orderedEmailRecipients = new ArrayList<EmailRecipientBean>(); TreeMap<String, EmailRecipientBean> orderMap = new TreeMap<String, EmailRecipientBean>(); for (EmailRecipientBean recipient : getEmailRecipients()) { if (recipient != null) { if (StringUtils.isNotBlank(recipient.getOrder())) { orderMap.put(recipient.getOrder(), recipient); } } } for (String key : orderMap.keySet()) { EmailRecipientBean recipient = orderMap.get(key); this.orderedEmailRecipients.add(recipient); } } return this.orderedEmailRecipients; }
From source file:org.eclipse.dataset.Stats.java
public static double[] outlierValuesMap(final Dataset a, int nl, int nh) { final TreeMap<Double, Integer> lMap = new TreeMap<Double, Integer>(); final TreeMap<Double, Integer> hMap = new TreeMap<Double, Integer>(); int ml = 0;/*from w w w .j a va 2 s . c om*/ int mh = 0; IndexIterator it = a.getIterator(); while (it.hasNext()) { Double x = a.getElementDoubleAbs(it.index); Integer i; if (ml == nl) { Double k = lMap.lastKey(); if (x < k) { i = lMap.get(k) - 1; if (i == 0) { lMap.remove(k); } else { lMap.put(k, i); } i = lMap.get(x); if (i == null) { lMap.put(x, 1); } else { lMap.put(x, i + 1); } } } else { i = lMap.get(x); if (i == null) { lMap.put(x, 1); } else { lMap.put(x, i + 1); } ml++; } if (mh == nh) { Double k = hMap.firstKey(); if (x > k) { i = hMap.get(k) - 1; if (i == 0) { hMap.remove(k); } else { hMap.put(k, i); } i = hMap.get(x); if (i == null) { hMap.put(x, 1); } else { hMap.put(x, i + 1); } } } else { i = hMap.get(x); if (i == null) { hMap.put(x, 1); } else { hMap.put(x, i + 1); } mh++; } } // Attempt to make values distinct double lx = lMap.lastKey(); double hx = hMap.firstKey(); if (lx >= hx) { Double h = hMap.higherKey(lx); if (h != null) { hx = h; mh--; } else { Double l = lMap.lowerKey(hx); if (l != null) { lx = l; ml--; } } } return new double[] { lMap.lastKey(), hMap.firstKey(), ml, mh }; }