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:dsd.dao.ParametersDAO.java

private static Object[] PrepareValuesForInsert(Parameter dataTuple) {
    Object[] valueArray = new Object[4];
    valueArray[0] = new Long(dataTuple.getParameterID());
    valueArray[1] = new Float(dataTuple.getValue());
    valueArray[2] = new Long(dataTuple.getUserID());
    valueArray[3] = new Timestamp(dataTuple.getTimestamp());
    return valueArray;
}

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

public void testPrimitive() 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(char.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(int.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"));
    }/*from   w w w .  j  a  v  a2 s .com*/

From source file:au.edu.archer.dimsim.plugins.sensorDisplayController.java

private String getChxl(long currTime, float scale) {
    String chxl = "";
    String chxp = "";
    SimpleDateFormat df = new SimpleDateFormat("H:mm");
    Date testDate;/*  ww  w  .j a v a 2 s  .c  o  m*/
    long lscale = new Float(scale).longValue();
    for (int i = 0; i < 6; i++) {
        testDate = new Date(currTime - (i * 20 * lscale));
        chxl += "|" + df.format(testDate);
        chxp += "," + (i * 20);
    }
    if (chxl.startsWith("|")) {
        chxl = chxl.substring(1);
        chxp = chxp.substring(1);
    }
    chxl = "chxl=2:|" + chxl;
    chxp = "chxp=2," + chxp;
    return chxl + "&" + chxp;
}

From source file:au.org.ala.delta.translation.dist.DistItemsFileWriter.java

private void encodeOrderedMultistateAttribute(ByteBuffer work, int wordOffset,
        IdentificationKeyCharacter keyChar, MultiStateAttribute attribute) {
    List<Integer> states = keyChar.getPresentStates(attribute);
    double average = average(states);
    work.putFloat(wordOffset * 4, new Float(average));

}

From source file:javadz.beanutils.locale.converters.FloatLocaleConverter.java

/**
 * Convert the specified locale-sensitive input object into an output object of the
 * specified type.  This method will return Float value or throw exception if value
 * can not be stored in the Float./*from   w  ww.j a  va  2 s  .c  om*/
 *
 * @param value The input object to be converted
 * @param pattern The pattern is used for the convertion
 * @return The converted value
 *
 * @exception ConversionException if conversion cannot be performed
 *  successfully
 * @throws ParseException if an error occurs parsing a String to a Number
 */
protected Object parse(Object value, String pattern) throws ParseException {
    final Number parsed = (Number) super.parse(value, pattern);
    double doubleValue = parsed.doubleValue();
    double posDouble = (doubleValue >= (double) 0) ? doubleValue : (doubleValue * (double) -1);
    if (posDouble != 0 && (posDouble < Float.MIN_VALUE || posDouble > Float.MAX_VALUE)) {
        throw new ConversionException("Supplied number is not of type Float: " + parsed);
    }
    return new Float(parsed.floatValue()); // unlike superclass it returns Float type
}

From source file:com.jaspersoft.jasperserver.ws.axis2.RepositoryHelper.java

/**
 *  This method get a string and tries to convert the string into the requested object.
 *  Valid classes are:// w  w w  .  j a  va  2s.c om
 *    java.util.Date (the string is supposed to represent a number of milliseconds)
 *    Number
 *    BigDecimal
 *    Byte
 *    Short
 *    Integer
 *    Long
 *    Float
 *    Double
 *    Boolean
 *    String
 *    java.util.Locale
 * 
 *  The default returned object is of type String
 * @param str the string representing the value
 * @param clazz The class of the result (not garanteed)
 * @return return an Object hopefully of the requested class (or a String)
 * 
 */
public Object stringToValue(String str, Class clazz) {
    Object value = str;
    if (value == null) {
        return value;
    }

    if (java.util.Date.class.getName().equals(clazz.getName())) {
        value = new java.util.Date(Long.valueOf(value.toString()).longValue());
    } else if (java.sql.Date.class.getName().equals(clazz.getName())) {
        value = new java.sql.Date(Long.valueOf(value.toString()).longValue());
    } else if (java.sql.Timestamp.class.getName().equals(clazz.getName())) {
        value = new java.sql.Timestamp(Long.valueOf(value.toString()).longValue());
    } else if (Number.class.isAssignableFrom(clazz)) {
        value = new java.math.BigDecimal(value.toString());
        if (Byte.class.getName().equals(clazz.getName())) {
            value = new Byte(((Number) value).byteValue());
        } else if (Short.class.getName().equals(clazz.getName())) {
            value = new Short(((Number) value).shortValue());
        } else if (Integer.class.getName().equals(clazz.getName())) {
            value = new Integer(((Number) value).intValue());
        } else if (Long.class.getName().equals(clazz.getName())) {
            value = new Long(((Number) value).longValue());
        } else if (Float.class.getName().equals(clazz.getName())) {
            value = new Float(((Number) value).floatValue());
        } else if (Double.class.getName().equals(clazz.getName())) {
            value = new Double(((Number) value).doubleValue());
        }
    } else if (Boolean.class.getName().equals(clazz.getName())) {
        value = Boolean.valueOf(value.toString());
    } else if (Locale.class.getName().equals(clazz.getName())) {
        value = LocaleHelper.getInstance().getLocale(str);
    } else if (DateRange.class.equals(clazz)) {
        try {
            value = DateRangeFactory.getInstance(str, Date.class);
        } catch (InvalidDateRangeExpressionException e) {
            //if DateRange passed as string with milliseconds we need to parse it
            Date dateValue = (Date) stringToValue(str, Date.class);
            value = DateRangeFactory.getInstance(dateValue);
        }
    } else if (TimestampRange.class.equals(clazz)) {
        try {
            value = DateRangeFactory.getInstance(str, Timestamp.class);
        } catch (InvalidDateRangeExpressionException e) {
            //if TimestampRange passed as string with milliseconds we need to parse it
            Timestamp timestamp = (Timestamp) stringToValue(str, Timestamp.class);
            value = DateRangeFactory.getInstance(timestamp);
        }
    }

    return value;
}

From source file:MainClass.java

public void actionPerformed(ActionEvent e) {
    JTextPane editor = (JTextPane) getEditor(e);
    int p0 = editor.getSelectionStart();
    StyledDocument doc = getStyledDocument(editor);
    Element paragraph = doc.getCharacterElement(p0);
    AttributeSet as = paragraph.getAttributes();

    family = StyleConstants.getFontFamily(as);
    fontSize = StyleConstants.getFontSize(as);

    formatText = new JDialog(new JFrame(), "Font and Size", true);
    formatText.getContentPane().setLayout(new BorderLayout());

    JPanel choosers = new JPanel();
    choosers.setLayout(new GridLayout(2, 1));

    JPanel fontFamilyPanel = new JPanel();
    fontFamilyPanel.add(new JLabel("Font"));

    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    String[] fontNames = ge.getAvailableFontFamilyNames();

    fontFamilyChooser = new JComboBox();
    for (int i = 0; i < fontNames.length; i++) {
        fontFamilyChooser.addItem(fontNames[i]);
    }/*from   www . ja v a 2 s .c  om*/
    fontFamilyChooser.setSelectedItem(family);
    fontFamilyPanel.add(fontFamilyChooser);
    choosers.add(fontFamilyPanel);

    JPanel fontSizePanel = new JPanel();
    fontSizePanel.add(new JLabel("Size"));
    fontSizeChooser = new JComboBox();
    fontSizeChooser.setEditable(true);
    fontSizeChooser.addItem(new Float(4));
    fontSizeChooser.addItem(new Float(8));
    fontSizeChooser.addItem(new Float(12));
    fontSizeChooser.addItem(new Float(16));
    fontSizeChooser.addItem(new Float(20));
    fontSizeChooser.addItem(new Float(24));
    fontSizeChooser.setSelectedItem(new Float(fontSize));
    fontSizePanel.add(fontSizeChooser);
    choosers.add(fontSizePanel);

    JButton ok = new JButton("OK");
    ok.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            accept = true;
            formatText.dispose();
            family = (String) fontFamilyChooser.getSelectedItem();
            fontSize = Float.parseFloat(fontSizeChooser.getSelectedItem().toString());
        }
    });

    JButton cancel = new JButton("Cancel");
    cancel.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            formatText.dispose();
        }
    });

    JPanel buttons = new JPanel();
    buttons.add(ok);
    buttons.add(cancel);
    formatText.getContentPane().add(choosers, BorderLayout.CENTER);
    formatText.getContentPane().add(buttons, BorderLayout.SOUTH);
    formatText.pack();
    formatText.setVisible(true);

    MutableAttributeSet attr = null;
    if (editor != null && accept) {
        attr = new SimpleAttributeSet();
        StyleConstants.setFontFamily(attr, family);
        StyleConstants.setFontSize(attr, (int) fontSize);
        setCharacterAttributes(editor, attr, false);
    }

}

From source file:io.nuun.plugin.configuration.common.ConfigurationMembersInjector.java

@Override
public void injectMembers(T instance) {
    NuunProperty injectConfigAnnotation = null;
    // The annotation is actual NuunProperty.class
    if (clonedAnno.annotationType() == NuunProperty.class) {
        injectConfigAnnotation = field.getAnnotation(NuunProperty.class);
    } else { // The annotation has the NuunProperty annotation on it we proxy it
        injectConfigAnnotation = AssertUtils.annotationProxyOf(NuunProperty.class, clonedAnno);
    }/*from w w  w. ja  v  a  2 s  .c  o  m*/

    String configurationParameterName = injectConfigAnnotation.value();

    // Pre verification //
    if (StringUtils.isEmpty(configurationParameterName)) {
        log.error("Value for annotation {} on field {} can not be null or empty.", clonedAnno.annotationType(),
                field.toGenericString());
        throw new PluginException("Value for annotation %s on field %s can not be null or empty.",
                clonedAnno.annotationType(), field.toGenericString());
    }

    if (!configuration.containsKey(configurationParameterName) && injectConfigAnnotation.mandatory()) {
        throw new PluginException("\"%s\" must be in one properties file for field %s.",
                configurationParameterName, field.toGenericString());
    }

    try {
        this.field.setAccessible(true);
        Class<?> type = field.getType();
        if (type == Integer.TYPE) {
            if (configuration.containsKey(configurationParameterName)) {
                field.setInt(instance, configuration.getInt(configurationParameterName));
            } else {
                log.debug(NO_PROPERTY_FOUND_LOG_MESSAGE, configurationParameterName);
                field.setInt(instance, injectConfigAnnotation.defaultIntValue());
            }
        } else if (type == Integer.class) {
            if (configuration.containsKey(configurationParameterName)) {
                field.set(instance, new Integer(configuration.getInt(configurationParameterName)));
            } else {
                log.debug(NO_PROPERTY_FOUND_LOG_MESSAGE, configurationParameterName);
                field.set(instance, new Integer(injectConfigAnnotation.defaultIntValue()));
            }
        } else if (type == Boolean.TYPE) {
            if (configuration.containsKey(configurationParameterName)) {
                field.setBoolean(instance, configuration.getBoolean(configurationParameterName));
            } else {
                log.debug(NO_PROPERTY_FOUND_LOG_MESSAGE, configurationParameterName);
                field.setBoolean(instance, injectConfigAnnotation.defaultBooleanValue());
            }

        } else if (type == Boolean.class) {
            if (configuration.containsKey(configurationParameterName)) {
                field.set(instance, new Boolean(configuration.getBoolean(configurationParameterName)));
            } else {
                log.debug(NO_PROPERTY_FOUND_LOG_MESSAGE, configurationParameterName);
                field.set(instance, new Boolean(injectConfigAnnotation.defaultBooleanValue()));
            }

        } else if (type == Short.TYPE) {
            if (configuration.containsKey(configurationParameterName)) {
                field.setShort(instance, configuration.getShort(configurationParameterName));
            } else {
                log.debug(NO_PROPERTY_FOUND_LOG_MESSAGE, configurationParameterName);
                field.setShort(instance, injectConfigAnnotation.defaultShortValue());
            }
        } else if (type == Short.class) {
            if (configuration.containsKey(configurationParameterName)) {
                field.set(instance, new Short(configuration.getShort(configurationParameterName)));
            } else {
                log.debug(NO_PROPERTY_FOUND_LOG_MESSAGE, configurationParameterName);
                field.set(instance, new Short(injectConfigAnnotation.defaultShortValue()));
            }
        } else if (type == Byte.TYPE) {
            if (configuration.containsKey(configurationParameterName)) {
                field.setByte(instance, configuration.getByte(configurationParameterName));
            } else {
                log.debug(NO_PROPERTY_FOUND_LOG_MESSAGE, configurationParameterName);
                field.setByte(instance, injectConfigAnnotation.defaultByteValue());
            }
        } else if (type == Byte.class) {
            if (configuration.containsKey(configurationParameterName)) {
                field.set(instance, new Byte(configuration.getByte(configurationParameterName)));
            } else {
                log.debug(NO_PROPERTY_FOUND_LOG_MESSAGE, configurationParameterName);
                field.set(instance, new Byte(injectConfigAnnotation.defaultByteValue()));
            }
        } else if (type == Long.TYPE) {
            if (configuration.containsKey(configurationParameterName)) {
                field.setLong(instance, configuration.getLong(configurationParameterName));
            } else {
                log.debug(NO_PROPERTY_FOUND_LOG_MESSAGE, configurationParameterName);
                field.setLong(instance, injectConfigAnnotation.defaultLongValue());
            }
        } else if (type == Long.class) {
            if (configuration.containsKey(configurationParameterName)) {
                field.set(instance, new Long(configuration.getLong(configurationParameterName)));
            } else {
                log.debug(NO_PROPERTY_FOUND_LOG_MESSAGE, configurationParameterName);
                field.set(instance, new Long(injectConfigAnnotation.defaultLongValue()));
            }
        } else if (type == Float.TYPE) {
            if (configuration.containsKey(configurationParameterName)) {
                field.setFloat(instance, configuration.getFloat(configurationParameterName));
            } else {
                log.debug(NO_PROPERTY_FOUND_LOG_MESSAGE, configurationParameterName);
                field.setFloat(instance, injectConfigAnnotation.defaultFloatValue());
            }
        } else if (type == Float.class) {
            if (configuration.containsKey(configurationParameterName)) {
                field.set(instance, new Float(configuration.getFloat(configurationParameterName)));
            } else {
                log.debug(NO_PROPERTY_FOUND_LOG_MESSAGE, configurationParameterName);
                field.set(instance, new Float(injectConfigAnnotation.defaultFloatValue()));
            }
        } else if (type == Double.TYPE) {
            if (configuration.containsKey(configurationParameterName)) {
                field.setDouble(instance, configuration.getDouble(configurationParameterName));
            } else {
                log.debug(NO_PROPERTY_FOUND_LOG_MESSAGE, configurationParameterName);
                field.setDouble(instance, injectConfigAnnotation.defaultDoubleValue());
            }
        } else if (type == Double.class) {
            if (configuration.containsKey(configurationParameterName)) {
                field.set(instance, new Double(configuration.getDouble(configurationParameterName)));
            } else {
                log.debug(NO_PROPERTY_FOUND_LOG_MESSAGE, configurationParameterName);
                field.set(instance, new Double(injectConfigAnnotation.defaultDoubleValue()));
            }
        } else if (type == Character.TYPE) {
            if (configuration.containsKey(configurationParameterName)) {
                field.setChar(instance, configuration.getString(configurationParameterName).charAt(0));
            }
        } else if (type == Character.class) {
            if (configuration.containsKey(configurationParameterName)) {
                field.set(instance,
                        new Character(configuration.getString(configurationParameterName).charAt(0)));
            }
        } else {
            Object property = getProperty(configurationParameterName, injectConfigAnnotation);
            field.set(instance, property);
        }
    } catch (IllegalArgumentException ex) {
        log.error("Wrong argument or argument type during configuration injection", ex);
    } catch (IllegalAccessException ex) {
        log.error("Illegal access during configuration injection", ex);
    } catch (InstantiationException ex) {
        log.error("Impossible to instantiate value converter", ex);
    } finally {
        this.field.setAccessible(false);
    }
}

From source file:com.jaspersoft.studio.editor.preview.input.BigNumericInput.java

protected Number getNumber(String number) throws NumberFormatException {
    if (param.getValueClass().equals(Long.class)) {
        return new Long(number);
    } else if (param.getValueClass().equals(BigInteger.class)) {
        return new BigInteger(number);
    } else if (param.getValueClass().equals(Float.class)) {
        return new Float(number);
    } else if (param.getValueClass().equals(Double.class)) {
        return new Double(number);
    } else if (param.getValueClass().equals(Integer.class)) {
        return new Integer(number);
    } else if (param.getValueClass().equals(Short.class)) {
        return new Short(number);
    } else if (param.getValueClass().equals(Byte.class)) {
        return new Byte(number);
    } else if (param.getValueClass().equals(BigDecimal.class)) {
        return new BigDecimal(number);
    }/*from  w  w w .j  a  v  a2s.  c om*/
    return null;
}

From source file:com.ushahidi.swiftriver.core.api.dao.impl.JpaBucketDaoTest.java

@Test
public void getDrops() {
    Account account = accountDao.findById(1L);
    DropFilter filter = new DropFilter();
    List<Drop> drops = bucketDao.getDrops(1L, filter, 1, 10, account);

    assertEquals(5, drops.size());//ww  w.j  a v  a  2  s . c o m

    Drop drop = drops.get(0);
    assertEquals(5, drop.getId());
    assertEquals(false, drop.getRead());
    assertEquals("rss", drop.getChannel());
    assertEquals("droplet 5 title", drop.getTitle());
    assertEquals("droplet 5 content", drop.getContent());
    assertEquals("5", drop.getOriginalId());
    assertEquals(30, drop.getCommentCount());
    assertEquals(1, drop.getIdentity().getId());
    assertEquals("identity1_name", drop.getIdentity().getName());
    assertEquals("identity1_avatar", drop.getIdentity().getAvatar());
    assertNotNull(drop.getOriginalUrl());
    assertEquals(3, drop.getOriginalUrl().getId());
    assertEquals("http://www.bbc.co.uk/nature/20273855", drop.getOriginalUrl().getUrl());

    assertEquals(2, drop.getTags().size());
    Tag tag = drop.getTags().get(0);
    assertEquals(1, tag.getId());
    assertEquals("Jeremy Hunt", tag.getTag());
    assertEquals("person", tag.getType());

    assertEquals(2, drop.getLinks().size());
    Link link = drop.getLinks().get(0);
    assertEquals(2, link.getId());
    assertEquals(
            "http://news.bbc.co.uk/democracylive/hi/house_of_commons/newsid_9769000/9769109.stm#sa-ns_mchannel=rss&amp;ns_source=PublicRSS20-sa&quot;",
            link.getUrl());

    assertEquals(2, drop.getMedia().size());
    Media media = drop.getMedia().get(0);
    assertEquals(1, media.getId());
    assertEquals("http://gigaom2.files.wordpress.com/2012/10/datacapspercentage.jpeg", media.getUrl());
    assertEquals("image", media.getType());

    assertEquals(2, media.getThumbnails().size());
    MediaThumbnail thumbnail = media.getThumbnails().get(0);
    assertEquals(
            "https://2bcbd22fbb0a02d76141-1680e9dfed1be27cdc47787ec5d4ef89.ssl.cf1.rackcdn.com/625dd7cb656d258b4effb325253e880631699d80345016e9e755b4a04341cda1.peg",
            thumbnail.getUrl());
    assertEquals(80, thumbnail.getSize());

    assertEquals(2, drop.getPlaces().size());
    Place place = drop.getPlaces().get(0);
    assertEquals(1, place.getId());
    assertEquals("Wales", place.getPlaceName());
    assertEquals(new Float(146.11), place.getLongitude());
    assertEquals(new Float(-33), place.getLatitude());

    drop = drops.get(3);
    assertEquals(2, drop.getId());
    assertEquals(2, drop.getForms().size());

    BucketDropForm form = (BucketDropForm) drop.getForms().get(0);
    assertEquals(1, (long) form.getId());
    List<BucketDropFormField> values = form.getValues();
    assertEquals(3, values.size());
    assertEquals(1, (long) values.get(0).getField().getId());
    assertEquals("[\"English\"]", values.get(0).getValue());
    assertEquals(2, (long) values.get(1).getField().getId());
    assertEquals("\"Journalist\"", values.get(1).getValue());
    assertEquals(3, (long) values.get(2).getField().getId());
    assertEquals("\"Kenyans\"", values.get(2).getValue());
}