List of usage examples for java.lang Float floatValue
@HotSpotIntrinsicCandidate public float floatValue()
From source file:org.etudes.mneme.impl.SubmissionStorageSample.java
/** * {@inheritDoc}/*w w w. j a va 2s.c o m*/ */ public Map<String, Float> getAssessmentHighestScores(Assessment assessment, Boolean releasedOnly) { Map<String, Float> rv = new HashMap<String, Float>(); for (SubmissionImpl submission : this.submissions.values()) { if (submission.getAssessment().equals(assessment) && submission.getIsComplete() && (!submission.getIsTestDrive())) { if (releasedOnly && !submission.getIsReleased()) continue; Float total = submission.getTotalScore(); if (total != null) { Float prior = rv.get(submission.getUserId()); if (prior != null) { if (prior.floatValue() < total.floatValue()) { rv.put(submission.getUserId(), total); } } else { rv.put(submission.getUserId(), total); } } } } return rv; }
From source file:org.apache.pdfbox.pdmodel.font.PDType1CFont.java
/** * {@inheritDoc}/*from w w w . jav a 2 s .c o m*/ */ public float getFontWidth(byte[] bytes, int offset, int length) throws IOException { String name = getName(bytes, offset, length); if (name == null && !Arrays.equals(SPACE_BYTES, bytes)) { log.debug("No name for code " + (bytes[offset] & 0xff) + " in " + this.cffFont.getName()); return 0; } Float width = (Float) this.glyphWidths.get(name); if (width == null) { width = Float.valueOf(getFontMetric().getCharacterWidth(name)); this.glyphWidths.put(name, width); } return width.floatValue(); }
From source file:org.apache.pdfbox.pdmodel.font.PDType1CFont.java
/** * {@inheritDoc}// w w w. java 2s. c om */ public float getFontHeight(byte[] bytes, int offset, int length) throws IOException { String name = getName(bytes, offset, length); if (name == null) { log.debug("No name for code " + (bytes[offset] & 0xff) + " in " + this.cffFont.getName()); return 0; } Float height = (Float) this.glyphHeights.get(name); if (height == null) { height = Float.valueOf(getFontMetric().getCharacterHeight(name)); this.glyphHeights.put(name, height); } return height.floatValue(); }
From source file:plugin.exporttokens.CRToken.java
/** * @see pcgen.io.exporttoken.Token#getToken(java.lang.String, pcgen.core.PlayerCharacter, pcgen.io.ExportHandler) *///w ww . ja v a 2 s. c o m @Override public String getToken(String tokenSource, CharacterDisplay display, ExportHandler eh) { String retString = ""; Float cr = display.calcCR(); String crAsString = Float.toString(cr); String decimalPlaceValue = crAsString.substring(crAsString.length() - 2); if (cr > 0 && cr < 1) { // If the CR is a fractional CR then we convert to a 1/x format Fraction fraction = Fraction.getFraction(cr);// new Fraction(CR); int denominator = fraction.getDenominator(); int numerator = fraction.getNumerator(); retString = numerator + "/" + denominator; } else if (cr >= 1 || cr == 0) { int newCr = -99; if (decimalPlaceValue.equals(".0")) { newCr = (int) cr.floatValue(); } if (newCr > -99) { retString = retString + newCr; } else { retString = retString + cr; } } else if (cr.isNaN()) { retString = "0"; } return retString; }
From source file:org.sakaiproject.entitybroker.impl.external.SakaiExternalIntegrationProvider.java
public void registerStatement(String prefix, String actorEmail, String verbStr, String objectURI, Boolean resultSuccess, Float resultScaledScore) { if (prefix == null || "".equals(prefix)) { throw new IllegalArgumentException("prefix must be set"); }/*w w w . j av a2 s .c o m*/ LRS_Statement statement = new LRS_Statement(actorEmail, verbStr, objectURI); if (resultSuccess != null && resultScaledScore != null) { statement = new LRS_Statement(actorEmail, verbStr, objectURI, resultSuccess.booleanValue(), resultScaledScore.floatValue()); } else { statement = new LRS_Statement(actorEmail, verbStr, objectURI); } learningResourceStoreService.registerStatement(statement, prefix); }
From source file:org.gumtree.vis.awt.time.TimePlotChartEditor.java
/** * Allow the user to change the outline stroke. */// w w w. ja va 2 s .co m private void modifyCurveStroke() { // StrokeChooserPanel panel = new StrokeChooserPanel( // this.curveStrokeSample, createStrokeItems()); // int result = JOptionPane.showConfirmDialog(this, panel, // localizationResources.getString("Stroke_Selection"), // JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE); // // if (result == JOptionPane.OK_OPTION) { // this.curveStrokeSample.setStroke(panel.getSelectedStroke()); // } Float value = (Float) strokeCombo.getSelectedItem(); Stroke stroke = null; if (value > 0) { stroke = new BasicStroke(value.floatValue()); } curveStrokeSample.setStroke(stroke); }
From source file:com.germinus.easyconf.ComponentProperties.java
public float getFloat(String key, Filter filter) { Float value = getFloat(key, filter, null); validateValue(key, value);//from ww w .java2 s. co m return value.floatValue(); }
From source file:org.displaytag.util.NumberUtils.java
/** * <p>Turns a string value into a java.lang.Number.</p> * * <p>First, the value is examined for a type qualifier on the end * (<code>'f','F','d','D','l','L'</code>). If it is found, it starts * trying to create successively larger types from the type specified * until one is found that can represent the value.</p> * * <p>If a type specifier is not found, it will check for a decimal point * and then try successively larger types from <code>Integer</code> to * <code>BigInteger</code> and from <code>Float</code> to * <code>BigDecimal</code>.</p> * * <p>If the string starts with <code>0x</code> or <code>-0x</code>, it * will be interpreted as a hexadecimal integer. Values with leading * <code>0</code>'s will not be interpreted as octal.</p> * * <p>Returns <code>null</code> if the string is <code>null</code>.</p> * * <p>This method does not trim the input string, i.e., strings with leading * or trailing spaces will generate NumberFormatExceptions.</p> * * @param str String containing a number, may be null * @return Number created from the string * @throws NumberFormatException if the value cannot be converted *///from ww w. j av a 2 s . c o m public static Number createNumber(String str) throws NumberFormatException { if (str == null) { return null; } if (StringUtils.isBlank(str)) { throw new NumberFormatException("A blank string is not a valid number"); } if (str.startsWith("--")) { // this is protection for poorness in java.lang.BigDecimal. // it accepts this as a legal value, but it does not appear // to be in specification of class. OS X Java parses it to // a wrong value. return null; } if (str.startsWith("0x") || str.startsWith("-0x")) { return createInteger(str); } char lastChar = str.charAt(str.length() - 1); String mant; String dec; String exp; int decPos = str.indexOf('.'); int expPos = str.indexOf('e') + str.indexOf('E') + 1; if (decPos > -1) { if (expPos > -1) { if (expPos < decPos || expPos > str.length()) { throw new NumberFormatException(str + " is not a valid number."); } dec = str.substring(decPos + 1, expPos); } else { dec = str.substring(decPos + 1); } mant = str.substring(0, decPos); } else { if (expPos > -1) { if (expPos > str.length()) { throw new NumberFormatException(str + " is not a valid number."); } mant = str.substring(0, expPos); } else { mant = str; } dec = null; } if (!Character.isDigit(lastChar) && lastChar != '.') { if (expPos > -1 && expPos < str.length() - 1) { exp = str.substring(expPos + 1, str.length() - 1); } else { exp = null; } //Requesting a specific type.. String numeric = str.substring(0, str.length() - 1); boolean allZeros = isAllZeros(mant) && isAllZeros(exp); switch (lastChar) { case 'l': case 'L': if (dec == null && exp == null && (numeric.charAt(0) == '-' && isDigits(numeric.substring(1)) || isDigits(numeric))) { try { return createLong(numeric); } catch (NumberFormatException nfe) { //Too big for a long } return createBigInteger(numeric); } throw new NumberFormatException(str + " is not a valid number."); case 'f': case 'F': try { Float f = NumberUtils.createFloat(numeric); if (!(f.isInfinite() || (f.floatValue() == 0.0F && !allZeros))) { //If it's too big for a float or the float value = 0 and the string //has non-zeros in it, then float does not have the precision we want return f; } } catch (NumberFormatException nfe) { // ignore the bad number } //$FALL-THROUGH$ case 'd': case 'D': try { Double d = NumberUtils.createDouble(numeric); if (!(d.isInfinite() || (d.floatValue() == 0.0D && !allZeros))) { return d; } } catch (NumberFormatException nfe) { // ignore the bad number } try { return createBigDecimal(numeric); } catch (NumberFormatException e) { // ignore the bad number } //$FALL-THROUGH$ default: throw new NumberFormatException(str + " is not a valid number."); } } else { //User doesn't have a preference on the return type, so let's start //small and go from there... if (expPos > -1 && expPos < str.length() - 1) { exp = str.substring(expPos + 1, str.length()); } else { exp = null; } if (dec == null && exp == null) { //Must be an int,long,bigint try { return createInteger(str); } catch (NumberFormatException nfe) { // ignore the bad number } try { return createLong(str); } catch (NumberFormatException nfe) { // ignore the bad number } return createBigInteger(str); } else { //Must be a float,double,BigDec boolean allZeros = isAllZeros(mant) && isAllZeros(exp); try { Float f = createFloat(str); if (!(f.isInfinite() || (f.floatValue() == 0.0F && !allZeros))) { return f; } } catch (NumberFormatException nfe) { // ignore the bad number } try { Double d = createDouble(str); if (!(d.isInfinite() || (d.doubleValue() == 0.0D && !allZeros))) { return d; } } catch (NumberFormatException nfe) { // ignore the bad number } return createBigDecimal(str); } } }
From source file:com.redhat.lightblue.metadata.parser.JSONMetadataParserTest.java
License:asdf
@Test public void putValueFloat() { ObjectNode parent = new ObjectNode(factory); String name = "foo"; Float value = new Float("123.222"); parser.putValue(parent, name, value); JsonNode x = parent.get(name);/*from w w w . j a v a 2 s .c o m*/ Assert.assertNotNull(x); Assert.assertEquals(value.floatValue(), x.floatValue(), 0.001); }
From source file:org.etudes.mneme.tool.SubmissionScoreDelegate.java
/** * {@inheritDoc}/*w ww . jav a 2s .c om*/ */ public String format(Context context, Object value) { // submission or assessment if (value == null) return null; Submission submission = null; Assessment assessment = null; if (value instanceof Submission) { submission = (Submission) value; assessment = submission.getAssessment(); } else if (value instanceof Assessment) { assessment = (Assessment) value; } if (assessment == null) return value.toString(); // use the {}/{} format if doing feedback, or just {} if not. StringBuffer rv = new StringBuffer(); Boolean review = (Boolean) context.get("review"); String selector = "worth-points"; // if we are doing review and the submission has been graded if ((review != null) && review && (submission != null) && submission.getIsReleased()) { // the total score rv.append("<img style=\"border-style: none;\" src=\"" + context.get("sakai.return.url") + "/icons/grade.png\" alt=\"" + context.getMessages().getString("grade") + "\" />"); Float score = submission.getTotalScore(); rv.append(context.getMessages().getString("grade") + ": " + FormatScoreDelegate.formatScore(score) + " "); selector = "of-points"; boolean partial = submission.getHasUnscoredAnswers(); if (partial) { selector += "-partial"; } if (assessment.getMinScoreSet().booleanValue() && (assessment.getType() != AssessmentType.survey)) { float minScore = (assessment.getMinScore() * assessment.getParts().getTotalPoints().floatValue()) / 100; if (score.floatValue() >= minScore) { context.put("minscoremet", Boolean.TRUE); } } } // add the total possible points for the assessment Float score = assessment.getParts().getTotalPoints(); if (score.equals(Float.valueOf(1))) { selector += "-singular"; } Object[] args = new Object[1]; args[0] = FormatScoreDelegate.formatScore(score); rv.append(context.getMessages().getFormattedMessage(selector, args)); return rv.toString(); }