Example usage for java.lang Long toString

List of usage examples for java.lang Long toString

Introduction

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

Prototype

public String toString() 

Source Link

Document

Returns a String object representing this Long 's value.

Usage

From source file:com.fengduo.bee.commons.util.NumberParser.java

public static int convertToInt(Long price, int defaultValue) {
    if (price == null) {
        return defaultValue;
    }//from  ww w .j  ava 2 s  . c o  m
    return parseInt(price.toString(), defaultValue);
}

From source file:com.netatmo.weatherstation.api.NetatmoUtils.java

public static HashMap<String, String> parseOAuthResponse(JSONObject response) {
    HashMap<String, String> parsedResponse = new HashMap<String, String>();

    try {//from www.  jav a2s . c  om
        String refreshToken = response.getString("refresh_token");
        parsedResponse.put("refresh_token", refreshToken);

        String accessToken = response.getString("access_token");
        parsedResponse.put("access_token", accessToken);

        String expiresIn = response.getString("expires_in");
        Long expiresAt = System.currentTimeMillis() + Long.valueOf(expiresIn) * 1000;
        parsedResponse.put("expires_at", expiresAt.toString());
    } catch (JSONException e) {
        e.printStackTrace();
    }

    return parsedResponse;
}

From source file:com.loy.MicroServiceConsole.java

static void killProcess() {
    for (Long pid : pids) {
        try {//w ww  .j av a 2s.com
            if (Processes.isProcessRunning(platform, pid)) {
                File pidFile = new File("./pids/" + pid.toString());
                pidFile.deleteOnExit();
                if (Platform.Windows == platform) {
                    Processes.tryKillProcess(null, platform, new NullProcessor(), pid);
                } else {
                    Processes.killProcess(null, platform, new NullProcessor(), pid);
                }
            }
        } catch (Exception ex) {
        }
    }
}

From source file:jp.co.nemuzuka.utils.ConvertUtils.java

/**
 * Long?String??./*  ww  w .j  a v  a2 s  .  c  o  m*/
 * @param targets ??
 * @return ?String?(???null???0??)
 */
public static String[] convert(Long[] targets) {
    if (targets == null) {
        return new String[0];
    }

    List<String> list = new ArrayList<String>();
    for (Long target : targets) {
        list.add(target.toString());
    }
    return list.toArray(new String[0]);
}

From source file:Money.java

public static Money getInfiniteMoney() {
    Long x = Long.MAX_VALUE;
    return new Money(x.toString());
}

From source file:eu.nubomedia.nubomedia_kurento_health_communicator_android.kc_and_communicator.services.CommandService.java

public static CommandObject newCommand(Context ctx, String json, String method, String object) {
    Long tsLong = System.currentTimeMillis() / 1000;
    String ts = tsLong.toString();

    String channelId = ChannelService.getChannelId(ctx);
    String id = ConstantKeys.STRING_DEFAULT + ts;

    String jsonCreated;//  w ww.j ava  2s  .c om
    try {
        jsonCreated = JsonParser.createCommandJson(id, channelId, method, json);
    } catch (JSONException e) {
        log.error("Error creating command", e);
        return null;
    }

    CommandObject command = new CommandObject();
    command.setJson(jsonCreated);
    command.setMedia(object);

    return command;
}

From source file:NTP_Example.java

/**
 * Process <code>TimeInfo</code> object and print its details.
 * @param info <code>TimeInfo</code> object.
 *//*from  w  w  w . j a  v a 2 s . c  o  m*/
public static void processResponse(TimeInfo info) {
    NtpV3Packet message = info.getMessage();
    int stratum = message.getStratum();
    String refType;
    if (stratum <= 0) {
        refType = "(Unspecified or Unavailable)";
    } else if (stratum == 1) {
        refType = "(Primary Reference; e.g., GPS)"; // GPS, radio clock, etc.
    } else {
        refType = "(Secondary Reference; e.g. via NTP or SNTP)";
    }
    // stratum should be 0..15...
    System.out.println(" Stratum: " + stratum + " " + refType);
    int version = message.getVersion();
    int li = message.getLeapIndicator();
    System.out.println(" leap=" + li + ", version=" + version + ", precision=" + message.getPrecision());

    System.out.println(" mode: " + message.getModeName() + " (" + message.getMode() + ")");
    int poll = message.getPoll();
    // poll value typically btwn MINPOLL (4) and MAXPOLL (14)
    System.out.println(
            " poll: " + (poll <= 0 ? 1 : (int) Math.pow(2, poll)) + " seconds" + " (2 ** " + poll + ")");
    double disp = message.getRootDispersionInMillisDouble();
    System.out.println(" rootdelay=" + numberFormat.format(message.getRootDelayInMillisDouble())
            + ", rootdispersion(ms): " + numberFormat.format(disp));

    int refId = message.getReferenceId();
    String refAddr = NtpUtils.getHostAddress(refId);
    String refName = null;
    if (refId != 0) {
        if (refAddr.equals("127.127.1.0")) {
            refName = "LOCAL"; // This is the ref address for the Local Clock
        } else if (stratum >= 2) {
            // If reference id has 127.127 prefix then it uses its own reference clock
            // defined in the form 127.127.clock-type.unit-num (e.g. 127.127.8.0 mode 5
            // for GENERIC DCF77 AM; see refclock.htm from the NTP software distribution.
            if (!refAddr.startsWith("127.127")) {
                try {
                    InetAddress addr = InetAddress.getByName(refAddr);
                    String name = addr.getHostName();
                    if (name != null && !name.equals(refAddr)) {
                        refName = name;
                    }
                } catch (UnknownHostException e) {
                    // some stratum-2 servers sync to ref clock device but fudge stratum level higher... (e.g. 2)
                    // ref not valid host maybe it's a reference clock name?
                    // otherwise just show the ref IP address.
                    refName = NtpUtils.getReferenceClock(message);
                }
            }
        } else if (version >= 3 && (stratum == 0 || stratum == 1)) {
            refName = NtpUtils.getReferenceClock(message);
            // refname usually have at least 3 characters (e.g. GPS, WWV, LCL, etc.)
        }
        // otherwise give up on naming the beast...
    }
    if (refName != null && refName.length() > 1) {
        refAddr += " (" + refName + ")";
    }
    System.out.println(" Reference Identifier:\t" + refAddr);

    TimeStamp refNtpTime = message.getReferenceTimeStamp();
    System.out.println(" Reference Timestamp:\t" + refNtpTime + "  " + refNtpTime.toDateString());

    // Originate Time is time request sent by client (t1)
    TimeStamp origNtpTime = message.getOriginateTimeStamp();
    System.out.println(" Originate Timestamp:\t" + origNtpTime + "  " + origNtpTime.toDateString());

    long destTime = info.getReturnTime();
    // Receive Time is time request received by server (t2)
    TimeStamp rcvNtpTime = message.getReceiveTimeStamp();
    System.out.println(" Receive Timestamp:\t" + rcvNtpTime + "  " + rcvNtpTime.toDateString());

    // Transmit time is time reply sent by server (t3)
    TimeStamp xmitNtpTime = message.getTransmitTimeStamp();
    System.out.println(" Transmit Timestamp:\t" + xmitNtpTime + "  " + xmitNtpTime.toDateString());

    // Destination time is time reply received by client (t4)
    TimeStamp destNtpTime = TimeStamp.getNtpTime(destTime);
    System.out.println(" Destination Timestamp:\t" + destNtpTime + "  " + destNtpTime.toDateString());

    info.computeDetails(); // compute offset/delay if not already done
    Long offsetValue = info.getOffset();
    Long delayValue = info.getDelay();
    String delay = (delayValue == null) ? "N/A" : delayValue.toString();
    String offset = (offsetValue == null) ? "N/A" : offsetValue.toString();

    System.out.println(" Roundtrip delay(ms)=" + delay + ", clock offset(ms)=" + offset); // offset in ms
}

From source file:beans.NTPClient.java

/**
 * Process <code>TimeInfo</code> object and print its details.
 * //from   w  w w .j a v  a 2  s  .co  m
 * @param info
 *          <code>TimeInfo</code> object.
 */
public static void processResponse(TimeInfo info) {
    NtpV3Packet message = info.getMessage();
    int stratum = message.getStratum();
    String refType;
    if (stratum <= 0) {
        refType = "(Unspecified or Unavailable)";
    } else if (stratum == 1) {
        refType = "(Primary Reference; e.g., GPS)"; // GPS, radio clock, etc.
    } else {
        refType = "(Secondary Reference; e.g. via NTP or SNTP)";
    }
    // stratum should be 0..15...
    System.out.println(" Stratum: " + stratum + " " + refType);
    int version = message.getVersion();
    int li = message.getLeapIndicator();
    System.out.println(" leap=" + li + ", version=" + version + ", precision=" + message.getPrecision());

    System.out.println(" mode: " + message.getModeName() + " (" + message.getMode() + ")");
    int poll = message.getPoll();
    // poll value typically btwn MINPOLL (4) and MAXPOLL (14)
    System.out.println(
            " poll: " + (poll <= 0 ? 1 : (int) Math.pow(2, poll)) + " seconds" + " (2 ** " + poll + ")");
    double disp = message.getRootDispersionInMillisDouble();
    System.out.println(" rootdelay=" + numberFormat.format(message.getRootDelayInMillisDouble())
            + ", rootdispersion(ms): " + numberFormat.format(disp));

    int refId = message.getReferenceId();
    String refAddr = NtpUtils.getHostAddress(refId);
    String refName = null;
    if (refId != 0) {
        if (refAddr.equals("127.127.1.0")) {
            refName = "LOCAL"; // This is the ref address for the Local Clock
        } else if (stratum >= 2) {
            // If reference id has 127.127 prefix then it uses its own reference
            // clock
            // defined in the form 127.127.clock-type.unit-num (e.g. 127.127.8.0
            // mode 5
            // for GENERIC DCF77 AM; see refclock.htm from the NTP software
            // distribution.
            if (!refAddr.startsWith("127.127")) {
                try {
                    InetAddress addr = InetAddress.getByName(refAddr);
                    String name = addr.getHostName();
                    if (name != null && !name.equals(refAddr)) {
                        refName = name;
                    }
                } catch (UnknownHostException e) {
                    // some stratum-2 servers sync to ref clock device but fudge stratum
                    // level higher... (e.g. 2)
                    // ref not valid host maybe it's a reference clock name?
                    // otherwise just show the ref IP address.
                    refName = NtpUtils.getReferenceClock(message);
                }
            }
        } else if (version >= 3 && (stratum == 0 || stratum == 1)) {
            refName = NtpUtils.getReferenceClock(message);
            // refname usually have at least 3 characters (e.g. GPS, WWV, LCL, etc.)
        }
        // otherwise give up on naming the beast...
    }
    if (refName != null && refName.length() > 1) {
        refAddr += " (" + refName + ")";
    }
    System.out.println(" Reference Identifier:\t" + refAddr);

    TimeStamp refNtpTime = message.getReferenceTimeStamp();
    System.out.println(" Reference Timestamp:\t" + refNtpTime + "  " + refNtpTime.toDateString());

    // Originate Time is time request sent by client (t1)
    TimeStamp origNtpTime = message.getOriginateTimeStamp();
    System.out.println(" Originate Timestamp:\t" + origNtpTime + "  " + origNtpTime.toDateString());

    long destTime = info.getReturnTime();
    // Receive Time is time request received by server (t2)
    TimeStamp rcvNtpTime = message.getReceiveTimeStamp();
    System.out.println(" Receive Timestamp:\t" + rcvNtpTime + "  " + rcvNtpTime.toDateString());

    // Transmit time is time reply sent by server (t3)
    TimeStamp xmitNtpTime = message.getTransmitTimeStamp();
    System.out.println(" Transmit Timestamp:\t" + xmitNtpTime + "  " + xmitNtpTime.toDateString());

    // Destination time is time reply received by client (t4)
    TimeStamp destNtpTime = TimeStamp.getNtpTime(destTime);
    System.out.println(" Destination Timestamp:\t" + destNtpTime + "  " + destNtpTime.toDateString());

    info.computeDetails(); // compute offset/delay if not already done
    Long offsetValue = info.getOffset();
    Long delayValue = info.getDelay();
    String delay = (delayValue == null) ? "N/A" : delayValue.toString();
    String offset = (offsetValue == null) ? "N/A" : offsetValue.toString();

    System.out.println(" Roundtrip delay(ms)=" + delay + ", clock offset(ms)=" + offset); // offset
                                                                                          // in
                                                                                          // ms
}

From source file:com.google.api.server.spi.response.ServletResponseResultWriter.java

private static SimpleModule getWriteLongAsStringModule() {
    JsonSerializer<Long> longSerializer = new JsonSerializer<Long>() {
        @Override//  w  ww. j  a v  a 2s .  co  m
        public void serialize(Long value, JsonGenerator jgen, SerializerProvider provider) throws IOException {
            jgen.writeString(value.toString());
        }
    };
    SimpleModule writeLongAsStringModule = new SimpleModule("writeLongAsStringModule",
            new Version(1, 0, 0, null, null, null));
    writeLongAsStringModule.addSerializer(Long.TYPE, longSerializer); // long (primitive)
    writeLongAsStringModule.addSerializer(Long.class, longSerializer); // Long (class)
    return writeLongAsStringModule;
}

From source file:de.cismet.lagis.cidsmigtest.StandartTypToStringTester.java

/**
 * DOCUMENT ME!//  w  w w  . jav a 2 s  .co  m
 *
 * @param   object  DOCUMENT ME!
 *
 * @return  DOCUMENT ME!
 */
public static String getStringOf(final Long object) {
    if (object == null) {
        return null;
    } else {
        return "(Long) " + object.toString();
    }
}