Example usage for org.apache.commons.lang3 StringUtils isNumeric

List of usage examples for org.apache.commons.lang3 StringUtils isNumeric

Introduction

In this page you can find the example usage for org.apache.commons.lang3 StringUtils isNumeric.

Prototype

public static boolean isNumeric(final CharSequence cs) 

Source Link

Document

Checks if the CharSequence contains only Unicode digits.

Usage

From source file:com.aol.one.patch.DefaultPatcher.java

private void invokeAddMethod(Object object, String fieldName, JsonNode valueNode)
        throws IllegalAccessException, InvocationTargetException, PatchException {

    if (object instanceof Patchable) {
        Patchable patchable = (Patchable) object;
        patchable.addValue(fieldName, valueNode);
        return;/*from  ww w  .j a  v  a 2 s . c om*/
    }

    if (StringUtils.isNumeric(fieldName) && object instanceof java.util.List) {
        List tmpList = (List) object;
        // WARN: inserting JsonNode into list
        tmpList.add(Integer.parseInt(fieldName), valueNode);
        return;
    }

    if (object instanceof java.util.Map) {
        Map tmpMap = (Map) object;
        // WARN: adding (String, Json) entry to Map, type of Map not known.
        tmpMap.put(fieldName, valueNode);
        return;
    }

    // first try to find set+CapitalizedField or add+CapitalizedField
    List<String> methodNames = new ArrayList<>();
    methodNames.add("set" + StringUtils.capitalize(fieldName));
    methodNames.add("add" + StringUtils.capitalize(fieldName));

    List<MethodData> methodDataList = generateMethodData(methodNames, valueNode);

    // final try, standard method
    List<Class<?>> argTypes = new ArrayList<>();
    argTypes.add(String.class);
    argTypes.add(JsonNode.class);

    List<Object> params = new ArrayList<>();
    params.add(fieldName);
    params.add(valueNode);

    MethodData standardMethodData = new MethodData(STANDARD_ADD_METHOD, argTypes, params);
    methodDataList.add(standardMethodData);

    invokeMethodFromMethodDataList(object, methodDataList);
}

From source file:com.agiletec.plugins.jpcrowdsourcing.aps.system.services.comment.ApiCommentInterface.java

public StringApiResponse deleteComment(Properties properties) throws ApiException, Throwable {
    StringApiResponse response = new StringApiResponse();
    try {/*w ww. j  a  v  a  2  s. co  m*/
        String idParam = properties.getProperty("id");
        if (!StringUtils.isNumeric(idParam)) {
            throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "Invalid param '" + idParam,
                    Response.Status.CONFLICT);
        }
        IIdeaComment comment = this.getIdeaCommentManager().getComment(new Integer(idParam).intValue());
        if (null == comment) {
            _logger.warn("comment {} not found", idParam);
            throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR,
                    "Comment with id '" + idParam + "' does not exist", Response.Status.CONFLICT);
        }
        this.getIdeaCommentManager().deleteComment(comment.getId());
        response.setResult(IResponseBuilder.SUCCESS, null);
    } catch (ApiException ae) {
        response.addErrors(ae.getErrors());
        response.setResult(IResponseBuilder.FAILURE, null);
    } catch (Throwable t) {
        _logger.error("Error deleting comment", t);
        throw new ApsSystemException("Error deleting comment", t);
    }
    return response;
}

From source file:com.hortonworks.streamline.streams.security.service.SecurityCatalogResource.java

@GET
@Path("/roles/{roleIdOrName}/children")
@Timed//  www.ja v  a 2s. c o m
public Response listChildRoles(@PathParam("roleIdOrName") String roleIdOrName,
        @Context SecurityContext securityContext) throws Exception {
    SecurityUtil.checkRole(authorizer, securityContext, ROLE_SECURITY_ADMIN);
    Long roleId = StringUtils.isNumeric(roleIdOrName) ? Long.parseLong(roleIdOrName)
            : getIdFromRoleName(roleIdOrName);
    return listChildRoles(roleId, securityContext);
}

From source file:net.ceos.project.poi.annotated.core.CellFormulaConverter.java

/**
 * Transform the start range address to a valid cell position.
 * <p>/*  ww w  .  j  a v  a 2 s.c o  m*/
 * Apply this method in case of the template contain a template range
 * address (eg. 'N:M' or '4:5').
 * <p>
 * The start range address will be treated here.
 * 
 * @param configCriteria
 *            the {@link XConfigCriteria}
 * @param splitted
 *            the base range address to transform
 * @return the range address converted to a valid cell position
 */
private static String transformToStartRange(final XConfigCriteria configCriteria, String startRange) {
    String start = null;
    if (StringUtils.isNumeric(startRange)) {
        start = transformToRange(configCriteria, startRange, configCriteria.getStartCellInmutable());
    } else if (StringUtils.isAlpha(startRange)) {
        start = transformToRange(configCriteria, startRange, configCriteria.getStartRowInmutable());
    }
    return start;
}

From source file:com.willwinder.ugs.nbp.setupwizard.panels.WizardPanelStepCalibration.java

private KeyListener createKeyListenerChangeSetting(Axis axis, JButton buttonUpdateSettings) {
    return new KeyListener() {
        @Override//from w w w .  j  ava 2 s  . c om
        public void keyTyped(KeyEvent event) {

        }

        @Override
        public void keyPressed(KeyEvent event) {

        }

        @Override
        public void keyReleased(KeyEvent event) {
            if (getBackend().getController() != null
                    && getBackend().getController().getFirmwareSettings() != null) {
                try {
                    JTextField source = (JTextField) event.getSource();
                    IFirmwareSettings firmwareSettings = getBackend().getController().getFirmwareSettings();

                    int stepsPerMillimeter = firmwareSettings.getStepsPerMillimeter(axis);
                    if (!StringUtils.isNumeric(source.getText())
                            || source.getText().trim().equalsIgnoreCase(String.valueOf(stepsPerMillimeter))) {
                        buttonUpdateSettings.setEnabled(false);
                    } else if (StringUtils.isNumeric(source.getText())) {
                        buttonUpdateSettings.setEnabled(true);
                    }
                } catch (FirmwareSettingsException e) {
                    e.printStackTrace();
                }
            }
        }
    };
}

From source file:gtu._work.ui.RenameUI.java

private void usePatternNewNameBtnActionPerformed() {
    try {/* w w  w  .  j  av a2 s.co  m*/
        String findFileRegex = Validate.notBlank(findFileRegexText.getText(), "??Regex");
        String renameRegex = Validate.notBlank(renameRegexText.getText(), "??");
        Pattern renameRegexPattern = Pattern.compile("\\#(\\w+)\\#");
        Matcher matcher2 = null;

        Pattern findFileRegexPattern = Pattern.compile(findFileRegex, Pattern.CASE_INSENSITIVE);
        Matcher matcher = null;
        DefaultTableModel model = JTableUtil.createModel(false, "??", "??", "");

        int ind = 1;
        for (XFile f : fileList) {
            matcher = findFileRegexPattern.matcher(f.fileName);
            if (matcher.matches()) {
                StringBuffer sb = new StringBuffer();
                matcher2 = renameRegexPattern.matcher(renameRegex);
                while (matcher2.find()) {
                    String val = matcher2.group(1);
                    if (val.matches("\\d+L")) {
                        int index = Integer.parseInt(val.substring(0, val.length() - 1));
                        matcher2.appendReplacement(sb, DateFormatUtils
                                .format(Long.parseLong(matcher.group(index)), "yyyyMMdd_HHmmss"));
                    } else if (val.equalsIgnoreCase("date")) {
                        matcher2.appendReplacement(sb,
                                DateFormatUtils.format(f.file.lastModified(), "yyyyMMdd_HHmmss"));
                    } else if (val.equalsIgnoreCase("serial")) {
                        matcher2.appendReplacement(sb, String.valueOf(ind++));
                    } else if (StringUtils.isNumeric(val)) {
                        int index = Integer.parseInt(val);
                        matcher2.appendReplacement(sb, matcher.group(index));
                    }
                }
                matcher2.appendTail(sb);
                model.addRow(this.getXFile(f, sb.toString()));
            }
        }
        renameTable.setModel(model);
    } catch (Exception ex) {
        JCommonUtil.handleException(ex);
    }
}

From source file:com.glaf.dts.web.rest.MxQueryResource.java

@GET
@POST/*from   w w  w. j  a  v  a 2  s.  c o  m*/
@Path("/treeJson")
@ResponseBody
@Produces({ MediaType.APPLICATION_OCTET_STREAM })
public byte[] treeJson(@Context HttpServletRequest request) throws IOException {
    JSONArray array = new JSONArray();
    Long nodeId = RequestUtils.getLong(request, "nodeId");
    String nodeCode = request.getParameter("nodeCode");
    String selected = request.getParameter("selected");

    logger.debug(RequestUtils.getParameterMap(request));
    List<TreeModel> treeModels = new java.util.ArrayList<TreeModel>();
    List<String> chooseList = new java.util.ArrayList<String>();
    if (StringUtils.isNotEmpty(selected)) {
        chooseList = StringTools.split(selected);
    }

    TreeModel treeNode = null;

    if (nodeId != null && nodeId > 0) {
        treeNode = treeModelService.getTreeModel(nodeId);
    } else if (StringUtils.isNotEmpty(nodeCode)) {
        treeNode = treeModelService.getTreeModelByCode(nodeCode);
    }
    if (treeNode != null) {
        QueryDefinitionQuery query = new QueryDefinitionQuery();
        List<TreeModel> subTrees = treeModelService.getSubTreeModels(treeNode.getId());
        if (subTrees != null && !subTrees.isEmpty()) {
            for (TreeModel tree : subTrees) {
                tree.getDataMap().put("nocheck", "true");
                tree.getDataMap().put("iconSkin", "tree_folder");
                tree.getDataMap().put("isParent", "true");
                tree.setIconCls("folder");
                tree.setLevel(0);
                treeModels.add(tree);
                query.nodeId(tree.getId());
                List<QueryDefinition> queries = queryDefinitionService.list(query);
                for (QueryDefinition q : queries) {
                    if (StringUtils.isNumeric(q.getId())) {
                        TreeModel t = new BaseTree();
                        t.setId(Long.parseLong(q.getId()));
                        t.setParentId(tree.getId());
                        t.setName(q.getTitle());
                        t.setCode(q.getId());
                        t.setTreeId(q.getId());
                        t.setIconCls("leaf");
                        t.getDataMap().put("iconSkin", "tree_leaf");
                        if (chooseList.contains(q.getId())) {
                            t.setChecked(true);
                        }
                        treeModels.add(t);
                    }
                }
            }
        }
        TreeHelper treeHelper = new TreeHelper();
        array = treeHelper.getTreeJSONArray(treeModels);
    }

    return array.toJSONString().getBytes("UTF-8");
}

From source file:com.nridge.core.base.io.xml.DataTableXML.java

/**
 * Parses an XML DOM element and loads it into a bag/table.
 *
 * @param anElement DOM element.//from   w w  w .ja va 2s  .  co m
 * @throws java.io.IOException I/O related exception.
 */
@Override
public void load(Element anElement) throws IOException {
    Node nodeItem;
    Attr nodeAttr;
    Element nodeElement;
    String nodeName, nodeValue, attrValue;

    attrValue = anElement.getAttribute("name");
    if (StringUtils.isNotEmpty(attrValue))
        mDataTable.setName(attrValue);

    NamedNodeMap namedNodeMap = anElement.getAttributes();
    int attrCount = namedNodeMap.getLength();
    for (int attrOffset = 0; attrOffset < attrCount; attrOffset++) {
        nodeAttr = (Attr) namedNodeMap.item(attrOffset);
        nodeName = nodeAttr.getNodeName();
        nodeValue = nodeAttr.getNodeValue();

        if (StringUtils.isNotEmpty(nodeValue)) {
            if (!StringUtils.equalsIgnoreCase(nodeName, "name"))
                mDataTable.addFeature(nodeName, nodeValue);
        }
    }

    NodeList nodeList = anElement.getChildNodes();
    for (int i = 0; i < nodeList.getLength(); i++) {
        nodeItem = nodeList.item(i);

        if (nodeItem.getNodeType() != Node.ELEMENT_NODE)
            continue;

        nodeName = nodeItem.getNodeName();
        if (nodeName.equalsIgnoreCase("Context")) {
            nodeElement = (Element) nodeItem;
            attrValue = nodeElement.getAttribute("start");
            if (StringUtils.isNumeric(attrValue))
                mContextStart = Integer.parseInt(attrValue);
            attrValue = nodeElement.getAttribute("limit");
            if (StringUtils.isNumeric(attrValue))
                mContextLimit = Integer.parseInt(attrValue);
            attrValue = nodeElement.getAttribute("total");
            if (StringUtils.isNumeric(attrValue))
                mContextTotal = Integer.parseInt(attrValue);
        } else if (nodeName.equalsIgnoreCase("Columns")) {
            nodeElement = (Element) nodeItem;
            DataBagXML dataBagXML = new DataBagXML();
            dataBagXML.load(nodeElement);
            DataBag dataBag = dataBagXML.getBag();
            dataBag.setName(mDataTable.getName());
            mDataTable = new DataTable(dataBag);
        } else if (nodeName.equalsIgnoreCase("Rows")) {
            nodeElement = (Element) nodeItem;
            loadRows(nodeElement);
        }
    }
}

From source file:com.worldline.easycukes.commons.helpers.JSONHelper.java

/**
 * Returns a particular property from a JSONArray
 *
 * @param jsonArray  JSONArray you want to parse
 * @param simpleProp property you're searching for
 * @return An Object matching the required property
 *//*from w  w w  .j  a v  a2 s  .c o m*/
private static Object getProperty(@NonNull JSONArray jsonArray, @NonNull String simpleProp) {
    if (simpleProp.startsWith("[")) {
        final int idx2 = simpleProp.indexOf("]");
        if (idx2 > 0) {
            final String exp = simpleProp.substring(1, idx2);
            if (exp.contains("=")) {
                final String[] expParams = exp.split("=");
                for (final Iterator<JSONObject> iterator = jsonArray.iterator(); iterator.hasNext();) {
                    final JSONObject jsonObject = iterator.next();
                    if (getValue(jsonObject, expParams[0]).equals(expParams[1]))
                        return jsonObject;
                }
            } else if (StringUtils.isNumeric(exp) && jsonArray.size() > Integer.parseInt(exp))
                return jsonArray.get(Integer.parseInt(exp));
        }
    }
    return null;
}

From source file:net.ceos.project.poi.annotated.core.CellFormulaConverter.java

/**
 * Transform the end range address to a valid cell position.
 * <p>/*ww  w  .  java2  s.  co m*/
 * Apply this method in case of the template contain a template range
 * address (eg. 'N:M' or '4:5').
 * <p>
 * The end range address will be treated here.
 * 
 * @param configCriteria
 *            the {@link XConfigCriteria}
 * @param endRange
 *            the base range address to transform
 * @return the range address converted to a valid cell position
 */
private static String transformToEndRange(final XConfigCriteria configCriteria, String endRange) {
    String end = null;
    if (StringUtils.isNumeric(endRange)) {
        end = transformToRange(configCriteria, endRange, configCriteria.getLastCellIndex());
    } else if (StringUtils.isAlpha(endRange)) {
        end = transformToRange(configCriteria, endRange, configCriteria.getSheet().getLastRowNum() + 1);
    }
    return end;
}