/** * @return true if the given value is non-null and non-empty */ public static boolean hasValue(String str) { return !isNullOrEmpty(str); }
/** * Converts a given String to lower case with Locale.ENGLISH * * @param str the string to be converted to lower case * @return the lower case of string, or itself if string is null/empty */ public static String lowerCase(String str) { if(isNullOrEmpty(str)) { return str; } return str.toLowerCase(LOCALE_ENGLISH); }
/** * Converts a given String to upper case with Locale.ENGLISH * * @param str the string to be converted to upper case * @return the upper case of string, or itself if string is null/empty */ public static String upperCase(String str) { if(isNullOrEmpty(str)) { return str; } return str.toUpperCase(LOCALE_ENGLISH); }
/** * <p> Asserts that the specified parameter value is neither <code>empty</code> nor null, and if * it is, throws a <code>SdkClientException</code> with the specified error message. </p> * * @param parameterValue The parameter value being checked. * @param errorMessage The error message to include in the SdkClientException if the * specified parameter value is empty. */ private void assertParameterNotEmpty(String parameterValue, String errorMessage) { if (StringUtils.isNullOrEmpty(parameterValue)) { throw new SdkClientException(errorMessage); } }
private void parseNonProxyHosts(String nonProxyHosts) { if (!StringUtils.isNullOrEmpty(nonProxyHosts)) { String[] hosts = nonProxyHosts.split("\\|"); hostPatterns = new String[hosts.length]; for (int i = 0; i < hosts.length; ++i) { hostPatterns[i] = hosts[i].toLowerCase().replace("*", ".*?"); } } }
public static void notEmpty(String in, String fieldName) { if (StringUtils.isNullOrEmpty(in)) { throw new IllegalArgumentException(String.format("%s cannot be empty", fieldName)); } }
/** * Replace all the labels in host with %s symbols and collect the input shape member names into a list */ private void replaceHostLabelsWithStringSpecifier(String hostExpression) { if (StringUtils.isNullOrEmpty(hostExpression)) { throw new IllegalArgumentException("Given host prefix is either null or empty"); } Matcher matcher = PATTERN.matcher(hostExpression); while (matcher.find()) { String matched = matcher.group(1); c2jNames.add(matched); hostWithStringSpecifier = hostWithStringSpecifier.replaceFirst("\\{" + matched + "}", "%s"); } }
/** * Throw exception if timestamp is provided for non-json protocol */ private void validateTimestampProtocol(String protocolString, String timestampFormat, String shape2) { if (!StringUtils.isNullOrEmpty(timestampFormat) && isNonJsonProtocol(protocolString)) { throw new IllegalArgumentException(String.format( "Shape %s has timestamp format provided. Timestamp format for requests is not supported for xml, query or ec2 " + "protocol", shape2)); } }
public static Date parseRfc822Date(String dateString) { if (StringUtils.isNullOrEmpty(dateString)) { return null; } return DateUtils.parseRFC822Date(dateString); }
private static boolean hasServingRegionHeader(HttpResponse response) { return !StringUtils.isNullOrEmpty(getServingRegionHeader(response)); }
/** * TODO The order would make more sense as System Property, Environment Variable, Default * Profile name but we have to keep the current order for backwards compatiblity. Consider * changing this in a future major version. */ public final String loadProfileName() { final String profileEnvVarOverride = getEnvProfileName(); if (!StringUtils.isNullOrEmpty(profileEnvVarOverride)) { return profileEnvVarOverride; } else { final String profileSysPropOverride = getSysPropertyProfileName(); if (!StringUtils.isNullOrEmpty(profileSysPropOverride)) { return profileSysPropOverride; } else { return DEFAULT_PROFILE_NAME; } } }
@Override public AWSCredentials getCredentials() { String accessKey = StringUtils.trim(System.getProperty(ACCESS_KEY_SYSTEM_PROPERTY)); String secretKey = StringUtils.trim(System.getProperty(SECRET_KEY_SYSTEM_PROPERTY)); String sessionToken = StringUtils.trim(System.getProperty(SESSION_TOKEN_SYSTEM_PROPERTY)); if (StringUtils.isNullOrEmpty(accessKey) || StringUtils.isNullOrEmpty(secretKey)) { throw new SdkClientException( "Unable to load AWS credentials from Java system " + "properties (" + ACCESS_KEY_SYSTEM_PROPERTY + " and " + SECRET_KEY_SYSTEM_PROPERTY + ")"); } if (StringUtils.isNullOrEmpty(sessionToken)) { return new BasicAWSCredentials(accessKey, secretKey); } else { return new BasicSessionCredentials(accessKey, secretKey, sessionToken); } }
/** * Asserts the string is not null and not empty, reporting to {@link ProblemReporter} with this context if it is. * * @param propertyValue Value to assert on. * @param propertyName Name of property. */ public void assertStringNotEmpty(String propertyValue, String propertyName) { if (StringUtils.isNullOrEmpty(propertyValue)) { problemReporter.report(new Problem(this, String.format("%s is a required property.", propertyName))); } }
public static JavaVersion parseJavaVersion(final String fullVersionString) { if (!StringUtils.isNullOrEmpty(fullVersionString)) { final Matcher matcher = VERSION_REGEX.matcher(fullVersionString); if (matcher.matches()) { final Integer majorVersionFamily = NumberUtils.tryParseInt(matcher.group(1)); final Integer majorVersion = NumberUtils.tryParseInt(matcher.group(2)); final Integer maintenanceNumber = NumberUtils.tryParseInt(matcher.group(3)); final Integer updateNumber = NumberUtils.tryParseInt(matcher.group(4)); return new JavaVersion(majorVersionFamily, majorVersion, maintenanceNumber, updateNumber); } } return JavaVersion.UNKNOWN; }
private static String uriFrom(Request<?> sdkRequest) { StringBuilder uriBuilder = new StringBuilder(sdkRequest.getEndpoint().toString()); if (!StringUtils.isNullOrEmpty(sdkRequest.getResourcePath())) { uriBuilder.append(sdkRequest.getResourcePath()); } QueryStringEncoder encoder = new QueryStringEncoder(uriBuilder.toString()); for (Map.Entry<String, List<String>> param : sdkRequest.getParameters().entrySet()) { for (String value : param.getValue()) { encoder.addParam(param.getKey(), value); } } return encoder.toString(); }
/** * @param value Raw string representing value of enum * @return HttpMethodName enum or null if value is not present. * @throws IllegalArgumentException If value does not represent a known enum value. */ public static HttpMethodName fromValue(String value) { if (StringUtils.isNullOrEmpty(value)) { return null; } final String upperCaseValue = StringUtils.upperCase(value); for (HttpMethodName httpMethodName : values()) { if (httpMethodName.name().equals(upperCaseValue)) { return httpMethodName; } } throw new IllegalArgumentException("Unsupported HTTP method name " + value); }
@Override public Boolean endpointDiscoveryEnabled() { Boolean endpointDiscoveryEnabled = null; File configFile = locationProvider.getLocation(); if (configFile != null && configFile.exists()) { BasicProfile profile = loadProfile(configFile); if (profile != null && !StringUtils.isNullOrEmpty(profile.getEndpointDiscovery())) { try { endpointDiscoveryEnabled = Boolean.parseBoolean(profile.getEndpointDiscovery()); } catch (Exception e) { throw new RuntimeException("Unable to parse value for " + ProfileKeyConstants.ENDPOINT_DISCOVERY); } } } return endpointDiscoveryEnabled; }
@Override public String getRegion() throws SdkClientException { File configFile = locationProvider.getLocation(); if (configFile != null && configFile.exists()) { BasicProfile profile = loadProfile(configFile); if (profile != null && !StringUtils.isNullOrEmpty(profile.getRegion())) { return profile.getRegion(); } } return null; }
@Override public AmazonServiceException handle(HttpResponse errorResponse) throws Exception { AmazonServiceException ase = createAse(errorResponse); if (ase == null) { throw new SdkClientException("Unable to unmarshall error response from service"); } ase.setHttpHeaders(errorResponse.getHeaders()); if (StringUtils.isNullOrEmpty(ase.getErrorCode())) { ase.setErrorCode(errorResponse.getStatusCode() + " " + errorResponse.getStatusText()); } return ase; }
/** * Initializing the IP finder. */ private void initClients() { if (credsProvider == null || isNullOrEmpty(loadBalancerName) || isNullOrEmpty(region)) throw new IgniteSpiException("One or more configuration parameters are invalid [setCredentialsProvider=" + credsProvider + ", setRegion=" + region + ", setLoadBalancerName=" + loadBalancerName + "]"); if (amazonEC2Client == null) amazonEC2Client = AmazonEC2ClientBuilder.standard().withRegion(region).withCredentials(credsProvider) .build(); if (amazonELBClient == null) amazonELBClient = AmazonElasticLoadBalancingClientBuilder.standard().withRegion(region) .withCredentials(credsProvider).build(); }