Example usage for com.google.common.collect RangeSet complement

List of usage examples for com.google.common.collect RangeSet complement

Introduction

In this page you can find the example usage for com.google.common.collect RangeSet complement.

Prototype

RangeSet<C> complement();

Source Link

Document

Returns a view of the complement of this RangeSet .

Usage

From source file:com.github.s4ke.moar.util.RangeRep.java

static <T extends Comparable> RangeSet<T> intersect(RangeSet<T> a, RangeSet<T> b) {
    RangeSet<T> copy = TreeRangeSet.create(a);
    copy.removeAll(b.complement());
    return copy;/*from   w w  w .  j av  a 2 s . c om*/
}

From source file:io.druid.sql.calcite.filtration.RangeSets.java

/**
 * Intersects a set of rangeSets, or returns null if the set is empty.
 *//*  w  w  w. j  a  v a2  s.com*/
public static <T extends Comparable<T>> RangeSet<T> intersectRangeSets(final Iterable<RangeSet<T>> rangeSets) {
    RangeSet<T> rangeSet = null;
    for (final RangeSet<T> set : rangeSets) {
        if (rangeSet == null) {
            rangeSet = TreeRangeSet.create();
            rangeSet.addAll(set);
        } else {
            rangeSet.removeAll(set.complement());
        }
    }
    return rangeSet;
}

From source file:com.rockhoppertech.music.examples.Guava.java

public static void ranges() {
    RangeSet<Double> set = TreeRangeSet.create();
    //        for (double i = 1d; i < 4d; i++) {
    //            set.add(Range.closed(i, i + 1d));
    //        }// w  ww .j  a  v a2s .co m

    set.add(Range.closed(1d, 4d));
    logger.debug("the set {}", set);

    set.remove(Range.closed(2.5, 3d));
    logger.debug("after remove: set {}", set);
    RangeSet<Double> comp = set.complement();
    logger.debug("after remove: set comp {}", comp);

    Range<Double> first = Iterables.getFirst(set.asRanges(), null);
    logger.debug("first {}", first);

    //Iterables.

    for (Range<Double> r : set.asRanges()) {
        logger.debug("iterated range {}", r);
    }

    //lowerEndpoint();

    set.clear();
    set.add(Range.open(1d, 4d));
    comp = set.complement();
    logger.debug("open comp {}", comp);

}

From source file:org.apache.druid.query.filter.NotDimFilter.java

/**
 * There are some special cases involving null that require special casing for And and Or instead of simply taking
 * the complement/*from  www .ja v  a 2s .co  m*/
 *
 * Example 1 : "NOT ( [0,INF) OR null)" The inside of NOT would evaluate to null, and the complement would also
 * be null. However, by breaking the NOT, this statement is "NOT([0,INF)) AND NOT(null)", which means it should
 * actually evaluate to (-INF, 0).
 *
 * Example 2 : "NOT ( [0,INF) AND null )" The inside of NOT would evaluate to [0,INF), and the complement would be
 * (-INF, 0). However the statement is actually "NOT([0,INF)) OR NOT(null)", and it should be evaluated to null.
 */
@Override
public RangeSet<String> getDimensionRangeSet(String dimension) {
    if (field instanceof AndDimFilter) {
        List<DimFilter> fields = ((AndDimFilter) field).getFields();
        return new OrDimFilter(Lists.transform(fields, NotDimFilter::new)).getDimensionRangeSet(dimension);
    }
    if (field instanceof OrDimFilter) {
        List<DimFilter> fields = ((OrDimFilter) field).getFields();
        return new AndDimFilter(Lists.transform(fields, NotDimFilter::new)).getDimensionRangeSet(dimension);
    }
    if (field instanceof NotDimFilter) {
        return ((NotDimFilter) field).getField().getDimensionRangeSet(dimension);
    }
    RangeSet<String> rangeSet = field.getDimensionRangeSet(dimension);
    return rangeSet == null ? null : rangeSet.complement();
}

From source file:io.horizondb.model.core.predicates.InPredicate.java

/**    
 * {@inheritDoc}//from   w  w  w  . j a  v  a2 s  .c om
 */
@Override
public RangeSet<Field> getTimestampRanges() {

    if (!isTimestamp()) {
        return TimestampField.ALL;
    }

    ImmutableRangeSet.Builder<Field> builder = ImmutableRangeSet.builder();

    for (Field field : this.values) {

        builder.add(Range.closed(field, field));
    }

    RangeSet<Field> rangeSet = builder.build();

    if (this.notIn) {
        return rangeSet.complement();
    }

    return rangeSet;
}

From source file:io.horizondb.model.core.predicates.BetweenPredicate.java

/**    
 * {@inheritDoc}/*from w  w  w .  j a  v a2s  .co m*/
 */
@Override
public RangeSet<Field> getTimestampRanges() {

    if (!isTimestamp()) {
        return TimestampField.ALL;
    }

    if (this.max.compareTo(this.min) < 0) {
        return ImmutableRangeSet.of();
    }

    Range<Field> range = Range.<Field>closed(this.min, this.max);
    RangeSet<Field> rangeSet = ImmutableRangeSet.of(range);

    if (this.notBetween) {
        return rangeSet.complement();
    }

    return rangeSet;
}

From source file:org.apache.druid.query.filter.AndDimFilter.java

@Override
public RangeSet<String> getDimensionRangeSet(String dimension) {
    RangeSet<String> retSet = null;
    for (DimFilter field : fields) {
        RangeSet<String> rangeSet = field.getDimensionRangeSet(dimension);
        if (rangeSet != null) {
            if (retSet == null) {
                retSet = TreeRangeSet.create(rangeSet);
            } else {
                retSet.removeAll(rangeSet.complement());
            }/*from w  w w .j  a  va 2  s .c o m*/
        }
    }
    return retSet;
}

From source file:org.eclipse.fx.ui.controls.styledtext.internal.ContentView.java

public void updateInsertionMarkerIndex(int index) {
    if (this.insertionMarkerIndex != index) {
        this.insertionMarkerIndex = index;
    }/*from   w w w .  jav a2 s  .  c  o m*/
    com.google.common.collect.RangeSet<Integer> rs = TreeRangeSet.create();
    updateNodesNow(rs.complement());
}