List of usage examples for com.google.common.collect BoundType CLOSED
BoundType CLOSED
To view the source code for com.google.common.collect BoundType CLOSED.
Click Source Link
From source file:org.apache.cassandra.cql3.restrictions.TokenFilter.java
private static BoundType toBoundType(boolean inclusive) { return inclusive ? BoundType.CLOSED : BoundType.OPEN; }
From source file:org.assertj.guava.api.RangeAssert.java
/** * Verifies that the actual {@link com.google.common.collect.Range} upper bound is closed.<br> * <p>/*w w w. ja v a2s . c om*/ * Example : * * <pre><code class='java'> Range<Integer> range = Range.closed(10, 12); * * assertThat(range).hasClosedUpperBound();</code></pre> * * @return this {@link OptionalAssert} for assertions chaining. * @throws AssertionError if the actual {@link com.google.common.collect.Range} is {@code null}. * @throws AssertionError if the actual {@link com.google.common.collect.Range} upper bound is opened. */ public RangeAssert<T> hasClosedUpperBound() throws AssertionError { Objects.instance().assertNotNull(info, actual); if (actual.upperBoundType() != BoundType.CLOSED) { throw failures.failure(info, shouldHaveClosedUpperBound(actual)); } return this; }
From source file:org.cinchapi.concourse.server.model.Ranges.java
/** * Return the ranges that include the points that are in {@code a} or the * {@code b} one and not in their intersection. The return set will include * between 0 and 2 ranges that together include all the points that meet * this criteria.//from w w w . j a v a 2 s.c o m * <p> * <strong>NOTE:</strong> If the two ranges do not intersect, then a * collection containing both of them is returned (since they already form * their xor). * </p> * * @param a * @param b * @return the set or ranges that make uValue the symmetric difference * between this range and the {@code other} one */ public static Iterable<Range<Value>> xor(Range<Value> a, Range<Value> b) { List<Range<Value>> ranges = Lists.newArrayList(); try { Range<Value> intersection = a.intersection(b); boolean aStart = compareToLower(a, b) < 0; boolean aEnd = compareToUpper(a, b) > 0; boolean lower = getLowerBoundType(aStart ? a : b) == BoundType.CLOSED; boolean upper = getUpperBoundType(aEnd ? a : b) == BoundType.CLOSED; boolean interLower = getLowerBoundType(intersection) == BoundType.OPEN; boolean interUpper = getUpperBoundType(intersection) == BoundType.OPEN; Range<Value> first; if (lower && interLower) { first = Range.closed(getLowerEndpoint(aStart ? a : b), getLowerEndpoint(intersection)); } else if (!lower && interLower) { first = Range.openClosed(getLowerEndpoint(aStart ? a : b), getLowerEndpoint(intersection)); } else if (lower && !interLower) { first = Range.closedOpen(getLowerEndpoint(aStart ? a : b), getLowerEndpoint(intersection)); } else { first = Range.open(getLowerEndpoint(aStart ? a : b), getLowerEndpoint(intersection)); } Range<Value> second; if (interUpper && upper) { second = Range.closed(getUpperEndpoint(intersection), getUpperEndpoint(aEnd ? a : b)); } else if (!interUpper && upper) { second = Range.openClosed(getUpperEndpoint(intersection), getUpperEndpoint(aEnd ? a : b)); } else if (interUpper && !interUpper) { second = Range.closedOpen(getUpperEndpoint(intersection), getUpperEndpoint(aEnd ? a : b)); } else { second = Range.open(getUpperEndpoint(intersection), getUpperEndpoint(aEnd ? a : b)); } if (!first.isEmpty()) { ranges.add(first); } if (!second.isEmpty()) { ranges.add(second); } } catch (IllegalArgumentException e) { // ranges dont intersect ranges.add(a); ranges.add(b); } return ranges; }
From source file:org.apache.mahout.math.neighborhood.ProjectionSearch.java
/** * Returns the closest vector to the query. * When only one the nearest vector is needed, use this method, NOT search(query, limit) because * it's faster (less overhead).// ww w . ja v a2 s. co m * * @param query the vector to search for * @param differentThanQuery if true, returns the closest vector different than the query (this * only matters if the query is among the searched vectors), otherwise, * returns the closest vector to the query (even the same vector). * @return the weighted vector closest to the query */ @Override public WeightedThing<Vector> searchFirst(Vector query, boolean differentThanQuery) { double bestDistance = Double.POSITIVE_INFINITY; Vector bestVector = null; Iterator<? extends Vector> projections = basisMatrix.iterator(); for (TreeMultiset<WeightedThing<Vector>> v : scalarProjections) { Vector basisVector = projections.next(); WeightedThing<Vector> projectedQuery = new WeightedThing<Vector>(query, query.dot(basisVector)); for (WeightedThing<Vector> candidate : Iterables.concat( Iterables.limit(v.tailMultiset(projectedQuery, BoundType.CLOSED), searchSize), Iterables.limit( v.headMultiset(projectedQuery, BoundType.OPEN).descendingMultiset(), searchSize))) { double distance = distanceMeasure.distance(query, candidate.getValue()); if (distance < bestDistance && (!differentThanQuery || !candidate.getValue().equals(query))) { bestDistance = distance; bestVector = candidate.getValue(); } } } return new WeightedThing<Vector>(bestVector, bestDistance); }
From source file:uk.ac.open.kmi.iserve.discovery.disco.impl.SparqlIndexedLogicConceptMatcher.java
/** * Obtain all the matching resources with the URI of {@code origin} within the range of MatchTypes provided, both inclusive. * * @param origin URI to match//from ww w . j a v a 2 s .co m * @param minType the minimum MatchType we want to obtain * @param maxType the maximum MatchType we want to obtain * @return a Map containing indexed by the URI of the matching resource and containing the particular {@code MatchResult}. If no * result is found the Map should be empty not null. */ @Override public synchronized Map<URI, MatchResult> listMatchesWithinRange(URI origin, MatchType minType, MatchType maxType) { if (origin == null || minType == null | maxType == null) { return ImmutableMap.of(); } Function<MatchResult, MatchType> getTypeFunction = new Function<MatchResult, MatchType>() { @Override public MatchType apply(@Nullable MatchResult matchResult) { if (matchResult != null) { return matchResult.getMatchType(); } return null; } }; // Get all the matches Map<URI, MatchResult> matches = this.indexedMatches.get(origin); // Return an immutable map out of the filtered view. Drop copyOf to obtain a live view if (matches != null) { return ImmutableMap.copyOf(Maps.filterValues(matches, MatchResultPredicates.withinRange(minType, BoundType.CLOSED, maxType, BoundType.CLOSED))); } else { return ImmutableMap.of(); } }
From source file:org.learningu.scheduling.util.bst.BstMap.java
private static BoundType boundType(boolean inclusive) { return inclusive ? BoundType.CLOSED : BoundType.OPEN; }
From source file:org.apache.druid.query.filter.BoundDimFilter.java
@Override public RangeSet<String> getDimensionRangeSet(String dimension) { if (!(Objects.equals(getDimension(), dimension) && getExtractionFn() == null && ordering.equals(StringComparators.LEXICOGRAPHIC))) { return null; }//from w w w . jav a2 s. c o m RangeSet<String> retSet = TreeRangeSet.create(); Range<String> range; if (getLower() == null) { range = isUpperStrict() ? Range.lessThan(getUpper()) : Range.atMost(getUpper()); } else if (getUpper() == null) { range = isLowerStrict() ? Range.greaterThan(getLower()) : Range.atLeast(getLower()); } else { range = Range.range(getLower(), isLowerStrict() ? BoundType.OPEN : BoundType.CLOSED, getUpper(), isUpperStrict() ? BoundType.OPEN : BoundType.CLOSED); } retSet.add(range); return retSet; }
From source file:net.sf.mzmine.modules.visualization.tic.TICVisualizerWindow.java
void updateTitle() { NumberFormat rtFormat = MZmineCore.getConfiguration().getRTFormat(); NumberFormat mzFormat = MZmineCore.getConfiguration().getMZFormat(); NumberFormat intensityFormat = MZmineCore.getConfiguration().getIntensityFormat(); StringBuffer mainTitle = new StringBuffer(); StringBuffer subTitle = new StringBuffer(); // If all data files have m/z range less than or equal to range of // the plot (mzMin, mzMax), then call this TIC, otherwise XIC Set<RawDataFile> fileSet = ticDataSets.keySet(); String ticOrXIC = "TIC"; // Enlarge range a bit to avoid rounding errors Range<Double> mzRange2 = Range.range(mzRange.lowerEndpoint() - 1, BoundType.CLOSED, mzRange.upperEndpoint() + 1, BoundType.CLOSED); for (RawDataFile df : fileSet) { if (!mzRange2.encloses(df.getDataMZRange())) { ticOrXIC = "XIC"; break; }/*from w ww .j a v a2 s.c o m*/ } if (plotType == TICPlotType.BASEPEAK) { if (ticOrXIC.equals("TIC")) { mainTitle.append("Base peak chromatogram"); } else { mainTitle.append("XIC (base peak)"); } } else { if (ticOrXIC.equals("TIC")) { mainTitle.append("TIC"); } else { mainTitle.append("XIC"); } } mainTitle.append(", m/z: " + mzFormat.format(mzRange.lowerEndpoint()) + " - " + mzFormat.format(mzRange.upperEndpoint())); CursorPosition pos = getCursorPosition(); if (pos != null) { subTitle.append("Selected scan #"); subTitle.append(pos.getScanNumber()); if (ticDataSets.size() > 1) { subTitle.append(" (" + pos.getDataFile() + ")"); } subTitle.append(", RT: " + rtFormat.format(pos.getRetentionTime())); if (plotType == TICPlotType.BASEPEAK) { subTitle.append(", base peak: " + mzFormat.format(pos.getMzValue()) + " m/z"); } subTitle.append(", IC: " + intensityFormat.format(pos.getIntensityValue())); } // update window title RawDataFile files[] = ticDataSets.keySet().toArray(new RawDataFile[0]); Arrays.sort(files, new SimpleSorter()); String dataFileNames = Joiner.on(",").join(files); setTitle("Chromatogram: [" + dataFileNames + "; " + mzFormat.format(mzRange.lowerEndpoint()) + " - " + mzFormat.format(mzRange.upperEndpoint()) + " m/z" + "]"); // update plot title ticPlot.setTitle(mainTitle.toString(), subTitle.toString()); }
From source file:com.pingcap.tikv.predicates.ScanBuilder.java
private List<KeyRange> buildIndexScanKeyRange(TiTableInfo table, TiIndexInfo index, List<IndexRange> indexRanges) { requireNonNull(table, "Table cannot be null to encoding keyRange"); requireNonNull(index, "Index cannot be null to encoding keyRange"); requireNonNull(index, "indexRanges cannot be null to encoding keyRange"); List<KeyRange> ranges = new ArrayList<>(indexRanges.size()); for (IndexRange ir : indexRanges) { CodecDataOutput cdo = new CodecDataOutput(); List<Object> values = ir.getAccessPoints(); List<DataType> types = ir.getTypes(); for (int i = 0; i < values.size(); i++) { Object v = values.get(i); DataType t = types.get(i);//from w ww.j ava2 s . c o m t.encode(cdo, DataType.EncodeType.KEY, v); } byte[] pointsData = cdo.toBytes(); cdo.reset(); Range r = ir.getRange(); byte[] lPointKey; byte[] uPointKey; byte[] lKey; byte[] uKey; if (r == null) { lPointKey = pointsData; uPointKey = KeyUtils.prefixNext(lPointKey.clone()); lKey = new byte[0]; uKey = new byte[0]; } else { lPointKey = pointsData; uPointKey = pointsData; DataType type = ir.getRangeType(); if (!r.hasLowerBound()) { // -INF type.encodeMinValue(cdo); lKey = cdo.toBytes(); } else { Object lb = r.lowerEndpoint(); type.encode(cdo, DataType.EncodeType.KEY, lb); lKey = cdo.toBytes(); if (r.lowerBoundType().equals(BoundType.OPEN)) { lKey = KeyUtils.prefixNext(lKey); } } cdo.reset(); if (!r.hasUpperBound()) { // INF type.encodeMaxValue(cdo); uKey = cdo.toBytes(); } else { Object ub = r.upperEndpoint(); type.encode(cdo, DataType.EncodeType.KEY, ub); uKey = cdo.toBytes(); if (r.upperBoundType().equals(BoundType.CLOSED)) { uKey = KeyUtils.prefixNext(lKey); } } cdo.reset(); } TableCodec.writeIndexSeekKey(cdo, table.getId(), index.getId(), lPointKey, lKey); ByteString lbsKey = ByteString.copyFrom(cdo.toBytes()); cdo.reset(); TableCodec.writeIndexSeekKey(cdo, table.getId(), index.getId(), uPointKey, uKey); ByteString ubsKey = ByteString.copyFrom(cdo.toBytes()); ranges.add(KeyRange.newBuilder().setStart(lbsKey).setEnd(ubsKey).build()); } if (ranges.isEmpty()) { ranges.add(INDEX_FULL_RANGE); } return ranges; }
From source file:com.basistech.tclre.ColorMap.java
/** * subrange - allocate new subcolors to this range of chars, fill in arcs. * The range will overlap existing ranges; even in the simplest case, * it will overlap the initial WHITE range. For each existing range that * it overlaps, allocate a new color, mark the range as mapping to that color, * and add an arc between the states for that color. *///from w w w . j av a 2 s .c o m void subrange(int from, int to, State lp, State rp) throws RegexException { /* Avoid one call to map.get() for each character in the range. * This map will usually contain one item, but in complex cases more. * For example, if we had [a-f][g-h] and then someone asked for [f-g], there * would be two. Each of these new ranges will get a new color via subcolor. */ Map<Range<Integer>, Short> curColors = map.subRangeMap(Range.closed(from, to)).asMapOfRanges(); /* * To avoid concurrent mod problems, we need to copy the ranges we are working from. */ List<Range<Integer>> ranges = Lists.newArrayList(curColors.keySet()); for (Range<Integer> rangeToProcess : ranges) { // bound management here irritating. int start = rangeToProcess.lowerEndpoint(); if (rangeToProcess.lowerBoundType() == BoundType.OPEN) { start++; } int end = rangeToProcess.upperEndpoint(); if (rangeToProcess.upperBoundType() == BoundType.CLOSED) { end++; } // allocate a new subcolor and account it owning the entire range. short color = subcolor(start, end - start); compiler.getNfa().newarc(Compiler.PLAIN, color, lp, rp); } }