package javaslang.lang;

import java.util.function.Function;
import java.util.function.Supplier;

import javaslang.util.Objects;

/**
 * General Java languange extensions. See also {@link java.util.Objects}.
 */
public final class Lang {

	private Lang() {
		throw new AssertionError(Lang.class.getName() + " cannot be instantiated.");
	}
	
	public static void print(Supplier<Object> supplier) {
		print(supplier.get());
	}

	public static void println(Supplier<Object> supplier) {
		println(supplier.get());
	}

	/**
	 * Shortcut for <code>System.out.print(javaslang.util.Objects.toString(o))</code>.
	 * 
	 * @param o an Object
	 */
	public static void print(Object o) {
		final String s = Objects.toString(o);
		System.out.print(s);
	}

	/**
	 * Shortcut for <code>System.out.println(javaslang.util.Objects.toString(o))</code>.
	 * 
	 * @param o an Object
	 */
	public static void println(Object o) {
		final String s = Objects.toString(o);
		System.out.println(s);
	}

	/**
	 * Shortcut for <code>System.out.print(String.format(format, args))</code>.
	 * 
	 * @param format
	 * @param args
	 * 
	 * @see String#format(String, Object...)
	 */
	public static void print(String format, Object... args) {
		final String s = String.format(format, args);
		System.out.print(s);
	}

	/**
	 * Shortcut for <code>System.out.println(String.format(format, args))</code>.
	 * 
	 * @param format
	 * @param args
	 * 
	 * @see String#format(String, Object...)
	 */
	public static void println(String format, Object... args) {
		final String s = String.format(format, args);
		System.out.println(s);
	}

	/**
	 * Runtime check which will throw an IllegalStateException containing the given message if the condition is false.
	 * 
	 * @param condition A boolean
	 * @param message A message An error message.
	 * @throws IllegalStateException If condition is false, contains the message.
	 */
	public static void require(boolean condition, String message) throws IllegalStateException {
		if (!condition) {
			throw new IllegalStateException(message);
		}
	}

	/**
	 * Runtime check which will throw an IllegalStateException containing the given message if the condition is false.
	 * The message is computed only if the condition is false.
	 * 
	 * @param condition A boolean
	 * @param messageSupplier An error message, computed lazily.
	 * @throws IllegalStateException If condition is false, contains the message.
	 */
	public static void require(boolean condition, Supplier<String> messageSupplier) throws IllegalStateException {
		if (!condition) {
			throw new IllegalStateException(messageSupplier.get());
		}
	}

	/**
	 * Builder pattern.
	 * 
	 * @param obj
	 * @param f
	 * @return
	 */
	public static <T, U> U with(T obj, Function<T, U> f) {
		return f.apply(obj);
	}

}

@@ -48,17 +48,18 @@
 ion.
-Function;
+Supplier;%0A
 %0Aimp
@@ -70,33 +70,26 @@
 java
-.util.function.Supplier;%0A
+slang.util.Arrays;
 %0Aimp
@@ -1019,36 +1019,70 @@
 .format(format, 
-args
+Arrays.map(objects, Objects::toString)
 ))%3C/code%3E.%0A%09 * %0A
@@ -1102,35 +1102,38 @@
 rmat%0A%09 * @param 
-arg
+object
 s%0A%09 * %0A%09 * @see 
@@ -1213,39 +1213,106 @@
 rmat, Object... 
-args) %7B
+objects) %7B%0A%09%09final Object%5B%5D args = Arrays.map(objects, Objects::toString);
 %0A%09%09final String 
@@ -1440,20 +1440,54 @@
 format, 
-args
+Arrays.map(objects, Objects::toString)
 ))%3C/code
@@ -1523,19 +1523,22 @@
  @param 
-arg
+object
 s%0A%09 * %0A%09
@@ -1640,15 +1640,82 @@
 ... 
-args) %7B
+objects) %7B%0A%09%09final Object%5B%5D args = Arrays.map(objects, Objects::toString);
 %0A%09%09f
@@ -2809,165 +2809,6 @@
 %09%7D%0A%0A
-%09/**%0A%09 * Builder pattern.%0A%09 * %0A%09 * @param obj%0A%09 * @param f%0A%09 * @return%0A%09 */%0A%09public static %3CT, U%3E U with(T obj, Function%3CT, U%3E f) %7B%0A%09%09return f.apply(obj);%0A%09%7D%0A%0A
 %7D%0A

print format args are mapped using Objects::toString