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

/**
 * Generalize integer number with specific separator and segment length.
 * @param number/*w ww. j a  v a 2s .c  o  m*/
 * @param separator Eg. "," or "." ...
 * @param segmentLenght
 * @return
 */
public static String generalizeIntegerNumber(long number, String separator, int segmentLenght) {
    return generalizeIntegerNumber(String.valueOf(number), separator, segmentLenght);
}

From source file:edu.ku.brc.af.ui.forms.validation.UIValidator.java

/**
 * Parse string for Type and return None if there is a parse error
 * @param type the string with the Type//from w w w  .  ja v  a  2s.c om
 * @return the Type
 */
public static Type parseValidationType(final String type) {
    if (isNotEmpty(type)) {
        try {
            return Type.valueOf(type);

        } catch (Exception ex) {
            edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount();
            edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(UIValidator.class, ex);
            return Type.OK;
        }
    }
    // else
    return Type.OK;
}

From source file:Main.java

/**
 * DOC bZhou Comment method "computePercent".
 * /*w  ww.j a va 2 s .co m*/
 * @param userCount
 * @param count
 * @return
 */
private static String computePercent(double userCount, double count) {
    double result = userCount / count;
    return result != Double.NaN ? String.valueOf(result) : null;
}

From source file:at.ait.dme.yuma.suite.apps.core.server.annotation.JSONAnnotationHandler.java

public static ArrayList<Annotation> parseAnnotations(String json) {
    ArrayList<Annotation> annotations = new ArrayList<Annotation>();
    JSONArray jsonArray = (JSONArray) JSONValue.parse(json);

    if (jsonArray == null)
        return annotations;

    for (Object obj : jsonArray) {
        JSONObject jsonObj = (JSONObject) obj;
        Annotation annotation;/*from  w ww. j  av a2 s. c  o m*/

        MediaType type = MediaType.valueOf(((String) jsonObj.get(KEY_MEDIA_TYPE)).toUpperCase());
        String fragment = (String) jsonObj.get(KEY_FRAGMENT);
        if (type == MediaType.IMAGE || type == MediaType.MAP) {
            annotation = new ImageAnnotation();

            if ((fragment != null) && (!fragment.isEmpty())) {
                SVGFragmentHandler svg = new SVGFragmentHandler();
                try {
                    annotation.setFragment(svg.toImageFragment((String) jsonObj.get(KEY_FRAGMENT)));
                } catch (IOException e) {
                    logger.warn("Could not parse image fragment: " + e.getMessage());
                }
            }
        } else if (type == MediaType.AUDIO) {
            annotation = new AudioAnnotation();

            if ((fragment != null) && (!fragment.isEmpty())) {
                AudioFragmentHandler afh = new AudioFragmentHandler();
                annotation.setFragment(afh.parseAudioFramgent(fragment));
            }

        } else {
            throw new RuntimeException("Unsupported annotation type: " + type.name());
        }

        annotation.setId((String) jsonObj.get(KEY_ID));
        annotation.setParentId((String) jsonObj.get(KEY_PARENT_ID));
        annotation.setRootId((String) jsonObj.get(KEY_ROOT_ID));
        annotation.setObjectUri((String) jsonObj.get(KEY_OBJECT_URI));
        annotation.setCreated(new Date((Long) jsonObj.get(KEY_CREATED)));
        annotation.setLastModified(new Date((Long) jsonObj.get(KEY_LAST_MODIFIED)));
        annotation.setCreatedBy(parseUser((JSONObject) jsonObj.get(KEY_CREATED_BY)));
        annotation.setTitle((String) jsonObj.get(KEY_TITLE));
        annotation.setText((String) jsonObj.get(KEY_TEXT));
        annotation.setMediaType(type);

        String scope = (String) jsonObj.get(KEY_SCOPE);
        if (scope != null) {
            annotation.setScope(Scope.valueOf(scope.toUpperCase()));
        } else {
            annotation.setScope(Scope.PUBLIC);
        }

        JSONArray jsonTags = (JSONArray) jsonObj.get(KEY_TAGS);
        if (jsonTags != null)
            annotation.setTags(parseSemanticTags(jsonTags));

        JSONArray jsonReplies = (JSONArray) jsonObj.get(KEY_REPLIES);
        if (jsonReplies != null) {
            ArrayList<Annotation> replies = parseAnnotations(jsonReplies.toString());
            annotation.setReplies(replies);
        }

        annotations.add(annotation);
    }
    return annotations;
}

From source file:Main.java

public static String getMonth(final Date date) {
    if (date != null) {
        Calendar calendar = Calendar.getInstance();
        TimeZone timeZone = TimeZone.getTimeZone("GMT+8");
        calendar.setTimeZone(timeZone);//from  w ww  . j  av a 2 s . c  o  m
        calendar.setTime(date);
        return String.valueOf(calendar.get(Calendar.MONTH) + 1);
    }
    return "0";
}

From source file:Main.java

public static String formatBytes(int bytesCount) {
    if (bytesCount > 999999) {
        return FORMAT.format(bytesCount / 1000000.0) + " MB";
    } else if (bytesCount > 999) {
        return bytesCount / 1000 + " KB";
    } else {/* w  ww . j av  a  2  s.c  o m*/
        return String.valueOf(bytesCount) + " bytes";
    }
}

From source file:Main.java

/**
 * Zero pad a number to a specified length
 *
 * @param buffer buffer to use for padding
 * @param value  the integer value to pad if necessary.
 * @param length the length of the string we should zero pad
 *//*from   w w  w.ja va  2s  .  c o m*/
private static void padInt(StringBuilder buffer, int value, int length) {
    String strValue = String.valueOf(value);
    for (int i = length - strValue.length(); i > 0; i--) {
        buffer.append('0');
    }
    buffer.append(strValue);
}

From source file:Main.java

public static void Log(int number) {
    android.util.Log.i("URUCAS_DEBUGGING >>>", String.valueOf(number));
}

From source file:Main.java

public static String getTime(String user_time, String format) {
    String re_time = null;/*from   w  ww .j  a  v  a 2s  .c om*/
    SimpleDateFormat sdf = new SimpleDateFormat(format);
    Date d;
    try {
        d = sdf.parse(user_time);
        long l = d.getTime();
        String str = String.valueOf(l);
        re_time = str.substring(0, 10);
    } catch (ParseException e) {
        e.printStackTrace();
    }
    return re_time;
}

From source file:Main.java

public static String weekDay(String year, String month, String day) {
    String strWeekday = "";
    try {/*from w  w w.  j a  va  2s .c o  m*/
        GregorianCalendar cal = new GregorianCalendar();
        cal.setLenient(false);
        cal.clear();
        cal.set(Integer.parseInt(year), Integer.parseInt(month) - 1, Integer.parseInt(day));
        strWeekday = String.valueOf(cal.get(Calendar.DAY_OF_WEEK) - 1);
    } catch (IllegalArgumentException e) {
        strWeekday = "";
    }
    return strWeekday;
}