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.workin.http.httpclient.v4.handler.response.FloatResponseHandler.java

@Override
public Float handleResponse(HttpResponse response) throws ClientProtocolException, IOException {
    String result = super.doResponse(response);
    if (result != null)
        return new Float(result);

    String defaultValue = super.getDefaultValue();
    return StringUtils.isNotBlank(defaultValue) ? new Float(defaultValue) : null;
}

From source file:com.redhat.lightblue.crud.validator.MinMaxCheckerTest.java

/**
 * Col1: For debugging purposes to know which test case had issues
 * Col2: A instantiation to test with. Should always represent 2.
 *//*ww w  .j  a v  a  2s  . c o  m*/
@Parameters(name = "{index}: {0}")
public static Collection<Object[]> data() {
    return Arrays.asList(new Object[][] { { Integer.class, new Integer(2) },
            { Byte.class, new Byte(new Integer(2).byteValue()) },
            { Short.class, new Short(new Integer(2).shortValue()) }, { Long.class, new Long(2L) },
            { Float.class, new Float(2F) }, { Double.class, new Double(2D) },
            { BigInteger.class, new BigInteger("2") }, { BigDecimal.class, new BigDecimal(2) } });
}

From source file:Main.java

public static Object getNamedElemValue(Element parent, String elementName, Class basicType, Object defaultVal) {
    String val = getNamedElemValue(parent, elementName);
    if (val == null) {
        return defaultVal;
    }//from ww  w  .j  a  va2  s  .c  o m

    try {
        if (Boolean.class.equals(basicType)) {
            return new Boolean(val);
        } else if (Integer.class.equals(basicType)) {
            return new Integer(val);
        } else if (Float.class.equals(basicType)) {
            return new Float(val);
        } else if (Double.class.equals(basicType)) {
            return new Double(val);
        } else
            return val;
    } catch (Exception e) {
        return defaultVal;
    }
}

From source file:jp.co.acroquest.endosnipe.report.converter.util.calc.FloatCalculator.java

public Object div(Object obj1, Object obj2) {
    Float floatData1 = (Float) obj1;
    Float floatData2 = (Float) obj2;

    return (Object) (new Float((float) (floatData1.floatValue() / floatData2.floatValue())));
}

From source file:Main.java

private static ArrayList<ArrayList> sortObjectArrayListSimpleMaster(ArrayList listIn, String paramName) {
    ArrayList<ArrayList> answer = new ArrayList<ArrayList>();
    ArrayList newList = new ArrayList();
    ArrayList<Integer> indices = new ArrayList<Integer>();
    try {//from   ww w. ja v a2  s.  co  m
        if (listIn.size() > 0) {
            Class<?> c = listIn.get(0).getClass();
            Field f = c.getDeclaredField(paramName);
            f.setAccessible(true);
            Class<?> t = f.getType();
            Double dd = new Double(14);
            Float ff = new Float(14);
            Integer ii = new Integer(14);
            Map sortedPos = new LinkedHashMap();
            Map sortedNeg = new LinkedHashMap();
            Map unsorted = new LinkedHashMap();
            int indexCount = 0;
            long count = 0;
            if (t.isPrimitive()) {
                for (Object thisObj : listIn) {
                    Object o = f.get(thisObj);
                    double d = 0;
                    if (t.getName().equals("char")) {
                        d = (int) ((Character) o);
                    } else if (t.isInstance(dd))
                        d = (Double) o;
                    else if (t.isInstance(ff))
                        d = (Float) o;
                    else if (t.isInstance(ii))
                        d = (Integer) o;
                    else
                        d = new Double(o.toString());

                    boolean isNegative = false;

                    if (d < 0) {
                        isNegative = true;
                        d = Math.abs(d);
                    }

                    String format = "%1$30f";
                    String newKey = String.format(format, d);
                    String format2 = "%1$20d";
                    String countString = String.format(format2, count);
                    newKey += "-" + countString;
                    if (isNegative) {
                        sortedNeg.put(newKey, thisObj);
                    } else {
                        sortedPos.put(newKey, thisObj);
                    }
                    unsorted.put(thisObj, indexCount);
                    count++;
                    indexCount++;
                }
                TreeMap<String, Object> resultPos = new TreeMap();
                resultPos.putAll(sortedPos);
                sortedPos = resultPos;
                TreeMap<String, Object> resultNeg = new TreeMap();
                resultNeg.putAll(sortedNeg);
                sortedNeg = resultNeg;
            } else if (t.isInstance(paramName)) {
                // System.out.println("is a string with value " + o);
                for (Object thisObj : listIn) {
                    String key = (String) (f.get(thisObj));
                    sortedPos.put(key + "-" + count, thisObj);
                    unsorted.put(thisObj, indexCount);
                    count++;
                    indexCount++;
                }
                TreeMap<String, Object> result = new TreeMap(String.CASE_INSENSITIVE_ORDER);
                result.putAll(sortedPos);
                sortedPos = result;
            }

            Iterator itNeg = sortedNeg.entrySet().iterator();
            while (itNeg.hasNext()) {
                Map.Entry pairs = (Map.Entry) itNeg.next();
                newList.add(pairs.getValue());
                itNeg.remove();
            }

            Collections.reverse(newList);

            Iterator itPos = sortedPos.entrySet().iterator();
            while (itPos.hasNext()) {
                Map.Entry pairs = (Map.Entry) itPos.next();
                Object obj = pairs.getValue();
                newList.add(obj);
                indices.add((Integer) unsorted.get(obj));
                itPos.remove();
            }
        }
    } catch (Exception e) {
        System.out
                .println("problem sorting list.  listIn.size(): " + listIn.size() + " and param: " + paramName);
        answer.add(newList);
        answer.add(indices);
        return answer;
    }
    answer.add(newList);
    answer.add(indices);
    return answer;
}

From source file:ca.tbcn.greenp.Carpark.java

public static Carpark fromJSON(JSONObject json) throws JSONException {
    Carpark c = new Carpark();

    c.setDateScraped(json.getString("date_scraped"));
    c.setPaymentOptions(json.getString("payment_options"));
    c.setCapacity(json.getString("capacity"));
    c.setTitle(json.getString("title"));
    c.setUrl(json.getString("url"));
    c.setRateDetails(json.getString("rate_details"));
    c.setFacilityType(json.getString("facility_type"));
    c.setRate(json.getString("rate"));
    c.setPaymentTypes(json.getString("payment_types"));
    c.setStreetAddress(json.getString("street_address"));
    c.setLat(new Float(json.getString("lat")).floatValue());
    c.setLng(new Float(json.getString("lng")).floatValue());

    return c;// w w w .j a v  a2 s  .c o  m
}

From source file:com.milang.torparknow.Carpark.java

public static Carpark fromJSON(JSONObject json) throws JSONException {
    Carpark c = new Carpark();

    c.setDateScraped(json.getString("date_scraped"));
    c.setPaymentOptions(json.getString("payment_options"));
    c.setCapacity(json.getString("capacity"));
    c.setTitle(json.getString("title"));
    c.setUrl(json.getString("url"));
    c.setRateDetails(json.getString("rate_details"));
    c.setFacilityType(json.getString("facility_type"));
    c.setRate(json.getString("rate"));
    c.setPaymentTypes(json.getString("payment_types"));
    c.setStreetAddress(json.getString("street_address"));
    c.setLat(new Float(json.getString("lat")).floatValue());
    c.setLng(new Float(json.getString("lng")).floatValue());

    //c.setCalcDistance(LocationUtil.calcDistanceInKm(c.getLat(), c.getLng(), currentLocation));

    return c;//from w  w  w .  jav a  2s . c om
}

From source file:com.infinities.skyport.compute.entity.patch.VolumeProductPatchBuilderTest.java

@Test
public void testDiff() {
    VolumeProduct vp = VolumeProduct.getInstance("id", "name", "description", VolumeType.SSD,
            new Storage<Gigabyte>(5, new Gigabyte()), "currency", 5, 5, new Float(5), new Float(5));
    vp.withMaxIopsRatio(1);//from   w w  w  . j  av a2 s  . com
    vp.withMaxVolumeSize(new Storage<Gigabyte>(1, new Gigabyte()));
    vp.withMinVolumeSize(new Storage<Gigabyte>(1, new Gigabyte()));
    VolumeProduct updated = VolumeProduct.getInstance("id", "name", "description", VolumeType.SSD,
            new Storage<Gigabyte>(5, new Gigabyte()), "currency", 5, 5, new Float(5), new Float(5));
    updated.withMaxIopsRatio(5);
    updated.withMaxVolumeSize(new Storage<Gigabyte>(100, new Gigabyte()));
    updated.withMinVolumeSize(new Storage<Gigabyte>(2, new Gigabyte()));
    DiffResult diffResult = builder.diff(vp, updated);
    assertEquals(3, diffResult.getNumberOfDiffs());
}

From source file:org.openmrs.module.sync.SyncUtilTest.java

@Test
public void getSetterMethod_shouldReturnMethodForPrimitiveFloat() {
    Method m = SyncUtil.getSetterMethod(new Xform().getClass(), "floatField", new Float(1).getClass());
    Assert.notNull(m);//from ww w . j  a va2 s  .  c  o  m
}

From source file:jp.co.acroquest.endosnipe.report.converter.util.calc.FloatCalculator.java

public Object mul(Object obj1, Object obj2) {
    Float floatData1 = (Float) obj1;
    Float floatData2 = (Float) obj2;

    return (Object) (new Float((float) (floatData1.floatValue() * floatData2.floatValue())));
}