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

项目: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)));
}
项目:grappa    文件:RangeMatcherBuilder.java   
private static Range<Integer> normalizeRange(final Range<Integer> range)
{
    Range<Integer> newRange = AT_LEAST_ZERO.intersection(range);

    if (newRange.isEmpty())
        throw new IllegalArgumentException("illegal range " + range
            + ": intersection with " + AT_LEAST_ZERO + " is empty");

    newRange = newRange.canonical(DiscreteDomain.integers());

    final int lowerBound = newRange.lowerEndpoint();

    return newRange.hasUpperBound()
        ? Range.closed(lowerBound, newRange.upperEndpoint() - 1)
        : Range.atLeast(lowerBound);
}
项目:streamjit    文件:Storage.java   
/**
 * Returns a range spanning the indices written in this storage during an
 * execution of the given schedule. (Note that, as a span, not every
 * contained index will be written.) The returned range will be
 * {@link Range#canonical(com.google.common.collect.DiscreteDomain) canonical}.
 * The range is not cached so as to be responsive to changes in output index
 * functions.
 * @param externalSchedule the schedule
 * @return a range spanning the indices written during the given schedule
 * under the current index functions
 * @see #writeIndices(java.util.Map)
 */
public Range<Integer> writeIndexSpan(Map<ActorGroup, Integer> externalSchedule) {
    Range<Integer> range = null;
    for (Actor a : upstream()) {
        //just the first and last iteration
        int maxIteration = a.group().schedule().get(a) * externalSchedule.get(a.group())-1;
        if (maxIteration >= 0)
            for (int iteration : new int[]{0, maxIteration}) {
                ImmutableSortedSet<Integer> writes = a.writes(this, iteration);
                Range<Integer> writeRange = writes.isEmpty() ? range : Range.closed(writes.first(), writes.last());
                range = range == null ? writeRange : range.span(writeRange);
            }
    }
    range = (range != null ? range : Range.closedOpen(0, 0));
    return range.canonical(DiscreteDomain.integers());
}
项目: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;
      }
    } );
}
项目: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());
}
项目:javaide    文件:JavaInput.java   
public RangeSet<Integer> characterRangesToTokenRanges(Collection<Range<Integer>> characterRanges)
        throws FormatterException {
    RangeSet<Integer> tokenRangeSet = TreeRangeSet.create();
    for (Range<Integer> characterRange0 : characterRanges) {
        Range<Integer> characterRange = characterRange0.canonical(DiscreteDomain.integers());
        tokenRangeSet.add(
                characterRangeToTokenRange(
                        characterRange.lowerEndpoint(),
                        characterRange.upperEndpoint() - characterRange.lowerEndpoint()));
    }
    return tokenRangeSet;
}
项目: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);
}
项目:athena    文件:EncodedDiscreteResources.java   
static EncodedDiscreteResources of(Set<DiscreteResource> resources, DiscreteResourceCodec codec) {
    RangeSet<Integer> rangeSet = TreeRangeSet.create();
    resources.stream()
            .map(x -> x.valueAs(Object.class))
            .flatMap(Tools::stream)
            .map(x -> codec.encode(x))
            .map(Range::singleton)
            .map(x -> x.canonical(DiscreteDomain.integers()))
            .forEach(rangeSet::add);

    return new EncodedDiscreteResources(rangeSet, codec);
}
项目: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    文件:Numbers.java   
/**
 * Performs {@link #toRange(IRange)} for a collection of ranges, and convert the result to a set
 * of integers.
 *
 * @param ranges Ranges to convert.
 * @return A set representing {@code ranges}.
 */
public static Set<Integer> rangesToInstanceIds(Iterable<IRange> ranges) {
  ImmutableRangeSet.Builder<Integer> instanceIds = ImmutableRangeSet.builder();
  for (IRange range : ranges) {
    instanceIds.add(toRange(range));
  }

  return instanceIds.build().asSet(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);
}
项目:science-journal    文件:GraphPopulator.java   
private Range<Long> getEffectiveAddedRange(TimeRange requested, Range<Long> returned) {
    if (returned == null) {
        return requested.getTimes().canonical(DiscreteDomain.longs());
    }

    switch (requested.getOrder()) {
        case NEWEST_FIRST:
            return Range.closed(returned.lowerEndpoint(), requested.getTimes().upperEndpoint());
        case OLDEST_FIRST:
            return Range.closed(requested.getTimes().lowerEndpoint(), returned.upperEndpoint());
        default:
            throw new IllegalArgumentException(
                    "Unexpected value for enum: " + requested.getOrder());
    }
}