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:com.senior.g40.servlet.RescuerAppInServlet.java

private float getF(String param) {
    return Float.valueOf(request.getParameter(param));
}

From source file:com.chinamobile.bcbsp.examples.bytearray.pagerank.PRBSPNew.java

@Override
public void compute(Iterator<PageRankMessage> messages, BSPStaffContextInterface context) throws Exception {
    // Receive messages sent to this Vertex.
    //LOG.info("Vertex is processed! PRBSPNew");
    receivedMsgValue = 0.0f;// w  ww .j av  a  2  s. c om
    receivedMsgSum = 0.0f;
    int i = 0;
    while (messages.hasNext()) {
        // Note Modified
        i++;
        receivedMsgValue = (messages.next()).getContent();
        receivedMsgSum += receivedMsgValue;
    }
    PRVertexLiteNew vertex = (PRVertexLiteNew) context.getVertex();
    // Handle received messages and Update vertex value.
    if (context.getCurrentSuperStepCounter() == 0) {
        sendMsgValue = Float.valueOf(vertex.getVertexValue()) / context.getOutgoingEdgesNum(); // old vertex value
    } else {
        newVertexValue = (float) (CLICK_RP * FACTOR + receivedMsgSum * (1 - FACTOR));
        sendMsgValue = newVertexValue / context.getOutgoingEdgesNum();
        vertex.setVertexValue(newVertexValue);
        context.updateVertex(vertex);
    }
    // Send new messages.
    outgoingEdges = context.getOutgoingEdges();
    while (outgoingEdges.hasNext()) {
        edge = (PREdgeLiteNew) outgoingEdges.next();
        // Note Improved For Message Reuse.
        msg = (PageRankMessage) context.getMessage();
        msg.setContent(sendMsgValue);
        msg.setMessageId(edge.getVertexID());
        context.send(msg);
    }
    return;
}

From source file:at.favre.tools.dconvert.ui.CLIInterpreter.java

public static Arguments parse(String[] args) {
    ResourceBundle strings = ResourceBundle.getBundle("bundles.strings", Locale.getDefault());
    Options options = setupOptions(strings);
    CommandLineParser parser = new DefaultParser();

    Arguments.Builder builder;/*from   w  w  w  . ja  va  2s. co m*/
    try {
        CommandLine commandLine = parser.parse(options, args);

        if (commandLine.hasOption("gui")) {
            return Arguments.START_GUI;
        }

        if (commandLine.hasOption("h") || commandLine.hasOption("help")) {
            printHelp(options);
            return null;
        }

        if (commandLine.hasOption("v") || commandLine.hasOption("version")) {
            System.out.println("Version: " + CLIInterpreter.class.getPackage().getImplementationVersion());
            return null;
        }

        String scaleRawParam = commandLine.getOptionValue(SCALE_ARG).toLowerCase();

        boolean dp = false;

        if (scaleRawParam.contains("dp")) {
            dp = true;
            scaleRawParam = scaleRawParam.replace("dp", "").trim();
        }

        builder = new Arguments.Builder(new File(commandLine.getOptionValue(SOURCE_ARG)),
                Float.parseFloat(scaleRawParam));

        if (dp && commandLine.hasOption(SCALE_IS_HEIGHT_DP_ARG)) {
            builder.scaleMode(EScaleMode.DP_HEIGHT);
        } else if (dp && !commandLine.hasOption(SCALE_IS_HEIGHT_DP_ARG)) {
            builder.scaleMode(EScaleMode.DP_WIDTH);
        } else {
            builder.scaleMode(EScaleMode.FACTOR);
        }

        if (commandLine.hasOption(DST_ARG)) {
            builder.dstFolder(new File(commandLine.getOptionValue(DST_ARG)));
        }

        float compressionQuality = Arguments.DEFAULT_COMPRESSION_QUALITY;
        if (commandLine.hasOption(COMPRESSION_QUALITY_ARG)) {
            compressionQuality = Float.valueOf(commandLine.getOptionValue(COMPRESSION_QUALITY_ARG));
        }

        if (commandLine.hasOption(OUT_COMPRESSION_ARG)) {
            switch (commandLine.getOptionValue(OUT_COMPRESSION_ARG)) {
            case "strict":
                builder.compression(EOutputCompressionMode.SAME_AS_INPUT_STRICT);
                break;
            case "png":
                builder.compression(EOutputCompressionMode.AS_PNG);
                break;
            case "jpg":
                builder.compression(EOutputCompressionMode.AS_JPG, compressionQuality);
                break;
            case "gif":
                builder.compression(EOutputCompressionMode.AS_GIF);
                break;
            case "bmp":
                builder.compression(EOutputCompressionMode.AS_BMP);
                break;
            case "png+jpg":
                builder.compression(EOutputCompressionMode.AS_JPG_AND_PNG, compressionQuality);
                break;
            default:
                System.err.println(
                        "unknown compression type: " + commandLine.getOptionValue(OUT_COMPRESSION_ARG));
            }
        }

        Set<EPlatform> platformSet = new HashSet<>(EPlatform.values().length);
        if (commandLine.hasOption(PLATFORM_ARG)) {
            switch (commandLine.getOptionValue(PLATFORM_ARG)) {
            case "all":
                platformSet = EPlatform.getAll();
                break;
            case "android":
                platformSet.add(EPlatform.ANDROID);
                break;
            case "ios":
                platformSet.add(EPlatform.IOS);
                break;
            case "win":
                platformSet.add(EPlatform.WINDOWS);
                break;
            case "web":
                platformSet.add(EPlatform.WEB);
                break;
            default:
                System.err.println("unknown mode: " + commandLine.getOptionValue(PLATFORM_ARG));
            }
            builder.platform(platformSet);
        }

        if (commandLine.hasOption(UPSCALING_ALGO_ARG)) {
            builder.upScaleAlgorithm(
                    EScalingAlgorithm.getByName(commandLine.getOptionValue(UPSCALING_ALGO_ARG)));
        }

        if (commandLine.hasOption(DOWNSCALING_ALGO_ARG)) {
            builder.upScaleAlgorithm(
                    EScalingAlgorithm.getByName(commandLine.getOptionValue(DOWNSCALING_ALGO_ARG)));
        }

        if (commandLine.hasOption(ROUNDING_MODE_ARG)) {
            switch (commandLine.getOptionValue(ROUNDING_MODE_ARG)) {
            case "round":
                builder.scaleRoundingStragy(RoundingHandler.Strategy.ROUND_HALF_UP);
                break;
            case "ceil":
                builder.scaleRoundingStragy(RoundingHandler.Strategy.CEIL);
                break;
            case "floor":
                builder.scaleRoundingStragy(RoundingHandler.Strategy.FLOOR);
                break;
            default:
                System.err.println("unknown mode: " + commandLine.getOptionValue(ROUNDING_MODE_ARG));
            }
        }

        if (commandLine.hasOption(THREADS_ARG)) {
            builder.threadCount(Integer.valueOf(commandLine.getOptionValue(THREADS_ARG)));
        }

        builder.skipUpscaling(commandLine.hasOption("skipUpscaling"));
        builder.skipExistingFiles(commandLine.hasOption(SKIP_EXISTING_ARG));
        builder.includeAndroidLdpiTvdpi(commandLine.hasOption("androidIncludeLdpiTvdpi"));
        builder.verboseLog(commandLine.hasOption(VERBOSE_ARG));
        builder.haltOnError(commandLine.hasOption("haltOnError"));
        builder.createMipMapInsteadOfDrawableDir(commandLine.hasOption("androidMipmapInsteadOfDrawable"));
        builder.antiAliasing(commandLine.hasOption("antiAliasing"));
        builder.enablePngCrush(commandLine.hasOption("postProcessorPngCrush"));
        builder.postConvertWebp(commandLine.hasOption("postProcessorWebp"));
        builder.dryRun(commandLine.hasOption("dryRun"));
        builder.enableMozJpeg(commandLine.hasOption("postProcessorMozJpeg"));
        builder.keepUnoptimizedFilesPostProcessor(commandLine.hasOption("keepOriginalPostProcessedFiles"));
        builder.iosCreateImagesetFolders(commandLine.hasOption("iosCreateImagesetFolders"));
        builder.clearDirBeforeConvert(commandLine.hasOption("clean"));

        return builder.build();
    } catch (Exception e) {
        System.err.println("Could not parse args: " + e.getMessage());
    }
    return null;
}

From source file:com.chinamobile.bcbsp.examples.kmeans.KMeansBSP.java

@Override
public void compute(Iterator<BSPMessage> messages, BSPStaffContextInterface context) throws Exception {
    jobconf = context.getJobConf();//w ww. ja  va2  s .c  om
    superStepCount = context.getCurrentSuperStepCounter();
    ArrayList<Float> thisPoint = new ArrayList<Float>();
    KMVertex thisVertex = (KMVertex) context.getVertex();
    Iterator<Edge> outgoingEdges = context.getOutgoingEdges();
    // Init this point
    while (outgoingEdges.hasNext()) {
        KMEdge edge = (KMEdge) outgoingEdges.next();
        thisPoint.add(Float.valueOf(edge.getEdgeValue()));
    }
    // Calculate the class tag of this vertex.
    byte tag = 0;
    double minDistance = Double.MAX_VALUE;
    // Find the shortest distance of this point with the kCenters.
    for (byte i = 0; i < kCenters.size(); i++) {
        ArrayList<Float> center = kCenters.get(i);
        double dist = distanceOf(thisPoint, center);
        if (dist < minDistance) {
            tag = i;
            minDistance = dist;
        }
    }
    // Write the vertex's class tag into the vertex value.
    thisVertex.setVertexValue(tag);
    context.updateVertex(thisVertex);
    if (this.errors < this.errorsThreshold) {
        context.voltToHalt();
    }
}

From source file:gov.nih.nci.caintegrator.application.analysis.heatmap.HeatmapGenomicDataFileWriterTest.java

private List<SegmentData> createSegmentDatas() {
    List<SegmentData> dataSet = new ArrayList<SegmentData>();
    SegmentData result = new SegmentData();
    result.setArrayData(new ArrayData());
    result.getArrayData().setSample(new Sample());
    result.getArrayData().getSample().setName("Sample 1");
    result.setLocation(new ChromosomalLocation());
    result.getLocation().setChromosome("1");
    result.getLocation().setStartPosition(Integer.valueOf(1));
    result.getLocation().setEndPosition(Integer.valueOf(5));
    result.setSegmentValue(Float.valueOf("0.1"));
    dataSet.add(result);//from   w  w w  . ja  v  a 2s . c om

    result = new SegmentData();
    result.setArrayData(new ArrayData());
    result.getArrayData().setSample(new Sample());
    result.getArrayData().getSample().setName("Sample 2");
    result.setLocation(new ChromosomalLocation());
    result.getLocation().setChromosome("2");
    result.getLocation().setStartPosition(Integer.valueOf(6));
    result.getLocation().setEndPosition(Integer.valueOf(9));
    result.setSegmentValue(Float.valueOf("0.2"));
    dataSet.add(result);

    return dataSet;
}

From source file:com.alibaba.dubboadmin.web.mvc.RouterController.java

private Object convertPrimitive(Class<?> cls, String value) {
    if (cls == boolean.class || cls == Boolean.class) {
        return value == null || value.length() == 0 ? false : Boolean.valueOf(value);
    } else if (cls == byte.class || cls == Byte.class) {
        return value == null || value.length() == 0 ? 0 : Byte.valueOf(value);
    } else if (cls == char.class || cls == Character.class) {
        return value == null || value.length() == 0 ? '\0' : value.charAt(0);
    } else if (cls == short.class || cls == Short.class) {
        return value == null || value.length() == 0 ? 0 : Short.valueOf(value);
    } else if (cls == int.class || cls == Integer.class) {
        return value == null || value.length() == 0 ? 0 : Integer.valueOf(value);
    } else if (cls == long.class || cls == Long.class) {
        return value == null || value.length() == 0 ? 0 : Long.valueOf(value);
    } else if (cls == float.class || cls == Float.class) {
        return value == null || value.length() == 0 ? 0 : Float.valueOf(value);
    } else if (cls == double.class || cls == Double.class) {
        return value == null || value.length() == 0 ? 0 : Double.valueOf(value);
    }/* w  ww  .  ja va  2s. co  m*/
    return value;
}

From source file:com.pivotal.gemfire.tools.pulse.internal.service.ClusterMemberService.java

public JSONObject execute(final HttpServletRequest request) throws Exception {

    // get cluster object
    Cluster cluster = Repository.get().getCluster();

    // json object to be sent as response
    JSONObject responseJSON = new JSONObject();

    Cluster.Member[] clusterMembersList = cluster.getMembers();

    // create members json
    List<JSONObject> memberListJson = new ArrayList<JSONObject>();
    try {/*from w  ww.  j  a  v a2 s.  c  om*/
        for (Cluster.Member clusterMember : clusterMembersList) {
            JSONObject memberJSON = new JSONObject();
            // getting members detail
            memberJSON.put("memberId", clusterMember.getId());
            memberJSON.put("name", clusterMember.getName());
            memberJSON.put("host", clusterMember.getHost());

            DecimalFormat df2 = new DecimalFormat(PulseConstants.DECIMAL_FORMAT_PATTERN);

            long usedHeapSize = cluster.getUsedHeapSize();
            long currentHeap = clusterMember.getCurrentHeapSize();
            if (usedHeapSize > 0) {
                float heapUsage = ((float) currentHeap / (float) usedHeapSize) * 100;
                memberJSON.put(this.HEAP_USAGE, Double.valueOf(df2.format(heapUsage)));
            } else {
                memberJSON.put(this.HEAP_USAGE, 0);
            }
            Float currentCPUUsage = clusterMember.getCpuUsage();

            memberJSON.put("cpuUsage", Float.valueOf(df2.format(currentCPUUsage)));
            memberJSON.put("currentHeapUsage", clusterMember.getCurrentHeapSize());
            memberJSON.put("isManager", clusterMember.isManager());
            memberJSON.put("uptime", TimeUtils.convertTimeSecondsToHMS(clusterMember.getUptime()));
            memberJSON.put("loadAvg", clusterMember.getLoadAverage());
            memberJSON.put("sockets", clusterMember.getTotalFileDescriptorOpen());
            memberJSON.put("openFDs", clusterMember.getTotalFileDescriptorOpen());
            memberJSON.put("threads", clusterMember.getNumThreads());

            // Number of member clients
            if (PulseController.getPulseProductSupport()
                    .equalsIgnoreCase(PulseConstants.PRODUCT_NAME_GEMFIREXD)) {
                memberJSON.put("clients", clusterMember.getNumGemFireXDClients());
            } else {
                memberJSON.put("clients", clusterMember.getMemberClientsHMap().size());
            }
            memberJSON.put("queues", clusterMember.getQueueBacklog());

            memberListJson.add(memberJSON);
        }
        // clucter's Members
        responseJSON.put("members", memberListJson);
        // Send json response
        return responseJSON;
    } catch (JSONException e) {
        throw new Exception(e);
    }
}

From source file:gov.nih.nci.caintegrator.web.action.query.form.SegmentCriterionWrapper.java

private TextFieldParameter createUpperLimitParameter() {
    final String label = "Segment Mean Value <=";
    TextFieldParameter textParameter = new TextFieldParameter(getParameters().size(), getRow().getRowIndex(),
            getCopyNumberAlterationCriterion().getDisplayUpperLimit());
    textParameter.setLabel(label);/*from   ww  w .  ja  v  a 2  s  .  com*/
    ValueHandler valueChangeHandler = new ValueHandlerAdapter() {

        @Override
        public boolean isValid(String value) {
            return StringUtils.isBlank(value) || NumberUtils.isNumber(value);
        }

        @Override
        public void validate(String formFieldName, String value, ValidationAware action) {
            if (!isValid(value)) {
                action.addActionError("Numeric value required or blank for " + label);
            }
        }

        @Override
        public void valueChanged(String value) {
            if (StringUtils.isBlank(value)) {
                getCopyNumberAlterationCriterion().setUpperLimit(null);
            } else {
                getCopyNumberAlterationCriterion().setUpperLimit(Float.valueOf(value));
            }
        }
    };
    textParameter.setValueHandler(valueChangeHandler);
    return textParameter;
}

From source file:demo.stockquote.java.MyStockQuoteDevice.java

@Override
protected void onOneLoop() throws Exception {

    // do your stuff
    URLConnection conn;//from  w  w w  .j  a  va  2 s. co  m
    String line, url;
    BufferedReader rdr;
    String[] infos;
    StockQuoteEvent ev;

    url = _url.replaceAll("SYMBOL", _symbols);
    conn = new URI(url).toURL().openConnection();
    try {
        rdr = new BufferedReader(new InputStreamReader(conn.getInputStream()));
        while ((line = rdr.readLine()) != null) {
            infos = line.split(",");
            ev = new StockQuoteEvent(this);
            ev.setTicker(infos[0].replaceAll("\"", ""));
            ev.setPrice(Float.valueOf(infos[1]));
            ev.setChange(Float.valueOf(infos[4]));

            // send it downstream to application
            dispatch(ev);
        }
    } finally {
        if (conn instanceof HttpURLConnection) {
            ((HttpURLConnection) conn).disconnect();
        }
    }

}

From source file:com.p5solutions.core.jpa.orm.ConversionUtilityImpl.java

/**
 * Convert string./*  ww w.  j av a  2  s  .c om*/
 * 
 * @param value
 *          the value
 * @param clazz
 *          the clazz
 * @return the object
 */
protected Object convertString(String value, Class<?> clazz) {
    if (ReflectionUtility.isBooleanClass(clazz)) {
        return Boolean.valueOf(value);
    } else if (ReflectionUtility.isShortClass(clazz)) {
        return Short.valueOf(value);
    } else if (ReflectionUtility.isIntegerClass(clazz)) {
        return Integer.valueOf(value);
    } else if (ReflectionUtility.isLongClass(clazz)) {
        return Long.valueOf(value);
    } else if (ReflectionUtility.isFloatClass(clazz)) {
        return Float.valueOf(value);
    } else if (ReflectionUtility.isDoubleClass(clazz)) {
        return Double.valueOf(value);
    } else if (ReflectionUtility.isBigDecimalClass(clazz)) {
        return new BigDecimal(value);
    } else if (ReflectionUtility.isBigIntegerClass(clazz)) {
        return new BigInteger(value);
    } else if (ReflectionUtility.isByteClass(clazz)) {
        return Byte.valueOf(value);
    } else if (ReflectionUtility.isDateOrTimestamp(clazz)) {
        try {
            return DATE_FORMAT.parse(value);
        } catch (ParseException e) {
            logger.error("Unable to parse " + value + " using date formatter " + DATE_FORMAT_STRING);
            return value;
        }
    } else {
        logger.warn("Unable to identify appropriate conversion strategy for value " + value
                + " using class type " + clazz);
    }

    return value;
}