Example usage for java.lang String valueOf

List of usage examples for java.lang String valueOf

Introduction

In this page you can find the example usage for java.lang String valueOf.

Prototype

public static String valueOf(double d) 

Source Link

Document

Returns the string representation of the double argument.

Usage

From source file:Main.java

/**
 * Returns String format of integer with padding of 2 digits.
 * /*from  ww w . ja v a  2s.c  o m*/
 * @param number
 *            the number to format
 * @return the String format of the given number.
 */
public static String pad(int c) {
    if (c >= 10) {
        return String.valueOf(c);
    } else {
        return "0" + c;
    }
}

From source file:Main.java

public static String formatNumber(int number) {

    String string = new String();

    if (number < 10) {
        string = "00" + number;
    } else if (number >= 10 && number < 100) {
        string = "0" + number;
    } else {// w ww  .  j  a va2 s . c  o m
        string = String.valueOf(number);
    }

    return string;
}

From source file:Main.java

/**
 * get the current sessionID String// w  ww .j ava2s.c o m
 * @return the current sessionID string, if session is smaller than 0, then return null
 */
public static String getSessionString() {
    if (sessionId > 0)
        return String.valueOf(getSessionID());
    return null;
}

From source file:com.painiu.webapp.util.PhotoUtils.java

public static License getLicense(HttpServletRequest request) {
    String license = request.getParameter("license");
    if (license == null || "".equals(license)) {
        return License.ATTRIBUTION_NONCOMMERCIAL_SHAREALIKE;
    }/*w  ww . j a v  a2  s. com*/
    return License.valueOf(Integer.valueOf(license).intValue());
}

From source file:Main.java

public static void setIntegerAttribute(Element node, String attr, int value) {
    lastState = DONE;/*w w  w  .  j a v  a 2 s  .  co  m*/
    try {
        node.setAttribute(attr, String.valueOf(value));
    } catch (NumberFormatException ex) {
        lastState = ERROR;
    }
}

From source file:Main.java

public static String cloneString(final String toClone) {
    if (toClone == null) {
        return null;
    }/*w  w w .j a  v a2s .c o  m*/
    if (toClone.isEmpty()) {
        return new String("").concat(new String(""));
    }

    if (toClone.length() == 1) {
        return String.valueOf(toClone.charAt(0));
    }

    return toClone.substring(0, 1) + toClone.substring(1);
}

From source file:Main.java

public static void latencyLog(String data) {
    data = data.substring(data.indexOf("time-") + 5);
    long started = Long.parseLong(data);
    long current = System.currentTimeMillis();
    Log.i("Latency", String.valueOf(current - started));

}

From source file:de.itsvs.cwtrpc.core.pattern.PatternFactory.java

public static Pattern compile(String patternType, MatcherType matcherType, String pattern)
        throws IllegalArgumentException {
    final PatternType convertedPatternType;

    Assert.notNull(patternType, "'patternType' must not be null");
    try {/*from   w  w  w  .  jav  a 2s . co m*/
        convertedPatternType = PatternType.valueOf(patternType.toUpperCase());
    } catch (IllegalArgumentException e) {
        throw new IllegalArgumentException("Pattern type '" + patternType + "' is unsupported");
    }

    return compile(convertedPatternType, matcherType, pattern);
}

From source file:Main.java

public static String formatTo2Bit(int num) {

    if (num < 10) {

        StringBuffer sb;/*from w  w w  .  j  ava 2 s . co m*/

        sb = new StringBuffer("0");
        sb.append(num);

        return sb.toString();
    } else {

        return String.valueOf(num);
    }
}

From source file:Main.java

public static String getTimeStampString(Long timestampInSeconds) {
    long tsLongNow = System.currentTimeMillis() / 1000;
    long timeInSeconds = tsLongNow - timestampInSeconds;
    String timestampString;//w w  w .j a v a  2s .  c  o  m
    if (timeInSeconds < 60) {
        timestampString = String.valueOf(timeInSeconds) + "s";
    } else if (timeInSeconds < 60 * 60) {
        long timeInMins = timeInSeconds / 60;
        timestampString = String.valueOf(timeInMins) + "m";
    } else if (timeInSeconds < 60 * 60 * 24) {
        long timeInHrs = timeInSeconds / 60 / 60;
        timestampString = String.valueOf(timeInHrs) + "h";
    } else {
        long timeInDays = timeInSeconds / 60 / 60 / 24;
        timestampString = String.valueOf(timeInDays) + "d";
    }
    return timestampString;
}