List of usage examples for com.google.common.collect Range hasUpperBound
public boolean hasUpperBound()
From source file:org.noroomattheinn.timeseries.InMemoryTS.java
@Override public NavigableMap<Long, Row> getIndex(Range<Long> period) { long from = period.hasLowerBound() ? period.lowerEndpoint() : 0; long to = period.hasUpperBound() ? period.upperEndpoint() : Long.MAX_VALUE; return index.subMap(from, true, to, true); }
From source file:org.noroomattheinn.visibletesla.data.CycleStore.java
List<C> getCycles(Range<Long> period) { if (period == null) period = Range.all();/* w w w .j av a 2 s . 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:org.corpus_tools.peppermodules.annis.Audio2ANNISMapper.java
private void outputVirtualTokenAnnotations() { for (Map.Entry<Long, Range<Double>> e : virtTokenTimes.entrySet()) { Range<Double> r = e.getValue(); String val = null; if (r.hasLowerBound() && r.hasUpperBound()) { val = r.lowerEndpoint() + "-" + r.upperEndpoint(); } else if (r.hasLowerBound()) { val = "" + r.lowerEndpoint(); } else if (r.hasUpperBound()) { val = "-" + r.upperEndpoint(); }//from www .jav a 2s.co m if (val != null) { mapSNodeAnnotation(e.getKey(), "annis", "time", val); } } }
From source file:li.klass.fhem.activities.graph.YAxis.java
public YAxis(Context context, GPlotAxis axis, String label) { this.context = context; this.label = label; Range<Double> range = axis.getRange().or(Range.range(-1d, BoundType.OPEN, 1d, BoundType.OPEN)); if (range.hasLowerBound()) { minimumY = range.lowerEndpoint(); }/*from w w w . jav a2 s . co m*/ if (range.hasUpperBound()) { maximumY = range.upperEndpoint(); } }
From source file:org.robotframework.ide.eclipse.main.plugin.assist.RedKeywordProposal.java
@Override public List<String> getArguments() { if (EmbeddedKeywordNamesSupport.hasEmbeddedArguments(getNameFromDefinition())) { return new ArrayList<>(); } else {//w ww.j av a 2 s. c o m final List<String> arguments = newArrayList( transform(getArgumentsDescriptor().getRequiredArguments(), new Function<Argument, String>() { @Override public String apply(final Argument arg) { return arg.getName(); } })); final Range<Integer> noOfArgs = getArgumentsDescriptor().getPossibleNumberOfArguments(); final boolean mayHaveMoreArguments = !noOfArgs.hasUpperBound() || noOfArgs.upperEndpoint() > arguments.size(); if (mayHaveMoreArguments) { arguments.add(""); } return arguments; } }
From source file:com.techshroom.wood.ModuleDependency.java
@Override public String toString() { StringBuilder builder = new StringBuilder(getId()).append(':'); Range<SemVer> r = getVersionRange(); if (r.hasLowerBound()) { builder.append(r.lowerBoundType() == BoundType.OPEN ? '(' : '[').append(r.lowerEndpoint()); } else {/*w ww . ja v a 2 s .com*/ builder.append('('); } builder.append(','); if (r.hasUpperBound()) { builder.append(r.upperEndpoint()).append(r.upperBoundType() == BoundType.OPEN ? ')' : ']'); } else { builder.append(')'); } return builder.toString(); }
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 www .j av a2s .c o m*/ 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:com.google.eclipse.protobuf.validation.ProtobufJavaValidator.java
private String rangeToString(Range<Long> range) { if (range.hasLowerBound() && range.hasUpperBound() && range.lowerEndpoint() == range.upperEndpoint()) { return String.valueOf(range.lowerEndpoint()); }//from w ww. j a va 2 s. c om String upper = range.hasUpperBound() ? String.valueOf(range.upperEndpoint()) : indexRanges.getMaxKeyword(); return String.format("%d to %s", range.lowerEndpoint(), upper); }
From source file:com.github.fge.grappa.matchers.join.JoinMatcherBuilder.java
/** * Generic method to build a {@link JoinMatcher} * * <p>You can use this method directly; note however that the range you will * pass as an argument will be {@link Range#intersection(Range) intersected} * with {@code Range.atLeast(0)}; if the result of the intersection is an * {@link Range#isEmpty() empty range}, this is an error condition.</p> * * <p>Ranges which are {@link BoundType#OPEN open} on any end will be turned * to closed range using {@link Range#canonical(DiscreteDomain)}.</p> * * @param range the range (must not be null) * @return a rule/*from w ww . ja v a 2s. c om*/ * @throws IllegalArgumentException see description * * @see Range#canonical(DiscreteDomain) */ // TODO: check that it actually has an effect @Cached public Rule range(@Nonnull Range<Integer> range) { Objects.requireNonNull(range, "range must not be null"); /* * We always intersect with that range... */ Range<Integer> realRange = AT_LEAST_ZERO.intersection(range); /* * Empty ranges not allowed (what are we supposed to do with that * anyway?) */ Preconditions.checkArgument(!realRange.isEmpty(), "illegal range " + range + ": should not be empty after intersection with " + AT_LEAST_ZERO); /* * Given that we intersect with AT_LEAST_ZERO, which has a lower bound, * the range will always have a lower bound. We want a closed range * internally, therefore change it if it is open. */ Range<Integer> closedRange = toClosedRange(realRange); /* * We always have a lower bound */ int lowerBound = closedRange.lowerEndpoint(); /* * Handle the case where there is no upper bound */ if (!closedRange.hasUpperBound()) return new BoundedDownJoinMatcher(joined, joining, lowerBound); /* * There is an upper bound. Handle the case where it is 0 or 1. Since * the range is legal, we know that if it is 0, so is the lowerbound; * and if it is one, the lower bound is either 0 or 1. */ int upperBound = closedRange.upperEndpoint(); if (upperBound == 0) return new EmptyMatcher(); if (upperBound == 1) return lowerBound == 0 ? new OptionalMatcher(joined) : joined; /* * So, upper bound is 2 or greater; return the appropriate matcher * according to what the lower bound is. * * Also, if the lower and upper bounds are equal, return a matcher doing * a fixed number of matches. */ if (lowerBound == 0) return new BoundedUpJoinMatcher(joined, joining, upperBound); return lowerBound == upperBound ? new ExactMatchesJoinMatcher(joined, joining, lowerBound) : new BoundedBothJoinMatcher(joined, joining, lowerBound, upperBound); }
From source file:com.wealdtech.collect.TreeRangedMap.java
/** * Validate a range prior to insertion/*from w w w.ja v a2 s .com*/ * @param range the range to validate */ private void validateRange(final Range<K> range) { if (!range.hasLowerBound()) { throw new IllegalArgumentException("RangedMap only supports ranges with defined lower bound"); } if (!range.lowerBoundType().equals(BoundType.CLOSED)) { throw new IllegalArgumentException("RangedMap must use ranges with closed lower bound"); } if (!range.hasUpperBound()) { throw new IllegalArgumentException("RangedMap must use ranges with defined upper bound"); } if (!range.upperBoundType().equals(BoundType.OPEN)) { throw new IllegalArgumentException("RangedMap must use ranges with open upper bound"); } if (range.isEmpty()) { throw new IllegalArgumentException("RangedMap must use ranges with non-zero size"); } }