Search in sources :

Example 1 with StringBuilder

use of org.rx.core.StringBuilder in project rxlib by RockyLOMO.

the class DataTable method toString.

@Override
public String toString() {
    StringBuilder txt = new StringBuilder();
    for (DataColumn<?> column : getColumns()) {
        txt.append(column.getColumnName()).append("\t");
    }
    txt.appendLine();
    Iterator<DataRow> rows = getRows();
    while (rows.hasNext()) {
        for (Object item : rows.next().items) {
            txt.append(item).append("\t");
        }
        txt.appendLine();
    }
    return txt.toString();
}
Also used : StringBuilder(org.rx.core.StringBuilder) JSONObject(com.alibaba.fastjson.JSONObject)

Example 2 with StringBuilder

use of org.rx.core.StringBuilder in project rxlib by RockyLOMO.

the class EntityQueryLambda method resolve.

static <T> String resolve(ArrayList<BiTuple<Serializable, Operator, ?>> conditions, List<Object> params, List<Tuple<BiFunc<T, ?>, Order>> orders, boolean autoUnderscoreColumnName, Integer limit, Integer offset) {
    StringBuilder b = new StringBuilder(128);
    boolean isParam = params != null;
    for (BiTuple<Serializable, Operator, ?> condition : conditions) {
        Operator op = condition.middle;
        switch(op) {
            case EQ:
            case NE:
            case GT:
            case LT:
            case GE:
            case LE:
            case LIKE:
            case NOT_LIKE:
                {
                    String colName = resolveColumnName(condition.left, autoUnderscoreColumnName);
                    if (!b.isEmpty()) {
                        b.append(OP_AND);
                    }
                    String valHold;
                    if (isParam) {
                        params.add(condition.right);
                        valHold = PARAM_HOLD;
                    } else {
                        valHold = toValueString(condition.right);
                    }
                    b.append(op.format, colName, valHold);
                }
                break;
            case IN:
            case NOT_IN:
                {
                    String colName = resolveColumnName(condition.left, autoUnderscoreColumnName);
                    if (!b.isEmpty()) {
                        b.append(OP_AND);
                    }
                    String valHold;
                    if (isParam) {
                        params.add(condition.right);
                        valHold = PARAM_HOLD;
                    } else {
                        valHold = NQuery.of((Object[]) condition.right).toJoinString(",", EntityQueryLambda::toValueString);
                    }
                    b.append(op.format, colName, valHold);
                }
                break;
            case BETWEEN:
            case NOT_BETWEEN:
                {
                    String colName = resolveColumnName(condition.left, autoUnderscoreColumnName);
                    Object[] p = (Object[]) condition.right;
                    if (!b.isEmpty()) {
                        b.append(OP_AND);
                    }
                    String valHold0, valHold1;
                    if (isParam) {
                        params.add(p[0]);
                        params.add(p[1]);
                        valHold0 = PARAM_HOLD;
                        valHold1 = PARAM_HOLD;
                    } else {
                        valHold0 = toValueString(p[0]);
                        valHold1 = toValueString(p[1]);
                    }
                    b.append(op.format, colName, valHold0, valHold1);
                }
                break;
            case AND:
            case OR:
                ArrayList<BiTuple<Serializable, Operator, ?>> l = (ArrayList<BiTuple<Serializable, Operator, ?>>) condition.left;
                EntityQueryLambda<T> r = (EntityQueryLambda<T>) condition.right;
                if (!b.isEmpty()) {
                    b.append(OP_AND);
                }
                b.append(op.format, resolve(l, params, null, autoUnderscoreColumnName, limit, offset), r.toString(params));
                break;
        }
    }
    if (!CollectionUtils.isEmpty(orders)) {
        b.append(ORDER_BY);
        for (Tuple<BiFunc<T, ?>, Order> bi : orders) {
            String colName = resolveColumnName(bi.left, autoUnderscoreColumnName);
            b.append("%s %s,", colName, bi.right);
        }
        b.setLength(b.length() - 1);
    }
    if (limit != null) {
        b.append(LIMIT);
        if (offset != null) {
            b.append("%s,", offset);
        }
        b.append(limit);
    }
    return b.toString();
}
Also used : Serializable(java.io.Serializable) BiFunc(org.rx.util.function.BiFunc) StringBuilder(org.rx.core.StringBuilder) ArrayList(java.util.ArrayList) BiTuple(org.rx.bean.BiTuple)

Example 3 with StringBuilder

use of org.rx.core.StringBuilder in project rxlib by RockyLOMO.

the class Files method concatPath.

public static String concatPath(@NonNull String root, String... paths) {
    StringBuilder p = new StringBuilder(CURD_FILE.padDirectoryPath(root));
    if (!Arrays.isEmpty(paths)) {
        int l = paths.length - 1;
        for (int i = 0; i < l; i++) {
            p.append(CURD_FILE.padDirectoryPath(paths[i]));
        }
        p.append(paths[l]);
    }
    return p.toString();
}
Also used : StringBuilder(org.rx.core.StringBuilder)

Example 4 with StringBuilder

use of org.rx.core.StringBuilder in project rxlib by RockyLOMO.

the class IOStream method readString.

@SneakyThrows
public static String readString(@NonNull InputStream in, Charset charset) {
    if (charset == null) {
        charset = StandardCharsets.UTF_8;
    }
    StringBuilder result = new StringBuilder();
    byte[] buffer = Bytes.arrayBuffer();
    int read;
    while ((read = in.read(buffer)) > 0) {
        result.append(new String(buffer, 0, read, charset));
    }
    return result.toString();
}
Also used : StringBuilder(org.rx.core.StringBuilder)

Example 5 with StringBuilder

use of org.rx.core.StringBuilder in project rxlib by RockyLOMO.

the class AuthenticEndpoint method toString.

@Override
public String toString() {
    StringBuilder s = new StringBuilder();
    if (!Strings.isEmpty(username)) {
        s.append(username);
    }
    if (!Strings.isEmpty(password)) {
        s.append(":%s", password);
    }
    s.append("@%s", Sockets.toString(endpoint));
    if (!MapUtils.isEmpty(parameters)) {
        s.append(HttpClient.buildUrl(null, (Map) parameters));
    }
    return s.toString();
}
Also used : StringBuilder(org.rx.core.StringBuilder) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

StringBuilder (org.rx.core.StringBuilder)19 SneakyThrows (lombok.SneakyThrows)5 InvalidException (org.rx.exception.InvalidException)4 io.netty.channel (io.netty.channel)3 InetSocketAddress (java.net.InetSocketAddress)3 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)3 Slf4j (lombok.extern.slf4j.Slf4j)3 App.toJsonString (org.rx.core.App.toJsonString)3 ExceptionHandler (org.rx.exception.ExceptionHandler)3 Sockets (org.rx.net.Sockets)3 TransportUtil (org.rx.net.TransportUtil)3 io.netty.handler.codec.socksx.v5 (io.netty.handler.codec.socksx.v5)2 Serializable (java.io.Serializable)2 Inet6Address (java.net.Inet6Address)2 Map (java.util.Map)2 ConcurrentLinkedQueue (java.util.concurrent.ConcurrentLinkedQueue)2 SUID (org.rx.bean.SUID)2 AESCodec (org.rx.net.AESCodec)2 JSONObject (com.alibaba.fastjson.JSONObject)1 ServerBootstrap (io.netty.bootstrap.ServerBootstrap)1