Example usage for java.lang String toString

List of usage examples for java.lang String toString

Introduction

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

Prototype

public String toString() 

Source Link

Document

This object (which is already a string!) is itself returned.

Usage

From source file:com.magnet.android.mms.request.GenericResponseParserPrimitiveTest.java

@SmallTest
public void testNumberResponse() throws MobileException, JSONException {
    GenericResponseParser<Integer> parser = new GenericResponseParser<Integer>(Integer.class);
    String response = Integer.toString(Integer.MIN_VALUE);

    Integer result = (Integer) parser.parseResponse(response.toString().getBytes());
    assertEquals(Integer.MIN_VALUE, result.intValue());

    Object nullresult = parser.parseResponse((byte[]) null);
    assertEquals(null, nullresult);/*from  w w w. j  a v  a2  s .c o  m*/

    long longvalue = new Random().nextLong();
    GenericResponseParser<Long> lparser = new GenericResponseParser<Long>(Long.class);
    long longresult = (Long) lparser.parseResponse(Long.toString(longvalue).getBytes());
    assertEquals(longvalue, longresult);

    short shortvalue = Short.MAX_VALUE;
    GenericResponseParser<Short> sparser = new GenericResponseParser<Short>(short.class);
    short shortresult = (Short) sparser.parseResponse(Short.toString(shortvalue).getBytes());
    assertEquals(shortvalue, shortresult);

    float floatvalue = new Random().nextFloat();
    GenericResponseParser<Float> fparser = new GenericResponseParser<Float>(Float.class);
    float floatresult = (Float) fparser.parseResponse(Float.toString(floatvalue).getBytes());
    assertEquals(String.valueOf(floatvalue), String.valueOf(floatresult));
    // use string as the value of the float

    double doublevalue = new Random().nextDouble();
    GenericResponseParser<Double> dparser = new GenericResponseParser<Double>(double.class);
    Double doubleresult = (Double) dparser.parseResponse(Double.toString(doublevalue).getBytes());
    assertEquals(String.valueOf(doublevalue), String.valueOf(doubleresult));

    byte bytevalue = Byte.MIN_VALUE + 10;
    GenericResponseParser<Byte> bparser = new GenericResponseParser<Byte>(Byte.class);
    Byte byteresult = (Byte) bparser.parseResponse(Byte.toString(bytevalue).getBytes());
    assertEquals(bytevalue, byteresult.byteValue());

}

From source file:com.bs.beans.PurchasesMB.java

public void createPurForm() {
    modelPurForm.clear();//from  w w  w. ja  v  a 2  s .c  om
    Connection con = null;
    PreparedStatement stm = null;
    List<ModelPurchases> list = new ArrayList<>();
    ResultSet rs = null;
    try {
        con = DB.getConnection();
        String sql = "SELECT Pro_Id FROM product WHERE Pro_Name=?;";
        stm = con.prepareStatement(sql);
        for (String p : selectedPoduct) {
            stm.setString(1, p.toString());
            rs = stm.executeQuery();
            //System.out.println(p);
            while (rs.next()) {
                modelPurForm.add(new ModelProduct(rs.getInt(1), p));
                System.out.println(rs.getInt(1));
            }

        }
        // selectedPoduct.clear();

        //setDoAct(true);
    } catch (Exception e) {
    } finally {
        try {
            rs.close();
            con.close();
        } catch (SQLException ex) {
            Logger.getLogger(PurchasesMB.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}

From source file:gov.nih.nci.cabig.caaers.datamigrator.UserPrivilegeMigrator.java

@Override
public void migrate(CaaersDataMigrationContext ctx) {
    log.debug("User Privilege data migration started......");

    //only do it for local mode
    if (StringUtils.equals("local", getAuthenticationMode())) {
        log.debug("User Privilege data migration : mode is local ");
        //ResearchStaff - find all the site specific roles
        String query = ctx.isOracle() ? rsSiteOracleSQL.toString() : rsSitePGSQL.toString();
        getJdbcTemplate().query(query.toString(), new UserRowMapper(true));

        //ResearchStaff - find all the study specific roles
        query = ctx.isOracle() ? rsStudyOracleSQL.toString() : rsStudyPGSQL.toString();
        getJdbcTemplate().query(query.toString(), new UserRowMapper(false));

        //Investigator - find all the site specific roles
        query = ctx.isOracle() ? invSiteOracleSQL.toString() : invSitePGSQL.toString();
        getJdbcTemplate().query(query.toString(), new UserRowMapper(true));

        //Investigator - find all the study specific roles
        query = ctx.isOracle() ? invStudyOracleSQL.toString() : invStudyPGSQL.toString();
        getJdbcTemplate().query(query.toString(), new UserRowMapper(false));

        if (!userDataMap.isEmpty()) {
            for (User user : userDataMap.values()) {
                log.debug("provisioning csm_user : " + user.getCsmUser().getUserId());
                userRepository.provisionUser(user);
            }/* w  w  w.j  a v a 2s .com*/
        }
    }

    //threw off the content from Site Research Staff Roles
    getJdbcTemplate().execute("delete from site_rs_staff_roles ");

    log.debug("User Privilege data migration done......");
}

From source file:jp.co.brilliantservice.android.ric.command.SocketController.java

private void doPost(List<Buffer> buffers) {

    StringBuilder b = new StringBuilder();

    for (int i = 0; i < buffers.size(); ++i) {
        Buffer e = buffers.get(i);
        if (i > 0)
            b.append('Z');
        for (int j = e.offset; j < e.count; ++j) {
            b.append(String.format("%02X", e.buffer[j]));
        }//from   w ww . ja v  a  2 s .  c  om
    }

    final String command = b.toString();

    context.runOnUiThread(new Runnable() {

        public void run() {
            Toast toast = Toast.makeText(context, command.toString(), Toast.LENGTH_SHORT);
            toast.show();
        }
    });

    Runnable task = new Runnable() {

        public void run() {
            List<NameValuePair> nvps = new ArrayList<NameValuePair>();
            Log.i("RIC", command);
            nvps.add(new BasicNameValuePair("c", command));
            // try {
            // req.setEntity(new UrlEncodedFormEntity(nvps, HTTP.UTF_8));
            // } catch (UnsupportedEncodingException e1) {
            // }

            try {
                // final HttpResponse res = client.execute(req);
                // context.runOnUiThread(new Runnable() {
                // public void run() {
                // Toast toast = Toast.makeText(context, res
                // .getStatusLine().toString(),
                // Toast.LENGTH_SHORT);
                // toast.show();
                // }
                // });
            } catch (final Exception e) {
                context.runOnUiThread(new Runnable() {
                    public void run() {
                        Toast toast = Toast.makeText(context, e.getLocalizedMessage(), Toast.LENGTH_SHORT);
                        toast.show();
                    }
                });
                return;
            }
        }
    };

    exec.execute(task);
}

From source file:com.stackify.log.log4j2.LogEventAdapter.java

/**
 * Gets properties from the event's MDC and MDC
 * @param event The logging event/*from  w  w w.j  a  v  a  2  s  . com*/
 * @return Map assembled from the event's MDC and NDC
 */
public Map<String, String> getProperties(final LogEvent event) {

    Map<String, String> properties = new HashMap<String, String>();

    // unload the MDC

    Map<String, String> mdc = event.getContextMap();

    if (mdc != null) {
        Iterator<Map.Entry<String, String>> mdcIterator = mdc.entrySet().iterator();

        while (mdcIterator.hasNext()) {
            Map.Entry<String, String> entryPair = (Map.Entry<String, String>) mdcIterator.next();

            String key = entryPair.getKey();
            String value = entryPair.getValue();

            properties.put(key, value != null ? value.toString() : null);
        }
    }

    // unload the NDC

    ContextStack contextStack = event.getContextStack();

    if (contextStack != null) {
        String ndc = contextStack.peek();

        if (ndc != null) {
            if (!ndc.isEmpty()) {
                properties.put("NDC", ndc);
            }
        }
    }

    // return the properties

    return properties;
}

From source file:it.larusba.integration.neo4jcouchbaseconnector.examples.spotify.service.impl.SpotifyLoaderServiceImpl.java

@Override
public String getArtist(String artistId) {
    String jsonResult = "";

    try {/* w  w  w .ja va  2  s. c  o  m*/
        jsonResult = getRequest("https://api.spotify.com/v1/artists/" + artistId);
    } catch (IOException e) {
        LOGGER.error("Error while getting the Artist: " + e.getMessage());
    }

    return jsonResult.toString();
}

From source file:by.creepid.jsf.fileupload.UploadRenderer.java

private String getServletRealPath(ExternalContext external, String target) {
    ServletContext servletContext = (ServletContext) external.getContext();

    String realPath = servletContext.getRealPath(target.toString());
    if (!realPath.endsWith("/")) {
        realPath += "/";
    }/*from   w w  w .  j a  va  2 s .  c  o m*/

    return realPath;
}

From source file:com.cdancy.artifactory.rest.features.ArtifactApiMockTest.java

public void testRetrieveArtifact() throws Exception {
    MockWebServer server = mockArtifactoryJavaWebServer();

    String payload = payloadFromResource("/retrieve-artifact.txt");
    server.enqueue(new MockResponse().setBody(payload).setHeader("X-Artifactory-Filename", "jar-1.0.txt")
            .setHeader("X-Checksum-Md5", randomString()).setResponseCode(200));

    ArtifactoryApi jcloudsApi = api(server.getUrl("/"));
    ArtifactApi api = jcloudsApi.artifactApi();
    File inputStream = null;//from   ww w  .j  av a 2  s .  c om
    try {
        inputStream = api.retrieveArtifact("libs-release-local", "my/jar/1.0/jar-1.0.txt", null);
        assertNotNull(inputStream);
        assertTrue(inputStream.exists());

        String content = FileUtils.readFileToString(inputStream);

        assertTrue(content.toString().equals(payload));
        assertSent(server, "GET", "/libs-release-local/my/jar/1.0/jar-1.0.txt",
                MediaType.APPLICATION_OCTET_STREAM);
    } finally {
        if (inputStream != null && inputStream.exists()) {
            FileUtils.deleteQuietly(inputStream.getParentFile());
        }

        jcloudsApi.close();
        server.shutdown();
    }
}

From source file:com.example.administrator.myapplication2._5_Group._5_Group.LeftFragment.java

public void getGroupMembers() {
    AsyncHttpClient client1 = new AsyncHttpClient();
    client1.get("http://14.63.219.140:8080/han5/webresources/han5.grouping/getNamelist/" + groupName,
            new JsonHttpResponseHandler() {
                @Override//  w ww  . j a  va 2  s  .c o  m
                public void onStart() {
                    Log.i("boogil1", "getGroupName receive json data start! ");
                }

                @Override
                public void onSuccess(int statusCode, Header[] headers, JSONArray response) {
                    Log.i("_4_", "getRecentData(right) success! ");
                    Log.i("_4_", response.toString());

                    try {

                        JSONArray jArray = response;

                        for (int i = 0; i < jArray.length(); i++) {
                            JSONObject json_data = jArray.getJSONObject(i);

                            String name = json_data.getString("name");
                            String kor_name = URLDecoder.decode(name.toString(), "UTF-8");
                            names += kor_name + "\n";

                        }

                        tvGroupMember.setText(names);

                    } catch (JSONException e) {
                    } catch (UnsupportedEncodingException e) {
                        e.printStackTrace();
                    }
                }

                @Override
                public void onFailure(int statusCode, Header[] headers, Throwable throwable,
                        JSONObject errorResponse) {
                    Log.i("boogil1", "getGroupMembers fail! ");
                }

            });

}

From source file:com.hmsinc.epicenter.surveillance.SchedulingSurveillanceService.java

@ManagedOperation(description = "Execute a Surveillance Task")
@ManagedOperationParameters({/* w w  w.j  a v  a  2  s. co m*/
        @ManagedOperationParameter(name = "id", description = "The id of the task to execute") })
public void executeTask(final String id) throws Exception {
    Validate.notNull(id, "Surveillance task id must be specified.");

    // If the scheduler is enabled, we can use it to execute the task..
    if (isSurveillanceEnabled()) {
        scheduler.triggerJob(JOB_PREFIX + id.toString(), Scheduler.DEFAULT_GROUP);
    } else {
        final SurveillanceTask task = surveillanceRepository.load(Long.valueOf(id), SurveillanceTask.class);
        Validate.notNull(task, "Invalid task id: " + id);
        surveillanceTaskRunner.execute(task);
    }
}