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

@HotSpotIntrinsicCandidate
public static String toString(int i) 

Source Link

Document

Returns a String object representing the specified integer.

Usage

From source file:Main.java

/**
 * If there is a suitable entity reference for this
 * character, return it. The list of available entity
 * references is almost but not identical between
 * XML and HTML./*  ww w . j  a  va  2s  .co m*/
 */
public static String escape(char ch) {
    String charRef = getEntityRef(ch);
    if (charRef == null) {
        if (isPrintable(ch)) {
            charRef = "" + ch;
        } else {
            charRef = "&#" + Integer.toString(ch) + ";";
        }
    }
    return charRef;
}

From source file:Main.java

/**
 * Get URI string from resourceId./*ww  w . jav  a 2s  .com*/
 *
 * @param context The context.
 * @param resourceId The resource id.
 * @return The URI string.
 */
public static String getUriString(final Context context, final int resourceId) {
    if (context == null) {
        throw new IllegalArgumentException("context == null");
    }
    return new Uri.Builder().scheme(ContentResolver.SCHEME_ANDROID_RESOURCE).authority(context.getPackageName())
            .appendPath(Integer.toString(resourceId)).toString();
}

From source file:Main.java

public static final void writeByteArrayXml(byte[] val, String name, XmlSerializer out)
        throws XmlPullParserException, java.io.IOException {

    if (val == null) {
        out.startTag(null, "null");
        out.endTag(null, "null");
        return;/*from  w  w w  .ja va2s. co m*/
    }

    out.startTag(null, "byte-array");
    if (name != null) {
        out.attribute(null, "name", name);
    }

    final int N = val.length;
    out.attribute(null, "num", Integer.toString(N));

    StringBuilder sb = new StringBuilder(val.length * 2);
    for (int i = 0; i < N; i++) {
        int b = val[i];
        int h = b >> 4;
        sb.append(h >= 10 ? 'a' + h - 10 : '0' + h);
        h = b & 0xff;
        sb.append(h >= 10 ? 'a' + h - 10 : '0' + h);
    }

    out.text(sb.toString());

    out.endTag(null, "byte-array");
}

From source file:Main.java

public static String getPackageVersionCode(Context context) {
    String msg = "versionCode not available.";
    try {/*from   ww  w. ja  v a 2 s . co m*/
        PackageManager pm = context.getPackageManager();
        PackageInfo pi = pm.getPackageInfo(context.getPackageName(), 0);
        msg = "";
        if (pi.versionCode > 0) {
            msg = Integer.toString(pi.versionCode);
        }
    } catch (NameNotFoundException e) {
    }
    return msg;
}

From source file:Main.java

public static String checkNull(Context context, int lastImageId, File fileCapture) {
    final String[] imageColumns = { Images.Media._ID, Images.Media.DATA };
    final String imageOrderBy = Images.Media._ID + " DESC";
    final String imageWhere = Images.Media._ID + ">?";
    final String[] imageArguments = { Integer.toString(lastImageId) };

    ContentResolver contentResolver = context.getContentResolver();
    Cursor cursor = contentResolver.query(Images.Media.EXTERNAL_CONTENT_URI, imageColumns, imageWhere,
            imageArguments, imageOrderBy);
    if (cursor == null)
        return null;

    String newpath = null;/*from   www .j  a  v  a  2s.  co  m*/
    if (cursor.getCount() >= 2) {
        for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) {
            int id = cursor.getInt(cursor.getColumnIndex(Images.Media._ID));
            String data = cursor.getString(cursor.getColumnIndex(Images.Media.DATA));
            if (data.equals(fileCapture.getPath())) {
                int rows = contentResolver.delete(Images.Media.EXTERNAL_CONTENT_URI, Images.Media._ID + "=?",
                        new String[] { Long.toString(id) });
                boolean ok = fileCapture.delete();

            } else {
                newpath = data;
            }
        }
    } else {
        newpath = fileCapture.getPath();
        Log.e("MediaUtils", "Not found duplicate.");
    }

    cursor.close();
    return newpath;
}

From source file:Main.java

public static String genReqSerialNum() {
    if (reqSerialNum.get() == 99999999) {
        reqSerialNum.set(0);/* w ww.  j av a  2  s.c o  m*/
    }
    int newValue = reqSerialNum.incrementAndGet();

    StringBuilder result = new StringBuilder(Integer.toString(newValue));
    int len = result.length();
    for (int i = len; i <= 8; i++) {
        result.insert(0, "0");
    }
    return result.toString();
}

From source file:Main.java

public static String getFirstLocalDocRevisionId() {
    return Integer.toString(1) + "-local";
}

From source file:Main.java

public static void setIntContent(Element elem, int value) {
    setTextContent(elem, Integer.toString(value));
}

From source file:Main.java

/**
 * Convert 125 minutes to 2 hours and 5 minutes 
 * // w w w.  j  a  va 2s .  co m
 * @param Minutes
 * @return
 */
public static String minutesToTime(String Minutes) {

    int min = Integer.parseInt(Minutes);

    int h = min / 60;
    int m = min % 60;

    String hSTR = Integer.toString(h);
    String mSTR = Integer.toString(m);
    while (hSTR.length() < 2) {
        hSTR = "0" + hSTR;
    }
    while (mSTR.length() < 2) {
        mSTR = "0" + mSTR;
    }

    return hSTR + ":" + mSTR;

}

From source file:com.esri.geoevent.test.tools.RunTcpInBdsOutTest.java

public static void main(String args[]) {

    // Example Command line args
    //-n 10000 -g w12ags104a.jennings.home -i 5565 -m https://w12ags104a.jennings.home/arcgis/rest/services/Hosted/FAA-Stream/MapServer/0 -f D:\github\performance-test-harness-for-geoevent\app\simulations\faa-stream.csv -r 1000,3000,1000

    int numberEvents = 10000; // Number of Events    
    String gisServer = "w12ags104a.jennings.home"; // GIS Server
    int inputTcpPort = 5565; // TCP Input Port       

    String msLayerUrl = "http://w12ags104a.jennings.home/arcgis/rest/services/Hosted/FAA-Stream/MapServer/0";

    String EventsInputFile = "D:\\github\\performance-test-harness-for-geoevent\\app\\simulations\\faa-stream.csv"; // Events input File        

    int start_rate = 5000;
    int end_rate = 5005;
    int rate_step = 1;

    Options opts = new Options();
    opts.addOption("n", true, "Number of Events");
    opts.addOption("g", true, "GIS Server");
    opts.addOption("i", true, "Input TCP Port");
    opts.addOption("m", true, "Map Service Layer URL");
    opts.addOption("f", true, "File with GeoEvents to Send");
    opts.addOption("r", true, "Rates to test Start,End,Step");
    opts.addOption("h", false, "Help");

    try {/*from  w  w w .j a  v a  2s  .co  m*/

        CommandLineParser parser = new BasicParser();
        CommandLine cmd = null;

        try {
            cmd = parser.parse(opts, args, false);
        } catch (org.apache.commons.cli.ParseException ignore) {
            System.err.println(ignore.getMessage());
        }

        String cmdInputErrorMsg = "";

        if (cmd.getOptions().length == 0 || cmd.hasOption("h")) {
            throw new org.apache.commons.cli.ParseException("Show Help");
        }

        if (cmd.hasOption("n")) {
            String val = cmd.getOptionValue("n");
            try {
                numberEvents = Integer.valueOf(val);
            } catch (NumberFormatException e) {
                cmdInputErrorMsg += "Invalid value for n. Must be integer.\n";
            }
        }

        if (cmd.hasOption("g")) {
            gisServer = cmd.getOptionValue("g");
        }

        if (cmd.hasOption("i")) {
            String val = cmd.getOptionValue("i");
            try {
                inputTcpPort = Integer.valueOf(val);
            } catch (NumberFormatException e) {
                cmdInputErrorMsg += "Invalid value for i. Must be integer.\n";
            }
        }

        if (cmd.hasOption("m")) {
            msLayerUrl = cmd.getOptionValue("m");
        }

        if (cmd.hasOption("f")) {
            EventsInputFile = cmd.getOptionValue("f");
        }

        if (cmd.hasOption("r")) {
            String val = cmd.getOptionValue("r");
            try {
                String parts[] = val.split(",");
                if (parts.length == 3) {
                    start_rate = Integer.parseInt(parts[0]);
                    end_rate = Integer.parseInt(parts[1]);
                    rate_step = Integer.parseInt(parts[2]);
                } else if (parts.length == 1) {
                    // Run single rate
                    start_rate = Integer.parseInt(parts[0]);
                    end_rate = start_rate;
                    rate_step = start_rate;
                } else {
                    throw new org.apache.commons.cli.ParseException(
                            "Rate must be three comma seperated values or a single value");
                }

            } catch (org.apache.commons.cli.ParseException e) {
                cmdInputErrorMsg += e.getMessage();
            } catch (NumberFormatException e) {
                cmdInputErrorMsg += "Invalid value for r. Must be integers.\n";
            }
        }

        if (!cmdInputErrorMsg.equalsIgnoreCase("")) {
            throw new org.apache.commons.cli.ParseException(cmdInputErrorMsg);
        }

        // Assuming the ES port is 9220 
        RunTcpInBdsOutTest t = new RunTcpInBdsOutTest();
        DecimalFormat df = new DecimalFormat("##0");

        if (start_rate == end_rate) {
            // Single Rate Test
            System.out.println("*********************************");
            System.out.println("Incremental testing at requested rate: " + start_rate);
            System.out.println("Count,Incremental Rate");

            t.runTest(numberEvents, start_rate, gisServer, inputTcpPort, EventsInputFile, msLayerUrl, true);
            if (t.send_rate < 0 || t.rcv_rate < 0) {
                throw new Exception("Test Run Failed!");
            }
            System.out.println("Overall Average Send Rate, Received Rate");
            System.out.println(df.format(t.send_rate) + "," + df.format(t.rcv_rate));

        } else {
            System.out.println("*********************************");
            System.out.println("rateRqstd,avgSendRate,avgRcvdRate");

            for (int rate = start_rate; rate <= end_rate; rate += rate_step) {

                t.runTest(numberEvents, rate, gisServer, inputTcpPort, EventsInputFile, msLayerUrl, false);
                if (t.send_rate < 0 || t.rcv_rate < 0) {
                    throw new Exception("Test Run Failed!");
                }
                System.out.println(
                        Integer.toString(rate) + "," + df.format(t.send_rate) + "," + df.format(t.rcv_rate));
                Thread.sleep(3 * 1000);
            }

        }

    } catch (ParseException e) {
        System.out.println("Invalid Command Options: ");
        System.out.println(e.getMessage());
        System.out.println(
                "Command line options: -n NumberOfEvents -g GISServer -i InputTCPPort -m MapServerLayerURL -f FileWithEvents -r StartRate,EndRate,Step");

    } catch (Exception e) {
        System.out.println(e.getMessage());
    }

}