Example usage for java.lang Float MAX_VALUE

List of usage examples for java.lang Float MAX_VALUE

Introduction

In this page you can find the example usage for java.lang Float MAX_VALUE.

Prototype

float MAX_VALUE

To view the source code for java.lang Float MAX_VALUE.

Click Source Link

Document

A constant holding the largest positive finite value of type float , (2-2-23)·2127.

Usage

From source file:net.sf.juffrou.reflect.spring.BeanWrapperTests.java

@Test
public void testSetNumberProperties() {
    NumberPropertyBean bean = new NumberPropertyBean();
    BeanWrapper bw = new JuffrouSpringBeanWrapper(bean);

    String byteValue = " " + Byte.MAX_VALUE + " ";
    String shortValue = " " + Short.MAX_VALUE + " ";
    String intValue = " " + Integer.MAX_VALUE + " ";
    String longValue = " " + Long.MAX_VALUE + " ";
    String floatValue = " " + Float.MAX_VALUE + " ";
    String doubleValue = " " + Double.MAX_VALUE + " ";

    bw.setPropertyValue("myPrimitiveByte", byteValue);
    bw.setPropertyValue("myByte", byteValue);

    bw.setPropertyValue("myPrimitiveShort", shortValue);
    bw.setPropertyValue("myShort", shortValue);

    bw.setPropertyValue("myPrimitiveInt", intValue);
    bw.setPropertyValue("myInteger", intValue);

    bw.setPropertyValue("myPrimitiveLong", longValue);
    bw.setPropertyValue("myLong", longValue);

    bw.setPropertyValue("myPrimitiveFloat", floatValue);
    bw.setPropertyValue("myFloat", floatValue);

    bw.setPropertyValue("myPrimitiveDouble", doubleValue);
    bw.setPropertyValue("myDouble", doubleValue);

    assertEquals(Byte.MAX_VALUE, bean.getMyPrimitiveByte());
    assertEquals(Byte.MAX_VALUE, bean.getMyByte().byteValue());

    assertEquals(Short.MAX_VALUE, bean.getMyPrimitiveShort());
    assertEquals(Short.MAX_VALUE, bean.getMyShort().shortValue());

    assertEquals(Integer.MAX_VALUE, bean.getMyPrimitiveInt());
    assertEquals(Integer.MAX_VALUE, bean.getMyInteger().intValue());

    assertEquals(Long.MAX_VALUE, bean.getMyPrimitiveLong());
    assertEquals(Long.MAX_VALUE, bean.getMyLong().longValue());

    assertEquals(Float.MAX_VALUE, bean.getMyPrimitiveFloat(), 0.001);
    assertEquals(Float.MAX_VALUE, bean.getMyFloat().floatValue(), 0.001);

    assertEquals(Double.MAX_VALUE, bean.getMyPrimitiveDouble(), 0.001);
    assertEquals(Double.MAX_VALUE, bean.getMyDouble().doubleValue(), 0.001);

}

From source file:org.eclipse.january.dataset.DatasetUtils.java

/**
 * Make floating point datasets contain only finite values. Infinities and NaNs are replaced
 * by +/- MAX_VALUE and 0, respectively.
 * All other dataset types are ignored.// www.  j  a  va  2s.  c o  m
 * 
 * @param a dataset
 */
public static void makeFinite(Dataset a) {
    if (a instanceof DoubleDataset) {
        final DoubleDataset set = (DoubleDataset) a;
        final IndexIterator it = set.getIterator();
        final double[] data = set.getData();
        while (it.hasNext()) {
            final double x = data[it.index];
            if (Double.isNaN(x))
                data[it.index] = 0;
            else if (Double.isInfinite(x))
                data[it.index] = x > 0 ? Double.MAX_VALUE : -Double.MAX_VALUE;
        }
    } else if (a instanceof FloatDataset) {
        final FloatDataset set = (FloatDataset) a;
        final IndexIterator it = set.getIterator();
        final float[] data = set.getData();
        while (it.hasNext()) {
            final float x = data[it.index];
            if (Float.isNaN(x))
                data[it.index] = 0;
            else if (Float.isInfinite(x))
                data[it.index] = x > 0 ? Float.MAX_VALUE : -Float.MAX_VALUE;
        }
    } else if (a instanceof CompoundDoubleDataset) {
        final CompoundDoubleDataset set = (CompoundDoubleDataset) a;
        final int is = set.getElementsPerItem();
        final IndexIterator it = set.getIterator();
        final double[] data = set.getData();
        while (it.hasNext()) {
            for (int j = 0; j < is; j++) {
                final double x = data[it.index + j];
                if (Double.isNaN(x))
                    data[it.index + j] = 0;
                else if (Double.isInfinite(x))
                    data[it.index + j] = x > 0 ? Double.MAX_VALUE : -Double.MAX_VALUE;
            }
        }
    } else if (a instanceof CompoundFloatDataset) {
        final CompoundFloatDataset set = (CompoundFloatDataset) a;
        final int is = set.getElementsPerItem();
        final IndexIterator it = set.getIterator();
        final float[] data = set.getData();
        while (it.hasNext()) {
            for (int j = 0; j < is; j++) {
                final float x = data[it.index + j];
                if (Float.isNaN(x))
                    data[it.index + j] = 0;
                else if (Float.isInfinite(x))
                    data[it.index + j] = x > 0 ? Float.MAX_VALUE : -Float.MAX_VALUE;
            }
        }
    }
}

From source file:au.org.ala.layers.intersect.Grid.java

/**
 * @return calculated min and max values of a grid file as float [] where [0] is min and [1] is max.
 *///from w w w.  ja v a 2s  . c om
public float[] calculatetMinMax() {

    float[] ret = new float[2];
    ret[0] = Float.MAX_VALUE;
    ret[1] = Float.MAX_VALUE * -1;

    long i;
    int size;
    byte[] b;
    RandomAccessFile afile = null;

    try { //read of random access file can throw an exception
        File f2 = new File(filename + ".GRI");
        if (!f2.exists()) {
            afile = new RandomAccessFile(filename + ".gri", "r");
        } else {
            afile = new RandomAccessFile(filename + ".GRI", "r");
        }

        long length = ((long) nrows) * ((long) ncols);
        float f;

        if (datatype.equalsIgnoreCase("BYTE")) {
            size = 1;
            b = new byte[size];
            for (i = 0; i < length; i++) {
                f = afile.readByte();
                if (f != (float) nodatavalue) {
                    ret[0] = Math.min(f * rescale, ret[0]);
                    ret[1] = Math.max(f * rescale, ret[1]);
                }
            }
        } else if (datatype.equalsIgnoreCase("UBYTE")) {
            size = 1;
            b = new byte[size];
            for (i = 0; i < length; i++) {
                f = afile.readByte();
                if (f < 0) {
                    f += 256;
                }
                if (f != (float) nodatavalue) {
                    ret[0] = Math.min(f * rescale, ret[0]);
                    ret[1] = Math.max(f * rescale, ret[1]);
                }
            }
        } else if (datatype.equalsIgnoreCase("SHORT")) {
            size = 2;
            b = new byte[size];
            for (i = 0; i < length; i++) {
                afile.read(b);
                if (byteorderLSB) {
                    f = (short) (((0xFF & b[1]) << 8) | (b[0] & 0xFF));
                } else {
                    f = (short) (((0xFF & b[0]) << 8) | (b[1] & 0xFF));
                }
                if (f != (float) nodatavalue) {
                    ret[0] = Math.min(f * rescale, ret[0]);
                    ret[1] = Math.max(f * rescale, ret[1]);
                }
            }
        } else if (datatype.equalsIgnoreCase("INT")) {
            size = 4;
            b = new byte[size];
            for (i = 0; i < length; i++) {
                afile.read(b);
                if (byteorderLSB) {
                    f = ((0xFF & b[3]) << 24) | ((0xFF & b[2]) << 16) + ((0xFF & b[1]) << 8) + (b[0] & 0xFF);
                } else {
                    f = ((0xFF & b[0]) << 24)
                            | ((0xFF & b[1]) << 16) + ((0xFF & b[2]) << 8) + ((0xFF & b[3]) & 0xFF);
                }
                if (f != (float) nodatavalue) {
                    ret[0] = Math.min(f * rescale, ret[0]);
                    ret[1] = Math.max(f * rescale, ret[1]);
                }
            }
        } else if (datatype.equalsIgnoreCase("LONG")) {
            size = 8;
            b = new byte[size];
            for (i = 0; i < length; i++) {
                afile.read(b);
                if (byteorderLSB) {
                    f = ((long) (0xFF & b[7]) << 56) + ((long) (0xFF & b[6]) << 48)
                            + ((long) (0xFF & b[5]) << 40) + ((long) (0xFF & b[4]) << 32)
                            + ((long) (0xFF & b[3]) << 24) + ((long) (0xFF & b[2]) << 16)
                            + ((long) (0xFF & b[1]) << 8) + (0xFF & b[0]);
                } else {
                    f = ((long) (0xFF & b[0]) << 56) + ((long) (0xFF & b[1]) << 48)
                            + ((long) (0xFF & b[2]) << 40) + ((long) (0xFF & b[3]) << 32)
                            + ((long) (0xFF & b[4]) << 24) + ((long) (0xFF & b[5]) << 16)
                            + ((long) (0xFF & b[6]) << 8) + (0xFF & b[7]);
                }
                if (f != (float) nodatavalue) {
                    ret[0] = Math.min(f * rescale, ret[0]);
                    ret[1] = Math.max(f * rescale, ret[1]);
                }
            }
        } else if (datatype.equalsIgnoreCase("FLOAT")) {
            size = 4;
            b = new byte[size];
            for (i = 0; i < length; i++) {
                afile.read(b);
                ByteBuffer bb = ByteBuffer.wrap(b);
                if (byteorderLSB) {
                    bb.order(ByteOrder.LITTLE_ENDIAN);
                }
                f = bb.getFloat();
                if (f != (float) nodatavalue) {
                    ret[0] = Math.min(f * rescale, ret[0]);
                    ret[1] = Math.max(f * rescale, ret[1]);
                }
            }
        } else if (datatype.equalsIgnoreCase("DOUBLE")) {
            size = 8;
            b = new byte[8];
            for (i = 0; i < length; i++) {
                afile.read(b);
                ByteBuffer bb = ByteBuffer.wrap(b);
                if (byteorderLSB) {
                    bb.order(ByteOrder.LITTLE_ENDIAN);
                }
                f = (float) bb.getDouble();
                if (f != (float) nodatavalue) {
                    ret[0] = Math.min(f * rescale, ret[0]);
                    ret[1] = Math.max(f * rescale, ret[1]);
                }
            }
        } else {
            logger.error("datatype not supported in Grid.getValues: " + datatype);
        }
    } catch (Exception e) {
        logger.error("error calculating min/max of a grid file", e);
    } finally {
        if (afile != null) {
            try {
                afile.close();
            } catch (Exception e) {
                logger.error(e.getMessage(), e);
            }
        }
    }
    return ret;
}

From source file:fr.cls.atoll.motu.library.misc.netcdf.NetCdfReader.java

/**
 * Initializes all array elements vith a the value cooresponding to the FillValue attribute of a variable.
 * If the FillValue attribute doesn't exist for the variable, fillvalue is set to the max value of the
 * data type (ie max value of a double, of a float ....) and attibute FillValue is added to the variable.
 * //from ww  w .ja va  2  s  .  c  om
 * @param var variable corresponding to the data (type, FillValue attribute)
 * @param data array to initialize
 * 
 * @return the fill vlue for the array.
 * 
 * @throws MotuNotImplementedException the motu not implemented exception
 */
public static double initializeMissingData(Variable var, Array data) throws MotuNotImplementedException {

    double fillValue = Double.MAX_VALUE;
    DataType dataType = var.getDataType();

    Attribute attribute = null;
    try {
        attribute = NetCdfReader.getAttribute(var, NetCdfReader.VARIABLEATTRIBUTE_FILEVALUE);
    } catch (NetCdfAttributeNotFoundException e) {
        // Do nothing
    }

    if (dataType.equals(DataType.DOUBLE)) {
        double fillValueDouble = Double.MAX_VALUE;
        if (attribute == null) {
            attribute = new Attribute(NetCdfReader.VARIABLEATTRIBUTE_FILEVALUE, fillValueDouble);
            var.addAttribute(attribute);
        } else {
            fillValueDouble = attribute.getNumericValue().doubleValue();
        }
        fillValue = fillValueDouble;
        NetCdfReader.initializeMissingData(data, fillValueDouble);

    } else if (dataType.equals(DataType.FLOAT)) {
        float fillValueFloat = Float.MAX_VALUE;
        if (attribute == null) {
            attribute = new Attribute(NetCdfReader.VARIABLEATTRIBUTE_FILEVALUE, fillValueFloat);
            var.addAttribute(attribute);
        } else {
            fillValueFloat = attribute.getNumericValue().floatValue();
        }
        fillValue = fillValueFloat;
        NetCdfReader.initializeMissingData(data, fillValueFloat);
    } else {
        throw new MotuNotImplementedException(String.format(
                "initialization with data type %s is not implemented (NetCdrfReader - initializeMissingData",
                dataType.toString()));
    }
    return fillValue;
}

From source file:com.zyk.launcher.AsyncTaskCallback.java

private CellLayout findMatchingPageForDragOver(DragView dragView, float originX, float originY, boolean exact) {
    // We loop through all the screens (ie CellLayouts) and see which ones overlap
    // with the item being dragged and then choose the one that's closest to the touch point
    final int screenCount = getChildCount();
    CellLayout bestMatchingScreen = null;
    float smallestDistSoFar = Float.MAX_VALUE;

    for (int i = 0; i < screenCount; i++) {
        // The custom content screen is not a valid drag over option
        //            if (mScreenOrder.get(i) == Workspace.CUSTOM_CONTENT_SCREEN_ID) {
        //                continue;
        //            }

        CellLayout cl = (CellLayout) getChildAt(i);

        final float[] touchXy = { originX, originY };
        // Transform the touch coordinates to the CellLayout's local coordinates
        // If the touch point is within the bounds of the cell layout, we can return immediately
        cl.getMatrix().invert(mTempInverseMatrix);
        mDragUtils.mapPointFromSelfToChild(cl, touchXy, mTempInverseMatrix);

        if (touchXy[0] >= 0 && touchXy[0] <= cl.getWidth() && touchXy[1] >= 0 && touchXy[1] <= cl.getHeight()) {
            return cl;
        }//from w  w  w .  j  a  v a  2s.c o m

        if (!exact) {
            // Get the center of the cell layout in screen coordinates
            final float[] cellLayoutCenter = mTempCellLayoutCenterCoordinates;
            cellLayoutCenter[0] = cl.getWidth() / 2;
            cellLayoutCenter[1] = cl.getHeight() / 2;
            mDragUtils.mapPointFromChildToSelf(cl, cellLayoutCenter);

            touchXy[0] = originX;
            touchXy[1] = originY;

            // Calculate the distance between the center of the CellLayout
            // and the touch point
            float dist = mDragUtils.squaredDistance(touchXy, cellLayoutCenter);

            if (dist < smallestDistSoFar) {
                smallestDistSoFar = dist;
                bestMatchingScreen = cl;
            }
        }
    }
    return bestMatchingScreen;
}

From source file:com.android.launcher2.Workspace.java

private CellLayout findMatchingPageForDragOver(DragView dragView, float originX, float originY, boolean exact) {
    // We loop through all the screens (ie CellLayouts) and see which ones overlap
    // with the item being dragged and then choose the one that's closest to the touch point
    final int screenCount = getChildCount();
    CellLayout bestMatchingScreen = null;
    float smallestDistSoFar = Float.MAX_VALUE;

    for (int i = 0; i < screenCount; i++) {
        CellLayout cl = (CellLayout) getChildAt(i);

        final float[] touchXy = { originX, originY };
        // Transform the touch coordinates to the CellLayout's local coordinates
        // If the touch point is within the bounds of the cell layout, we can return immediately
        cl.getMatrix().invert(mTempInverseMatrix);
        mapPointFromSelfToChild(cl, touchXy, mTempInverseMatrix);

        if (touchXy[0] >= 0 && touchXy[0] <= cl.getWidth() && touchXy[1] >= 0 && touchXy[1] <= cl.getHeight()) {
            return cl;
        }/*www  . ja  v a 2s . c  om*/

        if (!exact) {
            // Get the center of the cell layout in screen coordinates
            final float[] cellLayoutCenter = mTempCellLayoutCenterCoordinates;
            cellLayoutCenter[0] = cl.getWidth() / 2;
            cellLayoutCenter[1] = cl.getHeight() / 2;
            mapPointFromChildToSelf(cl, cellLayoutCenter);

            touchXy[0] = originX;
            touchXy[1] = originY;

            // Calculate the distance between the center of the CellLayout
            // and the touch point
            float dist = squaredDistance(touchXy, cellLayoutCenter);

            if (dist < smallestDistSoFar) {
                smallestDistSoFar = dist;
                bestMatchingScreen = cl;
            }
        }
    }
    return bestMatchingScreen;
}

From source file:cc.flydev.launcher.Workspace.java

private CellLayout findMatchingPageForDragOver(DragView dragView, float originX, float originY, boolean exact) {
    // We loop through all the screens (ie CellLayouts) and see which ones overlap
    // with the item being dragged and then choose the one that's closest to the touch point
    final int screenCount = getChildCount();
    CellLayout bestMatchingScreen = null;
    float smallestDistSoFar = Float.MAX_VALUE;

    for (int i = 0; i < screenCount; i++) {
        // The custom content screen is not a valid drag over option
        if (mScreenOrder.get(i) == CUSTOM_CONTENT_SCREEN_ID) {
            continue;
        }/*from   w ww  . jav a  2 s .c  om*/

        CellLayout cl = (CellLayout) getChildAt(i);

        final float[] touchXy = { originX, originY };
        // Transform the touch coordinates to the CellLayout's local coordinates
        // If the touch point is within the bounds of the cell layout, we can return immediately
        cl.getMatrix().invert(mTempInverseMatrix);
        mapPointFromSelfToChild(cl, touchXy, mTempInverseMatrix);

        if (touchXy[0] >= 0 && touchXy[0] <= cl.getWidth() && touchXy[1] >= 0 && touchXy[1] <= cl.getHeight()) {
            return cl;
        }

        if (!exact) {
            // Get the center of the cell layout in screen coordinates
            final float[] cellLayoutCenter = mTempCellLayoutCenterCoordinates;
            cellLayoutCenter[0] = cl.getWidth() / 2;
            cellLayoutCenter[1] = cl.getHeight() / 2;
            mapPointFromChildToSelf(cl, cellLayoutCenter);

            touchXy[0] = originX;
            touchXy[1] = originY;

            // Calculate the distance between the center of the CellLayout
            // and the touch point
            float dist = squaredDistance(touchXy, cellLayoutCenter);

            if (dist < smallestDistSoFar) {
                smallestDistSoFar = dist;
                bestMatchingScreen = cl;
            }
        }
    }
    return bestMatchingScreen;
}

From source file:com.aidy.launcher3.ui.workspace.Workspace.java

private CellLayout findMatchingPageForDragOver(DragView dragView, float originX, float originY, boolean exact) {
    // We loop through all the screens (ie CellLayouts) and see which ones
    // overlap/*from  ww w.  j  a  va 2s. co m*/
    // with the item being dragged and then choose the one that's closest to
    // the touch point
    final int screenCount = getChildCount();
    CellLayout bestMatchingScreen = null;
    float smallestDistSoFar = Float.MAX_VALUE;

    for (int i = 0; i < screenCount; i++) {
        // The custom content screen is not a valid drag over option
        if (mScreenOrder.get(i) == CUSTOM_CONTENT_SCREEN_ID) {
            continue;
        }

        CellLayout cl = (CellLayout) getChildAt(i);

        final float[] touchXy = { originX, originY };
        // Transform the touch coordinates to the CellLayout's local
        // coordinates
        // If the touch point is within the bounds of the cell layout, we
        // can return immediately
        cl.getMatrix().invert(mTempInverseMatrix);
        mapPointFromSelfToChild(cl, touchXy, mTempInverseMatrix);

        if (touchXy[0] >= 0 && touchXy[0] <= cl.getWidth() && touchXy[1] >= 0 && touchXy[1] <= cl.getHeight()) {
            return cl;
        }

        if (!exact) {
            // Get the center of the cell layout in screen coordinates
            final float[] cellLayoutCenter = mTempCellLayoutCenterCoordinates;
            cellLayoutCenter[0] = cl.getWidth() / 2;
            cellLayoutCenter[1] = cl.getHeight() / 2;
            mapPointFromChildToSelf(cl, cellLayoutCenter);

            touchXy[0] = originX;
            touchXy[1] = originY;

            // Calculate the distance between the center of the CellLayout
            // and the touch point
            float dist = squaredDistance(touchXy, cellLayoutCenter);

            if (dist < smallestDistSoFar) {
                smallestDistSoFar = dist;
                bestMatchingScreen = cl;
            }
        }
    }
    return bestMatchingScreen;
}

From source file:ca.oson.json.Oson.java

private <E, R> Float json2Float(FieldData objectDTO) {
    if (objectDTO == null || !objectDTO.json2Java) {
        return null;
    }/* ww  w  . j av  a  2 s.  c  o m*/

    E value = (E) objectDTO.valueToProcess;
    Class<R> returnType = objectDTO.returnType;

    if (value != null && value.toString().trim().length() > 0) {
        String valueToProcess = value.toString().trim();
        Float valueToReturn = null;

        try {
            Function function = objectDTO.getDeserializer();

            if (function != null) {
                try {
                    Object returnedValue = null;

                    if (function instanceof Json2DataMapperFunction) {
                        DataMapper classData = new DataMapper(returnType, value, objectDTO.classMapper,
                                objectDTO.level, getPrettyIndentation());
                        returnedValue = ((Json2DataMapperFunction) function).apply(classData);

                    } else if (function instanceof Json2FieldDataFunction) {
                        Json2FieldDataFunction f = (Json2FieldDataFunction) function;
                        FieldData fieldData = objectDTO.clone();

                        returnedValue = f.apply(fieldData);

                    } else if (function instanceof Json2FloatFunction) {
                        return ((Json2FloatFunction) function).apply(valueToProcess);
                    } else {
                        returnedValue = function.apply(valueToProcess);
                    }

                    if (returnedValue instanceof Optional) {
                        returnedValue = ObjectUtil.unwrap(returnedValue);
                    }

                    if (returnedValue == null) {
                        return null;

                    } else if (Number.class.isAssignableFrom(returnedValue.getClass())
                            || returnedValue.getClass().isPrimitive()) {

                        if (returnedValue instanceof Float) {
                            valueToReturn = (Float) returnedValue;
                        } else if (returnedValue instanceof String) {
                            valueToReturn = Float.parseFloat((String) returnedValue);

                        } else if (returnedValue instanceof Integer) {
                            valueToReturn = ((Integer) returnedValue).floatValue();
                        } else if (returnedValue instanceof Long) {
                            valueToReturn = ((Long) returnedValue).floatValue();
                        } else if (returnedValue instanceof Short) {
                            valueToReturn = ((Short) returnedValue).floatValue();
                        } else if (returnedValue instanceof Double) {
                            valueToReturn = ((Double) returnedValue).floatValue();
                        } else if (returnedValue instanceof Byte) {
                            valueToReturn = ((Byte) returnedValue).floatValue();
                        } else if (returnedValue instanceof BigInteger) {
                            valueToReturn = ((BigInteger) returnedValue).floatValue();
                        } else if (returnedValue instanceof BigDecimal) {
                            valueToReturn = ((BigDecimal) returnedValue).floatValue();
                        } else if (returnedValue instanceof AtomicInteger) {
                            valueToReturn = ((AtomicInteger) returnedValue).floatValue();
                        } else if (returnedValue instanceof AtomicLong) {
                            valueToReturn = ((AtomicLong) returnedValue).floatValue();
                        } else {
                            valueToReturn = ((Number) returnedValue).floatValue();
                        }

                    } else if (returnedValue instanceof Character) {
                        char c = (Character) returnedValue;
                        valueToReturn = (float) c;

                    } else if (returnedValue instanceof Boolean) {
                        if ((Boolean) returnedValue)
                            valueToReturn = 1f;
                        else
                            valueToReturn = 0f;

                    } else if (Enum.class.isAssignableFrom(returnedValue.getClass())) {
                        valueToReturn = ((Integer) ((Enum) returnedValue).ordinal()).floatValue();

                    } else if (Date.class.isAssignableFrom(returnedValue.getClass())) {
                        valueToReturn = (float) ((Date) returnedValue).getTime();

                    } else {
                        valueToReturn = Float.parseFloat(returnedValue.toString());
                    }

                    return valueToReturn;

                } catch (Exception e) {
                    e.printStackTrace();
                }

            } else {
                double doubleValue = Double.parseDouble(valueToProcess);

                if (doubleValue > Float.MAX_VALUE) {
                    valueToReturn = Float.MAX_VALUE;
                } else {
                    valueToReturn = (float) doubleValue;
                }

                // valueToReturn = Float.parseFloat(valueToProcess);
            }

            if (valueToReturn != null) {
                Long min = objectDTO.getMin();
                Long max = objectDTO.getMax();

                if (min != null && min.floatValue() > valueToReturn) {
                    return min.floatValue();
                }

                if (max != null && max.floatValue() < valueToReturn) {
                    valueToReturn = max.floatValue();
                }

                return valueToReturn;
            }

        } catch (Exception ex) {
            //ex.printStackTrace();
        }

    }

    return json2FloatDefault(objectDTO);
}

From source file:com.zyk.launcher.Workspace.java

/**
 * This method returns the CellLayout that is currently being dragged to. In order to drag
 * to a CellLayout, either the touch point must be directly over the CellLayout, or as a second
 * strategy, we see if the dragView is overlapping any CellLayout and choose the closest one
 *
 * Return null if no CellLayout is currently being dragged over
 *
 *//*from   w w  w  . j a  v  a 2  s  .  c o m*/
private CellLayout findMatchingPageForDragOver(DragView dragView, float originX, float originY, boolean exact) {
    // We loop through all the screens (ie CellLayouts) and see which ones overlap
    // with the item being dragged and then choose the one that's closest to the touch point
    final int screenCount = getChildCount();
    CellLayout bestMatchingScreen = null;
    float smallestDistSoFar = Float.MAX_VALUE;

    for (int i = 0; i < screenCount; i++) {
        // The custom content screen is not a valid drag over option
        if (mScreenOrder.get(i) == CUSTOM_CONTENT_SCREEN_ID) {
            continue;
        }

        CellLayout cl = (CellLayout) getChildAt(i);

        final float[] touchXy = { originX, originY };
        // Transform the touch coordinates to the CellLayout's local coordinates
        // If the touch point is within the bounds of the cell layout, we can return immediately
        cl.getMatrix().invert(mTempInverseMatrix);
        mDragUtils.mapPointFromSelfToChild(cl, touchXy, mTempInverseMatrix);

        if (touchXy[0] >= 0 && touchXy[0] <= cl.getWidth() && touchXy[1] >= 0 && touchXy[1] <= cl.getHeight()) {
            return cl;
        }

        if (!exact) {
            // Get the center of the cell layout in screen coordinates
            final float[] cellLayoutCenter = mTempCellLayoutCenterCoordinates;
            cellLayoutCenter[0] = cl.getWidth() / 2;
            cellLayoutCenter[1] = cl.getHeight() / 2;
            mDragUtils.mapPointFromChildToSelf(cl, cellLayoutCenter);

            touchXy[0] = originX;
            touchXy[1] = originY;

            // Calculate the distance between the center of the CellLayout
            // and the touch point
            float dist = mDragUtils.squaredDistance(touchXy, cellLayoutCenter);

            if (dist < smallestDistSoFar) {
                smallestDistSoFar = dist;
                bestMatchingScreen = cl;
            }
        }
    }
    return bestMatchingScreen;
}