Java Code Examples for org.apache.commons.lang3.math.NumberUtils#toFloat()

The following examples show how to use org.apache.commons.lang3.math.NumberUtils#toFloat() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: WeightSaveOrUpdateAction.java    From bamboobsc with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
private <T extends BaseValueObj> List<T> fillDatas(Class<?> clazz, String inputHeanId) throws Exception {
	List<T> elements = new ArrayList<T>();
	Enumeration<String> parameterNames = this.getHttpServletRequest().getParameterNames();
	while (parameterNames.hasMoreElements()) {
		String name = parameterNames.nextElement();
		if (!name.startsWith(inputHeanId)) {
			continue;
		}
		Float value = NumberUtils.toFloat( this.getHttpServletRequest().getParameter(name), 1f );
		T obj = (T)clazz.newInstance();
		Ognl.setValue("oid", obj, name.substring(inputHeanId.length(), name.length()) );
		Ognl.setValue("weight", obj, new BigDecimal(value) );
		elements.add(obj);
	}
	return elements;
}
 
Example 2
Source File: AggregationMethod.java    From bamboobsc with Apache License 2.0 5 votes vote down vote up
public float max(KpiVO kpi) throws Exception {
	List<BbMeasureData> measureDatas = kpi.getMeasureDatas();
	float score = 0.0f; // init
	int size = 0;
	float nowScore = 0.0f;
	for (BbMeasureData measureData : measureDatas) {
		BscMeasureData data = new BscMeasureData();
		data.setActual( measureData.getActual() );
		data.setTarget( measureData.getTarget() );
		data.setKpi(kpi); // 2018-12-02
		try {
			Object value = BscFormulaUtils.parse(kpi.getFormula(), data);
			if (value == null) {
				continue;
			}
			if ( !NumberUtils.isCreatable( String.valueOf(value) ) ) {
				continue;
			}
			nowScore = NumberUtils.toFloat(String.valueOf(value), 0.0f);
			if ( size < 1 ) {
				score = nowScore;
			} else { // Max
				if ( score < nowScore ) {
					score = nowScore;
				}
			}
			size++;
		} catch (Exception e) {
			e.printStackTrace();
		}
	}		
	return score;
}
 
Example 3
Source File: AggregationMethodUtils.java    From bamboobsc with Apache License 2.0 5 votes vote down vote up
public static float processDateRangeMode(KpiVO kpi, String frequency) throws Exception {
	Map<String, Object> results = getScore(kpi.getAggregationMethod().getType(), kpi.getAggregationMethod().getExpression2(), kpi, frequency);
	Object value = results.get( AggregationMethodVariable.SCORE );
	if ( null == value ) {
		return 0.0f;
	}
	if ( !NumberUtils.isCreatable( String.valueOf(value) ) ) {			
		return 0.0f;
	}
	return NumberUtils.toFloat( String.valueOf(value), 0.0f);	
}
 
Example 4
Source File: DialogScroller.java    From riiablo with Apache License 2.0 5 votes vote down vote up
public void play(String dialog) {
  // FIXME: scrollSpeed should be in pixels/sec, but timing is off by about 10-15%
  //        problem seems to be with fontformat11 metrics, applying scalar to line height
  final float lineScalar = 0.85f;
  String key = Riiablo.files.speech.get(dialog).soundstr;
  String text = Riiablo.string.lookup(key);
  String[] parts = text.split("\n", 2);
  scrollSpeed = NumberUtils.toFloat(parts[0]) / 60 * FONT.getLineHeight() * lineScalar;
  textArea.setText(parts[1]);
  scrollPane.layout();

  scrollPane.setScrollY(-scrollPane.getScrollHeight() + textArea.getStyle().font.getLineHeight() / 2);
  audio = Riiablo.audio.play(dialog, false);
}
 
Example 5
Source File: AggregationMethod.java    From bamboobsc with Apache License 2.0 5 votes vote down vote up
public void sumDistinctDateRange(KpiVO kpi, String frequency) throws Exception {
	BscReportSupportUtils.loadExpression();
	for (DateRangeScoreVO dateScore : kpi.getDateRangeScores()) {
		List<Float> scores = new ArrayList<Float>();
		float score = 0.0f;
		//int size = 0;
		for (BbMeasureData measureData : kpi.getMeasureDatas()) {
			String date = dateScore.getDate().replaceAll("/", "");
			if (!this.isDateRange(date, frequency, measureData)) {
				continue;
			}
			BscMeasureData data = new BscMeasureData();
			data.setActual( measureData.getActual() );
			data.setTarget( measureData.getTarget() );
			data.setKpi(kpi); // 2018-12-02
			try {
				Object value = BscFormulaUtils.parse(kpi.getFormula(), data);
				if (value == null) {
					continue;
				}
				if ( !NumberUtils.isCreatable( String.valueOf(value) ) ) {
					continue;
				}
				float nowScore = NumberUtils.toFloat(String.valueOf(value), 0.0f);
				if ( !scores.contains(nowScore) ) {
					scores.add( nowScore );
					//size++;
					score += nowScore;
				}					
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
		dateScore.setScore(score);
		dateScore.setFontColor( BscScoreColorUtils.getFontColor(score) );
		dateScore.setBgColor( BscScoreColorUtils.getBackgroundColor(score) );
		dateScore.setImgIcon( BscReportSupportUtils.getHtmlIcon(kpi, score) );
	}
}
 
Example 6
Source File: AggregationMethod.java    From bamboobsc with Apache License 2.0 5 votes vote down vote up
public float sumDistinct(KpiVO kpi) throws Exception {
	List<BbMeasureData> measureDatas = kpi.getMeasureDatas();
	List<Float> scores = new ArrayList<Float>();
	float score = 0.0f; // init
	//int size = 0;
	for (BbMeasureData measureData : measureDatas) {
		BscMeasureData data = new BscMeasureData();
		data.setActual( measureData.getActual() );
		data.setTarget( measureData.getTarget() );
		data.setKpi(kpi); // 2018-12-02
		try {
			Object value = BscFormulaUtils.parse(kpi.getFormula(), data);
			if (value == null) {
				continue;
			}
			if ( !NumberUtils.isCreatable( String.valueOf(value) ) ) {
				continue;
			}
			float nowScore = NumberUtils.toFloat(String.valueOf(value), 0.0f);
			if ( !scores.contains(nowScore) ) {
				scores.add( nowScore );
				//size++;
				score += nowScore;
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	return score;
}
 
Example 7
Source File: AggregationMethod.java    From bamboobsc with Apache License 2.0 5 votes vote down vote up
public void sumDateRange(KpiVO kpi, String frequency) throws Exception {
	BscReportSupportUtils.loadExpression();
	for (DateRangeScoreVO dateScore : kpi.getDateRangeScores()) {
		float score = 0.0f;
		//int size = 0;
		for (BbMeasureData measureData : kpi.getMeasureDatas()) {
			String date = dateScore.getDate().replaceAll("/", "");
			if (!this.isDateRange(date, frequency, measureData)) {
				continue;
			}
			BscMeasureData data = new BscMeasureData();
			data.setActual( measureData.getActual() );
			data.setTarget( measureData.getTarget() );
			data.setKpi(kpi); // 2018-12-02
			try {
				Object value = BscFormulaUtils.parse(kpi.getFormula(), data);
				if (value == null) {
					continue;
				}
				if ( !NumberUtils.isCreatable( String.valueOf(value) ) ) {
					continue;
				}
				score += NumberUtils.toFloat(String.valueOf(value), 0.0f);
				//size++;					
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
		dateScore.setScore(score);
		dateScore.setFontColor( BscScoreColorUtils.getFontColor(score) );
		dateScore.setBgColor( BscScoreColorUtils.getBackgroundColor(score) );
		dateScore.setImgIcon( BscReportSupportUtils.getHtmlIcon(kpi, score) );
	}
}
 
Example 8
Source File: AggregationMethod.java    From bamboobsc with Apache License 2.0 5 votes vote down vote up
public float min(KpiVO kpi) throws Exception {
	List<BbMeasureData> measureDatas = kpi.getMeasureDatas();
	float score = 0.0f; // init
	int size = 0;
	float nowScore = 0.0f;
	for (BbMeasureData measureData : measureDatas) {
		BscMeasureData data = new BscMeasureData();
		data.setActual( measureData.getActual() );
		data.setTarget( measureData.getTarget() );
		data.setKpi(kpi); // 2018-12-02
		try {
			Object value = BscFormulaUtils.parse(kpi.getFormula(), data);
			if (value == null) {
				continue;
			}
			if ( !NumberUtils.isCreatable( String.valueOf(value) ) ) {
				continue;
			}
			nowScore = NumberUtils.toFloat(String.valueOf(value), 0.0f);
			if ( size < 1 ) {
				score = nowScore;
			} else { // Min
				if ( score > nowScore ) {
					score = nowScore;
				}
			}
			size++;
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	return score;
}
 
Example 9
Source File: AggregationMethod.java    From bamboobsc with Apache License 2.0 5 votes vote down vote up
public void countDistinctDateRange(KpiVO kpi, String frequency) throws Exception {
	BscReportSupportUtils.loadExpression();
	for (DateRangeScoreVO dateScore : kpi.getDateRangeScores()) {
		List<Float> scores = new ArrayList<Float>();
		float score = 0.0f;
		//int size = 0;
		for (BbMeasureData measureData : kpi.getMeasureDatas()) {
			String date = dateScore.getDate().replaceAll("/", "");
			if (!this.isDateRange(date, frequency, measureData)) {
				continue;
			}	
			BscMeasureData data = new BscMeasureData();
			data.setActual( measureData.getActual() );
			data.setTarget( measureData.getTarget() );
			data.setKpi(kpi); // 2018-12-02
			try {
				Object value = BscFormulaUtils.parse(kpi.getFormula(), data);
				if (value == null) {
					continue;
				}
				if ( !NumberUtils.isCreatable( String.valueOf(value) ) ) {
					continue;
				}
				float nowScore = NumberUtils.toFloat(String.valueOf(value), 0.0f);
	      		if ( !scores.contains(nowScore) ) {
					scores.add( nowScore );
				}
			} catch (Exception e) {
				e.printStackTrace();
			}		
		}
	    score = Float.valueOf( scores.size() );
		dateScore.setScore(score);
		dateScore.setFontColor( BscScoreColorUtils.getFontColor(score) );
		dateScore.setBgColor( BscScoreColorUtils.getBackgroundColor(score) );
		dateScore.setImgIcon( BscReportSupportUtils.getHtmlIcon(kpi, score) );
	}		
}
 
Example 10
Source File: PersonalAndOrganizationReportDateRangeScoreCommand.java    From bamboobsc with Apache License 2.0 5 votes vote down vote up
private void setDateRangeScore(KpiVO kpi, String dateType, String year) throws Exception {
	float score = 0.0f;
	String date = year + "0101"; // year
	if ("2".equals(dateType)) { // second helf-year
		date = year + "0701";
	} 
	for (BbMeasureData measureData : kpi.getMeasureDatas()) {
		if ( date.equals(measureData.getDate()) ) {
			BscMeasureData data = new BscMeasureData();
			data.setActual( measureData.getActual() );
			data.setTarget( measureData.getTarget() );
			data.setKpi(kpi); // 2018-12-02
			Object value = BscFormulaUtils.parse(kpi.getFormula(), data);
			/* 2016-07-01 rem
			if (value != null && (value instanceof Integer || value instanceof Float || value instanceof Long) ) {
				score = NumberUtils.toFloat( String.valueOf(value), 0.0f);
			}
			*/
			// 2016-07-01
			if (NumberUtils.isCreatable( String.valueOf(value)) ) {
				score = NumberUtils.toFloat(String.valueOf(value), 0.0f);
			}
		}
	}
	DateRangeScoreVO dateRangeScore = new DateRangeScoreVO();
	dateRangeScore.setDate( date );
	dateRangeScore.setBgColor( BscScoreColorUtils.getBackgroundColor(score) );
	dateRangeScore.setFontColor( BscScoreColorUtils.getFontColor(score) );
	dateRangeScore.setTarget(kpi.getTarget());
	dateRangeScore.setMin(kpi.getMin());
	dateRangeScore.setScore(score);
	dateRangeScore.setImgIcon("");
	kpi.getDateRangeScores().add(dateRangeScore);		
}
 
Example 11
Source File: FileSizeFormatFilter.java    From jinjava with Apache License 2.0 5 votes vote down vote up
@Override
public Object filter(Object var, JinjavaInterpreter interpreter, String... args) {
  float bytes = NumberUtils.toFloat(Objects.toString(var), 0.0f);

  if (bytes == 1) {
    return "1 Byte";
  }

  boolean binary = false;
  if (args.length > 0) {
    binary = BooleanUtils.toBoolean(args[0]);
  }

  int base = binary ? 1024 : 1000;
  if (bytes < base) {
    return (int) bytes + " Bytes";
  }

  String[] sizes = binary ? BINARY_SIZES : DECIMAL_SIZES;
  int unit = 1;
  String prefix = "";

  for (int i = 0; i < sizes.length; i++) {
    unit = (int) Math.pow(base, i + 2);
    prefix = sizes[i];

    if (bytes < unit) {
      return String.format("%.1f %s", (base * bytes / unit), prefix);
    }
  }

  return String.format("%.1f %s", (base * bytes / unit), prefix);
}
 
Example 12
Source File: AggregationMethod.java    From bamboobsc with Apache License 2.0 5 votes vote down vote up
public void averageDateRange(KpiVO kpi, String frequency) throws Exception {
	BscReportSupportUtils.loadExpression();
	for (DateRangeScoreVO dateScore : kpi.getDateRangeScores()) {
		float score = 0.0f;
		int size = 0;
		for (BbMeasureData measureData : kpi.getMeasureDatas()) {
			String date = dateScore.getDate().replaceAll("/", "");
			if (!this.isDateRange(date, frequency, measureData)) {
				continue;
			}
			BscMeasureData data = new BscMeasureData();
			data.setActual( measureData.getActual() );
			data.setTarget( measureData.getTarget() );
			data.setKpi(kpi); // 2018-12-02
			try {
				Object value = BscFormulaUtils.parse(kpi.getFormula(), data);
				if (value == null) {
					continue;
				}
				if ( !NumberUtils.isCreatable( String.valueOf(value) ) ) {
					continue;
				}
				score += NumberUtils.toFloat( String.valueOf(value), 0.0f);
				size++;						
			} catch (Exception e) {
				e.printStackTrace();
			}				
		}
		if ( score != 0.0f && size > 0 ) {
			score = score / size;
		}
		dateScore.setScore(score);
		dateScore.setFontColor( BscScoreColorUtils.getFontColor(score) );
		dateScore.setBgColor( BscScoreColorUtils.getBackgroundColor(score) );
		dateScore.setImgIcon( BscReportSupportUtils.getHtmlIcon(kpi, score) );
	}
}
 
Example 13
Source File: AggregationMethod.java    From bamboobsc with Apache License 2.0 5 votes vote down vote up
public float average(KpiVO kpi) throws Exception {
	List<BbMeasureData> measureDatas = kpi.getMeasureDatas();
	float score = 0.0f; // init zero
	int size = 0;
	for (BbMeasureData measureData : measureDatas) {
		BscMeasureData data = new BscMeasureData();
		data.setActual( measureData.getActual() );
		data.setTarget( measureData.getTarget() );
		data.setKpi(kpi); // 2018-12-02
		try {
			Object value = BscFormulaUtils.parse(kpi.getFormula(), data);
			if (value == null) {
				continue;
			}
			if ( !NumberUtils.isCreatable( String.valueOf(value) ) ) {
				continue;
			}
			score += NumberUtils.toFloat(String.valueOf(value), 0.0f);
			size++;
		} catch (Exception e) {
			e.printStackTrace();
		}		
	}
	if ( score != 0.0f && size > 0 ) {
		score = score / size;
	}
	return score;
}
 
Example 14
Source File: CommonMeterChartAction.java    From bamboobsc with Apache License 2.0 5 votes vote down vote up
private void createChart() throws Exception {
	Map<String, Object> dataMap = JFreeChartDataMapperUtils.getChartData2Map(oid);
	if ( dataMap == null ) {
		return;
	}
	String title = String.valueOf(dataMap.get("title"));
	float value = NumberUtils.toFloat( String.valueOf(dataMap.get("value")) );
	Integer lowerBound = (Integer)dataMap.get("lowerBound");
	Integer upperBound = (Integer)dataMap.get("upperBound");
	this.width = String.valueOf( (Integer) dataMap.get("width") );
	this.height = String.valueOf( (Integer) dataMap.get("height") );
	this.fillChart(title, value, lowerBound, upperBound);		
}
 
Example 15
Source File: FloatFilter.java    From jinjava with Apache License 2.0 5 votes vote down vote up
@Override
public Object filter(Object var, JinjavaInterpreter interpreter, String... args) {
  float defaultVal = 0;
  if (args.length > 0) {
    defaultVal = NumberUtils.toFloat(args[0], 0.0f);
  }

  if (var == null) {
    return defaultVal;
  }

  if (Float.class.isAssignableFrom(var.getClass())) {
    return var;
  }
  if (Number.class.isAssignableFrom(var.getClass())) {
    return ((Number) var).floatValue();
  }

  String input = var.toString();
  Locale locale = interpreter.getConfig().getLocale();
  NumberFormat numberFormat = NumberFormat.getNumberInstance(locale);
  ParsePosition pp = new ParsePosition(0);
  float result;
  try {
    result = numberFormat.parse(input, pp).floatValue();
  } catch (Exception e) {
    result = defaultVal;
  }
  if (pp.getErrorIndex() != -1 || pp.getIndex() != input.length()) {
    result = defaultVal;
  }
  return result;
}
 
Example 16
Source File: ConfigUtils.java    From fastjgame with Apache License 2.0 4 votes vote down vote up
public static float getAsFloat(final String str, final float defaultValue) {
    return NumberUtils.toFloat(str, defaultValue);
}
 
Example 17
Source File: AggregationMethod.java    From bamboobsc with Apache License 2.0 4 votes vote down vote up
public void maxDateRange(KpiVO kpi, String frequency) throws Exception {
	BscReportSupportUtils.loadExpression();
	for (DateRangeScoreVO dateScore : kpi.getDateRangeScores()) {
		float score = 0.0f;
		float nowScore = 0.0f;
		int size = 0;
		for (BbMeasureData measureData : kpi.getMeasureDatas()) {
			String date = dateScore.getDate().replaceAll("/", "");
			if (!this.isDateRange(date, frequency, measureData)) {
				continue;
			}
			BscMeasureData data = new BscMeasureData();
			data.setActual( measureData.getActual() );
			data.setTarget( measureData.getTarget() );
			data.setKpi(kpi); // 2018-12-02
			try {
				Object value = BscFormulaUtils.parse(kpi.getFormula(), data);
				if (value == null) {
					continue;
				}
				if ( !NumberUtils.isCreatable( String.valueOf(value) ) ) {
					continue;
				}
				nowScore = NumberUtils.toFloat( String.valueOf(value), 0.0f);
				if ( size < 1 ) {
					score = nowScore;
				} else { // Max
					if ( score < nowScore ) {
						score = nowScore;
					}
				}
				size++;					
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
		dateScore.setScore(score);
		dateScore.setFontColor( BscScoreColorUtils.getFontColor(score) );
		dateScore.setBgColor( BscScoreColorUtils.getBackgroundColor(score) );
		dateScore.setImgIcon( BscReportSupportUtils.getHtmlIcon(kpi, score) );
	}		
}
 
Example 18
Source File: AggregationMethod.java    From bamboobsc with Apache License 2.0 4 votes vote down vote up
public void minDateRange(KpiVO kpi, String frequency) throws Exception {
	BscReportSupportUtils.loadExpression();
	for (DateRangeScoreVO dateScore : kpi.getDateRangeScores()) {
		float score = 0.0f;
		float nowScore = 0.0f;
		int size = 0;
		for (BbMeasureData measureData : kpi.getMeasureDatas()) {
			String date = dateScore.getDate().replaceAll("/", "");
			if (!this.isDateRange(date, frequency, measureData)) {
				continue;
			}
			BscMeasureData data = new BscMeasureData();
			data.setActual( measureData.getActual() );
			data.setTarget( measureData.getTarget() );
			data.setKpi(kpi); // 2018-12-02
			try {
				Object value = BscFormulaUtils.parse(kpi.getFormula(), data);
				if (value == null) {
					continue;
				}
				if ( !NumberUtils.isCreatable( String.valueOf(value) ) ) {
					continue;
				}
				nowScore = NumberUtils.toFloat(String.valueOf(value), 0.0f);
				if ( size < 1 ) {
					score = nowScore;
				} else { // Min
					if ( score > nowScore ) {
						score = nowScore;
					}
				}
				size++;					
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
		dateScore.setScore(score);
		dateScore.setFontColor( BscScoreColorUtils.getFontColor(score) );
		dateScore.setBgColor( BscScoreColorUtils.getBackgroundColor(score) );
		dateScore.setImgIcon( BscReportSupportUtils.getHtmlIcon(kpi, score) );
	}	
}
 
Example 19
Source File: NpcDialogBox.java    From riiablo with Apache License 2.0 4 votes vote down vote up
public NpcDialogBox(String sound, DialogCompletionListener listener) {
  this.listener = listener;
  setBackground(new BorderedPaletteIndexedDrawable());
  setTouchable(Touchable.disabled);
  //setDebug(true, true);

  // FIXME: scrollSpeed should be in pixels/sec, but timing is off by about 10-15%
  //        problem seems to be with fontformat11 metrics, applying scalar to line height
  final float lineScalar = 0.85f;
  final FontTBL.BitmapFont FONT = Riiablo.fonts.fontformal11;
  String key = Riiablo.files.speech.get(sound).soundstr;
  String text = Riiablo.string.lookup(key);
  String[] parts = text.split("\n", 2);
  scrollSpeed = NumberUtils.toFloat(parts[0]) / 60 * FONT.getLineHeight() * lineScalar;
  final int count = StringUtils.countMatches(parts[1], '\n');
  textArea = new TextArea(parts[1], new TextArea.TextFieldStyle() {{
    font = FONT;
    fontColor = Riiablo.colors.white;
  }}) {
    final float prefHeight = count * getStyle().font.getLineHeight();

    @Override
    public float getPrefHeight() {
      return prefHeight;
    }
  };

  scrollPane = new ScrollPane(textArea);
  scrollPane.setTouchable(Touchable.disabled);
  scrollPane.setSmoothScrolling(false);
  scrollPane.setFlickScroll(false);
  scrollPane.setFlingTime(0);
  scrollPane.setOverscroll(false, false);
  scrollPane.setClamp(false);
  scrollPane.setScrollX(-15); // FIXME: actual preferred width of text isn't calculated anywhere, this is best guess
  add(scrollPane).size(330, 128);
  pack();

  scrollPane.setScrollY(-scrollPane.getScrollHeight() + textArea.getStyle().font.getLineHeight() / 2);
  audio = Riiablo.audio.play(sound, false);
}
 
Example 20
Source File: RedisNumber.java    From azeroth with Apache License 2.0 4 votes vote down vote up
public Float getFloat() {
    String value = super.get();
    return value == null ? null : NumberUtils.toFloat(value);
}