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:org.springmodules.util.ObjectsTests.java

public void testHashCodeWithFloat() {
    float flt = 34.8f;
    int expected = (new Float(flt)).hashCode();
    assertEquals(expected, Objects.hashCode(flt));
}

From source file:com.baculsoft.beanutils.test.TestBeanUtil2.java

@Test
public void testCopy() throws Throwable {
    PojoExample pojoSource = new PojoExample();
    pojoSource.setStringProp("String Property");
    pojoSource.setBooleanProp(true);//from w  ww  . ja  v a2  s.  c om
    pojoSource.setBooleanProp1(Boolean.TRUE);
    pojoSource.setDateProp(new Date());
    pojoSource.setByteProp1(new Byte((byte) 11));
    pojoSource.setIntProp1(new Integer(15125));
    pojoSource.setLongProp1(new Long(20053215235l));
    pojoSource.setFloatProp1(new Float(20053215235f));

    PojoExample pojoTarget = new PojoExample();
    pojoDescriptor.copy(pojoSource, pojoTarget);
    pojoDescriptor.reset(pojoTarget);

    PojoExample pojoTarget2 = new PojoExample();
    PojoExample pojoTarget3 = new PojoExample();

    BeanUtils.copyProperties(pojoSource, pojoTarget2);
    org.apache.commons.beanutils.BeanUtils.copyProperties(pojoSource, pojoTarget3);

    long t1 = System.currentTimeMillis();
    for (int i = 0; i < 50; i++) {
        pojoDescriptor.copy(pojoSource, pojoTarget);

    }
    t1 = System.currentTimeMillis() - t1;

    long t2 = System.currentTimeMillis();
    for (int i = 0; i < 50; i++) {
        BeanUtils.copyProperties(pojoSource, pojoTarget2);
    }
    t2 = System.currentTimeMillis() - t2;

    long t3 = System.currentTimeMillis();
    for (int i = 0; i < 50; i++) {
        org.apache.commons.beanutils.BeanUtils.copyProperties(pojoSource, pojoTarget3);
    }
    t3 = System.currentTimeMillis() - t3;

    System.out.println("Time to copy properties ");
    System.out.println("this class: t1 ---> " + t1);
    System.out.println("spring-beans: t2 --->" + t2);
    System.out.println("apache commons: t3 --->" + t3);

    System.out.println(pojoDescriptor.describe(pojoTarget).equals(pojoDescriptor.describe(pojoTarget2)));

    assertEquals(pojoDescriptor.describe(pojoTarget), pojoDescriptor.describe(pojoTarget2));
}

From source file:NumberUtils.java

/**
 * Convert the given number into an instance of the given target class.
 * @param number the number to convert/*from ww  w  .  j a  v  a2 s . c o  m*/
 * @param targetClass the target class to convert to
 * @return the converted number
 * @throws IllegalArgumentException if the target class is not supported
 * (i.e. not a standard Number subclass as included in the JDK)
 * @see java.lang.Byte
 * @see java.lang.Short
 * @see java.lang.Integer
 * @see java.lang.Long
 * @see java.math.BigInteger
 * @see java.lang.Float
 * @see java.lang.Double
 * @see java.math.BigDecimal
 */
public static Number convertNumberToTargetClass(Number number, Class targetClass)
        throws IllegalArgumentException {

    if (targetClass.isInstance(number)) {
        return number;
    } else if (targetClass.equals(Byte.class)) {
        long value = number.longValue();
        if (value < Byte.MIN_VALUE || value > Byte.MAX_VALUE) {
            raiseOverflowException(number, targetClass);
        }
        return new Byte(number.byteValue());
    } else if (targetClass.equals(Short.class)) {
        long value = number.longValue();
        if (value < Short.MIN_VALUE || value > Short.MAX_VALUE) {
            raiseOverflowException(number, targetClass);
        }
        return new Short(number.shortValue());
    } else if (targetClass.equals(Integer.class)) {
        long value = number.longValue();
        if (value < Integer.MIN_VALUE || value > Integer.MAX_VALUE) {
            raiseOverflowException(number, targetClass);
        }
        return new Integer(number.intValue());
    } else if (targetClass.equals(Long.class)) {
        return new Long(number.longValue());
    } else if (targetClass.equals(Float.class)) {
        return new Float(number.floatValue());
    } else if (targetClass.equals(Double.class)) {
        return new Double(number.doubleValue());
    } else if (targetClass.equals(BigInteger.class)) {
        return BigInteger.valueOf(number.longValue());
    } else if (targetClass.equals(BigDecimal.class)) {
        // using BigDecimal(String) here, to avoid unpredictability of BigDecimal(double)
        // (see BigDecimal javadoc for details)
        return new BigDecimal(number.toString());
    } else {
        throw new IllegalArgumentException("Could not convert number [" + number + "] of type ["
                + number.getClass().getName() + "] to unknown target class [" + targetClass.getName() + "]");
    }
}

From source file:ejportal.dao.NutzungDaoTest.java

/**
 * Test add and remove journal./* w  w w  .  jav  a 2 s.c  o  m*/
 * 
 * @throws Exception
 *             the exception
 */
@Test
@ExpectedException(DataAccessException.class)
public void testAddAndRemoveJournal() throws Exception {
    Nutzung nutzung = new Nutzung();
    nutzung.setRechnungsbetrag(2.09F);

    nutzung = this.nutzungDao.save(nutzung);
    this.flush();

    nutzung = this.nutzungDao.get(nutzung.getNutzungId());

    Assert.assertEquals(new Float(2.09F), nutzung.getRechnungsbetrag());
    Assert.assertNotNull(nutzung.getNutzungId());

    this.log.debug("removing Nutzung...");

    this.nutzungDao.remove(nutzung.getNutzungId());
    this.flush();

    // should throw DataAccessException
    this.nutzungDao.get(nutzung.getNutzungId());
}

From source file:gov.nih.nci.ncicb.cadsr.loader.test.persister.DEPersisterTest.java

public void testGF22793() {

    ClassPathXmlApplicationContext cpCtx = new ClassPathXmlApplicationContext(
            new String[] { "beans.xml", "spring-datasources.xml", "loader-spring.xml" });

    DataElementBean de = new DataElementBean();
    de.setPublicId("1111");
    de.setVersion(new Float(1.0));

    DataElementConcept dec = new DataElementConceptBean();
    dec.setId("DEC1xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");

    ValueDomain vd = new ValueDomainBean();
    vd.setId("VD1xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
    vd.setPublicId("1111");
    vd.setVersion(new Float(1.0));

    de.setDataElementConcept(dec);/*from   ww w  .  j av  a2  s  .  co m*/
    de.setValueDomain(vd);

    ReferenceDocument rd = new ReferenceDocumentBean();
    rd.setType("Preferred Question Text");
    rd.setName("Inserted RD Name");
    rd.setText("Inserted RD Name");

    List<ReferenceDocument> rds = new ArrayList<ReferenceDocument>();
    rds.add(rd);

    UMLDefaults.getInstance().initParams("SIW_TEST", new Float(1.0), "MATHURA");
    UMLDefaults.getInstance().initWithDB();

    de.setReferenceDocuments(rds);

    ElementsLists.getInstance().addElement(de);
    CadsrPrivateApiModule cadsrModule = new CadsrPrivateApiModule();
    new LookupUtil().setCadsrModule(cadsrModule);

    DEPersister dePersister = new DEPersister();
    dePersister.setPersisterUtil(new PersisterUtil());
    dePersister.persist();

    try {
        Connection con = super.getDataSource().getConnection();
        Statement st = con.createStatement();
        ResultSet rs = st.executeQuery("select * from REFERENCE_DOCUMENTS");

        boolean comp = super.compareResultSet(rs, "REFERENCE_DOCUMENTS");
        assertTrue(comp);
    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

From source file:net.handle.servlet.AcceptsHeader.java

/**
 * <p>/*w  w w.j a  v a2 s  . c  o  m*/
 * Initialize with the raw header string.
 * </p>
 *
 * @param header the raw header string
 */
public AcceptsHeader(String header) {
    if (StringUtils.isNotBlank(header)) {
        // split entries, which are comma-separated
        String[] rawEntries = header.split(",");
        for (String rawEntry : rawEntries) {
            rawEntry = rawEntry.trim();
            AcceptsHeaderEntry entry = new AcceptsHeaderEntry();
            // split entry into type & params, which are semi-colon
            // separated
            String[] parts = rawEntry.split(";");
            for (String part : parts) {
                part = part.trim();
                if (part.split("=").length > 1) {
                    // it's a param
                    String[] rawParam = part.split("=");
                    if (rawParam.length == 2) {
                        String key = rawParam[0].trim();
                        String value = rawParam[1].trim();
                        if (key.equals("q")) {
                            entry.setQ(new Float(value));
                        } else if (key.equals("mxb")) {
                            entry.setMxb(new Float(value));
                        } else if (key.equals("mxs")) {
                            entry.setMxs(new Float(value));
                        }
                    }
                } else {
                    // it's the type
                    Mimetype mimetype = Mimetype.forName(part);

                    if (mimetype != null) {
                        entry.setType(mimetype);
                    }
                }
            }

            if (entry.getType() != null) {
                entries.add(entry);
            }
        }
    }
}

From source file:com.adaptris.core.services.jdbc.types.StringColumnTranslatorTest.java

@Test
public void testAsFloatTranslator() throws Exception {
    JdbcResultRow row = new JdbcResultRow();
    row.setFieldValue("testField", new Float(111), Types.VARCHAR);

    {//from   ww w. j av a 2s .  co m
        String translated = translator.translate(row, 0);
        assertEquals("111.0", translated);
    }
    {
        String translated = translator.translate(row, "testField");
        assertEquals("111.0", translated);
    }
}

From source file:probe.com.view.body.quantdatasetsoverview.diseasegroupsfilters.heatmap.HeatMapImgGenerator.java

public String generateHeatmap(String[] rows, String[] columns, String[][] data) {

    JPanel heatmapPanelLayout = new JPanel();
    heatmapPanelLayout.setLayout(null);//w w w  .  java  2  s  .  c  o  m
    heatmapPanelLayout.setVisible(true);

    int width = (columns.length + 1) * 50;
    int height = (rows.length + 1) * 50;
    heatmapPanelLayout.setSize(width, height);
    JPanel cornerCell = initCell("#ffffff", 0, 0);
    int x = 50;
    int y = 0;
    heatmapPanelLayout.add(cornerCell);

    for (String headerCell : columns) {
        JPanel cell = initCell(headerCell, x, y);
        x += 50;
        heatmapPanelLayout.add(cell);

    }
    y = 50;
    for (String headerCell : rows) {
        JPanel cell = initCell(headerCell, 0, y);
        y += 50;
        heatmapPanelLayout.add(cell);

    }
    x = 50;
    y = 50;
    for (String[] row : data) {
        for (String color : row) {
            JPanel cell = initCell(color, x, y);
            heatmapPanelLayout.add(cell);
            x += 50;
        }
        x = 50;
        y += 50;
    }

    BufferedImage image = new BufferedImage(width + 10, height + 10, BufferedImage.TYPE_INT_ARGB);
    Graphics2D graphics = image.createGraphics();
    graphics.setPaint(Color.WHITE);
    graphics.setBackground(Color.WHITE);
    heatmapPanelLayout.paint(graphics);
    byte[] imageData = null;

    try {

        ImageEncoder in = ImageEncoderFactory.newInstance(ImageFormat.PNG, new Float(0.084666f));
        imageData = in.encode(image);
    } catch (Exception e) {
        System.out.println(e.getLocalizedMessage());
    }

    String base64 = Base64.encodeBytes(imageData);
    base64 = "data:image/png;base64," + base64;
    return base64;

}

From source file:probe.com.model.util.vaadintoimageutil.HeatmapSwingComponent.java

public String generateHeatmap(String[] rows, String[] columns, String[][] data) {

    JPanel heatmapPanelLayout = new JPanel();
    heatmapPanelLayout.setLayout(null);//from  ww w.  j  a v a  2  s  .c o  m
    heatmapPanelLayout.setVisible(true);
    heatmapPanelLayout.setBorder(new LineBorder(Color.BLACK));
    int width = (columns.length + 1) * 50;
    int height = (rows.length + 1) * 50;
    heatmapPanelLayout.setSize(width, height);
    JPanel cornerCell = initCell("#ffffff", 0, 0);
    int x = 50;
    int y = 0;
    heatmapPanelLayout.add(cornerCell);

    for (String headerCell : columns) {
        JPanel cell = initCell(headerCell, x, y);
        x += 50;
        heatmapPanelLayout.add(cell);

    }
    y = 50;
    for (String headerCell : rows) {
        JPanel cell = initCell(headerCell, 0, y);
        y += 50;
        heatmapPanelLayout.add(cell);

    }
    x = 50;
    y = 50;
    for (String[] row : data) {
        for (String color : row) {
            JPanel cell = initCell(color, x, y);
            heatmapPanelLayout.add(cell);
            x += 50;
        }
        x = 50;
        y += 50;
    }

    BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
    Graphics2D graphics = image.createGraphics();
    graphics.setPaint(Color.WHITE);
    heatmapPanelLayout.paint(graphics);
    //        super.paint(graphics);
    byte[] imageData = null;

    try {

        ImageEncoder in = ImageEncoderFactory.newInstance(ImageFormat.PNG, new Float(0.084666f));
        imageData = in.encode(image);
    } catch (Exception e) {
        System.out.println(e.getLocalizedMessage());
    }

    String base64 = Base64.encodeBytes(imageData);
    base64 = "data:image/png;base64," + base64;
    return base64;
    //
    //        JFrame frame = new JFrame();
    //        frame.setSize(1000, 1000);
    //        frame.add(heatmapPanelLayout);
    //        frame.setVisible(true);

    //        return "";
}

From source file:com.bstek.dorado.data.variant.LinkedMetaData.java

public void setFloat(String key, float f) {
    put(key, new Float(f));
}