Example usage for org.apache.commons.lang3.math NumberUtils isNumber

List of usage examples for org.apache.commons.lang3.math NumberUtils isNumber

Introduction

In this page you can find the example usage for org.apache.commons.lang3.math NumberUtils isNumber.

Prototype

public static boolean isNumber(final String str) 

Source Link

Document

Checks whether the String a valid Java number.

Valid numbers include hexadecimal marked with the 0x or 0X qualifier, octal numbers, scientific notation and numbers marked with a type qualifier (e.g.

Usage

From source file:com.netsteadfast.greenstep.bsc.service.logic.impl.StrategyMapLogicServiceImpl.java

@SuppressWarnings("unchecked")
private void saveNodesAndConnections(StrategyMapVO strategyMap, Map<String, Object> jsonData)
        throws ServiceException, Exception {

    List<Map<String, Object>> connections = (List<Map<String, Object>>) jsonData.get("connections");
    List<Map<String, Object>> nodes = (List<Map<String, Object>>) jsonData.get("nodes");

    for (int i = 0; connections != null && i < connections.size(); i++) {
        Map<String, Object> data = connections.get(i);
        String connectionId = (String) data.get("connectionId");
        String sourceId = (String) data.get("sourceId");
        String targetId = (String) data.get("targetId");
        if (StringUtils.isBlank(connectionId) || StringUtils.isBlank(sourceId)
                || StringUtils.isBlank(targetId)) {
            continue;
        }//  w w w  .  j  ava2s .c  om
        StrategyMapConnsVO mapConns = new StrategyMapConnsVO();
        mapConns.setMasterOid(strategyMap.getOid());
        mapConns.setConnectionId(connectionId);
        mapConns.setSourceId(sourceId);
        mapConns.setTargetId(targetId);
        this.strategyMapConnsService.saveIgnoreUK(mapConns);
    }

    for (int i = 0; nodes != null && i < nodes.size(); i++) {
        Map<String, Object> data = nodes.get(i);
        String id = (String) data.get("id");
        String text = (String) data.get("text");
        String positionX = String.valueOf(data.get("positionX"));
        String positionY = String.valueOf(data.get("positionY"));
        if (StringUtils.isBlank(id) || StringUtils.isBlank(text) || !NumberUtils.isNumber(positionX)
                || !NumberUtils.isNumber(positionY)) {
            continue;
        }
        StrategyMapNodesVO mapNodes = new StrategyMapNodesVO();
        mapNodes.setMasterOid(strategyMap.getOid());
        mapNodes.setId(id);
        mapNodes.setText(text);
        mapNodes.setPositionX(NumberUtils.toInt(positionX));
        mapNodes.setPositionY(NumberUtils.toInt(positionY));
        this.strategyMapNodesService.saveIgnoreUK(mapNodes);
    }

}

From source file:com.netsteadfast.greenstep.bsc.util.AggregationMethod.java

public void averageDistinctDateRange(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;
            }//ww w . j  ava  2 s  .  co m
            BscMeasureData data = new BscMeasureData();
            data.setActual(measureData.getActual());
            data.setTarget(measureData.getTarget());
            try {
                Object value = BscFormulaUtils.parse(kpi.getFormula(), data);
                if (value == null) {
                    continue;
                }
                if (!NumberUtils.isNumber(String.valueOf(value))) {
                    continue;
                }
                float nowScore = NumberUtils.toFloat(String.valueOf(value), 0.0f);
                if (!scores.contains(nowScore)) {
                    scores.add(nowScore);
                    score += nowScore;
                    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));
    }
}

From source file:gov.nih.nci.caintegrator.external.biodbnet.BioDbNetSearchImpl.java

/**
 * Extracts the gene information from a line of bioDbNet gene search results.
 * @param line a gene search result line
 * @return the parsed gene//from  ww  w .j a va 2 s.  c o  m
 */
private GeneResults extractGene(String[] line) {
    Matcher descrptionMatcher = DESCRIPTION_PATTERN.matcher(line[GENE_INFO_INDEX]);
    Matcher taxonMatcher = TAXON_PATTERN.matcher(line[TAXON_INDEX]);

    GeneResults gene = new GeneResults();
    gene.setSymbol(line[GENE_SYMBOL_INDEX]);
    if (NumberUtils.isNumber(line[GENE_ID_INDEX])) {
        gene.setGeneId(Long.valueOf(line[GENE_ID_INDEX]));
    }
    gene.setDescription(getValue(descrptionMatcher));
    gene.setAliases(StringUtils.trim(StringUtils.replaceChars(line[GENE_SYNONYM_INDEX], ';', ',')));
    gene.setTaxon(getValue(taxonMatcher));
    return gene;
}

From source file:gov.nih.nci.caintegrator.web.action.query.form.FoldChangeCriterionWrapper.java

private TextFieldParameter createFoldsUpParameter() {
    final String label = RegulationTypeEnum.UNCHANGED.equals(criterion.getRegulationType()) ? "And"
            : "Up-regulation folds";
    TextFieldParameter foldsParameter = new TextFieldParameter(getParameters().size(), getRow().getRowIndex(),
            criterion.getFoldsUp().toString());
    foldsParameter.setLabel(label);/*w ww. jav a 2s  .co m*/
    ValueHandler foldsChangeHandler = new ValueHandlerAdapter() {

        @Override
        public boolean isValid(String value) {
            return NumberUtils.isNumber(value);
        }

        @Override
        public void validate(String formFieldName, String value, ValidationAware action) {
            if (!isValid(value)) {
                action.addActionError("Numeric value required for " + label);
            }
        }

        @Override
        public void valueChanged(String value) {
            criterion.setFoldsUp(Float.valueOf(value));
        }
    };
    foldsParameter.setValueHandler(foldsChangeHandler);
    return foldsParameter;
}

From source file:com.abixen.platform.service.businessintelligence.multivisualisation.service.impl.DataFileServiceImpl.java

private DataValue getObjForValue(String value) {
    DataValue dataValue;/*w  ww  . ja v  a2  s.  com*/
    if (value == null) {
        dataValue = new DataValueString();
        dataValue.setValue("");
    } else {
        if (NumberUtils.isNumber(value)) {
            if (Ints.tryParse(value) != null) {
                dataValue = new DataValueInteger();
                dataValue.setValue(Integer.parseInt(value));
            } else {
                dataValue = new DataValueDouble();
                dataValue.setValue(Double.parseDouble(value));
            }
        } else {
            dataValue = new DataValueString();
            dataValue.setValue(value);
        }
    }
    return dataValue;
}

From source file:com.reprezen.swagedit.assist.SwaggerProposalProvider.java

protected Collection<Proposal> createEnumProposals(TypeDefinition type, AbstractNode node) {
    final Collection<Proposal> proposals = new LinkedHashSet<>();
    final String subType = type.asJson().has("type") ? //
            type.asJson().get("type").asText() : //
            null;/*from w w  w  . j  a  va2 s . c o  m*/

    String replStr;
    for (String literal : enumLiterals(type)) {
        // if the type of array is string and
        // current value is a number, it should be put
        // into quotes to avoid validation issues
        if ((NumberUtils.isNumber(literal) && "string".equals(subType)) || "null".equals(literal)) {
            replStr = "\"" + literal + "\"";
        } else {
            replStr = literal;
        }

        String labelType = type.getType().getValue();

        proposals.add(new Proposal(replStr, literal, type.getDescription(), labelType));
    }

    return proposals;
}

From source file:gov.nih.nci.caintegrator.security.SecurityManagerImpl.java

@SuppressWarnings(UNCHECKED) // CSM API is untyped
private Set<Long> retrieveAuthorizedStudyElementsGroupIds(Set<ProtectionGroup> protectionGroups)
        throws CSException {
    Set<Long> authorizedStudyElementsGroupIds = new HashSet<Long>();
    for (ProtectionGroup group : protectionGroups) {
        Set<ProtectionElement> elements = getAuthorizationManager()
                .getProtectionElements(String.valueOf(group.getProtectionGroupId()));
        for (ProtectionElement element : elements) {
            if (AUTHORIZED_STUDY_ELEMENTS_GROUP_OBJECT.equals(element.getObjectId())
                    && NumberUtils.isNumber(element.getValue())) {
                authorizedStudyElementsGroupIds.add(Long.valueOf(element.getValue()));
            }/*from w  w  w. j  av a  2  s .c o m*/
        }
    }
    return authorizedStudyElementsGroupIds;
}

From source file:com.drevelopment.couponcodes.canary.coupon.CanaryCouponHandler.java

@Override
public HashMap<Integer, Integer> itemStringToHash(String args, CommandSender sender) {
    HashMap<Integer, Integer> ids = new HashMap<Integer, Integer>();
    String[] sp = args.split(",");
    try {//from   w w w.  j a v  a  2s .co  m
        for (int i = 0; i < sp.length; i++) {
            int a = 0;
            if (NumberUtils.isNumber(sp[i].split(":")[0])) {
                a = Integer.parseInt(sp[i].split(":")[0]);
            } else {
                if (Canary.factory().getItemFactory().newItem(sp[i].split(":")[0]) != null) {
                    a = Canary.factory().getItemFactory().newItem(sp[i].split(":")[0]).getId();
                } else {
                    a = 1;
                }
            }
            int b = Integer.parseInt(sp[i].split(":")[1]);
            ids.put(a, b);
        }
    } catch (NumberFormatException e) {
        e.printStackTrace();
    }
    return ids;
}

From source file:com.efficio.fieldbook.web.nursery.bean.CSVOziel.java

private int findRow(int plot) {
    int row = 0;/*w ww.  ja  v a2 s  . c o m*/

    String plotLabel = getLabel(TermId.PLOT_NO.getId());
    if (plotLabel == null) {
        plotLabel = getLabel(TermId.PLOT_NNO.getId());
    }

    for (MeasurementRow mRow : this.observations) {
        String plotValueStr = mRow.getMeasurementDataValue(plotLabel);
        if (plotValueStr != null && NumberUtils.isNumber(plotValueStr)) {
            int plotValue = Integer.valueOf(plotValueStr);
            if (plotValue == plot) {
                return row;
            }
        }
        row++;
    }

    return row;
}

From source file:com.esri.geoportal.harvester.agp.AgpOutputBroker.java

private Double[] extractEnvelope(String sBbox) {
    Double[] envelope = null;/*from  www .j  a v a  2s . co  m*/
    if (sBbox != null) {
        String[] corners = sBbox.split(",");
        if (corners != null && corners.length == 2) {
            String[] minXminY = corners[0].split(" ");
            String[] maxXmaxY = corners[1].split(" ");
            if (minXminY != null && minXminY.length == 2 && maxXmaxY != null && maxXmaxY.length == 2) {
                minXminY[0] = StringUtils.trimToEmpty(minXminY[0]);
                minXminY[1] = StringUtils.trimToEmpty(minXminY[1]);
                maxXmaxY[0] = StringUtils.trimToEmpty(maxXmaxY[0]);
                maxXmaxY[1] = StringUtils.trimToEmpty(maxXmaxY[1]);

                Double minX = NumberUtils.isNumber(minXminY[0]) ? NumberUtils.createDouble(minXminY[0]) : null;
                Double minY = NumberUtils.isNumber(minXminY[1]) ? NumberUtils.createDouble(minXminY[1]) : null;
                Double maxX = NumberUtils.isNumber(maxXmaxY[0]) ? NumberUtils.createDouble(maxXmaxY[0]) : null;
                Double maxY = NumberUtils.isNumber(maxXmaxY[1]) ? NumberUtils.createDouble(maxXmaxY[1]) : null;

                if (minX != null && minY != null && maxX != null && maxY != null) {
                    envelope = new Double[] { minX, minY, maxX, maxY };
                }
            }
        }
    }
    return envelope;
}