List of usage examples for com.google.common.collect Range closedOpen
public static <C extends Comparable<?>> Range<C> closedOpen(C lower, C upper)
From source file:com.google.errorprone.bugpatterns.ParameterName.java
private void checkArguments(Tree tree, List<? extends ExpressionTree> arguments, VisitorState state) { if (arguments.isEmpty()) { return;/* w w w .java 2s .c o m*/ } MethodSymbol sym = (MethodSymbol) ASTHelpers.getSymbol(tree); if (NamedParameterComment.containsSyntheticParameterName(sym)) { return; } int start = ((JCTree) tree).getStartPosition(); int end = state.getEndPosition(getLast(arguments)); if (start == Position.NOPOS || end == Position.NOPOS) { // best effort work-around for https://github.com/google/error-prone/issues/780 return; } String source = state.getSourceCode().subSequence(start, end).toString(); if (!source.contains("/*")) { // fast path if the arguments don't contain anything that looks like a comment return; } Deque<ErrorProneToken> tokens = new ArrayDeque<>(ErrorProneTokens.getTokens(source, state.context)); forEachPair(sym.getParameters().stream(), arguments.stream(), (p, a) -> { while (!tokens.isEmpty() && ((start + tokens.peekFirst().pos()) < ((JCTree) a).getStartPosition())) { tokens.removeFirst(); } if (tokens.isEmpty()) { return; } Range<Integer> argRange = Range.closedOpen(((JCTree) a).getStartPosition(), state.getEndPosition(a)); if (!argRange.contains(start + tokens.peekFirst().pos())) { return; } checkArgument(p, a, start, tokens.removeFirst(), state); }); }
From source file:com.github.fge.largetext.range.IntRange.java
/** * Return this range as a Guava {@link Range} * * @return a Guava range/* ww w . j a v a 2 s .c o m*/ * @see RangeMap */ public Range<Integer> asGuavaRange() { return Range.closedOpen(lowerBound, upperBound); }
From source file:io.horizondb.model.schema.PartitionType.java
/** * Returns the time range of the partition which contains the specified date. * //ww w . j av a 2s . c o m * @param calendar the date that the partition must contains * @param field the field corresponding to the partition type * @return the partition corresponding to the specified field which contains the specified date. */ private static Range<Field> getPartitionTimeRange(Calendar calendar, int field) { TimeUtils.truncate(calendar, field); Field from = FieldType.MILLISECONDS_TIMESTAMP.newField(); from.setTimestampInMillis(calendar.getTimeInMillis()); calendar.add(field, 1); Field to = FieldType.MILLISECONDS_TIMESTAMP.newField(); to.setTimestampInMillis(calendar.getTimeInMillis()); return Range.closedOpen(from, to); }
From source file:com.google.googlejavaformat.java.SnippetFormatter.java
/** * Generates {@code Replacement}s rewriting {@code source} to {@code replacement}, under the * assumption that they differ in whitespace alone. *///from w w w .ja va 2 s . com private static List<Replacement> toReplacements(String source, String replacement) { if (!NOT_WHITESPACE.retainFrom(source).equals(NOT_WHITESPACE.retainFrom(replacement))) { throw new IllegalArgumentException( "source = \"" + source + "\", replacement = \"" + replacement + "\""); } /* * In the past we seemed to have problems touching non-whitespace text in the formatter, even * just replacing some code with itself. Retrospective attempts to reproduce this have failed, * but this may be an issue for future changes. */ List<Replacement> replacements = new ArrayList<>(); int i = NOT_WHITESPACE.indexIn(source); int j = NOT_WHITESPACE.indexIn(replacement); if (i != 0 || j != 0) { replacements.add(Replacement.create(Range.closedOpen(0, i), replacement.substring(0, j))); } while (i != -1 && j != -1) { int i2 = NOT_WHITESPACE.indexIn(source, i + 1); int j2 = NOT_WHITESPACE.indexIn(replacement, j + 1); if (i2 == -1 || j2 == -1) { break; } if ((i2 - i) != (j2 - j) || !source.substring(i + 1, i2).equals(replacement.substring(j + 1, j2))) { replacements.add(Replacement.create(Range.closedOpen(i + 1, i2), replacement.substring(j + 1, j2))); } i = i2; j = j2; } return replacements; }
From source file:radsoft.syntaxhighlighter.SyntaxHighlighter.java
private static void addMatch(RangeMap<Integer, String> matches, int start, int end, String styleKey) { if (styleKey == null) throw new NullPointerException("argument 'styleKey' cannot be null"); Map.Entry<Range<Integer>, String> e = matches.getEntry(start); if (e == null || start < e.getKey().lowerEndpoint()) { if (e != null) matches.remove(e.getKey());/*from w w w.j a v a 2 s .c o m*/ e = matches.getEntry(end - 1); if (e != null) matches.remove(e.getKey()); Range<Integer> r = Range.closedOpen(start, end); matches.put(r, styleKey); } }
From source file:org.apache.drill.exec.record.RecordIterator.java
public void mark() { if (!enableMarkAndReset) { throw new UnsupportedOperationException("mark and reset disabled for this RecordIterator"); }/* w w w. ja v a2 s. c o m*/ // Release all batches before current batch. [0 to startBatchPosition). final Map<Range<Long>, RecordBatchData> oldBatches = batches .subRangeMap(Range.closedOpen(0l, startBatchPosition)).asMapOfRanges(); for (RecordBatchData rbd : oldBatches.values()) { rbd.clear(); } batches.remove(Range.closedOpen(0l, startBatchPosition)); markedInnerPosition = innerPosition; markedOuterPosition = outerPosition; }
From source file:org.openmhealth.shimmer.common.domain.DataPointSearchCriteria.java
protected Range<OffsetDateTime> asRange(OffsetDateTime onOrAfterDateTime, OffsetDateTime beforeDateTime) { if (onOrAfterDateTime != null && beforeDateTime != null) { return Range.closedOpen(onOrAfterDateTime, beforeDateTime); }//from w w w.jav a2s . c om if (onOrAfterDateTime != null) { return Range.atLeast(onOrAfterDateTime); } else if (beforeDateTime != null) { return Range.lessThan(beforeDateTime); } return Range.all(); }
From source file:radsoft.syntaxhighlighter.SyntaxHighlighter.java
private static void removeMatches(RangeMap<Integer, String> matches, int start, int end) { Range<Integer> r = Range.closedOpen(start, end); matches.remove(r);/*from ww w . j ava2 s . c o m*/ }
From source file:org.graylog2.indexer.results.ResultMessage.java
public void setHighlightRanges(Map<String, HighlightField> highlightFields) { if (!highlightFields.isEmpty()) { highlightRanges = ArrayListMultimap.create(); for (Map.Entry<String, HighlightField> hlEntry : highlightFields.entrySet()) { final HighlightField highlight = hlEntry.getValue(); final String s = highlight.fragments()[0].toString(); int pos = 0; int cutChars = 0; while (true) { int startIdx = s.indexOf("<em>", pos); if (startIdx == -1) { break; }//from ww w.ja v a2 s .co m final int endIdx = s.indexOf("</em>", startIdx); final Range<Integer> highlightPosition = Range.closedOpen(startIdx - cutChars, endIdx - cutChars - 4); pos = endIdx; cutChars += 9; highlightRanges.put(hlEntry.getKey(), highlightPosition); } } LOG.debug("Highlight positions for message {}: {}", message.getId(), highlightRanges); } }
From source file:zipkin.storage.cassandra.CassandraSpanStore.java
CassandraSpanStore(Session session, int bucketCount, int maxTraceCols, int indexFetchMultiplier, boolean strictTraceId) { this.session = session; this.maxTraceCols = maxTraceCols; this.indexFetchMultiplier = indexFetchMultiplier; this.strictTraceId = strictTraceId; ProtocolVersion protocolVersion = session.getCluster().getConfiguration().getProtocolOptions() .getProtocolVersion();/* w w w. jav a 2s. c o m*/ this.timestampCodec = new TimestampCodec(protocolVersion); this.buckets = ContiguousSet.create(Range.closedOpen(0, bucketCount), integers()); selectTraces = session.prepare(QueryBuilder.select("trace_id", "span").from("traces") .where(QueryBuilder.in("trace_id", QueryBuilder.bindMarker("trace_id"))) .limit(QueryBuilder.bindMarker("limit_"))); selectDependencies = session.prepare(QueryBuilder.select("dependencies").from("dependencies") .where(QueryBuilder.in("day", QueryBuilder.bindMarker("days")))); selectServiceNames = session.prepare(QueryBuilder.select("service_name").from(Tables.SERVICE_NAMES)); selectSpanNames = session.prepare(QueryBuilder.select("span_name").from(Tables.SPAN_NAMES) .where(QueryBuilder.eq("service_name", QueryBuilder.bindMarker("service_name"))) .and(QueryBuilder.eq("bucket", QueryBuilder.bindMarker("bucket"))) .limit(QueryBuilder.bindMarker("limit_"))); selectTraceIdsByServiceName = session .prepare(QueryBuilder.select("ts", "trace_id").from(Tables.SERVICE_NAME_INDEX) .where(QueryBuilder.eq("service_name", QueryBuilder.bindMarker("service_name"))) .and(QueryBuilder.in("bucket", QueryBuilder.bindMarker("bucket"))) .and(QueryBuilder.gte("ts", QueryBuilder.bindMarker("start_ts"))) .and(QueryBuilder.lte("ts", QueryBuilder.bindMarker("end_ts"))) .limit(QueryBuilder.bindMarker("limit_")).orderBy(QueryBuilder.desc("ts"))); selectTraceIdsBySpanName = session .prepare(QueryBuilder.select("ts", "trace_id").from(Tables.SERVICE_SPAN_NAME_INDEX) .where(QueryBuilder.eq("service_span_name", QueryBuilder.bindMarker("service_span_name"))) .and(QueryBuilder.gte("ts", QueryBuilder.bindMarker("start_ts"))) .and(QueryBuilder.lte("ts", QueryBuilder.bindMarker("end_ts"))) .limit(QueryBuilder.bindMarker("limit_")).orderBy(QueryBuilder.desc("ts"))); selectTraceIdsByAnnotation = session .prepare(QueryBuilder.select("ts", "trace_id").from(Tables.ANNOTATIONS_INDEX) .where(QueryBuilder.eq("annotation", QueryBuilder.bindMarker("annotation"))) .and(QueryBuilder.in("bucket", QueryBuilder.bindMarker("bucket"))) .and(QueryBuilder.gte("ts", QueryBuilder.bindMarker("start_ts"))) .and(QueryBuilder.lte("ts", QueryBuilder.bindMarker("end_ts"))) .limit(QueryBuilder.bindMarker("limit_")).orderBy(QueryBuilder.desc("ts"))); if (protocolVersion.compareTo(ProtocolVersion.V4) < 0) { LOG.warn("Please update Cassandra to 2.2 or later, as some features may fail"); // Log vs failing on "Partition KEY part service_name cannot be restricted by IN relation" selectTraceIdsByServiceNames = null; } else { selectTraceIdsByServiceNames = session .prepare(QueryBuilder.select("ts", "trace_id").from(Tables.SERVICE_NAME_INDEX) .where(QueryBuilder.in("service_name", QueryBuilder.bindMarker("service_name"))) .and(QueryBuilder.in("bucket", QueryBuilder.bindMarker("bucket"))) .and(QueryBuilder.gte("ts", QueryBuilder.bindMarker("start_ts"))) .and(QueryBuilder.lte("ts", QueryBuilder.bindMarker("end_ts"))) .limit(QueryBuilder.bindMarker("limit_")).orderBy(QueryBuilder.desc("ts"))); } traceIdToTimestamp = new Function<ResultSet, Map<Long, Long>>() { @Override public Map<Long, Long> apply(ResultSet input) { Map<Long, Long> traceIdsToTimestamps = new LinkedHashMap<>(); for (Row row : input) { traceIdsToTimestamps.put(row.getLong("trace_id"), timestampCodec.deserialize(row, "ts")); } return traceIdsToTimestamps; } }; }