本文整理匯總了Java中com.google.common.collect.ContiguousSet類的典型用法代碼示例。如果您正苦於以下問題:Java ContiguousSet類的具體用法?Java ContiguousSet怎麽用?Java ContiguousSet使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
ContiguousSet類屬於com.google.common.collect包,在下文中一共展示了ContiguousSet類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: create
import com.google.common.collect.ContiguousSet; //導入依賴的package包/類
@Override
protected SortedSet<Integer> create(Integer[] elements) {
SortedSet<Integer> set = nullCheckedTreeSet(elements);
if (set.isEmpty()) {
/*
* The (tooLow + 1, tooHigh) arguments below would be invalid because tooLow would be
* greater than tooHigh.
*/
return ContiguousSet.create(Range.openClosed(0, 1), DiscreteDomain.integers()).subSet(0, 1);
}
int tooHigh = set.last() + 1;
int tooLow = set.first() - 1;
set.add(tooHigh);
set.add(tooLow);
return checkedCreate(set).subSet(tooLow + 1, tooHigh);
}
示例2: 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"));
}
示例3: 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());
}
}
示例4: load
import com.google.common.collect.ContiguousSet; //導入依賴的package包/類
public WorldGenSpikes.EndSpike[] load(Long p_load_1_) throws Exception
{
List<Integer> list = Lists.newArrayList(ContiguousSet.create(Range.closedOpen(Integer.valueOf(0), Integer.valueOf(10)), DiscreteDomain.integers()));
Collections.shuffle(list, new Random(p_load_1_.longValue()));
WorldGenSpikes.EndSpike[] aworldgenspikes$endspike = new WorldGenSpikes.EndSpike[10];
for (int i = 0; i < 10; ++i)
{
int j = (int)(42.0D * Math.cos(2.0D * (-Math.PI + (Math.PI / 10D) * (double)i)));
int k = (int)(42.0D * Math.sin(2.0D * (-Math.PI + (Math.PI / 10D) * (double)i)));
int l = ((Integer)list.get(i)).intValue();
int i1 = 2 + l / 3;
int j1 = 76 + l * 3;
boolean flag = l == 1 || l == 2;
aworldgenspikes$endspike[i] = new WorldGenSpikes.EndSpike(j, k, i1, j1, flag);
}
return aworldgenspikes$endspike;
}
示例5: 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;
}
示例6: 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);
}
示例7: 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));
}
}
}
示例8: 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()));
}
示例9: UniformCrossover
import com.google.common.collect.ContiguousSet; //導入依賴的package包/類
@VisibleForTesting
UniformCrossover(final RandomGenerator rng, final double p) {
this(new Function<Integer, Iterable<Integer>>() {
@Override
public Iterable<Integer> apply(final Integer bitStringLength) {
if (bitStringLength * p < 0.01) {
return Samplings.random(rng).withoutReplacement().sample(
ContiguousSet.create(Range.closedOpen(0, bitStringLength), DiscreteDomain.integers()),
new BinomialDistribution(rng, bitStringLength, p).sample()
);
} else {
return Iterables.filter(
ContiguousSet.create(Range.closedOpen(0, bitStringLength), DiscreteDomain.integers()),
new Predicate<Integer>() {
@Override
public boolean apply(@Nullable final Integer input) {
return p > rng.nextFloat();
}
});
}
}
});
}
示例10: 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"));
}
示例11: 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"));
}
示例12: 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());
}
}
示例13: 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)));
}
示例14: 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)));
}
示例15: a
import com.google.common.collect.ContiguousSet; //導入依賴的package包/類
public WorldGenEnder.Spike[] a(Long olong) throws Exception {
ArrayList arraylist = Lists.newArrayList(ContiguousSet.create(Range.closedOpen(Integer.valueOf(0), Integer.valueOf(10)), DiscreteDomain.integers()));
Collections.shuffle(arraylist, new Random(olong.longValue()));
WorldGenEnder.Spike[] aworldgenender_spike = new WorldGenEnder.Spike[10];
for (int i = 0; i < 10; ++i) {
int j = (int) (42.0D * Math.cos(2.0D * (-3.141592653589793D + 0.3141592653589793D * (double) i)));
int k = (int) (42.0D * Math.sin(2.0D * (-3.141592653589793D + 0.3141592653589793D * (double) i)));
int l = ((Integer) arraylist.get(i)).intValue();
int i1 = 2 + l / 3;
int j1 = 76 + l * 3;
boolean flag = l == 1 || l == 2;
aworldgenender_spike[i] = new WorldGenEnder.Spike(j, k, i1, j1, flag);
}
return aworldgenender_spike;
}