com.github.tcurrie.rest.factory.Strings Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of rest.factory Show documentation
Show all versions of rest.factory Show documentation
Simple rest client-server factory, you give it a url, it does the rest!
package com.github.tcurrie.rest.factory;
import com.github.tcurrie.rest.factory.v1.RestFactoryException;
import org.slf4j.helpers.MessageFormatter;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.Arrays;
public final class Strings {
private Strings() {
throw new RestFactoryException("Can not construct instance of Factory class.");
}
public static String format(final String message, final Object... parameters) {
if (message == null) {
return Arrays.toString(parameters);
} else if (parameters == null || parameters.length == 0) {
return message;
} else if (getMarkerCount(message) < parameters.length) {
return format("Message[{}], parameters[{}]. Format failed.", message, parameters);
} else {
return MessageFormatter.arrayFormat(message, parameters).getMessage();
}
}
private static int getMarkerCount(final String message) {
int count = 0;
for (int index = message.indexOf("{}"); index > -1; index = message.indexOf("{}", index + 2)) {
count++;
}
return count;
}
public static String getStackTrace(final Throwable exception) {
final StringWriter stackTrace = new StringWriter();
exception.printStackTrace(new PrintWriter(stackTrace));
return stackTrace.toString();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy