List of usage examples for java.util.concurrent ConcurrentSkipListSet add
public boolean add(E e)
From source file:cn.wanghaomiao.seimi.def.DefaultLocalQueue.java
@Override public void addProcessed(Request req) { ConcurrentSkipListSet<String> set = getProcessedSet(req.getCrawlerName()); String sign = DigestUtils.md5Hex(req.getUrl()); set.add(sign); }
From source file:annis.gui.flatquerybuilder.SpanBox.java
public SpanBox(final String ebene, final FlatQueryBuilder sq) { this.ebene = ebene; this.sq = sq; sb = new HorizontalLayout(); sb.setImmediate(true);//from www . j a v a2 s . c o m sb.setSpacing(true); sb.setMargin(true); ConcurrentSkipListSet<String> annos = new ConcurrentSkipListSet<String>(); for (String a : sq.getAvailableAnnotationLevels(ebene)) { annos.add(a); } this.annonames = annos; Label tf = new Label(ebene); sb.addComponent(tf); this.cb = new SensitiveComboBox(); cb.setInputPrompt(ebene); cb.setWidth(SB_CB_WIDTH); // configure & load content cb.setImmediate(true); for (String annoname : this.annonames) { cb.addItem(annoname); } cb.setFilteringMode(AbstractSelect.Filtering.FILTERINGMODE_OFF); cb.addListener((FieldEvents.TextChangeListener) this); sb.addComponent(cb); HorizontalLayout sbtoolbar = new HorizontalLayout(); sbtoolbar.setSpacing(true); // searchbox tickbox for regex CheckBox tb = new CheckBox("Regex"); tb.setImmediate(true); sbtoolbar.addComponent(tb); tb.addListener(new ValueChangeListener() { // TODO make this into a nice subroutine @Override public void valueChange(ValueChangeEvent event) { boolean r = reBox.booleanValue(); cb.setNewItemsAllowed(r); if (!r) { SpanBox.buildBoxValues(cb, ebene, sq); } else if (cb.getValue() != null) { String escapedItem = sq.escapeRegexCharacters(cb.getValue().toString()); cb.addItem(escapedItem); cb.setValue(escapedItem); } } }); reBox = tb; // close the searchbox btClose = new Button(BUTTON_CLOSE_LABEL, (Button.ClickListener) this); btClose.setStyleName(ChameleonTheme.BUTTON_SMALL); sbtoolbar.addComponent(btClose); // make visable sb.addComponent(sbtoolbar); setContent(sb); }
From source file:annis.gui.flatquerybuilder.SearchBox.java
public SearchBox(final String ebene, final FlatQueryBuilder sq, final VerticalNode vn) { this.vn = vn; this.ebene = ebene; this.sq = sq; VerticalLayout sb = new VerticalLayout(); sb.setImmediate(true);//from w w w .j a va 2s .c o m sb.setSpacing(true); ConcurrentSkipListSet<String> annos = new ConcurrentSkipListSet<String>(); for (String a : sq.getAvailableAnnotationLevels(ebene)) { annos.add(a); } this.annonames = annos;//by Martin this.cb = new SensitiveComboBox(); cb.setCaption(ebene); cb.setInputPrompt(ebene); cb.setWidth(SB_CB_WIDTH); // configure & load content cb.setImmediate(true); for (String annoname : this.annonames) { cb.addItem(annoname); } cb.setFilteringMode(Filtering.FILTERINGMODE_OFF);//necessary? cb.addListener((FieldEvents.TextChangeListener) this); sb.addComponent(cb); HorizontalLayout sbtoolbar = new HorizontalLayout(); sbtoolbar.setSpacing(true); // searchbox tickbox for regex CheckBox tb = new CheckBox("Regex"); tb.setImmediate(true); sbtoolbar.addComponent(tb); tb.addListener(new ValueChangeListener() { // TODO make this into a nice subroutine @Override public void valueChange(ValueChangeEvent event) { boolean r = reBox.booleanValue(); cb.setNewItemsAllowed(r); if (!r) { SpanBox.buildBoxValues(cb, ebene, sq); } else if (cb.getValue() != null) { String escapedItem = sq.escapeRegexCharacters(cb.getValue().toString()); cb.addItem(escapedItem); cb.setValue(escapedItem); } } }); reBox = tb; // close the searchbox btClose = new Button(BUTTON_CLOSE_LABEL, (Button.ClickListener) this); btClose.setStyleName(ChameleonTheme.BUTTON_SMALL); sbtoolbar.addComponent(btClose); sb.addComponent(sbtoolbar); sb.setSpacing(true); setContent(sb); }
From source file:annis.gui.flatquerybuilder.ValueField.java
@Override public void textChange(TextChangeEvent event) { ReducingStringComparator rsc = sq.getRSC(); String fm = sq.getFilterMechanism(); if (!"generic".equals(fm)) { ConcurrentSkipListSet<String> notInYet = new ConcurrentSkipListSet<>(); String txt = event.getText(); if (!txt.equals("")) { scb.removeAllItems();// w w w . ja v a2 s. c om for (Iterator<String> it = values.keySet().iterator(); it.hasNext();) { String s = it.next(); if (rsc.compare(s, txt, fm) == 0) { scb.addItem(s); } else { notInYet.add(s); } } //startsWith for (String s : notInYet) { if (rsc.startsWith(s, txt, fm)) { scb.addItem(s); notInYet.remove(s); } } //contains for (String s : notInYet) { if (rsc.contains(s, txt, fm)) { scb.addItem(s); } } } else { buildValues(this.vm); } } else { String txt = event.getText(); HashMap<Integer, Collection> levdistvals = new HashMap<>(); if (txt.length() > 1) { scb.removeAllItems(); for (String s : values.keySet()) { Integer d = StringUtils.getLevenshteinDistance(removeAccents(txt).toLowerCase(), removeAccents(s).toLowerCase()); if (levdistvals.containsKey(d)) { levdistvals.get(d).add(s); } if (!levdistvals.containsKey(d)) { Set<String> newc = new TreeSet<>(); newc.add(s); levdistvals.put(d, newc); } } SortedSet<Integer> keys = new TreeSet<>(levdistvals.keySet()); for (Integer k : keys.subSet(0, 10)) { List<String> valueList = new ArrayList(levdistvals.get(k)); Collections.sort(valueList, String.CASE_INSENSITIVE_ORDER); for (String v : valueList) { scb.addItem(v); } } } } }
From source file:annis.gui.flatquerybuilder.SearchBox.java
@Override public void textChange(TextChangeEvent event) { if ("specific".equals(sq.getFilterMechanism())) { ConcurrentSkipListSet<String> notInYet = new ConcurrentSkipListSet<String>(); reducingStringComparator esc = new reducingStringComparator(); String txt = event.getText(); if (!txt.equals("")) { cb.removeAllItems();//from www. j a v a 2 s . c om for (Iterator<String> it = annonames.iterator(); it.hasNext();) { String s = it.next(); if (esc.compare(s, txt) == 0) { cb.addItem(s); } else { notInYet.add(s); } } //startsWith for (String s : notInYet) { if (esc.startsWith(s, txt)) { cb.addItem(s); notInYet.remove(s); } } //contains for (String s : notInYet) { if (esc.contains(s, txt)) { cb.addItem(s); } } } else { //have a look and speed it up SpanBox.buildBoxValues(cb, ebene, sq); } } if ("levenshtein".equals(sq.getFilterMechanism())) { String txt = event.getText(); HashMap<Integer, Collection> levdistvals = new HashMap<Integer, Collection>(); if (txt.length() > 1) { cb.removeAllItems(); 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.enitalk.configs.DateCache.java
public NavigableSet<DateTime> days(JsonNode tree, String tz, JsonNode teacherNode) { ConcurrentSkipListSet<DateTime> dates = new ConcurrentSkipListSet<>(); Iterator<JsonNode> els = tree.elements(); DateTimeZone dz = DateTimeZone.forID(tz); DateTimeFormatter hour = DateTimeFormat.forPattern("HH:mm").withZone(dz); DateTime today = DateTime.now().millisOfDay().setCopy(0); while (els.hasNext()) { JsonNode el = els.next();//w w w .j a va 2 s . c o m String day = el.path("day").asText(); boolean plus = today.getDayOfWeek() > days.get(day); if (el.has("start") && el.has("end")) { DateTime start = hour.parseDateTime(el.path("start").asText()).dayOfMonth() .setCopy(today.getDayOfMonth()).monthOfYear().setCopy(today.getMonthOfYear()).year() .setCopy(today.getYear()).withDayOfWeek(days.get(day)).plusWeeks(plus ? 1 : 0); DateTime end = hour.parseDateTime(el.path("end").asText()).dayOfMonth() .setCopy(today.getDayOfMonth()).monthOfYear().setCopy(today.getMonthOfYear()).year() .setCopy(today.getYear()).withDayOfWeek(days.get(day)).plusWeeks(plus ? 1 : 0); Hours hours = Hours.hoursBetween(start, end); int hh = hours.getHours() + 1; while (hh-- > 0) { dates.add(start.plusHours(hh).toDateTime(DateTimeZone.UTC)); } } else { List<String> datesAv = jackson.convertValue(el.path("times"), List.class); logger.info("Array of dates {} {}", datesAv, day); datesAv.forEach((String dd) -> { DateTime date = hour.parseDateTime(dd).dayOfMonth().setCopy(today.getDayOfMonth()).monthOfYear() .setCopy(today.getMonthOfYear()).year().setCopy(today.getYear()) .withDayOfWeek(days.get(day)).plusWeeks(plus ? 1 : 0); dates.add(date.toDateTime(DateTimeZone.UTC)); }); } } final TreeSet<DateTime> addWeek = new TreeSet<>(); for (int i = 1; i < 2; i++) { for (DateTime e : dates) { addWeek.add(e.plusWeeks(i)); } } dates.addAll(addWeek); DateTime nowUtc = DateTime.now().toDateTime(DateTimeZone.UTC); nowUtc = nowUtc.plusHours(teacherNode.path("notice").asInt(2)); NavigableSet<DateTime> ss = dates.tailSet(nowUtc, true); return ss; }
From source file:it.geosolutions.geobatch.destination.vulnerability.VulnerabilityComputation.java
private void calculateCell(RenderedImage currentImage, Map<Integer, TargetInfo> currentBPT, String targetID, String outFeatureName, int trace, VulnerabilityStatsEngine vse, OutputObject vulnerabilityObj, VulnerabilityOperation concreteOperation, VulnerabilityMonitor monitor, List<Double> allDistances, int reportingLoopStep, String geoName, Filter baseFilter, ConcurrentSkipListSet<BigDecimal> arcIdsSet, SimpleFeature currentCell) {/*from www . ja v a 2 s . com*/ // Selection of the id associated to the feature. BigDecimal cellId = ((BigDecimal) currentCell.getAttribute(ID_GEO_ARCO)); // Check if the feature has been already taken boolean newCell = arcIdsSet.add(cellId); if (newCell) { Map<Double, ResultStatsMap> statList = new TreeMap<Double, ResultStatsMap>(); // For level 3, get all the arcs that intersect with // the current grid cell FeatureIterator<SimpleFeature> iterator = null; try { iterator = getArcsForCell(geoName, baseFilter, currentCell); while (iterator.hasNext()) { calculateBetchOfArcsForCell(currentImage, currentBPT, vse, allDistances, statList, iterator, cellId.toString(), MAX_TEMP_CALC, monitor, targetID); } } catch (Exception e) { monitor.incrementErrors(); monitor.newMessage(new VulnerabilityMonitor.Message(TYPE.ERROR, "Raster=" + targetID + ", Error reading arcs for cell " + cellId, e)); LOGGER.error("Raster=" + targetID + ", Error reading arcs for cell " + cellId, e); } finally { if (iterator != null) { iterator.close(); } } // write cell stats for (Double processedDistance : allDistances) { try { // Writing of the result for the // selected distance and Id concreteOperation.writeOutputObjects(trace, vulnerabilityObj, monitor.getTotal(), outFeatureName, currentCell, buildFid(cellId.toString(), processedDistance), statList.get(processedDistance).getStatsMap(), partner); } catch (Exception e) { monitor.incrementErrors(); monitor.newMessage(new VulnerabilityMonitor.Message(TYPE.ERROR, "Raster=" + targetID + ", Error writing cell " + cellId + " on " + geoName, e)); LOGGER.error("Raster=" + targetID + ", Error writing objects on " + geoName, e); } } // Update of the LoopCounter monitor.incrementCounter(); monitor.newMessage( new VulnerabilityMonitor.Message(TYPE.PROGRESS, "Calculating vulnerability for " + targetID)); // DEBUG: indication of which arc is calculated if (LOGGER.isDebugEnabled() && currentCell != null) { LOGGER.debug("Raster=" + targetID + ", Computed cell " + cellId); } } }
From source file:it.geosolutions.geobatch.destination.vulnerability.VulnerabilityComputation.java
/** * Calculate all the buffers geometries for the next batchSize set of arcs. * /*www . j a v a 2 s .co m*/ * @param batchSize * @param arcIdsSet * @param vse * @param allDistances * @param monitor * @param targetID * @param x * @param y * @param arcList * @param arcIds * @param bufferList * @return */ private int calculateBuffersOnBatch(int batchSize, ConcurrentSkipListSet<BigDecimal> arcIdsSet, VulnerabilityStatsEngine vse, List<Double> allDistances, VulnerabilityMonitor monitor, String targetID, int x, int y, List<SimpleFeature> arcList, List<String> arcIds, List<MultipleBufferMap> bufferList) { int batchCounter = 0; try { while (batchCounter < batchSize && hasMoreInput(true)) { SimpleFeature inputFeature = readInput(); BigDecimal arcId = ((BigDecimal) inputFeature.getAttribute(ID_GEO_ARCO)); // Check if the feature has been already // taken boolean newArc = arcIdsSet.add(arcId); if (newArc) { try { MultipleBufferMap mbm = vse.computeBuffersOnArcs(Collections.singletonList(inputFeature), allDistances); bufferList.add(mbm); arcList.add(inputFeature); arcIds.add(arcId.toString()); } catch (Exception e) { monitor.incrementErrors(); monitor.newMessage(new VulnerabilityMonitor.Message(TYPE.ERROR, "Error calculating buffers for arc " + arcId, e)); LOGGER.error("Error calculating buffers for arc " + arcId, e); } } batchCounter++; } } catch (Exception e1) { monitor.incrementErrors(); monitor.newMessage(new VulnerabilityMonitor.Message(TYPE.ERROR, "Raster=" + targetID + ", TILE=(" + x + "," + y + ") Error reading arcs", e1)); LOGGER.error("Raster=" + targetID + ", TILE=(" + x + "," + y + ") Error reading arcs batch", e1); } return batchCounter; }
From source file:oculus.aperture.graph.aggregation.impl.ModularityAggregator.java
@Override public void run() { logger.debug("Running kSnap clustering algorithm on " + nodeMap.size() + " nodes and " + linkMap.size() + " links..."); StopWatch stopWatch = new StopWatch(); stopWatch.start();// w ww. j av a2 s . com HashMap<String, ModularityNode> linklookup = new HashMap<String, ModularityAggregator.ModularityNode>(); for (Node n : nodeMap.values()) { ModularityNode mn = new ModularityNode(n); linklookup.put(n.getId(), mn); groups.add(mn); } links = new ArrayList<ModularityLink>(); for (Link l : linkMap.values()) { if (linklookup.containsKey(l.getSourceId()) && linklookup.containsKey(l.getTargetId())) { //if this is not true we have links pointing to an invalid node... ModularityLink ml = new ModularityLink(linklookup.get(l.getSourceId()), linklookup.get(l.getTargetId())); links.add(ml); ModularityNode start = linklookup.get(l.getSourceId()); ModularityNode end = linklookup.get(l.getSourceId()); start.addLink(ml); end.addLink(ml); } } boolean notterminate = true; int linksize; while (notterminate) { final List<Future<?>> futures = new ArrayList<Future<?>>(); notterminate = false; final PriorityBlockingQueue<ModularityLink> linksort = new PriorityBlockingQueue<ModularityLink>(); linksize = links.size(); final int itrsize = linksize / nThreads; for (int i = 0; i < nThreads; i++) { final int passval = i; Future<?> foo = executor.submit(new Callable<Boolean>() { @Override public Boolean call() throws Exception { boolean nt = false; for (int lnknum = 0; lnknum < itrsize; lnknum++) { ModularityLink ln = links.get(passval * itrsize + lnknum); long nc = 0; if (ln.source.neighbourcounts.containsKey(ln.target)) { nc = ln.source.neighbourcounts.get(ln.target).intValue(); } else { System.out.println("Oooops"); } long q = nc - (ln.source.totalvolume * ln.target.totalvolume) / 2; if (q > 0) nt = true; ln.q.set(q); linksort.add(ln); } return nt; } }); futures.add(foo); } for (Future<?> foo : futures) { try { notterminate = (Boolean) foo.get(); } catch (InterruptedException interruptedCancellingAndSignalling) { Thread.currentThread().interrupt(); } catch (ExecutionException wtf) { wtf.printStackTrace(); } } if (!notterminate) break; //Now we take each link in the queue and add it to maximal matching ConcurrentLinkedQueue<ModularityLink> maximalmatching = new ConcurrentLinkedQueue<ModularityAggregator.ModularityLink>(); ConcurrentSkipListSet<ModularityNode> vertexcheck = new ConcurrentSkipListSet<ModularityAggregator.ModularityNode>(); ModularityLink top = linksort.poll(); maximalmatching.add(top); vertexcheck.add(top.source); vertexcheck.add(top.target); while (!linksort.isEmpty()) { ModularityLink nlnk = linksort.poll(); if (nlnk.q.intValue() < 0) continue; if (vertexcheck.contains(nlnk.source) || vertexcheck.contains(nlnk.target)) continue; maximalmatching.add(nlnk); vertexcheck.add(nlnk.source); vertexcheck.add(nlnk.target); } //Now we take all the pairs in maximal matching and fuse them for (ModularityLink ln : maximalmatching) { ModularityNode so = ln.source; ModularityNode tr = ln.target; so.assimilate(tr); groups.remove(tr); links.remove(ln); } linksize = links.size(); if (linksize == 1) notterminate = false; } /* final List<Future<?>> futures = new ArrayList<Future<?>>(); Future<?> foo = executor.submit(new Runnable(){ @Override public void run() { }}); futures.add(foo); */ clusterSet = new ArrayList<Set<Node>>(); for (ModularityNode g : groups) { if (cancel) { setStatusWaiting(); return; } Set<Node> set = new HashSet<Node>(); clusterSet.add(set); for (Node n : g.nodes) { if (cancel) { setStatusWaiting(); return; } set.add(n); } } if (clusterer != null) { graphResult = clusterer.convertClusterSet(clusterSet); } stopWatch.stop(); System.out.println("Finished Modularity clustering algorithm."); System.out.println("Algorithm took " + stopWatch.toString());//30 = 33.487 stopWatch.reset(); this.result = result; }
From source file:org.apache.hadoop.hbase.io.encoding.TestPrefixTreeEncoding.java
private static void generateFixedTestData(ConcurrentSkipListSet<KeyValue> kvset, int batchId, boolean partial, boolean useTags, PrefixTreeCodec encoder, HFileBlockEncodingContext blkEncodingCtx, DataOutputStream userDataStream) throws Exception { for (int i = 0; i < NUM_ROWS_PER_BATCH; ++i) { if (partial && i / 10 % 2 == 1) continue; for (int j = 0; j < NUM_COLS_PER_ROW; ++j) { if (!useTags) { KeyValue kv = new KeyValue(getRowKey(batchId, i), CF_BYTES, getQualifier(j), getValue(batchId, i, j)); kvset.add(kv); } else { KeyValue kv = new KeyValue(getRowKey(batchId, i), CF_BYTES, getQualifier(j), 0l, getValue(batchId, i, j), new Tag[] { new Tag((byte) 1, "metaValue1") }); kvset.add(kv);/*from w w w .jav a 2 s.com*/ } } } encoder.startBlockEncoding(blkEncodingCtx, userDataStream); for (KeyValue kv : kvset) { encoder.encode(kv, blkEncodingCtx, userDataStream); } encoder.endBlockEncoding(blkEncodingCtx, userDataStream, null); }