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:Main.java

public static void main(String[] args) {
    Long longObject = new Long("1234567");
    int i = longObject.intValue();
    System.out.println("int:" + i);

}

From source file:Main.java

public static void main(String[] args) {
    Long lObj = new Long("10");
    byte b = lObj.byteValue();
    System.out.println(b);/*  w  ww.j  a va2 s .  c  o  m*/

    short s = lObj.shortValue();
    System.out.println(s);

    int i = lObj.intValue();
    System.out.println(i);

    float f = lObj.floatValue();
    System.out.println(f);

    double d = lObj.doubleValue();
    System.out.println(d);
}

From source file:jetbrains.exodus.console.Console.java

public static void main(String[] args) throws IOException, ParseException {
    CommandLine line = getCommandLine(args);

    Long port = (Long) line.getParsedOptionValue("l");
    port = port == null ? 2222 : port;/*from ww w  .ja v  a  2  s.com*/
    String password = line.getOptionValue('p', null);

    Map<String, Object> config = new HashMap<>();
    config.put("location", line.getOptionValue('x', null));

    new RhinoServer(port.intValue(), password, config);
}

From source file:it.jnrpe.client.JNRPEClient.java

/**
 * /*  w  ww  .  j a v  a 2s . c  o m*/
 * @param args
 *            command line arguments
 *             -
 */
public static void main(final String[] args) {

    Parser parser = new Parser();
    parser.setGroup(configureCommandLine());

    CommandLine cli = null;

    try {
        cli = parser.parse(args);

        if (cli.hasOption("--help")) {
            printUsage(null);
        }

        //timeoutAsUnknown = cli.hasOption("--unknown");

        String sHost = (String) cli.getValue("--host");
        final Long port = (Long) cli.getValue("--port", Long.valueOf(DEFAULT_PORT));
        String sCommand = (String) cli.getValue("--command", "_NRPE_CHECK");

        JNRPEClient client = new JNRPEClient(sHost, port.intValue(), !cli.hasOption("--nossl"));
        client.setTimeout(((Long) cli.getValue("--timeout", Long.valueOf(DEFAULT_TIMEOUT))).intValue());

        if (cli.hasOption("--weakCiherSuites")) {
            client.enableWeakCipherSuites();
        }

        @SuppressWarnings("unchecked")
        List<String> argList = cli.getValues("--arglist");
        ReturnValue ret = client.sendCommand(sCommand, argList.toArray(new String[argList.size()]));

        System.out.println(ret.getMessage());
        System.exit(ret.getStatus().intValue());
    } catch (JNRPEClientException exc) {
        Status returnStatus;

        Throwable cause = exc.getCause();
        if (cli.hasOption("--unknown") && cause instanceof SocketTimeoutException) {
            returnStatus = Status.UNKNOWN;
        } else {
            returnStatus = Status.CRITICAL;
        }

        System.out.println(exc.getMessage());
        System.exit(returnStatus.intValue());
    } catch (OptionException oe) {
        printUsage(oe);
    }
}

From source file:com.tiempometa.thingmagic.ReadTest.java

public static void main(String argv[]) {
    // Program setup
    Reader r = null;/* www .  ja  v  a2s. c o m*/
    int nextarg = 0;
    boolean trace = false;

    if (argv.length < 1)
        usage();

    if (argv[nextarg].equals("-v")) {
        trace = true;
        nextarg++;
    }

    // Create Reader object, connecting to physical device
    try {

        TagReadData[] tagReads;
        String uri = argv[nextarg];
        System.out.println("Creating reader with " + uri);
        r = Reader.create(uri);
        System.out.println("Setting trace...");

        // if (trace) {
        // setTrace(r, new String[] { "on" });
        // }
        System.out.println("Connecting...");
        r.connect();
        System.out.println("Connected!");
        if (Reader.Region.UNSPEC == (Reader.Region) r.paramGet("/reader/region/id")) {
            Reader.Region[] supportedRegions = (Reader.Region[]) r
                    .paramGet(TMConstants.TMR_PARAM_REGION_SUPPORTEDREGIONS);
            if (supportedRegions.length < 1) {
                throw new Exception("Reader doesn't support any regions");
            } else {
                r.paramSet("/reader/region/id", supportedRegions[0]);
            }
        }
        r.addReadListener(new TagReadListener());
        int count = 0;
        while (runMe) {
            // Read tags
            tagReads = r.read(500);
            // Print tag reads
            Long password = null;
            Long killword = null;
            for (TagReadData tr : tagReads) {
                p(tr.toString());
                try {
                    String accessCode = readAccess(tr, r);
                    password = Long.parseLong(accessCode, 16);
                    p("Password " + password);
                    p("--" + Long.toHexString(password));
                    accessCode = readKill(tr, r);
                    killword = Long.parseLong(accessCode, 16);
                    p("Killword " + killword);
                    p("--" + Long.toHexString(killword));
                    // if (password == 0) {
                    p("Setting password");
                    password = 0xAFCC01ACl;
                    short[] access = new short[2];
                    access[1] = (short) 0x01AC;
                    access[0] = (short) 0xAFCC;
                    p("Setting password to ");
                    for (short word : access) {
                        System.out.printf("%04X", word);
                    }
                    p("\n");
                    writeAccess(access, tr, r);
                    // }
                    // if (killword == 0) {
                    p("Setting killword");
                    killword = 0xADD001ACl;
                    access = new short[2];
                    access[1] = (short) 0x01AC;
                    access[0] = (short) 0xADD0;
                    p("Setting killword to ");
                    for (short word : access) {
                        System.out.printf("%04X", word);
                    }
                    p("\n");
                    writeKill(access, tr, r);

                    // }
                    if (count < 10) {
                        p("Waiting to lock " + (10 - count));
                    } else if (count == 10) {
                        p("Locking..." + password.intValue());
                        p("--" + Long.toHexString(password));
                        lockTag(password.intValue(), new LockAction(LockAction.KILL_LOCK), tr, r);
                        p("Locked kill");
                        lockTag(password.intValue(), new LockAction(LockAction.ACCESS_LOCK), tr, r);
                        p("Locked access");
                    } else {
                        p("Done with this tag");
                    }
                    count++;
                } catch (ReaderException e) {
                    System.out.println("Exception : " + e.getMessage());
                    killword = 0xADD001ACl;
                    password = 0xAFCC01ACl;
                    if (count < 20) {
                        p("Waiting to unlock " + (20 - count));
                    } else if (count == 20) {
                        p("Unlocking...");
                        p("Password :" + password.intValue());
                        p("--" + Integer.toHexString(password.intValue()));
                        lockTag(password.intValue(), new LockAction(LockAction.ACCESS_UNLOCK), tr, r);
                        p("Unlocked access");
                        lockTag(password.intValue(), new LockAction(LockAction.KILL_UNLOCK), tr, r);
                        p("Unlocked kill");
                        p("***Unlocked");
                        p("Locking...");
                        p("Password :" + password.intValue());
                        lockTag(password.intValue(), new LockAction(LockAction.KILL_LOCK), tr, r);
                        p("Locked kill");
                        lockTag(password.intValue(), new LockAction(LockAction.ACCESS_LOCK), tr, r);
                        p("Locked access");
                    } else if (count == 30) {
                        p("Killing");
                        p("Unlocking access");
                        lockTag(password.intValue(), new LockAction(LockAction.KILL_UNLOCK), tr, r);
                        p("Issuing kill command");
                        killTag(killword.intValue(), tr, r);
                    } else {
                        p("Waiting to kill");
                    }
                    count++;
                }
            }
        }
        // Shut down reader
        r.destroy();
    } catch (ReaderException re) {
        System.out.println("Reader Exception : " + re.getMessage());
    } catch (Exception re) {
        System.out.println("Exception : " + re.getLocalizedMessage());
        System.out.println("Exception : " + re.getMessage());
    } finally {
        r.destroy();
    }
}

From source file:Main.java

private static String generateBrand() {

    Long result = Math.round(Math.random() * 2);

    switch (result.intValue()) {
    case 0:/*from w ww  .  j  a  v a 2 s.co m*/
        return "Heineken";
    case 1:
        return "Grimbergen";
    case 2:
        return "Kriek";
    default:
        break;
    }

    return null;
}

From source file:Main.java

/**
 * @param date//from   w w  w .  j  av  a  2s. c  om
 *            Date for which seconds since the epoch date is to be calculated
 * @return Number of seconds after the unix epoch date equivalent to the given date
 */
public static Integer secondsSinceUnixEpoch(final LocalDateTime date) {
    if (date == null) {
        return null;
    }
    final Long timeInSeconds = Long.valueOf(date.toEpochSecond(ZoneOffset.UTC));
    return Integer.valueOf(timeInSeconds.intValue());
}

From source file:com.google.gsa.valve.modules.utils.CookieManagement.java

/**
 * Transforms Apache cookies into Servlet Cookies
 * /*from   w  w w .  j  a va 2s .  c om*/
 * @param apacheCookie apache cookie 
 * 
 * @return servlet cookie
 */
public static javax.servlet.http.Cookie transformApacheCookie(
        org.apache.commons.httpclient.Cookie apacheCookie) {

    javax.servlet.http.Cookie newCookie = null;

    if (apacheCookie != null) {
        Date expire = apacheCookie.getExpiryDate();
        int maxAge = -1;

        if (expire == null) {
            maxAge = -1;
        } else {
            Date now = Calendar.getInstance().getTime();
            // Convert milli-second to second
            Long second = new Long((expire.getTime() - now.getTime()) / 1000);
            maxAge = second.intValue();
        }

        newCookie = new javax.servlet.http.Cookie(apacheCookie.getName(), apacheCookie.getValue());
        //Hardcoding the domain
        newCookie.setDomain(apacheCookie.getDomain());
        newCookie.setPath(apacheCookie.getPath());
        newCookie.setMaxAge(maxAge);
        newCookie.setSecure(apacheCookie.getSecure());
    }
    return newCookie;
}

From source file:msuresh.raftdistdb.RaftClient.java

public static void SetValue(String name, String key, String value) throws FileNotFoundException {
    if (key == null || key.isEmpty()) {
        return;//  w ww .j a v a  2 s  .  c  o m
    }
    File configFile = new File(Constants.STATE_LOCATION + name + ".info");
    if (!configFile.exists() || configFile.isDirectory()) {
        FileNotFoundException ex = new FileNotFoundException();
        throw ex;
    }
    try {
        System.out.println("Adding key .. hold on..");
        String content = new Scanner(configFile).useDelimiter("\\Z").next();
        JSONObject config = (JSONObject) (new JSONParser()).parse(content);
        Long numPart = (Long) config.get("countPartitions");
        Integer shardId = key.hashCode() % numPart.intValue();
        JSONArray memberJson = (JSONArray) config.get(shardId.toString());
        List<Address> members = new ArrayList<>();
        for (int i = 0; i < memberJson.size(); i++) {
            JSONObject obj = (JSONObject) memberJson.get(i);
            Long port = (Long) obj.get("port");
            String address = (String) obj.get("address");
            members.add(new Address(address, port.intValue()));
        }
        CopycatClient client = CopycatClient.builder(members).withTransport(new NettyTransport()).build();
        client.open().join();
        client.submit(new PutCommand(key, value)).get();
        client.close().join();
        while (client.isOpen()) {
            Thread.sleep(1000);
        }
        System.out.println("key " + key + " with value : " + value + " has been added to the cluster");
    } catch (Exception ex) {
        System.out.println(ex.toString());
    }
}

From source file:msuresh.raftdistdb.RaftClient.java

public static void GetValue(String name, String key) throws FileNotFoundException {
    if (key == null || key.isEmpty()) {
        return;/*  w ww.ja  v a  2s. c  o m*/
    }
    File configFile = new File(Constants.STATE_LOCATION + name + ".info");
    if (!configFile.exists() || configFile.isDirectory()) {
        FileNotFoundException ex = new FileNotFoundException();
        throw ex;
    }
    try {
        System.out.println("Getting key .. Hold on.");
        String content = new Scanner(configFile).useDelimiter("\\Z").next();
        JSONObject config = (JSONObject) (new JSONParser()).parse(content);
        Long numPart = (Long) config.get("countPartitions");
        Integer shardId = key.hashCode() % numPart.intValue();
        JSONArray memberJson = (JSONArray) config.get(shardId.toString());
        List<Address> members = new ArrayList<>();
        for (int i = 0; i < memberJson.size(); i++) {
            JSONObject obj = (JSONObject) memberJson.get(i);
            Long port = (Long) obj.get("port");
            String address = (String) obj.get("address");
            members.add(new Address(address, port.intValue()));
        }
        CopycatClient client = CopycatClient.builder(members).withTransport(new NettyTransport()).build();
        client.open().join();
        Object str = client.submit(new GetQuery(key)).get();
        System.out.println("For the key : " + key + ", the database returned the value : " + (String) str);
        client.close().join();
        while (client.isOpen()) {
            Thread.sleep(1000);
        }
    } catch (Exception ex) {
        System.out.println(ex.toString());
    }
}