Search in sources :

Example 46 with SB

use of org.apache.ignite.internal.util.typedef.internal.SB in project ignite by apache.

the class X method formatMins.

/**
     * Pretty-formatting for minutes.
     *
     * @param mins Minutes to format.
     * @return Formatted presentation of minutes.
     */
public static String formatMins(long mins) {
    assert mins >= 0;
    if (mins == 0)
        return "< 1 min";
    SB sb = new SB();
    // 1440 mins = 60 mins * 24 hours
    long dd = mins / 1440;
    if (dd > 0)
        sb.a(dd).a(dd == 1 ? " day " : " days ");
    mins %= 1440;
    long hh = mins / 60;
    if (hh > 0)
        sb.a(hh).a(hh == 1 ? " hour " : " hours ");
    mins %= 60;
    if (mins > 0)
        sb.a(mins).a(mins == 1 ? " min " : " mins ");
    return sb.toString().trim();
}
Also used : SB(org.apache.ignite.internal.util.typedef.internal.SB)

Example 47 with SB

use of org.apache.ignite.internal.util.typedef.internal.SB in project ignite by apache.

the class GridOffHeapSnapTreeMap method print.

/**
     * @param node Node.
     * @param s String builders.
     * @param level Level.
     * @param offset Offset.
     * @return Length.
     */
private int print(long node, ArrayList<SB> s, int level, int offset) {
    if (node == 0)
        return s.get(level - 1).length();
    SB sb = s.size() <= level ? null : s.get(level);
    if (sb == null) {
        sb = new SB();
        s.add(level, sb);
    }
    int o = Math.max(print(left(node), s, level + 1, offset), offset);
    String v = print0(node);
    while (sb.length() < o) sb.a(' ');
    sb.a(v);
    return print(right(node), s, level + 1, o + v.length());
}
Also used : SB(org.apache.ignite.internal.util.typedef.internal.SB)

Example 48 with SB

use of org.apache.ignite.internal.util.typedef.internal.SB in project ignite by apache.

the class VisorQueryUtils method binaryToString.

/**
     * Convert Binary object to string.
     *
     * @param obj Binary object.
     * @return String representation of Binary object.
     */
public static String binaryToString(BinaryObject obj) {
    int hash = obj.hashCode();
    if (obj instanceof BinaryObjectEx) {
        BinaryObjectEx objEx = (BinaryObjectEx) obj;
        BinaryType meta;
        try {
            meta = ((BinaryObjectEx) obj).rawType();
        } catch (BinaryObjectException ignore) {
            meta = null;
        }
        if (meta != null) {
            SB buf = new SB(meta.typeName());
            if (meta.fieldNames() != null) {
                buf.a(" [hash=").a(hash);
                for (String name : meta.fieldNames()) {
                    Object val = objEx.field(name);
                    buf.a(", ").a(name).a('=').a(val);
                }
                buf.a(']');
                return buf.toString();
            }
        }
    }
    return S.toString(obj.getClass().getSimpleName(), "hash", hash, false, "typeId", obj.type().typeId(), true);
}
Also used : BinaryType(org.apache.ignite.binary.BinaryType) BinaryObjectEx(org.apache.ignite.internal.binary.BinaryObjectEx) BinaryObject(org.apache.ignite.binary.BinaryObject) BinaryObjectException(org.apache.ignite.binary.BinaryObjectException) SB(org.apache.ignite.internal.util.typedef.internal.SB)

Example 49 with SB

use of org.apache.ignite.internal.util.typedef.internal.SB in project ignite by apache.

the class IgniteUtils method makeMBeanName.

/**
     * Constructs JMX object name with given properties.
     * Map with ordered {@code groups} used for proper object name construction.
     *
     * @param igniteInstanceName Ignite instance name.
     * @param grp Name of the group.
     * @param name Name of mbean.
     * @return JMX object name.
     * @throws MalformedObjectNameException Thrown in case of any errors.
     */
public static ObjectName makeMBeanName(@Nullable String igniteInstanceName, @Nullable String grp, String name) throws MalformedObjectNameException {
    SB sb = new SB(JMX_DOMAIN + ':');
    appendClassLoaderHash(sb);
    appendJvmId(sb);
    if (igniteInstanceName != null && !igniteInstanceName.isEmpty())
        sb.a("igniteInstanceName=").a(igniteInstanceName).a(',');
    if (grp != null)
        sb.a("group=").a(grp).a(',');
    sb.a("name=").a(name);
    return new ObjectName(sb.toString());
}
Also used : SB(org.apache.ignite.internal.util.typedef.internal.SB) ObjectName(javax.management.ObjectName)

Example 50 with SB

use of org.apache.ignite.internal.util.typedef.internal.SB in project ignite by apache.

the class IgniteUtils method addressesAsString.

/**
     * Returns string representation of addresses.
     *
     * @param addrs Addresses.
     * @param hostNames Host names.
     * @return String representation of addresses.
     */
public static String addressesAsString(Collection<String> addrs, Collection<String> hostNames) {
    if (F.isEmpty(addrs))
        return "";
    if (F.isEmpty(hostNames))
        return addrs.toString();
    SB sb = new SB("[");
    Iterator<String> hostNamesIt = hostNames.iterator();
    boolean first = true;
    for (String addr : addrs) {
        if (first)
            first = false;
        else
            sb.a(", ");
        String hostName = hostNamesIt.hasNext() ? hostNamesIt.next() : null;
        sb.a(hostName != null ? hostName : "").a('/').a(addr);
    }
    sb.a(']');
    return sb.toString();
}
Also used : SB(org.apache.ignite.internal.util.typedef.internal.SB)

Aggregations

SB (org.apache.ignite.internal.util.typedef.internal.SB)57 Map (java.util.Map)8 HashMap (java.util.HashMap)5 IOException (java.io.IOException)4 ArrayList (java.util.ArrayList)4 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)4 GridStringBuilder (org.apache.ignite.internal.util.GridStringBuilder)4 IgfsLogger (org.apache.ignite.internal.igfs.common.IgfsLogger)3 InputStream (java.io.InputStream)2 InputStreamReader (java.io.InputStreamReader)2 LineNumberReader (java.io.LineNumberReader)2 URL (java.net.URL)2 URLConnection (java.net.URLConnection)2 Date (java.util.Date)2 HashSet (java.util.HashSet)2 LinkedHashMap (java.util.LinkedHashMap)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 ObjectName (javax.management.ObjectName)2 BinaryObject (org.apache.ignite.binary.BinaryObject)2 BinaryObjectException (org.apache.ignite.binary.BinaryObjectException)2