/**
   * Joins array elements to string.
   *
   * @param arr Array.
   * @return String.
   */
  @Nullable
  public static String compactArray(Object[] arr) {
    if (arr == null || arr.length == 0) return null;

    String sep = ", ";

    StringBuilder sb = new StringBuilder();

    for (Object s : arr) sb.append(s).append(sep);

    if (sb.length() > 0) sb.setLength(sb.length() - sep.length());

    return U.compact(sb.toString());
  }
Esempio n. 2
1
 /**
  * Replace given characters in a given string builder.
  * The number of characters to replace has to match to number of
  * characters serving as a replacement.
  *
  * @param sb string builder containing a string to be modified
  * @param from characters to replaced
  * @param to replacement characters
  * @return original string builder with replaced characters.
  */
 public static StringBuilder replace(StringBuilder sb, CharSequence from, CharSequence to) {
   assert from.length() == to.length();
   for (int i=0; i<sb.length(); i++)
     for (int j=0; j<from.length(); j++)
       if (sb.charAt(i)==from.charAt(j)) sb.setCharAt(i, to.charAt(j));
   return sb;
 }
Esempio n. 3
0
 public static String calculateCrc32(String source) {
   CRC32 crc32 = new CRC32();
   Adler32 adler32 = new Adler32();
   adler32.update(source.getBytes());
   System.out.println(adler32.getValue());
   crc32.update(source.getBytes());
   StringBuilder builder = new StringBuilder(8);
   System.out.println(crc32.getValue());
   System.out.println(Long.toHexString(crc32.getValue()));
   builder.append(Long.toHexString(crc32.getValue()));
   if (builder.length() < 8) {
     builder.append(CHAR_TEMPLATE, 0, 8 - builder.length());
   }
   System.out.println(builder.toString());
   return builder.toString();
 }
Esempio n. 4
0
 public BSONTest() {
   for (int x = 8; x < 2048; x *= 2) {
     StringBuilder buf = new StringBuilder();
     while (buf.length() < x) buf.append(x);
     _data.add(buf.toString());
   }
 }