本文整理汇总了Java中org.apache.commons.lang3.StringUtils.trimToNull方法的典型用法代码示例。如果您正苦于以下问题:Java StringUtils.trimToNull方法的具体用法?Java StringUtils.trimToNull怎么用?Java StringUtils.trimToNull使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.lang3.StringUtils
的用法示例。
在下文中一共展示了StringUtils.trimToNull方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: buildConditions
import org.apache.commons.lang3.StringUtils; //导入方法依赖的package包/类
private String buildConditions(String prefix, List<String> conditions, List<String> operators) {
StringBuilder builder = new StringBuilder();
if (conditions.size()>0) {
if (StringUtils.trimToNull(prefix)!=null) {
builder.append(" ").append(prefix).append(" ");
}
for (int i=0; i<conditions.size(); i++) {
String condition = conditions.get(i);
builder.append(condition).append(" ");
if (i<conditions.size()-1) {
String operator = StringUtils.trimToNull(operators.get(i));
if (operator!=null) {
builder.append(operator).append(" ");
}
}
}
}
return builder.toString();
}
示例2: getFileKey
import org.apache.commons.lang3.StringUtils; //导入方法依赖的package包/类
public static String getFileKey(String name) {
String prefix = "/upload/" + DateKit.dateFormat(new Date(), "yyyy/MM");
if (!new File(AttachController.CLASSPATH + prefix).exists()) {
new File(AttachController.CLASSPATH + prefix).mkdirs();
}
name = StringUtils.trimToNull(name);
if (name == null) {
return prefix + "/" + UUID.UU32() + "." + null;
} else {
name = name.replace('\\', '/');
name = name.substring(name.lastIndexOf("/") + 1);
int index = name.lastIndexOf(".");
String ext = null;
if (index >= 0) {
ext = StringUtils.trimToNull(name.substring(index + 1));
}
return prefix + "/" + UUID.UU32() + "." + (ext == null ? null : (ext));
}
}
示例3: parseRecords
import org.apache.commons.lang3.StringUtils; //导入方法依赖的package包/类
private void parseRecords(InputStream stream) throws IOException {
LineIterator it = IOUtils.lineIterator(buffer(stream), IabFile.CHARSET);
while (it.hasNext()) {
String record = StringUtils.trimToNull(it.nextLine());
if (record != null) {
if (isCidrNotation(record)) {
cidrAddresses.add(subnetInfo(record));
} else {
plainAddresses.add(record);
}
}
}
}
示例4: deserialize
import org.apache.commons.lang3.StringUtils; //导入方法依赖的package包/类
@Override
public String[] deserialize(JsonParser jsonParser, DeserializationContext context) throws IOException {
final List<String> list = new ArrayList<>();
final JsonNode node = jsonParser.readValueAsTree();
if (node.isArray()) {
final Iterator elements = node.elements();
while (elements.hasNext()) {
final JsonNode childNode = (JsonNode) elements.next();
final String value = StringUtils.trimToNull(childNode.asText());
if (value != null) {
list.add(value);
}
}
}
if (list.size() == 0) {
return null;
} else {
return list.toArray(new String[list.size()]);
}
}
示例5: getFilterAttributes
import org.apache.commons.lang3.StringUtils; //导入方法依赖的package包/类
public Map<String, String> getFilterAttributes() {
if (uriInfo != null) {
MultivaluedMap<String, String> queryParams = uriInfo.getQueryParameters();
for (Map.Entry<String, List<String>> queryParam : queryParams.entrySet()) {
String queryParamAttribute = queryParam.getKey();
if (StringUtils.isBlank(queryParamAttribute) || !queryParamAttribute.startsWith("filter-")) {
continue;
}
queryParamAttribute = queryParamAttribute.substring("filter-".length(), queryParamAttribute.length());
String filterVal = StringUtils.trimToNull(queryParam.getValue().get(0));
if (filterVal != null) {
filterAttributes.put(queryParamAttribute, filterVal);
}
}
}
return filterAttributes;
}
示例6: getDocumentType
import org.apache.commons.lang3.StringUtils; //导入方法依赖的package包/类
/**
* Returms the content type of a response given the content-type
* @param fullContentType the content-type (from request.getContentType()), also with charset or other attributes like "text/html; charset=UTF-8"
* @return an integer for the type of the content
*/
public int getDocumentType(String fullContentType) {
if (StringUtils.trimToNull(fullContentType)==null) {
return CONTENT_UNKNOWN;
}
String[] parts = fullContentType.toLowerCase().split("[; ]", 2);
String contentType = parts[0];
// TODO application/x-www-form-urlencoded could actually ask for an image, so it isn't strictly correct !
if ("text/html".equals(contentType) || "application/xhtml+xml".equals(contentType) || "application/x-www-form-urlencoded".equals(contentType)) {
return CONTENT_DOCUMENT;
}
if ("text/xml".equals(contentType)) {
return CONTENT_XML;
}
if ("application/javascript".equals(contentType) || "application/x-javascript".equals(contentType) || "text/javascript".equals(contentType)) {
return CONTENT_JAVASCRIPT;
}
if ("text/css".equals(contentType)) {
return CONTENT_CSS;
}
if (contentType.startsWith("image/")) {
return CONTENT_IMAGE;
}
return CONTENT_OTHER;
}
示例7: savezhoubao
import org.apache.commons.lang3.StringUtils; //导入方法依赖的package包/类
@RequestMapping("/savezhoubao")
@SuppressWarnings("unchecked")
public void savezhoubao(String content) {
if (StringUtils.isNotEmpty(content)) {
content = StringUtils.trimToNull(content);
}
redisTemplate.opsForValue().set("zhoubao", content);
}
示例8: modelGetterMethodGenerated
import org.apache.commons.lang3.StringUtils; //导入方法依赖的package包/类
/**
* 解析处理注释,增加 getXxxText() 方法
* 注释格式范例:
* @enum 0: 有效期; 1: 无效
*/
@Override
public boolean modelGetterMethodGenerated(Method method, TopLevelClass topLevelClass,
IntrospectedColumn introspectedColumn,
IntrospectedTable introspectedTable,
ModelClassType modelClassType) {
String remarks = introspectedColumn.getRemarks();
int jdbcType = introspectedColumn.getJdbcType();
remarks = StringUtils.trimToNull(remarks);
if (remarks == null) {
return true;
}
if (!remarks.contains("@enum")) {
return true;
}
String annotation = remarks.substring(remarks.indexOf("@enum") + 5);
String[] items = StringUtils.split(annotation, ';');
StringBuilder mapInitSb = new StringBuilder("new HashMap<Object, String>(){{");
for (String item : items) {
if (!item.contains(":")) {
continue;
}
String[] kv = item.split(":");
String k = StringUtils.trim(kv[0]);
String v = StringUtils.trim(kv[1]);
mapInitSb.append("put(");
if (jdbcType == Types.TINYINT) {
mapInitSb.append("(byte)");
}
mapInitSb.append(k).append(",")
.append("\"").append(v).append("\");");
}
mapInitSb.append("}}");
// 增加常量
String fieldName = String.format("%sMap", introspectedColumn.getJavaProperty());
Field field = new Field(
fieldName,
new FullyQualifiedJavaType("java.util.HashMap<Object, String>")
);
field.setVisibility(JavaVisibility.PRIVATE);
field.setStatic(true);
field.setFinal(true);
field.setInitializationString(mapInitSb.toString());
topLevelClass.addField(field);
// 增加方法
Method textMethod = new Method(String.format("%sText", method.getName()));
textMethod.setReturnType(new FullyQualifiedJavaType(String.class.getCanonicalName()));
textMethod.setVisibility(JavaVisibility.PUBLIC);
if (jdbcType == Types.TINYINT) {
textMethod.addBodyLine(String.format("return %s.get((byte)this.%s);", fieldName, introspectedColumn.getJavaProperty()));
} else {
textMethod.addBodyLine(String.format("return %s.get(this.%s);", fieldName, introspectedColumn.getJavaProperty()));
}
remarks = remarks.replaceAll("\n", "\\\\n").replaceAll("\"", "\\\\\"");
textMethod.addAnnotation(
String.format("@ApiModelProperty(value = \"%s\")", remarks)
);
topLevelClass.addImportedType(new FullyQualifiedJavaType(HashMap.class.getCanonicalName()));
topLevelClass.addMethod(textMethod);
return true;
}
示例9: MigrationCommand
import org.apache.commons.lang3.StringUtils; //导入方法依赖的package包/类
@JsonCreator
public MigrationCommand(@JsonProperty("version") String version,
@JsonProperty("description") String description,
@JsonProperty("author") String author,
@JsonProperty("command") Map<String, Object> command) {
if (StringUtils.trimToNull(version) == null || StringUtils.trimToNull(description) == null || command == null)
throw new IllegalStateException("A migration command requires at least a version, description and a command!");
this.version = version;
this.description = description;
this.author = Optional.ofNullable(author).orElse(Migration.DEFAULT_AUTHOR);
this.command = new BasicDBObject(command);
}
示例10: getVersion
import org.apache.commons.lang3.StringUtils; //导入方法依赖的package包/类
@Override
public String getVersion(final Map<String, String> parameters) throws Exception {
final String page = StringUtils.trimToEmpty(getConfluencePublicResource(parameters, "/forgotuserpassword.action"));
final String ajsMeta = "ajs-version-number\" content=";
final int versionIndex = Math.min(page.length(), page.indexOf(ajsMeta) + ajsMeta.length() + 1);
return StringUtils.trimToNull(page.substring(versionIndex, Math.max(versionIndex, page.indexOf('\"', versionIndex))));
}
示例11: findAllByName
import org.apache.commons.lang3.StringUtils; //导入方法依赖的package包/类
/**
* Search the SonarQube's projects matching to the given criteria. Name, display name and description are
* considered.
*
* @param node
* the node to be tested with given parameters.
* @param criteria
* the search criteria.
* @return project names matching the criteria.
*/
@GET
@Path("{node}/{criteria}")
@Consumes(MediaType.APPLICATION_JSON)
public List<SonarProject> findAllByName(@PathParam("node") final String node, @PathParam("criteria") final String criteria) throws IOException {
// Prepare the context, an ordered set of projects
final Format format = new NormalizeFormat();
final String formatCriteria = format.format(criteria);
final Map<String, String> parameters = pvResource.getNodeParameters(node);
// Get the projects and parse them
final List<SonarProject> projectsRaw = getProjects(parameters);
final Map<String, SonarProject> result = new TreeMap<>();
for (final SonarProject project : projectsRaw) {
final String name = StringUtils.trimToNull(project.getName());
final String key = project.getKey();
// Check the values of this project
if (format.format(name).contains(formatCriteria) || format.format(key).contains(formatCriteria)) {
// Retrieve description and display name
result.put(project.getName(), project);
}
}
return new ArrayList<>(result.values());
}
示例12: isLocale
import org.apache.commons.lang3.StringUtils; //导入方法依赖的package包/类
private boolean isLocale(String locale) {
if (StringUtils.trimToNull(locale)==null) {
return false;
}
List<String> locales = config.getLocaleStrings();
return locales.contains(locale);
}
示例13: getSql
import org.apache.commons.lang3.StringUtils; //导入方法依赖的package包/类
public String getSql() {
StringBuilder builder = new StringBuilder();
if (select!=null) {
builder.append(select).append(" ");
if (from!=null) {
builder.append("from ").append(from).append(" ");
}
} else if (update!=null) {
builder.append(update).append(" ");
if (set!=null) {
builder.append(set).append(" ");
}
}
builder.append(joins);
builder.append(buildConditions("where", whereConditions, whereOperators));
if (StringUtils.trimToNull(groupby)!=null) {
builder.append(" ").append(groupby);
}
builder.append(buildConditions("having", havingConditions, havingOperators));
if (StringUtils.trimToNull(orderAndLimit)!=null) {
builder.append(" ").append(orderAndLimit);
}
if (log.isDebugEnabled()) {
log.debug(builder.toString());
}
return builder.toString();
}
示例14: extractAddress
import org.apache.commons.lang3.StringUtils; //导入方法依赖的package包/类
/**
* Extract the address from a url, without schema and path but with port
* @param url an url like http://www.myserver.net:8080/context/path or //www.myserver.net:8080/context/path
* @return the host[:port] like www.myserver.net:8080, or ""
*/
public String extractAddress(String url) {
if (StringUtils.trimToNull(url)!=null) {
try {
int pos = url.indexOf("//");
pos = (pos<0?0:pos+2);
int pos2 = url.indexOf("/", pos);
pos2 = (pos2<0?url.length():pos2);
return url.substring(pos, pos2);
} catch (Exception e) {
log.error("Can't extract address from {}", url);
}
}
return "";
}
示例15: getNameOrData
import org.apache.commons.lang3.StringUtils; //导入方法依赖的package包/类
/**
* Returns the column name if any, the column data otherwise.
* @return name or data or null
*/
public String getNameOrData() {
String result = StringUtils.trimToNull(getName());
if (result==null) {
result = StringUtils.trimToNull(getData());
}
return result;
}