Example usage for org.apache.commons.lang.math NumberUtils toFloat

List of usage examples for org.apache.commons.lang.math NumberUtils toFloat

Introduction

In this page you can find the example usage for org.apache.commons.lang.math NumberUtils toFloat.

Prototype

public static float toFloat(String str, float defaultValue) 

Source Link

Document

Convert a String to a float, returning a default value if the conversion fails.

If the string str is null, the default value is returned.

 NumberUtils.toFloat(null, 1.1f)   = 1.0f NumberUtils.toFloat("", 1.1f)     = 1.1f NumberUtils.toFloat("1.5", 0.0f)  = 1.5f 

Usage

From source file:com.cloud.utils.NumbersUtil.java

public static float parseFloat(String s, float defaultValue) {
    return NumberUtils.toFloat(s, defaultValue);
}

From source file:com.fengduo.bee.commons.util.NumberParser.java

public static float parseFloat(String data, float defaultValue) {
    if (StringUtils.isBlank(data)) {
        return defaultValue;
    }/*from   w w  w.j a v a  2s .co  m*/
    return NumberUtils.toFloat(data, defaultValue);
}

From source file:com.bstek.dorado.view.resolver.IE6PngFileResolver.java

protected Resource[] getResourcesByFileName(DoradoContext context, String resourcePrefix, String fileName,
        String resourceSuffix) throws Exception {
    String ua = context.getRequest().getHeader("User-Agent");
    if (ua.indexOf(CHROME_FRAME) < 0) {
        boolean isMSIE = (ua != null && ua.indexOf(MSIE) != -1);
        if (isMSIE) {
            float version = NumberUtils.toFloat(MSIE_VERSION_PATTERN.matcher(ua).replaceAll("$1"),
                    Float.MAX_VALUE);
            if (version < 7) {
                fileName = fileName.replace(PNG24_DIR, PNG8_DIR);
            }//  w w  w.  java2 s . co  m
        }
    }
    return super.getResourcesByFileName(context, resourcePrefix, fileName, resourceSuffix);
}

From source file:com.bstek.dorado.view.resolver.FontAwesomePngFileResolver.java

protected Resource[] getResourcesByFileName(DoradoContext context, String resourcePrefix, String fileName,
        String resourceSuffix) throws Exception {
    String ua = context.getRequest().getHeader("User-Agent");
    if (ua.indexOf(CHROME_FRAME) < 0) {
        boolean isMSIE = (ua != null && ua.indexOf(MSIE) != -1);
        if (isMSIE) {
            float version = NumberUtils.toFloat(MSIE_VERSION_PATTERN.matcher(ua).replaceAll("$1"),
                    Float.MAX_VALUE);
            if (version < 8) {
                fileName = fileName.replace(REQUEST_URI, TARGET_URI);
            }//from w  w w.  j  a  v  a2 s.  com
        }
    }
    return super.getResourcesByFileName(context, resourcePrefix, fileName, resourceSuffix);
}

From source file:com.bstek.dorado.view.resolver.OldIconsFileResolver.java

protected ResourcesWrapper createResourcesWrapper(HttpServletRequest request, DoradoContext context)
        throws Exception {
    String resourceType = PNG;//from  ww  w.  j  a v a2 s  . c  o m
    String ua = request.getHeader("User-Agent");
    if (ua.indexOf(CHROME_FRAME) < 0) {
        boolean isMSIE = (ua != null && ua.indexOf(MSIE) != -1);
        if (isMSIE) {
            float version = NumberUtils.toFloat(MSIE_VERSION_PATTERN.matcher(ua).replaceAll("$1"),
                    Float.MAX_VALUE);
            if (version < 7) {
                resourceType = GIF;
            }
        }
    }

    Resource[] resources = context.getResources(ICON_PATH + resourceType);
    return new ResourcesWrapper(resources, getResourceTypeManager().getResourceType(resourceType));
}

From source file:com.tdclighthouse.prototype.utils.MIMEParse.java

/**
 * Carves up a media range and returns a ParseResults.
 * //from  w w w . j a  v a 2 s.co m
 * For example, the media range 'application/*;q=0.5' would get parsed into:
 * 
 * ('application', '*', {'q', '0.5'})
 * 
 * In addition this function also guarantees that there is a value for 'q'
 * in the params dictionary, filling it in with a proper default if
 * necessary.
 * 
 * @param range
 */
protected static ParseResults parseMediaRange(String range) {
    ParseResults results = parseMimeType(range);
    String q = results.params.get("q");
    float f = NumberUtils.toFloat(q, 1);
    if (StringUtils.isBlank(q) || f < 0 || f > 1) {
        results.params.put("q", "1");
    }
    return results;
}

From source file:com.ctriposs.rest4j.internal.server.util.MIMEParse.java

/**
 * Carves up a media range and returns a ParseResults.
 *
 * For example, the media range 'application/*;q=0.5' would get parsed into:
 *
 * ('application', '*', {'q', '0.5'})/*from   www .  jav a2s  .  c  om*/
 *
 * In addition this function also guarantees that there is a value for 'q'
 * in the params dictionary, filling it in with a proper default if
 * necessary.
 */
protected static ParseResults parseMediaRange(String range) {
    ParseResults results = parseMimeType(range);
    String q = results.params.get("q");
    float f = NumberUtils.toFloat(q, 1);
    if (StringUtils.isBlank(q) || f < 0 || f > 1)
        results.params.put("q", "1");
    return results;
}

From source file:net.grinder.util.GrinderUtils.java

/**
 * Get the parameter passed by controller. When it's executed in the
 * validation mode, always returns the given default value 0.
 *
 * @since 3.2.3//from ww  w.  java  2 s  . c  o  m
 */
public static float getParamFloat() {
    return NumberUtils.toFloat(getParam("0"), 0f);
}

From source file:com.netsteadfast.greenstep.bsc.util.AggregationMethodUtils.java

public static float processDefaultMode(KpiVO kpi) throws Exception {
    Map<String, Object> results = getScore(kpi.getAggregationMethod().getType(),
            kpi.getAggregationMethod().getExpression1(), kpi, null);
    Object value = results.get(AggregationMethodVariable.SCORE);
    if (null == value) {
        return 0.0f;
    }/*from   w  ww  .  j  av a2  s .  c  om*/
    if (!NumberUtils.isNumber(String.valueOf(value))) {
        return 0.0f;
    }
    return NumberUtils.toFloat(String.valueOf(value), 0.0f);
}

From source file:com.edgenius.wiki.service.impl.NotificationServiceImpl.java

public void doVersionCheck() {
    HttpURLConnection conn = null;
    try {//from   w ww . ja  va  2s  .  c  o  m
        log.info("Version check starting");
        int currVer = (int) (NumberUtils.toFloat(Version.VERSION, 0f) * 1000);
        //hard code
        URL url = new URL("http://product.edgenius.com/versioncheck/" + SharedConstants.APP_NAME + "/"
                + Installation.INSTANCE_ID + "/" + currVer);
        //         Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("proxy url", 80));
        //         conn = (HttpURLConnection) url.openConnection(proxy);
        conn = (HttpURLConnection) url.openConnection();
        conn.setAllowUserInteraction(false);
        //         conn.addRequestProperty("Authorization", "Basic "+encrytString(username+":" + password));

        conn.setReadTimeout(20000);
        InputStream in = conn.getInputStream();
        StringBuffer sb = new StringBuffer();
        byte[] b = new byte[1024 * 10];
        int len;
        while ((len = in.read(b)) != -1) {
            sb.append(new String(b, 0, len));

        }
        String content = sb.toString();
        //         String content = "<version>3.01</version>";
        int start = content.indexOf("<version>");
        int end = content.indexOf("</version>");
        if (start != -1 && end != -1 && start < end) {
            String verStr = content.substring(start + 9, end);
            int version = (int) (NumberUtils.toFloat(verStr, 0f) * 1000);

            if (version > 0 && currVer > 0) {
                if (version > currVer) {
                    //check if this new version is already send notification to user, if so, silence.

                    List<ActivityLog> activities = activityLog.getByTarget(
                            ActivityType.Type.SYSTEM_EVENT.getCode(),
                            ActivityType.SubType.VERSION_PING.getCode(), version, "VERSION_CHECK"); //hardcode
                    if (activities == null || activities.size() == 0) {
                        Map<String, Object> map = new HashMap<String, Object>();
                        map.put("newVer", verStr);
                        map.put("currVer", Version.VERSION);
                        mailService.sendPlainToSystemAdmins(WikiConstants.MAIL_TEMPL_VERSION_CHECK, map);
                        log.info("New version {} found and notified to system administrators.", version);

                        //log activity
                        ActivityLog activity = new ActivityLog();
                        activity.setType(ActivityType.Type.SYSTEM_EVENT.getCode());
                        activity.setSubType(ActivityType.SubType.VERSION_PING.getCode());
                        activity.setTgtResourceType(version);
                        activity.setTgtResourceName("VERSION_CHECK");//hardcode
                        activity.setExtroInfo(verStr);
                        activity.setCreatedDate(new Date());
                        activityLog.save(activity);
                    } else {
                        log.info(
                                "New version {} found, but this version is already notified so no action takes",
                                2000);
                    }
                }
            } else {
                log.info("Wrong version number returned:{}", content);
            }
        }
        log.info("Version check is done");

    } catch (Exception e) {
        log.warn("Version check not success. This probably because of your network connection");
    } finally {
        try {
            if (conn != null)
                conn.disconnect();
        } catch (Exception e2) {
        }
    }
}