Example usage for java.lang Long intValue

List of usage examples for java.lang Long intValue

Introduction

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

Prototype

public int intValue() 

Source Link

Document

Returns the value of this Long as an int after a narrowing primitive conversion.

Usage

From source file:dbcount.DBCountPageView.java

private static long initialize(GridClient grid, DBMapReduceJobConf jobConf) throws Exception {
    Long pageview = grid.execute(DbCountInitializeJob.class, jobConf);
    return pageview.intValue();
}

From source file:com.github.dynamo.torrent.parser.TorrentProcessor.java

/**
 * Given a Map, retrieve all useful information and represent it as a TorrentFile object
 * @param m Map/*w ww.ja  v a2s .co m*/
 * @return TorrentFile
 */
private static TorrentFile getTorrentFile(Map m) {
    if (m == null)
        return null;

    TorrentFile torrent = new TorrentFile();

    if (m.containsKey("announce")) // mandatory key
        torrent.announceURL = new String((byte[]) m.get("announce"));
    else
        return null;
    if (m.containsKey("comment")) // optional key
        torrent.comment = new String((byte[]) m.get("comment"));
    if (m.containsKey("created by")) // optional key
        torrent.createdBy = new String((byte[]) m.get("created by"));
    if (m.containsKey("creation date")) // optional key
        torrent.creationDate = (Long) m.get("creation date");
    if (m.containsKey("encoding")) // optional key
        torrent.encoding = new String((byte[]) m.get("encoding"));

    //Store the info field data
    if (!m.containsKey("info")) {
        return null;
    }

    Map info = (Map) m.get("info");
    try {

        torrent.info_hash_as_binary = TorrentUtils.hash(BEncoder.encode(info));
        torrent.info_hash_as_hex = TorrentUtils.byteArrayToByteString(torrent.info_hash_as_binary);
        torrent.info_hash_as_url = TorrentUtils.byteArrayToURLString(torrent.info_hash_as_binary);
    } catch (IOException ioe) {
        return null;
    }
    if (info.containsKey("name"))
        torrent.saveAs = new String((byte[]) info.get("name"));
    if (info.containsKey("piece length"))
        torrent.pieceLength = ((Long) info.get("piece length")).intValue();
    else
        return null;

    if (info.containsKey("pieces")) {
        byte[] piecesHash2 = (byte[]) info.get("pieces");
        if (piecesHash2.length % 20 != 0)
            return null;

        for (int i = 0; i < piecesHash2.length / 20; i++) {
            byte[] temp = TorrentUtils.subArray(piecesHash2, i * 20, 20);
            torrent.piece_hash_values_as_binary.add(temp);
            torrent.piece_hash_values_as_hex.add(TorrentUtils.byteArrayToByteString(temp));
            torrent.piece_hash_values_as_url.add(TorrentUtils.byteArrayToURLString(temp));
        }
    } else
        return null;

    if (info.containsKey("files")) {
        List<Map> multFiles = (List<Map>) info.get("files");
        torrent.total_length = 0;
        for (int i = 0; i < multFiles.size(); i++) {

            Map currentFile = multFiles.get(i);

            Long length = (Long) currentFile.get("length");

            torrent.length.add(length);
            torrent.total_length += length.intValue();

            List path = (List) currentFile.get("path");
            String filePath = "";
            for (int j = 0; j < path.size(); j++) {
                if (StringUtils.isNotEmpty(filePath)) {
                    filePath += "/";
                }
                filePath += new String((byte[]) path.get(j));
            }
            torrent.fileNames.add(filePath);
        }
    } else {
        torrent.length.add((Long) info.get("length"));
        torrent.total_length = (Long) info.get("length");
        torrent.fileNames.add(new String((byte[]) info.get("name")));
    }

    return torrent;
}

From source file:org.spring.data.gemfire.cache.ClientCacheConnectedToMultipleDistributedSystemsTest.java

protected static int intValue(Long value) {
    return value.intValue();
}

From source file:org.spc.ofp.observer.domain.TripIdRepository.java

private static String buildGearAndYearQuery(final Long limit, String... years) {
    final StringBuilder sb = new StringBuilder(GEAR_AND_YEAR_QUERY);
    if (null != years && years.length > 0) {
        final Joiner joiner = Joiner.on(" OR ").skipNulls();
        sb.append(" AND (").append(joiner.join(years)).append(")");
    }//from  www .  j  av a 2  s  .c om
    if (null != limit && limit.longValue() > 0L) {
        sb.append(" LIMIT ").append(limit.intValue());
    }
    return sb.toString();
}

From source file:eu.trentorise.smartcampus.protocolcarrier.Communicator.java

public static MessageResponse call(MessageRequest msgRequest, String appToken, String authToken,
        Long responseTimeout) throws ConnectionException, ProtocolException, SecurityException {
    MessageResponse msgResponse = null;/*from   w ww.jav a  2  s  .  c  o  m*/

    try {
        HttpClient httpClient;

        if (responseTimeout != null && responseTimeout > 0) {
            HttpParams httpParameters = new BasicHttpParams();
            HttpConnectionParams.setConnectionTimeout(httpParameters, responseTimeout.intValue());
            HttpConnectionParams.setSoTimeout(httpParameters, responseTimeout.intValue());
            httpClient = HttpsClientBuilder.getNewHttpClient(httpParameters);
        } else {
            httpClient = HttpsClientBuilder.getNewHttpClient(null);
        }

        HttpRequestBase request = buildRequest(msgRequest, appToken, authToken);

        HttpResponse response = httpClient.execute(request);

        int status = response.getStatusLine().getStatusCode();

        if (status == Constants.CODE_SECURITY_ERROR) {
            throw new SecurityException("Invalid token");
        }
        if (status != 200) {
            throw new ProtocolException("Internal error: " + status);
        }

        long timestamp = AndroidHttpClient
                .parseDate(response.getFirstHeader(ResponseHeader.DATE.toString()).getValue());
        msgResponse = new MessageResponse(status, timestamp);

        // file
        if (msgRequest.isRequestFile()) {
            msgResponse.setFileContent(Utils.responseContentToByteArray(response.getEntity().getContent()));
        } else {

            // content
            String result = Utils.responseContentToString(response.getEntity().getContent());
            if (result != null) {
                msgResponse.setBody(result);
            }
        }
    } catch (SecurityException e) {
        throw e;
    } catch (SocketTimeoutException e) {
        throw new ConnectionException(e.getMessage());
    } catch (ClientProtocolException e) {
        throw new ProtocolException(e.getMessage());
    } catch (IOException e) {
        e.printStackTrace();
        throw new ConnectionException(e.getMessage());
    } catch (URISyntaxException e) {
        throw new ProtocolException(e.getMessage());
    } catch (Exception e) {
        e.printStackTrace();
        throw new ProtocolException(e.getMessage());
    }

    return msgResponse;
}

From source file:com.ibm.streamsx.topology.test.splpy.PythonFunctionalOperatorsTest.java

public static SPLStream sampleFilterStream(Topology topology) {
    TStream<Long> beacon = BeaconStreams.longBeacon(topology, TEST_TUPLES.length);

    return SPLStreams.convertStream(beacon, new BiFunction<Long, OutputTuple, OutputTuple>() {
        private static final long serialVersionUID = 1L;

        @Override/*from   w ww.j a  v  a 2  s. com*/
        public OutputTuple apply(Long v1, OutputTuple v2) {
            v2.assign(TEST_TUPLES[v1.intValue()]);
            return v2;
        }
    }, TEST_SCHEMA_SF);
}

From source file:com.galenframework.utils.GalenUtils.java

private static int obtainVerticalScrollPosition(WebDriver driver) {
    Long scrollLong = (Long) ((JavascriptExecutor) driver).executeScript(
            "return (window.pageYOffset !== undefined) ? window.pageYOffset : (document.documentElement || document.body.parentNode || document.body).scrollTop;");
    return scrollLong.intValue();
}

From source file:com.buaa.cfs.security.ShellBasedIdMapping.java

/**
 * uid and gid are defined as uint32 in linux. Some systems create (intended or unintended) <nfsnobody, 4294967294>
 * kind of <name,Id> mapping, where 4294967294 is 2**32-2 as unsigned int32. As an example,
 * https://bugzilla.redhat.com/show_bug.cgi?id=511876. Because user or group id are treated as Integer (signed
 * integer or int32) here, the number 4294967294 is out of range. The solution is to convert uint32 to int32, so to
 * map the out-of-range ID to the negative side of Integer, e.g. 4294967294 maps to -2 and 4294967295 maps to -1.
 *///from   ww  w .  j  av a2s .com
private static Integer parseId(final String idStr) {
    Long longVal = Long.parseLong(idStr);
    int intVal = longVal.intValue();
    return Integer.valueOf(intVal);
}

From source file:com.github.jessemull.microflex.util.IntegerUtil.java

/**
 * Safely converts a number to an integer. Loss of precision may occur. Throws
 * an arithmetic exception upon overflow.
 * @param    Object    number to parse//from ww w . j  a va  2  s  .com
 * @return             parsed number
 * @throws   ArithmeticException    on overflow
 */
public static int toInteger(Object obj) {

    /* Switch on class and convert to an int */

    String type = obj.getClass().getSimpleName();
    int parsed;

    switch (type) {

    case "Byte":
        Byte by = (Byte) obj;
        parsed = by.intValue();
        break;

    case "Short":
        Short sh = (Short) obj;
        parsed = sh.intValue();
        break;

    case "Integer":
        Integer in = (Integer) obj;
        parsed = in.intValue();
        break;

    case "Long":
        Long lo = (Long) obj;
        if (!OverFlowUtil.intOverflow(lo)) {
            throw new ArithmeticException("Overflow casting " + obj + " to an int.");
        }
        parsed = lo.intValue();
        break;

    case "Float":
        Float fl = (Float) obj;
        if (!OverFlowUtil.intOverflow(fl)) {
            throw new ArithmeticException("Overflow casting " + obj + " to an int.");
        }
        parsed = fl.intValue();
        break;

    case "BigInteger":
        BigInteger bi = (BigInteger) obj;
        if (!OverFlowUtil.intOverflow(bi)) {
            throw new ArithmeticException("Overflow casting " + obj + " to an int.");
        }
        parsed = bi.intValue();
        break;

    case "BigDecimal":
        BigDecimal bd = (BigDecimal) obj;
        if (!OverFlowUtil.intOverflow(bd)) {
            throw new ArithmeticException("Overflow casting " + obj + " to an int.");
        }
        parsed = bd.intValue();
        break;

    case "Double":
        Double db = (Double) obj;
        if (!OverFlowUtil.intOverflow(db)) {
            throw new ArithmeticException("Overflow casting " + obj + " to an int.");
        }
        parsed = db.intValue();
        break;

    default:
        throw new IllegalArgumentException(
                "Invalid type: " + type + "\nData values " + "must extend the abstract Number class.");

    }

    return parsed;
}

From source file:com.github.jessemull.microflex.util.IntegerUtil.java

/**
 * Safely converts a number to an integer. Loss of precision may occur. Throws
 * an arithmetic exception upon overflow.
 * @param    Number    number to parse/*from w w  w .  jav a  2  s . c  om*/
 * @return             parsed number
 * @throws   ArithmeticException    on overflow
 */
public static int toInteger(Number number) {

    /* Switch on class and convert to an int */

    String type = number.getClass().getSimpleName();
    int parsed;

    switch (type) {

    case "Byte":
        Byte by = (Byte) number;
        parsed = by.intValue();
        break;

    case "Short":
        Short sh = (Short) number;
        parsed = sh.intValue();
        break;

    case "Integer":
        Integer in = (Integer) number;
        parsed = in.intValue();
        break;

    case "Long":
        Long lo = (Long) number;
        if (!OverFlowUtil.intOverflow(lo)) {
            throw new ArithmeticException("Overflow casting " + number + " to an int.");
        }
        parsed = lo.intValue();
        break;

    case "Float":
        Float fl = (Float) number;
        if (!OverFlowUtil.intOverflow(fl)) {
            throw new ArithmeticException("Overflow casting " + number + " to an int.");
        }
        parsed = fl.intValue();
        break;

    case "BigInteger":
        BigInteger bi = (BigInteger) number;
        if (!OverFlowUtil.intOverflow(bi)) {
            throw new ArithmeticException("Overflow casting " + number + " to an int.");
        }
        parsed = bi.intValue();
        break;

    case "BigDecimal":
        BigDecimal bd = (BigDecimal) number;
        if (!OverFlowUtil.intOverflow(bd)) {
            throw new ArithmeticException("Overflow casting " + number + " to an int.");
        }
        parsed = bd.intValue();
        break;

    case "Double":
        Double db = (Double) number;
        if (!OverFlowUtil.intOverflow(db)) {
            throw new ArithmeticException("Overflow casting " + number + " to an int.");
        }
        parsed = db.intValue();
        break;

    default:
        throw new IllegalArgumentException(
                "Invalid type: " + type + "\nData values " + "must extend the abstract Number class.");

    }

    return parsed;
}