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.sosy_lab.solver.z3.Z3UnsafeFormulaManager.java

@Override
public Long replaceArgsAndName(Long t, String pNewName, List<Long> newArgs) {
    if (isVariable(t)) {
        checkArgument(newArgs.isEmpty());
        long sort = get_sort(z3context, t);
        return getFormulaCreator().makeVariable(sort, pNewName);

    } else if (isUF(t)) {
        int n = get_app_num_args(z3context, t);
        long[] sorts = new long[n];
        for (int i = 0; i < sorts.length; i++) {
            long arg = get_app_arg(z3context, t, i);
            inc_ref(z3context, arg);//from   w  w  w.j av a  2 s. co  m
            sorts[i] = get_sort(z3context, arg);
            inc_ref(z3context, sorts[i]);
            dec_ref(z3context, arg);
        }
        long symbol = mk_string_symbol(z3context, pNewName);
        long retSort = get_sort(z3context, t);
        long newFunc = mk_func_decl(z3context, symbol, sorts, retSort);
        inc_ref(z3context, newFunc);

        //      creator.getSmtLogger().logDeclaration(newFunc, retSort, sorts); // TODO necessary???

        long uif = createUIFCallImpl(newFunc, Longs.toArray(newArgs));

        for (int i = 0; i < sorts.length; i++) {
            dec_ref(z3context, sorts[i]);
        }
        return uif;

    } else {
        throw new IllegalArgumentException(
                "Cannot replace name '" + pNewName + "' in term '" + ast_to_string(z3context, t) + "'.");
    }
}

From source file:org.apache.hive.service.cli.Column.java

public Column(TColumn colValues) {
    if (colValues.isSetBoolVal()) {
        type = Type.BOOLEAN_TYPE;
        nulls = toBitset(colValues.getBoolVal().getNulls());
        boolVars = Booleans.toArray(colValues.getBoolVal().getValues());
        size = boolVars.length;/*from   w  w  w. j  ava2s. co  m*/
    } else if (colValues.isSetByteVal()) {
        type = Type.TINYINT_TYPE;
        nulls = toBitset(colValues.getByteVal().getNulls());
        byteVars = Bytes.toArray(colValues.getByteVal().getValues());
        size = byteVars.length;
    } else if (colValues.isSetI16Val()) {
        type = Type.SMALLINT_TYPE;
        nulls = toBitset(colValues.getI16Val().getNulls());
        shortVars = Shorts.toArray(colValues.getI16Val().getValues());
        size = shortVars.length;
    } else if (colValues.isSetI32Val()) {
        type = Type.INT_TYPE;
        nulls = toBitset(colValues.getI32Val().getNulls());
        intVars = Ints.toArray(colValues.getI32Val().getValues());
        size = intVars.length;
    } else if (colValues.isSetI64Val()) {
        type = Type.BIGINT_TYPE;
        nulls = toBitset(colValues.getI64Val().getNulls());
        longVars = Longs.toArray(colValues.getI64Val().getValues());
        size = longVars.length;
    } else if (colValues.isSetDoubleVal()) {
        type = Type.DOUBLE_TYPE;
        nulls = toBitset(colValues.getDoubleVal().getNulls());
        doubleVars = Doubles.toArray(colValues.getDoubleVal().getValues());
        size = doubleVars.length;
    } else if (colValues.isSetBinaryVal()) {
        type = Type.BINARY_TYPE;
        nulls = toBitset(colValues.getBinaryVal().getNulls());
        binaryVars = colValues.getBinaryVal().getValues();
        size = binaryVars.size();
    } else if (colValues.isSetStringVal()) {
        type = Type.STRING_TYPE;
        nulls = toBitset(colValues.getStringVal().getNulls());
        stringVars = colValues.getStringVal().getValues();
        size = stringVars.size();
    } else {
        throw new IllegalStateException("invalid union object");
    }
}

From source file:org.apache.hadoop.hive.serde2.thrift.ColumnBuffer.java

public ColumnBuffer(TColumn colValues) {
    if (colValues.isSetBoolVal()) {
        type = Type.BOOLEAN_TYPE;
        nulls = toBitset(colValues.getBoolVal().getNulls());
        boolVars = Booleans.toArray(colValues.getBoolVal().getValues());
        size = boolVars.length;//ww  w .j a v  a  2 s .c  om
    } else if (colValues.isSetByteVal()) {
        type = Type.TINYINT_TYPE;
        nulls = toBitset(colValues.getByteVal().getNulls());
        byteVars = Bytes.toArray(colValues.getByteVal().getValues());
        size = byteVars.length;
    } else if (colValues.isSetI16Val()) {
        type = Type.SMALLINT_TYPE;
        nulls = toBitset(colValues.getI16Val().getNulls());
        shortVars = Shorts.toArray(colValues.getI16Val().getValues());
        size = shortVars.length;
    } else if (colValues.isSetI32Val()) {
        type = Type.INT_TYPE;
        nulls = toBitset(colValues.getI32Val().getNulls());
        intVars = Ints.toArray(colValues.getI32Val().getValues());
        size = intVars.length;
    } else if (colValues.isSetI64Val()) {
        type = Type.BIGINT_TYPE;
        nulls = toBitset(colValues.getI64Val().getNulls());
        longVars = Longs.toArray(colValues.getI64Val().getValues());
        size = longVars.length;
    } else if (colValues.isSetDoubleVal()) {
        type = Type.DOUBLE_TYPE;
        nulls = toBitset(colValues.getDoubleVal().getNulls());
        doubleVars = Doubles.toArray(colValues.getDoubleVal().getValues());
        size = doubleVars.length;
    } else if (colValues.isSetBinaryVal()) {
        type = Type.BINARY_TYPE;
        nulls = toBitset(colValues.getBinaryVal().getNulls());
        binaryVars = colValues.getBinaryVal().getValues();
        size = binaryVars.size();
    } else if (colValues.isSetStringVal()) {
        type = Type.STRING_TYPE;
        nulls = toBitset(colValues.getStringVal().getNulls());
        stringVars = colValues.getStringVal().getValues();
        size = stringVars.size();
    } else {
        throw new IllegalStateException("invalid union object");
    }
}

From source file:org.jclouds.gogrid.compute.strategy.GoGridComputeServiceAdapter.java

@Override
public Iterable<Server> listNodesByIds(final Iterable<String> ids) {
    Set<Long> idsAsLongs = FluentIterable.from(ids).transform(toLong()).toSet();

    return client.getServerServices().getServersById(Longs.toArray(idsAsLongs));
}

From source file:org.nd4j.linalg.api.ops.impl.accum.TensorMmul.java

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;

    }// w  ww.j  a v a  2s  .co m

    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);
}

From source file:io.scigraph.internal.reachability.ReachabilityIndex.java

void commitIndexToGraph(InMemoryReachabilityIndex inMemoryIndex) {
    Transaction tx = graphDb.beginTx();/*from  www. j  a  v  a  2s .c  o m*/

    int operationCount = 0;
    for (Entry<Long, InOutList> e : inMemoryIndex.entrySet()) {
        Node node = graphDb.getNodeById(e.getKey());
        node.setProperty(IN_LIST_PROPERTY, Longs.toArray(e.getValue().getInList()));
        node.setProperty(OUT_LIST_PROPERTY, Longs.toArray(e.getValue().getOutList()));
        tx = batchTransactions(tx, operationCount++);
    }

    metaDataNode.setProperty(INDEX_EXISTS_PROPERTY, true);
    tx.success();
    tx.close();
}

From source file:edu.sdsc.scigraph.internal.reachability.ReachabilityIndex.java

@SuppressWarnings("deprecation")
void commitIndexToGraph(InMemoryReachabilityIndex inMemoryIndex) {
    Transaction tx = graphDb.beginTx();//from   w w  w.  ja  v  a2  s. c o m

    int operationCount = 0;
    for (Entry<Long, InOutList> e : inMemoryIndex.entrySet()) {
        Node node = graphDb.getNodeById(e.getKey());
        node.setProperty(IN_LIST_PROPERTY, Longs.toArray(e.getValue().getInList()));
        node.setProperty(OUT_LIST_PROPERTY, Longs.toArray(e.getValue().getOutList()));
        tx = batchTransactions(tx, operationCount++);
    }

    metaDataNode.setProperty(INDEX_EXISTS_PROPERTY, true);
    tx.success();
    tx.finish();
}

From source file:org.apache.hadoop.hdfs.protocolPB.ClientDatanodeProtocolServerSideTranslatorPB.java

@Override
public GetHdfsBlockLocationsResponseProto getHdfsBlockLocations(RpcController controller,
        GetHdfsBlockLocationsRequestProto request) throws ServiceException {
    HdfsBlocksMetadata resp;//from   w w w  .ja  va 2  s.  c  om
    try {
        String poolId = request.getBlockPoolId();
        List<Token<BlockTokenIdentifier>> tokens = new ArrayList<>(request.getTokensCount());
        for (TokenProto b : request.getTokensList()) {
            tokens.add(PBHelper.convert(b));
        }
        long[] blockIds = Longs.toArray(request.getBlockIdsList());

        // Call the real implementation
        resp = impl.getHdfsBlocksMetadata(poolId, blockIds, tokens);
    } catch (IOException e) {
        throw new ServiceException(e);
    }
    List<ByteString> volumeIdsByteStrings = new ArrayList<>(resp.getVolumeIds().size());
    for (byte[] b : resp.getVolumeIds()) {
        volumeIdsByteStrings.add(ByteString.copyFrom(b));
    }
    // Build and return the response
    Builder builder = GetHdfsBlockLocationsResponseProto.newBuilder();
    builder.addAllVolumeIds(volumeIdsByteStrings);
    builder.addAllVolumeIndexes(resp.getVolumeIndexes());
    return builder.build();
}

From source file:com.splicemachine.si.data.hbase.coprocessor.TxnLifecycleEndpoint.java

@Override
@SuppressFBWarnings(value = "SF_SWITCH_NO_DEFAULT", justification = "Intentional")
public void lifecycleAction(RpcController controller, TxnMessage.TxnLifecycleMessage request,
        RpcCallback<TxnMessage.ActionResponse> done) {
    try {/*from   w w  w .  ja  va 2s  .  c  o  m*/
        TxnMessage.ActionResponse response = null;
        switch (request.getAction()) {
        case COMMIT:
            response = TxnMessage.ActionResponse.newBuilder().setCommitTs(commit(request.getTxnId())).build();
            break;
        case TIMEOUT:
        case ROLLBACk:
            rollback(request.getTxnId());
            response = TxnMessage.ActionResponse.getDefaultInstance();
            break;
        case KEEPALIVE:
            boolean b = keepAlive(request.getTxnId());
            response = TxnMessage.ActionResponse.newBuilder().setContinue(b).build();
            break;
        case ROLLBACK_SUBTRANSACTIONS:
            long[] ids = Longs.toArray(request.getRolledbackSubTxnsList());
            rollbackSubtransactions(request.getTxnId(), ids);
            response = TxnMessage.ActionResponse.getDefaultInstance();
            break;
        }
        done.run(response);
    } catch (IOException ioe) {
        ResponseConverter.setControllerException(controller, ioe);
    }
}

From source file:com.seajas.search.codex.service.social.SocialFacade.java

@Override
@Cacheable(value = "twitterProfilesCache")
public List<TwitterProfile> getTwitterProfiles(List<Long> searchableProfileIds) {
    // first, fetch available profiles from the cache
    List<TwitterProfile> twitterProfiles = Lists.newArrayList();

    List<Long> idsCopy = Lists.newArrayList(searchableProfileIds);
    Iterator<Long> idIterator = idsCopy.iterator();

    while (idIterator.hasNext()) {
        Long id = idIterator.next();

        Cache.ValueWrapper valueWrapper = cacheManager.getCache(TWITTER_PROFILE_CACHE).get(id);
        if (valueWrapper != null && valueWrapper.get() != null) {
            LOG.debug(String.format("Read profile with id %d from cache", id));
            twitterProfiles.add((TwitterProfile) valueWrapper.get());
            idIterator.remove();//from   w  w  w  . ja  v  a  2  s . com
        }
    }

    // secondly, if not in the cache, retrieve from twitter and store in cache
    long[] ids = Longs.toArray(Lists.newArrayList(idsCopy));
    if (ids.length > 0) {
        LOG.debug("Grabbing twitter profiles with ids: " + ids);
        List<TwitterProfile> remainingProfiles = getTwitterTemplate().userOperations().getUsers(ids);
        for (TwitterProfile profile : remainingProfiles) {
            LOG.debug(String.format("Write profile with id %d to cache", profile.getId()));
            cacheManager.getCache(TWITTER_PROFILE_CACHE).put(profile.getId(), profile);
        }
        twitterProfiles.addAll(remainingProfiles);
    }

    return twitterProfiles;
}