Example usage for java.lang Integer toString

List of usage examples for java.lang Integer toString

Introduction

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

Prototype

public String toString() 

Source Link

Document

Returns a String object representing this Integer 's value.

Usage

From source file:com.radadev.xkcd.Comics.java

public static void downloadComic(Integer comicNumber, Context context)
        throws FileNotFoundException, IOException {
    ComicDbAdapter dbAdapter = new ComicDbAdapter(context);
    dbAdapter.open();/*from   ww w.j  ava 2  s . c om*/
    try {
        dbAdapter.updateComic(comicNumber);
        File file = new File(getSdDir(context), comicNumber.toString() + ".png");
        if (file.length() <= 0) {
            Cursor cursor = dbAdapter.fetchComic(comicNumber);
            String url = cursor.getString(cursor.getColumnIndexOrThrow(Comics.SQL_KEY_IMAGE));

            if (url == null || url.length() == 0) {
                dbAdapter.updateComic(comicNumber);
                cursor.close();
                cursor = dbAdapter.fetchComic(comicNumber);
                url = cursor.getString(cursor.getColumnIndexOrThrow(Comics.SQL_KEY_IMAGE));
            }
            cursor.close();

            Bitmap bitmap = Comics.downloadBitmap(url);
            FileOutputStream fileStream = new FileOutputStream(file);
            bitmap.compress(CompressFormat.PNG, 100, fileStream);
            bitmap.recycle();
            fileStream.close();
        }
    } finally {
        dbAdapter.close();
    }
}

From source file:net.sourceforge.fenixedu.presentationTier.validator.form.ValidateDate.java

public static boolean threeArgsDate(Object bean, ValidatorAction va, Field field, ActionMessages errors,
        HttpServletRequest request, ServletContext application) {

    String valueString1 = ValidatorUtils.getValueAsString(bean, field.getProperty());

    String sProperty2 = ValidatorUtils.getValueAsString(bean, field.getVarValue("month"));
    String sProperty3 = ValidatorUtils.getValueAsString(bean, field.getVarValue("day"));

    if (((valueString1 == null) && (sProperty2 == null) && (sProperty3 == null))
            || ((valueString1.length() == 0) && (sProperty2.length() == 0) && (sProperty3.length() == 0))) {
        // errors.add(field.getKey(),Resources.getActionError(request, va,
        // field));
        return true;
    }/*from  w w  w .  j ava 2s  .c o  m*/

    Integer year = null;
    Integer month = null;
    Integer day = null;

    try {
        year = new Integer(valueString1);
        month = new Integer(sProperty2);
        day = new Integer(sProperty3);
    } catch (NumberFormatException e) {
        errors.add(field.getKey(), Resources.getActionMessage(request, va, field));
        return false;
    }
    String date = new String(day.toString() + "/" + month.toString() + "/" + year);
    String datePattern = "dd/MM/yyyy";
    if (!GenericValidator.isDate(date, datePattern, false)) {
        errors.add(field.getKey(), Resources.getActionMessage(request, va, field));
        return false;

    }
    return true;
}

From source file:Main.java

/**
 * Corrects for the differences between numeric strings arising because
 * JDBC drivers use different representations for numbers
 * ({@link Double} vs. {@link java.math.BigDecimal}) and
 * these have different toString() behavior.
 *
 * <p>If it contains a decimal point, then
 * strip off trailing '0's. After stripping off
 * the '0's, if there is nothing right of the
 * decimal point, then strip off decimal point.
 *
 * @param numericStr Numeric string//  w  ww.j a v a 2  s . co m
 * @return Normalized string
 */
public static String normalizeNumericString(String numericStr, boolean isDecimal) {

    if (numericStr.equals("0") || numericStr.equals(null))
        return "0";

    //trim the ".0" if the input integer is in the format ##.0 
    if (!isDecimal && numericStr.contains(".")) {
        String[] strArray = numericStr.split("\\.");
        return strArray[0];
    }

    int index = numericStr.indexOf('.');

    //limit the number of decimal of numericStr to 5
    if (numericStr.length() > index + 4) {
        numericStr = numericStr.substring(0, index + 4);
    }

    //    return numericStr;
    char[] chars = numericStr.toCharArray();
    int start = 0;
    if (chars[0] == '-') {
        start = 1;
    }

    Integer E = 0;
    for (int i = start; i < chars.length; i++) {
        if (chars[i] == '.') {
            E = i - 1;
            while (i > 1) {
                chars[i] = chars[i - 1];
                i--;
            }
            chars[start + 1] = '.';
            break;
        }
    }
    return new String(chars).concat("E" + E.toString());
}

From source file:com.eho.dynamodb.DynamoDBConnection.java

public static String upload_resource(BaseResource resource,
        String primary_key /* if no primary key in case of post, send null*/ ) throws Exception {
    String id = add_primary_as_extension(resource, primary_key);
    String resource_string = DynamoDBConnection.fCtx.newJsonParser().setPrettyPrint(true)
            .encodeResourceToString(resource);
    ;//from   w  w  w. ja  v  a2 s  .c  o  m
    DynamoDB dynamoDB = new DynamoDB(dynamoDBClient);
    Table table = dynamoDB.getTable(PATIENT_TABLE);

    //lets retreive based on the key. if key invalid (not assigned yet) nullis returned.
    Item retreived_item = table.getItem(PRIMARY_KEY, id);
    if (retreived_item == null)//if null instantiate it
    {
        retreived_item = new Item();
        retreived_item.withPrimaryKey(PRIMARY_KEY, id);
        retreived_item.withInt("version", -1);
    }

    Integer new_version = retreived_item.getInt("version") + 1;
    retreived_item.withInt("version", new_version);

    Item item_to_upload = retreived_item//Item.fromJSON(retreived_item.toJSONPretty())
            .withString("text" + new_version.toString(), resource_string)
            .withMap("json-document", new ObjectMapper().readValue(resource_string, LinkedHashMap.class));
    PutItemSpec putItemSpec = new PutItemSpec().withItem(item_to_upload);
    table.putItem(putItemSpec);
    return id;
}

From source file:edu.temple.cis3238.wiki.utils.StringUtils.java

/**
 * Random semi-unique string/*from w  ww. j  ava2s .c  o  m*/
 *
 * @param prefix
 * @param length
 * @return
 */
public static final String getRandomString(String prefix, int length) {
    Integer r = (int) (Math.random() * 1000000.0);
    if (length < StringUtils.toS(prefix).length() + 6) {
        length = StringUtils.toS(prefix).length() + 6;
    }
    Integer hash = r.hashCode();
    Integer random = (11 * r) + (hash * 11);
    int end = Math.abs(length - StringUtils.toS(prefix).length()) + 1;
    return org.apache.commons.lang3.StringUtils.rightPad(prefix, length, random.toString());
    //     prefix + random.toString().substring(0, end < random.toString().length()
    //           ? end
    //           : random.toString().length() - 1);

}

From source file:fxts.stations.util.UserPreferences.java

public static String getStringValue(Integer aValue) {
    return aValue.toString();
}

From source file:com.kenai.redminenb.issue.JournalDisplay.java

private static String formatProject(RedmineRepository repo, RedmineIssue issue, String value) {
    if (value == null) {
        return null;
    }/*from ww  w.  java  2  s  . co m*/
    try {
        Integer id = Integer.valueOf(value);
        NestedProject np = repo.getProjects().get(id);
        return np.toString() + " (ID: " + id.toString() + ")";
    } catch (NumberFormatException | NullPointerException ex) {
    }
    return "(ID: " + value + ")";
}

From source file:com.alibaba.jstorm.daemon.worker.Worker.java

/**
 * Have one problem if the worker's start parameter length is longer than 4096, ps -ef|grep com.alibaba.jstorm.daemon.worker.Worker can't find worker
 * /*w  w  w .  ja va 2  s .co  m*/
 * @param port
 */

public static List<Integer> getOldPortPids(String port) {
    String currPid = JStormUtils.process_pid();

    List<Integer> ret = new ArrayList<Integer>();

    StringBuilder sb = new StringBuilder();

    sb.append("ps -Af ");
    // sb.append(" | grep ");
    // sb.append(Worker.class.getName());
    // sb.append(" |grep ");
    // sb.append(port);
    // sb.append(" |grep -v grep");

    try {
        LOG.info("Begin to execute " + sb.toString());
        Process process = JStormUtils.launch_process(sb.toString(), new HashMap<String, String>(), false);
        // Process process = Runtime.getRuntime().exec(sb.toString());

        InputStream stdin = process.getInputStream();
        BufferedReader reader = new BufferedReader(new InputStreamReader(stdin));

        JStormUtils.sleepMs(1000);

        // if (process.exitValue() != 0) {
        // LOG.info("Failed to execute " + sb.toString());
        // return null;
        // }

        String str;
        while ((str = reader.readLine()) != null) {
            if (StringUtils.isBlank(str)) {
                // LOG.info(str + " is Blank");
                continue;
            }

            // LOG.info("Output:" + str);
            if (str.contains(Worker.class.getName()) == false) {
                continue;
            } else if (str.contains(port) == false) {
                continue;
            }

            LOG.info("Find :" + str);

            String[] fields = StringUtils.split(str);

            boolean find = false;
            int i = 0;
            for (; i < fields.length; i++) {
                String field = fields[i];
                LOG.debug("Filed, " + i + ":" + field);

                if (field.contains(Worker.class.getName()) == true) {
                    if (i + 3 >= fields.length) {
                        LOG.info("Failed to find port ");

                    } else if (fields[i + 3].equals(String.valueOf(port))) {
                        find = true;
                    }

                    break;
                }
            }

            if (find == false) {
                LOG.info("No old port worker");
                continue;
            }

            if (fields.length >= 2) {
                try {
                    if (currPid.equals(fields[1])) {
                        LOG.info("Skip kill myself");
                        continue;
                    }
                    Integer pid = Integer.valueOf(fields[1]);

                    LOG.info("Find one process :" + pid.toString());
                    ret.add(pid);
                } catch (Exception e) {
                    LOG.error(e.getMessage(), e);
                    continue;
                }
            }
        }
        return ret;
    } catch (IOException e) {
        LOG.info("Failed to execute " + sb.toString());
        return ret;
    } catch (Exception e) {
        LOG.info(e.getMessage(), e);
        return ret;
    }
}

From source file:com.twitter.elephanttwin.util.DateUtil.java

/**
 * Convert dateid to calendar/* w  w  w .ja v  a 2s. c  o m*/
 * @param dateId the dateid
 * @return the calendar
 */
public static Calendar dateIdToCalendar(Integer dateId) {
    return formattedTimestampToCalendar(dateId.toString(), DATEID_TIMESTAMP_FORMAT);
}

From source file:ca.uqac.info.trace.generation.AmazonEcsGenerator.java

private static Node createKeyValue(EventTrace trace, String key, Integer value) {
    return createKeyValue(trace, key, value.toString());
}