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

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

Introduction

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

Prototype

public C lowerEndpoint() 

Source Link

Document

Returns the lower endpoint of this range.

Usage

From source file:edu.mit.streamjit.impl.compiler2.DescendingShareAllocationStrategy.java

@Override
public void allocateGroup(ActorGroup group, Range<Integer> iterations, List<Core> cores, Configuration config) {
    List<Float> shares = new ArrayList<>(cores.size());
    for (int core = 0; core < cores.size(); ++core) {
        String name = String.format("node%dcore%diter", group.id(), core);
        Configuration.FloatParameter parameter = config.getParameter(name, Configuration.FloatParameter.class);
        if (parameter == null)
            shares.add(0f);/*  ww w  .j a v  a  2 s  .c  o m*/
        else
            shares.add(parameter.getValue());
    }

    assert iterations.lowerBoundType() == BoundType.CLOSED && iterations.upperBoundType() == BoundType.OPEN;
    int totalAvailable = iterations.upperEndpoint() - iterations.lowerEndpoint();
    while (!iterations.isEmpty()) {
        int max = CollectionUtils.maxIndex(shares);
        float share = shares.get(max);
        if (share == 0)
            break;
        int amount = DoubleMath.roundToInt(share * totalAvailable, RoundingMode.HALF_EVEN);
        int done = iterations.lowerEndpoint();
        Range<Integer> allocation = group.isStateful() ? iterations
                : iterations.intersection(Range.closedOpen(done, done + amount));
        cores.get(max).allocate(group, allocation);
        iterations = Range.closedOpen(allocation.upperEndpoint(), iterations.upperEndpoint());
        shares.set(max, 0f); //don't allocate to this core again
    }

    //If we have iterations left over not assigned to a core, spread them
    //evenly over all cores.
    if (!iterations.isEmpty()) {
        int perCore = IntMath.divide(iterations.upperEndpoint() - iterations.lowerEndpoint(), cores.size(),
                RoundingMode.CEILING);
        for (int i = 0; i < cores.size() && !iterations.isEmpty(); ++i) {
            int min = iterations.lowerEndpoint();
            Range<Integer> allocation = group.isStateful() ? iterations
                    : iterations.intersection(Range.closedOpen(min, min + perCore));
            cores.get(i).allocate(group, allocation);
            iterations = Range.closedOpen(allocation.upperEndpoint(), iterations.upperEndpoint());
        }
    }
    assert iterations.isEmpty();
}

From source file:org.dishevelled.bio.range.tree.CenteredRangeTree.java

/**
 * Depth first search./*from  w w  w  .j a  va  2  s.  co m*/
 *
 * @param query query range
 * @param node node
 * @param result list of matching ranges
 * @param visited set of visited nodes
 */
private void depthFirstSearch(final Range<C> query, final Node node, final List<Range<C>> result,
        final Set<Node> visited) {
    if (node == null || visited.contains(node) || query.isEmpty()) {
        return;
    }
    if (node.left() != null && Ranges.isLessThan(query, node.center())) {
        depthFirstSearch(query, node.left(), result, visited);
    } else if (node.right() != null && Ranges.isGreaterThan(query, node.center())) {
        depthFirstSearch(query, node.right(), result, visited);
    }
    if (Ranges.isGreaterThan(query, node.center())) {
        for (Range<C> range : node.overlapByUpperEndpoint()) {
            if (Ranges.intersect(range, query)) {
                result.add(range);
            }
            if (Ranges.isGreaterThan(query, range.upperEndpoint())) {
                break;
            }
        }
    } else if (Ranges.isLessThan(query, node.center())) {
        for (Range<C> range : node.overlapByLowerEndpoint()) {
            if (Ranges.intersect(range, query)) {
                result.add(range);
            }
            if (Ranges.isLessThan(query, range.lowerEndpoint())) {
                break;
            }
        }
    } else {
        result.addAll(node.overlapByLowerEndpoint());
    }
    visited.add(node);
}

From source file:com.nimbits.client.io.http.NimbitsClientImpl.java

@Override
public List<Value> getSeries(final String entity, final Range<Date> range) {

    final Gson gson = GsonFactory.getInstance(true);

    RestAdapter restAdapter = new RestAdapter.Builder().setEndpoint(instanceUrl.getUrl())
            .setRequestInterceptor(requestInterceptor).setConverter(new GsonConverter(gson)).build();

    SeriesApi seriesApi = restAdapter.create(SeriesApi.class);

    List<Value> sample = seriesApi.getSeries(entity, range.lowerEndpoint().getTime(),
            range.upperEndpoint().getTime());

    List<Value> fixed = new ArrayList<Value>(sample.size());
    Set<Long> test = new HashSet<Long>(sample.size());
    for (Value value : sample) {
        if (!test.contains(value.getTimestamp().getTime())) {
            fixed.add(value);// ww w .j  av a 2 s  .c  om
            test.add(value.getTimestamp().getTime());
        }

    }
    return ImmutableList.copyOf(sample);

}

From source file:jetbrains.jetpad.hybrid.BaseHybridSynchronizer.java

public void select(Range<Integer> sel) {
    mySelectionSupport.select(myTargetList.get(sel.lowerEndpoint()), myTargetList.get(sel.upperEndpoint() - 1));
}

From source file:org.pshdl.model.validation.builtin.BuiltInValidator.java

private static void checkType(HDLPackage unit, Set<Problem> problems,
        Map<HDLQualifiedName, HDLEvaluationContext> hContext) {
    final HDLVariableDeclaration[] hvds = unit.getAllObjectsOf(HDLVariableDeclaration.class, true);
    for (final HDLVariableDeclaration hvd : hvds) {
        final Optional<? extends HDLType> type = hvd.resolveType();
        if (type.isPresent()) {
            final HDLType hdlType = type.get();
            if (hdlType instanceof HDLPrimitive) {
                final HDLPrimitive primType = (HDLPrimitive) hdlType;
                switch (primType.getType()) {
                case BIT:
                case INTEGER:
                case NATURAL:
                    break;
                case STRING:
                    if (primType.getWidth() != null) {
                        problems.add(new Problem(TYPE_INVALID_PRIMITIVE, hvd, "Strings can not have a width"));
                    }/*from w ww . j a  va2s. c  o m*/
                    break;
                case BOOL:
                    if (primType.getWidth() != null) {
                        problems.add(new Problem(TYPE_INVALID_PRIMITIVE, hvd, "Booleans can not have a width"));
                    }
                    break;
                case BITVECTOR:
                case INT:
                case UINT:
                    final Optional<Range<BigInteger>> rangeOpt = RangeExtension.rangeOf(primType.getWidth());
                    if (rangeOpt.isPresent()) {
                        final Range<BigInteger> range = rangeOpt.get();
                        if (!range.hasLowerBound()) {
                            problems.add(new Problem(ErrorCode.TYPE_NEGATIVE_WIDTH, hvd));
                        } else {
                            final BigInteger le = range.lowerEndpoint();
                            if (le.compareTo(BigInteger.ZERO) < 0) {
                                if (range.hasUpperBound()
                                        && (range.upperEndpoint().compareTo(BigInteger.ZERO) < 0)) {
                                    problems.add(new Problem(ErrorCode.TYPE_NEGATIVE_WIDTH, hvd));
                                } else {
                                    problems.add(new Problem(ErrorCode.TYPE_POSSIBLY_NEGATIVE_WIDTH, hvd));
                                }
                            } else if (le.equals(BigInteger.ZERO) && range.hasUpperBound()
                                    && range.upperEndpoint().equals(BigInteger.ZERO)) {
                                problems.add(new Problem(ErrorCode.TYPE_ZERO_WIDTH, hvd));
                            } else if (le.equals(BigInteger.ZERO)) {
                                problems.add(new Problem(ErrorCode.TYPE_POSSIBLY_ZERO_WIDTH, hvd));
                            }
                        }
                    }
                    break;
                }
            }
        }
    }

    final HDLOpExpression[] ops = unit.getAllObjectsOf(HDLOpExpression.class, true);
    for (final HDLOpExpression ope : ops) {
        if (skipExp(ope)) {
            continue;
        }
        checkOpExpression(problems, ope, ope);
    }
    final HDLManip[] manips = unit.getAllObjectsOf(HDLManip.class, true);
    for (final HDLManip manip : manips) {
        final Optional<? extends HDLType> targetType = TypeExtension.typeOf(manip.getTarget());
        if (targetType.isPresent()) {
            final HDLType tt = targetType.get();
            switch (manip.getType()) {
            case ARITH_NEG:
                if (tt instanceof HDLPrimitive) {
                    final HDLPrimitive primitive = (HDLPrimitive) tt;
                    if (!primitive.isNumber()) {
                        problems.add(new Problem(UNSUPPORTED_TYPE_FOR_OP, manip,
                                "Can not use arithmetic negate on a non-number"));
                    }
                } else {
                    problems.add(new Problem(UNSUPPORTED_TYPE_FOR_OP, manip,
                            "Can not use arithmetic negate on a non-number"));
                }
                break;
            case BIT_NEG:
                if (manip.getTarget().getClassType() == HDLClass.HDLLiteral) {
                    problems.add(new Problem(UNSUPPORTED_TYPE_FOR_OP, manip,
                            "Can not use binary negate on literals as they have no width"));
                }
                if (tt instanceof HDLPrimitive) {
                    final HDLPrimitive primitive = (HDLPrimitive) tt;
                    if (!primitive.isBits()) {
                        problems.add(new Problem(UNSUPPORTED_TYPE_FOR_OP, manip,
                                "Can not use binary negate on a non-bits"));
                    }
                } else {
                    problems.add(new Problem(UNSUPPORTED_TYPE_FOR_OP, manip,
                            "Can not use binary negate on a non-bits"));
                }
                break;
            case LOGIC_NEG:
                if (tt instanceof HDLPrimitive) {
                    final HDLPrimitive primitive = (HDLPrimitive) tt;
                    if ((primitive.getType() != HDLPrimitiveType.BOOL)
                            && (primitive.getType() != HDLPrimitiveType.BIT)) {
                        problems.add(new Problem(BOOL_NEGATE_NUMERIC_NOT_SUPPORTED, manip,
                                "Can not use logic negate on a non boolean/bit"));
                    }
                } else {
                    problems.add(new Problem(UNSUPPORTED_TYPE_FOR_OP, manip,
                            "Can not use logic negate on a non boolean"));
                }
                break;
            case CAST:
                final HDLType castTo = manip.getCastTo();
                if (castTo instanceof HDLInterface) {
                    if (!(tt instanceof HDLInterface)) {
                        problems.add(new Problem(UNSUPPORTED_TYPE_FOR_OP, manip,
                                "Can not cast from interface to non interface type:" + castTo));
                    }
                }
                if (castTo instanceof HDLEnum) {
                    problems.add(
                            new Problem(UNSUPPORTED_TYPE_FOR_OP, manip, "Enums can not be casted to anything"));
                }
                if (castTo instanceof HDLPrimitive) {
                    if (!(tt instanceof HDLPrimitive)) {
                        problems.add(new Problem(UNSUPPORTED_TYPE_FOR_OP, manip,
                                "Can not cast from primitve to non primitive type:" + castTo));
                    }
                }
                break;
            }
        }
    }
}

From source file:org.eclipse.fx.ui.controls.styledtext.skin.StyledTextSkin.java

public void scrollOffsetIntoView(int offset, int verticalOffset, int horizontalOffset) {
    if (offset >= 0) {
        int lineIdx = getSkinnable().getContent().getLineAtOffset(offset);
        Range<Integer> visibleLines = this.content.getVisibleLines();
        if (!visibleLines.contains(Integer.valueOf(lineIdx))) {
            int linesVisible = visibleLines.upperEndpoint().intValue()
                    - visibleLines.lowerEndpoint().intValue();
            int delta = linesVisible - verticalOffset;
            int scrollLine = Math.min(lineIdx + delta, getSkinnable().getContent().getLineCount() - 1);
            scrollLineIntoView(scrollLine);
        }/*from   w  w w.  j  a v a 2 s .c  o  m*/

        int colIdx = offset - getSkinnable().getContent().getOffsetAtLine(lineIdx);
        String line = getSkinnable().getContent().getLine(lineIdx).substring(0, colIdx);
        int tabCount = (int) line.chars().filter(c -> c == '\t').count();
        scrollColumnIntoView(colIdx + tabCount * (getSkinnable().tabAvanceProperty().get() - 1),
                horizontalOffset);
    } else {
        scrollLineIntoView(0);
        scrollColumnIntoView(0, 0);
    }
}

From source file:io.github.mzmine.parameters.parametertypes.selectors.ScanSelectionParameter.java

@Override
public void saveValueToXML(Element xmlElement) {
    ScanSelection value = getValue();//from   w w  w  .  j a  v a2  s.c om
    if (value == null)
        return;
    Document parentDocument = xmlElement.getOwnerDocument();

    final Range<Integer> scanNumberRange = value.getScanNumberRange();
    final Range<Double> scanRetentionTimeRange = value.getScanRTRange();
    final PolarityType polarity = value.getPolarity();
    final MsSpectrumType spectrumType = value.getSpectrumType();
    final Integer msLevel = value.getMsLevel();
    final String scanDefinition = value.getScanDefinition();

    if (scanNumberRange != null) {
        Element scanNumElement = parentDocument.createElement("scan_numbers");
        xmlElement.appendChild(scanNumElement);
        Element newElement = parentDocument.createElement("min");
        newElement.setTextContent(String.valueOf(scanNumberRange.lowerEndpoint()));
        scanNumElement.appendChild(newElement);
        newElement = parentDocument.createElement("max");
        newElement.setTextContent(String.valueOf(scanNumberRange.upperEndpoint()));
        scanNumElement.appendChild(newElement);
    }

    if (scanRetentionTimeRange != null) {
        Element scanRtElement = parentDocument.createElement("retention_time");
        xmlElement.appendChild(scanRtElement);
        Element newElement = parentDocument.createElement("min");
        newElement.setTextContent(String.valueOf(scanRetentionTimeRange.lowerEndpoint()));
        scanRtElement.appendChild(newElement);
        newElement = parentDocument.createElement("max");
        newElement.setTextContent(String.valueOf(scanRetentionTimeRange.upperEndpoint()));
        scanRtElement.appendChild(newElement);
    }

    if (polarity != null) {
        Element newElement = parentDocument.createElement("polarity");
        newElement.setTextContent(polarity.toString());
        xmlElement.appendChild(newElement);
    }

    if (spectrumType != null) {
        Element newElement = parentDocument.createElement("spectrum_type");
        newElement.setTextContent(spectrumType.toString());
        xmlElement.appendChild(newElement);
    }

    if (msLevel != null) {
        Element newElement = parentDocument.createElement("ms_level");
        newElement.setTextContent(String.valueOf(msLevel));
        xmlElement.appendChild(newElement);
    }

    if (scanDefinition != null) {
        Element newElement = parentDocument.createElement("scan_definition");
        newElement.setTextContent(scanDefinition);
        xmlElement.appendChild(newElement);
    }

}

From source file:com.google.eclipse.protobuf.validation.ProtobufJavaValidator.java

private void errorOnConflicts(Range<Long> range, Multimap<EObject, Range<Long>> rangeUsages,
        EObject errorSource, EStructuralFeature errorFeature) {
    for (Map.Entry<EObject, Range<Long>> rangeUsage : rangeUsages.entries()) {
        Range<Long> usedRange = rangeUsage.getValue();
        if (range.isConnected(usedRange)) {
            EObject rangeUser = rangeUsage.getKey();

            boolean rangeIsSingular = range.hasUpperBound() && range.upperEndpoint() == range.lowerEndpoint();
            String template = rangeIsSingular ? tagNumberConflict : tagNumberRangeConflict;

            String rangeUserString;
            String usedRangeString = rangeToString(usedRange);
            if (rangeUser instanceof MessageField) {
                rangeUserString = String.format(conflictingField, nameResolver.nameOf(rangeUser),
                        usedRangeString);
            } else if (rangeUser instanceof Group) {
                rangeUserString = String.format(conflictingGroup, nameResolver.nameOf(rangeUser),
                        usedRangeString);
            } else if (rangeUser instanceof Reserved) {
                rangeUserString = String.format(conflictingReservedNumber, usedRangeString);
            } else {
                rangeUserString = String.format(conflictingExtensions, usedRangeString);
            }/*from   ww w  . j a v  a2 s  .  c o  m*/

            String message = String.format(template, rangeToString(range), rangeUserString);
            error(message, errorSource, errorFeature);

            // Don't report more than one error per element.
            return;
        }
    }
}

From source file:org.sosy_lab.cpachecker.cpa.arg.ARGPathExport.java

private String tokensToText(Set<Integer> tokens) {
    StringBuilder result = new StringBuilder();
    RangeSet<Integer> tokenRanges = TreeRangeSet.create();
    for (Integer token : tokens) {
        tokenRanges.add(Range.closed(token, token));
    }/*from   ww w  .  j a  v a 2 s .c o  m*/
    for (Range<Integer> range : tokenRanges.asRanges()) {
        if (result.length() > 0) {
            result.append(",");
        }
        Integer from = range.lowerEndpoint();
        Integer to = range.upperEndpoint();
        if (to - from == 0) {
            result.append(from);
        } else {
            result.append(from);
            result.append("-");
            result.append(to);
        }
    }

    return result.toString();
}

From source file:com.nimbits.io.http.NimbitsClientImpl.java

@Override
public List<Value> getSeries(final String entity, final Range<Date> range) {

    final Gson gson = new GsonBuilder().registerTypeAdapter(Value.class, new ValueDeserializer()).create();

    RestAdapter restAdapter = new RestAdapter.Builder().setEndpoint(instanceUrl.getUrl())
            .setRequestInterceptor(requestInterceptor).setConverter(new GsonConverter(gson)).build();

    SeriesApi seriesApi = restAdapter.create(SeriesApi.class);

    List<Value> sample = seriesApi.getSeries(entity, range.lowerEndpoint().getTime(),
            range.upperEndpoint().getTime());

    List<Value> fixed = new ArrayList<>(sample.size());
    Set<Long> test = new HashSet<>(sample.size());
    for (Value value : sample) {
        if (!test.contains(value.getTimestamp().getTime())) {
            fixed.add(value);/* w w  w  .ja v  a2s. c  o m*/
            test.add(value.getTimestamp().getTime());
        }

    }
    return sample;

}