Java Code Examples for org.apache.commons.lang3.math.NumberUtils.isDigits()

The following are Jave code examples for showing how to use isDigits() of the org.apache.commons.lang3.math.NumberUtils class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: solo-spring   File: Requests.java   View Source Code Vote up 6 votes
/**
 * Gets the request page number from the specified path.
 *
 * @param path
 *            the specified path, see {@link #PAGINATION_PATH_PATTERN} for
 *            the details
 * @return page number, returns {@code 1} if the specified request URI can
 *         not convert to an number
 * @see #PAGINATION_PATH_PATTERN
 */
public static int getCurrentPageNum(final String path) {
	logger.trace("Getting current page number[path={}]", path);

	if (StringUtils.isBlank(path) || path.equals("/")) {
		return 1;
	}

	final String currentPageNumber = path.split("/")[0];

	if (!NumberUtils.isDigits(currentPageNumber)) {
		return 1;
	}

	return Integer.valueOf(currentPageNumber);
}
 
Example 2
Project: solo-spring   File: Requests.java   View Source Code Vote up 6 votes
/**
 * Gets the request page size from the specified path.
 *
 * @param path
 *            the specified path, see {@link #PAGINATION_PATH_PATTERN} for
 *            the details
 * @return page number, returns {@value #DEFAULT_PAGE_SIZE} if the specified
 *         request URI can not convert to an number
 * @see #PAGINATION_PATH_PATTERN
 */
public static int getPageSize(final String path) {
	logger.trace("Page number[string={}]", path);

	if (StringUtils.isBlank(path)) {
		return DEFAULT_PAGE_SIZE;
	}

	final String[] parts = path.split("/");

	if (1 >= parts.length) {
		return DEFAULT_PAGE_SIZE;
	}

	final String pageSize = parts[1];

	if (!NumberUtils.isDigits(pageSize)) {
		return DEFAULT_PAGE_SIZE;
	}

	return Integer.valueOf(pageSize);
}
 
Example 3
Project: solo-spring   File: Requests.java   View Source Code Vote up 6 votes
/**
 * Gets the request window size from the specified path.
 *
 * @param path
 *            the specified path, see {@link #PAGINATION_PATH_PATTERN} for
 *            the details
 * @return page number, returns {@value #DEFAULT_WINDOW_SIZE} if the
 *         specified request URI can not convert to an number
 * @see #PAGINATION_PATH_PATTERN
 */
public static int getWindowSize(final String path) {
	logger.trace("Page number[string={}]", path);

	if (StringUtils.isBlank(path)) {
		return DEFAULT_WINDOW_SIZE;
	}

	final String[] parts = path.split("/");

	if (2 >= parts.length) {
		return DEFAULT_WINDOW_SIZE;
	}

	final String windowSize = parts[2];

	if (!NumberUtils.isDigits(windowSize)) {
		return DEFAULT_WINDOW_SIZE;
	}

	return Integer.valueOf(windowSize);
}
 
Example 4
Project: OperatieBRP   File: ValideerZoekCriteriaServiceImpl.java   View Source Code Vote up 6 votes
private void valideerWaardeEnDataTypeKomenOvereen(final AttribuutElement attribuutElement, final String waarde, final Set<Melding> meldingen) {
    final ElementBasisType datatype = attribuutElement.getDatatype();
    boolean logMelding = false;
    if (datatype == ElementBasisType.DATUMTIJD) {
        try {
            datumService.parseDateTime(waarde);
        } catch (StapMeldingException e) {
            LOGGER.debug("datum tijd in zoekcriteria niet geldig", e);
            logMelding = true;
        }
    } else if (datatype == ElementBasisType.BOOLEAN) {
        if (!"n".equalsIgnoreCase(waarde) && !"j".equalsIgnoreCase(waarde)) {
            logMelding = true;
        }
    } else if (attribuutElement.isGetal() && !NumberUtils.isDigits(waarde)) {
        logMelding = true;
    }

    if (logMelding) {
        LOGGER.debug(String.format(FOUT_MELDING, Regel.R2308.toString(), attribuutElement.getElementNaam()));
        meldingen.add(new Melding(Regel.R2308));
    }
}
 
Example 5
Project: solo-spring   File: PermalinkQueryService.java   View Source Code Vote up 5 votes
/**
 * Checks whether the specified user-defined permalink is invalid on format.
 * 
 * @param permalink
 *            the specified user-defined permalink
 * @return {@code true} if invalid, returns {@code false} otherwise
 */
private static boolean invalidUserDefinedPermalinkFormat(final String permalink) {
	if (StringUtils.isBlank(permalink)) {
		return true;
	}

	if (isReservedLink(permalink)) {
		return true;
	}
	if (NumberUtils.isDigits(permalink.substring(1))) {
		// See issue 120
		// (http://code.google.com/p/b3log-solo/issues/detail?id=120#c4) for
		// more details
		return true;
	}

	int slashCnt = 0;

	for (int i = 0; i < permalink.length(); i++) {
		if ('/' == permalink.charAt(i)) {
			slashCnt++;
		}

		if (slashCnt > 1) {
			return true;
		}
	}

	return !UrlValidator.getInstance().isValid(Latkes.getServer() + permalink);
}
 
Example 6
Project: para-search-elasticsearch   File: ElasticSearchUtils.java   View Source Code Vote up 5 votes
/**
 * @param from from value
 * @param to to value
 * @return either "properties.vn" if one of the range limits is a number, or "properties.v" otherwise.
 */
static String getValueFieldNameFromRange(String from, String to) {
	if (("*".equals(from) && "*".equals(to)) || NumberUtils.isDigits(from) || NumberUtils.isDigits(to)) {
		return PROPS_PREFIX + "vn";
	}
	return PROPS_PREFIX + "v";
}
 
Example 7
Project: gitplex-mit   File: GitVersion.java   View Source Code Vote up 5 votes
public GitVersion(String versionStr) {
	for (String each: LoaderUtils.splitAndTrim(versionStr, ".")) {
		if (NumberUtils.isDigits(each))
			parts.add(Integer.valueOf(each));
		else if (each.equals("msysgit"))
			msysgit = true;
	}
}
 
Example 8
Project: NGB-master   File: AbstractHTTPCommandHandler.java   View Source Code Vote up 5 votes
/**
 * Retrieves BiologicalDataItemID for a file from an input String.
 * If input String might be interpreted as a number, this number will be returned as a result.
 * If input String isn't a number, method interprets it as a file name and tries to find a file
 * with such a name in the NGB server and retrieves its ID from a loaded data.
 * @param strId input String for file identification
 * @return BiologicalDataItemID of a file
 * @throws ApplicationException if method fails to find a file
 */
protected Long parseFileId(String strId) {
    if (NumberUtils.isDigits(strId)) {
        return Long.parseLong(strId);
    } else {
        List<BiologicalDataItem> items = loadItemsByName(strId);
        if (items == null || items.isEmpty()) {
            throw new ApplicationException(getMessage(ERROR_FILE_NOT_FOUND, strId));
        }
        if (items.size() > 1) {
            LOGGER.error(getMessage(SEVERAL_RESULTS_FOR_QUERY, strId));
        }
        return items.get(0).getBioDataItemId();
    }
}
 
Example 9
Project: NGB-master   File: AbstractHTTPCommandHandler.java   View Source Code Vote up 5 votes
/**
 * Loads BiologicalDataItem file from NGB server by an input String.
 * If input String might be interpreted as a number, item will be loaded by BiologicalDataItemID.
 * If input String isn't a number, method interprets it as a file name and tries to find a file
 * with such a name in the NGB server.
 * @param strId input String for file identification
 * @return BiologicalDataItem representing file
 * @throws ApplicationException if method fails to find a file
 */
protected BiologicalDataItem loadFileByNameOrBioID(String strId) {
    if (NumberUtils.isDigits(strId)) {
        return loadFileByBioID(strId);
    } else {
        List<BiologicalDataItem> items = loadItemsByName(strId);
        if (items == null || items.isEmpty()) {
            throw new ApplicationException(getMessage(ERROR_FILE_NOT_FOUND, strId));
        }
        if (items.size() > 1) {
            LOGGER.error(getMessage(SEVERAL_RESULTS_FOR_QUERY, strId));
        }
        return items.get(0);
    }
}
 
Example 10
Project: NGB-master   File: AbstractHTTPCommandHandler.java   View Source Code Vote up 5 votes
/**
 * Retrieves reference ID from an input String.
 * If input String might be interpreted as a number, this number is assumed to be a BiologicalDataItemID
 * for a reference and thus a reference is loaded from the server by this BiologicalDataItemID.
 * If input String isn't a number, method interprets it as a file name, tries to find a reference
 * with such a name in the NGB server and retrieves its ID from a loaded data.
 * @param strId input String for reference identification
 * @return ID of a reference
 */
//TODO: remove this method and all connected logic when ID and BiologicalDataItemID are merged on the server
protected Long loadReferenceId(String strId) {
    if (NumberUtils.isDigits(strId)) {
        BiologicalDataItem reference = loadFileByBioID(strId);
        return reference.getId();
    } else {
        List<BiologicalDataItem> items = loadItemsByName(strId);
        checkLoadedItems(strId, items);
        return items.get(0).getId();
    }
}
 
Example 11
Project: NGB-master   File: AbstractHTTPCommandHandler.java   View Source Code Vote up 5 votes
/**
 * Retrieves ID for a dataset(project) from an input String.
 * If input String might be interpreted as a number, this number will be returned as a result.
 * If input String isn't a number, method interprets it as a dataset name and tries to find a file
 * with such a name in the NGB server and retrieves its ID from a loaded data.
 * @param strId input String for dataset identification
 * @return ID of a dataset
 */
protected Long parseProjectId(String strId) {
    if (NumberUtils.isDigits(strId)) {
        return Long.parseLong(strId);
    } else {
        Project project = loadProjectByName(strId);
        return project.getId();
    }
}
 
Example 12
Project: NGB-master   File: UrlGeneratorHandler.java   View Source Code Vote up 5 votes
@Override
public void parseAndVerifyArguments(List<String> arguments, ApplicationOptions options) {
    if (CollectionUtils.isEmpty(arguments)) {
        throw new IllegalArgumentException(MessageConstants
                .getMessage(MINIMUM_COMMAND_ARGUMENTS, getCommand(), 1, arguments.size()));
    }

    dataset = arguments.get(0);
    ids = arguments.subList(1, arguments.size());

    printJson = options.isPrintJson();
    printTable = options.isPrintTable();

    String location = options.getLocation();
    if (StringUtils.isNoneBlank(location)) {
        String[] parts = location.split(":");
        chrName = parts[0];

        if (parts.length > 1 && parts[1].contains("-")) {
            String[] subParts = parts[1].split("-");
            if (NumberUtils.isDigits(subParts[0])) {
                startIndex = Integer.parseInt(subParts[0]);
            }
            if (NumberUtils.isDigits(subParts[1])) {
                endIndex = Integer.parseInt(subParts[1]);
            }
        }
    }
}
 
Example 13
Project: spring-boot-seed   File: FTPClientImpl.java   View Source Code Vote up 4 votes
/**
 * 执行FTP回调操作的方法
 *
 * @param <T>      the type parameter
 * @param callback 回调的函数
 * @return the t
 * @throws IOException the io exception
 */
public <T> T execute(FTPClientCallback<T> callback) throws IOException {
    FTPClient ftp = new FTPClient();
    try {
        //登录FTP服务器
        try {
            //设置超时时间
            ftp.setDataTimeout(7200);
            //设置默认编码
            ftp.setControlEncoding(DEAFULT_REMOTE_CHARSET);
            //设置默认端口
            ftp.setDefaultPort(DEAFULT_REMOTE_PORT);
            //设置是否显示隐藏文件
            ftp.setListHiddenFiles(false);
            //连接ftp服务器
            if (StringUtils.isNotEmpty(port) && NumberUtils.isDigits(port)) {
                ftp.connect(host, Integer.valueOf(port));
            } else {
                ftp.connect(host);
            }
        } catch (ConnectException e) {
            logger.error("连接FTP服务器失败:" + ftp.getReplyString() + ftp.getReplyCode());
            throw new IOException("Problem connecting the FTP-server fail", e);
        }
        //得到连接的返回编码
        int reply = ftp.getReplyCode();

        if (!FTPReply.isPositiveCompletion(reply)) {
            ftp.disconnect();
        }
        //登录失败权限验证失败
        if (!ftp.login(getUsername(), getPassword())) {
            ftp.quit();
            ftp.disconnect();
            logger.error("连接FTP服务器用户或者密码失败::" + ftp.getReplyString());
            throw new IOException("Cant Authentificate to FTP-Server");
        }
        if (logger.isDebugEnabled()) {
            logger.info("成功登录FTP服务器:" + host + " 端口:" + port);
        }
        ftp.setFileType(FTPClient.BINARY_FILE_TYPE);
        //回调FTP的操作
        return callback.doTransfer(ftp);
    } finally {
        //FTP退出
        ftp.logout();
        //断开FTP连接
        if (ftp.isConnected()) {
            ftp.disconnect();
        }
    }
}
 
Example 14
Project: smockin   File: GeneralUtils.java   View Source Code Vote up 3 votes
public static int exactVersionNo(String versionNo) {

        if (versionNo == null)
            throw new IllegalArgumentException("versionNo is not defined");

        versionNo = org.apache.commons.lang3.StringUtils.removeIgnoreCase(versionNo, "-SNAPSHOT");
        versionNo = org.apache.commons.lang3.StringUtils.remove(versionNo, ".");

        if (!NumberUtils.isDigits(versionNo))
            throw new IllegalArgumentException("extracted versionNo is not a valid number: " + versionNo);

        return Integer.valueOf(versionNo);
    }
 
Example 15
Project: para-search-elasticsearch   File: ElasticSearchUtils.java   View Source Code Vote up 2 votes
/**
 * @param v search term
 * @return the name of the value property inside a nested object, e.g. "properties.v"
 */
static String getValueFieldName(String v) {
	return PROPS_PREFIX + (NumberUtils.isDigits(v) ? "vn" : "v");
}
 
Example 16
Project: para-search-elasticsearch   File: ElasticSearchUtils.java   View Source Code Vote up 2 votes
/**
 * @param v search term
 * @return the long value of v if it is a number
 */
static Object getNumericValue(String v) {
	return NumberUtils.isDigits(v) ? NumberUtils.toLong(v, 0) : v;
}