Example usage for java.lang Long toUnsignedString

List of usage examples for java.lang Long toUnsignedString

Introduction

In this page you can find the example usage for java.lang Long toUnsignedString.

Prototype

public static String toUnsignedString(long i) 

Source Link

Document

Returns a string representation of the argument as an unsigned decimal value.

Usage

From source file:net.dv8tion.jda.core.handle.MessageBulkDeleteHandler.java

@Override
protected Long handleInternally(JSONObject content) {
    final long channelId = content.getLong("channel_id");

    if (api.isBulkDeleteSplittingEnabled()) {
        SocketHandler handler = api.getClient().getHandler("MESSAGE_DELETE");
        content.getJSONArray("ids").forEach(id -> {
            handler.handle(responseNumber, new JSONObject().put("d",
                    new JSONObject().put("channel_id", Long.toUnsignedString(channelId)).put("id", id)));
        });//from   ww w  .j  ava  2  s  .c o  m
    } else {
        TextChannel channel = api.getTextChannelMap().get(channelId);
        if (channel == null) {
            api.getEventCache().cache(EventCache.Type.CHANNEL, channelId,
                    () -> handle(responseNumber, allContent));
            EventCache.LOG.debug("Received a Bulk Message Delete for a TextChannel that is not yet cached.");
            return null;
        }

        if (api.getGuildLock().isLocked(channel.getGuild().getIdLong())) {
            return channel.getGuild().getIdLong();
        }

        LinkedList<String> msgIds = new LinkedList<>();
        content.getJSONArray("ids").forEach(id -> msgIds.add((String) id));
        api.getEventManager().handle(new MessageBulkDeleteEvent(api, responseNumber, channel, msgIds));
    }
    return null;
}

From source file:net.dv8tion.jda.core.requests.restaction.pagination.AuditLogPaginationAction.java

/**
 * Filters retrieved entities by the specified {@link net.dv8tion.jda.core.entities.User User} id.
 *
 * @param  userId//from   ww  w.j  av  a 2 s.  c o m
 *         {@link net.dv8tion.jda.core.entities.User User} id used to filter,
 *         or {@code null} to remove user filtering
 *
 * @return The current AuditLogPaginationAction for chaining convenience
 */
public AuditLogPaginationAction user(long userId) {
    return user(Long.toUnsignedString(userId));
}

From source file:net.dv8tion.jda.core.entities.MessageChannel.java

/**
 * The id for the most recent message sent
 * in this current MessageChannel./*from  ww  w  .  j a v a 2  s. co  m*/
 * <br>This should only be used if {@link #hasLatestMessage()} returns {@code true}!
 *
 * <p>This value is updated on each {@link net.dv8tion.jda.core.events.message.MessageReceivedEvent MessageReceivedEvent}
 * and <u><b>will be reset to {@code null} if the message associated with this ID gets deleted</b></u>
 *
 * @throws java.lang.IllegalStateException
 *         If no message id is available
 *
 * @return The most recent message's id
 */
default String getLatestMessageId() {
    return Long.toUnsignedString(getLatestMessageIdLong());
}

From source file:org.ScripterRon.TokenExchange.TokenAPI.java

/**
 * Process the API request//w w  w. j  a v a2  s .  com
 *
 * @param   req                 HTTP request
 * @return                      HTTP response
 * @throws  ParameterException  Parameter error detected
 */
@SuppressWarnings("unchecked")
@Override
protected JSONStreamAware processRequest(HttpServletRequest req) throws ParameterException {
    JSONObject response = new JSONObject();
    String function = Convert.emptyToNull(req.getParameter("function"));
    if (function == null) {
        return missing("function");
    }
    if (!BitcoinWallet.isWalletInitialized()) {
        return failure("Bitcoin wallet is not initialized yet");
    }
    BitcoinWallet.propagateContext();
    String heightString;
    String includeExchangedString;
    String accountString;
    String publicKeyString;
    String addressString;
    String amountString;
    String rateString;
    String txString;
    boolean includeExchanged;
    long accountId;
    int height;
    List<BitcoinAccount> accountList;
    BitcoinAccount account;
    switch (function) {
    case "getStatus":
        response.put("applicationName", TokenAddon.applicationName);
        response.put("applicationVersion", TokenAddon.applicationVersion);
        response.put("exchangeRate", TokenAddon.exchangeRate.toPlainString());
        response.put("currencyCode", TokenAddon.currencyCode);
        response.put("currencyId", Long.toUnsignedString(TokenAddon.currencyId));
        response.put("tokenAccount", Long.toUnsignedString(TokenAddon.accountId));
        response.put("tokenAccountRS", Convert.rsAccount(TokenAddon.accountId));
        List<Peer> peers = BitcoinWallet.getConnectedPeers();
        JSONArray connectedPeers = new JSONArray();
        peers.forEach((peer) -> {
            JSONObject JSONpeer = new JSONObject();
            PeerAddress peerAddress = peer.getAddress();
            VersionMessage versionMessage = peer.getPeerVersionMessage();
            JSONpeer.put("address", TokenAddon.formatAddress(peerAddress.getAddr(), peerAddress.getPort()));
            JSONpeer.put("version", versionMessage.clientVersion);
            JSONpeer.put("subVersion", versionMessage.subVer);
            connectedPeers.add(JSONpeer);
        });
        response.put("connectedPeers", connectedPeers);
        String downloadPeer = BitcoinWallet.getDownloadPeer();
        if (downloadPeer != null) {
            response.put("downloadPeer", downloadPeer);
        }
        response.put("nxtConfirmations", TokenAddon.nxtConfirmations);
        response.put("bitcoinConfirmations", TokenAddon.bitcoinConfirmations);
        response.put("walletAddress", BitcoinWallet.getWalletAddress());
        response.put("walletBalance", BitcoinWallet.getBalance().toPlainString());
        response.put("bitcoinTxFee", TokenAddon.bitcoinTxFee.toPlainString());
        response.put("bitcoinChainHeight", BitcoinWallet.getChainHeight());
        response.put("nxtChainHeight", Nxt.getBlockchain().getHeight());
        response.put("suspended", TokenAddon.isSuspended());
        if (TokenAddon.isSuspended()) {
            response.put("suspendReason", TokenAddon.getSuspendReason());
        }
        break;
    case "setExchangeRate":
        rateString = Convert.emptyToNull(req.getParameter("rate"));
        if (rateString == null) {
            return missing("rate");
        }
        try {
            BigDecimal rate = new BigDecimal(rateString).movePointRight(8).divideToIntegralValue(BigDecimal.ONE)
                    .movePointLeft(8).stripTrailingZeros();
            TokenDb.setExchangeRate(rate);
            response.put("processed", true);
        } catch (NumberFormatException exc) {
            return incorrect("rate", exc.getMessage());
        } catch (Exception exc) {
            Logger.logErrorMessage("SetExchangeRate failed", exc);
            return failure("Unable to set exchange rate: " + exc.getMessage());
        }
        break;
    case "getNxtTransactions":
        heightString = Convert.emptyToNull(req.getParameter("height"));
        if (heightString == null) {
            height = 0;
        } else {
            try {
                height = Integer.valueOf(heightString);
            } catch (NumberFormatException exc) {
                return incorrect("height", exc.getMessage());
            }
        }
        includeExchangedString = Convert.emptyToNull(req.getParameter("includeExchanged"));
        if (includeExchangedString == null) {
            includeExchanged = false;
        } else {
            includeExchanged = Boolean.valueOf(includeExchangedString);
        }
        try {
            List<TokenTransaction> tokenList = TokenDb.getTokens(height, includeExchanged);
            JSONArray tokenArray = new JSONArray();
            tokenList.forEach((token) -> {
                JSONObject tokenObject = new JSONObject();
                tokenObject.put("nxtTxId", Long.toUnsignedString(token.getNxtTxId()));
                tokenObject.put("sender", Long.toUnsignedString(token.getSenderId()));
                tokenObject.put("senderRS", token.getSenderIdRS());
                tokenObject.put("nxtChainHeight", token.getHeight());
                tokenObject.put("timestamp", token.getTimestamp());
                tokenObject.put("exchanged", token.isExchanged());
                tokenObject.put("tokenAmount", BigDecimal
                        .valueOf(token.getTokenAmount(), TokenAddon.currencyDecimals).toPlainString());
                tokenObject.put("bitcoinAmount",
                        BigDecimal.valueOf(token.getBitcoinAmount(), 8).toPlainString());
                tokenObject.put("address", token.getBitcoinAddress());
                if (token.getBitcoinTxId() != null) {
                    tokenObject.put("bitcoinTxId", token.getBitcoinTxIdString());
                }
                tokenArray.add(tokenObject);
            });
            response.put("transactions", tokenArray);
        } catch (Exception exc) {
            Logger.logErrorMessage("GetNxtTransactions failed", exc);
            return failure("Unable to get Nxt transactions: " + exc.getMessage());
        }
        break;
    case "suspend":
        TokenAddon.suspend("Suspended by the TokenExchange administrator");
        response.put("suspended", TokenAddon.isSuspended());
        break;
    case "resume":
        TokenAddon.resume();
        response.put("suspended", TokenAddon.isSuspended());
        break;
    case "getAddress":
        accountString = Convert.emptyToNull(req.getParameter("account"));
        if (accountString == null) {
            return missing("account");
        }
        try {
            accountId = Convert.parseAccountId(accountString);
        } catch (Exception exc) {
            return incorrect("account", exc.getMessage());
        }
        publicKeyString = Convert.emptyToNull(req.getParameter("publicKey"));
        byte[] publicKey;
        if (publicKeyString != null) {
            try {
                publicKey = Convert.parseHexString(publicKeyString);
            } catch (Exception exc) {
                return incorrect("publicKey", exc.getMessage());
            }
            if (publicKey.length != 32) {
                return incorrect("publicKey", "public key is not 32 bytes");
            }
            byte[] accountPublicKey = Account.getPublicKey(accountId);
            if (accountPublicKey != null && !Arrays.equals(accountPublicKey, publicKey)) {
                return incorrect("publicKey", "public key does not match account public key");
            }
        } else {
            publicKey = null;
        }
        try {
            accountList = TokenDb.getAccount(accountId);
            if (!accountList.isEmpty()) {
                account = accountList.get(accountList.size() - 1);
                if (TokenDb.transactionExists(account.getBitcoinAddress())) {
                    account = null;
                }
            } else {
                account = null;
            }
            if (account == null) {
                DeterministicKey key = BitcoinWallet.getNewKey();
                account = new BitcoinAccount(key, accountId, publicKey);
                TokenDb.storeAccount(account);
            }
            formatAccount(account, response);
        } catch (Exception exc) {
            Logger.logErrorMessage("GetAddress failed", exc);
            return failure("Unable to get new Bitcoin address: " + exc.getMessage());
        }
        break;
    case "getAccounts":
        JSONArray accountArray = new JSONArray();
        accountString = Convert.emptyToNull(req.getParameter("account"));
        addressString = Convert.emptyToNull(req.getParameter("address"));
        try {
            if (accountString != null) {
                try {
                    accountId = Convert.parseAccountId(accountString);
                } catch (Exception exc) {
                    return incorrect("account", exc.getMessage());
                }
                accountList = TokenDb.getAccount(accountId);
                accountList.forEach((a) -> accountArray.add(formatAccount(a, new JSONObject())));
            } else if (addressString != null) {
                account = TokenDb.getAccount(addressString);
                if (account != null) {
                    accountArray.add(formatAccount(account, new JSONObject()));
                }
            } else {
                accountList = TokenDb.getAccounts();
                accountList.forEach((a) -> accountArray.add(formatAccount(a, new JSONObject())));
            }
            response.put("accounts", accountArray);
        } catch (Exception exc) {
            Logger.logErrorMessage("GetAccounts failed", exc);
            return failure("Unable to get accounts: " + exc.getMessage());
        }
        break;
    case "deleteAddress":
        addressString = Convert.emptyToNull(req.getParameter("address"));
        if (addressString == null) {
            return missing("address");
        }
        try {
            boolean deleted = TokenDb.deleteAccountAddress(addressString);
            if (deleted) {
                BitcoinWallet.removeAddress(addressString);
            }
            response.put("deleted", deleted);
        } catch (Exception exc) {
            Logger.logErrorMessage("DeleteAddress failed", exc);
            return failure("Unable to delete account: " + exc.getMessage());
        }
        break;
    case "getBitcoinTransactions":
        JSONArray txArray = new JSONArray();
        addressString = Convert.emptyToNull(req.getParameter("address"));
        heightString = Convert.emptyToNull(req.getParameter("height"));
        if (heightString == null) {
            height = 0;
        } else {
            try {
                height = Integer.valueOf(heightString);
            } catch (NumberFormatException exc) {
                return incorrect("height", exc.getMessage());
            }
        }
        includeExchangedString = Convert.emptyToNull(req.getParameter("includeExchanged"));
        if (includeExchangedString == null) {
            includeExchanged = false;
        } else {
            includeExchanged = Boolean.valueOf(includeExchangedString);
        }
        try {
            List<BitcoinTransaction> txList = TokenDb.getTransactions(height, addressString, includeExchanged);
            txList.forEach((tx) -> {
                JSONObject txJSON = new JSONObject();
                txJSON.put("bitcoinTxId", tx.getBitcoinTxIdString());
                txJSON.put("bitcoinBlockId", tx.getBitcoinBlockIdString());
                txJSON.put("bitcoinChainHeight", tx.getHeight());
                txJSON.put("timestamp", tx.getTimestamp());
                txJSON.put("address", tx.getBitcoinAddress());
                txJSON.put("bitcoinAmount", BigDecimal.valueOf(tx.getBitcoinAmount(), 8).toPlainString());
                txJSON.put("tokenAmount",
                        BigDecimal.valueOf(tx.getTokenAmount(), TokenAddon.currencyDecimals).toPlainString());
                txJSON.put("account", Long.toUnsignedString(tx.getAccountId()));
                txJSON.put("accountRS", tx.getAccountIdRS());
                txJSON.put("exchanged", tx.isExchanged());
                if (tx.getNxtTxId() != 0) {
                    txJSON.put("nxtTxId", Long.toUnsignedString(tx.getNxtTxId()));
                }
                txArray.add(txJSON);
            });
            response.put("transactions", txArray);
        } catch (Exception exc) {
            Logger.logErrorMessage("GetBitcoinTransactions failed", exc);
            return failure("Unable to get Bitcoin transactions: " + exc.getMessage());
        }
        break;
    case "sendBitcoins":
        BitcoinWallet.propagateContext();
        addressString = Convert.emptyToNull(req.getParameter("address"));
        amountString = Convert.emptyToNull(req.getParameter("amount"));
        if (addressString == null) {
            return missing("address");
        }
        if (amountString == null) {
            return missing("amount");
        }
        try {
            Address toAddress = Address.fromBase58(BitcoinWallet.getNetworkParameters(), addressString);
            BigDecimal amount = new BigDecimal(amountString).movePointRight(8)
                    .divideToIntegralValue(BigDecimal.ONE).movePointLeft(8).stripTrailingZeros();
            txString = BitcoinWallet.sendCoins(toAddress, amount);
            response.put("transaction", txString);
        } catch (NumberFormatException exc) {
            return incorrect("amount", exc.getMessage());
        } catch (AddressFormatException exc) {
            return incorrect("address", exc.getMessage());
        } catch (Exception exc) {
            Logger.logErrorMessage("SendBitcoins failed", exc);
            return failure("Unable to send coins: " + exc.getMessage());
        }
        break;
    case "emptyWallet":
        BitcoinWallet.propagateContext();
        addressString = Convert.emptyToNull(req.getParameter("address"));
        if (addressString == null) {
            return missing("address");
        }
        try {
            Address toAddress = Address.fromBase58(BitcoinWallet.getNetworkParameters(), addressString);
            txString = BitcoinWallet.emptyWallet(toAddress);
            response.put("transaction", txString);
        } catch (AddressFormatException exc) {
            return incorrect("address", exc.getMessage());
        } catch (Exception exc) {
            Logger.logErrorMessage("EmptyWallet failed", exc);
            return failure("Unable to empty wallet: " + exc.getMessage());
        }
        break;
    case "rollbackChain":
        heightString = Convert.emptyToNull(req.getParameter("height"));
        if (heightString == null) {
            return missing("height");
        }
        try {
            height = Integer.valueOf(heightString);
            if (height < 0) {
                return incorrect("height", "The requested height is not valid");
            }
            boolean success = BitcoinWallet.rollbackChain(height);
            response.put("completed", success);
        } catch (NumberFormatException exc) {
            return incorrect("height", exc.getMessage());
        } catch (Exception exc) {
            Logger.logErrorMessage("RollbackChain failed", exc);
            return failure("Unable to rollback chain: " + exc.getMessage());
        }
        break;
    default:
        return unknown(function);
    }
    return response;
}

From source file:it.polimi.diceH2020.SPACE4CloudWS.solvers.solversImpl.QNSolver.QNSolver.java

@Override
protected Pair<List<File>, List<File>> createWorkingFiles(@NonNull SolutionPerJob solutionPerJob)
        throws IOException {
    Pair<List<File>, List<File>> returnValue;

    List<File> jsimgFileList = retrieveInputFiles(solutionPerJob, ".jsimg");

    final String experiment = String.format("%s, class %s, provider %s, VM %s, # %d",
            solutionPerJob.getParentID(), solutionPerJob.getId(), dataProcessor.getProviderName(),
            solutionPerJob.getTypeVMselected().getId(), solutionPerJob.getNumberVM());

    if (jsimgFileList.isEmpty()) {
        logger.debug(String.format("Generating QN model for %s", experiment));
        usingInputModel = false;//w  w w. j ava  2 s . com
        returnValue = generateQNModel(solutionPerJob);
    } else {
        logger.debug(String.format("Using input QN model for %s", experiment));
        usingInputModel = true;

        // TODO now it just takes the first file, I would expect a single file per list
        File inputJsimgFile = jsimgFileList.get(0);

        final String prefix = buildPrefix(solutionPerJob);

        Map<String, String> jsimgFilePlaceholders = new TreeMap<>();
        jsimgFilePlaceholders.put("@@CORES@@",
                Long.toUnsignedString(solutionPerJob.getNumberContainers().longValue()));
        jsimgFilePlaceholders.put("@@CONCURRENCY@@",
                Long.toUnsignedString(solutionPerJob.getNumberUsers().longValue()));
        List<String> outcomes = processPlaceholders(inputJsimgFile, jsimgFilePlaceholders);

        File jsimgFile = fileUtility.provideTemporaryFile(prefix, ".jsimg");
        writeLinesToFile(outcomes, jsimgFile);

        List<File> model = new ArrayList<>(1);
        model.add(jsimgFile);
        returnValue = new ImmutablePair<>(model, new ArrayList<>());
    }

    return returnValue;
}

From source file:sx.blah.discord.handle.impl.obj.Channel.java

/**
 * Makes a request to Discord for message history.
 *
 * @param before The ID of the message to get message history before.
 * @param limit The maximum number of messages to request.
 * @return The received messages./*  w  w  w  . ja  v  a  2 s. co m*/
 */
private IMessage[] getHistory(long before, int limit) {
    PermissionUtils.requirePermissions(this, client.getOurUser(), Permissions.READ_MESSAGES);

    String query = "?before=" + Long.toUnsignedString(before) + "&limit=" + limit;
    MessageObject[] messages = client.REQUESTS.GET.makeRequest(
            DiscordEndpoints.CHANNELS + getStringID() + "/messages" + query, MessageObject[].class);

    return Arrays.stream(messages).map(m -> DiscordUtils.getMessageFromJSON(this, m)).toArray(IMessage[]::new);
}

From source file:it.polimi.diceH2020.SPACE4CloudWS.solvers.solversImpl.SPNSolver.SPNSolver.java

@Override
protected Pair<List<File>, List<File>> createWorkingFiles(@NotNull SolutionPerJob solutionPerJob)
        throws IOException {
    Pair<List<File>, List<File>> returnValue;

    List<File> netFileList = dataProcessor.retrieveInputFiles(".net", solutionPerJob.getParentID(),
            solutionPerJob.getId(), dataProcessor.getProviderName(),
            solutionPerJob.getTypeVMselected().getId());
    List<File> defFileList = dataProcessor.retrieveInputFiles(".def", solutionPerJob.getParentID(),
            solutionPerJob.getId(), dataProcessor.getProviderName(),
            solutionPerJob.getTypeVMselected().getId());
    List<File> statFileList = dataProcessor.retrieveInputFiles(".stat", solutionPerJob.getParentID(),
            solutionPerJob.getId(), dataProcessor.getProviderName(),
            solutionPerJob.getTypeVMselected().getId());

    final String experiment = String.format("%s, class %s, provider %s, VM %s, # %d",
            solutionPerJob.getParentID(), solutionPerJob.getId(), dataProcessor.getProviderName(),
            solutionPerJob.getTypeVMselected().getId(), solutionPerJob.getNumberVM());

    if (netFileList.isEmpty() || defFileList.isEmpty() || statFileList.isEmpty()) {
        logger.debug(String.format("Generating SPN model for %s", experiment));
        usingInputModel = false;/*from   ww  w.ja v  a2s . c  om*/
        returnValue = generateSPNModel(solutionPerJob);
    } else {
        logger.debug(String.format("Using input SPN model for %s", experiment));
        usingInputModel = true;

        // TODO now it just takes the first file, I would expect a single file per list
        File inputNetFile = netFileList.get(0);
        File inputDefFile = defFileList.get(0);
        File inputStatFile = statFileList.get(0);

        String prefix = filePrefix(solutionPerJob);
        final String originalLabel = String.join("", Files.readAllLines(inputStatFile.toPath()));
        label = statSafeLabel;

        Map<String, String> placeHolders = new TreeMap<>();
        placeHolders.put("@@CONCURRENCY@@", Long.toUnsignedString(solutionPerJob.getNumberUsers().longValue()));
        placeHolders.put("@@CORES@@", Long.toUnsignedString(solutionPerJob.getNumberContainers().longValue()));
        logger.trace("@@CORES@@ replaced with " + solutionPerJob.getNumberContainers().toString());
        placeHolders.put(originalLabel, label);
        List<String> outcomes = processPlaceholders(inputDefFile, placeHolders);

        File defFile = fileUtility.provideTemporaryFile(prefix, ".def");
        writeLinesToFile(outcomes, defFile);
        outcomes = processPlaceholders(inputNetFile, placeHolders);

        File netFile = fileUtility.provideTemporaryFile(prefix, ".net");
        writeLinesToFile(outcomes, netFile);

        File statFile = fileUtility.provideTemporaryFile(prefix, ".stat");
        List<String> statContent = new ArrayList<>(1);
        statContent.add(label);
        writeLinesToFile(statContent, statFile);

        List<File> model = new ArrayList<>(3);
        model.add(netFile);
        model.add(defFile);
        model.add(statFile);
        returnValue = new ImmutablePair<>(model, new ArrayList<>());
    }

    return returnValue;
}

From source file:org.apache.metron.pcap.mr.PcapJob.java

public <T> Job createJob(Path basePath, Path outputPath, long beginNS, long endNS, int numReducers, T fields,
        Configuration conf, FileSystem fs, PcapFilterConfigurator<T> filterImpl) throws IOException {
    conf.set(START_TS_CONF, Long.toUnsignedString(beginNS));
    conf.set(END_TS_CONF, Long.toUnsignedString(endNS));
    conf.set(WIDTH_CONF, "" + findWidth(beginNS, endNS, numReducers));
    filterImpl.addToConfig(fields, conf);
    Job job = Job.getInstance(conf);/*from  w w  w  .  ja  va  2  s.  c om*/
    job.setJarByClass(PcapJob.class);
    job.setMapperClass(PcapJob.PcapMapper.class);
    job.setMapOutputKeyClass(LongWritable.class);
    job.setMapOutputValueClass(BytesWritable.class);
    job.setNumReduceTasks(numReducers);
    job.setReducerClass(PcapReducer.class);
    job.setPartitionerClass(PcapPartitioner.class);
    job.setOutputKeyClass(LongWritable.class);
    job.setOutputValueClass(BytesWritable.class);
    Iterable<String> filteredPaths = FileFilterUtil.getPathsInTimeRange(beginNS, endNS,
            listFiles(fs, basePath));
    String inputPaths = Joiner.on(',').join(filteredPaths);
    if (StringUtils.isEmpty(inputPaths)) {
        return null;
    }
    SequenceFileInputFormat.addInputPaths(job, inputPaths);
    job.setInputFormatClass(SequenceFileInputFormat.class);
    job.setOutputFormatClass(SequenceFileOutputFormat.class);
    SequenceFileOutputFormat.setOutputPath(job, outputPath);
    return job;
}

From source file:net.dv8tion.jda.core.entities.impl.JDAImpl.java

@Override
public RestAction<User> retrieveUserById(long id) {
    if (accountType != AccountType.BOT)
        throw new AccountTypeException(AccountType.BOT);

    // check cache
    User user = this.getUserById(id);
    if (user != null)
        return new RestAction.EmptyRestAction<>(this, user);

    Route.CompiledRoute route = Route.Users.GET_USER.compile(Long.toUnsignedString(id));
    return new RestAction<User>(this, route) {
        @Override/*from w w w .jav a  2s  . c om*/
        protected void handleResponse(Response response, Request<User> request) {
            if (!response.isOk()) {
                request.onFailure(response);
                return;
            }
            JSONObject user = response.getObject();
            request.onSuccess(getEntityBuilder().createFakeUser(user, false));
        }
    };
}