Example usage for java.lang Float Float

List of usage examples for java.lang Float Float

Introduction

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

Prototype

@Deprecated(since = "9")
public Float(String s) throws NumberFormatException 

Source Link

Document

Constructs a newly allocated Float object that represents the floating-point value of type float represented by the string.

Usage

From source file:de.odysseus.calyxo.base.util.ParseUtils.java

public void testObject() throws Exception {
        assertEquals(Boolean.TRUE, ParseUtils.parse(Boolean.class, "true"));
        assertEquals(Boolean.FALSE, ParseUtils.parse(Boolean.class, "false"));
        assertEquals(new Character((char) 10), ParseUtils.parse(Character.class, "\n"));
        assertEquals(new Byte((byte) 10), ParseUtils.parse(Byte.class, "10"));
        assertEquals(new Short((short) 10), ParseUtils.parse(Short.class, "10"));
        assertEquals(new Integer(10), ParseUtils.parse(Integer.class, "10"));
        assertEquals(new Long(10), ParseUtils.parse(Long.class, "10"));
        assertEquals(new Float(10), ParseUtils.parse(Float.class, "10"));
        assertEquals(new Double(10), ParseUtils.parse(Double.class, "10"));
        assertEquals(new BigInteger("10"), ParseUtils.parse(BigInteger.class, "10"));
        assertEquals(new BigDecimal(10), ParseUtils.parse(BigDecimal.class, "10"));
        assertEquals(new Date(0), ParseUtils.parse(Date.class, "1/1/70"));
        assertEquals("foo", ParseUtils.parse(String.class, "foo"));
    }/*from   w w  w.  j a v a2 s .c o  m*/

From source file:com.netspective.commons.text.ExpressionTextTest.java

public void testValueSourceOrJavaExpressionText() {
    // Java Expression Test
    ValueSourceOrJavaExpressionText jetOne = new ValueSourceOrJavaExpressionText();
    assertNotNull(jetOne);/*www  . j a va  2  s. com*/

    JexlContext jc = jetOne.getJexlContext();
    assertNotNull(jc);

    String javaExpInputOne = "2 + 2 = ${2 + 2}";
    String javaExpOutput = jetOne.getFinalText(null, javaExpInputOne);
    assertEquals("2 + 2 = 4", javaExpOutput);

    jc.getVars().put("pinky", new String("pinky"));
    String javaExpInputTwo = "'pinky' uppercased is ${pinky.toUpperCase()}";
    String javaExpOutputTwo = jetOne.getFinalText(null, javaExpInputTwo);
    assertEquals("'pinky' uppercased is PINKY", javaExpOutputTwo);

    Map vars = new HashMap();
    vars.put("theBrain", new String("The Brain"));
    vars.put("pi", new Float(3.14));
    vars.put("radius", new Float(2.5));

    ValueSourceOrJavaExpressionText jetTwo = new ValueSourceOrJavaExpressionText("${static:static} expression");
    assertNotNull(jetTwo);

    JexlContext jcTwo = jetTwo.getJexlContext();
    assertNotNull(jcTwo);

    jetTwo.init(vars);

    String javaExpInputThree = "Area = pi * radius^2 = ${pi * radius * radius}";
    String javaExpOutputThree = jetTwo.getFinalText(null, javaExpInputThree);
    assertEquals("Area = pi * radius^2 = 19.625", javaExpOutputThree);
    assertEquals("static expression", jetTwo.getFinalText(null));
    assertEquals("${static:static} expression", jetTwo.getStaticExpr());

    ValueSourceOrJavaExpressionText jetThree = new ValueSourceOrJavaExpressionText(
            "${theBrain} is a ${static:static expression}", vars);
    assertNotNull(jetThree);

    String javaExpInputFour = "Pinky's smarter half: ${theBrain}";
    String javaExpOutputFour = jetThree.getFinalText(null, javaExpInputFour);
    assertEquals("Pinky's smarter half: The Brain", javaExpOutputFour);
    assertEquals("The Brain is a static expression", jetThree.getFinalText(null));
    assertEquals("${theBrain} is a ${static:static expression}", jetThree.getStaticExpr());

    ValueSourceOrJavaExpressionText jetFour = new ValueSourceOrJavaExpressionText(vars);
    assertNotNull(jetFour);

    String javaExpInputFive = "Tom and Jerry like ${pi}";
    String javaExpOutputFive = jetFour.getFinalText(null, javaExpInputFive);
    assertEquals("Tom and Jerry like 3.14", javaExpOutputFive);
    assertNull(jetFour.getStaticExpr());

    ValueContext testVC = new DefaultValueContext();
    testVC.setAttribute("test-attribute", new String("Test Attribute - Do NOT Use"));
    assertEquals(javaExpOutputFive, jetFour.getFinalText(testVC, javaExpInputFive));
}

From source file:com.linkedin.pinot.segments.v1.creator.DictionariesTest.java

@Test
public void testIntColumnPreIndexStatsCollector() throws Exception {
    FieldSpec spec = new DimensionFieldSpec("column1", DataType.INT, true);
    AbstractColumnStatisticsCollector statsCollector = new IntColumnPreIndexStatsCollector(spec);
    statsCollector.collect(new Integer(1));
    Assert.assertTrue(statsCollector.isSorted());
    statsCollector.collect(new Float(2));
    Assert.assertTrue(statsCollector.isSorted());
    statsCollector.collect(new Long(3));
    Assert.assertTrue(statsCollector.isSorted());
    statsCollector.collect(new Double(4));
    Assert.assertTrue(statsCollector.isSorted());
    statsCollector.collect(new Integer(4));
    Assert.assertTrue(statsCollector.isSorted());
    statsCollector.collect(new Float(2));
    Assert.assertFalse(statsCollector.isSorted());
    statsCollector.collect(new Double(40));
    Assert.assertFalse(statsCollector.isSorted());
    statsCollector.collect(new Double(20));
    Assert.assertFalse(statsCollector.isSorted());
    statsCollector.seal();//w ww . j av  a 2s  .c o m
    Assert.assertEquals(statsCollector.getCardinality(), 6);
    Assert.assertEquals(((Number) statsCollector.getMinValue()).intValue(), 1);
    Assert.assertEquals(((Number) statsCollector.getMaxValue()).intValue(), 40);
    Assert.assertFalse(statsCollector.isSorted());
}

From source file:org.processbase.ui.core.template.ImmediateUpload.java

public void updateProgress(long readBytes, long contentLength) {
    if (contentLength > MAX_UPLOAD_SIZE) {
        setComponentError(new UserError(ProcessbaseApplication.getString("fileUploadSizeLimit")));
        getWindow().showNotification(ProcessbaseApplication.getString("fileUploadSizeLimit"),
                Notification.TYPE_ERROR_MESSAGE);
        upload.interruptUpload();//  ww w.jav  a2 s.co  m
        return;
    }

    // This method gets called several times during the update
    pi.setValue(new Float(readBytes / (float) contentLength));
}

From source file:com.aurel.track.dbase.InitDatabase.java

/**
 * This method loads resource strings from properties files (ApplicationResources.properties)
 * into the database.//  w  w  w  .ja  v a  2 s.  co  m
 * @throws ServletException
 */
public static void loadResourcesFromPropertiesFiles(Boolean customOnly, ServletContext servletContext) {
    Boolean useProjects = true;
    Connection con = null;
    try {
        con = getConnection();
        Statement stmt = con.createStatement();
        ResultSet rs = stmt.executeQuery("SELECT * FROM ID_TABLE WHERE TABLE_NAME = 'USESPACES'");
        if (rs.next()) {
            useProjects = false; // We have an installation that uses the workspace terminology
        }
    } catch (Exception e) {
        LOGGER.error("Problem reading from ID_TABLE when checking for USESPACES");
        LOGGER.debug(STACKTRACE, e);
    } finally {
        if (con != null) {
            try {
                con.close();
            } catch (Exception ee) {
                LOGGER.debug(ee);
            }
        }
    }
    List<Locale> locs = LocaleHandler.getPropertiesLocales();
    int numberOfLocales = locs.size();
    int step = Math.round((float) ApplicationStarter.RESOURCE_UPGRADE[1] / numberOfLocales);
    float delta = new Float(ApplicationStarter.RESOURCE_UPGRADE[1] / new Float(numberOfLocales)) - step;
    Iterator<Locale> it = locs.iterator();

    while (it.hasNext()) {
        Locale loc = it.next();
        String locCode = loc.getLanguage();
        if (ApplicationBean.getInstance().isInTestMode() && locCode != "en") {
            continue;
        }
        if (loc.getCountry() != null && !"".equals(loc.getCountry())) {
            locCode = locCode + "_" + loc.getCountry();
        }
        if (!customOnly) {
            ApplicationStarter.getInstance().actualizePercentComplete(step,
                    ApplicationStarter.RESOURCE_UPGRADE_LOCALE_TEXT + loc.getDisplayName() + "...");
            addResourceToDatabase(loc, locCode, useProjects);
        }
        addCustomResourceToDatabase(loc, locCode);
    }
    if (!customOnly) {
        ApplicationStarter.getInstance().actualizePercentComplete(step,
                ApplicationStarter.RESOURCE_UPGRADE_DEFAULT_LOCALE_TEXT);
        addResourceToDatabase(Locale.getDefault(), null, useProjects);
    }
    addCustomResourceToDatabase(Locale.getDefault(), null);
    if (!customOnly) {
        ApplicationStarter.getInstance().actualizePercentComplete(Math.round(delta),
                ApplicationStarter.RESOURCE_UPGRADE_DEFAULT_LOCALE_TEXT);
    }
}

From source file:chatbot.Chatbot.java

/** **************************************************************************************************
 * Assume that query is file index -1//w  w  w  .  j ava2  s . c o m
 * Calculate the similarity of each document to the query
 * Put the result in HashMap<Integer,Float> docSim
 */
private void calcDocSim() {

    //System.out.println("Info in TFIDF.calcDocSim(): tfidf: " + tfidf);
    Integer negone = new Integer(-1);
    HashMap<String, Float> tfidflist = tfidf.get(negone);
    HashMap<String, Float> normquery = new HashMap<String, Float>();
    float euc = euclid.get(negone);
    Iterator<String> it2 = tfidflist.keySet().iterator();
    while (it2.hasNext()) {
        String term = it2.next();
        float tfidffloat = tfidflist.get(term).floatValue();
        normquery.put(term, new Float(tfidffloat / euc));
    }
    //System.out.println("Info in TFIDF.calcDocSim(): normquery: " + normquery);
    Iterator<Integer> it1 = tf.keySet().iterator();
    while (it1.hasNext()) {
        Integer int1 = it1.next();
        if (int1.intValue() != -1) {
            tfidflist = tfidf.get(int1);
            euc = euclid.get(int1);
            float fval = 0;
            Iterator<String> it3 = tfidflist.keySet().iterator();
            while (it3.hasNext()) {
                String term = it3.next();
                float tfidffloat = tfidflist.get(term).floatValue();
                float query = 0;
                if (normquery.containsKey(term))
                    query = normquery.get(term).floatValue();
                float normalize = 0;
                if (euc != 0)
                    normalize = tfidffloat / euc;
                fval = fval + (normalize * query);
            }
            docSim.put(int1, fval);
            //if (int1 == 8362)
            //    System.out.println("TFIDF.calcDocSim(): " + fval + ":" + tf.get(8362));
        }
    }
    //System.out.println("Info in TFIDF.calcDocSim(): Doc sim:\n" + docSim);
}

From source file:blue.mixer.Channel.java

public void lineDataChanged(Parameter param) {
    if (!updatingLine) {
        float time = ParameterTimeManagerFactory.getInstance().getTime();
        float level = levelParameter.getLine().getValue(time);

        float oldVal = this.level;
        this.level = level;

        firePropertyChange(LEVEL, new Float(oldVal), new Float(level));
    }//from w  w w .  java2 s  . c  o m
}

From source file:com.salesmanager.core.module.impl.application.prices.OneTimePriceModule.java

public String getHtmlPriceFormated(String prefix, ProductPrice productPrice, Locale locale, String currency) {

    if (locale == null)
        locale = LocaleUtil.getDefaultLocale();

    if (currency == null)
        currency = CurrencyUtil.getDefaultCurrency();

    StringBuffer p = new StringBuffer();
    p.append("<div class='product-price product-onetime-price'>");
    if (!ProductUtil.hasDiscount(productPrice)) {
        p.append("<div class='product-price-price' style='width:50%;float:left;'>");
        if (!StringUtils.isBlank(prefix)) {
            p.append("<div class='product-price-text'><strong>").append(prefix).append(" : </strong></div>");
        }/*from w ww  . jav a  2 s  . c om*/
        p.append(
                CurrencyUtil.displayFormatedAmountWithCurrency(productPrice.getProductPriceAmount(), currency));
        p.append(getPriceSuffixText(currency, locale));
        p.append("</div>");
        p.append("<div class='product-line'>&nbsp;</div>");
    } else {

        double arith = productPrice.getSpecial().getProductPriceSpecialAmount().doubleValue()
                / productPrice.getProductPriceAmount().doubleValue();
        double fsdiscount = 100 - arith * 100;
        Float percentagediscount = new Float(fsdiscount);
        String savediscount = String.valueOf(percentagediscount.intValue());

        p.append("<div class='product-price-price' style='width:50%;float:left;'>");
        if (!StringUtils.isBlank(prefix)) {
            p.append("<div class='product-price-text'><strong>").append(prefix).append(" : </strong></div>");
        }
        p.append("<strike>")
                .append(CurrencyUtil.displayFormatedAmountWithCurrency(productPrice.getProductPriceAmount(),
                        currency))
                .append(getPriceSuffixText(currency, locale)).append("</strike>").append("</div>")
                .append("<div style='width:50%;float:right;'>").append("<font color='red'>")
                .append(CurrencyUtil.displayFormatedAmountWithCurrency(ProductUtil.determinePrice(productPrice),
                        currency))
                .append(getPriceSuffixText(currency, locale)).append("</font>").append("<br>")
                .append("<font color='red' style='font-size:75%;'>")
                .append(LabelUtil.getInstance().getText(locale, "label.generic.save")).append(" :")
                .append(savediscount)
                .append(LabelUtil.getInstance().getText(locale, "label.generic.percentsign")).append(" ")
                .append(LabelUtil.getInstance().getText(locale, "label.generic.off")).append("</font>");

        Date discountEndDate = ProductUtil.getDiscountEndDate(productPrice);

        if (discountEndDate != null) {
            p.append("<br>").append(" <font style='font-size:65%;'>")
                    .append(LabelUtil.getInstance().getText(locale, "label.generic.until")).append("&nbsp;")
                    .append(DateUtil.formatDate(discountEndDate)).append("</font>");
        }

        p.append("</div>");
    }
    p.append("</div>");
    return p.toString();

}

From source file:BQJDBC.QueryResultTest.BQForwardOnlyResultSetFunctionTest.java

@Test
public void TestResultSetgetFloat() {
    try {/*from w  ww  .  j  a va 2 s  . c o  m*/
        Assert.assertTrue(Result.next());
        Assert.assertEquals(new Float(42), BQForwardOnlyResultSetFunctionTest.Result.getFloat(2));
    } catch (SQLException e) {
        this.logger.error("SQLexception" + e.toString());
        Assert.fail("SQLException" + e.toString());
    }
}

From source file:edu.hawaii.soest.kilonalu.dvp2.DavisWxXMLSink.java

/**
 * Export data to disk./* www .  ja  va 2s  . co  m*/
 */
public boolean export() {
    logger.debug("DavisWxXMLSink.export() called.");

    if (setup(this.getServerName(), this.getServerPort(), this.getRBNBClientName())) {

        try {
            ChannelMap requestMap = new ChannelMap();

            String fullSourceName = "/KNHIGCampusDataTurbine" + "/" + this.getRBNBClientName() + "/";
            int channelIndex = 0;

            // add the barTrendAsString field data
            channelIndex = requestMap.Add(fullSourceName + "barTrendAsString"); // Falling Slowly

            // add the barometer field data
            channelIndex = requestMap.Add(fullSourceName + "barometer"); // 29.9

            // add the insideTemperature field data
            channelIndex = requestMap.Add(fullSourceName + "insideTemperature"); // 83.9

            // add the insideHumidity field data
            channelIndex = requestMap.Add(fullSourceName + "insideHumidity"); // 51

            // add the outsideTemperature field data
            channelIndex = requestMap.Add(fullSourceName + "outsideTemperature"); // 76.7

            // add the windSpeed field data
            channelIndex = requestMap.Add(fullSourceName + "windSpeed"); // 5

            // add the tenMinuteAverageWindSpeed field data
            channelIndex = requestMap.Add(fullSourceName + "tenMinuteAverageWindSpeed"); // 4

            // add the windDirection field data
            channelIndex = requestMap.Add(fullSourceName + "windDirection"); // 80

            // add the outsideHumidity field data
            channelIndex = requestMap.Add(fullSourceName + "outsideHumidity"); // 73

            // add the rainRate field data
            channelIndex = requestMap.Add(fullSourceName + "rainRate"); // 0.0

            // add the uvRadiation field data
            channelIndex = requestMap.Add(fullSourceName + "uvRadiation"); // 0

            // add the solarRadiation field data
            channelIndex = requestMap.Add(fullSourceName + "solarRadiation"); // 0.0

            // add the dailyRain field data
            channelIndex = requestMap.Add(fullSourceName + "dailyRain"); // 0.0

            // add the monthlyRain field data
            channelIndex = requestMap.Add(fullSourceName + "monthlyRain"); // 0.0

            // add the forecastAsString field data
            channelIndex = requestMap.Add(fullSourceName + "forecastAsString"); // Partially Cloudy

            // make the request to the DataTurbine for the above channels
            sink.Request(requestMap, 0.0, 0.0, "newest");
            ChannelMap responseMap = sink.Fetch(3000); // fetch with 5 sec timeout

            // then parse the results to and build the XML output
            int index = responseMap.GetIndex(fullSourceName + "barTrendAsString");

            if (index >= 0) {
                // convert sec to millisec
                double timestamp = responseMap.GetTimes(index)[0];
                long unixTime = (long) (timestamp * 1000.0);

                // get the updateDate
                Date updateDate = new Date(unixTime);
                String updateDateString = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG)
                        .format(updateDate);

                // create the ad hoc XML file from the data from the DataTurbine
                this.fileOutputStream = new FileOutputStream(xmlFile);
                StringBuilder sb = new StringBuilder();

                sb.append("<?xml version=\"1.0\"?>\n");
                sb.append("<wx>\n");
                sb.append("  <updatetime>" + updateDateString + "</updatetime>\n");
                sb.append("  <barotrend>"
                        + responseMap
                                .GetDataAsString(responseMap.GetIndex(fullSourceName + "barTrendAsString"))[0]
                        + "</barotrend>\n");
                sb.append("  <baropress>"
                        + String.format("%5.3f",
                                (Object) (new Float(responseMap.GetDataAsFloat32(
                                        responseMap.GetIndex(fullSourceName + "barometer"))[0])))
                        + "</baropress>\n");
                sb.append(
                        "  <outtemp>"
                                + String.format("%4.1f",
                                        (Object) (new Float(responseMap.GetDataAsFloat32(responseMap
                                                .GetIndex(fullSourceName + "outsideTemperature"))[0])))
                                + "</outtemp>\n");
                sb.append(
                        "  <intemp>"
                                + String.format("%4.1f",
                                        (Object) (new Float(responseMap.GetDataAsFloat32(responseMap
                                                .GetIndex(fullSourceName + "insideTemperature"))[0])))
                                + "</intemp>\n");
                sb.append("  <inrelhum>"
                        + String.format("%3d",
                                (Object) (new Integer(responseMap.GetDataAsInt32(
                                        responseMap.GetIndex(fullSourceName + "insideHumidity"))[0])))
                        + "</inrelhum>\n");
                sb.append("  <outrelhum>"
                        + String.format("%3d",
                                (Object) (new Integer(responseMap.GetDataAsInt32(
                                        responseMap.GetIndex(fullSourceName + "outsideHumidity"))[0])))
                        + "</outrelhum>\n");
                sb.append("  <windspd>"
                        + String.format("%3d",
                                (Object) (new Integer(responseMap.GetDataAsInt32(
                                        responseMap.GetIndex(fullSourceName + "windSpeed"))[0])))
                        + "</windspd>\n");
                sb.append("  <winddir>"
                        + String.format("%3d",
                                (Object) (new Integer(responseMap.GetDataAsInt32(
                                        responseMap.GetIndex(fullSourceName + "windDirection"))[0])))
                        + "</winddir>\n");
                sb.append("  <windavg>"
                        + String.format("%3d",
                                (Object) (new Integer(responseMap.GetDataAsInt32(responseMap
                                        .GetIndex(fullSourceName + "tenMinuteAverageWindSpeed"))[0])))
                        + "</windavg>\n");
                sb.append("  <todayrain>"
                        + String.format("%4.2f",
                                (Object) (new Float(responseMap.GetDataAsFloat32(
                                        responseMap.GetIndex(fullSourceName + "dailyRain"))[0])))
                        + "</todayrain>\n");
                sb.append("  <monthrain>"
                        + String.format("%4.2f",
                                (Object) (new Float(responseMap.GetDataAsFloat32(
                                        responseMap.GetIndex(fullSourceName + "monthlyRain"))[0])))
                        + "</monthrain>\n");
                sb.append("  <rainrate>"
                        + String.format("%4.2f",
                                (Object) (new Float(responseMap.GetDataAsFloat32(
                                        responseMap.GetIndex(fullSourceName + "rainRate"))[0])))
                        + "</rainrate>\n");
                sb.append("  <uv>"
                        + String.format("%4d",
                                (Object) (new Integer(responseMap.GetDataAsInt32(
                                        responseMap.GetIndex(fullSourceName + "uvRadiation"))[0])))
                        + "</uv>\n");
                sb.append("  <solrad>"
                        + String.format("%4.0f",
                                (Object) (new Float(responseMap.GetDataAsFloat32(
                                        responseMap.GetIndex(fullSourceName + "solarRadiation"))[0])))
                        + "</solrad>\n");
                sb.append("  <forecast>"
                        + responseMap
                                .GetDataAsString(responseMap.GetIndex(fullSourceName + "forecastAsString"))[0]
                        + "</forecast>\n");
                sb.append("</wx>\n");

                logger.info("\n" + sb.toString());

                this.fileOutputStream.write(sb.toString().getBytes());
                this.fileOutputStream.close();

            } else {
                logger.debug("The index is out of bounds: " + index);
            }

        } catch (java.io.FileNotFoundException fnfe) {
            logger.debug("Error: Unable to open XML output file for writing.");
            logger.debug("Error message: " + fnfe.getMessage());
            disconnect();
            return false;
        } catch (java.io.IOException ioe) {
            logger.debug("Error: There was a problem writing to the XML file.");
            logger.debug("Error message: " + ioe.getMessage());
            disconnect();
            return false;
        } catch (com.rbnb.sapi.SAPIException sapie) {
            logger.debug("Error: There was a problem with the DataTurbine connection.");
            logger.debug("Error message: " + sapie.getMessage());
            disconnect();
            return false;

        }
        return true;

    } else {
        return false;

    }
}