本文整理汇总了Java中org.febit.util.StringUtil类的典型用法代码示例。如果您正苦于以下问题:Java StringUtil类的具体用法?Java StringUtil怎么用?Java StringUtil使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
StringUtil类属于org.febit.util包,在下文中一共展示了StringUtil类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: keywords
import org.febit.util.StringUtil; //导入依赖的package包/类
public T keywords(String q, String... keys) {
if (StringUtil.isNotBlank(q)) {
q = q.trim();
StringBuilder buffer = new StringBuilder(q.length() * 3 / 2 + 3);
StringUtil.escapeRegex(buffer, q);
final int len = keys.length;
Condition[] array = new Condition[keys.length];
Condition val = c(
"$regex", buffer.toString()
);
for (int i = 0; i < len; i++) {
array[i] = c(keys[i], val);
}
or(array);
}
return (T) this;
}
示例2: find
import org.febit.util.StringUtil; //导入依赖的package包/类
public <T extends Entity> LcFindResponse<T> find(String id, String table, Class<T> entityType, String[] keys) {
if (StringUtil.isEmpty(id)) {
throw new IllegalArgumentException("id is required");
}
if (table == null) {
table = getEntityTableName(entityType);
}
EasyRequest request = new EasyRequest()
.get()
.addPathSegment(apiVersion)
.addPathSegment("classes")
.addPathSegment(table)
.addPathSegment(id);
if (keys != null && keys.length != 0) {
request.query("keys", StringUtil.join(keys, ','));
}
return readFindResponse(sendRequest(request), entityType);
}
示例3: delete
import org.febit.util.StringUtil; //导入依赖的package包/类
public <T extends Entity> LcDeleteResponse delete(String id, String table, Class<T> entityType, Condition where) {
if (StringUtil.isEmpty(id)) {
throw new IllegalArgumentException("id is required");
}
if (table == null) {
table = getEntityTableName(entityType);
}
EasyRequest request = new EasyRequest()
.delete()
.addPathSegment(apiVersion)
.addPathSegment("classes")
.addPathSegment(table);
if (id != null) {
request.addPathSegment(id);
}
if (where != null) {
request.query("where", JsonUtil.toJsonString(where));
}
return readBasicResponse(sendRequest(request));
}
示例4: update
import org.febit.util.StringUtil; //导入依赖的package包/类
public <T extends Entity> LcUpdateResponse update(String id, String table, Class<T> entityType, Map<String, ?> changes) {
if (StringUtil.isEmpty(id)) {
throw new IllegalArgumentException("id is required");
}
if (table == null) {
table = getEntityTableName(entityType);
}
EasyRequest request = new EasyRequest()
.put()
.addPathSegment(apiVersion)
.addPathSegment("classes")
.addPathSegment(table)
.addPathSegment(id);
setJsonBody(request, changes);
return readBasicResponse(sendRequest(request));
}
示例5: renderJson
import org.febit.util.StringUtil; //导入依赖的package包/类
public static Object renderJson(ActionRequest actionRequest, Object value, String boxName, String[] profiles) throws IOException {
final HttpServletResponse response = actionRequest.response;
final String encoding = response.getCharacterEncoding();
response.setContentType(MimeTypes.MIME_APPLICATION_JSON);
response.setCharacterEncoding(encoding);
final OutputStream out = response.getOutputStream();
try {
if (value == null) {
out.write("{}".getBytes(encoding));
return null;
}
final boolean hasBox = (boxName != null && !boxName.isEmpty());
final StringBuilder buffer = new StringBuilder(255);
if (hasBox) {
buffer.append("{\"").append(boxName).append("\":");
}
if (value instanceof Integer) {
buffer.append((Integer) value);
} else if (value instanceof String) {
StringUtil.escapeUTF8((String) value, buffer, true);
} else {
Json.writeTo(buffer, value, profiles);
}
if (hasBox) {
buffer.append('}');
}
out.write(buffer.toString().getBytes(encoding));
} finally {
//Notice: no close
out.flush();
}
return null;
}
示例6: pathToSegment
import org.febit.util.StringUtil; //导入依赖的package包/类
protected static String[] pathToSegment(String path) {
if (path == null) {
return null;
}
String[] segments = StringUtil.splitc(path, '/');
// if start with '/'
if (segments.length != 0 && segments[0].isEmpty()) {
segments = Arrays.copyOfRange(segments, 1, segments.length);
}
if (segments.length == 0) {
return null;
}
return segments;
}
示例7: keywords
import org.febit.util.StringUtil; //导入依赖的package包/类
public Condition keywords(String q, String... keys) {
if (keys == null || keys.length == 0
|| StringUtil.isBlank(q)) {
return this;
}
String bindName = addBindVar("q", '%' + escapeLike(q.trim()) + '%');
StringBuilder buf = filterBuffer();
buf.append('(');
for (int i = 0; i < keys.length; i++) {
String prop = fixColumnName(keys[i]);
if (i != 0) {
buf.append(" || ");
}
buf.append("d.`").append(prop)
.append("` LIKE @")
.append(bindName);
}
buf.append(')');
return this;
}
示例8: createDictMap
import org.febit.util.StringUtil; //导入依赖的package包/类
public Map<String, String> createDictMap(GeoLite2CsvDict dict) {
Map<String, String> result = CollectionUtil.createMap(this.map.size());
for (IntMap.Entry<DictEntry> entry : this.map) {
DictEntry keyEntry = entry.getValue();
DictEntry valueEntry = dict.get(keyEntry.geoId);
if (valueEntry == null) {
continue;
}
result.put(keyEntry.countryCode, valueEntry.countryCode);
result.put(keyEntry.country, valueEntry.country);
result.put(keyEntry.province, valueEntry.province);
result.put(keyEntry.city, valueEntry.city);
result.put(LocationUtil.fixProvince(keyEntry.province), valueEntry.province);
result.put(LocationUtil.fixCity(keyEntry.city), valueEntry.city);
result.put(StringUtil.cutSuffix(StringUtil.cutSuffix(keyEntry.city, "市"), "县"), valueEntry.city);
}
return result;
}
示例9: resoveDictIndex
import org.febit.util.StringUtil; //导入依赖的package包/类
protected int resoveDictIndex(String string) {
if (string == null) {
return 0;
}
string = string.trim();
if (string.isEmpty()) {
return 0;
}
string = StringUtil.remove(string, '\001');
Integer index = dict.get(string);
if (index == null) {
index = dict.size();
dict.put(string, index);
}
return index;
}
示例10: parserIntegerArray
import org.febit.util.StringUtil; //导入依赖的package包/类
public static Integer[] parserIntegerArray(String value, int max) {
if (value == null) {
return null;
}
if (max > 0 && StringUtil.count(value, ',') > max) {
return null;
}
String[] rawIds = StringUtil.splitc(value, ',');
List<Integer> idList = new ArrayList<>(rawIds.length);
for (String rawId : rawIds) {
try {
idList.add(Integer.parseInt(rawId));
} catch (NumberFormatException ignore) {
}
}
return idList.toArray(new Integer[idList.size()]);
}
示例11: parserLongArray
import org.febit.util.StringUtil; //导入依赖的package包/类
public static Long[] parserLongArray(String value, int max) {
if (value == null) {
return null;
}
if (max > 0 && StringUtil.count(value, ',') > max) {
return null;
}
String[] rawIds = StringUtil.splitc(value, ',');
List<Long> idList = new ArrayList<>(rawIds.length);
for (String rawId : rawIds) {
try {
idList.add(Long.parseLong(rawId));
} catch (NumberFormatException ignore) {
}
}
return idList.toArray(new Long[idList.size()]);
}
示例12: valueOf
import org.febit.util.StringUtil; //导入依赖的package包/类
public static DependLib valueOf(String string) {
if (string == null) {
return null;
}
final String[] arr = StringUtil.splitc(string, ":");
String group;
String artifact = "";
String version = null;
String type = JAR;
group = arr[0].trim();
if (arr.length >= 2) {
artifact = arr[1].trim();
if (arr.length == 3) {
version = arr[2].trim();
} else if (arr.length == 4) {
type = arr[2].trim();
version = arr[3].trim();
}
}
if (version != null && version.length() == 0) {
version = null;
}
return new DependLib(group, artifact, version, type);
}
示例13: valueOf
import org.febit.util.StringUtil; //导入依赖的package包/类
public static ColumnEnum valueOf(String string) {
final String[] arr = StringUtil.splitc(string, '|');
StringUtil.trim(arr);
Short id;
String name = "UNKOWN";
String remark = "unkown";
String value = arr[0];
id = Short.valueOf(value);
if (arr.length >= 2) {
name = arr[1];
if (arr.length == 3) {
remark = arr[2];
}
}
return new ColumnEnum(id, name, remark);
}
示例14: resolveEnums
import org.febit.util.StringUtil; //导入依赖的package包/类
protected List<ColumnEnum> resolveEnums(final ColumnRaw raw) {
if (raw.remarks == null
|| !raw.getJavaType().equals("java.lang.Short")) {
return null;
}
String enumsRaw = StringUtil.cutBetween(raw.remarks, "E(", ")");
if (enumsRaw == null) {
return null;
}
final List<ColumnEnum> enums = new ArrayList<>();
for (String emumRaw : StringUtil.toArrayExcludeCommit(enumsRaw)) {
try {
enums.add(ColumnEnum.valueOf(emumRaw));
} catch (Exception e) {
Logger.error("Faild to parse column enum: " + raw + " | " + enumsRaw);
throw new RuntimeException(e);
}
}
return enums;
}
示例15: handleFailedFindResponse
import org.febit.util.StringUtil; //导入依赖的package包/类
protected <T extends Entity> T handleFailedFindResponse(LcFindResponse<T> response, String id) {
if (response.getStatusCode() == 404
&& response.getCode() == 101) {
return null;
}
throw new LcException(StringUtil.format(
"Failed to query table: {}, response {}, where id={}",
_table, response, id
));
}