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:org.cirdles.ambapo.userInterface.AmbapoUIController.java

private void checkLatLongToUTMCorrect() {
    if (!latitudeText.getText().isEmpty() && !longitudeText.getText().isEmpty()
            && datumChooserUTMAndLatLong.getSelectionModel().getSelectedIndex() > 0
            && NumberUtils.isNumber(latitudeText.getText()) && NumberUtils.isNumber(longitudeText.getText())
            && Double.parseDouble(latitudeText.getText()) >= Coordinate.MIN_LATITUDE
            && Double.parseDouble(latitudeText.getText()) <= Coordinate.MAX_LATITUDE
            && Double.parseDouble(longitudeText.getText()) >= Coordinate.MIN_LONGITUDE
            && Double.parseDouble(longitudeText.getText()) <= Coordinate.MAX_LONGITUDE)
        convertToUTMButton.setDisable(false);
    else/* w w  w .  j  av  a2  s.c o  m*/
        convertToUTMButton.setDisable(true);
}

From source file:org.cirdles.ambapo.userInterface.AmbapoUIController.java

private void checkLatLongToLatLongCorrect() {
    if (!fromLatitude.getText().isEmpty() && !fromLongitude.getText().isEmpty()
            && NumberUtils.isNumber(fromLatitude.getText()) && NumberUtils.isNumber(fromLongitude.getText())
            && Double.parseDouble(fromLatitude.getText()) >= Coordinate.MIN_LATITUDE
            && Double.parseDouble(fromLatitude.getText()) <= Coordinate.MAX_LATITUDE
            && Double.parseDouble(fromLongitude.getText()) >= Coordinate.MIN_LONGITUDE
            && Double.parseDouble(fromLongitude.getText()) <= Coordinate.MAX_LONGITUDE
            && datumChooserLatLongFrom.getSelectionModel().getSelectedIndex() > 0
            && datumChooserLatLongTo.getSelectionModel().getSelectedIndex() > 0) {
        convertFromLatLongToLatLongButton.setDisable(false);
    } else//  ww w .  jav a  2s.  co m
        convertFromLatLongToLatLongButton.setDisable(true);

    if (!toLatitude.getText().isEmpty() && !toLongitude.getText().isEmpty()
            && NumberUtils.isNumber(toLatitude.getText()) && NumberUtils.isNumber(toLongitude.getText())
            && Double.parseDouble(toLatitude.getText()) >= Coordinate.MIN_LATITUDE
            && Double.parseDouble(toLatitude.getText()) <= Coordinate.MAX_LATITUDE
            && Double.parseDouble(toLongitude.getText()) >= Coordinate.MIN_LONGITUDE
            && Double.parseDouble(toLongitude.getText()) <= Coordinate.MAX_LONGITUDE
            && datumChooserLatLongFrom.getSelectionModel().getSelectedIndex() > 0
            && datumChooserLatLongTo.getSelectionModel().getSelectedIndex() > 0) {
        convertRightLatLongToLeftLatLongButton.setDisable(false);
    } else
        convertRightLatLongToLeftLatLongButton.setDisable(true);
}

From source file:org.dussan.vaadin.dcharts.helpers.ChartDataHelper.java

private static boolean isNumber(String value) {
    return (value != null && NumberUtils.isNumber(value));
}

From source file:org.flockdata.geography.dao.GeoSupportNeo.java

private GeoDataBean setFromNode(Tag sourceTag, GeoDataBeans geoBeans, Node node) {
    GeoDataBean geoData = new GeoDataBean();
    String label = getUserDefinedLabel(node);
    // Check we don't add the same tag twice
    if (label != null) {

        String code;//from  w w w .ja  v  a 2s.c o  m
        String name = null;
        Double lat = null;
        Double lon = null;
        code = (String) node.getProperty("code");
        if (node.hasProperty("name")) {
            name = (String) node.getProperty("name");
            if (name.equals(code))
                name = null;
        }
        if (node.hasProperty(Tag.NODE_LAT)) {
            String val = node.getProperty(Tag.NODE_LAT).toString();
            if (NumberUtils.isNumber(val))
                lat = Double.parseDouble(val);
        }

        if (node.hasProperty(Tag.NODE_LON)) {
            String val = node.getProperty(Tag.NODE_LON).toString();
            if (NumberUtils.isNumber(val))
                lon = Double.parseDouble(val);
        }

        geoData.add(label.toLowerCase(), code, name, lat, lon);
        geoBeans.add(label.toLowerCase(), geoData);

        if (label.equals(sourceTag.getLabel())) {
            geoData.setCode(null);
            geoData.setName(null);
        }

    }

    return geoData;
}

From source file:org.flockdata.search.model.SearchTag.java

public SearchTag(EntityTag entityTag) {
    this();/* w w  w. java2 s  .  c o  m*/
    this.code = entityTag.getTag().getCode();
    this.name = entityTag.getTag().getName();

    if (this.name != null && this.name.equalsIgnoreCase(code))
        this.name = null; // Prefer code over name if they are the same

    // DAT-446 - ignore the code if it it is numeric, short and we have a textual name
    if (NumberUtils.isNumber(this.code) && this.code.length() < 3 && this.name != null)
        this.code = null;

    for (String key : entityTag.getTag().getProperties().keySet()) {
        if (!TagHelper.isSystemKey(key)) {
            if (properties == null)
                properties = new HashMap<>();
            this.properties.put(key, entityTag.getTag().getProperty(key));
        }
    }
    handleSubTags(entityTag);

    if (entityTag.getGeoData() != null) {
        if (geo == null)
            geo = new HashMap<>();
        for (String s : entityTag.getGeoData().getGeoBeans().keySet()) {
            Object geoCode = entityTag.getGeoData().getGeoBeans().get(s).getCode();
            if (geoCode != null)
                geo.put(s + "Code", geoCode);
            if (entityTag.getGeoData().getGeoBeans().get(s).getName() != null)
                geo.put(s + "Name", entityTag.getGeoData().getGeoBeans().get(s).getName());
            if (entityTag.getGeoData().getPoints() != null) {
                geo.put("points", entityTag.getGeoData().getPoints());
            }
            this.geoDesc = entityTag.getGeoData().getDescription();
        }

        //this.geoDesc =entityTag.getGeoData().getDescription();
    }
    if (entityTag.getProperties() != null && !entityTag.getProperties().isEmpty()) {
        this.rlx = new HashMap<>();
        // Know one will want to see these column values. Applicable for a graph viz.
        entityTag.getProperties().keySet().stream().filter(key -> !isSystemKey(key)).forEach(key -> {
            rlx.put(key, entityTag.getProperties().get(key));
        });
    }

}

From source file:org.flockdata.transform.ExpressionHelper.java

public static Object getValue(Object value, ColumnDefinition colDef) {

    //        context.setVariable("colDef",colDef);
    if (value == null || value.equals("null"))
        return null;
    else if (NumberUtils.isNumber(value.toString())) {
        if (colDef != null && colDef.getDataType() != null && colDef.getDataType().equalsIgnoreCase("string"))
            return String.valueOf(value);
        else//from w w w .  ja va2 s .c  om
            return NumberUtils.createNumber(value.toString());
    } else {
        return value.toString().trim();
    }
}

From source file:org.flockdata.transform.TransformationHelper.java

static String getDataType(Object value, String column) {

    if (value == null)
        return null;

    Boolean tryAsNumber = true;/*from  w  ww  . j  av  a  2 s. co m*/
    Boolean tryAsDate = true;
    String dataType = null;

    // Code values are always strings
    if (column != null && (column.equals("code") || column.equals("name"))) {
        dataType = "string";
        tryAsNumber = false;
        tryAsDate = false;
    }

    if (tryAsDate) {
        if (isDate(value)) {
            dataType = "date";
            tryAsNumber = false;
        }
    }

    if (value.toString().startsWith("0x"))
        // Treating Hex as String
        return "string";

    if (tryAsNumber) {

        if (NumberUtils.isNumber(value.toString())) {
            value = NumberUtils.createNumber(value.toString());
            if (value != null)
                dataType = "number";
        } else
            dataType = "string";
    }

    return dataType;

}

From source file:org.flockdata.transform.TransformationHelper.java

public static Object transformValue(Object value, String column, ColumnDefinition colDef) {

    if (value == null)
        return null;

    Boolean tryAsNumber = true;//w ww .  j a  va 2s . c  o m
    String dataType = null;
    if (colDef != null) {
        dataType = colDef.getDataType();

        if (dataType == null && evaluate(colDef.isTag())) {
            dataType = "string";
            tryAsNumber = false;
        }

    }

    // Code values are always strings
    if (column != null && (column.equals("code") || column.equals("name"))) {
        dataType = "string";
        tryAsNumber = false;
    }

    if (value.toString().startsWith("0x"))
        // Treating Hex as String
        return value.toString();

    if (dataType != null) {
        if (dataType.equalsIgnoreCase("string") || dataType.equalsIgnoreCase("date"))
            tryAsNumber = false;
        else if (dataType.equalsIgnoreCase("number")) {
            tryAsNumber = true;
            // User wants us to coerce this to a number
            // To do so requires tidying up a few common formatting issues
            value = removeLeadingZeros(value.toString());
            value = removeSeparator(value.toString());// Sets an empty string to null

        }
    }

    if (tryAsNumber) {

        if (value != null && NumberUtils.isNumber(value.toString())) {
            if (dataType != null && dataType.equals("double"))
                value = value + "d";
            value = NumberUtils.createNumber(value.toString());
        } else if (dataType != null && dataType.equalsIgnoreCase("number")) {
            // Force to a number as it was not detected
            value = NumberUtils.createNumber(colDef == null ? "0" : colDef.getValueOnError());
        }
    }

    return value;

}

From source file:org.flowable.app.service.runtime.FlowableAbstractTaskService.java

public void fillPermissionInformation(TaskRepresentation taskRepresentation, TaskInfo task, User currentUser) {

    String processInstanceStartUserId = null;
    boolean initiatorCanCompleteTask = true;
    boolean isMemberOfCandidateGroup = false;
    boolean isMemberOfCandidateUsers = false;

    if (task.getProcessInstanceId() != null) {

        HistoricProcessInstance historicProcessInstance = historyService.createHistoricProcessInstanceQuery()
                .processInstanceId(task.getProcessInstanceId()).singleResult();

        if (historicProcessInstance != null
                && StringUtils.isNotEmpty(historicProcessInstance.getStartUserId())) {
            processInstanceStartUserId = historicProcessInstance.getStartUserId();
            BpmnModel bpmnModel = repositoryService.getBpmnModel(task.getProcessDefinitionId());
            FlowElement flowElement = bpmnModel.getFlowElement(task.getTaskDefinitionKey());
            if (flowElement instanceof UserTask) {
                UserTask userTask = (UserTask) flowElement;
                List<ExtensionElement> extensionElements = userTask.getExtensionElements()
                        .get("initiator-can-complete");
                if (CollectionUtils.isNotEmpty(extensionElements)) {
                    String value = extensionElements.get(0).getElementText();
                    if (StringUtils.isNotEmpty(value)) {
                        initiatorCanCompleteTask = Boolean.valueOf(value);
                    }//from  ww w  .j a v a 2 s  .  c  om
                }

                Map<String, Object> variableMap = new HashMap<String, Object>();
                if ((CollectionUtils.isNotEmpty(userTask.getCandidateGroups())
                        && userTask.getCandidateGroups().size() == 1
                        && userTask.getCandidateGroups().get(0)
                                .contains("${taskAssignmentBean.assignTaskToCandidateGroups('"))
                        || (CollectionUtils.isNotEmpty(userTask.getCandidateUsers())
                                && userTask.getCandidateUsers().size() == 1
                                && userTask.getCandidateUsers().get(0)
                                        .contains("${taskAssignmentBean.assignTaskToCandidateUsers('"))) {

                    List<HistoricVariableInstance> processVariables = historyService
                            .createHistoricVariableInstanceQuery()
                            .processInstanceId(task.getProcessInstanceId()).list();
                    if (CollectionUtils.isNotEmpty(processVariables)) {
                        for (HistoricVariableInstance historicVariableInstance : processVariables) {
                            variableMap.put(historicVariableInstance.getVariableName(),
                                    historicVariableInstance.getValue());
                        }
                    }
                }

                if (CollectionUtils.isNotEmpty(userTask.getCandidateGroups())) {
                    List<? extends Group> groups = remoteIdmService.getUser(currentUser.getId()).getGroups();
                    if (CollectionUtils.isNotEmpty(groups)) {

                        List<String> groupIds = new ArrayList<String>();
                        if (userTask.getCandidateGroups().size() == 1 && userTask.getCandidateGroups().get(0)
                                .contains("${taskAssignmentBean.assignTaskToCandidateGroups('")) {

                            String candidateGroupString = userTask.getCandidateGroups().get(0);
                            candidateGroupString = candidateGroupString
                                    .replace("${taskAssignmentBean.assignTaskToCandidateGroups('", "");
                            candidateGroupString = candidateGroupString.replace("', execution)}", "");
                            String groupsArray[] = candidateGroupString.split(",");
                            for (String group : groupsArray) {
                                if (group.contains("field(")) {
                                    String fieldCandidate = group.trim().substring(6, group.length() - 1);
                                    Object fieldValue = variableMap.get(fieldCandidate);
                                    if (fieldValue != null && NumberUtils.isNumber(fieldValue.toString())) {
                                        groupIds.add(fieldValue.toString());
                                    }

                                } else {
                                    groupIds.add(group);
                                }
                            }

                        } else {
                            groupIds.addAll(userTask.getCandidateGroups());
                        }

                        for (Group group : groups) {
                            if (groupIds.contains(String.valueOf(group.getId()))) {
                                isMemberOfCandidateGroup = true;
                                break;
                            }
                        }
                    }
                }

                if (CollectionUtils.isNotEmpty(userTask.getCandidateUsers())) {
                    if (userTask.getCandidateUsers().size() == 1 && userTask.getCandidateUsers().get(0)
                            .contains("${taskAssignmentBean.assignTaskToCandidateUsers('")) {

                        String candidateUserString = userTask.getCandidateUsers().get(0);
                        candidateUserString = candidateUserString
                                .replace("${taskAssignmentBean.assignTaskToCandidateUsers('", "");
                        candidateUserString = candidateUserString.replace("', execution)}", "");
                        String users[] = candidateUserString.split(",");
                        for (String user : users) {
                            if (user.contains("field(")) {
                                String fieldCandidate = user.substring(6, user.length() - 1);
                                Object fieldValue = variableMap.get(fieldCandidate);
                                if (fieldValue != null && NumberUtils.isNumber(fieldValue.toString())
                                        && String.valueOf(currentUser.getId()).equals(fieldValue.toString())) {

                                    isMemberOfCandidateGroup = true;
                                    break;
                                }

                            } else if (user.equals(String.valueOf(currentUser.getId()))) {
                                isMemberOfCandidateGroup = true;
                                break;
                            }
                        }

                    } else if (userTask.getCandidateUsers().contains(String.valueOf(currentUser.getId()))) {
                        isMemberOfCandidateUsers = true;
                    }
                }
            }
        }
    }

    taskRepresentation.setProcessInstanceStartUserId(processInstanceStartUserId);
    taskRepresentation.setInitiatorCanCompleteTask(initiatorCanCompleteTask);
    taskRepresentation.setMemberOfCandidateGroup(isMemberOfCandidateGroup);
    taskRepresentation.setMemberOfCandidateUsers(isMemberOfCandidateUsers);
}

From source file:org.flowable.cmmn.editor.json.converter.HumanTaskJsonConverter.java

protected int getExtensionElementValueAsInt(String name, HumanTask humanTask) {
    int intValue = 0;
    String value = getExtensionElementValue(name, humanTask);
    if (value != null && NumberUtils.isNumber(value)) {
        intValue = Integer.valueOf(value);
    }/*w  w w  . ja v  a  2 s .c  om*/
    return intValue;
}