public MappedPageSource(ConnectorPageSource delegate, List<Integer> delegateFieldIndex) { this.delegate = requireNonNull(delegate, "delegate is null"); this.delegateFieldIndex = Ints.toArray(requireNonNull(delegateFieldIndex, "delegateFieldIndex is null")); }
/** * Specifies multiple quantile indexes to be calculated, each index being the k in the kth * q-quantile. * * @param indexes the quantile indexes, each of which must be in the inclusive range [0, q] for * q-quantiles; the order of the indexes is unimportant, duplicates will be ignored, and the * set will be snapshotted when this method is called */ public ScaleAndIndexes indexes(Collection<Integer> indexes) { return new ScaleAndIndexes(scale, Ints.toArray(indexes)); } }
/** Returns an immutable array containing the given values, in order. */ public static ImmutableIntArray copyOf(Collection<Integer> values) { return values.isEmpty() ? EMPTY : new ImmutableIntArray(Ints.toArray(values)); }
private DistinctingAccumulator( Accumulator accumulator, List<Type> inputTypes, List<Integer> inputs, Optional<Integer> maskChannel, Session session, JoinCompiler joinCompiler) { this.accumulator = requireNonNull(accumulator, "accumulator is null"); this.maskChannel = requireNonNull(maskChannel, "maskChannel is null"); hash = new MarkDistinctHash(session, inputTypes, Ints.toArray(inputs), Optional.empty(), joinCompiler, UpdateMemory.NOOP); }
/** * Specifies multiple quantile indexes to be calculated, each index being the k in the kth * q-quantile. * * @param indexes the quantile indexes, each of which must be in the inclusive range [0, q] for * q-quantiles; the order of the indexes is unimportant, duplicates will be ignored, and the * set will be snapshotted when this method is called */ public ScaleAndIndexes indexes(Collection<Integer> indexes) { return new ScaleAndIndexes(scale, Ints.toArray(indexes)); } }
/** Returns an immutable array containing the given values, in order. */ public static ImmutableIntArray copyOf(Collection<Integer> values) { return values.isEmpty() ? EMPTY : new ImmutableIntArray(Ints.toArray(values)); }
public MappedRecordSet(RecordSet delegate, List<Integer> delegateFieldIndex) { this.delegate = requireNonNull(delegate, "delegate is null"); this.delegateFieldIndex = Ints.toArray(requireNonNull(delegateFieldIndex, "delegateFieldIndex is null")); List<Type> types = delegate.getColumnTypes(); this.columnTypes = delegateFieldIndex.stream().map(types::get).collect(toImmutableList()); }
public MarkDistinctOperator(OperatorContext operatorContext, List<Type> types, List<Integer> markDistinctChannels, Optional<Integer> hashChannel, JoinCompiler joinCompiler) { this.operatorContext = requireNonNull(operatorContext, "operatorContext is null"); requireNonNull(hashChannel, "hashChannel is null"); requireNonNull(markDistinctChannels, "markDistinctChannels is null"); ImmutableList.Builder<Type> distinctTypes = ImmutableList.builder(); for (int channel : markDistinctChannels) { distinctTypes.add(types.get(channel)); } this.markDistinctHash = new MarkDistinctHash(operatorContext.getSession(), distinctTypes.build(), Ints.toArray(markDistinctChannels), hashChannel, joinCompiler, this::updateMemoryReservation); this.localUserMemoryContext = operatorContext.localUserMemoryContext(); }
public void testToArray_withNull() { List<Integer> list = Arrays.asList((int) 0, (int) 1, null); try { Ints.toArray(list); fail(); } catch (NullPointerException expected) { } }
public void testToArray() { // need explicit type parameter to avoid javac warning!? List<Integer> none = Arrays.<Integer>asList(); assertTrue(Arrays.equals(EMPTY, Ints.toArray(none))); List<Integer> one = Arrays.asList((int) 1); assertTrue(Arrays.equals(ARRAY1, Ints.toArray(one))); int[] array = {(int) 0, (int) 1, (int) 0xdeadbeef}; List<Integer> three = Arrays.asList((int) 0, (int) 1, (int) 0xdeadbeef); assertTrue(Arrays.equals(array, Ints.toArray(three))); assertTrue(Arrays.equals(array, Ints.toArray(Ints.asList(array)))); }
public void testToArray_withConversion() { int[] array = {0, 1, 2}; List<Byte> bytes = Arrays.asList((byte) 0, (byte) 1, (byte) 2); List<Short> shorts = Arrays.asList((short) 0, (short) 1, (short) 2); List<Integer> ints = Arrays.asList(0, 1, 2); List<Float> floats = Arrays.asList((float) 0, (float) 1, (float) 2); List<Long> longs = Arrays.asList((long) 0, (long) 1, (long) 2); List<Double> doubles = Arrays.asList((double) 0, (double) 1, (double) 2); assertTrue(Arrays.equals(array, Ints.toArray(bytes))); assertTrue(Arrays.equals(array, Ints.toArray(shorts))); assertTrue(Arrays.equals(array, Ints.toArray(ints))); assertTrue(Arrays.equals(array, Ints.toArray(floats))); assertTrue(Arrays.equals(array, Ints.toArray(longs))); assertTrue(Arrays.equals(array, Ints.toArray(doubles))); }
public void testAsList_subList_toArray_roundTrip() { int[] array = {(int) 0, (int) 1, (int) 2, (int) 3}; List<Integer> list = Ints.asList(array); assertTrue(Arrays.equals(new int[] {(int) 1, (int) 2}, Ints.toArray(list.subList(1, 3)))); assertTrue(Arrays.equals(new int[] {}, Ints.toArray(list.subList(2, 2)))); }
public void testAsList_toArray_roundTrip() { int[] array = {(int) 0, (int) 1, (int) 2}; List<Integer> list = Ints.asList(array); int[] newArray = Ints.toArray(list); // Make sure it returned a copy list.set(0, (int) 4); assertTrue(Arrays.equals(new int[] {(int) 0, (int) 1, (int) 2}, newArray)); newArray[1] = (int) 5; assertEquals((int) 1, (int) list.get(1)); }
public void testPercentiles_indexes_varargsAll_compute_doubleCollection() { ArrayList<Integer> indexes = new ArrayList<>(); ImmutableMap.Builder<Integer, Double> expectedBuilder = ImmutableMap.builder(); for (int index = 0; index <= 100; index++) { indexes.add(index); expectedBuilder.put(index, expectedLargeDatasetPercentile(index)); } Random random = new Random(770683168895677741L); Collections.shuffle(indexes, random); assertThat(percentiles().indexes(Ints.toArray(indexes)).compute(PSEUDORANDOM_DATASET)) .comparingValuesUsing(QUANTILE_CORRESPONDENCE) .containsExactlyEntriesIn(expectedBuilder.build()); }
public void testToArray_threadSafe() { for (int delta : new int[] {+1, 0, -1}) { for (int i = 0; i < VALUES.length; i++) { List<Integer> list = Ints.asList(VALUES).subList(0, i); Collection<Integer> misleadingSize = Helpers.misleadingSizeCollection(delta); misleadingSize.addAll(list); int[] arr = Ints.toArray(misleadingSize); assertEquals(i, arr.length); for (int j = 0; j < i; j++) { assertEquals(VALUES[j], arr[j]); } } } }
private int[] toArray(PagingOffset offset) { List<Integer> ints = new ArrayList<>(); for (; offset.hasNext(); offset.next()) { ints.add(offset.current()); } return Ints.toArray(ints); } }
@AndroidIncompatible // slow public void testPercentiles_indexes_varargsAll_computeInPlace() { double[] dataset = Doubles.toArray(PSEUDORANDOM_DATASET); List<Integer> indexes = new ArrayList<>(); ImmutableMap.Builder<Integer, Double> expectedBuilder = ImmutableMap.builder(); for (int index = 0; index <= 100; index++) { indexes.add(index); expectedBuilder.put(index, expectedLargeDatasetPercentile(index)); } Random random = new Random(770683168895677741L); Collections.shuffle(indexes, random); assertThat(percentiles().indexes(Ints.toArray(indexes)).computeInPlace(dataset)) .comparingValuesUsing(QUANTILE_CORRESPONDENCE) .containsExactlyEntriesIn(expectedBuilder.build()); assertThat(dataset).usingExactEquality().containsExactlyElementsIn(PSEUDORANDOM_DATASET); }
public void testScale_indexes_varargs_compute_intVarargs() { int[] dataset = Ints.toArray(SIXTEEN_SQUARES_INTEGERS); assertThat(Quantiles.scale(10).indexes(0, 10, 5, 1, 8, 1).compute(dataset)) .comparingValuesUsing(QUANTILE_CORRESPONDENCE) .containsExactly( 0, SIXTEEN_SQUARES_MIN, 10, SIXTEEN_SQUARES_MAX, 5, SIXTEEN_SQUARES_MEDIAN, 1, SIXTEEN_SQUARES_DECILE_1, 8, SIXTEEN_SQUARES_DECILE_8); assertThat(dataset).asList().isEqualTo(SIXTEEN_SQUARES_INTEGERS); }
public void testScale_index_compute_intVarargs() { int[] dataset = Ints.toArray(SIXTEEN_SQUARES_INTEGERS); assertThat(Quantiles.scale(10).index(1).compute(dataset)) .isWithin(ALLOWED_ERROR) .of(SIXTEEN_SQUARES_DECILE_1); assertThat(dataset).asList().isEqualTo(SIXTEEN_SQUARES_INTEGERS); }
private static GroupByHash createGroupByHash(List<Type> partitionTypes, List<Integer> partitionChannels, UpdateMemory updateMemory) { return GroupByHash.createGroupByHash( partitionTypes, Ints.toArray(partitionChannels), Optional.empty(), 1, false, new JoinCompiler(createTestMetadataManager(), new FeaturesConfig()), updateMemory); }