Java Code Examples for com.google.common.primitives.Longs#toArray()

The following examples show how to use com.google.common.primitives.Longs#toArray() . 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: GuidePostsInfo.java    From phoenix with Apache License 2.0 6 votes vote down vote up
/**
 * Constructor that creates GuidePostsInfo per region
 * 
 * @param byteCounts
 *            The bytecounts of each guidePost traversed
 * @param guidePosts
 *            Prefix byte encoded guidePosts
 * @param rowCounts
 *            The rowCounts of each guidePost traversed
 * @param maxLength
 *            Maximum length of a guidePost collected
 * @param guidePostsCount
 *            Number of guidePosts
 * @param gpTimestamps
 *            Times at which guidePosts were updated/created
 */
public GuidePostsInfo(List<Long> byteCounts, ImmutableBytesWritable guidePosts, List<Long> rowCounts, int maxLength,
        int guidePostsCount, List<Long> updateTimes) {
    this.guidePosts = new ImmutableBytesWritable(guidePosts);
    this.maxLength = maxLength;
    this.guidePostsCount = guidePostsCount;
    this.rowCounts = Longs.toArray(rowCounts);
    this.byteCounts = Longs.toArray(byteCounts);
    this.gpTimestamps = Longs.toArray(updateTimes);
    // Those Java equivalents of sizeof() in C/C++, mentioned on the Web, might be overkilled here.
    int estimatedSize = SizedUtil.OBJECT_SIZE
            + SizedUtil.IMMUTABLE_BYTES_WRITABLE_SIZE + guidePosts.getLength() // guidePosts
            + SizedUtil.INT_SIZE // maxLength
            + SizedUtil.INT_SIZE // guidePostsCount
            + SizedUtil.ARRAY_SIZE + this.rowCounts.length * SizedUtil.LONG_SIZE // rowCounts
            + SizedUtil.ARRAY_SIZE + this.byteCounts.length * SizedUtil.LONG_SIZE // byteCounts
            + SizedUtil.ARRAY_SIZE + this.gpTimestamps.length * SizedUtil.LONG_SIZE // gpTimestamps
            + SizedUtil.INT_SIZE; // estimatedSize
    this.estimatedSize = estimatedSize;
}
 
Example 2
Source File: CalciteMetaImpl.java    From Quicksql with MIT License 5 votes vote down vote up
@Override public ExecuteBatchResult executeBatch(StatementHandle h,
    List<List<TypedValue>> parameterValueLists) throws NoSuchStatementException {
  final List<Long> updateCounts = new ArrayList<>();
  for (List<TypedValue> parameterValueList : parameterValueLists) {
    ExecuteResult executeResult = execute(h, parameterValueList, -1);
    final long updateCount =
        executeResult.resultSets.size() == 1
            ? executeResult.resultSets.get(0).updateCount
            : -1L;
    updateCounts.add(updateCount);
  }
  return new ExecuteBatchResult(Longs.toArray(updateCounts));
}
 
Example 3
Source File: CalciteMetaImpl.java    From calcite with Apache License 2.0 5 votes vote down vote up
@Override public ExecuteBatchResult executeBatch(StatementHandle h,
    List<List<TypedValue>> parameterValueLists) throws NoSuchStatementException {
  final List<Long> updateCounts = new ArrayList<>();
  for (List<TypedValue> parameterValueList : parameterValueLists) {
    ExecuteResult executeResult = execute(h, parameterValueList, -1);
    final long updateCount =
        executeResult.resultSets.size() == 1
            ? executeResult.resultSets.get(0).updateCount
            : -1L;
    updateCounts.add(updateCount);
  }
  return new ExecuteBatchResult(Longs.toArray(updateCounts));
}
 
Example 4
Source File: RaftServiceManager.java    From atomix with Apache License 2.0 5 votes vote down vote up
/**
 * Applies a session keep alive entry to the state machine.
 * <p>
 * Keep alive entries are applied to the internal state machine to reset the timeout for a specific session. If the
 * session indicated by the KeepAliveEntry is still held in memory, we mark the session as trusted, indicating that
 * the client has committed a keep alive within the required timeout. Additionally, we check all other sessions for
 * expiration based on the timestamp provided by this KeepAliveEntry. Note that sessions are never completely expired
 * via this method. Leaders must explicitly commit an UnregisterEntry to expire a session.
 * <p>
 * When a KeepAliveEntry is committed to the internal state machine, two specific fields provided in the entry are
 * used to update server-side session state. The {@code commandSequence} indicates the highest command for which the
 * session has received a successful response in the proper sequence. By applying the {@code commandSequence} to the
 * server session, we clear command output held in memory up to that point. The {@code eventVersion} indicates the
 * index up to which the client has received event messages in sequence for the session. Applying the {@code
 * eventVersion} to the server-side session results in events up to that index being removed from memory as they were
 * acknowledged by the client. It's essential that both of these fields be applied via entries committed to the Raft
 * log to ensure they're applied on all servers in sequential order.
 * <p>
 * Keep alive entries are retained in the log until the next time the client sends a keep alive entry or until the
 * client's session is expired. This ensures for sessions that have long timeouts, keep alive entries cannot be
 * cleaned from the log before they're replicated to some servers.
 */
private long[] applyKeepAlive(Indexed<KeepAliveEntry> entry) {

  // Store the session/command/event sequence and event index instead of acquiring a reference to the entry.
  long[] sessionIds = entry.entry().sessionIds();
  long[] commandSequences = entry.entry().commandSequenceNumbers();
  long[] eventIndexes = entry.entry().eventIndexes();

  // Iterate through session identifiers and keep sessions alive.
  List<Long> successfulSessionIds = new ArrayList<>(sessionIds.length);
  Set<RaftServiceContext> services = new HashSet<>();
  for (int i = 0; i < sessionIds.length; i++) {
    long sessionId = sessionIds[i];
    long commandSequence = commandSequences[i];
    long eventIndex = eventIndexes[i];

    RaftSession session = raft.getSessions().getSession(sessionId);
    if (session != null) {
      if (session.getService().keepAlive(entry.index(), entry.entry().timestamp(), session, commandSequence, eventIndex)) {
        successfulSessionIds.add(sessionId);
        services.add(session.getService());
      }
    }
  }

  // Iterate through services and complete keep-alives, causing sessions to be expired if necessary.
  for (RaftServiceContext service : services) {
    service.completeKeepAlive(entry.index(), entry.entry().timestamp());
  }

  expireOrphanSessions(entry.entry().timestamp());

  return Longs.toArray(successfulSessionIds);
}
 
Example 5
Source File: PropertyImpl.java    From jackalope with Apache License 2.0 5 votes vote down vote up
@Override
@Nonnull
public long[] getLengths() throws ValueFormatException, RepositoryException {
    if (!isMultiple()) throw new ValueFormatException();
    List<Long> lengths = new ArrayList<>();
    for (Value value : values)
        lengths.add((long)value.getString().length());
    return Longs.toArray(lengths);
}
 
Example 6
Source File: LongArray.java    From Strata with Apache License 2.0 5 votes vote down vote up
/**
 * Obtains an instance from a collection of {@code Long}.
 * <p>
 * The order of the values in the returned array is the order in which elements are returned
 * from the iterator of the collection.
 *
 * @param collection  the collection to initialize from
 * @return an array containing the values from the collection in iteration order
 */
public static LongArray copyOf(Collection<Long> collection) {
  if (collection.size() == 0) {
    return EMPTY;
  }
  if (collection instanceof ImmList) {
    return ((ImmList) collection).underlying;
  }
  return new LongArray(Longs.toArray(collection));
}
 
Example 7
Source File: TransactionConverterUtils.java    From phoenix-tephra with Apache License 2.0 5 votes vote down vote up
public static Transaction unwrap(TTransaction thriftTx) {
  return new Transaction(thriftTx.getReadPointer(), thriftTx.getTransactionId(), thriftTx.getWritePointer(),
                         thriftTx.getInvalids() == null ? EMPTY_LONG_ARRAY : Longs.toArray(thriftTx.getInvalids()),
                         thriftTx.getInProgress() == null ? EMPTY_LONG_ARRAY :
                             Longs.toArray(thriftTx.getInProgress()),
                         thriftTx.getFirstShort(), getTransactionType(thriftTx.getType()),
                         thriftTx.getCheckpointWritePointers() == null ? EMPTY_LONG_ARRAY :
                             Longs.toArray(thriftTx.getCheckpointWritePointers()),
                         getVisibilityLevel(thriftTx.getVisibilityLevel()));
}
 
Example 8
Source File: DremioMetaImpl.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
@Override
public ExecuteBatchResult executeBatch(StatementHandle h, List<List<TypedValue>> parameterValueLists)
    throws NoSuchStatementException {
  final List<Long> updateCounts = new ArrayList<>();
  for (List<TypedValue> parameterValueList : parameterValueLists) {
    ExecuteResult executeResult = execute(h, parameterValueList, -1);
    final long updateCount =
        executeResult.resultSets.size() == 1
            ? executeResult.resultSets.get(0).updateCount
            : -1L;
    updateCounts.add(updateCount);
  }
  return new ExecuteBatchResult(Longs.toArray(updateCounts));
}
 
Example 9
Source File: TransactionTest.java    From phoenix-tephra with Apache License 2.0 4 votes vote down vote up
private long[] toSortedArray(Set<Long> set) {
  long[] array = Longs.toArray(set);
  Arrays.sort(array);
  return array;
}
 
Example 10
Source File: OnnxGraphMapper.java    From nd4j with Apache License 2.0 4 votes vote down vote up
@Override
public long[] getShapeFromAttr(OnnxProto3.AttributeProto attr) {
    return Longs.toArray(attr.getT().getDimsList());
}
 
Example 11
Source File: TensorMmul.java    From nd4j with Apache License 2.0 4 votes vote down vote up
private SDVariable doTensorMmul(SDVariable a,
                                SDVariable b,
                                int[][] axes) {

    int validationLength = Math.min(axes[0].length, axes[1].length);
    for (int i = 0; i < validationLength; i++) {
        if (a.getShape()[axes[0][i]] != b.getShape()[axes[1][i]])
            throw new IllegalArgumentException("Size of the given axes at each dimension must be the same size.");
        if (axes[0][i] < 0)
            axes[0][i] += a.getShape().length;
        if (axes[1][i] < 0)
            axes[1][i] += b.getShape().length;

    }

    List<Integer> listA = new ArrayList<>();
    for (int i = 0; i < a.getShape().length; i++) {
        if (!Ints.contains(axes[0], i))
            listA.add(i);
    }

    int[] newAxesA = Ints.concat(Ints.toArray(listA), axes[0]);


    List<Integer> listB = new ArrayList<>();
    for (int i = 0; i < b.getShape().length; i++) {
        if (!Ints.contains(axes[1], i))
            listB.add(i);
    }

    int[] newAxesB = Ints.concat(axes[1], Ints.toArray(listB));

    int n2 = 1;
    int aLength = Math.min(a.getShape().length, axes[0].length);
    for (int i = 0; i < aLength; i++) {
        n2 *= a.getShape()[axes[0][i]];
    }

    //if listA and listB are empty these do not initialize.
    //so initializing with {1} which will then get overridden if not empty
    long[] newShapeA = {-1, n2};
    long[] oldShapeA;
    if (listA.size() == 0) {
        oldShapeA = new long[] {1};
    } else {
        oldShapeA = Longs.toArray(listA);
        for (int i = 0; i < oldShapeA.length; i++)
            oldShapeA[i] = a.getShape()[(int) oldShapeA[i]];
    }

    int n3 = 1;
    int bNax = Math.min(b.getShape().length, axes[1].length);
    for (int i = 0; i < bNax; i++) {
        n3 *= b.getShape()[axes[1][i]];
    }


    int[] newShapeB = {n3, -1};
    long[] oldShapeB;
    if (listB.size() == 0) {
        oldShapeB = new long[] {1};
    } else {
        oldShapeB = Longs.toArray(listB);
        for (int i = 0; i < oldShapeB.length; i++)
            oldShapeB[i] = b.getShape()[(int) oldShapeB[i]];
    }


    SDVariable at = f()
            .reshape(f().permute
                    (a,newAxesA),newShapeA);
    SDVariable bt = f()
            .reshape(f()
                    .permute(b,newAxesB),newShapeB);

    SDVariable ret = f().mmul(at,bt);
    long[] aPlusB = Longs.concat(oldShapeA, oldShapeB);
    return f().reshape(ret, aPlusB);
}
 
Example 12
Source File: DynamicCustomOp.java    From nd4j with Apache License 2.0 4 votes vote down vote up
@Override
public long[] iArgs() {
    return Longs.toArray(iArguments);
}
 
Example 13
Source File: XYDataProviderBaseTest.java    From tracecompass with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * From a SWT Chart, this method extract a {@link TmfCommonXAxisModel} that
 * represents the chart. Since, we unfortunately have no mecanism to deserialize
 * with GSON, we have to compare strings. So, once the model is extract from the
 * Chart, we serialize it and compare with a string
 *
 * @param chart
 *            A SWT Chart
 * @param otherSeries
 *            Name of other series to extract from Chart
 * @return A {@link TmfCommonXAxisModel}
 */
protected TmfCommonXAxisModel extractModelFromChart(final Chart chart, String... otherSeries) {
    String mainSeriesName = getMainSeriesName();
    ISeries<?> mainSeries = chart.getSeriesSet().getSeries(mainSeriesName);
    if (mainSeries == null) {
        System.out.println("Main Series " + mainSeriesName + " not found in chart");
        return null;
    }

    /* X and Y Values shown in chart */
    double[] xMain = mainSeries.getXSeries();
    double[] yMain = mainSeries.getYSeries();

    Map<@NonNull String, @NonNull IYModel> yModels = new LinkedHashMap<>();
    yModels.put(mainSeriesName, new YModel(-1, mainSeriesName, Objects.requireNonNull(yMain)));

    for (String other : otherSeries) {
        if (other != null) {
            ISeries<?> series = chart.getSeriesSet().getSeries(other);
            if (series == null) {
                System.out.println("Series " + other + " not found in chart");
                return null;
            }

            /* X and Y Values shown in chart */
            double[] xSeries = series.getXSeries();
            double[] ySeries = series.getYSeries();

            /* Series should have the same x axis values, not finished updating all series*/
            if (!Arrays.equals(xMain, xSeries)) {
                System.out.println("Series don't currently have the same x axis values");
                return null;
            }
            yModels.put(other, new YModel(-1, other, Objects.requireNonNull(ySeries)));
        }
    }

    long[] x = Longs.toArray(Doubles.asList(xMain));
    assertNotNull(x);
    return new TmfCommonXAxisModel(getTitle(), x, yModels);
}
 
Example 14
Source File: OnnxGraphMapper.java    From nd4j with Apache License 2.0 4 votes vote down vote up
@Override
public long[] getShapeFromAttribute(OnnxProto3.AttributeProto attributeProto) {
    return Longs.toArray(attributeProto.getT().getDimsList());
}
 
Example 15
Source File: SegmentStoreScatterDataProvider.java    From tracecompass with Eclipse Public License 2.0 4 votes vote down vote up
public SeriesModel build() {
    SeriesModelBuilder builder = new SeriesModel.SeriesModelBuilder(getId(), String.valueOf(getId()), Longs.toArray(fXValues), Doubles.toArray(fYValues));
    builder.setProperties(Ints.toArray(fProperties)).build();
    return builder.setProperties(Ints.toArray(fProperties)).build();
}
 
Example 16
Source File: SlidingWindowHistogramReservoirTest.java    From styx with Apache License 2.0 4 votes vote down vote up
private long[] toArray(Range<Long> range) {
    return Longs.toArray(ContiguousSet.create(range, DiscreteDomain.longs()));
}
 
Example 17
Source File: RetryUnsuccessfulResponseHandlerTest.java    From firebase-admin-java with Apache License 2.0 4 votes vote down vote up
long[] getDelays() {
  return Longs.toArray(delays);
}
 
Example 18
Source File: TestOrcBloomFilters.java    From presto with Apache License 2.0 4 votes vote down vote up
private static BloomFilter toBloomFilter(OrcProto.BloomFilter orcBloomFilter)
{
    return new BloomFilter(Longs.toArray(orcBloomFilter.getBitsetList()), orcBloomFilter.getNumHashFunctions());
}
 
Example 19
Source File: ArrayUtil.java    From nd4j with Apache License 2.0 4 votes vote down vote up
/**
 * Get the tensor matrix multiply shape
 * @param aShape the shape of the first array
 * @param bShape the shape of the second array
 * @param axes the axes to do the multiply
 * @return the shape for tensor matrix multiply
 */
public static long[] getTensorMmulShape(long[] aShape, long[] bShape, int[][] axes) {
    // FIXME: int cast


    int validationLength = Math.min(axes[0].length, axes[1].length);
    for (int i = 0; i < validationLength; i++) {
        if (aShape[axes[0][i]] != bShape[axes[1][i]])
            throw new IllegalArgumentException(
                            "Size of the given axes a" + " t each dimension must be the same size.");
        if (axes[0][i] < 0)
            axes[0][i] += aShape.length;
        if (axes[1][i] < 0)
            axes[1][i] += bShape.length;

    }

    List<Integer> listA = new ArrayList<>();
    for (int i = 0; i < aShape.length; i++) {
        if (!Ints.contains(axes[0], i))
            listA.add(i);
    }



    List<Integer> listB = new ArrayList<>();
    for (int i = 0; i < bShape.length; i++) {
        if (!Ints.contains(axes[1], i))
            listB.add(i);
    }


    int n2 = 1;
    int aLength = Math.min(aShape.length, axes[0].length);
    for (int i = 0; i < aLength; i++) {
        n2 *= aShape[axes[0][i]];
    }

    //if listA and listB are empty these donot initialize.
    //so initializing with {1} which will then get overriden if not empty
    long[] oldShapeA;
    if (listA.size() == 0) {
        oldShapeA = new long[] {1};
    } else {
        oldShapeA = Longs.toArray(listA);
        for (int i = 0; i < oldShapeA.length; i++)
            oldShapeA[i] = aShape[(int) oldShapeA[i]];
    }

    int n3 = 1;
    int bNax = Math.min(bShape.length, axes[1].length);
    for (int i = 0; i < bNax; i++) {
        n3 *= bShape[axes[1][i]];
    }


    long[] oldShapeB;
    if (listB.size() == 0) {
        oldShapeB = new long[] {1};
    } else {
        oldShapeB = Longs.toArray(listB);
        for (int i = 0; i < oldShapeB.length; i++)
            oldShapeB[i] = bShape[(int) oldShapeB[i]];
    }


    long[] aPlusB = Longs.concat(oldShapeA, oldShapeB);
    return aPlusB;
}
 
Example 20
Source File: TxUtils.java    From phoenix-tephra with Apache License 2.0 3 votes vote down vote up
/**
 * Creates a "dummy" transaction based on the given txVisibilityState's state.  This is not a "real" transaction in
 * the sense that it has not been started, data should not be written with it, and it cannot be committed.  However,
 * this can still be useful for filtering data according to the txVisibilityState's state.  Instead of the actual
 * write pointer from the txVisibilityState, however, we use {@code Long.MAX_VALUE} to avoid mis-identifying any cells
 * as being written by this transaction (and therefore visible).
 */
public static Transaction createDummyTransaction(TransactionVisibilityState txVisibilityState) {
  return new Transaction(txVisibilityState.getReadPointer(), Long.MAX_VALUE,
                         Longs.toArray(txVisibilityState.getInvalid()),
                         Longs.toArray(txVisibilityState.getInProgress().keySet()),
                         TxUtils.getFirstShortInProgress(txVisibilityState.getInProgress()), TransactionType.SHORT);
}