/** * Submits a histogram request to a given url * * @param histogram the histogram request * @param url the url to which the request is sent to * @return the response of the histogram request */ public static String submitHistogramRequest(final String histogram, final String url) { try { final Tuple<String, InputStream> response = Client.submitQueryAndRetrieveStream( url, histogram, "application/sparql-results+json"); // mime type would be better application/json, but // for that we do not have registered formatter, // such that errors would occur return EndpointManagement.getStringFromInputStream(response.getSecond()); } catch (final IOException e) { System.err.println(e); e.printStackTrace(); return null; } }
private UpdateEvent forceHighlighting( final List<Tuple<Integer, Integer>> areas, UpdateEvent nextEvent) { synchronized (this) { if (nextEvent != null || !this.buffer.isCurrentlyEmpty()) { // if currently some modifications have been done (should be few), // then handle these events such that all has been correctly updated! // new events should not occur because of the lock in the key listener nextEvent = eventHandling(areas, nextEvent); } this.doc.text.setRepaint(false); final String content = this.luposDocumentReader.getText(); for (Tuple<Integer, Integer> area : areas) { // determine start for rescanning: // rescan whole line, thus determine line start forceHighlightingInnerLoop(area.getFirst(), area.getSecond(), content); } // However, this is wrong for tokens spanning over several lines // For this, rescanning is started for each line with an error token before offset // This could theoretically lead also to errors, but should not occur in practical cases // (Theoretical case: Insert token c between token a and b, and a b c is also (another) token // (which is spanning over several lines)) LinkedList<ILuposToken> errorTokens = new LinkedList<ILuposToken>(); for (ILuposToken token : this.tokens.values()) { if (token.getDescription().isError()) { errorTokens.add(token); } } int lastEnd = -1; for (ILuposToken token : errorTokens) { final int beginChar = token.getBeginChar(); if (lastEnd < beginChar) { // rescan only if not already done... lastEnd = forceHighlightingInnerLoop( beginChar, beginChar + token.getContents().length(), content); } } this.doc.text.setRepaint(true); this.doc.text.repaint(); } return nextEvent; }
@Override public void run() { try { while (this.toBeAddedToSet.hasNext()) { final Tuple<Bindings, Boolean> next = this.toBeAddedToSet.get(); if (next == null) { break; } final boolean result = this.bindings.add(next.getFirst()); if (result && next.getSecond()) { this.distinctElements.put(next.getFirst()); } } } catch (final InterruptedException e) { System.err.println(e); e.printStackTrace(); } // all has been detailed checked! this.distinctElements.endOfData(); }
private boolean moveAreas(List<Tuple<Integer, Integer>> areas, int offset, int end) { // returns true is new area is already included! final int delta = end - offset; boolean result = false; for (Tuple<Integer, Integer> area : areas) { if (area.getSecond() < offset) { continue; } else if (area.getFirst() > end) { area.setFirst(area.getFirst() + delta); area.setSecond(area.getSecond() + delta); } else { result = true; area.setFirst(Math.min(area.getFirst(), offset)); area.setSecond(Math.max(area.getSecond() + delta, end)); } } return result; }
private boolean removeAreas( final List<Tuple<Integer, Integer>> areas, final int offset, final int end) { // returns true is new area is already included! final int delta = end - offset; boolean result = false; for (Tuple<Integer, Integer> area : areas) { if (area.getSecond() < offset) { continue; } else if (area.getFirst() > end) { area.setFirst(area.getFirst() - delta); area.setSecond(area.getSecond() - delta); } else { result = true; final int originalFirst = area.getFirst(); area.setFirst(Math.min(originalFirst, offset)); if (offset >= originalFirst && end <= area.getSecond()) { area.setSecond(area.getSecond() - delta); } else if (offset <= originalFirst && end >= area.getSecond()) { area.setSecond(offset); } else if (originalFirst <= offset) { area.setSecond(area.getSecond() - offset); } else { area.setSecond(area.getSecond() - end); } } } return result; }