/**
* <p>Checks whether the <code>String</code> contains only
* digit characters.</p>
* <p><code>Null</code> and empty String will return
* <code>false</code>.</p>
* @param str the <code>String</code> to check
* @return <code>true</code> if str contains only Unicode numeric
public static boolean isDigits(final String str) {
return StringUtils.isNumeric(str);
/**
* Checks whether the given String is a UN M.49 numeric area code.
* @param str the String to check
* @return true, is the given String is a UN M.49 numeric area code.
private static boolean isNumericAreaCode(final String str) {
return StringUtils.isNumeric(str) && str.length() == 3;
private boolean isWord(String token) {
boolean isWord = true;
if (token.isEmpty() || StringUtils.isNumeric(token)) {
isWord = false;
} else if (token.length() == 1) {
char c = token.charAt(0);
if (!Character.isLetter(c)) {
isWord = false;
return isWord;
private List<File> listFolders( File rootFolder )
File[] files = fileSystem.listFiles( rootFolder );
return files == null ? Collections.emptyList()
: Stream.of( files )
.filter( f -> fileSystem.isDirectory( f ) && StringUtils.isNumeric( f.getName() ) )
.sorted( FILE_COMPARATOR )
.collect( toList() );
public void setMaxLifetime(String maxLifetime) {
if (StringUtils.isNumeric(maxLifetime)) {
SessionManager.maxLifetime = Long.valueOf(maxLifetime);
} else {
SessionManager.maxLifetime = PropertyConverter.convertStringToTimeMillis(maxLifetime);
log.debug("Max lifetime set to {} ms", SessionManager.maxLifetime);
@Override public boolean accept(final Path fileName) { // The path should start with dir/<prefix> and end with our suffix final String fileNameString = fileName.toString(); if (!fileNameString.startsWith(prefixPathStr)) { return false; if (walFileSuffix.isEmpty()) { // in the case of the null suffix, we need to ensure the filename ends with a timestamp. return org.apache.commons.lang3.StringUtils .isNumeric(fileNameString.substring(prefixPathStr.length())); } else if (!fileNameString.endsWith(walFileSuffix)) { return false; return true;
public static Integer getContentLengthIfPresent(ZuulMessage msg)
final String contentLengthValue = msg.getHeaders().getFirst(com.netflix.zuul.message.http.HttpHeaderNames.CONTENT_LENGTH);
if (StringUtils.isNotEmpty(contentLengthValue) && StringUtils.isNumeric(contentLengthValue)) {
try {
return Integer.valueOf(contentLengthValue);
catch (NumberFormatException e) {
LOG.info("Invalid Content-Length header value on request. " +
"value = " + String.valueOf(contentLengthValue));
return null;
static Path findOriginalBucket(FileSystem fs,
Path directory,
int bucket) throws IOException {
for(FileStatus stat: fs.listStatus(directory)) {
String name = stat.getPath().getName();
String numberPart = name.substring(0, name.indexOf('_'));
if (org.apache.commons.lang3.StringUtils.isNumeric(numberPart) &&
Integer.parseInt(numberPart) == bucket) {
return stat.getPath();
throw new IllegalArgumentException("Can't find bucket " + bucket + " in " +
directory);
public int getLogLevel() {
String value = readProperty(GalenProperty.GALEN_LOG_LEVEL);
if (StringUtils.isNumeric(value)) {
return Integer.parseInt(value);
else return 10;
private Integer parseIntegerParameter(String name, String value) {
if (StringUtils.isNumeric(value)) {
return Integer.parseInt(value);
else throw new SyntaxException(name + " parameter should be integer: " + value);
private TypedEntity getTypedEntityFromServletPathId(String servletPath, String ceilingEntity) {
int idBegIndex = servletPath.indexOf("/", 1);
if (idBegIndex > 0) {
String id = servletPath.substring(idBegIndex + 1, servletPath.length());
if(StringUtils.isNumeric(id)) {
Object objectEntity = genericEntityService.readGenericEntity(ceilingEntity, Long.valueOf(id));
if (TypedEntity.class.isAssignableFrom(objectEntity.getClass())) {
return (TypedEntity) objectEntity;
return null;
private int getMonthFromArguments(Map<String, String> args) {
String monthStr = getRequired("month", args);
int month;
if (StringUtils.isNumeric(monthStr)) {
month = Integer.parseInt(monthStr);
} else {
month = getMonth(monthStr);
return month - 1;
/**
* This method extracts a port number from the serial number of a device.
* It assumes that the device name is of format [xxxx-nnnn] where nnnn is the
* port number.
* @param device The device to extract the port number from.
* @return Returns the port number of the device
private int extractPortFromDevice( IDevice device )
String portStr = StringUtils.substringAfterLast( device.getSerialNumber(), "-" );
if ( StringUtils.isNotBlank( portStr ) && StringUtils.isNumeric( portStr ) )
return Integer.parseInt( portStr );
//If the port is not available then return -1
return -1;
private int getMonthFromArguments(Map<String, String> args) {
String monthStr = getRequired("month", args);
int month;
if (StringUtils.isNumeric(monthStr)) {
month = Integer.parseInt(monthStr);
} else {
month = getMonth(monthStr);
return month - 1;
private int getMonthFromArguments(Map<String, String> args) { String monthStr = getRequired("month", args); int month; if (StringUtils.isNumeric(monthStr)) { month = Integer.parseInt(monthStr); } else { month = getMonth(monthStr); return month - 1;
/**
* Returns true if this qualified name identifies an
* anonymous class.
public boolean isAnonymousClass() {
return !isLocalClass() && StringUtils.isNumeric(getClassSimpleName());
@Test public void testIsNumeric() { assertFalse(StringUtils.isNumeric(null)); assertFalse(StringUtils.isNumeric("")); assertFalse(StringUtils.isNumeric(" ")); assertFalse(StringUtils.isNumeric("a")); assertFalse(StringUtils.isNumeric("A")); assertFalse(StringUtils.isNumeric("kgKgKgKgkgkGkjkjlJlOKLgHdGdHgl")); assertFalse(StringUtils.isNumeric("ham kso")); assertTrue(StringUtils.isNumeric("1")); assertTrue(StringUtils.isNumeric("1000")); assertTrue(StringUtils.isNumeric("\u0967\u0968\u0969")); assertFalse(StringUtils.isNumeric("\u0967\u0968 \u0969")); assertFalse(StringUtils.isNumeric("2.3")); assertFalse(StringUtils.isNumeric("10 00")); assertFalse(StringUtils.isNumeric("hkHKHik6iUGHKJgU7tUJgKJGI87GIkug")); assertFalse(StringUtils.isNumeric("_")); assertFalse(StringUtils.isNumeric("hkHKHik*khbkuh")); assertFalse(StringUtils.isNumeric("+123")); assertFalse(StringUtils.isNumeric("-123"));
public static Integer getContentLengthIfPresent(ZuulMessage msg)
final String contentLengthValue = msg.getHeaders().getFirst(com.netflix.zuul.message.http.HttpHeaderNames.CONTENT_LENGTH);
if (StringUtils.isNotEmpty(contentLengthValue) && StringUtils.isNumeric(contentLengthValue)) {
try {
return Integer.valueOf(contentLengthValue);
catch (NumberFormatException e) {
LOG.info("Invalid Content-Length header value on request. " +
"value = " + String.valueOf(contentLengthValue));
return null;
/**
* If hostname is a.b.c and the port is 123, return a:123 instead of a.b.c:123.
* @return if host looks like it is resolved -- not an IP -- then strip the domain portion
* otherwise returns same as {@link #toString()}}
public String toStringWithoutDomain() {
String hostname = getHostname();
String [] parts = hostname.split("\\.");
if (parts.length > 1) {
for (String part: parts) {
if (!StringUtils.isNumeric(part)) {
return Address.fromParts(parts[0], getPort()).toString();
return toString();
/**
* buildId should only be given when caller is absolutely sure about the job instance
* (makes sense in agent-uploading artifacts/properties scenario because agent won't run a job if its copied over(it only executes real jobs)) -JJ
* This does not return pipelineLabel
public JobIdentifier findJob(String pipelineName, String pipelineCounter, String stageName, String stageCounter, String buildName, Long buildId) {
JobConfigIdentifier jobConfigIdentifier = goConfigService.translateToActualCase(new JobConfigIdentifier(pipelineName, stageName, buildName));
PipelineIdentifier pipelineIdentifier;
if (JobIdentifier.LATEST.equalsIgnoreCase(pipelineCounter)) {
pipelineIdentifier = pipelineService.mostRecentPipelineIdentifier(jobConfigIdentifier.getPipelineName());
} else if (StringUtils.isNumeric(pipelineCounter)) {
pipelineIdentifier = pipelineService.findPipelineByNameAndCounter(pipelineName, Integer.parseInt(pipelineCounter)).getIdentifier();
} else {
throw new RuntimeException("Expected numeric pipeline counter but received '%s'" + pipelineCounter);
stageCounter = StringUtils.isEmpty(stageCounter) ? JobIdentifier.LATEST : stageCounter;
StageIdentifier stageIdentifier = translateStageCounter(pipelineIdentifier, jobConfigIdentifier.getStageName(), stageCounter);
JobIdentifier jobId;
if (buildId == null) {
jobId = jobResolverService.actualJobIdentifier(new JobIdentifier(stageIdentifier, jobConfigIdentifier.getJobName()));
} else {
jobId = new JobIdentifier(stageIdentifier, jobConfigIdentifier.getJobName(), buildId);
if (jobId == null) {
//fix for #5739
throw new JobNotFoundException(pipelineName, stageName, buildName);
return jobId;