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:com.stimulus.archiva.language.LanguageIdentifier.java

/**
 * Identify language of content.//from   w ww  .ja v  a  2 s  . c o  m
 * 
 * @param content is the content to analyze.
 * @return The 2 letter
 *         <a href="http://www.w3.org/WAI/ER/IG/ert/iso639.htm">ISO 639
 *         language code</a> (en, fi, sv, ...) of the language that best
 *         matches the specified content.
 */
public synchronized String identify(StringBuffer content) {
    //logger.debug("language identification sample:");
    //logger.debug(content.toString());
    StringBuffer text = content;
    if ((analyzeLength > 0) && (content.length() > analyzeLength)) {
        text = new StringBuffer().append(content);
        text.setLength(analyzeLength);
    }

    suspect.analyze(text);
    Iterator iter = suspect.getSorted().iterator();
    float topscore = Float.MIN_VALUE;
    String lang = null;
    HashMap scores = new HashMap();
    NGramEntry searched = null;

    while (iter.hasNext()) {
        searched = (NGramEntry) iter.next();
        NGramEntry[] ngrams = (NGramEntry[]) ngramsIdx.get(searched.getSeq());
        if (ngrams != null) {
            for (int j = 0; j < ngrams.length; j++) {
                NGramProfile profile = ngrams[j].getProfile();
                Float pScore = (Float) scores.get(profile);
                if (pScore == null) {
                    pScore = new Float(0);
                }
                float plScore = pScore.floatValue();
                plScore += ngrams[j].getFrequency() + searched.getFrequency();
                scores.put(profile, new Float(plScore));
                if (plScore > topscore) {
                    topscore = plScore;
                    lang = profile.getName();
                }
            }
        }
    }
    logger.debug("document language identified {language='" + lang + "'}");
    return lang;
}

From source file:com.openbravo.pos.util.JRPrinterAWT.java

/**
 *
 *///from  www . ja v a2  s  .  c  om
public Image printPageToImage(int pageIndex, float zoom) throws JRException {
    Image pageImage = new BufferedImage((int) (jasperPrint.getPageWidth() * zoom) + 1,
            (int) (jasperPrint.getPageHeight() * zoom) + 1, BufferedImage.TYPE_INT_RGB);

    JRGraphics2DExporter exporter = new JRGraphics2DExporter(jasperReportsContext);
    exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
    exporter.setParameter(JRGraphics2DExporterParameter.GRAPHICS_2D, pageImage.getGraphics());
    exporter.setParameter(JRExporterParameter.PAGE_INDEX, Integer.valueOf(pageIndex));
    exporter.setParameter(JRGraphics2DExporterParameter.ZOOM_RATIO, new Float(zoom));
    exporter.exportReport();

    return pageImage;
}

From source file:control.Functions.java

public static float getPercentageStep(int max) {
    return new Float(1.0 / max);
}

From source file:org.hdiv.web.servlet.tags.form.SelectTagTests.java

public void testWithFloatCustom() throws Exception {
    PropertyEditor propertyEditor = new SimpleFloatEditor();
    BeanPropertyBindingResult errors = new BeanPropertyBindingResult(getTestBean(), COMMAND_NAME);
    errors.getPropertyAccessor().registerCustomEditor(Float.class, propertyEditor);
    exposeBindingResult(errors);/*  w  ww  .j a  v  a 2  s .  c  om*/

    this.tag.setPath("myFloat");

    Float[] array = new Float[] { new Float("12.30"), new Float("12.32"), new Float("12.34"),
            new Float("12.36"), new Float("12.38"), new Float("12.40"), new Float("12.42"), new Float("12.44"),
            new Float("12.46"), new Float("12.48") };

    this.tag.setItems(array);
    int result = this.tag.doStartTag();
    assertEquals(Tag.SKIP_BODY, result);

    String output = getWriter().toString();
    assertTrue(output.startsWith("<select "));
    assertTrue(output.endsWith("</select>"));

    SAXReader reader = new SAXReader();
    Document document = reader.read(new StringReader(output));
    Element rootElement = document.getRootElement();
    assertEquals("select", rootElement.getName());
    assertEquals("myFloat", rootElement.attribute("name").getValue());
    List children = rootElement.elements();
    assertEquals("Incorrect number of children", array.length, children.size());

    Element e = (Element) rootElement.selectSingleNode("option[text() = '12.34f']");
    assertEquals("'12.34' node not selected", "selected", e.attribute("selected").getValue());

    e = (Element) rootElement.selectSingleNode("option[text() = '12.32f']");
    assertNull("'12.32' node incorrectly selected", e.attribute("selected"));
}

From source file:com.mirth.connect.connectors.tcp.TcpMessageDispatcher.java

public void doDispatch(UMOEvent event) throws Exception {
    StateAwareSocket socket = null;//from ww w  .  jav a2  s.  c  om
    Object payload = null;
    boolean success = false;
    Exception exceptionWriting = null;
    String exceptionMessage = "";
    String endpointUri = event.getEndpoint().getEndpointURI().toString();
    MessageObject messageObject = messageObjectController.getMessageObjectFromEvent(event);
    if (messageObject == null) {
        return;
    }

    String host = replacer.replaceURLValues(endpointUri, messageObject);

    try {
        if (connector.isUsePersistentQueues()) {
            connector.putMessageInQueue(event.getEndpoint().getEndpointURI(), messageObject);
            return;
        } else {
            int retryCount = -1;
            int maxRetries = connector.getMaxRetryCount();
            while (!success && !disposed && (retryCount < maxRetries)) {

                monitoringController.updateStatus(connector, connectorType, Event.ATTEMPTING, socket);

                if (maxRetries != TcpConnector.KEEP_RETRYING_INDEFINETLY) {
                    retryCount++;
                }
                try {
                    if (!connector.isKeepSendSocketOpen()) {
                        socket = initSocket(host);
                        writeTemplatedData(socket, messageObject);
                        success = true;
                    } else {
                        socket = connectedSockets.get(host);

                        // Dispose the socket if the remote side closed it
                        if (socket != null && socket.remoteSideHasClosed()) {
                            doDispose(socket);
                            socket = null;
                        }

                        if (socket != null && !socket.isClosed()) {
                            try {
                                writeTemplatedData(socket, messageObject);
                                success = true;
                            } catch (Exception e) {
                                // if the connection was lost, try creating
                                // it again
                                doDispose(socket);
                                socket = initSocket(host);
                                writeTemplatedData(socket, messageObject);
                                success = true;
                            }
                        } else {
                            socket = initSocket(host);
                            writeTemplatedData(socket, messageObject);
                            success = true;
                        }
                    }
                } catch (Exception exs) {
                    if (retryCount < maxRetries) {
                        if (socket != null) {
                            doDispose(socket);
                        }
                        logger.warn("Can't connect to the endpoint,waiting"
                                + new Float(connector.getReconnectMillisecs() / 1000)
                                + "seconds for reconnecting \r\n(" + exs + ")");
                        try {
                            Thread.sleep(connector.getReconnectMillisecs());
                        } catch (Throwable t) {
                            exceptionMessage = "Unable to send message. Too many retries";
                            logger.error("Sending interrupption. Payload not sent");
                            retryCount = maxRetries + 1;
                            exceptionWriting = exs;
                        }
                    } else {
                        exceptionMessage = "Unable to connect to destination";
                        logger.error("Can't connect to the endpoint: payload not sent");
                        exceptionWriting = exs;

                    }
                }
            }
        }
    } catch (Exception exu) {
        exceptionMessage = exu.getMessage();
        alertController.sendAlerts(((TcpConnector) connector).getChannelId(), Constants.ERROR_411, null, exu);
        logger.error("Unknown exception dispatching " + exu);
        exceptionWriting = exu;
    } finally {

    }
    if (!success) {
        messageObjectController.setError(messageObject, Constants.ERROR_411, exceptionMessage, exceptionWriting,
                null);
        alertController.sendAlerts(((TcpConnector) connector).getChannelId(), Constants.ERROR_411,
                exceptionMessage, exceptionWriting);
    }
    if (success && (exceptionWriting == null)) {
        manageResponseAck(socket, endpointUri, messageObject);
        if (!connector.isKeepSendSocketOpen()) {
            monitoringController.updateStatus(connector, connectorType, Event.DISCONNECTED, socket);
            doDispose();
        }
    }
}

From source file:com.germinus.easyconf.taglib.PropertyTag.java

private Object readProperty(ComponentProperties conf) throws JspException {
    Object value;/*from  w  w w .  j a v  a  2 s. c o m*/
    if (getType().equals("java.util.List")) {
        value = conf.getList(property, getPropertyFilter(), EMPTY_LIST);
    } else if (getType().equals("java.lang.Integer")) {
        value = conf.getInteger(property, getPropertyFilter(), new Integer(0));
    } else if (getType().equals("java.lang.String[]")) {
        value = conf.getStringArray(property, getPropertyFilter(), new String[0]);
    } else if (getType().equals("java.lang.String")) {
        if (defaultValue != null) {
            value = conf.getString(property, getPropertyFilter(), defaultValue);
        } else {
            value = conf.getString(property, getPropertyFilter());
        }
    } else if (getType().equals("java.lang.Double")) {
        value = new Double(conf.getDouble(property, getPropertyFilter()));
    } else if (getType().equals("java.lang.Float")) {
        value = new Float(conf.getFloat(property, getPropertyFilter()));
    } else if (getType().equals("java.lang.Byte")) {
        value = new Byte(conf.getByte(property, getPropertyFilter()));
    } else if (getType().equals("java.math.BigDecimal")) {
        value = conf.getBigDecimal(property, getPropertyFilter());
    } else if (getType().equals("java.lang.BigInteger")) {
        value = conf.getBigInteger(property, getPropertyFilter());
    } else if (getType().equals("java.lang.Boolean")) {
        value = new Boolean(conf.getBoolean(property, getPropertyFilter()));
    } else if (getType().equals("java.lang.Short")) {
        value = new Short(conf.getShort(property, getPropertyFilter()));
    } else if (getType().equals("java.lang.Long")) {
        value = new Long(conf.getLong(property, getPropertyFilter()));
    } else {
        JspException e = new JspException("Unsupported type: " + type);
        RequestUtils.saveException(pageContext, e);
        throw e;
    }
    return value;
}

From source file:com.fluidops.iwb.api.APIImpl.java

public void setConfigOption(String key, String value) throws Exception {
    Method found = null;// ww  w  . j  av  a2  s. c  om
    // fbase Config
    for (Method m : Config.class.getMethods()) {
        ConfigDoc cfd = m.getAnnotation(ConfigDoc.class);
        if (cfd != null)
            if (cfd.name().equals(key))
                found = m;
    }

    // check if prop exists
    if (found == null)
        throw new Exception("Config property does not exist: " + key);

    // check type
    if (found.getReturnType().equals(boolean.class))
        Boolean.valueOf(value);
    else if (found.getReturnType().equals(int.class))
        new Integer(value);
    else if (found.getReturnType().equals(long.class))
        new Long(value);
    else if (found.getReturnType().equals(byte.class))
        new Byte(value);
    else if (found.getReturnType().equals(short.class))
        new Short(value);
    else if (found.getReturnType().equals(float.class))
        new Float(value);
    else if (found.getReturnType().equals(double.class))
        new Double(value);
    else if (found.getReturnType().equals(char.class))
        Character.valueOf(value.charAt(0));
    else if (found.getReturnType().equals(Character.class))
        Character.valueOf(value.charAt(0));
    else
        found.getReturnType().getConstructor(String.class).newInstance(value);

    com.fluidops.config.Config.getConfig().set(key, value);
}

From source file:com.infinira.aerospike.dataaccess.model.Entity.java

/**
 * Get Float object for a given field value
 * @param name  field name/*from   w  w  w .  ja  v a  2  s . c  o  m*/
 * @return  Float value
 */
protected Float getFloat(String name) {
    String value = this.getString(name);
    return value != null ? new Float(value) : null;
}

From source file:Coordinate.java

/**
 * A method to add distance in a southerly direction to a coordinate
 *
 * @param latitude  a latitude coordinate in decimal notation
 * @param longitude a longitude coordinate in decimal notation
 * @param distance  the distance to add in metres
 *
 * @return          the new coordinate/* w  ww .  j a  v a 2 s  . c  om*/
 */
public static Coordinate addDistanceSouth(float latitude, float longitude, int distance) {

    // check on the parameters
    if (isValidLatitude(latitude) == false || isValidLongitude(longitude) == false || distance <= 0) {
        throw new IllegalArgumentException("All parameters are required and must be valid");
    }

    // convert the distance from metres to kilometers
    float kilometers = distance / new Float(1000);

    // calculate the new latitude
    double newLat = latitude - (kilometers / latitudeConstant());

    return new Coordinate(new Float(newLat).floatValue(), longitude);

}

From source file:org.pentaho.reporting.engine.classic.extensions.legacy.charts.LegacyChartType.java

public void configureDesignTimeDefaults(final ReportElement element, final Locale locale) {
    final AbstractChartExpression theExpression = new BarChartExpression();
    element.setAttributeExpression(AttributeNames.Core.NAMESPACE, AttributeNames.Core.VALUE, theExpression);
    element.getStyle().setStyleProperty(ElementStyleKeys.MIN_WIDTH, new Float(280));
    element.getStyle().setStyleProperty(ElementStyleKeys.MIN_HEIGHT, new Float(190));
}