List of usage examples for com.google.common.collect Range toString
@Override
public String toString()
From source file:edu.mit.streamjit.test.Datasets.java
public static Dataset allIntsInRange(Range<Integer> range) { return fromIterable(range.toString(), ContiguousSet.create(range, DiscreteDomain.integers())); }
From source file:org.obiba.opal.web.gwt.app.client.magma.derive.view.ValueMapEntry.java
public static Builder fromRange(Range<? extends Number> range) { return fromRange(range.hasLowerBound() ? range.lowerEndpoint() : null, range.hasUpperBound() ? range.upperEndpoint() : null).label(range.toString()); }
From source file:com.android.build.gradle.integration.common.utils.AndroidVersionMatcher.java
public static Matcher<AndroidVersion> forRange(Range<Integer> range) { return new BaseMatcher<AndroidVersion>() { @Override//from w w w . j av a 2 s.c om public boolean matches(Object item) { return item instanceof AndroidVersion && range.contains(((AndroidVersion) item).getApiLevel()); } @Override public void describeTo(Description description) { description.appendText("Android versions in the ").appendText(range.toString()) .appendText(" range."); } }; }
From source file:com.dssmp.pipeline.config.Configuration.java
/** * Validates that a given value falls withing a range. * * @param value/*from www .ja v a 2 s .co m*/ * @param range * @throws ConfigurationException if the value doesn't fall within the range. */ public static <T extends Comparable<T>> void validateRange(T value, Range<T> range, String label) { if (!range.contains(value)) { String message = String.format("'%s' value %s is outside of valid range (%s)", label, value.toString(), range.toString()); throw new ConfigurationException(message); } }
From source file:de.visiom.carpc.asb.serviceregistry.impl.entities.adapters.RangeAdapter.java
@Override public String marshal(Range<BigDecimal> v) throws Exception { return v.toString(); }
From source file:com.wealdtech.jackson.modules.RangeSerializer.java
@Override public void serialize(final Range<?> value, final JsonGenerator gen, final SerializerProvider provider) throws IOException { gen.writeString(value.toString()); }
From source file:com.comphenix.protocol.RangeParser.java
/** * Parse ranges from an array of elements. * @param args - array of elements./*from w ww . ja va2 s . c o m*/ * @param offset - beginning offset. * @param lastIndex - the last index of the array to read. * @param legalRange - range of legal values. * @return The parsed ranges. */ public static List<Range<Integer>> getRanges(Deque<String> input, Range<Integer> legalRange) { List<String> tokens = tokenizeInput(input); List<Range<Integer>> ranges = new ArrayList<Range<Integer>>(); for (int i = 0; i < tokens.size(); i++) { Range<Integer> range; String current = tokens.get(i); String next = i + 1 < tokens.size() ? tokens.get(i + 1) : null; // Yoda equality is done for null-safety if ("-".equals(current)) { throw new IllegalArgumentException("A hyphen must appear between two numbers."); } else if ("-".equals(next)) { if (i + 2 >= tokens.size()) throw new IllegalArgumentException("Cannot form a range without a upper limit."); // This is a proper range range = Range.closed(Integer.parseInt(current), Integer.parseInt(tokens.get(i + 2))); ranges.add(range); // Skip the two next tokens i += 2; } else { // Just a single number range = Range.singleton(Integer.parseInt(current)); ranges.add(range); } // Validate ranges if (!legalRange.encloses(range)) { throw new IllegalArgumentException(range + " is not in the range " + range.toString()); } } return simplify(ranges, legalRange.upperEndpoint()); }
From source file:com.rackspacecloud.blueflood.io.EnumMetricData.java
/** * Reads from both the metrics_enum and metrics_preaggregated_{granularity} column families, * in parallel, and join the data to construct {@link com.rackspacecloud.blueflood.outputs.formats.MetricData} * objects//from w ww .j av a 2 s . c o m * * @param locators * @param range * @param columnFamily * @return */ private Map<Locator, MetricData> getEnumMetricDataForRangeForLocatorList(final List<Locator> locators, final Range range, final String columnFamily) { if (range.getStart() > range.getStop()) { throw new IllegalArgumentException(String.format("invalid range: ", range.toString())); } Future<Table<Locator, Long, String>> enumHashValuesFuture = taskExecutor.submit(new Callable() { @Override public Table<Locator, Long, String> call() throws Exception { return enumReader.getEnumHashValuesForLocators(locators); } }); Future<Table<Locator, Long, BluefloodEnumRollup>> enumHashRollupFuture = taskExecutor .submit(new Callable() { @Override public Table<Locator, Long, BluefloodEnumRollup> call() throws Exception { return enumReader.getEnumRollupsForLocators(locators, columnFamily, range); } }); Map<Locator, MetricData> resultMap = new HashMap<Locator, MetricData>(); try { Table<Locator, Long, String> enumHashValues = enumHashValuesFuture.get(); Table<Locator, Long, BluefloodEnumRollup> enumHashRollup = enumHashRollupFuture.get(); for (Locator locator : locators) { populateEnumValueToCountMap(enumHashRollup.row(locator), enumHashValues.row(locator)); Points points = convertToPoints(enumHashRollup.row(locator)); MetricData metricData = new MetricData(points, metadataCache.getUnitString(locator), MetricData.Type.ENUM); resultMap.put(locator, metricData); } } catch (InterruptedException e) { LOG.error("Interrupted while reading Enum metrics for locators " + locators, e); } catch (ExecutionException e) { LOG.error("Execution error while reading Enum metrics for locators " + locators, e); } return resultMap; }
From source file:com.rackspacecloud.blueflood.io.astyanax.AstyanaxReader.java
protected Map<Locator, ColumnList<Long>> getColumnsFromDB(List<Locator> locators, ColumnFamily<Locator, Long> CF, Range range) { if (range.getStart() > range.getStop()) { throw new RuntimeException(String.format("Invalid rollup range: ", range.toString())); }//from w w w .j a v a2 s . c o m boolean isBatch = locators.size() != 1; final Map<Locator, ColumnList<Long>> columns = new HashMap<Locator, ColumnList<Long>>(); final RangeBuilder rangeBuilder = new RangeBuilder().setStart(range.getStart()).setEnd(range.getStop()); Timer.Context ctx = isBatch ? Instrumentation.getBatchReadTimerContext(CF.getName()) : Instrumentation.getReadTimerContext(CF.getName()); try { // We don't paginate this call. So we should make sure the number of reads is tolerable. // TODO: Think about paginating this call. OperationResult<Rows<Locator, Long>> query = keyspace.prepareQuery(CF).getKeySlice(locators) .withColumnRange(rangeBuilder.build()).execute(); for (Row<Locator, Long> row : query.getResult()) { columns.put(row.getKey(), row.getColumns()); } } catch (ConnectionException e) { if (e instanceof NotFoundException) { // TODO: Not really sure what happens when one of the keys is not found. Instrumentation.markNotFound(CF.getName()); } else { if (isBatch) { Instrumentation.markBatchReadError(e); } else { Instrumentation.markReadError(e); } } log.error((isBatch ? "Batch " : "") + " read query failed for column family " + CF.getName() + " for locators: " + StringUtils.join(locators, ","), e); } finally { ctx.stop(); } return columns; }
From source file:com.rackspacecloud.blueflood.io.AstyanaxReader.java
private Map<Locator, ColumnList<Long>> getColumnsFromDB(List<Locator> locators, ColumnFamily<Locator, Long> CF, Range range) { if (range.getStart() > range.getStop()) { throw new RuntimeException(String.format("Invalid rollup range: ", range.toString())); }/*from w ww . j a v a 2 s .c o m*/ boolean isBatch = locators.size() != 1; final Map<Locator, ColumnList<Long>> columns = new HashMap<Locator, ColumnList<Long>>(); final RangeBuilder rangeBuilder = new RangeBuilder().setStart(range.getStart()).setEnd(range.getStop()); Timer.Context ctx = isBatch ? Instrumentation.getBatchReadTimerContext(CF) : Instrumentation.getReadTimerContext(CF); try { // We don't paginate this call. So we should make sure the number of reads is tolerable. // TODO: Think about paginating this call. OperationResult<Rows<Locator, Long>> query = keyspace.prepareQuery(CF).getKeySlice(locators) .withColumnRange(rangeBuilder.build()).execute(); for (Row<Locator, Long> row : query.getResult()) { columns.put(row.getKey(), row.getColumns()); } } catch (ConnectionException e) { if (e instanceof NotFoundException) { // TODO: Not really sure what happens when one of the keys is not found. Instrumentation.markNotFound(CF); } else { if (isBatch) { Instrumentation.markBatchReadError(e); } else { Instrumentation.markReadError(e); } } log.warn((isBatch ? "Batch " : "") + " read query failed for column family " + CF.getName(), e); } finally { ctx.stop(); } return columns; }