Java Code Examples for org.osgl.util.S#builder()
The following examples show how to use
org.osgl.util.S#builder() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: StringUtils.java From actframework with Apache License 2.0 | 6 votes |
public static String processStringSubstitution(String s, $.Func1<String, String> evaluator) { if (S.blank(s)) { return ""; } int n = s.indexOf("${"); if (n < 0) { return s; } int a = 0; int z = n; StringBuilder buf = S.builder(); while (true) { buf.append(s.substring(a, z)); n = s.indexOf("}", z); a = n + 1; String key = s.substring(z + 2, a - 1); buf.append(evaluator.apply(key)); n = s.indexOf("${", a); if (n < 0) { buf.append(s.substring(a)); return buf.toString(); } z = n; } }
Example 2
Source File: SimpleRestfulServiceBase.java From actframework with Apache License 2.0 | 4 votes |
public static <MODEL_TYPE> Dao.Query<MODEL_TYPE, ?> filter(Dao<?, MODEL_TYPE, ?> dao, ParamValueProvider paramValueProvider) { Set<String> filterKeys = paramValueProvider.paramKeys(); if (filterKeys.isEmpty()) { return dao.q(); } JodaDateTimeCodec dateTimeCodec = Act.getInstance(JodaDateTimeCodec.class); JodaLocalDateCodec localDateCodec = Act.getInstance(JodaLocalDateCodec.class); JodaLocalTimeCodec localTimeCodec = Act.getInstance(JodaLocalTimeCodec.class); JodaLocalDateTimeCodec localDateTimeCodec = Act.getInstance(JodaLocalDateTimeCodec.class); StringBuilder filters = S.builder(); List targets = new ArrayList(); for (String key : filterKeys) { if (key.startsWith("_")) { continue; } String[] vals = paramValueProvider.paramVals(key); int n = vals.length; for (int i = 0; i < n; ++i) { String val = vals[i]; String op = null; Object tgt = val; if (val.startsWith("~")) { op = "like"; tgt = dao.processLikeValue(val.substring(1)); } else if (val.contains("_")) { String prefix = S.cut(val).beforeFirst("_"); N.Comparator comp = N.Comparator.of(prefix); if (null != comp) { op = comp.name(); if (comp == N.Comparator.EQ) { op = null; } val = S.cut(val).afterFirst("_"); } if (N.isInt(val)) { tgt = Integer.parseInt(val); } else if (N.isNumeric(val)) { tgt = Double.parseDouble(val); } else { // try date time try { tgt = dateTimeCodec.parse(val); } catch (Exception e) { try { tgt = localDateCodec.parse(val); } catch (Exception e1) { try { tgt = localTimeCodec.parse(val); } catch (Exception e2) { try { tgt = localDateTimeCodec.parse(val); } catch (Exception e3) { // ignore } } } } } } filters.append(key); if (null != op) { filters.append(" ").append(op); } filters.append(","); targets.add(tgt); } } if (filters.length() > 0) { filters.deleteCharAt(filters.length() - 1); // remove last comma return dao.q(filters.toString(), targets.toArray(new Object[targets.size()])); } return dao.q(); }
Example 3
Source File: EndpointTester.java From actframework with Apache License 2.0 | 4 votes |
public ReqBuilder(String pathTmpl, Object ... args) { String s = fullUrl(pathTmpl, args); sb = S.builder(s); paramAttached = s.contains("?"); }