List of usage examples for org.apache.commons.lang3 StringUtils split
public static String[] split(final String str, final String separatorChars)
Splits the provided text into an array, separators specified.
From source file:com.mxep.web.common.persistence.DynamicSpecifications.java
private static List<Predicate> getPredicate(Collection<SearchFilter> filters, Root<?> root, CriteriaQuery<?> query, CriteriaBuilder builder) { List<Predicate> predicates = Lists.newArrayList(); for (SearchFilter filter : filters) { // nested path translate, Task??"user.name"filedName, // ?Task.user.name String[] names = StringUtils.split(filter.fieldName, "."); Path expression = root.get(names[0]); for (int i = 1; i < names.length; i++) { expression = expression.get(names[i]); }//from w ww .j a va 2 s. c o m /*????*/ if (expression.getJavaType().equals(Integer.class) && !filter.operator.equals(SearchFilter.Operator.IN)) { filter.value = Integer.parseInt(filter.value.toString()); } // logic operator switch (filter.operator) { case EQ: predicates.add(builder.equal(expression, filter.value)); break; case LIKE: predicates.add(builder.like(expression, "%" + filter.value + "%")); break; case GT: predicates.add(builder.greaterThan(expression, (Comparable) filter.value)); break; case LT: predicates.add(builder.lessThan(expression, (Comparable) filter.value)); break; case GTE: predicates.add(builder.greaterThanOrEqualTo(expression, (Comparable) filter.value)); break; case LTE: predicates.add(builder.lessThanOrEqualTo(expression, (Comparable) filter.value)); break; case NEQ: predicates.add(builder.notEqual(expression, filter.value)); break; case IN: In in = builder.in(expression); String value = filter.value.toString(); String[] values = StringUtils.split(value, ","); for (int i = 0; i < values.length; i++) { /*????*/ if (expression.getJavaType().equals(Integer.class) || expression.getJavaType().equals(int.class) || expression.getJavaType().equals(byte.class)) { in.value(Integer.valueOf(values[i])); } else { in.value(values[i]); } } predicates.add(in); break; case NULL: predicates.add(builder.isNull(expression)); break; case NOTNULL: predicates.add(builder.isNotNull(expression)); break; } } return predicates; }
From source file:com.phone.cn.entity.search.filter.Condition.java
/** * ?key?Condition/*from w w w . ja v a2 s. c om*/ * * @param key name_like * @param value * @return */ @SuppressWarnings("rawtypes") static Condition newCondition(final String key, final Object value) throws SearchException { Assert.notNull(key, "Condition key must not null"); String[] searchs = StringUtils.split(key, separator); if (searchs.length == 0) { throw new SearchException("Condition key format must be : property or property_op"); } String searchProperty = searchs[0]; SearchOperator operator = null; if (searchs.length == 1) { operator = SearchOperator.custom; } else { try { operator = SearchOperator.valueOf(searchs[1]); } catch (IllegalArgumentException e) { throw new InvlidSearchOperatorException(searchProperty, searchs[1]); } } boolean allowBlankValue = SearchOperator.isAllowBlankValue(operator); boolean isValueBlank = (value == null); isValueBlank = isValueBlank || (value instanceof String && StringUtils.isBlank((String) value)); isValueBlank = isValueBlank || (value instanceof List && ((List) value).size() == 0); //??? if (!allowBlankValue && isValueBlank) { return null; } Condition searchFilter = newCondition(searchProperty, operator, value); return searchFilter; }
From source file:com.yuanbao.crm.common.entity.search.filter.Condition.java
/** * ?key?Condition/*from w w w . jav a 2s .c o m*/ * * @param key name_like * @param value * @return */ static Condition newCondition(final String key, final Object value) throws SearchException { Assert.notNull(key, "Condition key must not null"); String[] searchs = StringUtils.split(key, separator); if (searchs.length == 0) { throw new SearchException("Condition key format must be : property or property_op"); } String searchProperty = searchs[0]; SearchOperator operator = null; if (searchs.length == 1) { operator = SearchOperator.custom; } else { try { operator = SearchOperator.valueOf(searchs[1]); } catch (IllegalArgumentException e) { throw new InvalidSearchOperatorException(searchProperty, searchs[1]); } } boolean allowBlankValue = SearchOperator.isAllowBlankValue(operator); boolean isValueBlank = (value == null); isValueBlank = isValueBlank || (value instanceof String && StringUtils.isBlank((String) value)); isValueBlank = isValueBlank || (value instanceof List && ((List) value).size() == 0); //??? if (!allowBlankValue && isValueBlank) { return null; } Condition searchFilter = newCondition(searchProperty, operator, value); return searchFilter; }
From source file:net.gtaun.shoebill.util.config.MapConfiguration.java
@SuppressWarnings("unchecked") private static void set(Map<String, Object> map, String path, Object value) { String[] childs = StringUtils.split(path, '.'); Map<String, Object> node = map; for (int i = 0; i < childs.length - 1; i++) { Object obj = node.get(childs[i]); if (obj instanceof Map<?, ?> == false) { obj = new HashMap<>(); node.put(childs[i], obj);//w w w. j a v a 2s . c om } node = (Map<String, Object>) obj; } node.put(childs[childs.length - 1], value); }
From source file:cn.guoyukun.spring.jpa.entity.search.filter.Condition.java
/** * ?key?Condition//from ww w. j a va 2 s .com * * @param key name_like * @param value * @return */ static Condition newCondition(final String key, final Object value) throws SearchException { Assert.notNull(key, "Condition key must not null"); String[] searchs = StringUtils.split(key, separator); if (searchs.length == 0) { throw new SearchException("Condition key format must be : property or property_op"); } String searchProperty = searchs[0]; SearchOperator operator = null; if (searchs.length == 1) { operator = SearchOperator.custom; } else { try { operator = SearchOperator.valueOf(searchs[1]); } catch (IllegalArgumentException e) { throw new InvlidSearchOperatorException(searchProperty, searchs[1]); } } boolean allowBlankValue = SearchOperator.isAllowBlankValue(operator); boolean isValueBlank = (value == null); isValueBlank = isValueBlank || (value instanceof String && StringUtils.isBlank((String) value)); isValueBlank = isValueBlank || (value instanceof List && ((List) value).size() == 0); //??? if (!allowBlankValue && isValueBlank) { return null; } Condition searchFilter = newCondition(searchProperty, operator, value); return searchFilter; }
From source file:de.micromata.genome.util.runtime.DynamicClassPath.java
public static void initClassPath(LocalSettings localSettings) { String cp = localSettings.getProperty("sys.classpathext"); if (StringUtils.isBlank(cp) == true) { return;/* w w w. j av a 2 s. co m*/ } String[] cpl = StringUtils.split(cp, ","); URL[] urls = new URL[cpl.length]; for (int i = 0; i < cpl.length; ++i) { URL url = createClUrl(new File(cpl[i])); urls[i] = url; } boolean extendSystemCl = false; if (extendSystemCl == false) { addContextClassPathes(urls); } else { for (String c : cpl) { URL url = createClUrl(new File(c)); addSystemClassPath(url); } } // Class cls = Class.forName("org.springbyexample.jdbc.datasource.InitializingBasicDataSource", true, Thread.currentThread() // .getContextClassLoader()); }
From source file:com.withub.common.SearchFilter.java
/** * searchParamskey?OPERATOR_FIELDNAME/*from ww w .j a v a 2s . c o m*/ */ public static Map<String, SearchFilter> parse(Map<String, Object> searchParams) { Map<String, SearchFilter> filters = Maps.newHashMap(); for (Map.Entry<String, Object> entry : searchParams.entrySet()) { // String key = entry.getKey(); Object value = entry.getValue(); if (value == null || StringUtils.isBlank(value.toString())) { continue; } // operatorfiledAttribute String[] names = StringUtils.split(key, "_"); if (names.length != 2) { throw new IllegalArgumentException(key + " is not a valid search filter name"); } String filedName = names[1]; Operator operator = Operator.valueOf(names[0]); // searchFilter SearchFilter filter = new SearchFilter(filedName, operator, value); filters.put(key, filter); } return filters; }
From source file:cc.sion.core.persistence.DynamicSpecifications.java
public static <T> Specification<T> bySearchFilter(final Collection<SearchFilter> filters, final Class<T> entityClazz) { return new Specification<T>() { @Override/*from w w w .j av a2 s .c om*/ public Predicate toPredicate(Root<T> root, CriteriaQuery<?> query, CriteriaBuilder builder) { if (Collections3.isNotEmpty(filters)) { List<Predicate> predicates = Lists.newArrayList(); for (SearchFilter filter : filters) { // nested path translate, Task??"user.name"filedName, ?Task.user.name String[] names = StringUtils.split(filter.fieldName, "."); Path expression = root.get(names[0]); for (int i = 1; i < names.length; i++) { expression = expression.get(names[i]); } // if(log.isDebugEnabled()){ // log.debug(" {}-{}-{}",names[0],filter.operator,filter.value); // } // logic operator switch (filter.operator) { case EQ: predicates.add(builder.equal(expression, filter.value)); break; case NE: predicates.add(builder.notEqual(expression, filter.value)); break; case LIKE: predicates.add(builder.like(expression, "%" + filter.value + "%")); break; case GT: predicates.add(builder.greaterThan(expression, (Comparable) filter.value)); break; case LT: predicates.add(builder.lessThan(expression, (Comparable) filter.value)); break; case GTE: predicates.add(builder.greaterThanOrEqualTo(expression, (Comparable) filter.value)); break; case LTE: predicates.add(builder.lessThanOrEqualTo(expression, (Comparable) filter.value)); break; } } // ? and ??? if (!predicates.isEmpty()) { return builder.and(predicates.toArray(new Predicate[predicates.size()])); } } return builder.conjunction(); } }; }
From source file:io.apiman.gateway.engine.vertx.polling.fetchers.auth.AbstractOAuth2Base.java
protected static JsonObject mapToJson(Map<String, String> map) { JsonObject root = new JsonObject(); for (Entry<String, String> entry : map.entrySet()) { String[] split = StringUtils.split(entry.getKey(), '.'); ArrayDeque<String> dq = new ArrayDeque<>(Arrays.asList(split)); createOrDescend(root, dq, entry.getValue()); }/*from w w w . j a v a 2s. c om*/ return root; }
From source file:com.ciwen.xhb.cms.common.persistence.SearchFilter.java
/** * searchParamskey?OPERATOR_FIELDNAME/*from w w w . j a v a 2s.c o m*/ */ public static Map<String, SearchFilter> parse(Map<String, Object> searchParams) { Map<String, SearchFilter> filters = Maps.newHashMap(); for (Entry<String, Object> entry : searchParams.entrySet()) { // String key = entry.getKey(); Object value = entry.getValue(); if (StringUtils.isBlank(String.valueOf(value))) { continue; } // operatorfiledAttribute String[] names = StringUtils.split(key, "_"); if (names.length != 2) { throw new IllegalArgumentException(key + " is not a valid search filter name"); } String filedName = names[1]; Operator operator = Operator.valueOf(names[0]); // searchFilter SearchFilter filter = new SearchFilter(filedName, operator, value); filters.put(key, filter); } return filters; }