Java 类com.google.common.collect.ContiguousSet 实例源码

项目:guava-mock    文件:SetGenerators.java   
@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);
}
项目:es-sql    文件:AggregationTest.java   
@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"));
}
项目:es-sql    文件:AggregationTest.java   
@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());

    }


}
项目:googles-monorepo-demo    文件:SetGenerators.java   
@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);
}
项目:Backmemed    文件:BiomeEndDecorator.java   
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;
}
项目:CustomWorldGen    文件:BiomeEndDecorator.java   
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;
}
项目:fact-tools    文件:Utils.java   
/**
 * 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;
}
项目:aet    文件:RemoveLinesDataModifier.java   
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);
}
项目:owsi-core-parent    文件:AbstractExcelTableExport.java   
/**
 * 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));
        }
    }
}
项目:core-java    文件:StreamObserversShould.java   
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()));
}
项目:greyfish    文件:Recombinations.java   
@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();
                            }
                        });
            }
        }
    });
}
项目:es4sql    文件:AggregationTest.java   
@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"));
}
项目:guava    文件:SetGenerators.java   
@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);
}
项目:guava    文件:SetGenerators.java   
@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);
}
项目:elasticsearch-sql    文件:AggregationTest.java   
@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"));
}
项目:elasticsearch-sql    文件:AggregationTest.java   
@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());

    }


}
项目:java-util-examples    文件:GenerateOddNumbers.java   
@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)));
}
项目:java-util-examples    文件:GenerateEvenNumbers.java   
@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)));
}
项目:SpigotSource    文件:BiomeTheEndDecorator.java   
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;
}
项目:MFIBlocking    文件:MathUtilsTest.java   
@Test
public void testNormilize() throws Exception {
    int[] rangeNumbersPrimitive = Ints.toArray(ContiguousSet.create(Range.closed(1, 10), DiscreteDomain.integers()));
    HashMap<Integer, Float> idToValue = new HashMap<>();
    for (int index = 0; index < rangeNumbersPrimitive.length; index++) {
        idToValue.put(index, (float) rangeNumbersPrimitive[index]);
    }
    HashMap<Integer, Float> copyMap = new HashMap<>(idToValue);
    MathUtils.normilize(idToValue);

    //assert range
    for (Float normValue : idToValue.values()) {
        assertThat((double) normValue, allOf(lessThanOrEqualTo(1.0), greaterThanOrEqualTo(0.0)));
    }
    //assert values
    for (Map.Entry<Integer, Float> entry : idToValue.entrySet()) {
        Integer key = entry.getKey();
        assertThat((double) entry.getValue(), closeTo((copyMap.get(key) - 1.0) / (9), 0.0001));
    }
}
项目:levelup-java-examples    文件:GenerateOddNumbers.java   
@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)));
}
项目:levelup-java-examples    文件:GenerateEvenNumbers.java   
@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)));
}
项目:sdf    文件:CharacterClassRangeSet.java   
private final BitSet convertToBitSet(final RangeSet<Integer> rangeSet) {
    if(rangeSet.isEmpty()) {
        return new BitSet();
    }

    final BitSet bitSet = new BitSet(rangeSet.span().upperEndpoint());

    rangeSet.asRanges().forEach(range -> {
        if(!range.canonical(DiscreteDomain.integers()).isEmpty()) {
            Range<Integer> closedRange = ContiguousSet.create(range, DiscreteDomain.integers()).range();
            bitSet.set(closedRange.lowerEndpoint(), closedRange.upperEndpoint() + 1);
        }
    });

    return bitSet;
}
项目:sdf    文件:CharacterClassRangeSet.java   
@Override public String toString() {
    final List<String> ranges = new ArrayList<>();

    rangeSet.asRanges().forEach(range -> {
        if(!range.isEmpty()) {
            Range<Integer> closedRange = ContiguousSet.create(range, DiscreteDomain.integers()).range();
            final int from = closedRange.lowerEndpoint();
            final int to = closedRange.upperEndpoint();

            if(from != to)
                ranges.add("" + from + "-" + to);
            else
                ranges.add("" + from);
        }
    });

    if(containsEOF)
        ranges.add("EOF");

    return "[" + String.join(",", ranges) + "]";
}
项目:RoaringBitmap    文件:TestRoaringBitmap.java   
@Test
public void testFirstLast_AfterLazyMutation2() {
  RoaringBitmap rb = new RoaringBitmap();
  Iterable<Integer> willForceUseOfBitmapContainer = Iterables.filter(
          ContiguousSet.create(Range.openClosed(0, 1 << 16), DiscreteDomain.integers()),
          new Predicate<Integer>() {
            @Override
            public boolean apply(Integer input) {
              return input % 3 == 0;
            }
          }
          );
  int max = 0;
  for(Integer i : willForceUseOfBitmapContainer) {
    rb.add(i);
    max = i;
  }
  Assert.assertEquals(3, rb.first());
  Assert.assertEquals(max, rb.last());
  RoaringBitmap mutator = new RoaringBitmap();
  mutator.add(0, 2, 4, 6, 8);
  rb.lazyor(mutator);
  Assert.assertEquals(0, rb.first());
  Assert.assertEquals(max, rb.last());
}
项目:pentaho-kettle    文件:MemoryGroupByAggregationTest.java   
private Iterable<Object[]> getRows() {
  if ( data.isEmpty() ) {
    return ImmutableSet.of();
  }

  Range<Integer> rows = Range.closed( 0, data.rowMap().lastKey() );

  return FluentIterable.from( ContiguousSet.create( rows, DiscreteDomain.integers() ) )
    .transform( Functions.forMap( data.rowMap(), ImmutableMap.<Integer, Optional<Object>>of() ) )
    .transform( new Function<Map<Integer, Optional<Object>>, Object[]>() {
      @Override public Object[] apply( Map<Integer, Optional<Object>> input ) {
        Object[] row = new Object[rowMeta.size()];
        for ( Map.Entry<Integer, Optional<Object>> entry : input.entrySet() ) {
          row[entry.getKey()] = entry.getValue().orNull();
        }
        return row;
      }
    } );
}
项目:BlackBananaCoin    文件:Foo.java   
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());     

}
项目:open-kilda    文件:ResourcePool.java   
/**
 * 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");
}
项目:guava-mock    文件:SetGenerators.java   
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());
}
项目:matplotlib4j    文件:NumpyUtils.java   
public static List<Double> arange(double start, double end, double step) {
    double scaledStart = start / step;
    double scaledEnd = end / step;
    double floorGap = scaledStart - (int) scaledStart;
    return ContiguousSet.create(Range.closed((int) scaledStart, (int) scaledEnd), DiscreteDomain.integers())
            .stream().map(x -> (x + floorGap) * step).collect(Collectors.toList());
}
项目:es-sql    文件:AggregationTest.java   
@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);
}
项目:googles-monorepo-demo    文件:SetGenerators.java   
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());
}
项目:Mastering-Mesos    文件:JobDiff.java   
/**
 * Creates a map of {@code instanceCount} copies of {@code config}.
 *
 * @param config Configuration to generate an instance mapping for.
 * @param instanceCount Number of instances to represent.
 * @return A map of instance IDs (from 0 to {@code instanceCount - 1}) to {@code config}.
 */
public static Map<Integer, ITaskConfig> asMap(ITaskConfig config, int instanceCount) {
  requireNonNull(config);

  Set<Integer> desiredInstances = ContiguousSet.create(
      Range.closedOpen(0, instanceCount),
      DiscreteDomain.integers());
  return ImmutableMap.copyOf(Maps.asMap(desiredInstances, Functions.constant(config)));
}
项目:Mastering-Mesos    文件:SanitizedConfiguration.java   
/**
 * Constructs a SanitizedConfiguration object and populates the set of instance IDs for
 * the provided {@link org.apache.aurora.scheduler.storage.entities.ITaskConfig}.
 *
 * @param sanitized A sanitized configuration.
 */
@VisibleForTesting
public SanitizedConfiguration(IJobConfiguration sanitized) {
  this.sanitized = sanitized;
  this.instanceIds = ContiguousSet.create(
      Range.closedOpen(0, sanitized.getInstanceCount()),
      DiscreteDomain.integers());
}
项目:Mastering-Mesos    文件:CrontabEntry.java   
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);
}
项目:grakn    文件:FibonacciQueueTest.java   
@Test
public void testIterator() {
    // insert lots of numbers in order
    final Set<Integer> values = ContiguousSet.create(closedOpen(0, 1000), integers());
    final FibonacciQueue<Integer> queue = FibonacciQueue.create();
    assertTrue(queue.addAll(values));
    assertEquals(values, ImmutableSet.copyOf(queue.iterator()));
    assertEquals(values, ImmutableSet.copyOf(queue));
}
项目:beam    文件:ReadUnboundTranslatorTest.java   
@Test
public void testReadBounded() throws Exception {
  ApexPipelineOptions options = PipelineOptionsFactory.create()
      .as(ApexPipelineOptions.class);
  EmbeddedCollector.RESULTS.clear();
  options.setApplicationName("ReadBounded");
  options.setRunner(ApexRunner.class);
  Pipeline p = Pipeline.create(options);

  Set<Long> expected = ContiguousSet.create(Range.closedOpen(0L, 10L), DiscreteDomain.longs());
  p.apply(GenerateSequence.from(0).to(10))
      .apply(ParDo.of(new EmbeddedCollector()));

  ApexRunnerResult result = (ApexRunnerResult) p.run();
  DAG dag = result.getApexDAG();
  String operatorName = "GenerateSequence/Read(BoundedCountingSource)";
  DAG.OperatorMeta om = dag.getOperatorMeta(operatorName);
  Assert.assertNotNull(om);
  Assert.assertEquals(om.getOperator().getClass(), ApexReadUnboundedInputOperator.class);

  long timeout = System.currentTimeMillis() + 30000;
  while (System.currentTimeMillis() < timeout) {
    if (EmbeddedCollector.RESULTS.containsAll(expected)) {
      break;
    }
    LOG.info("Waiting for expected results.");
    Thread.sleep(1000);
  }
  Assert.assertEquals(Sets.newHashSet(expected), EmbeddedCollector.RESULTS);
}
项目:beam    文件:UnboundedReadEvaluatorFactoryTest.java   
@Test
public void generatesInitialSplits() throws Exception {
  when(context.createRootBundle()).thenAnswer(new Answer<UncommittedBundle<?>>() {
    @Override
    public UncommittedBundle<?> answer(InvocationOnMock invocation) throws Throwable {
      return bundleFactory.createRootBundle();
    }
  });

  int numSplits = 5;
  Collection<CommittedBundle<?>> initialInputs =
      new UnboundedReadEvaluatorFactory.InputProvider(context)
          .getInitialInputs(graph.getProducer(longs), numSplits);
  // CountingSource.unbounded has very good splitting behavior
  assertThat(initialInputs, hasSize(numSplits));

  int readPerSplit = 100;
  int totalSize = numSplits * readPerSplit;
  Set<Long> expectedOutputs =
      ContiguousSet.create(Range.closedOpen(0L, (long) totalSize), DiscreteDomain.longs());

  Collection<Long> readItems = new ArrayList<>(totalSize);
  for (CommittedBundle<?> initialInput : initialInputs) {
    CommittedBundle<UnboundedSourceShard<Long, ?>> shardBundle =
        (CommittedBundle<UnboundedSourceShard<Long, ?>>) initialInput;
    WindowedValue<UnboundedSourceShard<Long, ?>> shard =
        Iterables.getOnlyElement(shardBundle.getElements());
    assertThat(shard.getTimestamp(), equalTo(BoundedWindow.TIMESTAMP_MIN_VALUE));
    assertThat(shard.getWindows(), Matchers.<BoundedWindow>contains(GlobalWindow.INSTANCE));
    UnboundedSource<Long, ?> shardSource = shard.getValue().getSource();
    readItems.addAll(
        SourceTestUtils.readNItemsFromUnstartedReader(
            shardSource.createReader(
                PipelineOptionsFactory.create(), null /* No starting checkpoint */),
            readPerSplit));
  }
  assertThat(readItems, containsInAnyOrder(expectedOutputs.toArray(new Long[0])));
}
项目:beam    文件:UnboundedReadEvaluatorFactoryTest.java   
@Test
public void evaluatorThrowsInCloseRethrows() throws Exception {
  ContiguousSet<Long> elems = ContiguousSet.create(Range.closed(0L, 20L), DiscreteDomain.longs());
  TestUnboundedSource<Long> source =
      new TestUnboundedSource<>(BigEndianLongCoder.of(), elems.toArray(new Long[0]))
          .throwsOnClose();

  PCollection<Long> pcollection = p.apply(Read.from(source));
  AppliedPTransform<?, ?, ?> sourceTransform =
      DirectGraphs.getGraph(p).getProducer(pcollection);

  when(context.createRootBundle()).thenReturn(bundleFactory.createRootBundle());
  UncommittedBundle<Long> output = bundleFactory.createBundle(pcollection);
  when(context.createBundle(pcollection)).thenReturn(output);

  WindowedValue<UnboundedSourceShard<Long, TestCheckpointMark>> shard =
      WindowedValue.valueInGlobalWindow(
          UnboundedSourceShard.unstarted(source, NeverDeduplicator.create()));
  CommittedBundle<UnboundedSourceShard<Long, TestCheckpointMark>> inputBundle =
      bundleFactory
          .<UnboundedSourceShard<Long, TestCheckpointMark>>createRootBundle()
          .add(shard)
          .commit(Instant.now());
  UnboundedReadEvaluatorFactory factory =
      new UnboundedReadEvaluatorFactory(context, 0.0 /* never reuse */);
  TransformEvaluator<UnboundedSourceShard<Long, TestCheckpointMark>> evaluator =
      factory.forApplication(sourceTransform, inputBundle);
  thrown.expect(IOException.class);
  thrown.expectMessage("throws on close");
  evaluator.processElement(shard);
}
项目:nomulus    文件:TimeOfYear.java   
/**
 * Returns an {@link Iterable} of {@link DateTime}s of every recurrence of this particular
 * time of year within a given {@link Range} (usually one spanning many years).
 *
 * <p>WARNING: This can return a potentially very large {@link Iterable} if {@code END_OF_TIME}
 * is used as the upper endpoint of the range.
 */
public Iterable<DateTime> getInstancesInRange(Range<DateTime> range) {
  // In registry world, all dates are within START_OF_TIME and END_OF_TIME, so restrict any
  // ranges without bounds to our notion of zero-to-infinity.
  Range<DateTime> normalizedRange = range.intersection(Range.closed(START_OF_TIME, END_OF_TIME));
  Range<Integer> yearRange = Range.closed(
      normalizedRange.lowerEndpoint().getYear(),
      normalizedRange.upperEndpoint().getYear());
  return ContiguousSet.create(yearRange, integers())
      .stream()
      .map(this::getDateTimeWithYear)
      .filter(normalizedRange)
      .collect(toImmutableList());
}