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:org.noroomattheinn.visibletesla.data.CycleStore.java

List<C> getCycles(Range<Long> period) {
    if (period == null)
        period = Range.all();//from   w w w.ja  v a 2s  .com
    long startTime = period.hasLowerBound() ? period.lowerEndpoint() : 0;
    long endTime = period.hasUpperBound() ? period.upperEndpoint() : Long.MAX_VALUE;

    List<C> cycles = new ArrayList<>();
    BufferedReader r = null;
    try {
        r = new BufferedReader(new FileReader(cycleFile));

        try {
            String entry;
            while ((entry = r.readLine()) != null) {
                C cycle = BaseCycle.fromJSON(entry, theClass);
                if (cycle.startTime >= startTime && cycle.startTime <= endTime) {
                    cycles.add(cycle);
                } else if (cycle.startTime > endTime) {
                    break;
                }
            }
        } catch (IOException ex) {
            logger.warning("Problem reading " + cycleType + " Cycle data: " + ex);
        }
    } catch (FileNotFoundException ex) {
        logger.warning("Could not open " + cycleType + " file: " + ex);
    } finally {
        if (r != null) {
            try {
                r.close();
            } catch (IOException e) {
                logger.warning("Failed closing reader: " + e);
            }
        }
    }
    return cycles;
}

From source file:com.b2international.snowowl.snomed.core.ecl.SnomedEclRefinementEvaluator.java

static Function<Collection<Property>, Collection<Property>> filterByCardinality(
        final boolean grouped, final Range<Long> groupCardinality, final Range<Long> cardinality,
        final Function<Property, Object> idProvider) {
    return matchingProperties -> {
        final Multimap<Object, Property> propertiesByMatchingIds = Multimaps.index(matchingProperties,
                idProvider);//from  ww  w .j  a v  a 2s.  c  om
        final Collection<Property> properties = newHashSet();

        final Range<Long> allowedRelationshipCardinality;
        if (grouped) {
            final long minRelationships = groupCardinality.lowerEndpoint() == 0 ? cardinality.lowerEndpoint()
                    : groupCardinality.lowerEndpoint() * cardinality.lowerEndpoint();
            final long maxRelationships;
            if (groupCardinality.hasUpperBound() && cardinality.hasUpperBound()) {
                if (groupCardinality.upperEndpoint() == Long.MAX_VALUE
                        || cardinality.upperEndpoint() == Long.MAX_VALUE) {
                    maxRelationships = Long.MAX_VALUE;
                } else {
                    maxRelationships = groupCardinality.upperEndpoint() * cardinality.upperEndpoint();
                }
            } else {
                // group and relationship cardinalities are unbounded
                maxRelationships = Long.MAX_VALUE;
            }
            allowedRelationshipCardinality = Range.closed(minRelationships, maxRelationships);
        } else {
            allowedRelationshipCardinality = cardinality;
        }

        for (Object matchingConceptId : propertiesByMatchingIds.keySet()) {
            final Collection<Property> propertiesOfConcept = propertiesByMatchingIds.get(matchingConceptId);
            if (allowedRelationshipCardinality.contains((long) propertiesOfConcept.size())) {
                if (grouped) {
                    final Multimap<Integer, Property> indexedByGroup = FluentIterable.from(propertiesOfConcept)
                            .index(Property::getGroup);
                    // if groups should be considered as well, then check group numbers in the matching sets
                    // check that the concept has at least the right amount of groups
                    final Multimap<Integer, Property> validGroups = ArrayListMultimap.create();

                    for (Integer group : indexedByGroup.keySet()) {
                        final Collection<Property> groupedRelationships = indexedByGroup.get(group);
                        if (cardinality.contains((long) groupedRelationships.size())) {
                            validGroups.putAll(group, groupedRelationships);
                        }
                    }

                    if (groupCardinality.contains((long) validGroups.keySet().size())) {
                        properties.addAll(validGroups.values());
                    }
                } else {
                    properties.addAll(propertiesOfConcept);
                }
            }
        }
        return properties;
    };
}

From source file:org.pascani.dsl.dbmapper.databases.Influxdb.java

private Point makeRequestString(ChangeEvent e, Serializable value, Map<String, String> tags) {
    Builder point = Point.measurement(e.variable()).tag(tags).time(e.timestamp(), TimeUnit.MILLISECONDS);
    if (value instanceof Range<?>) {
        Range<?> range = (Range<?>) value;
        Number start = (Number) range.lowerEndpoint();
        Number end = (Number) range.upperEndpoint();
        point.addField("start", start + "");
        point.addField("end", end + "");
        point.addField("value", (end.doubleValue() - start.doubleValue()) + "");
    } else if (value instanceof Number) {
        point.addField("value", (Number) value);
    } else if (value instanceof Boolean) {
        point.addField("value", (Boolean) value);
    } else if (value instanceof String) {
        point.addField("value", (String) value);
    }//from w w  w .  ja  v a  2 s.c om
    return point.build();
}

From source file:org.robotframework.red.nattable.TableCellStringData.java

public int getCharacterIndexFrom(final int x, final int y) {
    if (coordinate.x <= x && x <= coordinate.x + extent.x && coordinate.y <= y && y < coordinate.y + extent.y) {
        // the (x,y) position is over the string

        final Range<Integer> startingRegion = getStartingRegion(extent.y, y - coordinate.y);
        int begin = startingRegion.lowerEndpoint();
        int end = startingRegion.upperEndpoint();

        int beginX = coordinate.x;
        int endX = beginX + extent.x;

        while (beginX < (endX - 1)) {
            final int midX = (beginX + endX) / 2;
            if (x >= midX) {
                beginX = midX;/*from  w  w  w  .  ja  v a2 s.c om*/
                begin = (begin + end) / 2;
            } else {
                endX = midX;
                end = (begin + end) / 2;
            }
        }
        return begin;
    }
    return -1;
}

From source file:google.registry.model.common.TimeOfYear.java

/**
 * Returns an {@link Iterable} of {@link DateTime}s of every recurrence of this particular
 * time of year within a given {@link Range} (usually one spanning many years).
 *
 * <p>WARNING: This can return a potentially very large {@link Iterable} if {@code END_OF_TIME}
 * is used as the upper endpoint of the range.
 *///w w  w. j  a v a2  s  .  co m
public Iterable<DateTime> getInstancesInRange(Range<DateTime> range) {
    // In registry world, all dates are within START_OF_TIME and END_OF_TIME, so restrict any
    // ranges without bounds to our notion of zero-to-infinity.
    Range<DateTime> normalizedRange = range.intersection(Range.closed(START_OF_TIME, END_OF_TIME));
    Range<Integer> yearRange = Range.closed(normalizedRange.lowerEndpoint().getYear(),
            normalizedRange.upperEndpoint().getYear());
    return FluentIterable.from(ContiguousSet.create(yearRange, integers()))
            .transform(new Function<Integer, DateTime>() {
                @Override
                public DateTime apply(Integer year) {
                    return getDateTimeWithYear(year);
                }
            }).filter(normalizedRange);
}

From source file:com.github.fge.largetext.range.IntRange.java

public IntRange(Range<Integer> guavaRange) {
    this.upperBound = guavaRange.upperEndpoint();
    this.lowerBound = guavaRange.lowerEndpoint();
}

From source file:net.joala.data.random.AbstractRandomNumberProvider.java

/**
 * Provide a random number in the given range.
 * @param range (closed) range in which to choose a number from
 * @return random value/*from   w ww . ja va  2  s . c om*/
 * @throws IllegalStateException if range is empty
 */
private T nextRandom(final Range<T> range) {
    checkState(!range.isEmpty(), "Range must not be empty.");
    final T lowerEndpoint = range.lowerEndpoint();
    final T upperEndpoint = range.upperEndpoint();
    final double random = nextRandomRatio();
    return numberType.sum(numberType.percentOf(random, upperEndpoint),
            numberType.percentOf((1d - random), lowerEndpoint));
}

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

@Override
public void allocateGroup(ActorGroup group, Range<Integer> iterations, List<Core> cores, Configuration config) {
    int coresSize = Math.min(cores.size(), maxNumCores);
    int perCore = IntMath.divide(iterations.upperEndpoint() - iterations.lowerEndpoint(), coresSize,
            RoundingMode.CEILING);
    for (int i = 0; i < coresSize && !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());
    }//  w  w  w.  java2 s .  c  o  m
    assert iterations.isEmpty();
}

From source file:it.units.malelab.ege.ge.genotype.BitsGenotype.java

public BitsGenotype slice(Range<Integer> range) {
    if ((range.upperEndpoint() - range.lowerEndpoint()) == 0) {
        return new BitsGenotype(0);
    }//from  w  ww. j  ava2 s. c  o m
    return slice(range.lowerEndpoint(), range.upperEndpoint());
}

From source file:org.jclouds.googlecomputeengine.compute.functions.FirewallToIpPermission.java

@Override
public Iterable<IpPermission> apply(Firewall fw) {
    ImmutableSet.Builder setBuilder = ImmutableSet.builder();

    for (Rule rule : fw.getAllowed()) {
        if (!rule.getPorts().isEmpty()) {
            for (Range<Integer> r : rule.getPorts().asRanges()) {
                IpPermission.Builder builder = populateBuilder(fw, rule.getIpProtocol());
                builder.fromPort(r.lowerEndpoint());
                builder.toPort(r.upperEndpoint());
                setBuilder.add(builder.build());
            }//  w  w  w  . ja v a 2  s  .c  om
        } else {
            setBuilder.add(populateBuilder(fw, rule.getIpProtocol()).build());
        }
    }

    return setBuilder.build();
}