Example usage for java.lang Double toString

List of usage examples for java.lang Double toString

Introduction

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

Prototype

public static String toString(double d) 

Source Link

Document

Returns a string representation of the double argument.

Usage

From source file:com.intuit.tank.harness.functions.NumericFunctions.java

private static String add(String[] values, Variables variables) {
    double result = 0;
    for (int i = 3; i < values.length; i++) {
        if (values[i] != null) {
            result += NumberUtils.toDouble(values[i]);
        } else {//w  w w. j  av  a 2  s  .  c o  m
            break;
        }
    }
    return Double.toString(result);
}

From source file:com.silverpeas.util.ImageUtil.java

public static String[] getWidthAndHeightByWidth(InputStream image, int widthParam) {
    String[] result = new String[2];
    try {//from  ww w .  j a v a 2  s. co m
        BufferedImage inputBuf = ImageIO.read(image);
        // calcul de la taille de la sortie
        double inputBufWidth;
        double inputBufHeight;
        double width;
        double ratio;
        double height;
        if (inputBuf.getWidth() > widthParam) {
            inputBufWidth = inputBuf.getWidth();
            inputBufHeight = inputBuf.getHeight();
            width = widthParam;
            ratio = inputBufWidth / width;
            height = inputBufHeight / ratio;
        } else {
            width = inputBuf.getWidth();
            height = inputBuf.getHeight();
        }
        String sWidth = Double.toString(width);
        String sHeight = Double.toString(height);

        result[0] = sWidth.substring(0, sWidth.indexOf('.'));
        result[1] = sHeight.substring(0, sHeight.indexOf('.'));

        return result;
    } catch (Exception e) {
        if (image != null) {
            SilverTrace.error("util", "ImageUtil.getWidthAndHeightByWidth", "root.MSG_GEN_ERROR", e);
        }
    }
    result[0] = "";
    result[1] = "";
    return result;
}

From source file:org.openiot.gsn.http.rest.PushRemoteWrapper.java

public boolean initialize() {

    try {/*w  w  w  . j av a2  s  .c  o m*/
        initParams = new RemoteWrapperParamParser(getActiveAddressBean(), true);
        uid = Math.random();

        postParameters = new ArrayList<NameValuePair>();
        postParameters.add(new BasicNameValuePair(PushDelivery.NOTIFICATION_ID_KEY, Double.toString(uid)));
        postParameters.add(
                new BasicNameValuePair(PushDelivery.LOCAL_CONTACT_POINT, initParams.getLocalContactPoint()));
        // Init the http client
        if (initParams.isSSLRequired()) {
            KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType());
            trustStore.load(new FileInputStream(new File("conf/servertestkeystore")),
                    Main.getContainerConfig().getSSLKeyStorePassword().toCharArray());
            SSLSocketFactory socketFactory = new SSLSocketFactory(trustStore);
            socketFactory.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
            int sslPort = Main.getContainerConfig().getSSLPort() > 0 ? Main.getContainerConfig().getSSLPort()
                    : ContainerConfig.DEFAULT_SSL_PORT;
            Scheme sch = new Scheme("https", socketFactory, sslPort);
            httpclient.getConnectionManager().getSchemeRegistry().register(sch);
        }
        Scheme plainsch = new Scheme("http", PlainSocketFactory.getSocketFactory(),
                Main.getContainerConfig().getContainerPort());
        httpclient.getConnectionManager().getSchemeRegistry().register(plainsch);
        //
        lastReceivedTimestamp = initParams.getStartTime();
        structure = registerAndGetStructure();
    } catch (Exception e) {
        logger.error(e.getMessage(), e);
        NotificationRegistry.getInstance().removeNotification(uid);
        return false;
    }

    return true;
}

From source file:net.kaczmarzyk.spring.data.jpa.domain.LessThanTest.java

@Test
public void filtersByPrimitiveFloatValue() {
    assertFilterContainsOnlyExpectedMembers("weightFloat", HEAVIER_THAN_MOE_DOUBLE, margeSimpson, moeSzyslak,
            joeQuimby);//from   w w w. ja va  2s.c om
    assertFilterContainsOnlyExpectedMembers("weightFloat",
            Double.toString(margeSimpson.getWeightFloat() - 0000.1), joeQuimby);

    //this test fails:
    //assertFilterMembers("weightFloat", Double.toString(margeSimpson.getWeightFloat()), joeQuimby);
}

From source file:com.fengduo.bee.commons.util.NumberParser.java

public static double sub(double a, double b) {
    BigDecimal b1 = new BigDecimal(Double.toString(a));
    BigDecimal b2 = new BigDecimal(Double.toString(b));
    return b1.subtract(b2).doubleValue();
}

From source file:com.mgalgs.trackthatthing.LocationReceiver.java

@Override
public void onReceive(Context context, Intent intent) {
    mContext = context;/*from  w w  w  .  j av  a 2 s . c  om*/
    Location loc = (Location) intent.getExtras().get(LocationPoller.EXTRA_LOCATION);

    if (loc == null) {
        msg = intent.getStringExtra(LocationPoller.EXTRA_ERROR);
    } else {
        SharedPreferences settings = context.getSharedPreferences(TrackThatThing.PREFS_NAME,
                Context.MODE_PRIVATE);

        long sleep_period = settings.getLong(TrackThatThing.PREF_SLEEP_TIME, TrackThatThing.DEFAULT_SLEEP_TIME);
        if (getTimeSinceLastLoc_S() > sleep_period - 3 || mLastLocTime == -1) {
            // it has been long enough
        } else {
            // it hasn't been long enough!
            Log.d(TrackThatThing.TAG, "It has only been " + getTimeSinceLastLoc_S()
                    + " seconds since the last location update, not long enough!");
            return;
        }

        mLastLocTime = SystemClock.elapsedRealtime();

        float acc = loc.getAccuracy();
        double lat = loc.getLatitude();
        double lon = loc.getLongitude();
        float speed = loc.getSpeed();

        String secret_code = settings.getString(TrackThatThing.PREF_SECRET_CODE, null);

        QueryString qs = new QueryString(TrackThatThing.BASE_URL + "/put");
        qs.add("secret", secret_code);
        qs.add("lat", Double.toString(lat));
        qs.add("lon", Double.toString(lon));
        qs.add("acc", Float.toString(acc));
        qs.add("speed", Float.toString(speed));

        Runnable r = new MyInternetThread(qs);
        new Thread(r).start();

        msg = loc.toString();
    }

    Log.d(TrackThatThing.TAG, "got this location: " + msg);
}

From source file:edu.umd.cs.psl.model.kernel.predicateconstraint.GroundValueConstraint.java

@Override
public String toString() {
    return "{Value} on " + atom.toString() + " = " + Double.toString(value);
}

From source file:com.rvce.rvce8thmile.driver.TTSService.java

@Override
public void onStart(Intent intent, int startId) {

    sayHello(str);/*from  www. jav a 2s .  co  m*/
    Log.v(TAG, "onstart_service");
    gps = new GPSTracker(getApplicationContext());
    super.onStart(intent, startId);
    final SharedPreferences prefs = getSharedPreferences(MainActivity.class.getSimpleName(),
            Context.MODE_PRIVATE);
    busno = prefs.getString("busno", "nobuses");
    license = prefs.getString("license", "unlicensed");

    final android.os.Handler h = new android.os.Handler();
    Runnable r = new Runnable() {
        @Override
        public void run() {

            // create class object

            // check if GPS enabled
            if (gps.canGetLocation()) {
                latitude = gps.getLatitude();
                longitude = gps.getLongitude();

            } else {
                // can't get location
                // GPS or Network is not enabled
                // Ask user to enable GPS/network in settings
                gps.showSettingsAlert();
            }

            Thread t = new Thread(new Runnable() {
                @Override
                public void run() {
                    HttpClient httpClient = new DefaultHttpClient();
                    HttpPost httpPost = new HttpPost("http://rotaractrvce.com/bidn/updatebus.php");
                    //HttpPost httpPost=new HttpPost("http://ibmhackblind.mybluemix.net/updatebus.php");
                    BasicResponseHandler responseHandler = new BasicResponseHandler();
                    List<NameValuePair> nameValuePair = new ArrayList<NameValuePair>(4);
                    nameValuePair.add(new BasicNameValuePair("busno", busno));
                    nameValuePair.add(new BasicNameValuePair("license", license));
                    nameValuePair.add(new BasicNameValuePair("x", Double.toString(latitude)));
                    nameValuePair.add(new BasicNameValuePair("y", Double.toString(longitude)));
                    try {
                        httpPost.setEntity(new UrlEncodedFormEntity(nameValuePair));
                    } catch (UnsupportedEncodingException e) {
                        // log exception
                        e.printStackTrace();
                    }
                    try {
                        ans = httpClient.execute(httpPost, responseHandler);
                        //Toast.makeText(getApplicationContext(),response,Toast.LENGTH_LONG).show();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
            });
            t.start();
            try {
                t.join();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            Toast.makeText(getApplicationContext(), latitude.toString() + " : " + longitude.toString(),
                    Toast.LENGTH_SHORT).show();
            Toast.makeText(getApplicationContext(), ans, Toast.LENGTH_SHORT).show();
            latitude = (double) 0;
            longitude = (double) 0;
            h.postDelayed(this, 5000);
        }
    };
    h.post(r);

}

From source file:nz.co.wholemeal.christchurchmetro.Stop.java

/**
 * Returns an ArrayList of all the stops within the square bounded by the
 * two GeoPoints.//w  w w . j a  va 2 s  . c  om
 */
public static ArrayList<Stop> getAllWithinBounds(Context context, GeoPoint topLeft, GeoPoint bottomRight) {

    String topLat = Double.toString(topLeft.getLatitudeE6() / 1E6);
    String topLon = Double.toString(topLeft.getLongitudeE6() / 1E6);
    String bottomLat = Double.toString(bottomRight.getLatitudeE6() / 1E6);
    String bottomLon = Double.toString(bottomRight.getLongitudeE6() / 1E6);

    String query = "SELECT p.platform_tag, p.platform_number, p.name, "
            + "p.road_name, p.latitude, p.longitude FROM platforms p" + " WHERE p.latitude < " + topLat
            + " AND p.longitude > " + topLon + " AND p.latitude > " + bottomLat + " AND p.longitude < "
            + bottomLon;

    return doArrayListQuery(context, query);
}

From source file:de.ii.ldproxy.gml2json.BufferedTransformingCoordinatesWriter.java

private void writeCoordinates(boolean force) throws IOException {
    if (tupleBuffer != null) {
        if (tupleBuffer.hasX()) {
            coordinateBuffer[counter - 2 - zCounter] = tupleBuffer.getX();
        }//from   ww w .j  a  va 2 s.  c o m
        if (tupleBuffer.hasY()) {
            coordinateBuffer[counter - 1 - zCounter] = tupleBuffer.getY();
        }
        tupleBuffer = null;
    }

    if (force || counter == BUFFER_SIZE) {

        double[] c = postProcessCoordinates(coordinateBuffer, (counter - zCounter) / 2);

        if (this.reversepolygon) {

            if (!force) { // force == end of coordinates
                // add c to the buffer
                reversePolygonBuffer.add(c);
            } else {

                // the buffer is empty, just write out the current c
                if (reversePolygonBuffer.isEmpty()) {

                    for (int i = 0; i < c.length; i += 2) {
                        json.writeRawValue(Double.toString(c[i]));
                        json.writeRawValue(Double.toString(c[i + 1]));
                        if (i < c.length - 2) {
                            super.writeSeparator();
                        }
                    }
                } else { // the buffer must be written out in reverse order                   
                    for (int i0 = reversePolygonBuffer.size() - 1; i0 >= 0; i0--) {
                        double[] c0 = reversePolygonBuffer.get(i0);
                        for (int i = 0; i < c0.length; i += 2) {
                            json.writeRawValue(Double.toString(c0[i]));
                            json.writeRawValue(Double.toString(c0[i + 1]));
                            if (i < c0.length - 2) {
                                super.writeSeparator();
                            }
                        }
                    }
                    reversePolygonBuffer.clear();
                }
            }
        } else {

            int numCoo;
            if (c.length == coordinateBuffer.length) {
                numCoo = (counter - zCounter);
            } else {
                numCoo = c.length;
            }
            for (int i = 0; i < numCoo; i += 2) {
                json.writeRawValue(Double.toString(c[i]));
                json.writeRawValue(Double.toString(c[i + 1]));
                if (i < numCoo - 2) {
                    super.writeSeparator();
                }
            }
            counter = 0;
        }
    }
}