List of usage examples for com.google.common.collect BoundType equals
public boolean equals(Object obj)
From source file:uk.ac.open.kmi.iserve.discovery.util.MatchResultPredicates.java
/** * Generates a Predicate that only accepts the Match Results within a range. The range may be closed or open at each * of the boundaries. {@code BoundType.CLOSED} means that the boundary should also be accepted. {@code BoundType.OPEN} * on the other indicates that the boundary itself should not be accepted. * * @param minMatchType the matchType that defines the lower boundary * @param minBound the lower {@code BoundType} * @param maxMatchType the matchType that defines the upper boundary * @param maxBound the upper {@code BoundType} * @param <T> a subclass of MatchResult * @param <S> a subclass of MatchType * @return the Predicate/*from w ww . j a v a 2 s.c o m*/ */ public static <T extends MatchResult, S extends MatchType> Predicate<T> withinRange(S minMatchType, BoundType minBound, S maxMatchType, BoundType maxBound) { Predicate<T> lowerPredicate; Predicate<T> upperPredicate; if (minBound.equals(BoundType.CLOSED)) { lowerPredicate = greaterOrEqualTo(minMatchType); } else { lowerPredicate = greaterThan(minMatchType); } if (maxBound.equals(BoundType.CLOSED)) { upperPredicate = lowerOrEqualTo(maxMatchType); } else { upperPredicate = lowerThan(maxMatchType); } return Predicates.and(lowerPredicate, upperPredicate); }
From source file:org.kitesdk.data.spi.ConstraintsSerialization.java
/** * Deserializes an {@link Range} from the specified {@code in} stream. *//* w ww.j a v a2 s. co m*/ @SuppressWarnings("unchecked") private static Range readRangePredicate(Schema fieldSchema, ObjectInputStream in) throws IOException { Range range = null; //read in boolean indicating if there is a lower bound if (in.readBoolean()) { BoundType lowerType = in.readBoolean() ? BoundType.OPEN : BoundType.CLOSED; Comparable lowerBound = (Comparable) readValue(fieldSchema, in); if (lowerType.equals(BoundType.OPEN)) { range = Ranges.greaterThan(lowerBound); } else { range = Ranges.atLeast(lowerBound); } } //read in boolean indicating if there is an upper bound if (in.readBoolean()) { Range upperRange = null; BoundType upperType = in.readBoolean() ? BoundType.OPEN : BoundType.CLOSED; Comparable upperBound = (Comparable) readValue(fieldSchema, in); if (upperType.equals(BoundType.OPEN)) { upperRange = Ranges.lessThan(upperBound); } else { upperRange = Ranges.atMost(upperBound); } range = range == null ? upperRange : range.intersection(upperRange); } return range; }
From source file:org.apache.lens.cube.parse.BetweenTimeRangeWriter.java
@Override public String getTimeRangeWhereClause(CubeQueryContext cubeQueryContext, String tableName, Set<FactPartition> rangeParts) throws LensException { if (rangeParts.size() == 0) { return ""; }/* w w w.j a v a 2s.c o m*/ //Flag to check if only between range needs to be used boolean useBetweenOnly = cubeQueryContext.getConf().getBoolean( CubeQueryConfUtil.BETWEEN_ONLY_TIME_RANGE_WRITER, CubeQueryConfUtil.DEFAULT_BETWEEN_ONLY_TIME_RANGE_WRITER); //Fetch the date start and end bounds from config BoundType startBound = BoundType.valueOf(cubeQueryContext.getConf() .get(CubeQueryConfUtil.START_DATE_BOUND_TYPE, CubeQueryConfUtil.DEFAULT_START_BOUND_TYPE)); BoundType endBound = BoundType.valueOf(cubeQueryContext.getConf().get(CubeQueryConfUtil.END_DATE_BOUND_TYPE, CubeQueryConfUtil.DEFAULT_END_BOUND_TYPE)); StringBuilder partStr = new StringBuilder(); if (!useBetweenOnly && rangeParts.size() == 1) { partStr.append("("); String partFilter = TimeRangeUtils.getTimeRangePartitionFilter(rangeParts.iterator().next(), cubeQueryContext, tableName); partStr.append(partFilter); partStr.append(")"); } else { TreeSet<FactPartition> parts = new TreeSet<>(); FactPartition first = null; for (FactPartition part : rangeParts) { if (part.hasContainingPart()) { throw new LensException(LensCubeErrorCode.CANNOT_USE_TIMERANGE_WRITER.getLensErrorInfo(), "Partition has containing part"); } if (first == null) { first = part; } else { // validate partcol, update period are same for both if (!first.getPartCol().equalsIgnoreCase(part.getPartCol())) { throw new LensException(LensCubeErrorCode.CANNOT_USE_TIMERANGE_WRITER.getLensErrorInfo(), "Part columns are different in partitions"); } if (!first.getPeriod().equals(part.getPeriod())) { throw new LensException(LensCubeErrorCode.CANNOT_USE_TIMERANGE_WRITER.getLensErrorInfo(), "Partitions are in different update periods"); } } parts.add(part); } FactPartition start = parts.first(); FactPartition end = parts.last(); if (startBound.equals(BoundType.OPEN)) { start = start.previous(); } if (endBound.equals(BoundType.OPEN)) { end = end.next(); } String partCol = start.getPartCol(); if (!cubeQueryContext.shouldReplaceTimeDimWithPart()) { partCol = cubeQueryContext.getTimeDimOfPartitionColumn(partCol); } partStr.append(" (").append(tableName).append(".").append(partCol).append(" BETWEEN '") .append(start.getFormattedPartSpec()).append("' AND '").append(end.getFormattedPartSpec()) .append("') "); } return partStr.toString(); }