Java Code Examples for com.google.common.collect.Range#lessThan()

The following examples show how to use com.google.common.collect.Range#lessThan() . 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 Bats with Apache License 2.0 6 votes vote down vote up
private Range<Calendar> floorRange(TimeUnitRange timeUnit, SqlKind comparison, Calendar c) {
    Calendar floor = floor(c, timeUnit);
    boolean boundary = floor.equals(c);
    switch (comparison) {
    case EQUALS:
        return Range.closedOpen(floor, boundary ? increment(floor, timeUnit) : floor);
    case LESS_THAN:
        return boundary ? Range.lessThan(floor) : Range.lessThan(increment(floor, timeUnit));
    case LESS_THAN_OR_EQUAL:
        return Range.lessThan(increment(floor, timeUnit));
    case GREATER_THAN:
        return Range.atLeast(increment(floor, timeUnit));
    case GREATER_THAN_OR_EQUAL:
        return boundary ? Range.atLeast(floor) : Range.atLeast(increment(floor, timeUnit));
    default:
        throw Util.unexpected(comparison);
    }
}
 
Example 2
Source File: RexSimplify.java    From calcite with Apache License 2.0 6 votes vote down vote up
private static <C extends Comparable<C>> Range<C> range(SqlKind comparison,
    C c) {
  switch (comparison) {
  case EQUALS:
    return Range.singleton(c);
  case LESS_THAN:
    return Range.lessThan(c);
  case LESS_THAN_OR_EQUAL:
    return Range.atMost(c);
  case GREATER_THAN:
    return Range.greaterThan(c);
  case GREATER_THAN_OR_EQUAL:
    return Range.atLeast(c);
  default:
    throw new AssertionError();
  }
}
 
Example 3
Source File: DateRangeRules.java    From calcite with Apache License 2.0 6 votes vote down vote up
private Range<Calendar> floorRange(TimeUnitRange timeUnit, SqlKind comparison,
    Calendar c) {
  Calendar floor = floor(c, timeUnit);
  boolean boundary = floor.equals(c);
  switch (comparison) {
  case EQUALS:
    return Range.closedOpen(floor, boundary ? increment(floor, timeUnit) : floor);
  case LESS_THAN:
    return boundary ? Range.lessThan(floor) : Range.lessThan(increment(floor, timeUnit));
  case LESS_THAN_OR_EQUAL:
    return Range.lessThan(increment(floor, timeUnit));
  case GREATER_THAN:
    return Range.atLeast(increment(floor, timeUnit));
  case GREATER_THAN_OR_EQUAL:
    return boundary ? Range.atLeast(floor) : Range.atLeast(increment(floor, timeUnit));
  default:
    throw Util.unexpected(comparison);
  }
}
 
Example 4
Source File: DateRangeRules.java    From calcite with Apache License 2.0 6 votes vote down vote up
private Range<Calendar> extractRange(TimeUnitRange timeUnit, SqlKind comparison,
    Calendar c) {
  switch (comparison) {
  case EQUALS:
    return Range.closedOpen(round(c, timeUnit, true),
        round(c, timeUnit, false));
  case LESS_THAN:
    return Range.lessThan(round(c, timeUnit, true));
  case LESS_THAN_OR_EQUAL:
    return Range.lessThan(round(c, timeUnit, false));
  case GREATER_THAN:
    return Range.atLeast(round(c, timeUnit, false));
  case GREATER_THAN_OR_EQUAL:
    return Range.atLeast(round(c, timeUnit, true));
  default:
    throw new AssertionError(comparison);
  }
}
 
Example 5
Source File: FixedTimeZoneDateTimeRangeTransformer.java    From shimmer with Apache License 2.0 6 votes vote down vote up
@Override
public Range<OffsetDateTime> transformRange(Range<OffsetDateTime> inputRange) {

    if (inputRange.hasLowerBound() && inputRange.hasUpperBound()) {
        return Range.closedOpen(
                toFixedTimeZone(inputRange.lowerEndpoint()),
                toFixedTimeZone(inputRange.upperEndpoint()));
    }

    if (inputRange.hasLowerBound()) {
        return Range.atLeast(toFixedTimeZone(inputRange.lowerEndpoint()));
    }

    if (inputRange.hasUpperBound()) {
        return Range.lessThan(toFixedTimeZone(inputRange.upperEndpoint()));
    }

    return Range.all();

}
 
Example 6
Source File: DataPointSearchCriteria.java    From shimmer with Apache License 2.0 6 votes vote down vote up
protected Range<OffsetDateTime> asRange(OffsetDateTime onOrAfterDateTime, OffsetDateTime beforeDateTime) {

        if (onOrAfterDateTime != null && beforeDateTime != null) {
            return Range.closedOpen(onOrAfterDateTime, beforeDateTime);
        }

        if (onOrAfterDateTime != null) {
            return Range.atLeast(onOrAfterDateTime);
        }

        else if (beforeDateTime != null) {
            return Range.lessThan(beforeDateTime);
        }

        return Range.all();
    }
 
Example 7
Source File: DataPointSearchController.java    From shimmer with Apache License 2.0 6 votes vote down vote up
public Range<OffsetDateTime> asRange(OffsetDateTime onOrAfterDateTime, OffsetDateTime beforeDateTime) {

        if (onOrAfterDateTime != null && beforeDateTime != null) {
            return Range.closedOpen(onOrAfterDateTime, beforeDateTime);
        }

        if (onOrAfterDateTime != null) {
            return Range.atLeast(onOrAfterDateTime);
        }

        else if (beforeDateTime != null) {
            return Range.lessThan(beforeDateTime);
        }

        return Range.all();
    }
 
Example 8
Source File: RexSimplify.java    From Quicksql with MIT License 6 votes vote down vote up
private static <C extends Comparable<C>> Range<C> range(SqlKind comparison,
    C c) {
  switch (comparison) {
  case EQUALS:
    return Range.singleton(c);
  case LESS_THAN:
    return Range.lessThan(c);
  case LESS_THAN_OR_EQUAL:
    return Range.atMost(c);
  case GREATER_THAN:
    return Range.greaterThan(c);
  case GREATER_THAN_OR_EQUAL:
    return Range.atLeast(c);
  default:
    throw new AssertionError();
  }
}
 
Example 9
Source File: DateRangeRules.java    From Quicksql with MIT License 6 votes vote down vote up
private Range<Calendar> floorRange(TimeUnitRange timeUnit, SqlKind comparison,
    Calendar c) {
  Calendar floor = floor(c, timeUnit);
  boolean boundary = floor.equals(c);
  switch (comparison) {
  case EQUALS:
    return Range.closedOpen(floor, boundary ? increment(floor, timeUnit) : floor);
  case LESS_THAN:
    return boundary ? Range.lessThan(floor) : Range.lessThan(increment(floor, timeUnit));
  case LESS_THAN_OR_EQUAL:
    return Range.lessThan(increment(floor, timeUnit));
  case GREATER_THAN:
    return Range.atLeast(increment(floor, timeUnit));
  case GREATER_THAN_OR_EQUAL:
    return boundary ? Range.atLeast(floor) : Range.atLeast(increment(floor, timeUnit));
  default:
    throw Util.unexpected(comparison);
  }
}
 
Example 10
Source File: DateRangeRules.java    From Quicksql with MIT License 6 votes vote down vote up
private Range<Calendar> extractRange(TimeUnitRange timeUnit, SqlKind comparison,
    Calendar c) {
  switch (comparison) {
  case EQUALS:
    return Range.closedOpen(round(c, timeUnit, true),
        round(c, timeUnit, false));
  case LESS_THAN:
    return Range.lessThan(round(c, timeUnit, true));
  case LESS_THAN_OR_EQUAL:
    return Range.lessThan(round(c, timeUnit, false));
  case GREATER_THAN:
    return Range.atLeast(round(c, timeUnit, false));
  case GREATER_THAN_OR_EQUAL:
    return Range.atLeast(round(c, timeUnit, true));
  default:
    throw new AssertionError(comparison);
  }
}
 
Example 11
Source File: RexSimplify.java    From Bats with Apache License 2.0 6 votes vote down vote up
private static <C extends Comparable<C>> Range<C> range(SqlKind comparison, C c) {
    switch (comparison) {
    case EQUALS:
        return Range.singleton(c);
    case LESS_THAN:
        return Range.lessThan(c);
    case LESS_THAN_OR_EQUAL:
        return Range.atMost(c);
    case GREATER_THAN:
        return Range.greaterThan(c);
    case GREATER_THAN_OR_EQUAL:
        return Range.atLeast(c);
    default:
        throw new AssertionError();
    }
}
 
Example 12
Source File: DateRangeRules.java    From Bats with Apache License 2.0 6 votes vote down vote up
private Range<Calendar> extractRange(TimeUnitRange timeUnit, SqlKind comparison, Calendar c) {
    switch (comparison) {
    case EQUALS:
        return Range.closedOpen(round(c, timeUnit, true), round(c, timeUnit, false));
    case LESS_THAN:
        return Range.lessThan(round(c, timeUnit, true));
    case LESS_THAN_OR_EQUAL:
        return Range.lessThan(round(c, timeUnit, false));
    case GREATER_THAN:
        return Range.atLeast(round(c, timeUnit, false));
    case GREATER_THAN_OR_EQUAL:
        return Range.atLeast(round(c, timeUnit, true));
    default:
        throw new AssertionError(comparison);
    }
}
 
Example 13
Source File: KeyRangeUtils.java    From tikv-client-lib-java with Apache License 2.0 5 votes vote down vote up
public static Range toRange(Coprocessor.KeyRange range) {
  if (range == null || (range.getStart().isEmpty() && range.getEnd().isEmpty())) {
    return Range.all();
  }
  if (range.getStart().isEmpty()) {
    return Range.lessThan(Comparables.wrap(range.getEnd()));
  }
  if (range.getEnd().isEmpty()) {
    return Range.atLeast(Comparables.wrap(range.getStart()));
  }
  return Range.closedOpen(Comparables.wrap(range.getStart()), Comparables.wrap(range.getEnd()));
}
 
Example 14
Source File: KeyRangeUtils.java    From tikv-client-lib-java with Apache License 2.0 5 votes vote down vote up
public static Range makeRange(ByteString startKey, ByteString endKey) {
  if (startKey.isEmpty() && endKey.isEmpty()) {
    return Range.all();
  }
  if (startKey.isEmpty()) {
    return Range.lessThan(Comparables.wrap(endKey));
  } else if (endKey.isEmpty()) {
    return Range.atLeast(Comparables.wrap(startKey));
  }
  return Range.closedOpen(Comparables.wrap(startKey), Comparables.wrap(endKey));
}
 
Example 15
Source File: AutoIntervalShardingAlgorithmTest.java    From shardingsphere with Apache License 2.0 5 votes vote down vote up
@Test
public void assertRangeDoShardingWithoutLowerBound() {
    List<String> availableTargetNames = Arrays.asList("t_order_0", "t_order_1", "t_order_2", "t_order_3");
    Range<String> rangeValue = Range.lessThan("2020-01-01 00:00:11");
    List<RouteValue> shardingValues = Collections.singletonList(new RangeRouteValue<>("create_time", "t_order", rangeValue));
    Collection<String> actual = shardingStrategy.doSharding(availableTargetNames, shardingValues, new ConfigurationProperties(new Properties()));
    assertThat(actual.size(), is(4));
    assertTrue(actual.contains("t_order_0"));
    assertTrue(actual.contains("t_order_1"));
    assertTrue(actual.contains("t_order_2"));
    assertTrue(actual.contains("t_order_3"));
}
 
Example 16
Source File: RangeHeader.java    From notification with Apache License 2.0 5 votes vote down vote up
/**
 * Constructor
 *
 * @param builder
 */
private RangeHeader(final Builder builder) {

  this.field = builder.field;

  if (builder.fromId != null && builder.toId != null) {
    if (builder.fromInclusive && builder.toInclusive) {
      range = Range.closed(builder.fromId, builder.toId);
    } else if (builder.fromInclusive && !builder.toInclusive) {
      range = Range.closedOpen(builder.fromId, builder.toId);
    } else if (!builder.fromInclusive && builder.toInclusive) {
      range = Range.openClosed(builder.fromId, builder.toId);
    } else {
      range = Range.open(builder.fromId, builder.toId);
    }
  } else if (builder.fromId != null && builder.toId == null) {
    if (builder.fromInclusive) {
      range = Range.atLeast(builder.fromId);
    } else {
      range = Range.greaterThan(builder.fromId);
    }
  } else if (builder.fromId == null && builder.toId != null) {
    if (builder.toInclusive) {
      range = Range.atMost(builder.toId);
    } else {
      range = Range.lessThan(builder.toId);
    }
  } else {
    range = Range.all();
  }

  this.max = builder.max;
}
 
Example 17
Source File: Parameter.java    From activitystreams with Apache License 2.0 5 votes vote down vote up
public <O extends Comparable<? super O>>Range<O> bounds() {
  O mini = minInclusive();
  O mine = minExclusive();
  O maxi = maxInclusive();
  O maxe = maxExclusive();
  Ordering<O> ordering = Ordering.<O>natural();
  O min = ordering.nullsLast().min(mini,mine);
  O max = ordering.nullsFirst().max(maxi,maxe);
  BoundType lower = 
    min == null ? null :
    min == mini ? BoundType.CLOSED :
      BoundType.OPEN;
  BoundType upper = 
    max == null ? null : 
    max == maxi ? BoundType.CLOSED :
      BoundType.OPEN;
  if (lower == null && upper == null)
    return Range.<O>all();
  else if (lower != null && upper == null) 
    return lower == BoundType.CLOSED ? 
      Range.atLeast(min) : 
      Range.greaterThan(min);
  else if (lower == null && upper != null)
    return upper == BoundType.CLOSED ?
      Range.atMost(max) :
      Range.lessThan(max);
  else {
    return Range.range(min, lower, max, upper);
  }
}
 
Example 18
Source File: TsConditionExtractor.java    From kylin-on-parquet-v2 with Apache License 2.0 4 votes vote down vote up
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();
}
 
Example 19
Source File: PostgreSQLGuavaRangeType.java    From hibernate-types with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
public static <T extends Comparable> Range<T> ofString(String str, Function<String, T> converter, Class<T> cls) {
    BoundType lowerBound = str.charAt(0) == '[' ? BoundType.CLOSED : BoundType.OPEN;
    BoundType upperBound = str.charAt(str.length() - 1) == ']' ? BoundType.CLOSED : BoundType.OPEN;

    int delim = str.indexOf(',');

    if (delim == -1) {
        throw new IllegalArgumentException("Cannot find comma character");
    }

    String lowerStr = str.substring(1, delim);
    String upperStr = str.substring(delim + 1, str.length() - 1);

    T lower = null;
    T upper = null;

    if (lowerStr.length() > 0) {
        lower = converter.apply(lowerStr);
    }

    if (upperStr.length() > 0) {
        upper = converter.apply(upperStr);
    }

    if (lower == null && upper == null) {
        throw new IllegalArgumentException("Cannot find bound type");
    }

    if (lowerStr.length() == 0) {
        return upperBound == BoundType.CLOSED ?
                Range.atMost(upper) :
                Range.lessThan(upper);
    } else if (upperStr.length() == 0) {
        return lowerBound == BoundType.CLOSED ?
                Range.atLeast(lower) :
                Range.greaterThan(lower);
    } else {
        return Range.range(lower, lowerBound, upper, upperBound);
    }
}
 
Example 20
Source File: RandomFilter.java    From PGM with GNU Affero General Public License v3.0 4 votes vote down vote up
public RandomFilter(double chance) {
  this(Range.lessThan(chance));
}