org.apache.commons.lang.math.NumberUtils#toFloat ( )源码实例Demo

下面列出了org.apache.commons.lang.math.NumberUtils#toFloat ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: cachecloud   文件: ServerController.java
/**
 * parse net to map
 * @param netString
 * @param subnetMap
 * @param isIn
 */
private void addNetMap(String netString, Map<String, NetChart> subnetMap, boolean isIn) {
	String[] subnetArray = netString.split(";");
	for(String subnet : subnetArray) {
		if(StringUtils.isEmpty(subnet)) {
			continue;
		}
		String[] net = subnet.split(",");
		NetChart netChart = subnetMap.get(net[0]);
		if(netChart == null) {
			netChart = new NetChart(net[0]);
			subnetMap.put(net[0], netChart);
		}
		float v = NumberUtils.toFloat(net[1]);
		if(isIn) {
			netChart.addInSeries(v);
			netChart.addTotalIn(v);
			netChart.setMaxIn(v);
		}else {
			netChart.addOutSeries(v);
			netChart.addTotalOut(v);
			netChart.setMaxOut(v);
		}
	}
}
 
源代码2 项目: usergrid   文件: ConversionUtils.java
public static float getFloat( Object obj ) {
    if ( obj instanceof Float ) {
        return ( Float ) obj;
    }
    if ( obj instanceof Number ) {
        return ( ( Number ) obj ).floatValue();
    }
    if ( obj instanceof String ) {
        return NumberUtils.toFloat( ( String ) obj );
    }
    if ( obj instanceof Date ) {
        return ( ( Date ) obj ).getTime();
    }
    if ( obj instanceof byte[] ) {
        return getFloat( ( byte[] ) obj );
    }
    if ( obj instanceof ByteBuffer ) {
        return getFloat( ( ByteBuffer ) obj );
    }
    return 0;
}
 
源代码3 项目: usergrid   文件: ConversionUtils.java
public static float getFloat( Object obj ) {
    if ( obj instanceof Float ) {
        return ( Float ) obj;
    }
    if ( obj instanceof Number ) {
        return ( ( Number ) obj ).floatValue();
    }
    if ( obj instanceof String ) {
        return NumberUtils.toFloat( ( String ) obj );
    }
    if ( obj instanceof Date ) {
        return ( ( Date ) obj ).getTime();
    }
    if ( obj instanceof byte[] ) {
        return getFloat( ( byte[] ) obj );
    }
    if ( obj instanceof ByteBuffer ) {
        return getFloat( ( ByteBuffer ) obj );
    }
    return 0;
}
 
源代码4 项目: cachecloud   文件: ServerController.java
private void addToChart(String line, DiskChart chart) {
	String[] parts = line.split(",");
	for(String part : parts) {
		if(StringUtils.isEmpty(part)) {
			continue;
		}
		String[] values = part.split(":");
		float d = NumberUtils.toFloat(values[1]);
		chart.addSeries(values[0], d);
		chart.setMax(d);
		chart.addTotal(d);
	}
}
 
源代码5 项目: cachecloud   文件: Load.java
/**
 * line format:
 * BBBP,585,uptime," 09:35:00 up 567 days, 15:07,  0 users,  load average: 0.60, 0.63, 0.67"
 */
public void parse(String line, String timeKey) throws Exception{
	Matcher matcher = PATTERN.matcher(line);
	if(matcher.find()) {
		load1 = NumberUtils.toFloat(matcher.group(1));
		load5 = NumberUtils.toFloat(matcher.group(2));
		load15 = NumberUtils.toFloat(matcher.group(3));
	}
}
 
源代码6 项目: cachecloud   文件: Memory.java
/**
 * line format:
 * MEM,Memory MB bx-50-13,memtotal,hightotal,lowtotal,swaptotal,memfree,highfree,lowfree,swapfree,memshared,cached,active,bigfree,buffers,swapcached,inactive
 * MEM,T0001,48288.7,0.0,48288.7,8189.4,132.6,0.0,132.6,8189.1,-0.0,24210.6,30819.7,-1.0,153.9,0.0,16451.1
 */
public void parse(String line, String timeKey) throws Exception{
	if(line.startsWith(FLAG)) {
		String[] items = line.split(",");
		if(!items[1].equals(timeKey)) {
			return;
		}
		total = NumberUtils.toFloat(items[2]);
		swap = NumberUtils.toFloat(items[5]);
		totalFree = NumberUtils.toFloat(items[6]);
		swapFree = NumberUtils.toFloat(items[9]);
		cache = NumberUtils.toFloat(items[11]);
		buffer = NumberUtils.toFloat(items[14]);
	}
}
 
源代码7 项目: Server.Java   文件: MIMEParse.java
/**
 * Find the best match for a given mimeType against a list of media_ranges
 * that have already been parsed by MimeParse.parseMediaRange(). Returns a
 * tuple of the fitness value and the value of the 'q' quality parameter of
 * the best match, or (-1, 0) if no match was found. Just as for
 * quality_parsed(), 'parsed_ranges' must be a list of parsed media ranges.
 * 
 * @param mimeType
 * @param parsedRanges
 * @return 
 */
protected static FitnessAndQuality fitnessAndQualityParsed(String mimeType,
        Collection<ParseResults> parsedRanges)
{
    int bestFitness = -1;
    float bestFitQ = 0;
    ParseResults target = parseMediaRange(mimeType);

    for (ParseResults range : parsedRanges)
    {
        if ((target.type.equals(range.type) || range.type.equals("*") || target.type
                .equals("*"))
                && (target.subType.equals(range.subType)
                        || range.subType.equals("*") || target.subType
                        .equals("*")))
        {
            for (String k : target.params.keySet())
            {
                int paramMatches = 0;
                if (!k.equals("q") && range.params.containsKey(k)
                        && target.params.get(k).equals(range.params.get(k)))
                {
                    paramMatches++;
                }
                int fitness = (range.type.equals(target.type)) ? 100 : 0;
                fitness += (range.subType.equals(target.subType)) ? 10 : 0;
                fitness += paramMatches;
                if (fitness > bestFitness)
                {
                    bestFitness = fitness;
                    bestFitQ = NumberUtils
                            .toFloat(range.params.get("q"), 0);
                }
            }
        }
    }
    return new FitnessAndQuality(bestFitness, bestFitQ);
}
 
源代码8 项目: XSeries   文件: ParticleDisplay.java
/**
 * Builds particle settings from a configuration section.
 *
 * @param location the location for this particle settings.
 * @param config   the config section for the settings.
 * @return a parsed ParticleDisplay.
 * @since 1.0.0
 */
@Nonnull
public static ParticleDisplay fromConfig(@Nullable Location location, @Nonnull ConfigurationSection config) {
    Objects.requireNonNull(config, "Cannot parse ParticleDisplay from a null config section");
    Particle particle = XParticle.getParticle(config.getString("particle"));
    if (particle == null) particle = Particle.FLAME;
    int count = config.getInt("count");
    double extra = config.getDouble("extra");
    double offsetx = 0, offsety = 0, offsetz = 0;

    String offset = config.getString("offset");
    if (offset != null) {
        String[] offsets = StringUtils.split(offset, ',');
        if (offsets.length > 0) {
            offsetx = NumberUtils.toDouble(offsets[0]);
            if (offsets.length > 1) {
                offsety = NumberUtils.toDouble(offsets[1]);
                if (offsets.length > 2) {
                    offsetz = NumberUtils.toDouble(offsets[2]);
                }
            }
        }
    }

    double x = 0, y = 0, z = 0;
    String rotation = config.getString("rotation");
    if (rotation != null) {
        String[] rotations = StringUtils.split(rotation, ',');
        if (rotations.length > 0) {
            x = NumberUtils.toDouble(rotations[0]);
            if (rotations.length > 1) {
                y = NumberUtils.toDouble(rotations[1]);
                if (rotations.length > 2) {
                    z = NumberUtils.toDouble(rotations[2]);
                }
            }
        }
    }

    float[] rgbs = null;
    String color = config.getString("color");
    if (color != null) {
        String[] colors = StringUtils.split(rotation, ',');
        if (colors.length >= 3) rgbs = new float[]
                {NumberUtils.toInt(colors[0]), NumberUtils.toInt(colors[1]), NumberUtils.toInt(colors[2]),
                        (colors.length > 3 ? NumberUtils.toFloat(colors[0]) : 1.0f)};
    }

    Vector rotate = new Vector(x, y, z);
    ParticleDisplay display = new ParticleDisplay(particle, location, count, offsetx, offsety, offsetz, extra);
    display.rotation = rotate;
    display.data = rgbs;
    return display;
}
 
源代码9 项目: cosmic   文件: NumbersUtil.java
public static float parseFloat(final String s, final float defaultValue) {
    return NumberUtils.toFloat(s, defaultValue);
}
 
源代码10 项目: cloudstack   文件: NumbersUtil.java
public static float parseFloat(String s, float defaultValue) {
    return NumberUtils.toFloat(s, defaultValue);
}
 
源代码11 项目: Server.Java   文件: 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'})
 * 
 * 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
 * @return 
 */
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;
}