Java Code Examples for com.google.common.collect.ContiguousSet#create()
The following examples show how to use
com.google.common.collect.ContiguousSet#create() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GenerateOddNumbers.java From levelup-java-examples with Apache License 2.0 | 6 votes |
@Test public void generate_odd_numbers_in_range_guava() { Set<Integer> set = ContiguousSet.create(Range.closed(1, 10), DiscreteDomain.integers()); Iterable<Integer> oddNumbers = Iterables.filter(set, new Predicate<Integer>() { @Override public boolean apply(Integer input) { return input % 2 != 0; } }); logger.info(oddNumbers); assertThat( oddNumbers, contains(new Integer(1), new Integer(3), new Integer(5), new Integer(7), new Integer(9))); }
Example 2
Source File: AggregationTest.java From elasticsearch-sql with Apache License 2.0 | 6 votes |
@Test public void multipleGroupBysWithSize() throws Exception { Set expectedAges = new HashSet<Integer>(ContiguousSet.create(Range.closed(20, 40), DiscreteDomain.integers())); Map<String, Set<Integer>> buckets = new HashMap<>(); Aggregations result = query(String.format("SELECT COUNT(*) FROM %s/account GROUP BY gender, terms('alias'='ageAgg','field'='age','size'=3)", TEST_INDEX_ACCOUNT)); Terms gender = result.get("gender"); Assert.assertEquals(2,gender.getBuckets().size()); for(Terms.Bucket genderBucket : gender.getBuckets()) { String genderKey = genderBucket.getKey().toString(); buckets.put(genderKey, new HashSet<Integer>()); Terms ageBuckets = genderBucket.getAggregations().get("ageAgg"); Assert.assertEquals(3,ageBuckets.getBuckets().size()); } }
Example 3
Source File: GenerateEvenNumbers.java From levelup-java-examples with Apache License 2.0 | 6 votes |
@Test public void generate_even_numbers_in_range_guava() { Set<Integer> set = ContiguousSet.create(Range.closed(1, 10), DiscreteDomain.integers()); Iterable<Integer> evenNumbers = Iterables.filter(set, new Predicate<Integer>() { @Override public boolean apply(Integer input) { return input % 2 == 0; } }); assertThat( evenNumbers, contains(new Integer(2), new Integer(4), new Integer(6), new Integer(8), new Integer(10))); }
Example 4
Source File: UnboundableCQLStatementIterator.java From Rhombus with MIT License | 5 votes |
public UnboundableCQLStatementIterator(Range<Long> shardKeyList, long limit, CObjectOrdering ordering, CQLStatement CQLTemplate, String objectName){ this.keyRange = shardKeyList; ContiguousSet<Long> set = ContiguousSet.create(shardKeyList, DiscreteDomain.longs()); this.keyIterator = (ordering == CObjectOrdering.ASCENDING) ? set.iterator() : set.descendingIterator(); this.ordering = ordering; this.size = (long)set.size(); this.limit = limit; this.numberRemaining = this.limit; this.CQLTemplate = CQLTemplate; this.setObjectName(objectName); }
Example 5
Source File: PreferredAlbumsTableFactory.java From calcite with Apache License 2.0 | 5 votes |
private Queryable<Integer> fetchPreferredAlbums() { if (EnvironmentFairy.getUser() == EnvironmentFairy.User.SPECIFIC_USER) { return Linq4j.asEnumerable(SPECIFIC_USER_PREFERRED_ALBUMS).asQueryable(); } else { final ContiguousSet<Integer> set = ContiguousSet.create(Range.closed(FIRST_ID, LAST_ID), DiscreteDomain.integers()); return Linq4j.asEnumerable(set).asQueryable(); } }
Example 6
Source File: PreferredGenresTableFactory.java From calcite with Apache License 2.0 | 5 votes |
private Queryable<Integer> fetchPreferredGenres() { if (EnvironmentFairy.getUser() == EnvironmentFairy.User.SPECIFIC_USER) { return Linq4j.asEnumerable(SPECIFIC_USER_PREFERRED_GENRES).asQueryable(); } else { final ContiguousSet<Integer> set = ContiguousSet.create(Range.closed(FIRST_ID, LAST_ID), DiscreteDomain.integers()); return Linq4j.asEnumerable(set).asQueryable(); } }
Example 7
Source File: AggregationTest.java From elasticsearch-sql with Apache License 2.0 | 5 votes |
@Test public void testSubAggregations() throws Exception { Set expectedAges = new HashSet<>(ContiguousSet.create(Range.closed(20, 40), DiscreteDomain.integers())); final String query = String.format("SELECT /*! DOCS_WITH_AGGREGATION(10) */" + " * FROM %s/account GROUP BY (gender, terms('field'='age','size'=200,'alias'='age')), (state) LIMIT 200,200", TEST_INDEX_ACCOUNT); Map<String, Set<Integer>> buckets = new HashMap<>(); SqlElasticSearchRequestBuilder select = getSearchRequestBuilder(query); SearchResponse response = (SearchResponse) select.get(); Aggregations result = response.getAggregations(); Terms gender = result.get("gender"); for(Terms.Bucket genderBucket : gender.getBuckets()) { String genderKey = genderBucket.getKey().toString(); buckets.put(genderKey, new HashSet<Integer>()); Terms ageBuckets = (Terms) genderBucket.getAggregations().get("age"); for(Terms.Bucket ageBucket : ageBuckets.getBuckets()) { buckets.get(genderKey).add(Integer.parseInt(ageBucket.getKey().toString())); } } Assert.assertEquals(2, buckets.keySet().size()); Assert.assertEquals(expectedAges, buckets.get("m")); Assert.assertEquals(expectedAges, buckets.get("f")); Terms state = result.get("state"); for(Terms.Bucket stateBucket : state.getBuckets()) { if(stateBucket.getKey().toString().equalsIgnoreCase("ak")) { Assert.assertTrue("There are 22 entries for state ak", stateBucket.getDocCount() == 22); } } Assert.assertEquals(response.getHits().getTotalHits().value, 1000); Assert.assertEquals(response.getHits().getHits().length, 10); }
Example 8
Source File: HeatmapRenderer.java From JuiceboxLegacy with MIT License | 5 votes |
private void updatePreDefColors() { int arrSize = MainViewPanel.preDefMapColorGradient.size(); ImmutableSortedSet<Integer> set = ContiguousSet.create(Range.closed(0, arrSize), DiscreteDomain.integers()); Integer[] arrTmp = set.toArray(new Integer[arrSize]); final int[] arrScores = new int[arrSize]; for (int idx = 0; idx < arrSize; idx++) { arrScores[idx] = arrTmp[idx]; } preDefColorScale.updateColors(MainViewPanel.preDefMapColorGradient.toArray(new Color[arrSize]), arrScores); }
Example 9
Source File: CrontabEntry.java From attic-aurora with Apache License 2.0 | 5 votes |
private String fieldToString(RangeSet<Integer> rangeSet, Range<Integer> coveringRange) { if (rangeSet.asRanges().size() == 1 && rangeSet.encloses(coveringRange)) { return "*"; } List<String> components = Lists.newArrayList(); for (Range<Integer> range : rangeSet.asRanges()) { ContiguousSet<Integer> set = ContiguousSet.create(range, DiscreteDomain.integers()); if (set.size() == 1) { components.add(set.first().toString()); } else { components.add(set.first() + "-" + set.last()); } } return String.join(",", components); }
Example 10
Source File: SetFactoryTest.java From dagger2-sample with Apache License 2.0 | 5 votes |
private static Provider<Set<Integer>> integerSetProvider(Range<Integer> range) { final ContiguousSet<Integer> set = ContiguousSet.create(range, integers()); return new Provider<Set<Integer>>() { @Override public Set<Integer> get() { return set; } }; }
Example 11
Source File: PortManager.java From android-test with Apache License 2.0 | 5 votes |
/** For testing, control all the dependencies of the PortManager. */ @VisibleForTesting PortManager( Range<Integer> portRange, Collection<PortChecker> checkers, Random random, PortChecker clientConnectChecker) { this.random = checkNotNull(random); this.portSet = ContiguousSet.create(checkNotNull(portRange), DiscreteDomain.integers()); this.checkers = ImmutableList.copyOf(checkNotNull(checkers)); this.clientConnectChecker = checkNotNull(clientConnectChecker); }
Example 12
Source File: PinLaterBackendBase.java From pinlater with Apache License 2.0 | 4 votes |
public Future<PinLaterScanJobsResponse> scanJobs(final PinLaterScanJobsRequest request) { // Validate continuation token. CONTINUATION_START is the only supported token right now. if (!request.getContinuation().equals(Constants.CONTINUATION_START)) { return Future.exception(new PinLaterException(ErrorCode.CONTINUATION_INVALID, "CONTINUATION_START is the only continuation token supported right now.")); } // If no priority is specified, search for jobs of all priorities. Range<Integer> priorityRange = request.isSetPriority() ? Range.closed((int) request.getPriority(), (int) request.getPriority()) : Range.closed(1, numPriorityLevels); final ContiguousSet<Integer> priorities = ContiguousSet.create(priorityRange, DiscreteDomain.integers()); // Execute scanJobs query on each shard in parallel. List<Future<List<PinLaterJobInfo>>> futures = Lists.newArrayListWithCapacity(getShards().size()); for (final String shardName : getShards()) { futures.add(futurePool.apply(new ExceptionalFunction0<List<PinLaterJobInfo>>() { @Override public List<PinLaterJobInfo> applyE() throws Throwable { return scanJobsFromShard( request.getQueueName(), shardName, priorities, request.getJobState(), request.isScanFutureJobs(), request.getContinuation(), request.getLimit(), request.getBodyRegexToMatch()); } })); } // Perform a merge, and then truncate at the requested limit. return Future.collect(futures).map( new Function<List<List<PinLaterJobInfo>>, PinLaterScanJobsResponse>() { @Override public PinLaterScanJobsResponse apply(List<List<PinLaterJobInfo>> shardLists) { // First grab all of the lists of job info and perform a merge on them. List<PinLaterJobInfo> mergedList = PinLaterBackendUtils.mergeIntoList( shardLists, PinLaterBackendUtils.JobInfoComparator.getInstance(), request.getLimit()); // If we were to support continuation we would need to create and set the token here. // Right now, we just leave it as the default: CONTINUATION_END. return new PinLaterScanJobsResponse(mergedList); } }); }
Example 13
Source File: CMSExtensions.java From fenixedu-cms with GNU Lesser General Public License v3.0 | 4 votes |
@Override public Object execute(Map<String, Object> args) { Range<Integer> range = Range.closedOpen((Integer) args.get("from"), (Integer) args.get("to")); return ContiguousSet.create(range, DiscreteDomain.integers()); }
Example 14
Source File: AbstractTestOrcReader.java From presto with Apache License 2.0 | 4 votes |
private static ContiguousSet<Integer> intsBetween(int lowerInclusive, int upperExclusive) { return ContiguousSet.create(Range.closedOpen(lowerInclusive, upperExclusive), DiscreteDomain.integers()); }
Example 15
Source File: FakeIdRange.java From Rhombus with MIT License | 4 votes |
private Iterator<IdInRange> getIterator(CObjectOrdering ordering, Range<Long> range) { ContiguousSet<Long> set = ContiguousSet.create(range, DiscreteDomain.longs()); Iterator<Long> rangeIterator = (ordering == CObjectOrdering.ASCENDING) ? set.iterator() : set.descendingIterator(); return new IdIterator(rangeIterator); }
Example 16
Source File: AbstractTestParquetReader.java From presto with Apache License 2.0 | 4 votes |
private static ContiguousSet<BigInteger> bigIntegersBetween(BigInteger lowerInclusive, BigInteger upperExclusive) { return ContiguousSet.create(Range.closedOpen(lowerInclusive, upperExclusive), DiscreteDomain.bigIntegers()); }
Example 17
Source File: AbstractTestParquetReader.java From presto with Apache License 2.0 | 4 votes |
private static ContiguousSet<Integer> intsBetween(int lowerInclusive, int upperExclusive) { return ContiguousSet.create(Range.closedOpen(lowerInclusive, upperExclusive), DiscreteDomain.integers()); }
Example 18
Source File: AbstractTestRcFileReader.java From presto with Apache License 2.0 | 4 votes |
private static ContiguousSet<Integer> intsBetween(int lowerInclusive, int upperExclusive) { return ContiguousSet.create(Range.openClosed(lowerInclusive, upperExclusive), DiscreteDomain.integers()); }
Example 19
Source File: AbstractTestRcFileReader.java From presto with Apache License 2.0 | 4 votes |
private static ContiguousSet<Long> longsBetween(long lowerInclusive, long upperExclusive) { return ContiguousSet.create(Range.openClosed(lowerInclusive, upperExclusive), DiscreteDomain.longs()); }
Example 20
Source File: GenerateRangeOfSequentialNumbers.java From levelup-java-examples with Apache License 2.0 | 3 votes |
@Test public void range_sequential_numbers_guava() { Range<Integer> range = Range.closed(20, 30); Set<Integer> ranges = ContiguousSet.create(range, DiscreteDomain.integers()); logger.info(ranges); assertTrue(ranges.size() == 11); }