Java Utililty Methods Java String Format

List of utility methods to do Java String Format

Description

The list of methods to do Java String Format are organized into topic(s).

Method

StringtoJavaScriptSafeString(String content)
Convert a string to a JavaScript safe string (escape quotes and remove cr and lf).
content = content.replaceAll("'", "\\\\'");
content = content.replaceAll("\"", "\\\\\"");
content = content.replaceAll("\\r\\n", "");
content = content.replaceAll("\\r", "");
content = content.replaceAll("\\n", "");
return content;
longtoJavaSecs(long secs)
Converts the given postgresql seconds to java seconds.
secs += 946684800L;
if (secs < -12219292800L) { 
    secs += 86400 * 10;
    if (secs < -14825808000L) { 
        int extraLeaps = (int) ((secs + 14825808000L) / 3155760000L);
        extraLeaps--;
        extraLeaps -= extraLeaps / 4;
        secs += extraLeaps * 86400L;
...
StringtoJavaSourceType(String type)
Class.getName() return arrays in the form "[[[", where et, the element type can be one of ZBCDFIJS or L; It is converted into forms that can be understood by javac.
if (type.charAt(0) != '[') {
    return type;
int dims = 1;
String t = null;
for (int i = 1; i < type.length(); i++) {
    if (type.charAt(i) == '[') {
        dims++;
...
StringtoJavaStaticIdentifier(String string)
Fashion a static identifier from the given string.
String javaIdentifierName = toJavaInstanceIdentifier(string);
StringBuilder sb = new StringBuilder(javaIdentifierName.length() + 5);
for (int i = 0, l = javaIdentifierName.length(); i < l; i++) {
    char ch = javaIdentifierName.charAt(i);
    if (Character.isUpperCase(ch)) {
        boolean nextCharLowerCase = false;
        boolean prevCharLowerCase = false;
        int nextIndex = i + 1;
...
StringtoJavaString(final String s)
to Java String
if (s == null) {
    return null;
String t = s.trim();
if (!isGamaString(t)) {
    return s;
if (t.length() >= 2) {
...
StringtoJavaString(String buf)
Escape characters unallowed in the Java source files.
return escape(buf, "\\u");
StringtoJavaString(String text)
to Java String
String string = text;
if (string != null) {
    string = string.replaceAll("\n", "\\\\n");
    string = string.replaceAll("\r", "\\\\r");
    string = string.replaceAll("\"", "\\\\\"");
StringBuilder sb = new StringBuilder();
sb.append("\"");
...
longtoJavaTime(double time)
Convert from Hydra time in seconds since the epoch as a double to Java standard time in milliseconds since the epoch as a long.
return (long) (1000d * time);
StringtoJavaTypeIdentifier(String string)
Fashion a type identifier from the given string.
StringBuilder sb = new StringBuilder(toJavaInstanceIdentifier(string));
sb.setCharAt(0, Character.toUpperCase(sb.charAt(0)));
return sb.toString();
StringtoJavaTypeName(String edmTypeName)
Returns the name of the corresponding Java class or scalar type.
String result = "Object";
if (edmTypeName.endsWith("Binary")) {
    result = "byte[]";
} else if (edmTypeName.endsWith("Boolean")) {
    result = "boolean";
} else if (edmTypeName.endsWith("DateTime")) {
    result = "Date";
} else if (edmTypeName.endsWith("DateTimeOffset")) {
...