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();
}
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());
}
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);
}
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());
}
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();
}
Aggregations