List of usage examples for com.google.common.collect DiscreteDomains longs
public static DiscreteDomain<Long> longs()
From source file:org.kitesdk.data.spi.partition.YearFieldPartitioner.java
@Override public Predicate<Integer> project(Predicate<Long> predicate) { // year is the only time field that can be projected if (predicate instanceof Predicates.Exists) { return Predicates.exists(); } else if (predicate instanceof Predicates.In) { return ((Predicates.In<Long>) predicate).transform(this); } else if (predicate instanceof Range) { return Predicates.transformClosed( Predicates.adjustClosed((Range<Long>) predicate, DiscreteDomains.longs()), this); } else {//from w w w .j a v a2 s.c o m return null; } }
From source file:org.kitesdk.data.spi.partition.LongFixedSizeRangeFieldPartitioner.java
@Override public Predicate<Long> project(Predicate<Long> predicate) { if (predicate instanceof Exists) { return Predicates.exists(); } else if (predicate instanceof In) { return ((In<Long>) predicate).transform(this); } else if (predicate instanceof Range) { return Ranges.transformClosed(Ranges.adjustClosed((Range<Long>) predicate, DiscreteDomains.longs()), this); } else {//from w w w . j ava2 s. c om return null; } }
From source file:org.kitesdk.data.spi.partition.YearFieldPartitioner.java
@Override public Predicate<Integer> projectStrict(Predicate<Long> predicate) { if (predicate instanceof Predicates.Exists) { return Predicates.exists(); } else if (predicate instanceof Predicates.In) { // not enough information to make a judgement on behalf of the // original predicate. the year may match when month does not return null; } else if (predicate instanceof Range) { //return Predicates.transformClosedConservative( // (Range<Long>) predicate, this, DiscreteDomains.integers()); Range<Long> adjusted = Predicates.adjustClosed((Range<Long>) predicate, DiscreteDomains.longs()); if (adjusted.hasLowerBound()) { long lower = adjusted.lowerEndpoint(); int lowerImage = apply(lower); if (apply(lower - 1) == lowerImage) { // at least one excluded value maps to the same lower endpoint lowerImage += 1;//from w w w . j a v a2 s. co m } if (adjusted.hasUpperBound()) { long upper = adjusted.upperEndpoint(); int upperImage = apply(upper); if (apply(upper + 1) == upperImage) { // at least one excluded value maps to the same upper endpoint upperImage -= 1; } if (lowerImage <= upperImage) { return Ranges.closed(lowerImage, upperImage); } } else { return Ranges.atLeast(lowerImage); } } else if (adjusted.hasUpperBound()) { long upper = adjusted.upperEndpoint(); int upperImage = apply(upper); if (apply(upper + 1) == upperImage) { // at least one excluded value maps to the same upper endpoint upperImage -= 1; } return Ranges.atMost(upperImage); } } // could not produce a satisfying predicate return null; }
From source file:org.kitesdk.data.spi.partition.LongFixedSizeRangeFieldPartitioner.java
@Override public Predicate<Long> projectStrict(Predicate<Long> predicate) { if (predicate instanceof Exists) { return Predicates.exists(); } else if (predicate instanceof In) { Set<Long> possibleValues = Sets.newHashSet(); In<Long> in = ((In<Long>) predicate).transform(this); for (Long val : Predicates.asSet(in)) { boolean matchedAll = true; for (long i = 0; i < size; i++) { matchedAll = matchedAll && predicate.apply(val + i); }//from w w w . j a v a 2s. co m if (matchedAll) { possibleValues.add(val); } } if (!possibleValues.isEmpty()) { return Predicates.in(possibleValues); } } else if (predicate instanceof Range) { Range<Long> closed = Ranges.adjustClosed((Range<Long>) predicate, DiscreteDomains.longs()); Long start = null; if (closed.hasLowerBound()) { if ((closed.lowerEndpoint() % size) == 0) { // the entire set of values is included start = closed.lowerEndpoint(); } else { // start the predicate at the next value start = apply(closed.lowerEndpoint() + size); } } Long end = null; if (closed.hasUpperBound()) { if (((closed.upperEndpoint() + 1) % size) == 0) { // all values are included end = apply(closed.upperEndpoint()); } else { // end the predicate at the previous value end = apply(closed.upperEndpoint() - size); } } if (start != null && end != null && start > end) { return null; } return Ranges.closed(start, end); // null start or end => unbound } return null; }