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 static String toString(long i) 

Source Link

Document

Returns a String object representing the specified long .

Usage

From source file:Main.java

/**
 * Generate a random message-id header for locally-generated messages.
 *///from w ww  .  j a va 2s.c o  m
public static String generateMessageId() {
    StringBuffer sb = new StringBuffer();
    sb.append("<");
    for (int i = 0; i < 24; i++) {
        sb.append(Integer.toString((int) (Math.random() * 35), 36));
    }
    sb.append(".");
    sb.append(Long.toString(System.currentTimeMillis()));
    sb.append("@email.android.com>");
    return sb.toString();
}

From source file:Main.java

/**
 * Convert company prefix to string of length according to partition
 *
 * @param companyPrefix cp//from ww  w  .j  a v a2s .c  om
 * @param partition     p
 * @return Company prefix string
 * @throws Exception
 */
private static String getCompanyPrefixString(long companyPrefix, byte partition) throws Exception {
    String result = Long.toString(companyPrefix);
    int length;
    switch (partition) {
    case 0:
        length = 12;
        break;
    case 1:
        length = 11;
        break;
    case 2:
        length = 10;
        break;
    case 3:
        length = 9;
        break;
    case 4:
        length = 8;
        break;
    case 5:
        length = 7;
        break;
    case 6:
        length = 6;
        break;
    default:
        throw new Exception("Unknown partition: " + partition);
    }
    while (result.length() < length)
        result = "0" + result;
    return result;
}

From source file:Main.java

public static Intent createShortcutIntent(String url) {
    Intent shortcutIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
    long urlHash = url.hashCode();
    long uniqueId = (urlHash << 32) | shortcutIntent.hashCode();
    shortcutIntent.putExtra(Browser.EXTRA_APPLICATION_ID, Long.toString(uniqueId));
    return shortcutIntent;
}

From source file:Main.java

public static void contentLongSet(Document doc, Element base, String name, long value, long defaultLong) {
    if (value != defaultLong) {
        addElementAndSetContent(doc, name, base, Long.toString(value));
    }//from   w  ww .j  a v a2s.com
}

From source file:Main.java

public static String formatFromSize(long size) {
    if (size == -1)
        return "";
    String suffix = " B";
    if (size >= 1024) {
        suffix = " KB";
        size /= 1024;//from   ww w  . ja v a  2s  .co m
        if (size >= 1024) {
            suffix = " MB";
            size /= 1024;
        }
    }

    StringBuilder resultBuffer = new StringBuilder(Long.toString(size));

    int commaOffset = resultBuffer.length() - 3;
    while (commaOffset > 0) {
        resultBuffer.insert(commaOffset, ',');
        commaOffset -= 3;
    }

    if (suffix != null)
        resultBuffer.append(suffix);
    return resultBuffer.toString();
}

From source file:Main.java

public static String getBalanceDisplay(String bal, int floatSize) {
    if ("".equals(bal)) {
        return "";
    } else {/*from www.  ja  v  a2  s  . co m*/
        long amount = Long.parseLong(bal);
        NumberFormat format = NumberFormat.getInstance();
        if (NumEmpty == amount)
            return "";
        if (floatSize < 0) { // error input
            return Long.toString(amount);
        }
        if (floatSize == 2) {
            boolean zs = true;
            if (amount < 0) {
                zs = false;
                amount = -amount;
            }
            long m = amount / 100;
            long f = amount - m * 100;
            return (zs ? "" : "-") + format.format(m) + "." + (f > 9 ? Long.toString(f) : "0" + f);
        } else if (floatSize == 0) {
            return format.format(amount);
        } else { // error input
            return format.format(amount);
        }
    }
}

From source file:Main.java

/**
 * elapsedTimeDisplay// w  w  w  .  j a va 2  s  . co m
 * Get the elapsed time between two dates in readable format
 *
 * @param dateStart the date start
 * @param dateEnd   the date end
 * @return the elapsed hours and minutes
 */
public static String elapsedTimeDisplay(Date dateStart, Date dateEnd) {
    long diff = dateEnd.getTime() - dateStart.getTime();
    long diffMinutes = diff / (60 * 1000) % 60;
    long diffHours = diff / (60 * 60 * 1000);
    String mins = Long.toString(diffMinutes);
    if (mins.length() == 1) {
        mins = "0" + mins;
    }
    return Long.toString(diffHours) + ":" + mins;
}

From source file:Main.java

public static String long2String(long l, int minDigits) {
    StringBuilder s = new StringBuilder(minDigits);
    s.append(Long.toString(l));
    while (s.length() < minDigits) {
        s.insert(0, "0");
    }//from w  ww  . jav  a  2  s . c  o  m
    return s.toString();
}

From source file:Main.java

public static String formatSize(long fileSize) {
    if (fileSize > GIGA) {
        return mFmt.format((double) fileSize / GIGA) + "GB";
    } else if (fileSize > MEGA) {
        return mFmt.format((double) fileSize / MEGA) + "MB";
    } else if (fileSize > KILO) {
        return mFmt.format((double) fileSize / KILO) + "KB";
    } else {// w  w  w . ja  v  a  2 s.c om
        return Long.toString(fileSize) + "B";
    }
}

From source file:Main.java

/**
 * Adds a new element containing a CDATA section with the specified value to the parent element.
 * @param parent the parent element to add the new element to
 * @param namespaceURI the namespace of the added element's tag name, or null if there isn't any..
 * @param tag the tag name of the new element
 * @param value the value to store in the CDATA section of the new element
 *///  w  ww .j  a  v  a  2s  . c o  m
public static void addLongElementNS(Element parent, String namespaceURI, String tag, long value) {
    addTextElementNS(parent, namespaceURI, tag, Long.toString(value));
}