Example usage for java.lang Double intValue

List of usage examples for java.lang Double intValue

Introduction

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

Prototype

public int intValue() 

Source Link

Document

Returns the value of this Double as an int after a narrowing primitive conversion.

Usage

From source file:ca.sfu.federation.model.Expression.java

/**
 * Determines the type of the left and right hand side objects, converts
 * them to an operable type, performs the add calculation then returns the
 * result object.//from w  w  w  . j  ava  2 s.  co  m
 * @param lhs Left hand operand.
 * @param rhs Right hand operand.
 * @return Sum of left and right hand operands.
 * TODO: throw an exception if the add operation can not be performed
 * TODO: need to consider when objects are of different types, then convert them to a common type
 */
private static Object add(Object lhs, Object rhs) {
    // initialize
    Object result = null;
    Double dblVal = new Double(0.0);
    Integer intVal = new Integer(0);
    // determine parameter type, do calculation based on object type
    if (lhs.getClass().isInstance(dblVal) && rhs.getClass().isInstance(dblVal)) {
        // convert values to double
        Double _lhs = (Double) lhs;
        Double _rhs = (Double) rhs;
        result = add(_lhs.doubleValue(), _rhs.doubleValue());
    } else if (lhs.getClass().isInstance(intVal) && rhs.getClass().isInstance(intVal)) {
        // convert values to int
        Integer _lhs = (Integer) lhs;
        Integer _rhs = (Integer) rhs;
        result = add(_lhs.intValue(), _rhs.intValue());
    }
    // return result
    return result;
}

From source file:io.cloudex.cloud.impl.google.auth.InstanceAuthenticationProvider.java

/**
 * Retrieves a service account access token from the metadata server, the response has the format
 * {/*  ww w .j a v  a  2 s .c  o  m*/
  "access_token":"ya29.AHES6ZRN3-HlhAPya30GnW_bHSb_QtAS08i85nHq39HE3C2LTrCARA",
  "expires_in":3599,
  "token_type":"Bearer"
}
 * @throws IOException
 * For more details see https://developers.google.com/compute/docs/authentication
 */
protected void refreshOAuthToken() throws IOException {

    log.debug("Refreshing OAuth token from metadata server");
    Map<String, Object> token = ObjectUtils.jsonToMap(GoogleMetaData.getMetaData(TOKEN_PATH));
    this.accessToken = (String) token.get(ACCESS_TOKEN);

    Double expiresIn = (Double) token.get(EXPIRES_IN);
    this.tokenExpire = DateUtils.addSeconds(new Date(), expiresIn.intValue());

    log.debug("Successfully refreshed OAuth token from metadata server");

}

From source file:com.thomaskuenneth.openweathermapweather.BasicView.java

private void doIt() {
    Task<Void> t = new Task<Void>() {
        @Override//from   w  ww .  j a v  a2 s.c  o m
        protected Void call() throws Exception {
            try {
                final WeatherData weather = WeatherUtils.getWeather(city.getText());
                Platform.runLater(() -> {
                    Image i = new Image("http://openweathermap.org/img/w/" + weather.icon + ".png");
                    image.setImage(i);
                    beschreibung.setText(weather.description);
                    Double temp = weather.temp - 273.15;
                    temperatur.setText(MessageFormat.format("{0} \u2103", temp.intValue()));
                });
            } catch (JSONException | IOException ex) {
                LOGGER.log(Level.SEVERE, "handleButtonAction()", ex);
            }
            return null;
        }
    };
    new Thread(t).start();
}

From source file:com.thomaskuenneth.openweathermapweather.MainActivity.java

private void doIt() {
    new Thread(new Runnable() {
        public void run() {
            try {
                final WeatherData weather = WeatherUtils.getWeather(city.getText().toString());
                final Bitmap bitmapWeather = getImage(weather);
                runOnUiThread(new Runnable() {

                    @Override/*from  w w  w . j av  a 2  s.co  m*/
                    public void run() {
                        image.setImageBitmap(bitmapWeather);
                        beschreibung.setText(weather.description);
                        Double temp = weather.temp - 273.15;
                        temperatur.setText(getString(R.string.temp_template, temp.intValue()));
                        city.setSelection(0, city.getText().length());
                    }

                });
            } catch (IOException | JSONException ex) {
                Log.e(TAG, "doIt()", ex);
            }
        }
    }).start();
}

From source file:com.mobiquitynetworks.statsutilspig.CreateCombinations.java

public int[] getCombinationValues(Integer fieldsCardinality) {
    int[] combinations = new int[fieldsCardinality];
    for (int i = 1; i <= combinations.length; i++) {
        Double number = binomialCoefficientDouble(fieldsCardinality, i);
        combinations[i - 1] = number.intValue();
    }/*ww  w  . j  a v  a  2  s  .  c o  m*/
    return combinations;
}

From source file:com.thomaskuenneth.openweathermapweather.FXMLDocumentController.java

@FXML
void handleButtonAction(ActionEvent event) {
    Task<Void> t = new Task<Void>() {

        @Override//  w  ww.ja v a2  s.co  m
        protected Void call() throws Exception {
            try {
                final WeatherData weather = WeatherUtils.getWeather(city.getText());
                Platform.runLater(new Runnable() {

                    @Override
                    public void run() {
                        Image i = new Image("http://openweathermap.org/img/w/" + weather.icon + ".png");
                        image.setImage(i);
                        beschreibung.setText(weather.description);
                        Double temp = weather.temp - 273.15;
                        temperatur.setText(MessageFormat.format("{0} \u2103", temp.intValue()));
                    }

                });
            } catch (JSONException | IOException ex) {
                LOGGER.log(Level.SEVERE, "handleButtonAction()", ex);
            }
            return null;
        }
    };
    new Thread(t).start();
}

From source file:org.structr.core.property.IntProperty.java

@Override
public Integer convertToNumber(Double source) {

    if (source != null) {
        return source.intValue();
    }/*  ww  w.  j a v a2  s .c o m*/

    return null;
}

From source file:modelibra.designer.metaconceptgraphic.MetaConceptGraphic.java

public void setLocation(Point point) {
    Double xDouble = point.getX();
    Integer x = new Integer(xDouble.intValue());
    setX(x);/*from  ww  w. j a  va  2  s . c om*/

    Double yDouble = point.getY();
    Integer y = new Integer(yDouble.intValue());
    setY(y);
}

From source file:modelibra.designer.metaconceptgraphic.MetaConceptGraphic.java

public void setSize(Dimension dimension) {
    Double widthDouble = dimension.getWidth();
    Integer width = new Integer(widthDouble.intValue());
    setWidth(width);//  ww  w .  j a va2  s  .  c o  m

    Double heightDouble = dimension.getWidth();
    Integer height = new Integer(heightDouble.intValue());
    setHeight(height);
}

From source file:org.dkpro.tc.ml.liblinear.LiblinearTestTask.java

private void predict(TaskContext aContext, Model model, Problem test) throws Exception {
    File predFolder = aContext.getFolder("", AccessMode.READWRITE);
    String predFileName = LiblinearAdapter.getInstance()
            .getFrameworkFilename(AdapterNameEntries.predictionsFile);
    File predictionsFile = new File(predFolder, predFileName);

    BufferedWriter writer = new BufferedWriter(
            new OutputStreamWriter(new FileOutputStream(predictionsFile), "utf-8"));
    writer.append("#PREDICTION;GOLD" + "\n");

    Feature[][] testInstances = test.x;/*  w w w .  ja  va  2  s. com*/
    for (int i = 0; i < testInstances.length; i++) {
        Feature[] instance = testInstances[i];
        Double prediction = Linear.predict(model, instance);

        writer.write(prediction.intValue() + SEPARATOR_CHAR + new Double(test.y[i]).intValue());
        writer.write("\n");
    }

    writer.close();
}