Example usage for java.lang Float valueOf

List of usage examples for java.lang Float valueOf

Introduction

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

Prototype

@HotSpotIntrinsicCandidate
public static Float valueOf(float f) 

Source Link

Document

Returns a Float instance representing the specified float value.

Usage

From source file:com.funzio.pure2D.ui.vo.FontVO.java

public TextOptions createTextOptions(final UIManager manager) {
    final TextOptions options = TextOptions.getDefault();

    options.id = name;//from   w ww  .  j a  va  2  s . co  m
    options.inCharacters = manager.evalString(characters);
    options.inMipmaps = texture_mipmaps;

    try {
        options.inTextPaint.setTypeface(
                Typeface.createFromAsset(manager.getContext().getAssets(), manager.evalString(typeface)));
    } catch (Exception e) {
        // Log.e(TAG, "Creating Typeface Error: " + typeface, e);
        // fallback solution
        options.inTextPaint.setTypeface(Typeface.create(typeface, TextOptions.getTypefaceStyle(style)));
    }

    options.inTextPaint.setTextSize(Float.valueOf(manager.evalString(size)) * mScale);
    options.inTextPaint.setColor(Color.parseColor(color));

    options.inPaddingX = padding_x * mScale;
    options.inPaddingY = padding_y * mScale;

    // stroke
    final float ss = Float.valueOf(manager.evalString(stroke_size)) * mScale;
    if (ss > 0) {
        options.inStrokePaint = new TextPaint(options.inTextPaint);
        options.inStrokePaint.setColor(Color.parseColor(stroke_color));
        options.inStrokePaint.setTextSize(ss);
    }

    // shadow
    if (shadow_radius > 0) {
        if (options.inStrokePaint == null) {
            options.inStrokePaint = new TextPaint(options.inTextPaint);
        }
        options.inStrokePaint.setShadowLayer(shadow_radius * mScale, shadow_dx * mScale, shadow_dy * mScale,
                Color.parseColor(shadow_color));
    }

    return options;
}

From source file:me.rojo8399.placeholderapi.impl.utils.TypeUtils.java

@SuppressWarnings("unchecked")
public static <T> T convertPrimitive(String val, Class<T> primitiveClass) {
    val = val.toLowerCase().trim();
    if (primitiveClass.equals(char.class) || primitiveClass.equals(Character.class)) {
        return (T) (Character) val.charAt(0);
    }//from ww w .j a  va2 s.c o  m
    if (primitiveClass.equals(int.class) || primitiveClass.equals(Integer.class)) {
        return (T) Integer.valueOf(val);
    }
    if (primitiveClass.equals(long.class) || primitiveClass.equals(Long.class)) {
        return (T) Long.valueOf(val);
    }
    if (primitiveClass.equals(short.class) || primitiveClass.equals(Short.class)) {
        return (T) Short.valueOf(val);
    }
    if (primitiveClass.equals(byte.class) || primitiveClass.equals(Byte.class)) {
        return (T) Byte.valueOf(val);
    }
    if (primitiveClass.equals(double.class) || primitiveClass.equals(Double.class)) {
        return (T) Double.valueOf(val);
    }
    if (primitiveClass.equals(float.class) || primitiveClass.equals(Float.class)) {
        return (T) Float.valueOf(val);
    }
    if (primitiveClass.equals(boolean.class) || primitiveClass.equals(Boolean.class)) {
        return (T) (Boolean) isTrue(val);
    }
    throw new IllegalArgumentException("Class is not primitive or a wrapper!");
}

From source file:de.zib.gndms.kit.network.NetworkAuxiliariesProvider.java

/**
 * Calculated the transfertime in milli-seconds.
 *
 * To catch possible rounding errors, which may occur when the transfer size is to small and the connection is
 * very fast. A minimal value for the transfer time can be provided (see the <EM>min</EM> parameter).
 *
 * @param size The transfer file size in byte.
 * @param bandWidth The bandwidth in byte/s
 * @param min The minimum time which is returned if the calculated time is smaller.
 *            If min is < 1 it will be ignored.
 *
 * @return The transfer-time in ms.//  w  ww . ja  v  a2s  .  c  o m
 */
public static long calculateTransferTime(long size, float bandWidth, int min) {

    long tt = Float.valueOf(size * 1000 / bandWidth).longValue();

    if (min > 0 && tt < min)
        tt = min;

    return tt;
}

From source file:cz.babi.desktop.remoteme.common.Controller.java

/**
 * Mouse wheel.//from  www  .  ja  v  a 2  s .com
 * @param addInfo Wheel amout.
 */
public void mouseWheel(String addInfo) {
    if (Common.DEBUG)
        LOGGER.debug("[mouseWheel]");

    float wheelAmount = Float.valueOf(addInfo);
    if (Common.DEBUG)
        LOGGER.debug("[mouseWheel][" + wheelAmount + "]");
    robot.mouseWheel(((int) wheelAmount * -1));
}

From source file:com.fjn.helper.common.io.file.common.FileUpAndDownloadUtil.java

/**
 * ???????//from   w w w  .  j ava  2 s .  co  m
 * @param klass   ???klass?Class
 * @param filepath   ?
 * @param sizeThreshold   ??
 * @param isFileNameBaseTime   ????
 * @return bean
 */
public static <T> Object upload(HttpServletRequest request, Class<T> klass, String filepath, int sizeThreshold,
        boolean isFileNameBaseTime) throws Exception {
    FileItemFactory fileItemFactory = null;
    if (sizeThreshold > 0) {
        File repository = new File(filepath);
        fileItemFactory = new DiskFileItemFactory(sizeThreshold, repository);
    } else {
        fileItemFactory = new DiskFileItemFactory();
    }
    ServletFileUpload upload = new ServletFileUpload(fileItemFactory);
    ServletRequestContext requestContext = new ServletRequestContext(request);
    T bean = null;
    if (klass != null) {
        bean = klass.newInstance();
    }
    // 
    if (ServletFileUpload.isMultipartContent(requestContext)) {
        File parentDir = new File(filepath);

        List<FileItem> fileItemList = upload.parseRequest(requestContext);
        for (int i = 0; i < fileItemList.size(); i++) {
            FileItem item = fileItemList.get(i);
            // ??
            if (item.isFormField()) {
                String paramName = item.getFieldName();
                String paramValue = item.getString("UTF-8");
                log.info("?" + paramName + "=" + paramValue);
                request.setAttribute(paramName, paramValue);
                // ?bean
                if (klass != null) {
                    Field field = null;
                    try {
                        field = klass.getDeclaredField(paramName);

                        if (field != null) {
                            field.setAccessible(true);
                            Class type = field.getType();
                            if (type == Integer.TYPE) {
                                field.setInt(bean, Integer.valueOf(paramValue));
                            } else if (type == Double.TYPE) {
                                field.setDouble(bean, Double.valueOf(paramValue));
                            } else if (type == Float.TYPE) {
                                field.setFloat(bean, Float.valueOf(paramValue));
                            } else if (type == Boolean.TYPE) {
                                field.setBoolean(bean, Boolean.valueOf(paramValue));
                            } else if (type == Character.TYPE) {
                                field.setChar(bean, paramValue.charAt(0));
                            } else if (type == Long.TYPE) {
                                field.setLong(bean, Long.valueOf(paramValue));
                            } else if (type == Short.TYPE) {
                                field.setShort(bean, Short.valueOf(paramValue));
                            } else {
                                field.set(bean, paramValue);
                            }
                        }
                    } catch (NoSuchFieldException e) {
                        log.info("" + klass.getName() + "?" + paramName);
                    }
                }
            }
            // 
            else {
                // <input type='file' name='xxx'> xxx
                String paramName = item.getFieldName();
                log.info("?" + item.getSize());

                if (sizeThreshold > 0) {
                    if (item.getSize() > sizeThreshold)
                        continue;
                }
                String clientFileName = item.getName();
                int index = -1;
                // ?IE?
                if ((index = clientFileName.lastIndexOf("\\")) != -1) {
                    clientFileName = clientFileName.substring(index + 1);
                }
                if (clientFileName == null || "".equals(clientFileName))
                    continue;

                String filename = null;
                log.info("" + paramName + "\t??" + clientFileName);
                if (isFileNameBaseTime) {
                    filename = buildFileName(clientFileName);
                } else
                    filename = clientFileName;

                request.setAttribute(paramName, filename);

                // ?bean
                if (klass != null) {
                    Field field = null;
                    try {
                        field = klass.getDeclaredField(paramName);
                        if (field != null) {
                            field.setAccessible(true);
                            field.set(bean, filename);
                        }
                    } catch (NoSuchFieldException e) {
                        log.info("" + klass.getName() + "?  " + paramName);
                        continue;
                    }
                }

                if (!parentDir.exists()) {
                    parentDir.mkdirs();
                }

                File newfile = new File(parentDir, filename);
                item.write(newfile);
                String serverPath = newfile.getPath();
                log.info("?" + serverPath);
            }
        }
    }
    return bean;
}

From source file:com.ewcms.common.query.jpa.QueryInit.java

private void insertCertificate() throws IOException {
    Insert<Certificate> insert = new Insert<Certificate>("certificate.csv", getJpaTemplate());
    final JpaTemplate jpaTemplate = this.getJpaTemplate();
    insert.insert(new InsertCallback<Certificate>() {
        @Override/*from  w w w . j a v a2  s  .c om*/
        public Certificate mapping(String line) {
            String[] array = line.split(",");
            Certificate c = new Certificate();
            c.setId(array[0]);
            c.setName(array[1]);
            c.setLimit(Float.valueOf(array[4]).intValue());
            c.setSex(jpaTemplate.getReference(Sex.class, Integer.valueOf(array[2])));
            try {
                c.setBrithdate(format.parse(array[3]));
            } catch (ParseException e) {
                e.printStackTrace();
            }
            return c;
        }
    });
}

From source file:net.iaeste.iws.core.transformers.CSVTransformer.java

static void transformFloat(final Map<String, String> errors, final Verifiable obj, final OfferFields field,
        final CSVRecord record) {
    final String value = record.get(field.getField());

    if ((value != null) && !value.isEmpty()) {
        try {//from   ww w.ja  va 2  s.c  o m
            final Float number = Float.valueOf(value);
            invokeMethodOnObject(errors, obj, field, number);
        } catch (NumberFormatException e) {
            LOG.debug(e.getMessage(), e);
            errors.put(field.getField(), e.getMessage());
        }
    }
}

From source file:com.segment.analytics.internal.Utils.java

/**
 * Returns the float representation at {@code value} if it exists and is a float or can be
 * coerced/*from  w  w w . j av  a 2  s.c  om*/
 * to a float. Returns {@code defaultValue} otherwise.
 */
public static float coerceToFloat(Object value, float defaultValue) {
    if (value instanceof Float) {
        return (float) value;
    }
    if (value instanceof Number) {
        return ((Number) value).floatValue();
    } else if (value instanceof String) {
        try {
            return Float.valueOf((String) value);
        } catch (NumberFormatException ignored) {
        }
    }
    return defaultValue;
}

From source file:com.alibaba.doris.admin.service.impl.ValueParseUtil.java

/**
 * ?String ?:/*from w w  w  . j a  va  2  s .  co  m*/
 * 
 * <pre>
 * short, int, long, float : 0
 * char, byte: 0
 * String: null
 * Map, List: null
 * Integer, Long, Float : null
 * Date: null
 * array: null
 * </pre>
 * 
 * @param strValue
 * @param clazz
 * @return
 */
@SuppressWarnings("unchecked")
public static <T> T parseStringValue(String strValue, Class<T> clazz, boolean autoDefault) {

    if (DEF_NULL.equals(strValue)) {
        if (!clazz.isPrimitive()) {
            return null;
        }
        if (autoDefault) {
            return (T) getInternalDefaultValue(clazz);
        } else {
            return null;
        }
    }

    if (DEF_EMPTY.equals(strValue)) {
        if (clazz.isArray()) {
            return (T) Array.newInstance(clazz.getComponentType(), 0);
        }

        if (Map.class.isAssignableFrom(clazz)) {
            return (T) Collections.EMPTY_MAP;
        }

        if (List.class.isAssignableFrom(clazz)) {
            return (T) new ArrayList<Object>();
        }

        if (Set.class.isAssignableFrom(clazz)) {
            return (T) new HashSet<Object>();
        }

        if (String.class.equals(clazz)) {
            return (T) StringUtils.EMPTY;
        }

        if (Character.TYPE.equals(clazz) || Character.class.equals(clazz)) {
            return (T) Character.valueOf(' ');
        }

        if (autoDefault) {
            return (T) getInternalDefaultValue(clazz);
        } else {
            return null;
        }
    }

    if (StringUtils.isBlank(strValue)) {// ?
        if (autoDefault) {
            return (T) getInternalDefaultValue(clazz);
        } else {
            return null;
        }
    } else {

        if (String.class.equals(clazz)) {
            return (T) strValue;
        }

        if (Short.TYPE.equals(clazz) || Short.class.equals(clazz)) {
            return (T) Short.valueOf(strValue);
        }

        if (Integer.TYPE.equals(clazz) || Integer.class.equals(clazz)) {
            return (T) Integer.valueOf(strValue);
        }
        if (Long.TYPE.equals(clazz) || Long.class.equals(clazz)) {
            return (T) Long.valueOf(strValue);
        }
        if (Boolean.TYPE.equals(clazz) || Boolean.class.equals(clazz)) {
            return (T) Boolean.valueOf(strValue);
        }
        if (Float.TYPE.equals(clazz) || Float.class.equals(clazz)) {
            return (T) Float.valueOf(strValue);
        }
        if (Double.TYPE.equals(clazz) || Double.class.equals(clazz)) {
            return (T) Double.valueOf(strValue);
        }
        if (Byte.TYPE.equals(clazz) || Byte.class.equals(clazz)) {
            return (T) Byte.valueOf(strValue);
        }
        if (Character.TYPE.equals(clazz) || Character.class.equals(clazz)) {
            return (T) Character.valueOf(strValue.charAt(0));
        }

        if (clazz.isArray()) {
            final Class<?> componentType = clazz.getComponentType();
            // String[]
            if (String.class.equals(componentType)) {
                return (T) StringUtils.split(strValue, ',');
            }
            // ?char[]
            if (Character.TYPE.equals(componentType)) {
                return (T) strValue.toCharArray();
            }

            if (Character.class.equals(componentType)) {
                final char[] tmp = strValue.toCharArray();
                final Character[] result = new Character[tmp.length];
                for (int i = 0; i < result.length; i++) {
                    result[i] = tmp[i];
                }
                return (T) result;
            }

            if (Byte.TYPE.equals(componentType) || Byte.class.equals(componentType)) {
                return (T) (strValue == null ? null : strValue.getBytes());
            }
        }
    }

    return null;

}

From source file:business.security.control.OwmClient.java

/**
 * Find current weather around a geographic point
 *
 * @param lat is the latitude of the geographic point of interest
 * (North/South coordinate)/*  w  ww  .j  ava  2s  . c  o  m*/
 * @param lon is the longitude of the geographic point of interest
 * (East/West coordinate)
 * @param cnt is the requested number of weather stations to retrieve (the
 * actual answer might be less than the requested).
 * @throws JSONException if the response from the OWM server can't be parsed
 * @throws IOException if there's some network error or the OWM server
 * replies with a error.
 */
public WeatherStatusResponse currentWeatherAroundPoint(float lat, float lon, int cnt)
        throws IOException, JSONException { //, boolean cluster, OwmClient.Lang lang) {
    String subUrl = String.format(Locale.ROOT, "find/station?lat=%f&lon=%f&cnt=%d&cluster=yes",
            Float.valueOf(lat), Float.valueOf(lon), Integer.valueOf(cnt));
    JSONObject response = doQuery(subUrl);
    return new WeatherStatusResponse(response);
}