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 String toString() 

Source Link

Document

Returns a string representation of this Double object.

Usage

From source file:TaxSvc.TaxSvc.java

public GeoTaxResult EstimateTax(Double latitude, Double longitude, Double saleAmount) {
    //Create query/url
    String taxest = svcURL + "/1.0/tax/" + latitude.toString() + "," + longitude.toString() + "/get?saleamount="
            + saleAmount.toString();//from www. ja  v  a  2s .c o  m
    URL url;
    HttpURLConnection conn;
    try {
        //Connect to specified URL with authorization header
        url = new URL(taxest);
        conn = (HttpURLConnection) url.openConnection();
        String encoded = "Basic " + new String(Base64.encodeBase64((accountNum + ":" + license).getBytes())); //Create auth content
        conn.setRequestProperty("Authorization", encoded); //Add authorization header
        conn.disconnect();

        ObjectMapper mapper = new ObjectMapper(); //Deserialization object

        if (conn.getResponseCode() != 200) //If we didn't get a success back, print out the error
        {
            GeoTaxResult res = mapper.readValue(conn.getErrorStream(), GeoTaxResult.class); //Deserializes the response object
            return res;
        }

        else //Otherwise, print out the validated address.
        {
            GeoTaxResult res = mapper.readValue(conn.getInputStream(), GeoTaxResult.class); //Deserializes the response object
            return res;
        }

    } catch (IOException e) {
        e.printStackTrace();
        return null;

    }
}

From source file:net.refractions.udig.catalog.wmsc.server.TileImageReadWriter.java

/**
 * Fetch the directory path for the given tile. Tile directory structure is as follow: <tile
 * folder>\<server>\<layer names>_<EPSG code>_<image format>\<scale>\
 * /*from  w  w  w.  jav a2  s.co  m*/
 * @param tile
 * @return
 */
public String getTileDirectoryPath(Tile tile) {
    String serverURL = this.server.getHost() + "_" + this.server.getPath(); //$NON-NLS-1$
    serverURL = serverURL.replace('\\', '_');
    serverURL = serverURL.replace('/', '_');
    String layers = tile.getTileSet().getLayers();
    layers += "_" + tile.getTileSet().getEPSGCode();//$NON-NLS-1$
    layers += "_" + tile.getTileSet().getFormat(); //$NON-NLS-1$
    layers = layers.replace(',', '_');
    layers = layers.replace(':', '_');
    layers = layers.replace('\\', '_');
    layers = layers.replace('/', '_');
    layers = layers.replace(File.separator, "_"); //$NON-NLS-1$
    Double scale = tile.getScale();
    String scaleStr = scale.toString();
    scaleStr = scaleStr.replace('.', '_');
    return baseTileFolder + File.separator + serverURL + File.separator + layers + File.separator + scaleStr
            + File.separator;
}

From source file:com.esri.geoevent.solutions.adapter.geomessage.DefenseOutboundAdapter.java

@SuppressWarnings("incomplete-switch")
@Override/*w  w w . j  ava  2 s  .  c  o  m*/
public synchronized void receive(GeoEvent geoEvent) {

    ByteBuffer byteBuffer = ByteBuffer.allocate(10 * 1024);
    Integer wkid = -1;
    String message = "";

    message += "<geomessage v=\"1.0\">\n\r";
    message += "<_type>";
    message += messageType;
    message += "</_type>\n\r";
    message += "<_action>";
    message += "update";
    message += "</_action>\n\r";
    String messageid = UUID.randomUUID().toString();
    message += "<_id>";
    message += "{" + messageid + "}";
    message += "</_id>\n\r";
    MapGeometry geom = geoEvent.getGeometry();
    if (geom.getGeometry().getType() == com.esri.core.geometry.Geometry.Type.Point) {
        Point p = (Point) geom.getGeometry();
        message += "<_control_points>";
        message += ((Double) p.getX()).toString();
        message += ",";
        message += ((Double) p.getY()).toString();
        message += "</_control_points>\n\r";
        wkid = ((Integer) geom.getSpatialReference().getID());
    }

    if (wkid > 0) {
        String wkidValue = wkid.toString();
        message += "<_wkid>";
        message += wkidValue.toString();
        message += "</_wkid>\n\r";
    }
    GeoEventDefinition definition = geoEvent.getGeoEventDefinition();
    for (FieldDefinition fieldDefinition : definition.getFieldDefinitions()) {

        String attributeName = fieldDefinition.getName();
        Object value = geoEvent.getField(attributeName);

        if (value == null || value.equals("null")) {
            continue;
        }
        FieldType t = fieldDefinition.getType();
        if (t != FieldType.Geometry) {
            message += "<" + attributeName + ">";

            switch (t) {
            case String:
                // if(((String)value).isEmpty())
                // continue;
                message += value;
                break;
            case Date:
                Date date = (Date) value;
                message += (formatter.format(date));
                break;
            case Double:
                Double doubleValue = (Double) value;
                message += doubleValue.toString();
                break;
            case Float:
                Float floatValue = (Float) value;
                message += floatValue.toString();
                break;

            case Integer:
                Integer intValue = (Integer) value;
                message += intValue.toString();
                break;
            case Long:
                Long longValue = (Long) value;
                message += longValue.toString();
                break;
            case Short:
                Short shortValue = (Short) value;
                message += shortValue.toString();
                break;
            case Boolean:
                Boolean booleanValue = (Boolean) value;
                message += booleanValue.toString();
                break;

            }
            message += "</" + attributeName + ">\n\r";
        } else {
            if (definition.getIndexOf(attributeName) == definition.getIndexOf("GEOMETRY")) {
                continue;
            } else {
                String json = GeometryEngine.geometryToJson(wkid, (Geometry) value);
                message += "<" + attributeName + ">";
                message += json;
                message += "</" + attributeName + ">\n\r";
            }
            break;
        }

    }
    message += "</geomessage>";
    // stringBuffer.append("</geomessages>");
    message += "\r\n";

    ByteBuffer buf = charset.encode(message);
    if (buf.position() > 0)
        buf.flip();

    try {
        byteBuffer.put(buf);
    } catch (BufferOverflowException ex) {
        LOG.error(
                "Csv Outbound Adapter does not have enough room in the buffer to hold the outgoing data.  Either the receiving transport object is too slow to process the data, or the data message is too big.");
    }
    byteBuffer.flip();
    super.receive(byteBuffer, geoEvent.getTrackId(), geoEvent);
    byteBuffer.clear();
}

From source file:com.opengamma.analytics.math.differentiation.ScalarFirstOrderDifferentiator.java

@Override
public Function1D<Double, Double> differentiate(final Function1D<Double, Double> function,
        final Function1D<Double, Boolean> domain) {
    Validate.notNull(function);/*from   w ww  . ja  v a 2 s. co m*/
    Validate.notNull(domain);

    final double[] wFwd = new double[] { -3. / _twoEps, 4. / _twoEps, -1. / _twoEps };
    final double[] wCent = new double[] { -1. / _twoEps, 0., 1. / _twoEps };
    final double[] wBack = new double[] { 1. / _twoEps, -4. / _twoEps, 3. / _twoEps };

    return new Function1D<Double, Double>() {

        @SuppressWarnings("synthetic-access")
        @Override
        public Double evaluate(final Double x) {
            Validate.notNull(x, "x");
            ArgumentChecker.isTrue(domain.evaluate(x), "point {} is not in the function domain", x.toString());

            final double[] y = new double[3];
            double[] w;

            if (!domain.evaluate(x + _eps)) {
                if (!domain.evaluate(x - _eps)) {
                    throw new MathException("cannot get derivative at point " + x.toString());
                }
                y[0] = function.evaluate(x - _twoEps);
                y[1] = function.evaluate(x - _eps);
                y[2] = function.evaluate(x);
                w = wBack;
            } else {
                if (!domain.evaluate(x - _eps)) {
                    y[0] = function.evaluate(x);
                    y[1] = function.evaluate(x + _eps);
                    y[2] = function.evaluate(x + _twoEps);
                    w = wFwd;
                } else {
                    y[0] = function.evaluate(x - _eps);
                    y[2] = function.evaluate(x + _eps);
                    w = wCent;
                }
            }

            double res = y[0] * w[0] + y[2] * w[2];
            if (w[1] != 0) {
                res += y[1] * w[1];
            }
            return res;
        }
    };
}

From source file:com.wordpress.growworkinghard.riverNe3.composite.key.Key.java

/**
 * @brief Compute if the key is odd or even
 *
 * @description The computation is done following these steps:
 *              <ol>/*from ww  w . j  av  a 2 s  .c o m*/
 *              <li>dividing the decimal format of the key by 2;</li>
 *              <li>converting the result from <tt>Double</tt> to
 *              <tt>String</tt>;</li>
 *              <li>parsing the <tt>String</tt> through regular expression,
 *              splitting <strong>integer</strong> part and
 *              <strong>decimal</strong> part and saving them in an array of
 *              <tt>String</tt>;</li>
 *              <li>comparing the <strong>decimal</strong> part with 0.</li>
 *              </ol>
 *
 * @retval TRUE if the key is even
 * @retval FALSE if the key is odd
 */
public boolean isEven() {

    Double division = hexToDecimal() / 2;
    String tmpString = division.toString();
    String[] result = tmpString.split("\\.");

    return (result[1].compareTo("0") == 0) ? true : false;

}

From source file:com.log4ic.compressor.utils.Compressor.java

private static List<String> buildTrueConditions(HttpServletRequest request) {
    List<String> conditions = new FastList<String>();
    if (!HttpUtils.getBooleanParam(request, "condition")) {
        return conditions;
    }/*from ww w  . ja v  a2 s .  c o  m*/
    //???
    List<BrowserInfo> browserInfoList = HttpUtils.getRequestBrowserInfo(request);
    String prefix = "browser_";
    //?
    for (BrowserInfo info : browserInfoList) {
        //?  BROWSER_IE
        conditions.add((prefix + info.getBrowserType()).toUpperCase());
        Double version = info.getBrowserVersion();
        if (version != null) {
            String versionStr = version.toString();
            //???  BROWSER_IE6.2
            conditions.add((prefix + info.getBrowserType() + versionStr.replace(".", "_")).toUpperCase());
            versionStr = versionStr.substring(0, versionStr.indexOf("."));
            //??  BROWSER_IE6
            conditions.add((prefix + info.getBrowserType() + versionStr).toUpperCase());
        }
    }

    List<String> platformList = HttpUtils.getRequestPlatform(request);

    for (String platform : platformList) {
        conditions.add(("platform_" + platform).toUpperCase());
    }

    return conditions;
}

From source file:org.starfishrespect.myconsumption.android.tasks.ConfigUpdater.java

public void refreshDB() {

    AsyncTask<Void, List, Void> task = new AsyncTask<Void, List, Void>() {
        @Override/*from w  ww .j  a v  a  2 s .c  o m*/
        protected Void doInBackground(Void... params) {
            DatabaseHelper db = SingleInstance.getDatabaseHelper();
            RestTemplate template = new RestTemplate();
            template.getMessageConverters().add(new MappingJacksonHttpMessageConverter());

            try {
                String url = SingleInstance.getServerUrl() + "configs/co2";
                Double co2 = template.getForObject(url, Double.class);

                int id = db.getIdForKey("config_co2");
                KeyValueData valueData = new KeyValueData("config_co2", co2.toString());
                valueData.setId(id);

                LOGD(TAG, "writing stat in local db: " + co2);
                db.getKeyValueDao().createOrUpdate(valueData);

            } catch (SQLException e) {
                LOGD(TAG, "Cannot create config co2", e);
            } catch (ResourceAccessException | HttpClientErrorException e) {
                LOGE(TAG, "Cannot access server ", e);
            }

            try {
                String url = SingleInstance.getServerUrl() + "configs/day";
                Double day = template.getForObject(url, Double.class);

                int id = db.getIdForKey("config_day");
                KeyValueData valueData = new KeyValueData("config_day", day.toString());
                valueData.setId(id);

                LOGD(TAG, "writing stat in local db: " + day);
                db.getKeyValueDao().createOrUpdate(valueData);

            } catch (SQLException e) {
                LOGD(TAG, "Cannot create config day", e);
            } catch (ResourceAccessException | HttpClientErrorException e) {
                LOGE(TAG, "Cannot access server ", e);
            }

            try {
                String url = SingleInstance.getServerUrl() + "configs/night";
                Double night = template.getForObject(url, Double.class);

                int id = db.getIdForKey("config_night");
                KeyValueData valueData = new KeyValueData("config_night", night.toString());
                valueData.setId(id);

                LOGD(TAG, "writing stat in local db: " + night);
                db.getKeyValueDao().createOrUpdate(valueData);

            } catch (SQLException e) {
                LOGD(TAG, "Cannot create config night", e);
            } catch (ResourceAccessException | HttpClientErrorException e) {
                LOGE(TAG, "Cannot access server ", e);
            }
            return null;
        }

        @Override
        protected void onPostExecute(Void aVoid) {
            if (configUpdateFinishedCallback != null) {
                configUpdateFinishedCallback.onConfigUpdateFinished();
            }
        }
    };

    task.execute();
}

From source file:ch.zhaw.icclab.tnova.expressionsolver.OTFlyEval.java

String findSum(LinkedList<Double> paramList) {
    Double sum = new Double("0.0");
    for (int i = 0; i < paramList.size(); i++) {
        sum += paramList.get(i);/*  ww  w.  j  a v a  2s  .  c o  m*/
    }
    return sum.toString();
}

From source file:au.gov.ga.earthsci.bookmark.properties.layer.LayersProperty.java

/**
 * Add additional layer state to this property.
 * /*from ww  w.  j  ava2s  .  c o  m*/
 * @param id
 *            The id of the layer
 * @param opacity
 *            The opacity of the layer
 */
public void addLayer(String id, Double opacity, String name) {
    //      layerState.put(id, opacity);
    //      layerName.put(id, name);
    List<Pair<String, String>> pairs = new ArrayList<Pair<String, String>>();
    pairs.add(new ImmutablePair<String, String>("opacity", opacity.toString()));
    pairs.add(new ImmutablePair<String, String>("name", name));
    addLayer(id, pairs.toArray(new Pair[0]));

}

From source file:net.sourceforge.fenixedu.presentationTier.Action.credits.ManageTeacherAdviseServiceDispatchAction.java

private void addMessages(AdvisePercentageException ape, ActionMessages actionMessages, AdviseType adviseType) {
    ExecutionSemester executionSemester = ape.getExecutionPeriod();
    ActionMessage initialActionMessage = new ActionMessage("message.teacherAdvise.percentageExceed");
    actionMessages.add("", initialActionMessage);
    for (Advise advise : ape.getAdvises()) {
        TeacherAdviseService teacherAdviseService = advise
                .getTeacherAdviseServiceByExecutionPeriod(executionSemester);
        if (adviseType.equals(ape.getAdviseType()) && teacherAdviseService != null) {
            String teacherId = advise.getTeacher().getPerson().getIstUsername();
            String teacherName = advise.getTeacher().getPerson().getName();
            Double percentage = teacherAdviseService.getPercentage();
            ActionMessage actionMessage = new ActionMessage("message.teacherAdvise.teacher.percentageExceed",
                    teacherId.toString(), teacherName, percentage.toString(), "%");
            actionMessages.add("message.teacherAdvise.teacher.percentageExceed", actionMessage);
        }//  w  w w.  ja v  a 2s .  c  o m
    }
}