Example usage for java.lang Double valueOf

List of usage examples for java.lang Double valueOf

Introduction

In this page you can find the example usage for java.lang Double valueOf.

Prototype

@HotSpotIntrinsicCandidate
public static Double valueOf(double d) 

Source Link

Document

Returns a Double instance representing the specified double value.

Usage

From source file:co.com.soinsoftware.altablero.controller.NoteValueController.java

private NoteValueBO buildNoteValueFromString(final String objectStr) {
    NoteValueBO noteValue = null;//from   w  ww  .  j  av a  2 s .  c  o  m
    final String[] properties = objectStr.split(";");
    int idNoteDefinition = 0;
    int idStudent = 0;
    BigDecimal value = null;
    for (int i = 0; i < properties.length; i++) {
        final String[] property = properties[i].split("=");
        switch (property[0]) {
        case "idNoteDefinition":
            idNoteDefinition = Integer.valueOf(property[1]);
            break;
        case "idStudent":
            idStudent = Integer.valueOf(property[1]);
            break;
        case "value":
            value = BigDecimal.valueOf(Double.valueOf(property[1].replace("_", "")));
            break;
        }
        if (idNoteDefinition > 0 && idStudent > 0 && value != null) {
            noteValue = new NoteValueBO(idNoteDefinition, idStudent, value);
        }
    }
    return noteValue;
}

From source file:com.gallatinsystems.survey.dao.SurveyUtils.java

public static Survey copySurvey(Survey source, SurveyDto dto) {

    final SurveyDAO sDao = new SurveyDAO();
    final Survey tmp = new Survey();

    BeanUtils.copyProperties(source, tmp, Constants.EXCLUDED_PROPERTIES);
    // set name and surveyGroupId to values we got from the dashboard
    tmp.setCode(dto.getCode());/*from   w  w w.j av  a2s  .  c  o  m*/
    tmp.setName(dto.getName());
    tmp.setSurveyGroupId(dto.getSurveyGroupId());

    tmp.setStatus(Survey.Status.COPYING);
    tmp.setPath(getPath(tmp));
    tmp.setVersion(Double.valueOf("1.0"));

    log.log(Level.INFO, "Copying `Survey` " + source.getKey().getId());
    final Survey newSurvey = sDao.save(tmp);

    log.log(Level.INFO, "New `Survey` ID: " + newSurvey.getKey().getId());

    SurveyUtils.copyTranslation(source.getKey().getId(), newSurvey.getKey().getId(), newSurvey.getKey().getId(),
            null, ParentType.SURVEY_NAME, ParentType.SURVEY_DESC);

    log.log(Level.INFO, "Running rest of copy functionality as a task...");

    final Queue queue = QueueFactory.getDefaultQueue();

    final TaskOptions options = TaskOptions.Builder.withUrl("/app_worker/dataprocessor")
            .param(DataProcessorRequest.ACTION_PARAM, DataProcessorRequest.COPY_SURVEY)
            .param(DataProcessorRequest.SURVEY_ID_PARAM, String.valueOf(newSurvey.getKey().getId()))
            .param(DataProcessorRequest.SOURCE_PARAM, String.valueOf(source.getKey().getId()));

    queue.add(options);

    return newSurvey;
}

From source file:NumberUtils.java

/**
 * Parse the given text into a number instance of the given target class,
 * using the corresponding default <code>decode</code> methods. Trims the
 * input <code>String</code> before attempting to parse the number. Supports
 * numbers in hex format (with leading 0x) and in octal format (with leading 0).
 * @param text the text to convert//from   ww  w .  j  a va2  s .co  m
 * @param targetClass the target class to parse into
 * @return the parsed number
 * @throws IllegalArgumentException if the target class is not supported
 * (i.e. not a standard Number subclass as included in the JDK)
 * @see java.lang.Byte#decode
 * @see java.lang.Short#decode
 * @see java.lang.Integer#decode
 * @see java.lang.Long#decode
 * @see #decodeBigInteger(String)
 * @see java.lang.Float#valueOf
 * @see java.lang.Double#valueOf
 * @see java.math.BigDecimal#BigDecimal(String)
 */
public static Number parseNumber(String text, Class<?> targetClass) {
    //   Assert.notNull(text, "Text must not be null");
    //Assert.notNull(targetClass, "Target class must not be null");

    String trimmed = text.trim();

    if (targetClass.equals(Byte.class)) {
        return Byte.decode(trimmed);
    } else if (targetClass.equals(Short.class)) {
        return Short.decode(trimmed);
    } else if (targetClass.equals(Integer.class)) {
        return Integer.decode(trimmed);
    } else if (targetClass.equals(Long.class)) {
        return Long.decode(trimmed);
    } else if (targetClass.equals(BigInteger.class)) {
        return decodeBigInteger(trimmed);
    } else if (targetClass.equals(Float.class)) {
        return Float.valueOf(trimmed);
    } else if (targetClass.equals(Double.class)) {
        return Double.valueOf(trimmed);
    } else if (targetClass.equals(BigDecimal.class) || targetClass.equals(Number.class)) {
        return new BigDecimal(trimmed);
    } else {
        throw new IllegalArgumentException(
                "Cannot convert String [" + text + "] to target class [" + targetClass.getName() + "]");
    }
}

From source file:com.spotify.ffwd.carbon.CarbonDecoder.java

@Override
protected void decode(final ChannelHandlerContext arg0, final String in, final List<Object> out)
        throws Exception {

    final String[] tokens = WHITE_SPACE_PATTERN.split(in);

    if (tokens.length != 3) {
        throw new CorruptedFrameException(String.format("malformed carbon frame (%s)", in));
    }/*from  www .j av  a 2  s.co m*/

    final double value;
    try {
        value = Double.valueOf(tokens[1]);
    } catch (final NumberFormatException e) {
        throw new CorruptedFrameException(String.format("malformed carbon frame (%s), (%s) is an invalid value",
                in, StringEscapeUtils.escapeJava(tokens[1])));
    }

    final long timestamp;
    try {
        timestamp = Long.valueOf(tokens[2]);
    } catch (final NumberFormatException e) {
        throw new CorruptedFrameException(
                String.format("malformed carbon frame (%s), (%s) is an invalid timestamp", in,
                        StringEscapeUtils.escapeJava(tokens[2])));
    }

    final Map<String, String> tags = new HashMap<>();
    tags.put("what", tokens[0]);

    out.add(new Metric(key, value, new Date(timestamp), EMPTY_TAGS, tags, EMPTY_RESOURCE, null));
}

From source file:com.adaptris.core.services.jdbc.DoubleStatementParameter.java

Double toDouble(Object value) throws ServiceException {
    if (isBlank((String) value) && convertNull()) {
        return Double.valueOf(NumberUtils.toDouble((String) value));
    } else {//from  ww  w  .  j  av a  2s  . com
        return Double.valueOf((String) value);
    }
}

From source file:com.itemanalysis.psychometrics.scaling.PercentileRank.java

/**
 * All doubles are converted to integers see page 44, Kolen and Brennan(2004).
 *
 * @param score a test score./*from ww w.j  a  va  2 s .com*/
 */
public void addValue(Double score) {
    int iScore = Double.valueOf(Math.floor(score + 0.5)).intValue();
    if (iScore >= min && iScore <= max) {
        freqTable.addValue(iScore);
    }
}

From source file:com.redhat.lightblue.metadata.types.DoubleType.java

@Override
public Object cast(Object obj) {
    Double value = null;//  w w  w .  j a va  2  s . co  m
    if (obj != null) {
        if (obj instanceof Number) {
            value = ((Number) obj).doubleValue();
        } else if (obj instanceof Boolean) {
            value = ((Boolean) obj) ? 1.0 : 0.0;
        } else if (obj instanceof String) {
            try {
                value = Double.valueOf((String) obj);
            } catch (NumberFormatException e) {
                throw Error.get(NAME, MetadataConstants.ERR_INCOMPATIBLE_VALUE, obj.toString());
            }
        } else {
            throw Error.get(NAME, MetadataConstants.ERR_INCOMPATIBLE_VALUE, obj.toString());
        }
    }
    return value;
}

From source file:com.rptools.io.NameFileParser.java

@Override
protected Names parseFileData(String data) {
    MarkovChain<String, String> markovChain = new MarkovChain<>(this::separateName, JOINER::join);

    Matcher nameMatcher = namePat.matcher(data);

    while (nameMatcher.find()) {
        String[] nameFreq = nameMatcher.group().split(":");
        String name = nameFreq[0];
        Double weight = 1.0;/*from w  w  w .jav a 2  s  .c o  m*/
        if (nameFreq.length > 1) {
            weight = Double.valueOf(nameFreq[1]);
        }
        markovChain.process(name, weight);
    }

    return new Names(markovChain);
}

From source file:com.bigdata.dastor.utils.FBUtilities.java

/**
 * Parses a string representing either a fraction, absolute value or percentage.
 *//*  www  . ja  v a2 s.c om*/
public static double parseDoubleOrPercent(String value) {
    if (value.endsWith("%")) {
        return Double.valueOf(value.substring(0, value.length() - 1)) / 100;
    } else {
        return Double.valueOf(value);
    }
}

From source file:com.mgmtp.perfload.loadprofiles.ui.component.DoubleCellEditor.java

@Override
public boolean stopCellEditing() {
    String s = (String) super.getCellEditorValue();
    JTextField textField = (JTextField) getComponent();

    if (isBlank(s)) {
        textField.setBorder(new LineBorder(Color.red));
        return false;
    }/*from   w  w  w .  j av  a2s  . co  m*/

    try {
        value = Double.valueOf(s);
    } catch (NumberFormatException ex2) {
        try {
            Number n = FORMAT.parse(s);
            value = n.doubleValue();
        } catch (ParseException ex1) {
            textField.setBorder(new LineBorder(Color.red));
            textField.selectAll();
            return false;
        }
    }

    return super.stopCellEditing();
}