Java Code Examples for org.osgl.util.S#notEmpty()

The following examples show how to use org.osgl.util.S#notEmpty() . 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: Help.java    From actframework with Apache License 2.0 6 votes vote down vote up
private void list(String label, Collection<CliCmdInfo> commands, CliContext context, String q, String fmt) {
    List<String> lines = new ArrayList<>();
    lines.add(label.toUpperCase());
    q = S.string(q).trim();
    boolean hasFilter = S.notEmpty(q);
    List<CliCmdInfo> toBeDisplayed = new ArrayList<>();
    for (CliCmdInfo info : commands) {
        String cmd = info.name;
        if (hasFilter && !(cmd.toLowerCase().contains(q) || cmd.matches(q))) {
            continue;
        }
        if (null == fmt) {
            toBeDisplayed.add(info);
        } else {
            lines.add(S.fmt(fmt, info.nameAndShortcut(), info.help));
        }
    }
    context.println(Ansi.ansi().render(S.join("\n", lines)).toString());

    if (null == fmt) {
        // display table list
        context.println(CliView.TABLE.render(toBeDisplayed, metaInfo, context));
    }
}
 
Example 2
Source File: ParamTree.java    From actframework with Apache License 2.0 5 votes vote down vote up
private static void addTokenToList(List<String> list, S.Buffer token) {
    String s = token.toString();
    if (S.notEmpty(s)) {
        list.add(s);
    } else {
        LOGGER.warn("empty index encountered");
    }
    token.delete(0, s.length() + 1);
}
 
Example 3
Source File: Exists.java    From actframework with Apache License 2.0 5 votes vote down vote up
private boolean exists(Object value) {
    if (null == value) {
        return false;
    }
    if (value instanceof String) {
        return S.notEmpty((String) value);
    }
    return true;
}
 
Example 4
Source File: I18n.java    From actframework with Apache License 2.0 5 votes vote down vote up
public static Map<String, Object> i18n(Locale locale, String bundleName, Class<? extends Enum> enumClass, boolean outputProperties) {
    LinkedHashMap<String, Object> map = new LinkedHashMap<>();

    for (Enum<?> enumInstance : enumClass.getEnumConstants()) {
        String name = enumInstance.name();
        String val = i18n(locale, bundleName, enumInstance);
        if (outputProperties) {
            Map<String, Object> values = new HashMap<>();
            map.put(name, values);
            values.put("message", val);
            Map<String, $.Function<Object, Object>> getters = enumPropertyGetters(enumClass);
            for (Map.Entry<String, $.Function<Object, Object>> entry : getters.entrySet()) {
                String key = entry.getKey();
                if (key.startsWith("get")) {
                    String newKey = key.substring(3);
                    if (S.notEmpty(newKey)) {
                        char c = newKey.charAt(0);
                        if (Character.isUpperCase(c)) {
                            key = S.lowerFirst(newKey);
                        }
                    }
                }
                values.put(key, entry.getValue().apply(enumInstance));
            }
        } else {
            map.put(name, val);
        }
    }
    return map;
}