Example usage for com.google.common.collect Range atLeast

List of usage examples for com.google.common.collect Range atLeast

Introduction

In this page you can find the example usage for com.google.common.collect Range atLeast.

Prototype

public static <C extends Comparable<?>> Range<C> atLeast(C endpoint) 

Source Link

Document

Returns a range that contains all values greater than or equal to endpoint .

Usage

From source file:com.pingcap.tikv.predicates.RangeBuilder.java

/**
 * Turn CNF filters into range// w  w  w.java  2s .  c o  m
 *
 * @param accessConditions filters in CNF list
 * @param type index column type
 * @return access ranges
 */
@SuppressWarnings("unchecked")
static List<Range> exprToRanges(List<TiExpr> accessConditions, DataType type) {
    if (accessConditions == null || accessConditions.size() == 0) {
        return ImmutableList.of();
    }
    RangeSet ranges = TreeRangeSet.create();
    ranges.add(Range.all());
    for (TiExpr ac : accessConditions) {
        NormalizedCondition cond = AccessConditionNormalizer.normalize(ac);
        TiConstant constVal = cond.constantVals.get(0);
        Comparable<?> comparableVal = Comparables.wrap(constVal.getValue());
        TiExpr expr = cond.condition;

        if (expr instanceof GreaterThan) {
            ranges = ranges.subRangeSet(Range.greaterThan(comparableVal));
        } else if (expr instanceof GreaterEqual) {
            ranges = ranges.subRangeSet(Range.atLeast(comparableVal));
        } else if (expr instanceof LessThan) {
            ranges = ranges.subRangeSet(Range.lessThan(comparableVal));
        } else if (expr instanceof LessEqual) {
            ranges = ranges.subRangeSet(Range.atMost(comparableVal));
        } else if (expr instanceof Equal) {
            ranges = ranges.subRangeSet(Range.singleton(comparableVal));
        } else if (expr instanceof NotEqual) {
            RangeSet left = ranges.subRangeSet(Range.lessThan(comparableVal));
            RangeSet right = ranges.subRangeSet(Range.greaterThan(comparableVal));
            ranges = TreeRangeSet.create(left);
            ranges.addAll(right);
        } else {
            throw new TiClientInternalException(
                    "Unsupported conversion to Range " + expr.getClass().getSimpleName());
        }
    }
    return ImmutableList.copyOf(ranges.asRanges());
}

From source file:org.apache.kylin.common.util.RangeUtil.java

/**
 * remove from self the elements that exist in other
 * @return//w  w  w . j  a  v  a  2 s .  com
 */
public static <C extends Comparable<?>> List<Range<C>> remove(Range<C> self, Range<C> other) {

    // mimic the following logic in guava 18:
    //        RangeSet<C> rangeSet = TreeRangeSet.create();
    //        rangeSet.add(self);
    //        rangeSet.remove(other);
    //        return Lists.newArrayList(rangeSet.asRanges());

    if (other == null || !self.isConnected(other)) {
        return Collections.singletonList(self);
    }

    Range<C> share = self.intersection(other);
    if (share.isEmpty()) {
        return Collections.singletonList(self);
    }

    List<Range<C>> ret = Lists.newArrayList();

    //see left part
    if (!self.hasLowerBound()) {
        if (share.hasLowerBound()) {
            if (share.lowerBoundType() == BoundType.CLOSED) {
                ret.add(Range.lessThan(share.lowerEndpoint()));
            } else {
                ret.add(Range.atMost(share.lowerEndpoint()));
            }
        }
    } else {
        if (self.lowerEndpoint() != share.lowerEndpoint()) {
            if (self.lowerBoundType() == BoundType.CLOSED) {
                if (share.lowerBoundType() == BoundType.CLOSED) {
                    ret.add(Range.closedOpen(self.lowerEndpoint(), share.lowerEndpoint()));
                } else {
                    ret.add(Range.closed(self.lowerEndpoint(), share.lowerEndpoint()));
                }
            } else {
                if (share.lowerBoundType() == BoundType.CLOSED) {
                    ret.add(Range.open(self.lowerEndpoint(), share.lowerEndpoint()));
                } else {
                    ret.add(Range.openClosed(self.lowerEndpoint(), share.lowerEndpoint()));
                }
            }
        } else {
            if (self.lowerBoundType() == BoundType.CLOSED && share.lowerBoundType() == BoundType.OPEN) {
                ret.add(Range.closed(self.lowerEndpoint(), share.lowerEndpoint()));
            }
        }
    }

    //see right part 
    if (!self.hasUpperBound()) {
        if (share.hasUpperBound()) {
            if (share.upperBoundType() == BoundType.CLOSED) {
                ret.add(Range.greaterThan(share.upperEndpoint()));
            } else {
                ret.add(Range.atLeast(share.upperEndpoint()));
            }
        }
    } else {
        if (self.upperEndpoint() != share.upperEndpoint()) {
            if (self.upperBoundType() == BoundType.CLOSED) {
                if (share.upperBoundType() == BoundType.CLOSED) {
                    ret.add(Range.openClosed(share.upperEndpoint(), self.upperEndpoint()));
                } else {
                    ret.add(Range.closed(share.upperEndpoint(), self.upperEndpoint()));
                }
            } else {
                if (share.upperBoundType() == BoundType.CLOSED) {
                    ret.add(Range.open(share.upperEndpoint(), self.upperEndpoint()));
                } else {
                    ret.add(Range.closedOpen(share.upperEndpoint(), self.upperEndpoint()));
                }
            }
        } else {
            if (self.upperBoundType() == BoundType.CLOSED && share.upperBoundType() == BoundType.OPEN) {
                ret.add(Range.closed(self.upperEndpoint(), share.upperEndpoint()));
            }
        }
    }

    return ret;

}

From source file:com.stackframe.sarariman.LDAPDirectory.java

/**
 * Load the directory from LDAP./*from w w  w . java2  s .  c  o  m*/
 */
private void load() {
    try {
        List<Employee> tmp = new ArrayList<>();
        NamingEnumeration<SearchResult> answer = context.search("ou=People", null,
                new String[] { "uid", "sn", "givenName", "employeeNumber", "fulltime", "active", "mail",
                        "birthdate", "displayName", "hiredate", "jpegPhoto", "mobile", "url", "title" });
        while (answer.hasMore()) {
            Attributes attributes = answer.next().getAttributes();
            String givenName = attributes.get("givenName").getAll().next().toString();
            String surname = attributes.get("sn").getAll().next().toString();
            String name = surname + ", " + givenName;
            String uid = attributes.get("uid").getAll().next().toString();
            String displayName = attributes.get("displayName").getAll().next().toString();
            String mail = attributes.get("mail").getAll().next().toString();
            boolean fulltime = Boolean.parseBoolean(attributes.get("fulltime").getAll().next().toString());
            boolean active = Boolean.parseBoolean(attributes.get("active").getAll().next().toString());
            String mobile = getAttribute(attributes, "mobile");
            int employeeNumber = Integer.parseInt(attributes.get("employeeNumber").getAll().next().toString());
            LocalDate birthdate = new LocalDate(attributes.get("birthdate").getAll().next().toString());
            LocalDate hiredate = new LocalDate(attributes.get("hiredate").getAll().next().toString());
            Range<java.sql.Date> periodOfService = Range.atLeast(convert(hiredate.toDateMidnight().toDate()));
            Attribute jpegPhotoAttribute = attributes.get("jpegPhoto");
            byte[] photo = jpegPhotoAttribute == null ? null : (byte[]) jpegPhotoAttribute.getAll().next();
            Iterable<URL> profileLinks = getURLs(attributes, "url");
            Iterable<String> titles = getAttributes(attributes, "title");
            tmp.add(new StackFrameEmployee(name, givenName, surname, uid, employeeNumber, fulltime, active,
                    mail, birthdate, displayName, periodOfService, photo, this, sarariman.getDataSource(),
                    sarariman, mobile, profileLinks, titles));
        }

        Collections.sort(tmp, (Employee e1, Employee e2) -> e1.getFullName().compareTo(e2.getFullName()));

        ImmutableMap.Builder<String, Employee> byUserNameBuilder = new ImmutableMap.Builder<>();
        ImmutableMap.Builder<Object, Employee> byNumberBuilder = new ImmutableMap.Builder<>();
        ImmutableSet.Builder<Employee> employeeBuilder = new ImmutableSet.Builder<>();
        for (Employee employee : tmp) {
            byNumberBuilder.put(employee.getNumber(), employee);

            // We index by employee number as long instead of int so as to be compatible with JSP EL.
            long employeeNumberAsLong = employee.getNumber();
            byNumberBuilder.put(employeeNumberAsLong, employee);

            byNumberBuilder.put(Integer.toString(employee.getNumber()), employee);
            byUserNameBuilder.put(employee.getUserName(), employee);
            employeeBuilder.add(employee);
        }

        byUserName = byUserNameBuilder.build();
        byNumber = byNumberBuilder.build();
        employees = employeeBuilder.build();
    } catch (NamingException ne) {
        throw new RuntimeException(ne);
    }
}

From source file:org.openmhealth.shimmer.common.domain.DataPointSearchCriteria.java

protected Range<OffsetDateTime> asRange(OffsetDateTime onOrAfterDateTime, OffsetDateTime beforeDateTime) {

    if (onOrAfterDateTime != null && beforeDateTime != null) {
        return Range.closedOpen(onOrAfterDateTime, beforeDateTime);
    }/*  ww w. ja  v a2  s.  c om*/

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

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

    return Range.all();
}

From source file:dk.dma.ais.view.rest.QueryParameterHelper.java

public QueryParameterHelper(UriInfo uriInfo) {
    this.uriInfo = requireNonNull(uriInfo);
    this.area = findBoundingBox(uriInfo);
    this.interval = findInterval(uriInfo);

    this.createSituationFolder = findCreateSituationFolder(uriInfo);
    this.createMovementsFolder = findCreateMovementsFolder(uriInfo);
    this.createTracksFolder = findCreateTracksFolder(uriInfo);

    this.kmlSnapshotAt = findAt(uriInfo);
    String limit = getParameter(uriInfo, "limit", null);
    this.limit = limit == null ? null : Integer.parseInt(limit);
    Set<Integer> mmsi = new HashSet<>(QueryParameterValidators.getParametersAsInt(uriInfo, "mmsi"));
    this.mmsis = Ints.toArray(mmsi);
    sourceFilter = getSourceFilter(uriInfo);
    packetFilter = getPacketFilter(uriInfo);

    minDistance = getParameterAsIntWithRange(uriInfo, "minDistance", null, Range.atLeast(0));
    minDuration = findMinimumDurationMS(uriInfo);
    primaryMmsi = findPrimaryMmsi(uriInfo);
    secondaryMmsi = findSecondaryMmsi(uriInfo);
    title = getParameter(uriInfo, "title", null);
    description = getParameter(uriInfo, "description", null);
    interpolationStepSecs = getParameterAsInt(uriInfo, "interpolation", null);

    outputSink = getOutputSink(uriInfo);
    jobId = QueryParameterValidators.getParameter(uriInfo, "jobId", null);

    LOG.debug(toString());/*w w  w  .  j a v  a  2 s.  co m*/
}

From source file:guru.qas.martini.gherkin.DefaultMixology.java

protected RangeMap<Integer, ScenarioDefinition> getRangeMap(FeatureWrapper feature) {
    List<ScenarioDefinition> children = Lists.newArrayList(feature.getChildren());

    ImmutableRangeMap.Builder<Integer, ScenarioDefinition> builder = ImmutableRangeMap.builder();
    while (!children.isEmpty()) {
        ScenarioDefinition child = children.remove(0);
        Location location = child.getLocation();
        Integer childStart = location.getLine();

        ScenarioDefinition sibling = children.isEmpty() ? null : children.get(0);
        Location siblingLocation = null == sibling ? null : sibling.getLocation();
        Integer siblingStart = null == siblingLocation ? null : siblingLocation.getLine();

        Range<Integer> range = null == siblingStart ? Range.atLeast(childStart)
                : Range.closedOpen(childStart, siblingStart);
        builder.put(range, child);// w  w w. j  a  va 2 s. c  o m
    }
    return builder.build();
}

From source file:org.asoem.greyfish.utils.collect.Products.java

/**
 * Zips the {@code iterable} with its indices of the iteration.
 *
 * @param iterable the elements to zip with their indices
 * @param <E>      the type of the elements of the iterable
 * @return an iterable of products/*from  w w w.java 2s  .  co m*/
 */
public static <E> Iterable<Product2<E, Integer>> zipWithIndex(final Iterable<? extends E> iterable) {
    checkNotNull(iterable);
    return new Zip2<>(iterable, ContiguousSet.create(Range.atLeast(0), DiscreteDomain.integers()));
}

From source file:org.corpus_tools.peppermodules.annis.Audio2ANNISMapper.java

@Override
public void nodeReached(GRAPH_TRAVERSE_TYPE traversalType, String traversalId, SNode currNode,
        SRelation sRelation, SNode fromNode, long order) {

    if (sRelation instanceof SMedialRelation
            && traversionType == Salt2ANNISMapper.TRAVERSION_TYPE.DOCUMENT_STRUCTURE_AUDIO) {
        SMedialRelation dsRel = (SMedialRelation) sRelation;
        Double start = dsRel.getStart();
        Double end = dsRel.getEnd();

        String val;
        if (start != null && end != null) {
            val = "" + start + "-" + end;
        } else if (start != null) {
            val = "" + start;
        } else if (end != null) {
            val = "-" + end;
        } else {/*  www  .  j  a v  a2 s . c o  m*/
            val = "";
        }

        SToken tok = dsRel.getSource();
        List<Long> virtualToken = idManager.getVirtualisedTokenId(tok.getId());
        if (virtualToken == null) {

            tok.createAnnotation("annis", "time", val);
            mapSNode(dsRel.getSource());
        } else if (!virtualToken.isEmpty()) {
            // there is already a virtual span written for this token,
            // add the time information to the overlapped virtual token instead

            if (virtualToken.size() == 1) {

                Range<Double> newRange = Range.all();
                if (start != null && end != null) {
                    newRange = Range.closed(start, end);
                } else if (start != null) {
                    newRange = Range.atLeast(start);
                } else if (end != null) {
                    newRange = Range.atMost(end);
                }

                addVirtualRange(virtualToken.get(0), newRange);
            } else {
                Long firstTokenID = virtualToken.get(0);
                Long lastTokenID = virtualToken.get(virtualToken.size() - 1);

                if (start != null) {
                    addVirtualRange(firstTokenID, Range.atLeast(start));
                }
                if (end != null) {
                    addVirtualRange(lastTokenID, Range.atMost(end));
                }
            }
        }

        URI linkedFile = dsRel.getTarget().getMediaReference();
        if (linkedFile != null) {
            if (mappedFiles.add(linkedFile)) {
                copyLinkedFile(linkedFile);
            }
        }

    }

}

From source file:li.klass.fhem.service.graph.gplot.GPlotParser.java

private GPlotAxis createAxis(Map<String, String> setsDeclarations, String prefix) {
    String labelKey = prefix + "label";
    String rightLabel = setsDeclarations.containsKey(labelKey) ? setsDeclarations.get(labelKey) : "";

    String rangeKey = prefix + "range";
    Optional<Range<Double>> optRange = Optional.absent();
    if (setsDeclarations.containsKey(rangeKey)) {
        String rangeValue = setsDeclarations.get(rangeKey);
        String[] parts = rangeValue.split(":");

        Range<Double> range;
        if (rangeValue.startsWith(":")) {
            range = Range.atMost(Double.parseDouble(parts[0]));
        } else if (rangeValue.endsWith(":")) {
            range = Range.atLeast(Double.parseDouble(parts[0]));
        } else {// ww  w  . j  av  a 2 s .  c o m
            range = Range.closed(Double.parseDouble(parts[0]), Double.parseDouble(parts[1]));
        }
        optRange = Optional.of(range);
    }

    return new GPlotAxis(rightLabel, optRange);
}

From source file:org.obiba.opal.web.gwt.app.client.magma.derive.helper.NumericalVariableDerivationHelper.java

public static <N extends Number & Comparable<N>> Range<N> buildRange(@Nullable N lower, @Nullable N upper) {
    if (lower == null) {
        return Range.lessThan(upper);
    }/*from   w  w w . j  ava2 s  . c  o m*/
    if (upper == null) {
        return Range.atLeast(lower);
    }
    if (lower.equals(upper)) {
        return Range.closed(lower, upper);
    }
    return Range.closedOpen(lower, upper);
}