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:no.firestorm.weathernotificatonservice.WeatherNotificationService.java

/**
 * Display a notification with temperature
 * //from   ww  w.j ava  2 s.  co  m
 * @param weather
 *            Weather element to with data to be shown in notification, if
 *            null a message for that say that this station does not provide
 *            data will be shown
 */
private void makeNotification(WeatherElement weather) {
    int tickerIcon, contentIcon;
    CharSequence tickerText, contentTitle, contentText, contentTime;
    final DateFormat df = DateFormat.getTimeInstance(DateFormat.SHORT);
    long when;
    Float temperatureF = null;
    if (weather != null) {
        // Has data
        final WeatherElement temperature = weather;
        // Find name
        final String stationName = WeatherNotificationSettings.getStationName(WeatherNotificationService.this);

        // Find icon
        tickerIcon = TempToDrawable.getDrawableFromTemp(Float.valueOf(temperature.getValue()));
        contentIcon = tickerIcon;
        // Set title
        tickerText = stationName;
        contentTitle = stationName;
        contentTime = df.format(temperature.getDate());
        when = temperature.getDate().getTime();

        final Context context = WeatherNotificationService.this;
        temperatureF = new Float(temperature.getValue());
        contentText = String.format("%s %.1f C", context.getString(R.string.temperatur_),
                new Float(temperature.getValue()));

        updateAlarm(weather);

    } else {
        // No data
        contentIcon = android.R.drawable.stat_notify_error;
        final Context context = WeatherNotificationService.this;
        contentTime = df.format(new Date());
        when = (new Date()).getTime();
        tickerText = context.getText(R.string.no_available_data);
        contentTitle = context.getText(R.string.no_available_data);
        contentText = context.getString(R.string.try_another_station);
        tickerIcon = android.R.drawable.stat_notify_error;

    }

    makeNotification(tickerIcon, contentIcon, tickerText, contentTitle, contentText, contentTime, when,
            temperatureF);

}

From source file:com.exadel.flamingo.flex.messaging.amf.io.AMF0Serializer.java

protected Object[] convertPrimitiveArrayToObjectArray(Object array) {
    Class<?> componentType = array.getClass().getComponentType();

    Object[] result = null;/*  ww w .j ava2s.c  o  m*/

    if (componentType == null) {
        throw new NullPointerException("componentType is null");
    } else if (componentType == Character.TYPE) {
        char[] carray = (char[]) array;
        result = new Object[carray.length];
        for (int i = 0; i < carray.length; i++) {
            result[i] = new Character(carray[i]);
        }
    } else if (componentType == Byte.TYPE) {
        byte[] barray = (byte[]) array;
        result = new Object[barray.length];
        for (int i = 0; i < barray.length; i++) {
            result[i] = new Byte(barray[i]);
        }
    } else if (componentType == Short.TYPE) {
        short[] sarray = (short[]) array;
        result = new Object[sarray.length];
        for (int i = 0; i < sarray.length; i++) {
            result[i] = new Short(sarray[i]);
        }
    } else if (componentType == Integer.TYPE) {
        int[] iarray = (int[]) array;
        result = new Object[iarray.length];
        for (int i = 0; i < iarray.length; i++) {
            result[i] = Integer.valueOf(iarray[i]);
        }
    } else if (componentType == Long.TYPE) {
        long[] larray = (long[]) array;
        result = new Object[larray.length];
        for (int i = 0; i < larray.length; i++) {
            result[i] = new Long(larray[i]);
        }
    } else if (componentType == Double.TYPE) {
        double[] darray = (double[]) array;
        result = new Object[darray.length];
        for (int i = 0; i < darray.length; i++) {
            result[i] = new Double(darray[i]);
        }
    } else if (componentType == Float.TYPE) {
        float[] farray = (float[]) array;
        result = new Object[farray.length];
        for (int i = 0; i < farray.length; i++) {
            result[i] = new Float(farray[i]);
        }
    } else if (componentType == Boolean.TYPE) {
        boolean[] barray = (boolean[]) array;
        result = new Object[barray.length];
        for (int i = 0; i < barray.length; i++) {
            result[i] = new Boolean(barray[i]);
        }
    } else {
        throw new IllegalArgumentException("unexpected component type: " + componentType.getClass().getName());
    }

    return result;
}

From source file:com.ibuildapp.romanblack.FanWallPlugin.data.JSONParser.java

/**
 * Downloads and parses JSON comments data.
 * @return comments array/*from   w  w w . ja  v a  2  s.co  m*/
 */
public static ArrayList<FanWallMessage> makeRequest(long wallMsgId, long commentId, long wallCommentsMsgIdEarly,
        int limit) {
    try {
        String url = String.format("%s/%s/%s/%d/%d/%d/%d/%s/%s", Statics.BASE_URL,
                com.appbuilder.sdk.android.Statics.appId, Statics.MODULE_ID, wallMsgId, commentId,
                wallCommentsMsgIdEarly, limit, com.appbuilder.sdk.android.Statics.appId,
                com.appbuilder.sdk.android.Statics.appToken);

        Log.e("URLTAG", url);

        String resp = loadURLData(url);

        if (TextUtils.isEmpty(resp))
            return null;

        JSONObject mainObject = new JSONObject(resp);

        JSONArray messagesJSON = mainObject.getJSONArray("posts");

        ArrayList<FanWallMessage> parsedMessages = new ArrayList<FanWallMessage>();

        for (int i = 0; i < messagesJSON.length(); i++) {
            JSONObject messageJSON = messagesJSON.getJSONObject(i);

            FanWallMessage tmpMessage = new FanWallMessage();
            try {
                tmpMessage.setSharingCount(new Long(messageJSON.getString("sharing_count")).longValue());
            } catch (JSONException e) {
            }
            tmpMessage.setId(new Long(messageJSON.getString("post_id")).longValue());
            tmpMessage.setAuthor(messageJSON.getString("user_name"));
            tmpMessage.setDate(new Date(new Long(messageJSON.getString("create")).longValue()));
            tmpMessage.setUserAvatarUrl(messageJSON.getString("user_avatar"));
            tmpMessage.setText(messageJSON.getString("text"));
            try {
                tmpMessage.setPoint(new Float(messageJSON.getString("latitude")).floatValue(),
                        new Float(messageJSON.getString("longitude")).floatValue());
            } catch (NumberFormatException nFEx) {
                Log.e("", "");
            }

            try {
                tmpMessage.setParentId(new Integer(messageJSON.getString("parent_id")).intValue());
            } catch (NumberFormatException nFEx) {
                Log.e("", "");
            }

            try {
                tmpMessage.setReplyId(new Integer(messageJSON.getString("reply_id")).intValue());
            } catch (NumberFormatException nFEx) {
                Log.e("", "");
            }

            tmpMessage.setTotalComments(new Integer(messageJSON.getString("total_comments")).intValue());

            JSONArray imagesJSON = messageJSON.getJSONArray("images");
            if (imagesJSON.length() > 0) {
                tmpMessage.setImageUrl(imagesJSON.getString(0));
            }

            tmpMessage.setAccountId(messageJSON.getString("account_id"));
            tmpMessage.setAccountType(messageJSON.getString("account_type"));

            parsedMessages.add(tmpMessage);
        }

        return parsedMessages;
    } catch (JSONException jSSONEx) {

        return null;
    }
}

From source file:TwitterPlanet.java

public void initDestroyer() {

    /// set up markers
    for (int i = 0; i < GPSArray.size(); i++) {
        // / add a new GPS marker, set its lat and long arrays
        // / and compute its position
        // theMarker[i] = new GPSMarker(longArray[i], latArray[i]);
        // theMarker[i].computePosOnSphere(EARTH_RADIUS);

    }/*w w w .  j a v  a2s .  com*/

    //// init the destroyer
    //// placeholder lat and long
    float lt = new Float(34.024704);
    float lo = new Float(-84.5033);

    try {
        theDestroyer = new Destroyer(lo, lt);
        theDestroyer.computePosOnSphere(EARTH_RADIUS);

    } catch (Exception e) {
        println(e);
    }
}

From source file:javadz.beanutils.ConvertUtilsBean.java

/**
 * Sets the default value for Float conversions.
 * @param newDefaultFloat The default Float value
 * @deprecated Register replacement converters for Float.TYPE and
 *  Float.class instead//from www  .j  a va2 s.  co  m
 */
public void setDefaultFloat(float newDefaultFloat) {
    defaultFloat = new Float(newDefaultFloat);
    register(new FloatConverter(defaultFloat), Float.TYPE);
    register(new FloatConverter(defaultFloat), Float.class);
}

From source file:blue.components.lines.Line.java

public Object getValueAt(int rowIndex, int columnIndex) {
    LinePoint p = points.get(rowIndex);//  w ww.j  a v  a 2 s .c  om

    if (columnIndex == 0) {
        return new Float(p.getX());
    }

    return new Float(p.getY());
}

From source file:com.jaspersoft.studio.components.chart.wizard.fragments.data.DSPie.java

@Override
protected Control createChartRight(Composite parent) {
    Composite yCompo = new Composite(parent, SWT.NONE);
    yCompo.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    yCompo.setLayout(new GridLayout(2, false));

    new Label(yCompo, SWT.NONE).setText(Messages.DSPie_minSlicePercentage);
    minSlice = new Text(yCompo, SWT.BORDER);
    minSlice.addListener(SWT.Verify, new Listener() {

        public void handleEvent(Event e) {
            try {
                String number = e.text;
                String oldText = ((Text) e.widget).getText();
                if (e.start == 0)
                    number = e.text + oldText;
                else
                    number = oldText.substring(0, e.start) + e.text;
                if (oldText.length() - 1 > e.start + 1)
                    number += oldText.substring(e.start + 1);

                if (number.equals("-")) //$NON-NLS-1$
                    number = "-0";//$NON-NLS-1$
                if (number.equals(".")) //$NON-NLS-1$
                    number = "0.";//$NON-NLS-1$

                e.doit = FloatValidator.getInstance().isValid(number);
            } catch (NumberFormatException ne) {
                e.doit = false;/*from   w  w w  .  ja v  a 2 s  .  com*/
            }
        }
    });
    minSlice.addModifyListener(new ModifyListener() {

        public void modifyText(ModifyEvent e) {
            try {
                dataset.setMinPercentage(new Float(minSlice.getText()));
            } catch (NumberFormatException ne) {

            }
        }
    });

    new Label(yCompo, SWT.NONE).setText(Messages.DSPie_maxSlices);
    maxSlice = new Spinner(yCompo, SWT.BORDER);
    maxSlice.addModifyListener(new ModifyListener() {

        public void modifyText(ModifyEvent e) {
            Integer intValue = maxSlice.getSelection();
            if (intValue == 0)
                intValue = null;
            dataset.setMaxCount(intValue);
        }
    });

    obtn = new Button(yCompo, SWT.PUSH);
    obtn.setText(Messages.DSPie_otherSectionButton);
    obtn.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false, 2, 1));
    obtn.addSelectionListener(new SelectionListener() {

        public void widgetSelected(SelectionEvent e) {
            MHyperLink hyperLinkElement = null;
            JRHyperlink hyperlink = dataset.getOtherSectionHyperlink();
            if (hyperlink != null) {
                hyperLinkElement = new MHyperLink((JRHyperlink) hyperlink.clone());
            } else {
                hyperLinkElement = new MHyperLink(null);
            }
            JRDesignExpression otherKeyExp = getCopyExpression(dataset.getOtherKeyExpression());
            JRDesignExpression otherLabelExp = getCopyExpression(dataset.getOtherLabelExpression());
            OtherSectionPage dlg = new OtherSectionPage(hyperlinkBtn.getShell(), hyperLinkElement, otherKeyExp,
                    otherLabelExp);
            int operationResult = dlg.open();
            if (operationResult == Window.OK) {
                dataset.setOtherSectionHyperlink(dlg.getHyperlink());
                dataset.setOtherKeyExpression(dlg.getKeyExpression());
                dataset.setOtherLabelExpression(dlg.getLabelExpression());
            }
        }

        public void widgetDefaultSelected(SelectionEvent e) {
            widgetSelected(e);
        }
    });

    return yCompo;
}

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

public void testWithCustomObjectAndEditorSelected() throws Exception {
    final PropertyEditor floatEditor = new SimpleFloatEditor();
    floatEditor.setValue(new Float("12.34"));
    BindStatus bindStatus = new BindStatus(getRequestContext(), "testBean.someNumber", false) {
        public PropertyEditor getEditor() {
            return floatEditor;
        }//  ww w .j a  va 2 s . c  o  m
    };
    getPageContext().setAttribute(SelectTagHDIV.LIST_VALUE_PAGE_ATTRIBUTE, bindStatus);

    this.tag.setValue("${myNumber}");
    this.tag.setLabel("${myNumber}");

    int result = this.tag.doStartTag();
    assertEquals(BodyTag.EVAL_BODY_BUFFERED, result);
    result = this.tag.doEndTag();
    assertEquals(Tag.EVAL_PAGE, result);

    String output = getOutput();
    assertOptionTagOpened(output);
    assertOptionTagClosed(output);
    assertContainsAttribute(output, "selected", "selected");
    assertBlockTagContains(output, "12.34f");
}

From source file:io.github.msdk.features.ransacaligner.RansacAlignerMethod.java

private Hashtable<FeatureTableRow, FeatureTableRow> getAlignmentMap(FeatureTable featureTable) {

    // Create a table of mappings for best scores
    Hashtable<FeatureTableRow, FeatureTableRow> alignmentMapping = new Hashtable<FeatureTableRow, FeatureTableRow>();

    // Create a sorted set of scores matching
    TreeSet<RowVsRowScore> scoreSet = new TreeSet<RowVsRowScore>();

    // RANSAC algorithm
    List<AlignStructMol> list = ransacPeakLists(result, featureTable);
    PolynomialFunction function = this.getPolynomialFunction(list);

    List<FeatureTableRow> allRows = featureTable.getRows();

    for (FeatureTableRow row : allRows) {
        // Calculate limits for a row with which the row can be aligned
        Range<Double> mzRange = mzTolerance.getToleranceRange(row.getMz());

        double rt;
        try {/*from   ww  w.  j  av  a2 s  .  com*/
            rt = function.value(row.getChromatographyInfo().getRetentionTime());
        } catch (NullPointerException e) {
            rt = row.getChromatographyInfo().getRetentionTime();
        }
        if (Double.isNaN(rt) || rt == -1) {
            rt = row.getChromatographyInfo().getRetentionTime();
        }

        Range<Double> rtRange = rtToleranceAfterCorrection.getToleranceRange(rt);

        // Get all rows of the aligned feature table within the m/z and
        // RT limits
        List<FeatureTableRow> candidateRows = result.getRowsInsideRange(rtRange, mzRange);

        for (FeatureTableRow candidateRow : candidateRows) {
            RowVsRowScore score;
            if (requireSameCharge) {
                FeatureTableColumn<Integer> chargeColumn1 = featureTable.getColumn(ColumnName.CHARGE, null);
                FeatureTableColumn<Integer> chargeColumn2 = result.getColumn(ColumnName.CHARGE, null);
                Integer charge1 = row.getData(chargeColumn1);
                Integer charge2 = candidateRow.getData(chargeColumn2);
                if (!charge1.equals(charge2))
                    continue;
            }

            // Check ion annotation
            if (requireSameAnnotation) {
                FeatureTableColumn<List<IonAnnotation>> ionAnnotationColumn1 = featureTable
                        .getColumn(ColumnName.IONANNOTATION, null);
                FeatureTableColumn<List<IonAnnotation>> ionAnnotationColumn2 = result
                        .getColumn(ColumnName.IONANNOTATION, null);
                List<IonAnnotation> ionAnnotations1 = row.getData(ionAnnotationColumn1);
                List<IonAnnotation> ionAnnotations2 = candidateRow.getData(ionAnnotationColumn2);

                // Check that all ion annotations in first row are in
                // the candidate row
                boolean equalIons = false;
                if (ionAnnotations1 != null && ionAnnotations2 != null) {
                    for (IonAnnotation ionAnnotation : ionAnnotations1) {
                        for (IonAnnotation targetIonAnnotation : ionAnnotations2) {
                            if (targetIonAnnotation.compareTo(ionAnnotation) == 0)
                                equalIons = true;
                        }
                    }
                }
                if (!equalIons)
                    continue;

            }

            try {
                double mzLength = mzRange.upperEndpoint() - mzRange.lowerEndpoint();
                double rtLength = rtRange.upperEndpoint() - rtRange.lowerEndpoint();
                score = new RowVsRowScore(row, candidateRow, mzLength, rtLength, new Float(rt));

                scoreSet.add(score);

            } catch (Exception e) {
                return null;
            }
        }
    }

    // Iterate scores by descending order
    Iterator<RowVsRowScore> scoreIterator = scoreSet.iterator();
    while (scoreIterator.hasNext()) {

        RowVsRowScore score = scoreIterator.next();

        // Check if the row is already mapped
        if (alignmentMapping.containsKey(score.getFeatureTableRow())) {
            continue;
        }

        // Check if the aligned row is already filled
        if (alignmentMapping.containsValue(score.getAlignedRow())) {
            continue;
        }

        alignmentMapping.put(score.getFeatureTableRow(), score.getAlignedRow());

    }

    return alignmentMapping;
}

From source file:es.caib.zkib.jxpath.util.BasicTypeConverter.java

/**
 * Convert a string to a primitive type.
 * @param object String/*from w w  w .j av  a2 s.c o  m*/
 * @param toType destination class
 * @return wrapper
 */
protected Object convertStringToPrimitive(Object object, Class toType) {
    toType = TypeUtils.wrapPrimitive(toType);
    if (toType == Boolean.class) {
        return Boolean.valueOf((String) object);
    }
    if (toType == Character.class) {
        return new Character(((String) object).charAt(0));
    }
    if (toType == Byte.class) {
        return new Byte((String) object);
    }
    if (toType == Short.class) {
        if ("".equals(object))
            return null;
        else
            return new Short((String) object);
    }
    if (toType == Integer.class) {
        if ("".equals(object))
            return null;
        else
            return new Integer((String) object);
    }
    if (toType == Long.class) {
        if ("".equals(object))
            return null;
        else
            return new Long((String) object);
    }
    if (toType == Float.class) {
        if ("".equals(object))
            return null;
        else
            return new Float((String) object);
    }
    if (toType == Double.class) {
        if ("".equals(object))
            return null;
        else
            return new Double((String) object);
    }
    return null;
}