List of usage examples for java.lang Float floatValue
@HotSpotIntrinsicCandidate public float floatValue()
From source file:com.joliciel.csvLearner.CSVEventListReader.java
public float getMean(String featureName) { String fileName = this.groupedFeatures.get(featureName); float meanValue = 0; if (fileName != null) { // in this case, this feature was grouped with other features into a file // that needs to be normalised as a whole Float meanValueObj = this.fileMeanValues.get(fileName); if (meanValueObj == null) { float totalValue = 0; int totalCount = 0; for (String feature : this.fileToFeatureMap.get(fileName)) { totalValue += this.featureStatsMap.get(feature).total; totalCount += this.featureStatsMap.get(feature).count; }//from w w w . j a va 2s.co m meanValue = totalValue / (float) totalCount; this.fileMeanValues.put(fileName, meanValue); } else { meanValue = meanValueObj.floatValue(); } } else { // this feature is normalised on its own float totalValue = this.featureStatsMap.get(featureName).total; int totalCount = this.featureStatsMap.get(featureName).count; meanValue = totalValue / (float) totalCount; } return meanValue; }
From source file:pcgen.cdom.facet.analysis.ChallengeRatingFacet.java
public int getXPAward(CharID id) { Map<String, Integer> xpAwardsMap = SettingsHandler.getGame().getXPAwards(); if (xpAwardsMap.size() > 0) { Float cr = getCR(id); if (cr.isNaN() || cr == 0) { return 0; }//from ww w . jav a 2s . c om String crString = ""; String crAsString = Float.toString(cr); String decimalPlaceValue = crAsString.substring(crAsString.length() - 2); // If the CR is a fractional CR then we convert to a 1/x format if (cr > 0 && cr < 1) { Fraction fraction = Fraction.getFraction(cr);// new Fraction(CR); int denominator = fraction.getDenominator(); int numerator = fraction.getNumerator(); crString = numerator + "/" + denominator; } else if (cr >= 1 || cr == 0) { int newCr = -99; if (decimalPlaceValue.equals(".0")) { newCr = (int) cr.floatValue(); } if (newCr > -99) { crString = crString + newCr; } else { crString = crString + cr; } } return xpAwardsMap.get(crString); } return 0; }
From source file:net.sourceforge.msscodefactory.cflib.v1_11.CFLib.Swing.CFJFloatEditor.java
public Float getFloatValue() { final String S_ProcName = "getFloatValue"; Float retval;/*from w w w. j a v a2 s .c om*/ String text = getText(); if ((text == null) || (text.length() <= 0)) { retval = null; } else { if (!isEditValid()) { throw CFLib.getDefaultExceptionFactory().newInvalidArgumentException(getClass(), S_ProcName, "Field is not valid"); } try { commitEdit(); } catch (ParseException e) { throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName, "Field is not valid - " + e.getMessage(), e); } Object obj = getValue(); if (obj == null) { retval = null; } else if (obj instanceof Float) { Float v = (Float) obj; Float min = getMinValue(); Float max = getMaxValue(); if ((v.compareTo(min) < 0) || (v.compareTo(max) > 0)) { throw CFLib.getDefaultExceptionFactory().newArgumentRangeException(getClass(), S_ProcName, 0, "EditedValue", v, min, max); } retval = v; } else if (obj instanceof Double) { Double v = (Double) obj; Double min = getMinValue().doubleValue(); Double max = getMaxValue().doubleValue(); if ((v.compareTo(min) < 0) || (v.compareTo(max) > 0)) { throw CFLib.getDefaultExceptionFactory().newArgumentRangeException(getClass(), S_ProcName, 0, "EditedValue", v, min, max); } retval = new Float(v.floatValue()); } else if (obj instanceof Short) { Short s = (Short) obj; Float v = new Float(s.floatValue()); Float min = getMinValue(); Float max = getMaxValue(); if ((v.compareTo(min) < 0) || (v.compareTo(max) > 0)) { throw CFLib.getDefaultExceptionFactory().newArgumentRangeException(getClass(), S_ProcName, 0, "EditedValue", v, min, max); } retval = v; } else if (obj instanceof Integer) { Integer i = (Integer) obj; Float v = new Float(i.floatValue()); Float min = getMinValue(); Float max = getMaxValue(); if ((v.compareTo(min) < 0) || (v.compareTo(max) > 0)) { throw CFLib.getDefaultExceptionFactory().newArgumentRangeException(getClass(), S_ProcName, 0, "EditedValue", v, min, max); } retval = v; } else if (obj instanceof Long) { Long l = (Long) obj; Float v = new Float(l.floatValue()); Float min = getMinValue(); Float max = getMaxValue(); if ((v.compareTo(min) < 0) || (v.compareTo(max) > 0)) { throw CFLib.getDefaultExceptionFactory().newArgumentRangeException(getClass(), S_ProcName, 0, "EditedValue", v, min, max); } retval = v; } else if (obj instanceof BigDecimal) { BigDecimal b = (BigDecimal) obj; Float v = new Float(b.toString()); Float min = getMinValue(); Float max = getMaxValue(); if ((v.compareTo(min) < 0) || (v.compareTo(max) > 0)) { throw CFLib.getDefaultExceptionFactory().newArgumentRangeException(getClass(), S_ProcName, 0, "EditedValue", v, min, max); } retval = v; } else if (obj instanceof Number) { Number n = (Number) obj; Float v = new Float(n.toString()); Float min = getMinValue(); Float max = getMaxValue(); if ((v.compareTo(min) < 0) || (v.compareTo(max) > 0)) { throw CFLib.getDefaultExceptionFactory().newArgumentRangeException(getClass(), S_ProcName, 0, "EditedValue", v, min, max); } retval = v; } else { throw CFLib.getDefaultExceptionFactory().newUnsupportedClassException(getClass(), S_ProcName, "EditedValue", obj, "Short, Integer, Long, BigDecimal or Number"); } } return (retval); }
From source file:com.joliciel.csvLearner.CSVEventListReader.java
public float getMax(String featureName) { String fileName = this.groupedFeatures.get(featureName); float maxValue = 0; if (fileName != null) { // in this case, this feature was grouped with other features into a file // that needs to be normalised as a whole Float maxValueObj = this.fileMaxValues.get(fileName); if (maxValueObj == null) { maxValue = 0;/*from w ww. j a v a 2 s. c o m*/ for (String feature : this.fileToFeatureMap.get(fileName)) { float featureMax = 0; FeatureStats featureStats = this.featureStatsMap.get(feature); if (featureStats != null) featureMax = featureStats.max; if (featureMax > maxValue) maxValue = featureMax; } this.fileMaxValues.put(fileName, maxValue); } else { maxValue = maxValueObj.floatValue(); } } else { // this feature is normalised on its own maxValue = this.featureStatsMap.get(featureName).max; } return maxValue; }
From source file:org.muse.mneme.impl.SubmissionStorageSql.java
/** * {@inheritDoc}/*from ww w . ja v a2 s.c om*/ */ public Float getSubmissionHighestScore(Assessment assessment, String userId) { // TODO: pre-compute into MNEME_SUBMISSION.TOTAL_SCORE? -ggolden StringBuilder sql = new StringBuilder(); sql.append("SELECT S.ID, S.EVAL_SCORE, SUM(A.EVAL_SCORE), SUM(A.AUTO_SCORE) FROM MNEME_SUBMISSION S"); sql.append(" JOIN MNEME_ANSWER A ON S.ID=A.SUBMISSION_ID"); sql.append(" WHERE S.ASSESSMENT_ID=? AND S.USERID=? AND S.COMPLETE='1'"); sql.append(" GROUP BY S.ID, S.EVAL_SCORE"); Object[] fields = new Object[2]; fields[0] = Long.valueOf(assessment.getId()); fields[1] = userId; final Map<String, Float> scores = new HashMap<String, Float>(); this.sqlService.dbRead(sql.toString(), fields, new SqlReader() { public Object readSqlResultRecord(ResultSet result) { try { String sid = SqlHelper.readId(result, 1); Float sEval = SqlHelper.readFloat(result, 2); Float aEval = SqlHelper.readFloat(result, 3); Float aAuto = SqlHelper.readFloat(result, 4); Float total = Float.valueOf( (sEval == null ? 0f : sEval.floatValue()) + (aEval == null ? 0f : aEval.floatValue()) + (aAuto == null ? 0f : aAuto.floatValue())); // massage total - 2 decimal places if (total != null) { total = Float.valueOf(((float) Math.round(total.floatValue() * 100.0f)) / 100.0f); } scores.put(sid, total); return null; } catch (SQLException e) { M_log.warn("getSubmissionHighestScore: " + e); return null; } } }); // find the submission with the highest score String highestId = null; Float highestTotal = null; for (Map.Entry entry : scores.entrySet()) { String sid = (String) entry.getKey(); Float total = (Float) entry.getValue(); if (highestTotal == null) { highestId = sid; highestTotal = total; } else if (total.floatValue() > highestTotal.floatValue()) { highestId = sid; highestTotal = total; } } return highestTotal; }
From source file:org.apache.pig.data.SchemaTuple.java
protected float unbox(Float v) { return v.floatValue(); }
From source file:com.commontime.cordova.audio.AudioPlayer.java
private void sendStatusChange(int messageType, Integer additionalCode, Float value) { if (additionalCode != null && value != null) { throw new IllegalArgumentException("Only one of additionalCode or value can be specified, not both"); }/*from w w w. j a v a 2 s.co m*/ JSONObject statusDetails = new JSONObject(); try { statusDetails.put("id", this.id); statusDetails.put("msgType", messageType); if (additionalCode != null) { JSONObject code = new JSONObject(); code.put("code", additionalCode.intValue()); statusDetails.put("value", code); } else if (value != null) { statusDetails.put("value", value.floatValue()); } } catch (JSONException e) { Log.e(LOG_TAG, "Failed to create status details", e); } this.handler.sendEventMessage("status", statusDetails); }
From source file:pcgen.cdom.facet.analysis.ChallengeRatingFacet.java
/** * Returns the Challenge Rating of the Player Character represented by the * given CharID/*from ww w. j av a 2s . c o m*/ * * @param id * The CharID representing the Player Character for which the * Challenge Rating should be returned * @return The Challenge Rating of the Player Character represented by the * given CharID */ public Float getCR(CharID id) { Float CR = new Float(0); if (levelFacet.getMonsterLevelCount(id) == 0) { if (levelFacet.getNonMonsterLevelCount(id) == 0) { return Float.NaN; } // calculate and add class CR for 0-HD races CR += calcClassesCR(id); } else { // calculate and add race CR and classes CR for // races with racial hit dice Float classRaceCR = calcClassesForRaceCR(id); if (classRaceCR.isNaN()) { return Float.NaN; } CR += calcRaceCR(id); CR += classRaceCR; } // calculate and add CR bonus from templates CR += getTemplateCR(id); // calculate and add in the MISC bonus to CR CR += (float) bonusCheckingFacet.getBonus(id, "MISC", "CR"); // change calculated results of less than CR 1 to fraction format if (CR < 1) { Float crMod = SettingsHandler.getGame().getCRSteps().get((int) CR.floatValue()); if (crMod != null) { CR = crMod; } else { CR = Math.max(CR, 0); } } return CR; }
From source file:org.etudes.mneme.impl.SubmissionStorageSql.java
/** * {@inheritDoc}/*from w w w .j a v a2s .c om*/ */ public Float getSubmissionScore(Submission submission) { // TODO: pre-compute into MNEME_SUBMISSION.TOTAL_SCORE? -ggolden StringBuilder sql = new StringBuilder(); sql.append("SELECT S.EVAL_SCORE, SUM(A.EVAL_SCORE), SUM(A.AUTO_SCORE) FROM MNEME_SUBMISSION S"); sql.append(" JOIN MNEME_ANSWER A ON S.ID=A.SUBMISSION_ID"); sql.append(" WHERE S.ID=?"); sql.append(" GROUP BY S.ID, S.EVAL_SCORE"); Object[] fields = new Object[1]; fields[0] = Long.valueOf(submission.getId()); // to collect the score (we just need something that we can change that is also Final) final List<Float> score = new ArrayList<Float>(); this.sqlService.dbRead(sql.toString(), fields, new SqlReader() { public Object readSqlResultRecord(ResultSet result) { try { Float sEval = SqlHelper.readFloat(result, 1); Float aEval = SqlHelper.readFloat(result, 2); Float aAuto = SqlHelper.readFloat(result, 3); Float total = Float.valueOf( (sEval == null ? 0f : sEval.floatValue()) + (aEval == null ? 0f : aEval.floatValue()) + (aAuto == null ? 0f : aAuto.floatValue())); // massage total - 2 decimal places if (total != null) { total = Float.valueOf(((float) Math.round(total.floatValue() * 100.0f)) / 100.0f); } score.add(total); return null; } catch (SQLException e) { M_log.warn("getSubmissionScore: " + e); return null; } } }); if (score.size() > 0) { return score.get(0); } // TODO: return null here? sample returns 0f -ggolden return Float.valueOf(0f); }
From source file:org.etudes.mneme.impl.SubmissionStorageSql.java
/** * {@inheritDoc}/*from ww w . j a va2 s . co m*/ */ public Map<String, Float> getAssessmentHighestScores(Assessment assessment, Boolean releasedOnly) { StringBuilder sql = new StringBuilder(); sql.append( "SELECT S.ID, S.USERID, S.EVAL_SCORE, SUM(A.EVAL_SCORE), SUM(A.AUTO_SCORE) FROM MNEME_SUBMISSION S"); sql.append(" JOIN MNEME_ANSWER A ON S.ID=A.SUBMISSION_ID"); sql.append(" WHERE S.ASSESSMENT_ID=? AND S.COMPLETE='1' AND S.TEST_DRIVE='0'"); if (releasedOnly) { sql.append(" AND S.RELEASED='1'"); } sql.append(" GROUP BY S.ID, S.USERID, S.EVAL_SCORE"); Object[] fields = new Object[1]; fields[0] = Long.valueOf(assessment.getId()); final Map<String, Float> scores = new HashMap<String, Float>(); this.sqlService.dbRead(sql.toString(), fields, new SqlReader() { public Object readSqlResultRecord(ResultSet result) { try { String sid = SqlHelper.readId(result, 1); String user = SqlHelper.readString(result, 2); Float sEval = SqlHelper.readFloat(result, 3); Float aEval = SqlHelper.readFloat(result, 4); Float aAuto = SqlHelper.readFloat(result, 5); Float total = Float.valueOf( (sEval == null ? 0f : sEval.floatValue()) + (aEval == null ? 0f : aEval.floatValue()) + (aAuto == null ? 0f : aAuto.floatValue())); // massage total - 2 decimal places if (total != null) { total = Float.valueOf(((float) Math.round(total.floatValue() * 100.0f)) / 100.0f); } // if the user has an entry already, replace it if this score is higher Float prior = scores.get(user); if (prior != null) { if (prior.floatValue() < total.floatValue()) { scores.put(user, total); } } else { scores.put(user, total); } return null; } catch (SQLException e) { M_log.warn("getAssessmentHighestScores: " + e); return null; } } }); return scores; }