rspec/rules/S3457/java/compliant.java

42 lines
1.5 KiB
Java
Raw Normal View History

2020-06-22 13:16:10 +02:00
// TODO: Add includes
public class Main
{
public void main() {
2020-06-22 20:34:26 +02:00
// tag::String.format[]
2020-06-22 13:16:10 +02:00
String.format("First %s and then %s", "foo", "bar");
String.format("Display %2$d and then %d", 1, 3);
String.format("Too many arguments %d %d", 1, 2);
String.format("First Line%n");
String.format("Is myObject null ? %b", myObject == null);
String.format("value is %d", value);
2020-06-22 20:34:26 +02:00
String s = "string without arguments";
// end::String.format[]
2020-06-22 13:16:10 +02:00
2020-06-22 20:34:26 +02:00
// tag::MessageFormat[]
2020-06-22 13:16:10 +02:00
MessageFormat.format("Result {0}.", value);
MessageFormat.format("Result '{0}' = {0}", value);
MessageFormat.format("Result {0}.", myObject);
2020-06-22 20:34:26 +02:00
// end::MessageFormat[]
2020-06-22 13:16:10 +02:00
2020-06-22 20:34:26 +02:00
// tag::java.util.Logger[]
2020-06-22 13:16:10 +02:00
java.util.Logger logger;
logger.log(java.util.logging.Level.SEVERE, "Result {0}.", myObject);
logger.log(java.util.logging.Level.SEVERE, "Result {0}'", 14);
logger.log(java.util.logging.Level.SEVERE, exception, () -> "Result " + param);
2020-06-22 20:34:26 +02:00
// end::java.util.Logger[]
2020-06-22 13:16:10 +02:00
2020-06-22 20:34:26 +02:00
// tag::org.slf4j.Logger[]
2020-06-22 13:16:10 +02:00
org.slf4j.Logger slf4jLog;
org.slf4j.Marker marker;
slf4jLog.debug(marker, "message {}");
slf4jLog.debug(marker, "message {}", 1);
2020-06-22 20:34:26 +02:00
// end::org.slf4j.Logger[]
2020-06-22 13:16:10 +02:00
2020-06-22 20:34:26 +02:00
// tag::org.apache.logging.log4j.Logger[]
2020-06-22 13:16:10 +02:00
org.apache.logging.log4j.Logger log4jLog;
log4jLog.debug("message {}", 1);
2020-06-22 20:34:26 +02:00
// end::org.apache.logging.log4j.Logger[]
2020-06-22 13:16:10 +02:00
}
}