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:io.coala.config.AbstractPropertyGetter.java

/**
 * @param defaultValue/*from  w ww  .  j a  va 2s .  c o m*/
 * @return
 */
public Float getFloat(final Float defaultValue) {
    final String value = get(defaultValue == null ? null : Float.toString(defaultValue));
    return value == null ? null : Float.valueOf(value);
}

From source file:com.phoenixnap.oss.ramlapisync.pojo.PojoBuilder.java

public PojoBuilder withField(String name, String type, String comment, RamlTypeValidations validations,
        String defaultValue) {//w  w  w.ja  v a  2s.c  o m
    pojoCreationCheck();
    logger.debug("Adding field: " + name + " to " + this.pojo.name());

    JClass resolvedType = resolveType(type);

    try {
        //If this class is a collection (List)- lets add an import
        if (resolvedType.fullName().startsWith(List.class.getName() + "<")) {
            resolvedType = this.pojo.owner().ref(List.class).narrow(resolvedType.getTypeParameters().get(0));
        }
        //If this class is a collection (Set) - lets add an import
        if (resolvedType.fullName().startsWith(Set.class.getName() + "<")) {
            resolvedType = this.pojo.owner().ref(Set.class).narrow(resolvedType.getTypeParameters().get(0));
        }
    } catch (Exception ex) {
        //skip import
    }

    //lets ignore this if parent contains it and we will use parent's in the constructor
    if (parentContainsField(this.pojo, name)) {
        return this;
    }

    JExpression jExpression = null;
    if (StringUtils.hasText(defaultValue)) {
        if (resolvedType.name().equals(Integer.class.getSimpleName())) {
            jExpression = JExpr.lit(Integer.valueOf(defaultValue));
        } else if (resolvedType.name().equals(Boolean.class.getSimpleName())) {
            jExpression = JExpr.lit(Boolean.valueOf(defaultValue));
        } else if (resolvedType.name().equals(Double.class.getSimpleName())) {
            jExpression = JExpr.lit(Double.valueOf(defaultValue));
        } else if (resolvedType.name().equals(Float.class.getSimpleName())) {
            jExpression = JExpr.lit(Float.valueOf(defaultValue));
        } else if (resolvedType.name().equals(Long.class.getSimpleName())) {
            jExpression = JExpr.lit(Long.valueOf(defaultValue));
        } else if (resolvedType.name().equals(BigDecimal.class.getSimpleName())) {
            jExpression = JExpr.direct("new BigDecimal(\"" + defaultValue + "\")");
        } else if (resolvedType.name().equals(String.class.getSimpleName())) {
            jExpression = JExpr.lit(defaultValue);
        } else if (type.contains(".") && resolvedType instanceof JDefinedClass
                && ((JDefinedClass) resolvedType).getClassType().equals(ClassType.ENUM)) {
            jExpression = JExpr
                    .direct(resolvedType.name() + "." + NamingHelper.cleanNameForJavaEnum(defaultValue));
        }
    } else if (resolvedType.fullName().startsWith(List.class.getName() + "<")) {
        JClass narrowedListClass = this.pojoModel.ref(ArrayList.class)
                .narrow(resolvedType.getTypeParameters().get(0));
        jExpression = JExpr._new(narrowedListClass);
    }

    // Add private variable
    JFieldVar field = this.pojo.field(JMod.PRIVATE, resolvedType, toJavaName(name), jExpression);
    if (this.config.isGenerateJSR303Annotations() && validations != null) {
        validations.annotateFieldJSR303(field);
    }

    if (StringUtils.hasText(comment)) {
        field.javadoc().add(comment);
    }
    String fieldName = NamingHelper.convertToClassName(name);

    // Add get method
    JMethod getter = this.pojo.method(JMod.PUBLIC, field.type(), "get" + fieldName);
    getter.body()._return(field);
    getter.javadoc().add("Returns the " + name + ".");
    getter.javadoc().addReturn().add(field.name());

    // Add set method
    JMethod setter = this.pojo.method(JMod.PUBLIC, this.pojoModel.VOID, "set" + fieldName);
    setter.param(field.type(), field.name());
    setter.body().assign(JExpr._this().ref(field.name()), JExpr.ref(field.name()));
    setter.javadoc().add("Set the " + name + ".");
    setter.javadoc().addParam(field.name()).add("the new " + field.name());

    //Add to Hashcode
    if (hashCodeBuilderInvocation != null) {
        hashCodeBuilderInvocation = hashCodeBuilderInvocation.invoke("append").arg(field);
    }
    if (equalsBuilderInvocation != null) {
        equalsBuilderInvocation = equalsBuilderInvocation.invoke("append").arg(field)
                .arg(otherObjectVar.ref(field.name()));
    }

    return this;
}

From source file:strat.mining.multipool.stats.builder.CoinsolverStatsBuilder.java

private AddressStats updateAddressStats(Address address, Date refreshDate) throws Exception {
    LOGGER.debug("Update addressStats for coinsolver address {}.", address.getAddress());
    long start = System.currentTimeMillis();

    strat.mining.multipool.stats.jersey.model.coinsolver.AddressStats rawAddressStats = coinsolverRestClient
            .getAddressStats(address.getAddress());

    AddressStats result = null;//from  www  .j  av a 2 s  .com
    if (rawAddressStats != null) {
        result = new AddressStats();
        result.setAddressId(address.getId());
        result.setBalance(
                rawAddressStats.getBtc_balance() == null ? 0 : Float.valueOf(rawAddressStats.getBtc_balance()));
        result.setUnexchanged(rawAddressStats.getBtc_unexchanged() == null ? 0
                : Float.valueOf(rawAddressStats.getBtc_unexchanged()));
        result.setImmature(rawAddressStats.getBtc_immature() == null ? 0
                : Float.valueOf(rawAddressStats.getBtc_immature()));
        result.setPaidout(rawAddressStats.getTotal_btc_paid() == null ? 0
                : Float.valueOf(rawAddressStats.getTotal_btc_paid()));
        result.setHashRate(
                rawAddressStats.getHashrate() == null ? 0 : Float.valueOf(rawAddressStats.getHashrate()));
        result.setRefreshTime(refreshDate);

        addressStatsDao.insertAddressStats(result);

    } else {
        throw new Exception("Unable to retrieve coinsolver raw stats for address " + address);
    }

    PERF_LOGGER.debug("coinsolver address {} updated in {} ms.", address.getAddress(),
            System.currentTimeMillis() - start);

    return result;
}

From source file:com.kircherelectronics.accelerationexplorer.activity.NoiseActivity.java

private float getPrefMedianFilterSmoothingTimeConstant() {
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());

    return Float.valueOf(prefs.getString(NoiseConfigActivity.MEDIAN_FILTER_SMOOTHING_TIME_CONSTANT_KEY, "1"));
}

From source file:net.librec.conf.Configuration.java

public Float getFloat(String name) {
    String value = get(name);// w  w  w.j  a va 2s  .  c  om
    if (StringUtils.isNotBlank(value)) {
        return Float.valueOf(value);
    } else {
        return null;
    }
}

From source file:com.streamreduce.storm.bolts.InventoryItemMetricsBolt.java

/**
 * {@inheritDoc}/*from w  ww  . j  a  va 2s .c o m*/
 */
@Override
public void handleEvent(String id, Long timestamp, EventId eventId, String accountId, String userId,
        String targetId, Map<String, Object> metadata) {
    switch (eventId) {
    case CREATE:
    case DELETE:
        String connectionId = metadata.get("targetConnectionId").toString();
        String providerType = metadata.get("targetProviderType").toString();
        String targetType = metadata.get("targetType").toString();
        String objectType = getExternalObjectType(metadata);
        Float eventValue = getEventValue(eventId);
        List<Values> metrics = new ArrayList<>();

        if (providerType.equals(ConnectionTypeConstants.CLOUD_TYPE)) {
            String iso3166Code = (String) metadata.get("targetISO3166Code");
            String region = (String) metadata.get("targetRegion");
            String zone = (String) metadata.get("targetZone");
            String osName = (String) metadata.get("targetOS");

            for (String criteriaName : ImmutableSet.of("iso3166Code", "region", "zone", "osName")) {
                MetricCriteria metricCriteria;
                String criteriaValue;

                if (criteriaName.equals("iso3166Code")) {
                    criteriaValue = iso3166Code;
                    metricCriteria = MetricCriteria.ISO_3166_CODE;
                } else if (criteriaName.equals("region")) {
                    criteriaValue = region;
                    metricCriteria = MetricCriteria.REGION;
                } else if (criteriaName.equals("zone")) {
                    criteriaValue = zone;
                    metricCriteria = MetricCriteria.AVAILABILITY_ZONE;
                } else if (criteriaName.equals("osName")) {
                    criteriaValue = osName;
                    metricCriteria = MetricCriteria.OS_NAME;
                } else {
                    LOGGER.error(criteriaName + " is an unsupported CloudInventoryItem metric.");
                    return;
                }

                // If we have an empty value, no need in processing it
                if (!StringUtils.hasText(criteriaValue)) {
                    return;
                }

                // Global (metric name specific)
                metrics.add(createGlobalMetric(MetricName.INVENTORY_ITEM_COUNT,
                        ImmutableMap.of(metricCriteria, criteriaValue), MetricModeType.DELTA, timestamp,
                        eventValue));

                // Account specific (metric name specific)
                metrics.add(createAccountMetric(accountId, MetricName.INVENTORY_ITEM_COUNT,
                        ImmutableMap.of(metricCriteria, criteriaValue), MetricModeType.DELTA, timestamp,
                        eventValue));

                // Connection specific
                metrics.add(createAccountMetric(
                        accountId, MetricName.INVENTORY_ITEM_COUNT, ImmutableMap.of(metricCriteria,
                                criteriaValue, MetricCriteria.CONNECTION_ID, connectionId),
                        MetricModeType.DELTA, timestamp, eventValue));

                if (objectType != null) {
                    // Global (metric name specific)
                    metrics.add(createGlobalMetric(
                            MetricName.INVENTORY_ITEM_COUNT, ImmutableMap.of(metricCriteria, criteriaValue,
                                    MetricCriteria.OBJECT_TYPE, objectType),
                            MetricModeType.DELTA, timestamp, eventValue));

                    // Account specific (metric name specific)
                    metrics.add(createAccountMetric(
                            accountId, MetricName.INVENTORY_ITEM_COUNT, ImmutableMap.of(metricCriteria,
                                    criteriaValue, MetricCriteria.OBJECT_TYPE, objectType),
                            MetricModeType.DELTA, timestamp, eventValue));

                    // Connection specific
                    metrics.add(createAccountMetric(accountId, MetricName.INVENTORY_ITEM_COUNT,
                            ImmutableMap.of(metricCriteria, criteriaValue, MetricCriteria.CONNECTION_ID,
                                    connectionId, MetricCriteria.OBJECT_TYPE, objectType),
                            MetricModeType.DELTA, timestamp, eventValue));
                }
            }
        }

        emitMetricsAndHashagMetrics(metrics, eventId, targetId, targetType, metadata);
        break;
    case ACTIVITY:
        String providerId = metadata.get("targetProviderId").toString();

        if (providerId.equals(ProviderIdConstants.AWS_PROVIDER_ID)) {
            Map<String, Object> metricsPayload = (Map<String, Object>) metadata.get("payload");

            if (metadata.containsKey("isAgentActivity")
                    && Boolean.valueOf(metadata.get("isAgentActivity").toString())) {
                JSONObject json = JSONUtils.flattenJSON(JSONObject.fromObject(metadata.get("payload")), null);

                for (Object rawKey : json.keySet()) {
                    String key = rawKey.toString();
                    Object value = json.get(key);

                    // elapsed_time and generated are not metrics
                    if (key.equals("elapsed_time") || key.equals("generated")) {
                        continue;
                    }

                    if (value != null && !(value instanceof JSONNull)) {
                        emitAccountMetric(accountId, MetricName.INVENTORY_ITEM_RESOURCE_USAGE,
                                ImmutableMap.of(MetricCriteria.OBJECT_ID, targetId, MetricCriteria.RESOURCE_ID,
                                        key, MetricCriteria.METRIC_ID, key),
                                MetricModeType.ABSOLUTE, timestamp, Float.valueOf(json.get(key).toString()));
                    }
                }
            } else {
                Set<String> knownMetricKeys = ImmutableSet.of("maximum", "minimum", "average");

                for (Map.Entry<String, Object> metric : metricsPayload.entrySet()) {
                    String key = metric.getKey();
                    Map<String, Object> metricJson = (Map<String, Object>) metric.getValue();

                    for (String metricKey : knownMetricKeys) {
                        emitAccountMetric(accountId, MetricName.INVENTORY_ITEM_RESOURCE_USAGE,
                                ImmutableMap.of(MetricCriteria.OBJECT_ID, targetId, MetricCriteria.RESOURCE_ID,
                                        key, MetricCriteria.METRIC_ID, metricKey),
                                MetricModeType.ABSOLUTE, timestamp,
                                Float.valueOf(metricJson.get(metricKey).toString()));
                    }
                }
            }
        } else if (providerId.equals(ProviderIdConstants.PINGDOM_PROVIDER_ID)) {
            Map<String, Object> payload = metadata.containsKey("payload")
                    ? (Map<String, Object>) metadata.get("payload")
                    : null;

            if (payload != null) {
                int lastresponsetime = payload.containsKey("lastresponsetime")
                        ? (Integer) payload.get("lastresponsetime")
                        : 0;
                emitAccountMetric(accountId, MetricName.INVENTORY_ITEM_RESOURCE_USAGE,
                        ImmutableMap.of(MetricCriteria.OBJECT_ID, targetId, MetricCriteria.RESOURCE_ID,
                                "ServerResponse", MetricCriteria.METRIC_ID, "time"),
                        MetricModeType.ABSOLUTE, timestamp, (float) lastresponsetime);
            }
        } else if (providerId.equals(ProviderIdConstants.CUSTOM_PROVIDER_ID)) {
            Map<String, Object> payload = metadata.containsKey("payload")
                    ? (Map<String, Object>) metadata.get("payload")
                    : null;

            if (payload != null && payload.containsKey("metrics")) {
                Set<Object> imgMetrics = (Set<Object>) payload.get("metrics");

                for (Object rawMetric : imgMetrics) {
                    Map<String, Object> metric = (Map<String, Object>) rawMetric;

                    emitAccountMetric(accountId, MetricName.INVENTORY_ITEM_RESOURCE_USAGE,
                            ImmutableMap.of(MetricCriteria.OBJECT_ID, targetId, MetricCriteria.RESOURCE_ID,
                                    (String) metric.get("name")),
                            MetricModeType.valueOf((String) metric.get("type")), timestamp,
                            Float.valueOf((metric.get("value")).toString()));
                }
            }
        } else if (providerId.equals(ProviderIdConstants.NAGIOS_PROVIDER_ID)) {
            Map<String, Object> payload = metadata.containsKey("payload")
                    ? (Map<String, Object>) metadata.get("payload")
                    : null;

            if (payload != null && payload.containsKey("metrics")) {
                Set<Object> imgMetrics = (Set<Object>) payload.get("metrics");

                for (Object rawMetric : imgMetrics) {
                    Map<String, Object> metric = (Map<String, Object>) rawMetric;
                    String[] nameTokens = ((String) metric.get("name")).split("_");

                    emitAccountMetric(accountId, MetricName.INVENTORY_ITEM_RESOURCE_USAGE,
                            ImmutableMap.of(MetricCriteria.OBJECT_ID, targetId.toString(),
                                    MetricCriteria.RESOURCE_ID, nameTokens[0], MetricCriteria.METRIC_ID,
                                    nameTokens[1]),
                            MetricModeType.valueOf((String) metric.get("type")), timestamp,
                            Float.valueOf((metric.get("value")).toString()));
                }
            }
        }
        break;
    default:
        // Due to the nature of how built-in metrics work and such, you can end up with events
        // being passed through that are expected but unprocessed.  No need to log.
    }
}

From source file:ml.dmlc.xgboost4j.java.XGBoost.java

/**
 * Aggregate cross-validation results./*from  w  ww .  j  a va  2s .  c o m*/
 *
 * @param results eval info from each data sample
 * @return cross-validation eval info
 */
private static String aggCVResults(String[] results) {
    Map<String, List<Float>> cvMap = new HashMap<String, List<Float>>();
    String aggResult = results[0].split("\t")[0];
    for (String result : results) {
        String[] items = result.split("\t");
        for (int i = 1; i < items.length; i++) {
            String[] tup = items[i].split(":");
            String key = tup[0];
            Float value = Float.valueOf(tup[1]);
            if (!cvMap.containsKey(key)) {
                cvMap.put(key, new ArrayList<Float>());
            }
            cvMap.get(key).add(value);
        }
    }

    for (String key : cvMap.keySet()) {
        float value = 0f;
        for (Float tvalue : cvMap.get(key)) {
            value += tvalue;
        }
        value /= cvMap.get(key).size();
        aggResult += String.format("\tcv-%s:%f", key, value);
    }

    return aggResult;
}

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

public void addProperty(final Enum<?> key, final float f) {
    super.addProperty(key.name().toLowerCase(), Float.valueOf(f));
}

From source file:com.kircherelectronics.gyroscopeexplorer.activity.filter.Orientation.java

private float getPrefMeanFilterSmoothingTimeConstant() {
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);

    return Float.valueOf(prefs.getString(ConfigActivity.MEAN_FILTER_SMOOTHING_TIME_CONSTANT_KEY, "0.5"));
}