本文整理匯總了Java中com.google.common.collect.ContiguousSet.create方法的典型用法代碼示例。如果您正苦於以下問題:Java ContiguousSet.create方法的具體用法?Java ContiguousSet.create怎麽用?Java ContiguousSet.create使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.google.common.collect.ContiguousSet
的用法示例。
在下文中一共展示了ContiguousSet.create方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: multipleGroupByTest
import com.google.common.collect.ContiguousSet; //導入方法依賴的package包/類
@Test
public void multipleGroupByTest() 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('field'='age','size'=200,'alias'='age')", TEST_INDEX));
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"));
}
示例2: multipleGroupBysWithSize
import com.google.common.collect.ContiguousSet; //導入方法依賴的package包/類
@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));
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());
}
}
示例3: getValidPixelSetAsIntArr
import com.google.common.collect.ContiguousSet; //導入方法依賴的package包/類
/**
* Return an int array with the ids of the pixelSet belonging to the given Key,
* return all camera pixel Ids if the set is not existing
*/
public static int[] getValidPixelSetAsIntArr(Data item, int npix, String pixelSetKey) {
int[] pixels;
//Load a given pixelset, otherwise use the the whole camera
if (pixelSetKey == null) {
ContiguousSet<Integer> numbers = ContiguousSet.create(Range.closed(0, npix - 1), DiscreteDomain.integers());
pixels = Ints.toArray(numbers);
} else {
Utils.isKeyValid(item, pixelSetKey, PixelSet.class);
PixelSet pixelSet = (PixelSet) item.get(pixelSetKey);
pixels = pixelSet.toIntArray();
}
return pixels;
}
示例4: modify
import com.google.common.collect.ContiguousSet; //導入方法依賴的package包/類
private String modify(String data, Set<Integer> indexesToRemove) {
List<String> lines = Arrays.asList(StringUtils.split(data, NEWLINE));
Set<Integer> dataIndexes = ContiguousSet.create(Range.closed(1, lines.size()),
DiscreteDomain.integers());
if (!dataIndexes.containsAll(indexesToRemove)) {
LOGGER.warn("Some of defined ranges exceed source lenght. Source length is: " + lines.size());
}
Set<Integer> filtereedIndexesToRemove = Sets.intersection(dataIndexes, indexesToRemove);
List<String> modifiedLines = new ArrayList<String>(
lines.size() - filtereedIndexesToRemove.size());
for (int i = 0; i < lines.size(); i++) {
if (!filtereedIndexesToRemove.contains(i + 1)) {
modifiedLines.add(lines.get(i));
}
}
return StringUtils.join(modifiedLines, NEWLINE);
}
示例5: addHeadersToSheet
import com.google.common.collect.ContiguousSet; //導入方法依賴的package包/類
/**
* Ajoute les en-têtes dans la feuille de calcul et cache les colonnes qui doivent l'être.
*
* @param sheet feuille de calcul
* @param rowIndex numéro de la ligne
* @param columnInfos RangeMap contenant les informations de colonnes (valeurs) et les index sur auxquelles s'appliquent ces colonnes (clés).
* Les "colonnes" s'étendant sur plus d'un index seront automatiquement fusionnées.
*/
protected void addHeadersToSheet(Sheet sheet, int rowIndex, RangeMap<Integer, ColumnInformation> columnInfos) {
Row rowHeader = sheet.createRow(rowIndex);
for (Map.Entry<Range<Integer>, ColumnInformation> entry : columnInfos.asMapOfRanges().entrySet()) {
Range<Integer> range = entry.getKey();
ColumnInformation columnInformation = entry.getValue();
addHeaderCell(rowHeader, range.lowerEndpoint(), getColumnLabel(columnInformation.getHeaderKey()));
for (Integer columnIndex : ContiguousSet.create(range, DiscreteDomain.integers())) {
sheet.setColumnHidden(columnIndex, columnInformation.isHidden());
}
int beginIndex = range.lowerEndpoint();
int endIndex = range.upperEndpoint();
if (beginIndex != endIndex) {
sheet.addMergedRegion(new CellRangeAddress(rowIndex, rowIndex, beginIndex, endIndex));
}
}
}
示例6: checkOnNext
import com.google.common.collect.ContiguousSet; //導入方法依賴的package包/類
private static void checkOnNext(MemoizingObserver<Object> observer) {
assertTrue(observer.responses().isEmpty());
final Object firstResponse = new Object();
observer.onNext(firstResponse);
assertEquals(firstResponse, observer.firstResponse());
final ContiguousSet<Integer> sorted = ContiguousSet.create(Range.closed(1, 20),
DiscreteDomain.integers());
final List<Integer> moreResponses = newArrayList(newHashSet(sorted));
for (Integer element : moreResponses) {
observer.onNext(element);
}
final List<Object> actualResponses = observer.responses();
assertEquals(firstResponse, actualResponses.get(0));
assertEquals(moreResponses.size() + 1, // as there was the first response
actualResponses.size());
assertEquals(moreResponses, actualResponses.subList(1, actualResponses.size()));
}
示例7: multipleGroupByTest
import com.google.common.collect.ContiguousSet; //導入方法依賴的package包/類
@Test
public void multipleGroupByTest() 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, age", TestsConstants.TEST_INDEX));
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"));
}
示例8: multipleGroupByTest
import com.google.common.collect.ContiguousSet; //導入方法依賴的package包/類
@Test
public void multipleGroupByTest() 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('field'='age','size'=200,'alias'='age')", TEST_INDEX_ACCOUNT));
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"));
}
示例9: multipleGroupBysWithSize
import com.google.common.collect.ContiguousSet; //導入方法依賴的package包/類
@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());
}
}
示例10: generate_odd_numbers_in_range_guava
import com.google.common.collect.ContiguousSet; //導入方法依賴的package包/類
@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)));
}
示例11: generate_even_numbers_in_range_guava
import com.google.common.collect.ContiguousSet; //導入方法依賴的package包/類
@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)));
}
示例12: main
import com.google.common.collect.ContiguousSet; //導入方法依賴的package包/類
public static void main(String[] args) {
// why isn't the maximum target 2^256 - 1
BigInteger unitTestTarget = BigInteger.valueOf (1).shiftLeft (256).subtract (BigInteger.ONE);
System.out.println(unitTestTarget);
System.out.println(unitTestTarget.toString(16));
BigInteger testnet3Target = BigInteger.valueOf (0xFFFFL).shiftLeft (8 * (0x1d - 3));
System.out.println(testnet3Target);
System.out.println(testnet3Target.toString(16));
ContiguousSet<Integer> set = ContiguousSet.create(Range.closed(Integer.MIN_VALUE, Integer.MAX_VALUE), integers());
System.out.println(new Date());
int count = 0;
for(Integer v : set){
count++;
}
System.out.println(new Date());
}
示例13: allocate
import com.google.common.collect.ContiguousSet; //導入方法依賴的package包/類
/**
* Allocates resource id.
*
* @return allocated resource id
*/
public Integer allocate() {
for (Integer id : ContiguousSet.create(range, DiscreteDomain.integers())) {
if (resources.add(id)) {
return id;
}
}
throw new ArrayIndexOutOfBoundsException("Could not allocate resource: pool is full");
}
示例14: checkedCreate
import com.google.common.collect.ContiguousSet; //導入方法依賴的package包/類
protected final ContiguousSet<Integer> checkedCreate(SortedSet<Integer> elementsSet) {
List<Integer> elements = newArrayList(elementsSet);
/*
* A ContiguousSet can't have holes. If a test demands a hole, it should be changed so that it
* doesn't need one, or it should be suppressed for ContiguousSet.
*/
for (int i = 0; i < elements.size() - 1; i++) {
assertEquals(elements.get(i) + 1, (int) elements.get(i + 1));
}
Range<Integer> range =
(elements.isEmpty()) ? Range.closedOpen(0, 0) : Range.encloseAll(elements);
return ContiguousSet.create(range, DiscreteDomain.integers());
}
示例15: testSubAggregations
import com.google.common.collect.ContiguousSet; //導入方法依賴的package包/類
@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);
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().totalHits(), 1000);
Assert.assertEquals(response.getHits().hits().length, 10);
}