Java Code Examples for com.google.common.collect.Range#isEmpty()
The following examples show how to use
com.google.common.collect.Range#isEmpty() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DateRangeRules.java From calcite with Apache License 2.0 | 6 votes |
private RexNode compareFloorCeil(SqlKind comparison, RexNode operand, RexLiteral timeLiteral, TimeUnitRange timeUnit, boolean floor) { RangeSet<Calendar> rangeSet = operandRanges.get(operand); if (rangeSet == null) { rangeSet = ImmutableRangeSet.<Calendar>of().complement(); } final RangeSet<Calendar> s2 = TreeRangeSet.create(); final Calendar c = timestampValue(timeLiteral); final Range<Calendar> range = floor ? floorRange(timeUnit, comparison, c) : ceilRange(timeUnit, comparison, c); s2.add(range); // Intersect old range set with new. s2.removeAll(rangeSet.complement()); operandRanges.put(operand, ImmutableRangeSet.copyOf(s2)); if (range.isEmpty()) { return rexBuilder.makeLiteral(false); } return toRex(operand, range); }
Example 2
Source File: RangeMatcherBuilder.java From grappa with Apache License 2.0 | 6 votes |
private static Range<Integer> normalizeRange(final Range<Integer> range) { Range<Integer> newRange = AT_LEAST_ZERO.intersection(range); if (newRange.isEmpty()) throw new IllegalArgumentException("illegal range " + range + ": intersection with " + AT_LEAST_ZERO + " is empty"); newRange = newRange.canonical(DiscreteDomain.integers()); final int lowerBound = newRange.lowerEndpoint(); return newRange.hasUpperBound() ? Range.closed(lowerBound, newRange.upperEndpoint() - 1) : Range.atLeast(lowerBound); }
Example 3
Source File: DateRangeRules.java From Bats with Apache License 2.0 | 6 votes |
private RexNode compareFloorCeil(SqlKind comparison, RexNode operand, RexLiteral timeLiteral, TimeUnitRange timeUnit, boolean floor) { RangeSet<Calendar> rangeSet = operandRanges.get(operand); if (rangeSet == null) { rangeSet = ImmutableRangeSet.<Calendar> of().complement(); } final RangeSet<Calendar> s2 = TreeRangeSet.create(); final Calendar c = timestampValue(timeLiteral); final Range<Calendar> range = floor ? floorRange(timeUnit, comparison, c) : ceilRange(timeUnit, comparison, c); s2.add(range); // Intersect old range set with new. s2.removeAll(rangeSet.complement()); operandRanges.put(operand, ImmutableRangeSet.copyOf(s2)); if (range.isEmpty()) { return rexBuilder.makeLiteral(false); } return toRex(operand, range); }
Example 4
Source File: DateRangeRules.java From Quicksql with MIT License | 6 votes |
private RexNode compareFloorCeil(SqlKind comparison, RexNode operand, RexLiteral timeLiteral, TimeUnitRange timeUnit, boolean floor) { RangeSet<Calendar> rangeSet = operandRanges.get(operand); if (rangeSet == null) { rangeSet = ImmutableRangeSet.<Calendar>of().complement(); } final RangeSet<Calendar> s2 = TreeRangeSet.create(); final Calendar c = timestampValue(timeLiteral); final Range<Calendar> range = floor ? floorRange(timeUnit, comparison, c) : ceilRange(timeUnit, comparison, c); s2.add(range); // Intersect old range set with new. s2.removeAll(rangeSet.complement()); operandRanges.put(operand, ImmutableRangeSet.copyOf(s2)); if (range.isEmpty()) { return rexBuilder.makeLiteral(false); } return toRex(operand, range); }
Example 5
Source File: RangeUtil.java From kylin-on-parquet-v2 with Apache License 2.0 | 6 votes |
/** * for NavigableMap sorted by C, given a range of C, return the sub map whose key falls in the range */ public static <C extends Comparable<?>, V> NavigableMap<C, V> filter(NavigableMap<C, V> values, Range<C> filterRange) { if (filterRange == null || filterRange.isEmpty()) { return Maps.newTreeMap(); } else if (filterRange.equals(Range.all())) { return values; } if (filterRange.hasUpperBound() && !filterRange.hasLowerBound()) { return values.headMap(filterRange.upperEndpoint(), upperBoundInclusive(filterRange)); } else if (filterRange.hasLowerBound() && !filterRange.hasUpperBound()) { return values.tailMap(filterRange.lowerEndpoint(), lowerBoundInclusive(filterRange)); } else { return values.subMap(filterRange.lowerEndpoint(), lowerBoundInclusive(filterRange), // filterRange.upperEndpoint(), upperBoundInclusive(filterRange)); } }
Example 6
Source File: NumberSpace.java From batfish with Apache License 2.0 | 5 votes |
/** Include a range. The {@link Range} must be a finite range. */ public final B including(Range<T> range) { checkArgument( range.hasLowerBound() && range.hasUpperBound(), "Infinite ranges are not supported"); if (!range.isEmpty()) { _including.add(range.canonical(discreteDomain())); } return getThis(); }
Example 7
Source File: NumberSpace.java From batfish with Apache License 2.0 | 5 votes |
/** Exclude a range. The {@link Range} must be finite. */ public final B excluding(Range<T> range) { checkArgument( range.hasLowerBound() && range.hasUpperBound(), "Infinite ranges are not supported"); if (!range.isEmpty()) { _excluding.add(range.canonical(discreteDomain())); } return getThis(); }
Example 8
Source File: StackdriverWriter.java From java-monitoring-client-library with Apache License 2.0 | 5 votes |
private static TimeInterval encodeTimeInterval(Range<Instant> nativeInterval, Kind metricKind) { TimeInterval encodedInterval = new TimeInterval().setStartTime(nativeInterval.lowerEndpoint().toString()); Instant endTimestamp = nativeInterval.isEmpty() && metricKind != Kind.GAUGE ? nativeInterval.upperEndpoint().plusMillis(1) : nativeInterval.upperEndpoint(); return encodedInterval.setEndTime(endTimestamp.toString()); }
Example 9
Source File: Doc.java From javaide with GNU General Public License v3.0 | 4 votes |
private static Range<Integer> union(Range<Integer> x, Range<Integer> y) { return x.isEmpty() ? y : y.isEmpty() ? x : x.span(y).canonical(INTEGERS); }
Example 10
Source File: SchedulerImpl.java From ganttproject with GNU General Public License v3.0 | 4 votes |
private void schedule(Node node) { Logger logger = GPLogger.getLogger(this); GPLogger.debug(logger, "Scheduling node %s", node); Range<Date> startRange = Range.all(); Range<Date> endRange = Range.all(); Range<Date> weakStartRange = Range.all(); Range<Date> weakEndRange = Range.all(); List<Date> subtaskRanges = Lists.newArrayList(); List<DependencyEdge> incoming = node.getIncoming(); GPLogger.debug(logger, ".. #incoming edges=%d", incoming.size()); for (DependencyEdge edge : incoming) { if (!edge.refresh()) { continue; } if (edge instanceof ImplicitSubSuperTaskDependency) { subtaskRanges.add(edge.getStartRange().upperEndpoint()); subtaskRanges.add(edge.getEndRange().lowerEndpoint()); } else { if (edge.isWeak()) { weakStartRange = weakStartRange.intersection(edge.getStartRange()); weakEndRange = weakEndRange.intersection(edge.getEndRange()); } else { startRange = startRange.intersection(edge.getStartRange()); endRange = endRange.intersection(edge.getEndRange()); } } if (startRange.isEmpty() || endRange.isEmpty()) { GPLogger.logToLogger("both start and end ranges were calculated as empty for task=" + node.getTask() + ". Skipping it"); } } GPLogger.debug(logger, "..Ranges: start=%s end=%s weakStart=%s weakEnd=%s", startRange, endRange, weakStartRange, weakEndRange); Range<Date> subtasksSpan = subtaskRanges.isEmpty() ? Range.closed(node.getTask().getStart().getTime(), node.getTask().getEnd().getTime()) : Range.encloseAll(subtaskRanges); Range<Date> subtreeStartUpwards = subtasksSpan.span(Range.downTo(node.getTask().getStart().getTime(), BoundType.CLOSED)); Range<Date> subtreeEndDownwards = subtasksSpan.span(Range.upTo(node.getTask().getEnd().getTime(), BoundType.CLOSED)); GPLogger.debug(logger, "..Subtasks span=%s", subtasksSpan); if (!startRange.equals(Range.all())) { startRange = startRange.intersection(weakStartRange); } else if (!weakStartRange.equals(Range.all())) { startRange = weakStartRange.intersection(subtreeStartUpwards); } if (!endRange.equals(Range.all())) { endRange = endRange.intersection(weakEndRange); } else if (!weakEndRange.equals(Range.all())) { endRange = weakEndRange.intersection(subtreeEndDownwards); } if (node.getTask().getThirdDateConstraint() == TaskImpl.EARLIESTBEGIN && node.getTask().getThird() != null) { startRange = startRange.intersection(Range.downTo(node.getTask().getThird().getTime(), BoundType.CLOSED)); GPLogger.debug(logger, ".. applying earliest start=%s. Now start range=%s", node.getTask().getThird(), startRange); } if (!subtaskRanges.isEmpty()) { startRange = startRange.intersection(subtasksSpan); endRange = endRange.intersection(subtasksSpan); } GPLogger.debug(logger, ".. finally, start range=%s", startRange); if (startRange.hasLowerBound()) { modifyTaskStart(node.getTask(), startRange.lowerEndpoint()); } if (endRange.hasUpperBound()) { GPCalendarCalc cal = node.getTask().getManager().getCalendar(); Date endDate = endRange.upperEndpoint(); TimeUnit timeUnit = node.getTask().getDuration().getTimeUnit(); if (DayMask.WORKING == (cal.getDayMask(endDate) & DayMask.WORKING)) { // in case if calculated end date falls on first day after holidays (say, on Monday) // we'll want to modify it a little bit, so that it falls on that holidays start // If we don't do this, it will be done automatically the next time task activities are recalculated, // and thus task end date will keep changing Date closestWorkingEndDate = cal.findClosest( endDate, timeUnit, GPCalendarCalc.MoveDirection.BACKWARD, GPCalendar.DayType.WORKING); Date closestNonWorkingEndDate = cal.findClosest( endDate, timeUnit, GPCalendarCalc.MoveDirection.BACKWARD, GPCalendar.DayType.NON_WORKING, closestWorkingEndDate); // If there is a non-working date between current task end and closest working date // then we're really just after holidays if (closestNonWorkingEndDate != null && closestWorkingEndDate.before(closestNonWorkingEndDate)) { // we need to adjust-right closest working date to position to the very beginning of the holidays interval Date nonWorkingPeriodStart = timeUnit.adjustRight(closestWorkingEndDate); if (nonWorkingPeriodStart.after(node.getTask().getStart().getTime())) { endDate = nonWorkingPeriodStart; } } } modifyTaskEnd(node.getTask(), endDate); } }
Example 11
Source File: Doc.java From google-java-format with Apache License 2.0 | 4 votes |
private static Range<Integer> union(Range<Integer> x, Range<Integer> y) { return x.isEmpty() ? y : y.isEmpty() ? x : x.span(y).canonical(INTEGERS); }
Example 12
Source File: JavaOutput.java From google-java-format with Apache License 2.0 | 4 votes |
private static Range<Integer> union(Range<Integer> x, Range<Integer> y) { return x.isEmpty() ? y : y.isEmpty() ? x : x.span(y).canonical(DiscreteDomain.integers()); }
Example 13
Source File: JavaOutput.java From google-java-format with Apache License 2.0 | 4 votes |
@Override public void append(String text, Range<Integer> range) { if (!range.isEmpty()) { boolean sawNewlines = false; // Skip over input line we've passed. int iN = javaInput.getLineCount(); while (iLine < iN && (javaInput.getRanges(iLine).isEmpty() || javaInput.getRanges(iLine).upperEndpoint() <= range.lowerEndpoint())) { if (javaInput.getRanges(iLine).isEmpty()) { // Skipped over a blank line. sawNewlines = true; } ++iLine; } /* * Output blank line if we've called {@link OpsBuilder#blankLine}{@code (true)} here, or if * there's a blank line here and it's a comment. */ BlankLineWanted wanted = blankLines.getOrDefault(lastK, BlankLineWanted.NO); if (isComment(text) ? sawNewlines : wanted.wanted().orElse(sawNewlines)) { ++newlinesPending; } } if (Newlines.isNewline(text)) { /* * Don't update range information, and swallow extra newlines. The case below for '\n' is for * block comments. */ if (newlinesPending == 0) { ++newlinesPending; } spacesPending = new StringBuilder(); } else { boolean rangesSet = false; int textN = text.length(); for (int i = 0; i < textN; i++) { char c = text.charAt(i); switch (c) { case ' ': spacesPending.append(' '); break; case '\t': spacesPending.append('\t'); break; case '\r': if (i + 1 < text.length() && text.charAt(i + 1) == '\n') { i++; } // falls through case '\n': spacesPending = new StringBuilder(); ++newlinesPending; break; default: while (newlinesPending > 0) { // drop leading blank lines if (!mutableLines.isEmpty() || lineBuilder.length() > 0) { mutableLines.add(lineBuilder.toString()); } lineBuilder = new StringBuilder(); rangesSet = false; --newlinesPending; } if (spacesPending.length() > 0) { lineBuilder.append(spacesPending); spacesPending = new StringBuilder(); } lineBuilder.append(c); if (!range.isEmpty()) { if (!rangesSet) { while (ranges.size() <= mutableLines.size()) { ranges.add(Formatter.EMPTY_RANGE); } ranges.set(mutableLines.size(), union(ranges.get(mutableLines.size()), range)); rangesSet = true; } } } } } if (!range.isEmpty()) { lastK = range.upperEndpoint(); } }
Example 14
Source File: RangeSerializer.java From jackson-datatypes-collections with Apache License 2.0 | 4 votes |
@Override public boolean isEmpty(SerializerProvider prov, Range<?> value) { return value.isEmpty(); }
Example 15
Source File: RangeUtil.java From kylin-on-parquet-v2 with Apache License 2.0 | 4 votes |
/** * remove from self the elements that exist in other * @return */ public static <C extends Comparable<?>> List<Range<C>> remove(Range<C> self, Range<C> other) { // mimic the following logic in guava 18: // RangeSet<C> rangeSet = TreeRangeSet.create(); // rangeSet.add(self); // rangeSet.remove(other); // return Lists.newArrayList(rangeSet.asRanges()); if (other == null || !self.isConnected(other)) { return Collections.singletonList(self); } Range<C> share = self.intersection(other); if (share.isEmpty()) { return Collections.singletonList(self); } List<Range<C>> ret = Lists.newArrayList(); //see left part if (!self.hasLowerBound()) { if (share.hasLowerBound()) { if (share.lowerBoundType() == BoundType.CLOSED) { ret.add(Range.lessThan(share.lowerEndpoint())); } else { ret.add(Range.atMost(share.lowerEndpoint())); } } } else { if (self.lowerEndpoint() != share.lowerEndpoint()) { if (self.lowerBoundType() == BoundType.CLOSED) { if (share.lowerBoundType() == BoundType.CLOSED) { ret.add(Range.closedOpen(self.lowerEndpoint(), share.lowerEndpoint())); } else { ret.add(Range.closed(self.lowerEndpoint(), share.lowerEndpoint())); } } else { if (share.lowerBoundType() == BoundType.CLOSED) { ret.add(Range.open(self.lowerEndpoint(), share.lowerEndpoint())); } else { ret.add(Range.openClosed(self.lowerEndpoint(), share.lowerEndpoint())); } } } else { if (self.lowerBoundType() == BoundType.CLOSED && share.lowerBoundType() == BoundType.OPEN) { ret.add(Range.closed(self.lowerEndpoint(), share.lowerEndpoint())); } } } //see right part if (!self.hasUpperBound()) { if (share.hasUpperBound()) { if (share.upperBoundType() == BoundType.CLOSED) { ret.add(Range.greaterThan(share.upperEndpoint())); } else { ret.add(Range.atLeast(share.upperEndpoint())); } } } else { if (self.upperEndpoint() != share.upperEndpoint()) { if (self.upperBoundType() == BoundType.CLOSED) { if (share.upperBoundType() == BoundType.CLOSED) { ret.add(Range.openClosed(share.upperEndpoint(), self.upperEndpoint())); } else { ret.add(Range.closed(share.upperEndpoint(), self.upperEndpoint())); } } else { if (share.upperBoundType() == BoundType.CLOSED) { ret.add(Range.open(share.upperEndpoint(), self.upperEndpoint())); } else { ret.add(Range.closedOpen(share.upperEndpoint(), self.upperEndpoint())); } } } else { if (self.upperBoundType() == BoundType.CLOSED && share.upperBoundType() == BoundType.OPEN) { ret.add(Range.closed(self.upperEndpoint(), share.upperEndpoint())); } } } return ret; }
Example 16
Source File: JavaOutput.java From javaide with GNU General Public License v3.0 | 4 votes |
private static Range<Integer> union(Range<Integer> x, Range<Integer> y) { return x.isEmpty() ? y : y.isEmpty() ? x : x.span(y).canonical(DiscreteDomain.integers()); }
Example 17
Source File: Doc.java From java-n-IDE-for-Android with Apache License 2.0 | 4 votes |
private static Range<Integer> union(Range<Integer> x, Range<Integer> y) { return x.isEmpty() ? y : y.isEmpty() ? x : x.span(y).canonical(INTEGERS); }
Example 18
Source File: JavaOutput.java From java-n-IDE-for-Android with Apache License 2.0 | 4 votes |
@Override public void append(String text, Range<Integer> range) { if (!range.isEmpty()) { boolean sawNewlines = false; // Skip over input line we've passed. int iN = javaInput.getLineCount(); while (iLine < iN && (javaInput.getRange1s(iLine).isEmpty() || javaInput.getRange1s(iLine).upperEndpoint() <= range.lowerEndpoint())) { if (javaInput.getRanges(iLine).isEmpty()) { // Skipped over a blank line. sawNewlines = true; } ++iLine; } /* * Output blank line if we've called {@link OpsBuilder#blankLine}{@code (true)} here, or if * there's a blank line here and it's a comment. */ BlankLineWanted wanted = firstNonNull(blankLines.get(lastK), BlankLineWanted.NO); if (isComment(text) ? sawNewlines : wanted.wanted().or(sawNewlines)) { ++newlinesPending; } } if (Newlines.isNewline(text)) { /* * Don't update range information, and swallow extra newlines. The case below for '\n' is for * block comments. */ if (newlinesPending == 0) { ++newlinesPending; } spacesPending = 0; } else { boolean range0sSet = false; boolean rangesSet = false; int textN = text.length(); for (int i = 0; i < textN; i++) { char c = text.charAt(i); switch (c) { case ' ': ++spacesPending; break; case '\r': if (i + 1 < text.length() && text.charAt(i + 1) == '\n') { i++; } // falls through case '\n': spacesPending = 0; ++newlinesPending; break; default: while (newlinesPending > 0) { // drop leading blank lines if (!mutableLines.isEmpty() || lineBuilder.length() > 0) { mutableLines.add(lineBuilder.toString()); } lineBuilder = new StringBuilder(); rangesSet = false; --newlinesPending; } while (spacesPending > 0) { lineBuilder.append(' '); --spacesPending; } lineBuilder.append(c); if (!range.isEmpty()) { if (!range0sSet) { if (!range.isEmpty()) { while (range0s.size() <= mutableLines.size()) { range0s.add(Formatter.EMPTY_RANGE); } range0s.set(mutableLines.size(), union(range0s.get(mutableLines.size()), range)); range0sSet = true; } } if (!rangesSet) { while (ranges.size() <= mutableLines.size()) { ranges.add(Formatter.EMPTY_RANGE); } ranges.set(mutableLines.size(), union(ranges.get(mutableLines.size()), range)); rangesSet = true; } } } } // TODO(jdd): Move others down here. Use common method for these. if (!range.isEmpty()) { while (range1s.size() <= mutableLines.size()) { range1s.add(Formatter.EMPTY_RANGE); } range1s.set(mutableLines.size(), union(range1s.get(mutableLines.size()), range)); } } if (!range.isEmpty()) { lastK = range.upperEndpoint(); } }
Example 19
Source File: JavaOutput.java From java-n-IDE-for-Android with Apache License 2.0 | 4 votes |
private static Range<Integer> union(Range<Integer> x, Range<Integer> y) { return x.isEmpty() ? y : y.isEmpty() ? x : x.span(y).canonical(DiscreteDomain.integers()); }
Example 20
Source File: TsConditionExtractor.java From kylin-on-parquet-v2 with Apache License 2.0 | 4 votes |
private static Range<Long> extractTsConditionInternal(TupleFilter filter, TblColRef colRef) { if (filter == null) { return Range.all(); } if (filter instanceof LogicalTupleFilter) { if (filter.getOperator() == TupleFilter.FilterOperatorEnum.AND) { Range<Long> ret = Range.all(); for (TupleFilter child : filter.getChildren()) { Range childRange = extractTsConditionInternal(child, colRef); if (childRange != null) { if (ret.isConnected(childRange) && !ret.intersection(childRange).isEmpty()) { ret = ret.intersection(childRange); } else { return null; } } else { return null; } } return ret.isEmpty() ? null : ret; } else { //for conditions like date > DATE'2000-11-11' OR date < DATE '1999-01-01' //we will use Ranges.all() rather than two ranges to represent them return Range.all(); } } if (filter instanceof CompareTupleFilter) { CompareTupleFilter compareTupleFilter = (CompareTupleFilter) filter; if (compareTupleFilter.getColumn() == null)// column will be null at filters like " 1<>1" return Range.all(); if (compareTupleFilter.getColumn().equals(colRef)) { Object firstValue = compareTupleFilter.getFirstValue(); long t; switch (compareTupleFilter.getOperator()) { case EQ: t = DateFormat.stringToMillis((String) firstValue); return Range.closed(t, t); case LT: t = DateFormat.stringToMillis((String) firstValue); return Range.lessThan(t); case LTE: t = DateFormat.stringToMillis((String) firstValue); return Range.atMost(t); case GT: t = DateFormat.stringToMillis((String) firstValue); return Range.greaterThan(t); case GTE: t = DateFormat.stringToMillis((String) firstValue); return Range.atLeast(t); case NEQ: case IN://not handled for now break; default: } } } return Range.all(); }