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

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

Introduction

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

Prototype

void removeAll(RangeSet<C> other);

Source Link

Document

Removes all of the ranges from the specified range set from this range set (optional operation).

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 ww .  jav a2  s.com
}

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. c  om
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:org.onosproject.store.resource.impl.EncodedDiscreteResources.java

EncodedDiscreteResources difference(EncodedDiscreteResources other) {
    checkArgument(this.codec.getClass() == other.codec.getClass());

    RangeSet<Integer> newRangeSet = TreeRangeSet.create(this.rangeSet);
    newRangeSet.removeAll(other.rangeSet);

    return new EncodedDiscreteResources(newRangeSet, this.codec);
}

From source file:org.mskcc.shenkers.view.GeneViewBuilder.java

public GeneViewBuilder(Range<Integer> transcript, Optional<RangeSet<Integer>> exons,
        Optional<Range<Integer>> cds) {

    gene = transcript;//from  w w  w  .  ja v a  2s  .c  om
    codingSubset = cds.map(c -> exons.map(e -> asClosed(e.subRangeSet(c))).orElse(ImmutableRangeSet.of()))
            .orElse(ImmutableRangeSet.of());
    introns = TreeRangeSet.create();
    introns.add(transcript);
    exons.ifPresent(e -> introns.removeAll(e));
    RangeSet<Integer> utr = exons.map(e -> (RangeSet<Integer>) TreeRangeSet.create(e))
            .orElse(TreeRangeSet.create());
    utr.removeAll(codingSubset);
    untranslated = utr;

    log.info("UTRs {}", untranslated);
    log.info("introns {}", introns);
    log.info("CDSs {}", codingSubset);

}

From source file:org.apache.druid.sql.calcite.filtration.MoveTimeFiltersToIntervals.java

@Override
public Filtration apply(final Filtration filtration) {
    if (filtration.getDimFilter() == null) {
        return filtration;
    }//from   w  ww.  j  av a 2  s. c om

    // Convert existing filtration intervals to a RangeSet.
    final RangeSet<Long> rangeSet = RangeSets.fromIntervals(filtration.getIntervals());

    // Remove anything outside eternity.
    rangeSet.removeAll(RangeSets.fromIntervals(ImmutableList.of(Filtration.eternity())).complement());

    // Extract time bounds from the dimFilter.
    final Pair<DimFilter, RangeSet<Long>> pair = extractConvertibleTimeBounds(filtration.getDimFilter());

    if (pair.rhs != null) {
        rangeSet.removeAll(pair.rhs.complement());
    }

    return Filtration.create(pair.lhs, RangeSets.toIntervals(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  v  a 2s. co m
        }
    }
    return retSet;
}

From source file:hudson.model.Fingerprint.java

/**
 * Trim off references to non-existent builds and jobs, thereby making the fingerprint smaller.
 *
 * @return true//from   w w  w . ja v a  2  s .  com
 *      if this record was modified.
 * 
 * @throws IOException Save failure
 */
public synchronized boolean trim() throws IOException {
    boolean modified = false;

    for (Entry<String, RangeSet> e : new Hashtable<String, RangeSet>(usages).entrySet()) {// copy because we mutate
        Job j = Jenkins.getInstance().getItemByFullName(e.getKey(), Job.class);
        if (j == null) {// no such job any more. recycle the record
            modified = true;
            usages.remove(e.getKey());
            continue;
        }

        Run firstBuild = j.getFirstBuild();
        if (firstBuild == null) {// no builds. recycle the whole record
            modified = true;
            usages.remove(e.getKey());
            continue;
        }

        RangeSet cur = e.getValue();

        // builds that are around without the keepLog flag on are normally clustered together (in terms of build #)
        // so our basic strategy is to discard everything up to the first ephemeral build, except those builds
        // that are marked as kept
        RangeSet kept = new RangeSet();
        Run r = firstBuild;
        while (r != null && r.isKeepLog()) {
            kept.add(r.getNumber());
            r = r.getNextBuild();
        }

        if (r == null) {
            // all the build records are permanently kept ones, so we'll just have to keep 'kept' out of whatever currently in 'cur'
            modified |= cur.retainAll(kept);
        } else {
            // otherwise we are ready to discard [0,r.number) except those marked as 'kept'
            RangeSet discarding = new RangeSet(new Range(-1, r.getNumber()));
            discarding.removeAll(kept);
            modified |= cur.removeAll(discarding);
        }

        if (cur.isEmpty()) {
            usages.remove(e.getKey());
            modified = true;
        }
    }

    if (modified) {
        if (logger.isLoggable(Level.FINE)) {
            logger.log(Level.FINE, "Saving trimmed {0}", getFingerprintFile(md5sum));
        }
        save();
    }

    return modified;
}