Example usage for java.lang Float valueOf

List of usage examples for java.lang Float valueOf

Introduction

In this page you can find the example usage for java.lang Float valueOf.

Prototype

@HotSpotIntrinsicCandidate
public static Float valueOf(float f) 

Source Link

Document

Returns a Float instance representing the specified float value.

Usage

From source file:de.unisb.cs.st.javalanche.mutation.util.AddOffutt96Sufficient.java

public static void addUoiForConstants() {
    Session session = sessionFactory.openSession();
    Transaction tx = session.beginTransaction();
    String projectPrefix = ConfigurationLocator.getJavalancheConfiguration().getProjectPrefix();
    Query query = session.createQuery(
            "from Mutation as m where className LIKE '" + projectPrefix + "%' and m.mutationType=:type");
    query.setParameter("type", MutationType.REPLACE_CONSTANT);
    @SuppressWarnings("unchecked")
    List<Mutation> results = query.list();
    for (Mutation m : results) {
        // System.out.println("Mutation " + m);
        if (checkCovered(m) && m.getBaseMutationId() == null) {
            String addInfo = m.getAddInfo();
            String origValue = getRicOriginalValue(addInfo);
            TypeInfo type = getTypeInfo(addInfo);
            String[] replaceValues = null;
            if (type.equals(TypeInfo.DOUBLE)) {
                Double d = Double.valueOf(origValue);
                replaceValues = new String[] { -d + "" };
            } else if (type.equals(TypeInfo.FLOAT)) {
                Float f = Float.valueOf(origValue);
                replaceValues = new String[] { -f + "" };

            } else if (type.equals(TypeInfo.INT)) {
                Integer i = Integer.valueOf(origValue);
                replaceValues = new String[] { -i + "", ~i + "" };
            } else if (type.equals(TypeInfo.LONG)) {
                Long l = Long.valueOf(origValue);
                replaceValues = new String[] { -l + "", ~l + "" };
            } else {
                throw new RuntimeException("Did not expect value of type " + type);
            }//from  ww w  .  j av  a2  s .  c  o  m

            boolean baseMutationUsed = false;
            for (String replaceVal : replaceValues) {

                if (baseMutationUsed) {
                    Mutation m2 = Mutation.copyMutation(m);
                    PossibilitiesRicMethodAdapter.setAddInfo(m2, origValue, replaceVal, type);
                    if (QueryManager.getMutationOrNull(m2) == null) {
                        // System.out.println("New mutation " + m2);
                        QueryManager.saveMutation(m2);

                        MutationCoverageFile.addDerivedMutation(m.getId(), m2.getId());
                    }
                } else {
                    Mutation m2 = Mutation.copyMutation(m);
                    PossibilitiesRicMethodAdapter.setAddInfo(m2, origValue, replaceVal, type);
                    if (QueryManager.getMutationOrNull(m2) == null) {
                        PossibilitiesRicMethodAdapter.setAddInfo(m, origValue, replaceVal, type);
                        // QueryManager.updateMutation(m, null);
                        // System.out.println("Updated mutation " + m);
                        session.update(m);
                        baseMutationUsed = true;
                    }
                }
            }
        } else {
            session.delete(m);
        }
        session.flush();
    }
    tx.commit();
    session.close();
    MutationCoverageFile.update();
}

From source file:com.bringcommunications.etherpay.SendActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    overlay_frame_layout = new FrameLayout(getApplicationContext());
    setContentView(overlay_frame_layout);
    ////  w  w  w .ja  v a 2  s .co  m
    context = this;
    hex = new Hex();
    preferences = getSharedPreferences("etherpay.bringcommunications.com", MODE_PRIVATE);
    private_key = preferences.getString("key", private_key);
    acct_addr = preferences.getString("acct_addr", acct_addr);
    long wei_balance = preferences.getLong("balance", 0);
    eth_balance = (float) wei_balance / Util.WEI_PER_ETH;
    price = preferences.getFloat("price", price);
    show_gas = preferences.getBoolean("show_gas", show_gas);
    show_data = preferences.getBoolean("show_data", show_data);
    boolean denomination_eth = preferences.getBoolean("denomination_eth", true);
    System.out.println("denomination_eth is " + denomination_eth);
    denomination = denomination_eth ? Denomination.ETH : Denomination.FINNEY;
    auto_pay = getIntent().getStringExtra("AUTO_PAY");
    to_addr = getIntent().getStringExtra("TO_ADDR");
    String size_str = getIntent().getStringExtra("SIZE");
    eth_size = Float.valueOf(size_str);
    data = getIntent().getStringExtra("DATA");
    send_is_done = false;
    //
    View activity_send_view = getLayoutInflater().inflate(R.layout.activity_send, overlay_frame_layout, false);
    setContentView(activity_send_view);
    //
    Spinner dropdown = (Spinner) findViewById(R.id.denomination);
    String[] items = new String[] { "ETH", "Finney" };
    ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_dropdown_item,
            items);
    dropdown.setSelection((denomination == Denomination.ETH) ? 0 : 1);
    dropdown.setOnItemSelectedListener(this);
    dropdown.setAdapter(adapter);
    //
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    String app_name = getResources().getString(R.string.app_name);
    toolbar.setTitle(app_name);
    toolbar.setSubtitle("Send Payment");
    toolbar.setBackgroundResource(R.color.color_toolbar);
    setSupportActionBar(toolbar);
    //
    TextView to_addr_view = (TextView) findViewById(R.id.to_addr);
    to_addr_view.setText(to_addr);
    //
    TextView size_view = (TextView) findViewById(R.id.size);
    size_str = (denomination == Denomination.ETH) ? String.format("%1.03f", eth_size)
            : String.format("%03d", (int) (eth_size * 1000 + 0.5));
    size_view.setText(size_str);
    //
    LinearLayout gas_layout = (LinearLayout) findViewById(R.id.gas_layout);
    TextView gas_prompt_view = (TextView) findViewById(R.id.gas_prompt);
    TextView gas_view = (TextView) findViewById(R.id.gas);
    ImageButton gas_help_view = (ImageButton) findViewById(R.id.gas_help);
    if (show_gas) {
        String gas_str = String.format("%7d", gas_limit);
        gas_view.setText(gas_str);
        gas_layout.setVisibility(View.VISIBLE);
        gas_prompt_view.setVisibility(View.VISIBLE);
        gas_help_view.setVisibility(View.VISIBLE);
        gas_view.setVisibility(View.VISIBLE);
    } else {
        gas_layout.setVisibility(View.GONE);
        gas_prompt_view.setVisibility(View.GONE);
        gas_help_view.setVisibility(View.GONE);
        gas_view.setVisibility(View.GONE);
    }

    LinearLayout data_layout = (LinearLayout) findViewById(R.id.data_layout);
    TextView data_prompt_view = (TextView) findViewById(R.id.data_prompt);
    TextView data_view = (TextView) findViewById(R.id.data);
    ImageButton data_help_view = (ImageButton) findViewById(R.id.data_help);
    if (show_data) {
        data_view.setText(data);
        data_layout.setVisibility(View.VISIBLE);
        data_prompt_view.setVisibility(View.VISIBLE);
        data_help_view.setVisibility(View.VISIBLE);
        data_view.setVisibility(View.VISIBLE);
    } else {
        data = "";
        data_layout.setVisibility(View.GONE);
        data_prompt_view.setVisibility(View.GONE);
        data_help_view.setVisibility(View.GONE);
        data_view.setVisibility(View.GONE);
    }

    //
    //sanity check
    if (to_addr.length() != 42) {
        this.finish();
    }
}

From source file:com.laxser.blitz.web.paramresolver.MethodParameterResolver.java

public Object[] resolve(final Invocation inv, final ParameterBindingResult parameterBindingResult)
        throws Exception {
    Object[] parameters = new Object[paramMetaDatas.length];
    for (int i = 0; i < resolvers.length; i++) {
        if (resolvers[i] == null) {
            continue;
        }/*from   ww  w .j av a 2 s  . co  m*/
        try {
            if (logger.isDebugEnabled()) {
                logger.debug("Resolves parameter " + paramMetaDatas[i].getParamType().getSimpleName()
                        + " using " + resolvers[i].getClass().getName());
            }
            parameters[i] = resolvers[i].resolve(inv, paramMetaDatas[i]);
            // afterPropertiesSet
            if (parameters[i] instanceof InitializingBean) {
                ((InitializingBean) parameters[i]).afterPropertiesSet();
            }
        } catch (TypeMismatchException e) {
            // ???bean???

            logger.debug("", e);

            // ???
            if (paramMetaDatas[i].getParamType().isPrimitive()) {
                DefValue defValudeAnnotation = paramMetaDatas[i].getAnnotation(DefValue.class);
                if (defValudeAnnotation == null
                        || DefValue.NATIVE_DEFAULT.equals(defValudeAnnotation.value())) {
                    // ?if-else?converter???
                    if (paramMetaDatas[i].getParamType() == int.class) {
                        parameters[i] = Integer.valueOf(0);
                    } else if (paramMetaDatas[i].getParamType() == long.class) {
                        parameters[i] = Long.valueOf(0);
                    } else if (paramMetaDatas[i].getParamType() == boolean.class) {
                        parameters[i] = Boolean.FALSE;
                    } else if (paramMetaDatas[i].getParamType() == double.class) {
                        parameters[i] = Double.valueOf(0);
                    } else if (paramMetaDatas[i].getParamType() == float.class) {
                        parameters[i] = Float.valueOf(0);
                    } else {
                        TypeConverter typeConverter = SafedTypeConverterFactory.getCurrentConverter();
                        parameters[i] = typeConverter.convertIfNecessary("0", paramMetaDatas[i].getParamType());
                    }
                } else {
                    TypeConverter typeConverter = SafedTypeConverterFactory.getCurrentConverter();
                    parameters[i] = typeConverter.convertIfNecessary(defValudeAnnotation.value(),
                            paramMetaDatas[i].getParamType());
                }
            }
            // 
            String paramName = parameterNames[i];
            if (paramName == null) {
                for (String name : paramMetaDatas[i].getParamNames()) {
                    if ((paramName = name) != null) {
                        break;
                    }
                }
            }
            Assert.isTrue(paramName != null);
            FieldError fieldError = new FieldError(//
                    "method", // ????method
                    paramName, // ??????
                    inv.getParameter(paramName), // ?
                    true, //whether this error represents a binding failure (like a type mismatch); else, it is a validation failure
                    new String[] { e.getErrorCode() }, // "typeMismatch"
                    new String[] { inv.getParameter(paramName) }, //the array of arguments to be used to resolve this message
                    null // the default message to be used to resolve this message
            );
            parameterBindingResult.addError(fieldError);
        } catch (Exception e) {
            // ????
            logger.error("", e);
            throw e;
        }
    }
    return parameters;
}

From source file:com.workday.autoparse.json.demo.InstanceUpdaterTest.java

@Test
public void testBoxedPrimitives() {
    TestObject testObject = new TestObject();
    testObject.myBoxedBoolean = false;//from  w  ww. j a v  a 2 s . c o m
    testObject.myBoxedByte = 1;
    testObject.myBoxedChar = 'a';
    testObject.myBoxedDouble = 1.1;
    testObject.myBoxedFloat = 1.1f;
    testObject.myBoxedInt = 1;
    testObject.myBoxedLong = 1L;
    testObject.myBoxedShort = 1;

    Map<String, Object> updates = new HashMap<>();
    updates.put("myBoxedBoolean", true);
    updates.put("myBoxedByte", (byte) 2);
    updates.put("myBoxedChar", 'b');
    updates.put("myBoxedDouble", 2.2);
    updates.put("myBoxedFloat", 2.2f);
    updates.put("myBoxedInt", 2);
    updates.put("myBoxedLong", 2L);
    updates.put("myBoxedShort", (short) 2);

    TestObject$$JsonObjectParser.INSTANCE.updateInstanceFromMap(testObject, updates, CONTEXT);

    assertEquals("myBoxedBoolean", true, testObject.myBoxedBoolean);
    assertEquals("myBoxedByte", Byte.valueOf((byte) 2), testObject.myBoxedByte);
    assertEquals("myBoxedChar", Character.valueOf('b'), testObject.myBoxedChar);
    assertEquals("myBoxedDouble", Double.valueOf(2.2), testObject.myBoxedDouble);
    assertEquals("myBoxedFloat", Float.valueOf(2.2f), testObject.myBoxedFloat);
    assertEquals("myBoxedInt", Integer.valueOf(2), testObject.myBoxedInt);
    assertEquals("myBoxedLong", Long.valueOf(2L), testObject.myBoxedLong);
    assertEquals("myBoxedShort", Short.valueOf((short) 2), testObject.myBoxedShort);
}

From source file:com.linkedin.pinot.common.data.FieldSpec.java

private static Object getDefaultNullValue(@Nonnull FieldType fieldType, @Nonnull DataType dataType,
        String stringDefaultNullValue) {
    if (stringDefaultNullValue != null) {
        switch (dataType) {
        case INT:
            return Integer.valueOf(stringDefaultNullValue);
        case LONG:
            return Long.valueOf(stringDefaultNullValue);
        case FLOAT:
            return Float.valueOf(stringDefaultNullValue);
        case DOUBLE:
            return Double.valueOf(stringDefaultNullValue);
        case STRING:
            return stringDefaultNullValue;
        case BYTES:
            try {
                return new ByteArray(Hex.decodeHex(stringDefaultNullValue.toCharArray()));
            } catch (DecoderException e) {
                Utils.rethrowException(e); // Re-throw to avoid handling exceptions in all callers.
            }//from w  w  w.j  a  v a 2 s.c  o  m
        default:
            throw new UnsupportedOperationException("Unsupported data type: " + dataType);
        }
    } else {
        switch (fieldType) {
        case METRIC:
            switch (dataType) {
            case INT:
                return DEFAULT_METRIC_NULL_VALUE_OF_INT;
            case LONG:
                return DEFAULT_METRIC_NULL_VALUE_OF_LONG;
            case FLOAT:
                return DEFAULT_METRIC_NULL_VALUE_OF_FLOAT;
            case DOUBLE:
                return DEFAULT_METRIC_NULL_VALUE_OF_DOUBLE;
            case STRING:
                return DEFAULT_METRIC_NULL_VALUE_OF_STRING;
            case BYTES:
                return DEFAULT_METRIC_NULL_VALUE_OF_BYTES;
            default:
                throw new UnsupportedOperationException(
                        "Unknown default null value for metric field of data type: " + dataType);
            }
        case DIMENSION:
        case TIME:
        case DATE_TIME:
            switch (dataType) {
            case INT:
                return DEFAULT_DIMENSION_NULL_VALUE_OF_INT;
            case LONG:
                return DEFAULT_DIMENSION_NULL_VALUE_OF_LONG;
            case FLOAT:
                return DEFAULT_DIMENSION_NULL_VALUE_OF_FLOAT;
            case DOUBLE:
                return DEFAULT_DIMENSION_NULL_VALUE_OF_DOUBLE;
            case STRING:
                return DEFAULT_DIMENSION_NULL_VALUE_OF_STRING;
            case BYTES:
                return DEFAULT_DIMENSION_NULL_VALUE_OF_BYTES;
            default:
                throw new UnsupportedOperationException(
                        "Unknown default null value for dimension/time field of data type: " + dataType);
            }
        default:
            throw new UnsupportedOperationException("Unsupported field type: " + fieldType);
        }
    }
}

From source file:controllers.transformer.ExcelTransformer.java

public byte[] getBytes() {
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    HSSFWorkbook wb = new HSSFWorkbook();
    HSSFSheet sheet = wb.createSheet("Sheet1");

    if (results == null) {
        results = survey.resultCollection;
    }/*ww  w .ja  v  a2 s  .co  m*/

    /** Header **/
    HSSFRow row = sheet.createRow(0);
    int fieldcounter = 0;
    row.createCell(fieldcounter++).setCellValue("ResultId");
    row.createCell(fieldcounter++).setCellValue("SurveyId");
    row.createCell(fieldcounter++).setCellValue("Title");
    row.createCell(fieldcounter++).setCellValue("Start time");
    row.createCell(fieldcounter++).setCellValue("End time");
    row.createCell(fieldcounter++).setCellValue("Date Sent");
    row.createCell(fieldcounter++).setCellValue("User");
    row.createCell(fieldcounter++).setCellValue("Phone Number");
    row.createCell(fieldcounter++).setCellValue("Lat");
    row.createCell(fieldcounter++).setCellValue("Lon");

    /** Header Fields**/
    for (Question question : survey.getQuestions()) {
        row.createCell(fieldcounter++).setCellValue(question.label);
    }

    int countrow = 0;
    row = sheet.createRow(++countrow);

    //SimpleDateFormat dateFormat = new SimpleDateFormat("EEE, d MMM yyyy HH:mm:ss Z");
    SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss Z");

    for (NdgResult result : results) {
        fieldcounter = 0;
        row.createCell(fieldcounter++).setCellValue(result.resultId);
        row.createCell(fieldcounter++).setCellValue(result.survey.surveyId);
        row.createCell(fieldcounter++).setCellValue(result.title);
        row.createCell(fieldcounter++).setCellValue(dateFormat.format(result.startTime));
        row.createCell(fieldcounter++).setCellValue(dateFormat.format(result.endTime));

        if (result.dateSent != null) {
            row.createCell(fieldcounter++).setCellValue(dateFormat.format(result.dateSent));
        } else {
            row.createCell(fieldcounter++).setCellValue("");
        }

        row.createCell(fieldcounter++).setCellValue(result.ndgUser.username);
        row.createCell(fieldcounter++).setCellValue(result.ndgUser.phoneNumber);
        row.createCell(fieldcounter++).setCellValue(result.latitude);
        row.createCell(fieldcounter++).setCellValue(result.longitude);

        for (Question question : survey.getQuestions()) {//to ensure right answer order
            Collection<Answer> answers = CollectionUtils.intersection(question.answerCollection,
                    result.answerCollection);//only one should left, hope that it does not modify results
            if (answers.isEmpty()) {
                row.createCell(fieldcounter++).setCellValue("");
            } else if (answers.size() == 1) {
                Answer answer = answers.iterator().next();
                if (answer.question.questionType.typeName.equalsIgnoreCase(QuestionTypesConsts.IMAGE)) {//TODO handle other binary data
                    row.createCell(fieldcounter++).setCellValue(storeImagesAndGetValueToExport(survey.surveyId,
                            result.resultId, answer.id, answer.binaryData));
                } else if (answer.question.questionType.typeName.equalsIgnoreCase(QuestionTypesConsts.INT)) {
                    Integer value = Integer.valueOf(answer.textData);
                    row.createCell(fieldcounter++).setCellValue(value);
                } else if (answer.question.questionType.typeName
                        .equalsIgnoreCase(QuestionTypesConsts.DECIMAL)) {
                    Float value = Float.valueOf(answer.textData);
                    row.createCell(fieldcounter++).setCellValue(value);
                } else {
                    String value = answer.textData;
                    value = value.trim().replaceAll("\n", "");
                    row.createCell(fieldcounter++).setCellValue(value);
                }
            } else {
                Logger.getAnonymousLogger().log(Level.WARNING,
                        "to many answers. ResID={0}questioId={1}answerCount={2}",
                        new Object[] { result.resultId, question.id, question.answerCollection.size() });
                break;
            }
        }
        row = sheet.createRow(++countrow);
    }
    try {
        wb.write(out);
    } catch (IOException e) {
        e.printStackTrace();
    }
    return out.toByteArray();
}

From source file:com.hybris.mobile.activity.StoreLocatorActivity.java

@Override
protected void onResume() {
    super.onResume();

    handleIntent();/* www  .ja va  2s.c o m*/

    // Launching the activity from an intent, we try to look if there is a city identifier or just a radius (geolocation)
    if (getIntent().hasExtra(DataConstants.STORE_LOCATOR_RADIUS_VALUE)
            || (getIntent().hasExtra(DataConstants.STORE_LOCATOR_LAT)
                    && getIntent().hasExtra(DataConstants.STORE_LOCATOR_LONG)
                    && getIntent().hasExtra(DataConstants.STORE_LOCATOR_RADIUS_VALUE))) {
        String radiusValue = getIntent().getStringExtra(DataConstants.STORE_LOCATOR_RADIUS_VALUE);
        String latValue = getIntent().getStringExtra(DataConstants.STORE_LOCATOR_LAT);
        String longValue = getIntent().getStringExtra(DataConstants.STORE_LOCATOR_LONG);

        // Is geolocation?
        boolean isGeolocation = StringUtils.isNotEmpty(radiusValue) && StringUtils.isEmpty(latValue)
                && StringUtils.isEmpty(longValue);

        // Geolocation, we just need the radius
        if (isGeolocation) {

            try {
                mRadius = Float.valueOf(radiusValue);

                // Getting the user coordinates
                setCurrentUserLocation();
            } catch (Exception e) {
                // do nothing, error in case of wrong radius format
            }

        }
        // Store location by coordinates, we need the longitude, latitude and the radius
        else if (StringUtils.isNotEmpty(latValue) && StringUtils.isNotEmpty(longValue)
                && StringUtils.isNotEmpty(radiusValue)) {

            mRadius = Float.valueOf(radiusValue);
            float latitude = Float.valueOf(latValue);
            float longitude = Float.valueOf(longValue);

            // Creating a new location based on the coordinates
            Location location = new Location("");
            location.reset();
            location.setLatitude(latitude);
            location.setLongitude(longitude);

            fetchStoreFromParticularLocation(location);

        }
    }

}

From source file:de.codesourcery.geoip.GeoLocation.java

private static Map<String, Object> readMap(JSONObject jsonObject) {
    Map<String, Object> result = new HashMap<>();
    final String[] names = JSONObject.getNames(jsonObject);
    if (names == null) {
        return result;
    }/* w  ww  .  j  a  v a  2s. c om*/
    for (String key : names) {

        final JSONObject pair = jsonObject.getJSONObject(key);
        final String type = pair.getString("t");
        final Object value;
        switch (type) {
        case "l":
            value = pair.getLong("v");
            break;
        case "i":
            value = Integer.valueOf((int) pair.getLong("v"));
            break;
        case "s":
            value = pair.getString("v");
            break;
        case "d":
            value = pair.getDouble("v");
            break;
        case "f":
            value = Float.valueOf((float) pair.getDouble("v"));
            break;
        default:
            throw new JSONException("Unhandled type: >" + type + "<");
        }
        result.put(key, value);
    }
    return result;
}

From source file:org.nabucco.alfresco.enhScriptEnv.common.script.converter.general.NumberConverter.java

protected Object convertNumber(final Object value, final Class<?> expectedClass) {
    if (!(value instanceof Number)) {
        throw new IllegalArgumentException("value must be a " + Number.class);
    }/*from ww w  .  j  a v  a 2s  .  c  o m*/

    final Number resultNumber;
    if (expectedClass.isAssignableFrom(Number.class)) {
        final double doubleValue = ((Number) value).doubleValue();
        if (doubleValue == Math.floor(doubleValue)) {
            resultNumber = Long.valueOf(Math.round(Math.floor(doubleValue)));
        } else {
            resultNumber = Double.valueOf(doubleValue);
        }
    } else if (Integer.class.equals(expectedClass) || int.class.equals(expectedClass)) {
        resultNumber = Integer.valueOf(((Number) value).intValue());
    } else if (Long.class.equals(expectedClass) || long.class.equals(expectedClass)) {
        resultNumber = Long.valueOf(((Number) value).longValue());
    } else if (Float.class.equals(expectedClass) || float.class.equals(expectedClass)) {
        resultNumber = Float.valueOf(((Number) value).floatValue());
    } else if (Double.class.equals(expectedClass) || double.class.equals(expectedClass)) {
        resultNumber = Double.valueOf(((Number) value).doubleValue());
    } else if (Byte.class.equals(expectedClass) || byte.class.equals(expectedClass)) {
        resultNumber = Byte.valueOf(((Number) value).byteValue());
    } else {
        resultNumber = Short.valueOf(((Number) value).shortValue());
    }

    return resultNumber;
}

From source file:it.unimi.dsi.util.Properties.java

public void addProperty(final String key, final float f) {
    super.addProperty(key, Float.valueOf(f));
}