Class Strings

java.lang.Object
arc.util.Strings
com.xpdustry.claj.common.util.Strings

public class Strings extends arc.util.Strings
  • Constructor Details

    • Strings

      public Strings()
  • Method Details

    • rJust

      public static String rJust(String str, int length)
    • rJust

      public static String rJust(String str, int length, String filler)
      Justify string to the right. E.g. "  right"
    • rJust

      public static arc.struct.Seq<String> rJust(arc.struct.Seq<String> list, int length)
    • rJust

      public static arc.struct.Seq<String> rJust(arc.struct.Seq<String> list, int length, String filler)
    • lJust

      public static String lJust(String str, int length)
    • lJust

      public static String lJust(String str, int length, String filler)
      Justify string to the left. E.g. "left  "
    • lJust

      public static arc.struct.Seq<String> lJust(arc.struct.Seq<String> list, int length)
    • lJust

      public static arc.struct.Seq<String> lJust(arc.struct.Seq<String> list, int length, String filler)
    • cJust

      public static String cJust(String str, int length)
    • cJust

      public static String cJust(String str, int length, String filler)
      Justify string to the center. E.g. "  center  ".
    • cJust

      public static arc.struct.Seq<String> cJust(arc.struct.Seq<String> list, int length)
    • cJust

      public static arc.struct.Seq<String> cJust(arc.struct.Seq<String> list, int length, String filler)
    • sJust

      public static String sJust(String left, String right, int length)
    • sJust

      public static String sJust(String left, String right, int length, String filler)
      Justify string to the sides. E.g. "left   right"
    • sJust

      public static arc.struct.Seq<String> sJust(arc.struct.Seq<String> left, arc.struct.Seq<String> right, int length)
    • sJust

      public static arc.struct.Seq<String> sJust(arc.struct.Seq<String> left, arc.struct.Seq<String> right, int length, String filler)
    • columnify

      @SafeVarargs public static arc.struct.Seq<String> columnify(arc.struct.Seq<String>... columns)
    • columnify

      @SafeVarargs public static arc.struct.Seq<String> columnify(int gap, arc.struct.Seq<String>... columns)
    • columnify

      @SafeVarargs public static arc.struct.Seq<String> columnify(String filler, arc.struct.Seq<String>... columns)
    • columnify

      @SafeVarargs public static arc.struct.Seq<String> columnify(int gap, String filler, arc.struct.Seq<String>... columns)
    • columnify

      public static arc.struct.Seq<String> columnify(String filler, arc.struct.Seq<String>[] columns, int[] lengths)
    • columnify

      public static arc.struct.Seq<String> columnify(int gap, String filler, arc.struct.Seq<String>[] columns, int[] lengths)
    • tableify

      public static arc.struct.Seq<String> tableify(arc.struct.Seq<String> lines, int width)
    • tableify

      public static arc.struct.Seq<String> tableify(arc.struct.Seq<String> lines, int width, int gap)
    • tableify

      public static arc.struct.Seq<String> tableify(arc.struct.Seq<String> lines, int width, arc.func.Func2<String,Integer,String> justifier)
    • tableify

      public static arc.struct.Seq<String> tableify(arc.struct.Seq<String> lines, int width, int gap, arc.func.Func2<String,Integer,String> justifier)
      Create a table with given lines.
      Columns number is automatic calculated with the table's width.
    • isVersionAtLeast

      public static boolean isVersionAtLeast(String currentVersion, String newVersion)
    • isVersionAtLeast

      public static boolean isVersionAtLeast(String currentVersion, String newVersion, int maxDepth)
    • compareVersion

      public static int compareVersion(String currentVersion, String newVersion)
    • compareVersion

      public static int compareVersion(String currentVersion, String newVersion, int maxDepth)
      Compare if newVersion is greater or less than currentVersion, e.g. "v146" > "124.1".
      maxDepth defines the number of comparisons of version segments, allowing sub-versions to be ignored. (default is 0)
    • kebabize

      public static String kebabize(String s)
    • repeat

      public static String repeat(String str, int count)
      Taken from the String.repeat(int) method of JDK 11
    • repeat

      public static String repeat(char c, int count)
    • maxLength

      public static int maxLength(Iterable<? extends String> list)
    • maxLength

      public static int maxLength(String... list)
    • normalize

      public static String normalize(String str)
    • isTrue

      public static boolean isTrue(String str)
      Returns:
      whether the specified string mean true
    • isTrue

      public static boolean isTrue(String str, boolean isValue)
      Returns:
      whether the specified string mean true
    • isFalse

      public static boolean isFalse(String str)
      Returns:
      whether the specified string mean false
    • isFalse

      public static boolean isFalse(String str, boolean isValue)
      Returns:
      whether the specified string mean false
    • jsonPrettyPrint

      public static String jsonPrettyPrint(arc.util.serialization.JsonValue object, arc.util.serialization.JsonWriter.OutputType outputType)
    • jsonPrettyPrint

      public static void jsonPrettyPrint(arc.util.serialization.JsonValue object, Writer writer, arc.util.serialization.JsonWriter.OutputType outputType) throws IOException
      Throws:
      IOException
    • jsonPrettyPrint

      public static void jsonPrettyPrint(arc.util.serialization.JsonValue object, Writer writer, arc.util.serialization.JsonWriter.OutputType outputType, int indent) throws IOException
      Re-implementation of JsonValue.prettyPrint(OutputType, Writer), because the ident isn't correct and the max object size before new line is too big.
      Throws:
      IOException
    • toJson

      public static void toJson(arc.util.serialization.JsonValue object, Writer writer, arc.util.serialization.JsonWriter.OutputType outputType) throws IOException
      Re-implementation of JsonValue.json(JsonValue, StringBuilder, OutputType), with the ability write directly to a Writer instead of a StringBuilder.
      Throws:
      IOException
    • format

      public static void format(StringBuilder out, String text, Object... args)
      Like Strings.format(String, Object[]) but you can specify the StringBuilder.
    • join

      public static String join(CharSequence delimiter, CharSequence[] elements, int start, int end)
      Like String.join(CharSequence, CharSequence[]) but you can specify the start and end of the list.
    • toSentence

      public static <T> String toSentence(Iterable<T> list, arc.func.Func<T,String> stringifier)
      Converts a list to a human readable sentence. E.g. [1, 2, 3, 4, 5] -> "1, 2, 3, 4 and 5"
    • toSentence

      public static <T> String toSentence(Iterable<T> list, arc.func.Func<T,String> stringifier, String or, String and)
      Converts a list to a human readable sentence with configurable or and and delimiters.
    • toSentence

      public static <T> void toSentence(StringBuilder builder, Iterable<T> list, arc.func.Cons2<StringBuilder, T> stringifier)
      Converts a list to a human readable sentence. E.g. [1, 2, 3, 4, 5] -> "1, 2, 3, 4 and 5"
    • toSentence

      public static <T> void toSentence(StringBuilder builder, Iterable<T> list, arc.func.Cons2<StringBuilder, T> stringifier, String or, String and)
      Converts a list to a human readable sentence with configurable or and and delimiters.
    • contains

      public static boolean contains(String src, arc.func.Boolf<Character> predicate)
      String.contains(CharSequence) but with a predicate.
    • matches

      public static boolean matches(String src, arc.func.Boolf<Character> predicate)
      String.matches(String) but with a predicate.
    • longToBase64

      public static String longToBase64(long l)
      Encodes a long to an url-safe base64 string.
    • base64ToLong

      public static long base64ToLong(String str)
    • readUTF

      public static String readUTF(arc.util.io.ByteBufferInput in)
      Method that suppress IOException from ByteBufferInput.readUTF().
    • writeUTF

      public static void writeUTF(arc.util.io.ByteBufferOutput in, String str)
      Method that suppress IOException from ByteBufferOutput.writeUTF(String).
    • formattedClassName

      public static String formattedClassName(Class<?> clazz)
    • formatBytes

      public static String formatBytes(long v)
    • formatSize

      public static String formatSize(long value, int base, String unit)
    • formatDuration

      public static String formatDuration(long millis, boolean narrow)
      Convert millis duration to localized human readable format (e.g. 123456 -> 2 minutes and 3 seconds), using the logger system.
      Parameters:
      millis - milliseconds to convert to duration
      narrow - use short units or not. E.g. "5 months" if false, "5mo" if true
    • wordTruncate

      public static String wordTruncate(String str, int length)
    • wordTruncate

      public static String wordTruncate(String str, int length, String ellipsis)
      https://stackoverflow.com/a/17188686