Java Code Examples for com.google.common.primitives.Ints#asList()

The following examples show how to use com.google.common.primitives.Ints#asList() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BenchmarkArraySort.java    From presto with Apache License 2.0 6 votes vote down vote up
@ScalarFunction
@SqlType("array(varchar)")
public static Block oldArraySort(@SqlType("array(varchar)") Block block)
{
    List<Integer> positions = Ints.asList(new int[block.getPositionCount()]);
    for (int i = 0; i < block.getPositionCount(); i++) {
        positions.set(i, i);
    }

    positions.sort((p1, p2) -> {
        //TODO: This could be quite slow, it should use parametric equals
        return VARCHAR.compareTo(block, p1, block, p2);
    });

    BlockBuilder blockBuilder = VARCHAR.createBlockBuilder(null, block.getPositionCount());

    for (int position : positions) {
        VARCHAR.appendTo(block, position, blockBuilder);
    }

    return blockBuilder.build();
}
 
Example 2
Source File: TestSpatialJoinOperator.java    From presto with Apache License 2.0 6 votes vote down vote up
@Test
public void testDistributedSpatialSelfJoin()
{
    TaskContext taskContext = createTaskContext();
    DriverContext driverContext = taskContext.addPipelineContext(0, true, true, true).addDriverContext();

    RowPagesBuilder pages = rowPagesBuilder(ImmutableList.of(GEOMETRY, VARCHAR, INTEGER))
            .row(POLYGON_A, "A", 1)
            .row(POLYGON_A, "A", 2)
            .row(null, "null", null)
            .pageBreak()
            .row(POLYGON_B, "B", 0)
            .row(POLYGON_B, "B", 2);

    MaterializedResult expected = resultBuilder(taskContext.getSession(), ImmutableList.of(VARCHAR, VARCHAR))
            .row("A", "A")
            .row("A", "B")
            .row("B", "A")
            .row("B", "B")
            .build();

    PagesSpatialIndexFactory pagesSpatialIndexFactory = buildIndex(driverContext, (build, probe, r) -> build.intersects(probe), Optional.empty(), Optional.of(2), Optional.of(KDB_TREE_JSON), Optional.empty(), pages);
    OperatorFactory joinOperatorFactory = new SpatialJoinOperatorFactory(2, new PlanNodeId("test"), INNER, pages.getTypes(), Ints.asList(1), 0, Optional.of(2), pagesSpatialIndexFactory);
    assertOperatorEquals(joinOperatorFactory, driverContext, pages.build(), expected);
}
 
Example 3
Source File: ArraySortComparatorFunction.java    From presto with Apache License 2.0 5 votes vote down vote up
private void initPositionsList(int arrayLength)
{
    if (positions.size() < arrayLength) {
        positions = Ints.asList(new int[arrayLength]);
    }
    for (int i = 0; i < arrayLength; i++) {
        positions.set(i, i);
    }
}
 
Example 4
Source File: Dataset.java    From JuiceboxLegacy with MIT License 5 votes vote down vote up
public void setBpZooms(int[] bpBinSizes) {

        bpZoomResolutions = Ints.asList(bpBinSizes);

        bpZooms = new ArrayList<HiCZoom>(bpBinSizes.length);
        for (int bpBinSize : bpZoomResolutions) {
            bpZooms.add(new HiCZoom(HiC.Unit.BP, bpBinSize));
        }
    }
 
Example 5
Source File: TestIntIteratorFlyweight.java    From RoaringBitmap with Apache License 2.0 5 votes vote down vote up
private static List<Integer> asList(IntIterator ints) {
  int[] values = new int[10];
  int size = 0;
  while (ints.hasNext()) {
    if (!(size < values.length)) {
      values = Arrays.copyOf(values, values.length * 2);
    }
    values[size++] = ints.next();
  }
  return Ints.asList(Arrays.copyOf(values, size));
}
 
Example 6
Source File: Collections2Example.java    From levelup-java-examples with Apache License 2.0 5 votes vote down vote up
@Test
public void permutations () {

	List<Integer> vals = Ints.asList(new int[] {1, 2, 3});
	
	Collection<List<Integer>> orderPerm = 
			Collections2.permutations(vals);
	
	for (List<Integer> val : orderPerm) {
		logger.info(val);
	}
	
	assertEquals(6, orderPerm.size());
}
 
Example 7
Source File: TestArrayContainer.java    From RoaringBitmap with Apache License 2.0 5 votes vote down vote up
private static List<Integer> asList(CharIterator ints) {
    int[] values = new int[10];
    int size = 0;
    while (ints.hasNext()) {
        if (!(size < values.length)) {
            values = Arrays.copyOf(values, values.length * 2);
        }
        values[size++] = ints.next();
    }
    return Ints.asList(Arrays.copyOf(values, size));
}
 
Example 8
Source File: DetailsPanel.java    From consulo with Apache License 2.0 5 votes vote down vote up
private void rebuildCommitPanels(int[] selection) {
  myEmptyText.setText("");

  int selectionLength = selection.length;

  // for each commit besides the first there are two components: Separator and CommitPanel
  int existingCount = (myMainContentPanel.getComponentCount() + 1) / 2;
  int requiredCount = Math.min(selectionLength, MAX_ROWS);
  for (int i = existingCount; i < requiredCount; i++) {
    if (i > 0) {
      myMainContentPanel.add(new SeparatorComponent(0, OnePixelDivider.BACKGROUND, null));
    }
    myMainContentPanel.add(new CommitPanel(myLogData, myColorManager));
  }

  // clear superfluous items
  while (myMainContentPanel.getComponentCount() > 2 * requiredCount - 1) {
    myMainContentPanel.remove(myMainContentPanel.getComponentCount() - 1);
  }

  if (selectionLength > MAX_ROWS) {
    myMainContentPanel.add(new SeparatorComponent(0, OnePixelDivider.BACKGROUND, null));
    JBLabel label = new JBLabel("(showing " + MAX_ROWS + " of " + selectionLength + " selected commits)");
    label.setFont(VcsHistoryUtil.getCommitDetailsFont());
    label.setBorder(CommitPanel.getDetailsBorder());
    myMainContentPanel.add(label);
  }

  mySelection = Ints.asList(Arrays.copyOf(selection, requiredCount));

  repaint();
}
 
Example 9
Source File: TestSpatialJoinOperator.java    From presto with Apache License 2.0 5 votes vote down vote up
@Test(dataProvider = "testDuplicateProbeFactoryDataProvider")
public void testDuplicateProbeFactory(boolean createSecondaryOperators)
        throws Exception
{
    TaskContext taskContext = createTaskContext();
    PipelineContext pipelineContext = taskContext.addPipelineContext(0, true, true, false);
    DriverContext probeDriver = pipelineContext.addDriverContext();
    DriverContext buildDriver = pipelineContext.addDriverContext();

    RowPagesBuilder buildPages = rowPagesBuilder(ImmutableList.of(GEOMETRY, VARCHAR, DOUBLE))
            .row(stPoint(0, 0), "0_0", 1.5);
    PagesSpatialIndexFactory pagesSpatialIndexFactory = buildIndex(buildDriver, (build, probe, r) -> build.distance(probe) <= r.getAsDouble(), Optional.of(2), Optional.empty(), buildPages);

    RowPagesBuilder probePages = rowPagesBuilder(ImmutableList.of(GEOMETRY, VARCHAR))
            .row(stPoint(0, 1), "0_1");
    OperatorFactory firstFactory = new SpatialJoinOperatorFactory(2, new PlanNodeId("test"), INNER, probePages.getTypes(), Ints.asList(1), 0, Optional.empty(), pagesSpatialIndexFactory);

    for (int i = 0; i < 3; i++) {
        DriverContext secondDriver = pipelineContext.addDriverContext();
        OperatorFactory secondFactory = firstFactory.duplicate();
        if (createSecondaryOperators) {
            try (Operator secondOperator = secondFactory.createOperator(secondDriver)) {
                assertEquals(toPages(secondOperator, emptyIterator()), ImmutableList.of());
            }
        }
        secondFactory.noMoreOperators();
    }

    MaterializedResult expected = resultBuilder(taskContext.getSession(), ImmutableList.of(VARCHAR, VARCHAR))
            .row("0_1", "0_0")
            .build();
    assertOperatorEquals(firstFactory, probeDriver, probePages.build(), expected);
}
 
Example 10
Source File: BenchmarkHashBuildAndJoinOperators.java    From presto with Apache License 2.0 5 votes vote down vote up
@Override
@Setup
public void setup()
{
    super.setup();

    switch (outputColumns) {
        case "varchar":
            outputChannels = Ints.asList(0);
            break;
        case "bigint":
            outputChannels = Ints.asList(1);
            break;
        case "all":
            outputChannels = Ints.asList(0, 1, 2);
            break;
        default:
            throw new UnsupportedOperationException(format("Unknown outputColumns value [%s]", hashColumns));
    }

    JoinBridgeManager<PartitionedLookupSourceFactory> lookupSourceFactory = getLookupSourceFactoryManager(this, outputChannels);
    joinOperatorFactory = LOOKUP_JOIN_OPERATORS.innerJoin(
            HASH_JOIN_OPERATOR_ID,
            TEST_PLAN_NODE_ID,
            lookupSourceFactory,
            types,
            hashChannels,
            hashChannel,
            Optional.of(outputChannels),
            OptionalInt.empty(),
            unsupportedPartitioningSpillerFactory());
    buildHash(this, lookupSourceFactory, outputChannels);
    initializeProbePages();
}
 
Example 11
Source File: SequentialMessageIDPoolImpl.java    From hivemq-community-edition with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 *
 * @throws IllegalArgumentException if one of the message id is not between 1 and 65535
 */
@ThreadSafe
@Override
public synchronized void prepopulateWithUnavailableIds(final int... ids) {

    for (final int id : ids) {
        checkArgument(id > 0);
        checkArgument(id <= 65535);
    }
    final List<Integer> idList = Ints.asList(ids);
    Collections.sort(idList);
    circularTicker.set(idList.get(idList.size() - 1));
    usedMessageIds.addAll(idList);
}
 
Example 12
Source File: ArraySortFunction.java    From presto with Apache License 2.0 4 votes vote down vote up
@TypeParameter("E")
@SqlType("array(E)")
public Block sort(
        @OperatorDependency(operator = LESS_THAN, argumentTypes = {"E", "E"}) MethodHandle lessThanFunction,
        @TypeParameter("E") Type type,
        @SqlType("array(E)") Block block)
{
    int arrayLength = block.getPositionCount();
    if (positions.size() < arrayLength) {
        positions = Ints.asList(new int[arrayLength]);
    }
    for (int i = 0; i < arrayLength; i++) {
        positions.set(i, i);
    }

    Collections.sort(positions.subList(0, arrayLength), new Comparator<Integer>()
    {
        @Override
        public int compare(Integer p1, Integer p2)
        {
            boolean nullLeft = block.isNull(p1);
            boolean nullRight = block.isNull(p2);
            if (nullLeft && nullRight) {
                return 0;
            }
            if (nullLeft) {
                return 1;
            }
            if (nullRight) {
                return -1;
            }

            //TODO: This could be quite slow, it should use parametric equals
            return type.compareTo(block, p1, block, p2);
        }
    });

    if (pageBuilder.isFull()) {
        pageBuilder.reset();
    }

    BlockBuilder blockBuilder = pageBuilder.getBlockBuilder(0);

    for (int i = 0; i < arrayLength; i++) {
        type.appendTo(block, positions.get(i), blockBuilder);
    }
    pageBuilder.declarePositions(arrayLength);

    return blockBuilder.getRegion(blockBuilder.getPositionCount() - arrayLength, arrayLength);
}
 
Example 13
Source File: CommitSelectionListener.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nonnull
protected List<Integer> getSelectionToLoad() {
  return Ints.asList(myGraphTable.getSelectedRows());
}
 
Example 14
Source File: TestRowNumberOperator.java    From presto with Apache License 2.0 4 votes vote down vote up
@Test
public void testRowNumberUnpartitioned()
{
    DriverContext driverContext = getDriverContext();
    List<Page> input = rowPagesBuilder(BIGINT, DOUBLE)
            .row(1L, 0.3)
            .row(2L, 0.2)
            .row(3L, 0.1)
            .row(3L, 0.19)
            .pageBreak()
            .row(1L, 0.4)
            .pageBreak()
            .row(1L, 0.5)
            .row(1L, 0.6)
            .row(2L, 0.7)
            .row(2L, 0.8)
            .row(2L, 0.9)
            .build();

    RowNumberOperator.RowNumberOperatorFactory operatorFactory = new RowNumberOperator.RowNumberOperatorFactory(
            0,
            new PlanNodeId("test"),
            ImmutableList.of(BIGINT, DOUBLE),
            Ints.asList(1, 0),
            Ints.asList(),
            ImmutableList.of(),
            Optional.empty(),
            Optional.empty(),
            10,
            joinCompiler);

    MaterializedResult expectedResult = resultBuilder(driverContext.getSession(), DOUBLE, BIGINT)
            .row(0.3, 1L)
            .row(0.4, 1L)
            .row(0.5, 1L)
            .row(0.6, 1L)
            .row(0.2, 2L)
            .row(0.7, 2L)
            .row(0.8, 2L)
            .row(0.9, 2L)
            .row(0.1, 3L)
            .row(0.19, 3L)
            .build();

    List<Page> pages = toPages(operatorFactory, driverContext, input);
    Block rowNumberColumn = getRowNumberColumn(pages);
    assertEquals(rowNumberColumn.getPositionCount(), 10);

    pages = stripRowNumberColumn(pages);
    MaterializedResult actual = toMaterializedResult(driverContext.getSession(), ImmutableList.of(DOUBLE, BIGINT), pages);
    assertEqualsIgnoreOrder(actual.getMaterializedRows(), expectedResult.getMaterializedRows());
}
 
Example 15
Source File: TestTopNRowNumberOperator.java    From presto with Apache License 2.0 4 votes vote down vote up
@Test(dataProvider = "partial")
public void testUnPartitioned(boolean partial)
{
    List<Page> input = rowPagesBuilder(BIGINT, DOUBLE)
            .row(1L, 0.3)
            .row(2L, 0.2)
            .row(3L, 0.1)
            .row(3L, 0.91)
            .pageBreak()
            .row(1L, 0.4)
            .pageBreak()
            .row(1L, 0.5)
            .row(1L, 0.6)
            .row(2L, 0.7)
            .row(2L, 0.8)
            .pageBreak()
            .row(2L, 0.9)
            .build();

    TopNRowNumberOperatorFactory operatorFactory = new TopNRowNumberOperatorFactory(
            0,
            new PlanNodeId("test"),
            ImmutableList.of(BIGINT, DOUBLE),
            Ints.asList(1, 0),
            Ints.asList(),
            ImmutableList.of(),
            Ints.asList(1),
            ImmutableList.of(SortOrder.ASC_NULLS_LAST),
            3,
            partial,
            Optional.empty(),
            10,
            joinCompiler);

    MaterializedResult expected;
    if (partial) {
        expected = resultBuilder(driverContext.getSession(), DOUBLE, BIGINT)
                .row(0.1, 3L)
                .row(0.2, 2L)
                .row(0.3, 1L)
                .build();
    }
    else {
        expected = resultBuilder(driverContext.getSession(), DOUBLE, BIGINT, BIGINT)
                .row(0.1, 3L, 1L)
                .row(0.2, 2L, 2L)
                .row(0.3, 1L, 3L)
                .build();
    }

    assertOperatorEquals(operatorFactory, driverContext, input, expected);
}
 
Example 16
Source File: WrapperPlayServerEntityDestroy.java    From PacketWrapper with GNU Lesser General Public License v3.0 2 votes vote down vote up
/**
 * Retrieve the IDs of the entities that will be destroyed.
 * @return The current entities.
*/
public List<Integer> getEntities() {
    return Ints.asList(handle.getIntegerArrays().read(0));
}
 
Example 17
Source File: ArrayUtil.java    From vjtools with Apache License 2.0 2 votes vote down vote up
/**
 * Arrays.asList()的加强版, 返回一个底层为原始类型int的List
 * 
 * 与保存Integer相比节约空间,同时只在读取数据时AutoBoxing.
 * 
 * @see java.util.Arrays#asList(Object...)
 * @see com.google.common.primitives.Ints#asList(int...)
 * 
 */
public static List<Integer> intAsList(int... backingArray) {
	return Ints.asList(backingArray);
}
 
Example 18
Source File: WrapperPlayServerEntityDestroy.java    From HolographicDisplays with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Retrieve the IDs of the entities that will be destroyed.
 * @return The current entities.
*/
public List<Integer> getEntities() {
    return Ints.asList(handle.getIntegerArrays().read(0));
}
 
Example 19
Source File: GamaIntMatrix.java    From gama with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Method iterator()
 *
 * @see msi.gama.util.matrix.GamaMatrix#iterator()
 */
@Override
public java.lang.Iterable<Integer> iterable(final IScope scope) {
	return Ints.asList(matrix);
}
 
Example 20
Source File: ArrayUtil.java    From j360-dubbo-app-all with Apache License 2.0 2 votes vote down vote up
/**
 * Arrays.asList()的加强版, 返回一个底层为原始类型int的List
 *
 * 与保存Integer相比节约空间,同时只在读取数据时AutoBoxing.
 *
 * @see Arrays#asList(Object...)
 * @see com.google.common.primitives.Ints#asList(int...)
 *
 */
public static List<Integer> intAsList(int... backingArray) {
	return Ints.asList(backingArray);
}