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

public static String formatStringTwoDecPercent(float number) {
    NumberFormat formatter = NumberFormat.getNumberInstance();
    formatter.setMinimumFractionDigits(0);
    formatter.setMaximumFractionDigits(2);

    return String.valueOf(formatter.format(number) + "%");
}

From source file:Main.java

@SuppressWarnings("unused")
public static String getRandomNumber(int count) {
    Random rdm = new Random(System.currentTimeMillis());
    String random = "";
    for (int i = 0; i < count; i++) {
        String str = String.valueOf((int) (Math.random() * 10 - 1));
        random = random + str;/* w w w .  ja v  a  2  s.  c  om*/
    }
    return random;
}

From source file:org.openmrs.module.omodexport.util.OmodExportUtil.java

/**
 * Utility method which checks the type of export and calls the appropriate method
 * /*www  .ja  v a 2 s  .c  o m*/
 * @param moduleId -The id of the module to export or a dash separated sting of module Id's to
 *            do the export
 * @param exportType -One of the possible export types (SINGLE,CUSTOM,WITH_DEPENDECIES or ALL)
 * @param response
 * @throws IOException
 */
public static void doExport(String moduleId, String exportType, HttpServletResponse response)
        throws IOException {

    switch (ExportType.valueOf(exportType)) {
    case SINGLE:
        exportSingleModule(ModuleFactory.getModuleById(moduleId), response);
        break;

    case ALL:
        exportAllModules(response);
        break;

    case WITH_DEPENDECIES:
        exportModuleWithDependecies(ModuleFactory.getModuleById(moduleId), response);
        break;

    case CUSTOM:
        exportSelectedModules(moduleId, response);
        break;

    default:
        log.info("Unable to find an export type");
        break;
    }

}

From source file:Main.java

public static String objectToString(Object obj) {
    if (obj == null) {
        return "";
    }//from w  w w .j  a v  a 2  s  . c  o m
    String string = "";
    if (obj instanceof String) {
        string = (String) obj;
    }
    try {
        string = String.valueOf(obj);
    } catch (Exception e) {
        e.printStackTrace();
    }
    if (string.equals("null")) {
        string = "";
    }
    return string;
}

From source file:Main.java

public static String getScores(int home_goals, int awaygoals) {
    if (home_goals < 0 || awaygoals < 0) {
        return DEFAULT_SCORE;
    } else {/*from  w  w  w .j  a  va2  s .c  o m*/
        return String.valueOf(home_goals) + " - " + String.valueOf(awaygoals);
    }
}

From source file:Main.java

public static String generateNonce() {
    long l = c.nextLong();
    int i = (int) (System.currentTimeMillis() / 60000L);
    return (new StringBuilder(String.valueOf(l))).append(":").append(i).toString();
}

From source file:Main.java

public static String getAbsoluteTime() {
    mAbsTime = System.currentTimeMillis();
    //        String absoluteTime = getTimeInSalLogFormat(mAbsTime);
    //        Log.i(LOG_TAG, "ABSOLUTE_TIME : " + absoluteTime);
    return String.valueOf(mAbsTime);
}

From source file:Main.java

/**
 * //from w  ww  . j  a  v  a 2  s.  c o  m
 * @description getStringDateFromYmd
 * @param year
 * @param month
 * @param day
 * @return 2014-08-30
 * @exception
 */
public static String getStringDateFromYmd(int year, int month, int day) {
    String y = String.valueOf(year);
    String m = String.valueOf(month);
    if (month < 10) {
        m = "0" + m;
    }
    String d = String.valueOf(day);
    if (day < 10) {
        d = "0" + d;
    }
    return y + "-" + m + "-" + d;
}

From source file:Main.java

public static String setStringNotNull(String stringRes) {
    if (stringRes == null || stringRes.isEmpty()) {
        return "";
    }//from  w  w  w  .ja v  a  2s.  c  o m

    //Convert Non_breaking (ASCI 160) to Simple Space. trim() does'nt handle it.
    stringRes = stringRes.replace(String.valueOf((char) 160), " ");

    String tempString = stringRes.trim();
    return tempString;
}

From source file:Main.java

public static String collectionJoinElements(Collection collection, String split) {
    StringBuilder builder = new StringBuilder();

    int count = 0;
    for (Object object : collection) {
        builder.append(String.valueOf(object));
        count++;/*from  w w w .  ja va 2s  .  c o  m*/
        if (count < collection.size()) {
            builder.append(split);
        }
    }

    return builder.toString();
}