下面列出了org.apache.commons.lang3.StringUtils#isEmpty ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
public Strength getScore(final String password) {
if(StringUtils.isEmpty(password)) {
return Strength.veryweak;
}
else {
final int score = zxcvbn.measure(password, Collections.singletonList(
PreferencesFactory.get().getProperty("application.name"))).getScore();
switch(score) {
case 0:
return Strength.veryweak;
case 1:
return Strength.weak;
case 2:
return Strength.fair;
case 3:
return Strength.strong;
case 4:
default:
return Strength.verystrong;
}
}
}
private Observable<ResourceResponse<Permission>> readPermissionInternal(String permissionLink, RequestOptions options, IDocumentClientRetryPolicy retryPolicyInstance ) {
try {
if (StringUtils.isEmpty(permissionLink)) {
throw new IllegalArgumentException("permissionLink");
}
logger.debug("Reading a Permission. permissionLink [{}]", permissionLink);
String path = Utils.joinPath(permissionLink, null);
Map<String, String> requestHeaders = getRequestHeaders(options);
RxDocumentServiceRequest request = RxDocumentServiceRequest.create(OperationType.Read,
ResourceType.Permission, path, requestHeaders, options);
if (retryPolicyInstance != null) {
retryPolicyInstance.onBeforeSendRequest(request);
}
return this.read(request).map(response -> toResourceResponse(response, Permission.class));
} catch (Exception e) {
logger.debug("Failure in reading a Permission due to [{}]", e.getMessage(), e);
return Observable.error(e);
}
}
/**
* API to post a bunch of strings
*
*/
@ApiOperation(value = APIOperation.KEY_SET_POST_VALUE, notes = APIOperation.KEY_SET_POST_NOTES)
@RequestMapping(value = APIV2.KEY_SET_POST, method = RequestMethod.POST, produces = { API.API_CHARSET })
@ResponseStatus(HttpStatus.OK)
public APIResponseDTO postSources(
@ApiParam(name = APIParamName.PRODUCT_NAME, required = true, value = APIParamValue.PRODUCT_NAME) @PathVariable(APIParamName.PRODUCT_NAME) String productName,
@ApiParam(name = APIParamName.VERSION, required = true, value = APIParamValue.VERSION) @PathVariable(value = APIParamName.VERSION) String version,
@ApiParam(name = APIParamName.LOCALE, required = true, value = APIParamValue.LOCALE) @PathVariable(value = APIParamName.LOCALE) String locale,
@ApiParam(name = APIParamName.COMPONENT, required = true, value = APIParamValue.COMPONENT) @PathVariable(APIParamName.COMPONENT) String component,
@RequestBody List<KeySourceCommentDTO> sourceSet,
@ApiParam(name = APIParamName.COLLECT_SOURCE, value = APIParamValue.COLLECT_SOURCE) @RequestParam(value = APIParamName.COLLECT_SOURCE, required = false, defaultValue = "false") String collectSource,
HttpServletRequest request) throws JsonProcessingException {
request.setAttribute(ConstantsKeys.KEY, ConstantsKeys.JSON_KEYSET);
ObjectMapper mapper = new ObjectMapper();
String requestJson = mapper.writeValueAsString(sourceSet);
if (!StringUtils.isEmpty(requestJson)) {
request.setAttribute(ConstantsKeys.SOURCE, requestJson);
}
return super.handleResponse(APIResponseStatus.OK, "Recieved the sources and comments(please use translation-product-component-api to confirm it).");
}
/**
* getQueryParameters - map of query parameter to value
* @param request
* @return map of request parameters
*/
private Map<String, String> getQueryParameters(HttpServletRequest request){
Map<String, String> queryParameters = new HashMap<>();
String queryString = request.getQueryString();
if (StringUtils.isEmpty(queryString)) {
System.out.println("TimeRangeOHLCActionHandler.getQueryParameters(): ERROR: query string is empty !!!");
return null;
}
String[] parameters;
if(queryString.contains("&")){
parameters = queryString.split("&");
} else{
parameters = queryString.split("%26");
}
for (String parameter : parameters) {
String[] keyValuePair = parameter.split("=");
queryParameters.put(keyValuePair[0], keyValuePair[1]);
}
return queryParameters;
}
@Override
public String getString(String key) {
String value = StringUtils.EMPTY;
value = this.data.getString(key);
if (StringUtils.isEmpty(value)) {
String message = String.format("Value for secret %s not found in local env. " +
" Trying to get the secret from KeyVault.", key);
log.warn(message);
value = this.keyVault.getKeyVaultSecret(key);
}
return value;
}
@Override
public List<Command> getCountMetadata(String schema, String entity, WorkUnit workUnit, List<Predicate> predicateList)
throws RecordCountException {
log.debug("Build query to get source record count");
List<Command> commands = new ArrayList<>();
String columnProjection = "COUNT(1)";
String watermarkFilter = this.concatPredicates(predicateList);
String query = this.getExtractSql();
if (StringUtils.isBlank(watermarkFilter)) {
watermarkFilter = "1=1";
}
query = query.replace(this.getOutputColumnProjection(), columnProjection)
.replace(ConfigurationKeys.DEFAULT_SOURCE_QUERYBASED_WATERMARK_PREDICATE_SYMBOL, watermarkFilter);
String sampleFilter = this.constructSampleClause();
query = query + sampleFilter;
if (!StringUtils.isEmpty(sampleFilter)) {
query = "SELECT COUNT(1) FROM (" + query.replace(" COUNT(1) ", " 1 ") + ")temp";
}
commands.add(getCommand(query, JdbcCommand.JdbcCommandType.QUERY));
return commands;
}
/**
* 补充和检验一下配置文件中的人员的所属组织和顶层组织信息是否正常
* @param attendanceEmployeeConfig
* @return
* @throws Exception
*/
public AttendanceEmployeeConfig checkAttendanceEmployeeConfig( AttendanceEmployeeConfig attendanceEmployeeConfig ) throws Exception {
String unitName = null;
String topUnitName = null;
if ( StringUtils.isNotEmpty( attendanceEmployeeConfig.getUnitName() )){
//检验一下组织是否存在,如果不存在,则重新进行查询
unitName = userManagerService.checkUnitNameExists( attendanceEmployeeConfig.getUnitName() );
}
if( StringUtils.isEmpty( unitName ) ){
unitName = userManagerService.getUnitNameWithPersonName( attendanceEmployeeConfig.getEmployeeName() );
}
if( StringUtils.isNotEmpty( unitName ) ){
topUnitName = userManagerService.getTopUnitNameWithUnitName( unitName );
attendanceEmployeeConfig.setUnitName( unitName );
attendanceEmployeeConfig.setTopUnitName( topUnitName );
}else{
throw new Exception( "system can not find user unit with username:"+ attendanceEmployeeConfig.getEmployeeName() +"." );
}
return attendanceEmployeeConfig;
}
/**
* 判断字符串是否以字母结尾
*
* 如果字符串为Null或空,返回false
*/
public static boolean endWith(@Nullable CharSequence s, char c) {
if (StringUtils.isEmpty(s)) {
return false;
}
return s.charAt(s.length() - 1) == c;
}
private String getMessageKeyForHubState(String state) {
if(StringUtils.isEmpty(state)) {
return null;
}
switch(state) {
case HubConnectionCapability.STATE_ONLINE:
return "hub.connection.online";
case HubConnectionCapability.STATE_OFFLINE:
return "hub.connection.offline";
default:
return null;
}
}
public static CloudTarget splitTargetSpaceValue(String value) {
if (StringUtils.isEmpty(value)) {
return new CloudTarget("", "");
}
Pattern whitespacePattern = Pattern.compile("\\s+");
Matcher matcher = whitespacePattern.matcher(value);
if (!matcher.find()) {
return new CloudTarget("", value);
}
String[] orgSpace = value.split("\\s+", 2);
return new CloudTarget(orgSpace[0], orgSpace[1]);
}
public ValidationResult validateGetProperties(GoogleDriveGetProperties properties) {
ValidationResultMutable vr = new ValidationResultMutable(Result.OK);
if (StringUtils.isEmpty(properties.file.getValue())) {
vr.setStatus(Result.ERROR);
vr.setMessage(messages.getMessage("error.validation.filename.empty"));
return vr;
}
return vr;
}
@Override
public void processOpts() {
super.processOpts();
if (StringUtils.isEmpty(System.getenv("RUST_POST_PROCESS_FILE"))) {
LOGGER.info("Environment variable RUST_POST_PROCESS_FILE not defined. rustfmt will be used" +
" by default. To choose a different tool, try" +
" 'export RUST_POST_PROCESS_FILE=\"/usr/local/bin/rustfmt\"' (Linux/Mac)");
LOGGER.info("NOTE: To enable file post-processing, 'enablePostProcessFile' must be set to `true` " +
" (--enable-post-process-file for CLI).");
}
if (!Boolean.TRUE.equals(ModelUtils.isGenerateAliasAsModel())) {
LOGGER.warn("generateAliasAsModel is set to false, which means array/map will be generated as model instead and the resulting code may have issues. Please enable `generateAliasAsModel` to address the issue.");
}
setPackageName((String) additionalProperties.getOrDefault(CodegenConstants.PACKAGE_NAME, "openapi_client"));
if (additionalProperties.containsKey(CodegenConstants.PACKAGE_VERSION)) {
setPackageVersion((String) additionalProperties.get(CodegenConstants.PACKAGE_VERSION));
}
additionalProperties.put("apiDocPath", apiDocPath);
additionalProperties.put("modelDocPath", modelDocPath);
additionalProperties.put(CodegenConstants.PACKAGE_NAME, packageName);
additionalProperties.put("externCrateName", externCrateName);
}
@Override
public void postProcessFile(File file, String fileType) {
if (file == null) {
return;
}
String fsharpPostProcessFile = System.getenv("FSHARP_POST_PROCESS_FILE");
if (StringUtils.isEmpty(fsharpPostProcessFile)) {
return; // skip if FSHARP_POST_PROCESS_FILE env variable is not defined
}
// only process files with .fs extension
if ("fs".equals(FilenameUtils.getExtension(file.toString()))) {
String command = fsharpPostProcessFile + " " + file.toString();
try {
Process p = Runtime.getRuntime().exec(command);
int exitValue = p.waitFor();
if (exitValue != 0) {
LOGGER.error("Error running the command ({}). Exit code: {}", command, exitValue);
} else {
LOGGER.info("Successfully executed: " + command);
}
} catch (Exception e) {
LOGGER.error("Error running the command ({}). Exception: {}", command, e.getMessage());
}
}
}
@Override
public void setRowId() {
// General fields for generating unique id.
StringBuilder idBuilder = new StringBuilder(getCustomerId().toString());
if (budgetId != null) {
idBuilder.append("-").append(budgetId);
}
// Include all segmentation fields (if set).
if (associatedCampaignId != null) {
idBuilder.append("-").append(associatedCampaignId);
}
if (!StringUtils.isEmpty(associatedCampaignName)) {
idBuilder.append("-").append(associatedCampaignName);
}
if (!StringUtils.isEmpty(associatedCampaignStatus)) {
idBuilder.append("-").append(associatedCampaignStatus);
}
if (!StringUtils.isEmpty(budgetCampaignAssociationStatus)) {
idBuilder.append("-").append(budgetCampaignAssociationStatus);
}
if (!StringUtils.isEmpty(conversionCategoryName)) {
idBuilder.append("-").append(conversionCategoryName);
}
if (conversionTrackerId != null) {
idBuilder.append("-").append(conversionTrackerId);
}
if (!StringUtils.isEmpty(conversionTypeName)) {
idBuilder.append("-").append(conversionTypeName);
}
if (!StringUtils.isEmpty(externalConversionSource)) {
idBuilder.append("-").append(externalConversionSource);
}
this.rowId = idBuilder.toString();
}
private String getS2IBuildName(BuildServiceConfig config, ImageName imageName) {
final StringBuilder s2IBuildName = new StringBuilder(imageName.getSimpleName());
if (!StringUtils.isEmpty(config.getS2iBuildNameSuffix())) {
s2IBuildName.append(config.getS2iBuildNameSuffix());
} else if (config.getOpenshiftBuildStrategy() == OpenShiftBuildStrategy.s2i) {
s2IBuildName.append(DEFAULT_S2I_BUILD_SUFFIX);
}
return s2IBuildName.toString();
}
private String getProxyNodeName(String hostAddress, int port) throws Exception {
if (StringUtils.isBlank(hostAddress)) {
hostAddress = CommonUtils.getHostAddress();
}
if (StringUtils.isEmpty(hostAddress)) {
LOGGER.error("do not get host address");
throw new Exception("do not get host address");
}
return hostAddress + ":" + port;
}
@Override
public Map<String, String[]> getParameterMap() {
if (parameterMap == null) {
Map<String, String[]> result = new LinkedHashMap<String, String[]>();
decode(getQueryString(), result);
String encoding = getRequest().getCharacterEncoding();
if (StringUtils.isEmpty(encoding)) {
encoding = Charset.defaultCharset().name();
}
decode(getPostBodyAsString(encoding), result);
parameterMap = Collections.unmodifiableMap(result);
}
return parameterMap;
}
/**
* Parse the values in <code>map</code> into the internal date. The
* <code>map</code> must map the names of the date widget fields like
* <code>date_year</code> etc. to <code>Integer</code> or parsable
* <code>String</code> values.
*
* If the map does not contain all of the required fields, the default
* date of now will be used.
*
* @param map a map from date widget field names to <code>Integer</code>
* or <code>String</code> values.
*/
public void readMap(Map map) {
cal.clear();
Map fieldCalMap = getFieldCalMap();
//go through and read all of the fields we need.
for (Iterator i = fieldCalMap.keySet().iterator(); i.hasNext();) {
String field = (String) i.next();
Object value = map.get(propertyName(field));
Integer fieldValue;
if (value == null) {
fieldValue = null;
}
else if (value instanceof Integer) {
fieldValue = (Integer)value;
}
else if (value instanceof String) {
fieldValue = Integer.parseInt((String) value);
}
//this is necessary for reading request parameters.
else if (value instanceof String[]) {
String [] s = (String[])value;
if (StringUtils.isEmpty(s[0])) {
fieldValue = null;
}
else {
fieldValue = Integer.parseInt(s[0]);
}
}
else {
throw new IllegalArgumentException("Form contains a date picker field" +
" that is the wrong type: " + value.getClass());
}
if (fieldValue == null) {
//This means that one of the required fields wasn't found
//Therefore, we can't really build up a date, so fall back
// on the default date, now.
cal.clear();
setDate(new Date());
break; //stop looking for the rest of the fields.
}
setField(field, fieldValue);
}
}
@Override
public void processOpts() {
super.processOpts();
if (StringUtils.isEmpty(System.getenv("KOTLIN_POST_PROCESS_FILE"))) {
LOGGER.info("Environment variable KOTLIN_POST_PROCESS_FILE not defined so the Kotlin code may not be properly formatted. To define it, try 'export KOTLIN_POST_PROCESS_FILE=\"/usr/local/bin/ktlint -F\"' (Linux/Mac)");
LOGGER.info("NOTE: To enable file post-processing, 'enablePostProcessFile' must be set to `true` (--enable-post-process-file for CLI).");
}
if (additionalProperties.containsKey(CodegenConstants.ENUM_PROPERTY_NAMING)) {
setEnumPropertyNaming((String) additionalProperties.get(CodegenConstants.ENUM_PROPERTY_NAMING));
}
if (additionalProperties.containsKey(CodegenConstants.SERIALIZATION_LIBRARY)) {
setSerializationLibrary((String) additionalProperties.get(CodegenConstants.SERIALIZATION_LIBRARY));
additionalProperties.put(this.serializationLibrary.name(), true);
} else {
additionalProperties.put(this.serializationLibrary.name(), true);
}
if (additionalProperties.containsKey(CodegenConstants.SOURCE_FOLDER)) {
this.setSourceFolder((String) additionalProperties.get(CodegenConstants.SOURCE_FOLDER));
} else {
additionalProperties.put(CodegenConstants.SOURCE_FOLDER, sourceFolder);
}
if (additionalProperties.containsKey(CodegenConstants.PACKAGE_NAME)) {
this.setPackageName((String) additionalProperties.get(CodegenConstants.PACKAGE_NAME));
if (!additionalProperties.containsKey(CodegenConstants.MODEL_PACKAGE))
this.setModelPackage(packageName + ".models");
if (!additionalProperties.containsKey(CodegenConstants.API_PACKAGE))
this.setApiPackage(packageName + ".apis");
} else {
additionalProperties.put(CodegenConstants.PACKAGE_NAME, packageName);
}
if (additionalProperties.containsKey(CodegenConstants.API_SUFFIX)) {
this.setApiSuffix((String) additionalProperties.get(CodegenConstants.API_SUFFIX));
}
if (additionalProperties.containsKey(CodegenConstants.ARTIFACT_ID)) {
this.setArtifactId((String) additionalProperties.get(CodegenConstants.ARTIFACT_ID));
} else {
additionalProperties.put(CodegenConstants.ARTIFACT_ID, artifactId);
}
if (additionalProperties.containsKey(CodegenConstants.GROUP_ID)) {
this.setGroupId((String) additionalProperties.get(CodegenConstants.GROUP_ID));
} else {
additionalProperties.put(CodegenConstants.GROUP_ID, groupId);
}
if (additionalProperties.containsKey(CodegenConstants.ARTIFACT_VERSION)) {
this.setArtifactVersion((String) additionalProperties.get(CodegenConstants.ARTIFACT_VERSION));
} else {
additionalProperties.put(CodegenConstants.ARTIFACT_VERSION, artifactVersion);
}
if (additionalProperties.containsKey(CodegenConstants.INVOKER_PACKAGE)) {
LOGGER.warn(CodegenConstants.INVOKER_PACKAGE + " with " + this.getName() + " generator is ignored. Use " + CodegenConstants.PACKAGE_NAME + ".");
}
if (additionalProperties.containsKey(CodegenConstants.SERIALIZABLE_MODEL)) {
this.setSerializableModel(convertPropertyToBooleanAndWriteBack(CodegenConstants.SERIALIZABLE_MODEL));
} else {
additionalProperties.put(CodegenConstants.SERIALIZABLE_MODEL, serializableModel);
}
if (additionalProperties.containsKey(CodegenConstants.PARCELIZE_MODELS)) {
this.setParcelizeModels(convertPropertyToBooleanAndWriteBack(CodegenConstants.PARCELIZE_MODELS));
} else {
additionalProperties.put(CodegenConstants.PARCELIZE_MODELS, parcelizeModels);
}
if (additionalProperties.containsKey(CodegenConstants.NON_PUBLIC_API)) {
this.setNonPublicApi(convertPropertyToBooleanAndWriteBack(CodegenConstants.NON_PUBLIC_API));
} else {
additionalProperties.put(CodegenConstants.NON_PUBLIC_API, nonPublicApi);
}
additionalProperties.put(CodegenConstants.SORT_PARAMS_BY_REQUIRED_FLAG, getSortParamsByRequiredFlag());
additionalProperties.put(CodegenConstants.SORT_MODEL_PROPERTIES_BY_REQUIRED_FLAG, getSortModelPropertiesByRequiredFlag());
additionalProperties.put(CodegenConstants.API_PACKAGE, apiPackage());
additionalProperties.put(CodegenConstants.MODEL_PACKAGE, modelPackage());
additionalProperties.put("apiDocPath", apiDocPath);
additionalProperties.put("modelDocPath", modelDocPath);
}
public Object coerceValue(List<String> arguments, Parameter parameter, Class<?> cls) throws ConversionException {
if (arguments == null || arguments.size() == 0) {
return null;
}
LOGGER.debug("casting `" + arguments + "` to " + cls);
if (List.class.equals(cls)) {
if (parameter.getSchema() != null) {
List<Object> output = new ArrayList<>();
if (parameter.getSchema() instanceof ArraySchema) {
ArraySchema arraySchema = ((ArraySchema) parameter.getSchema());
Schema inner = arraySchema.getItems();
// TODO: this does not need to be done this way, update the helper method
Parameter innerParam = new QueryParameter();
innerParam.setSchema(inner);
JavaType innerClass = getTypeFromParameter(innerParam, definitions);
for (String obj : arguments) {
String[] parts = new String[0];
if (Parameter.StyleEnum.FORM.equals(parameter.getStyle()) && !StringUtils.isEmpty(obj) && parameter.getExplode() == false ) {
parts = obj.split(",");
}
if (Parameter.StyleEnum.PIPEDELIMITED.equals(parameter.getStyle()) && !StringUtils.isEmpty(obj)) {
parts = obj.split("|");
}
if (Parameter.StyleEnum.SPACEDELIMITED.equals(parameter.getStyle()) && !StringUtils.isEmpty(obj)) {
parts = obj.split(" ");
}
if (Parameter.StyleEnum.FORM.equals(parameter.getStyle()) && !StringUtils.isEmpty(obj) && parameter.getExplode() == true) {
parts = new String[1];
parts[0]= obj;
}
for (String p : parts) {
Object ob = cast(p, inner, innerClass);
if (ob != null) {
output.add(ob);
}
}
}
}
return output;
}
} else if (parameter.getSchema() != null) {
TypeFactory tf = Json.mapper().getTypeFactory();
return cast(arguments.get(0), parameter.getSchema(), tf.constructType(cls));
}
return null;
}