Example usage for com.google.common.primitives Longs toArray

List of usage examples for com.google.common.primitives Longs toArray

Introduction

In this page you can find the example usage for com.google.common.primitives Longs toArray.

Prototype

public static long[] toArray(Collection<? extends Number> collection) 

Source Link

Document

Returns an array containing each value of collection , converted to a long value in the manner of Number#longValue .

Usage

From source file:org.voltdb.sysprocs.SnapshotSave.java

@Override
public DependencyPair executePlanFragment(Map<Integer, List<VoltTable>> dependencies, long fragmentId,
        ParameterSet params, SystemProcedureExecutionContext context) {
    String hostname = CoreUtils.getHostnameOrAddress();
    if (fragmentId == SysProcFragmentId.PF_saveTest) {
        assert (params.toArray()[0] != null);
        assert (params.toArray()[1] != null);
        assert (params.toArray()[2] != null);
        String file_path = (String) params.toArray()[0];
        String file_nonce = (String) params.toArray()[1];
        SnapshotFormat format = SnapshotFormat.getEnumIgnoreCase((String) params.toArray()[2]);
        String data = (String) params.toArray()[3];
        return saveTest(file_path, file_nonce, format, data, context, hostname);
    } else if (fragmentId == SysProcFragmentId.PF_saveTestResults) {
        VoltTable result = VoltTableUtil.unionTables(dependencies.get(DEP_saveTest));
        return new DependencyPair(DEP_saveTestResults, result);
    } else if (fragmentId == SysProcFragmentId.PF_createSnapshotTargets) {
        assert (params.toArray()[0] != null);
        assert (params.toArray()[1] != null);
        assert (params.toArray()[2] != null);
        assert (params.toArray()[3] != null);
        assert (params.toArray()[4] != null);
        assert (params.toArray()[5] != null);
        assert (params.toArray()[6] != null);
        assert (params.toArray()[7] != null);
        final String file_path = (String) params.toArray()[0];
        final String file_nonce = (String) params.toArray()[1];
        final long txnId = (Long) params.toArray()[2];
        long perPartitionTxnIds[] = (long[]) params.toArray()[3];
        byte block = (Byte) params.toArray()[4];
        SnapshotFormat format = SnapshotFormat.getEnumIgnoreCase((String) params.toArray()[5]);

        /*/* www  . j  a  v  a 2 s . c  o  m*/
         * Filter out the partitions that are active in the cluster
         * and include values for all partitions that aren't part of the current cluster.
         * These transaction ids are used to track partitions that have come and gone
         * so that the ids can resume without duplicates if the partitions are brought back.
         */
        List<Long> perPartitionTransactionIdsToKeep = new ArrayList<Long>();
        for (long txnid : perPartitionTxnIds) {
            int partitionId = TxnEgo.getPartitionId(txnid);
            if (partitionId >= context.getNumberOfPartitions() && partitionId != MpInitiator.MP_INIT_PID) {
                perPartitionTransactionIdsToKeep.add(txnid);
            }
        }

        String data = (String) params.toArray()[6];
        final long timestamp = (Long) params.toArray()[7];
        SnapshotSaveAPI saveAPI = new SnapshotSaveAPI();
        VoltTable result = saveAPI.startSnapshotting(file_path, file_nonce, format, block, txnId,
                context.getLastCommittedSpHandle(), Longs.toArray(perPartitionTransactionIdsToKeep), data,
                context, hostname, timestamp);
        return new DependencyPair(SnapshotSave.DEP_createSnapshotTargets, result);
    } else if (fragmentId == SysProcFragmentId.PF_createSnapshotTargetsResults) {
        VoltTable result = VoltTableUtil.unionTables(dependencies.get(DEP_createSnapshotTargets));
        return new DependencyPair(DEP_createSnapshotTargetsResults, result);
    } else if (fragmentId == SysProcFragmentId.PF_snapshotSaveQuiesce) {
        // tell each site to quiesce
        context.getSiteProcedureConnection().quiesce();
        VoltTable results = new VoltTable(new ColumnInfo("id", VoltType.BIGINT));
        results.addRow(context.getSiteId());
        return new DependencyPair(DEP_snapshotSaveQuiesce, results);
    } else if (fragmentId == SysProcFragmentId.PF_snapshotSaveQuiesceResults) {
        VoltTable dummy = new VoltTable(VoltSystemProcedure.STATUS_SCHEMA);
        dummy.addRow(VoltSystemProcedure.STATUS_OK);
        return new DependencyPair(DEP_snapshotSaveQuiesceResults, dummy);
    }
    assert (false);
    return null;
}

From source file:org.sosy_lab.solver.z3.Z3UnsafeFormulaManager.java

@Override
protected Long substitute(Long t, List<Long> changeFrom, List<Long> changeTo) {
    int size = changeFrom.size();
    Preconditions.checkState(size == changeTo.size());
    return Z3NativeApi.substitute(z3context, t, size, Longs.toArray(changeFrom), Longs.toArray(changeTo));
}

From source file:com.todoroo.astrid.ui.ReminderControlSet.java

@Override
public void onSaveInstanceState(Bundle outState) {
    super.onSaveInstanceState(outState);

    outState.putLong(EXTRA_TASK_ID, taskId);
    outState.putInt(EXTRA_FLAGS, getFlags());
    outState.putLong(EXTRA_RANDOM_REMINDER, getRandomReminderPeriod());
    outState.putLongArray(EXTRA_ALARMS, Longs.toArray(alarms));
    outState.putParcelableArrayList(EXTRA_GEOFENCES, newArrayList(geofences));
}

From source file:org.sosy_lab.solver.z3.Z3UnsafeFormulaManager.java

@Override
protected Long replaceQuantifiedBody(Long pF, Long pBody) {
    boolean isForall = is_quantifier_forall(z3context, pF);
    int boundCount = get_quantifier_num_bound(z3context, pF);
    ArrayList<Long> boundVars = Lists.newArrayList();

    for (int b = 0; b < boundCount; b++) {
        long varName = get_quantifier_bound_name(z3context, pF, b);
        long varSort = get_quantifier_bound_sort(z3context, pF, b);
        long var = mk_const(z3context, varName, varSort);
        boundVars.add(var);
        inc_ref(z3context, var);
    }//from   ww  w  .j  av  a  2s .co  m

    if (isForall) {
        return Z3NativeApi.mk_forall_const(z3context, 0, boundVars.size(), Longs.toArray(boundVars), 0,
                Longs.toArray(Collections.<Long>emptyList()), pBody);
    } else {
        return Z3NativeApi.mk_exists_const(z3context, 0, boundVars.size(), Longs.toArray(boundVars), 0,
                Longs.toArray(Collections.<Long>emptyList()), pBody);

    }
}

From source file:com.twcable.jackalope.impl.jcr.PropertyImpl.java

@Override
@Nonnull//  w  ww. ja  v a2 s  .  c  o  m
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);
}

From source file:com.b2international.commons.collect.LongSets.java

public static void main(final String[] args) {

    System.out.println("**********************************************");
    System.out.println("difference");
    System.out.println("**********************************************");

    HashSet<Long> set1 = Sets.newHashSet();
    HashSet<Long> set2 = Sets.newHashSet();
    for (int i = 1; i < 12; i++) {
        set1.add((long) i);
    }// w w  w  . j  av a 2s.com

    for (int i = 5; i < 20; i++) {
        set2.add((long) i);
    }

    System.out.println("reference " + Sets.difference(set1, set2));
    System.out.println("reference " + Sets.difference(set2, set1));

    LongSet longset1 = PrimitiveSets.newLongOpenHashSet(Longs.toArray(set1));
    LongSet longset2 = PrimitiveSets.newLongOpenHashSet(Longs.toArray(set2));
    LongSet diff1 = LongSets.difference(longset1, longset2);
    LongSet diff2 = LongSets.difference(longset2, longset1);
    System.out.println("assert " + diff1);
    System.out.println("assert " + diff2);

    System.out.println("*******************************************");

    set1 = Sets.newHashSet();
    set2 = Sets.newHashSet();
    for (int i = 1; i < 3500000; i++) {
        set1.add((long) i);
    }

    for (int i = 500000; i < 4000000; i++) {
        set2.add((long) i);
    }

    long t = System.currentTimeMillis();

    System.out.println(Sets.difference(set1, set2).size());
    System.out.println(Sets.difference(set2, set1).size());

    StopWatch.time("diff sets", t);
    longset1 = PrimitiveSets.newLongOpenHashSet(Longs.toArray(set1));
    longset2 = PrimitiveSets.newLongOpenHashSet(Longs.toArray(set2));

    t = System.currentTimeMillis();
    diff1 = LongSets.difference(longset1, longset2);
    diff2 = LongSets.difference(longset2, longset1);
    System.out.println(diff1.size());
    System.out.println(diff2.size());
    StopWatch.time("diff longsets", t);

    System.out.println("**********************************************");
    System.out.println("intersection");
    System.out.println("**********************************************");

    set1 = Sets.newHashSet();
    set2 = Sets.newHashSet();
    for (int i = 1; i < 12; i++) {
        set1.add((long) i);
    }

    for (int i = 5; i < 20; i++) {
        set2.add((long) i);
    }

    System.out.println("reference " + Sets.intersection(set1, set2));
    System.out.println("reference " + Sets.intersection(set2, set1));

    longset1 = PrimitiveSets.newLongOpenHashSet(Longs.toArray(set1));
    longset2 = PrimitiveSets.newLongOpenHashSet(Longs.toArray(set2));
    LongSet intersection1 = LongSets.intersection(longset1, longset2);
    LongSet intersection2 = LongSets.intersection(longset2, longset1);
    System.out.println("assert " + intersection1);
    System.out.println("assser " + intersection2);

    System.out.println("*******************************************");

    set1 = Sets.newHashSet();
    set2 = Sets.newHashSet();
    for (int i = 1; i < 3500000; i++) {
        set1.add((long) i);
    }

    for (int i = 500000; i < 4000000; i++) {
        set2.add((long) i);
    }

    t = System.currentTimeMillis();

    System.out.println(Sets.intersection(set1, set2).size());
    System.out.println(Sets.intersection(set2, set1).size());

    StopWatch.time("intersection sets", t);
    longset1 = PrimitiveSets.newLongOpenHashSet(Longs.toArray(set1));
    longset2 = PrimitiveSets.newLongOpenHashSet(Longs.toArray(set2));

    t = System.currentTimeMillis();
    intersection1 = LongSets.intersection(longset1, longset2);
    intersection2 = LongSets.intersection(longset2, longset1);
    System.out.println(intersection1.size());
    System.out.println(intersection2.size());
    StopWatch.time("intersection longsets", t);

}

From source file:org.voltcore.agreement.MeshArbiter.java

/**
 * Notify all survivors when you are closing links to nodes
 * @param decision map where the keys contain the kill sites
 *   and its values are their last known safe transaction ids
 *//*from ww w.  j  a  v a2s .  c om*/
protected void notifyOnKill(Set<Long> hsIds, Map<Long, Long> decision) {

    SiteFailureMessage.Builder sfmb = SiteFailureMessage.builder().decisions(decision.keySet())
            .failures(decision.keySet());

    Set<Long> dests = Sets.filter(m_seeker.getSurvivors(), not(equalTo(m_hsId)));
    if (dests.isEmpty())
        return;

    sfmb.survivors(Sets.difference(m_seeker.getSurvivors(), decision.keySet()));
    sfmb.safeTxnIds(getSafeTxnIdsForSites(hsIds));

    SiteFailureMessage sfm = sfmb.build();
    m_mailbox.send(Longs.toArray(dests), sfm);

    m_recoveryLog.info("Agreement, Sending [" + CoreUtils.hsIdCollectionToString(dests) + "]  " + sfm);
}

From source file:com.b2international.snowowl.datastore.server.history.HistoryInfoProvider.java

private static Pair<Long, Long> getPreviousAndCurrentTimestamps(final Collection<Long> longs) {
    final long[] timestamps = Longs.toArray(longs);
    final long timestamp = Longs.max(timestamps);
    final long previousTimestamp = Longs.min(timestamps) - 1L;
    return Pair.of(previousTimestamp, timestamp);
}

From source file:org.voltcore.agreement.MeshArbiter.java

/**
 * Send one message to each surviving execution site providing this site's
 * multi-partition commit point and this site's safe txnid
 * (the receiver will filter the later for its
 * own partition). Do this once for each failed initiator that we know about.
 * Sends all data all the time to avoid a need for request/response.
 *///from www  . j av  a  2s.  c  om
private void discoverGlobalFaultData_send(Set<Long> hsIds) {
    Set<Long> dests = Sets.filter(m_seeker.getSurvivors(), not(equalTo(m_hsId)));

    SiteFailureMessage.Builder msgBuilder = SiteFailureMessage.builder().survivors(m_seeker.getSurvivors())
            .failures(m_inTrouble.keySet()).safeTxnIds(getSafeTxnIdsForSites(hsIds));

    SiteFailureMessage sfm = msgBuilder.build();
    sfm.m_sourceHSId = m_hsId;

    updateFailedSitesLedger(hsIds, sfm);
    m_seeker.add(sfm);

    m_mailbox.send(Longs.toArray(dests), sfm);

    m_recoveryLog.info("Agreement, Sending survivors " + sfm);
}

From source file:io.hops.transaction.context.INodeContext.java

private List<INode> findBatchWithLocalCacheCheck(INode.Finder inodeFinder, Object[] params)
        throws TransactionContextException, StorageException {
    final String[] names = (String[]) params[0];
    final long[] parentIds = (long[]) params[1];
    final long[] partitionIds = (long[]) params[2];

    List<String> namesRest = Lists.newArrayList();
    List<Long> parentIdsRest = Lists.newArrayList();
    List<Long> partitionIdsRest = Lists.newArrayList();
    List<Integer> unpopulatedIndeces = Lists.newArrayList();

    List<INode> result = new ArrayList<>(Collections.<INode>nCopies(names.length, null));

    for (int i = 0; i < names.length; i++) {
        final String nameParentKey = INode.nameParentKey(parentIds[i], names[i]);
        INode node = inodesNameParentIndex.get(nameParentKey);
        if (node != null) {
            result.set(i, node);//from   w w w.  j ava 2  s  .co  m
            hit(inodeFinder, node, "name", names[i], "parent_id", parentIds[i], "partition_id",
                    partitionIds[i]);
        } else {
            namesRest.add(names[i]);
            parentIdsRest.add(parentIds[i]);
            partitionIdsRest.add(partitionIds[i]);
            unpopulatedIndeces.add(i);
        }
    }

    if (unpopulatedIndeces.isEmpty()) {
        return result;
    }

    if (unpopulatedIndeces.size() == names.length) {
        return findBatch(inodeFinder, names, parentIds, partitionIds);
    } else {
        List<INode> batch = findBatch(inodeFinder, namesRest.toArray(new String[namesRest.size()]),
                Longs.toArray(parentIdsRest), Longs.toArray(partitionIdsRest));
        Iterator<INode> batchIterator = batch.listIterator();
        for (Integer i : unpopulatedIndeces) {
            if (batchIterator.hasNext()) {
                result.set(i, batchIterator.next());
            }
        }
        return result;
    }
}