package net.etalia.client.utils;

import java.util.Collection;

public class Utils {

	public static void assertFalse(String string, boolean b) {
		if (b) throw new IllegalStateException(string);
	}

	public static void assertTrue(String string, boolean b) {
		if (!b) throw new IllegalStateException(string);
	}

	/**
	 * Joins the given path segments together, adding slashes where appropriate.
	 * @param segments A list of strings representing path segments.
	 * @return the segments joined with forward slash properly to form a valid path.
	 */
	public static String pathConcat(String... segments) {
		StringBuilder sb = new StringBuilder();
		boolean lastEndsWithSlash = false;
		boolean first = true;
		for(String s : segments) {
			if(first) {
				sb.append(s);
				first = false;
			} else {
				if((! lastEndsWithSlash) && (! s.startsWith("/"))) {
					sb.append("/");
					sb.append(s);
				} else if(lastEndsWithSlash && s.startsWith("/")) {
					sb.append(s.substring(1));
				} else {
					sb.append(s);
				}
			}
			if(s.endsWith("/")) {
				lastEndsWithSlash = true;
			}
		}
		return sb.toString();
	}
	
	/**
	 * @see #pathConcat(String...)
	 */
	public static String pathConcat(Collection<String> segments) {
		return pathConcat(segments.toArray(new String[segments.size()]));
	}

	public static void assertNull(String string, Object obj) {
		// TODO Auto-generated method stub
		
	}	
	
}

@@ -43,46 +43,224 @@
 ava.
-util.Collection;%0A%0Apublic class Utils %7B
+security.MessageDigest;%0Aimport java.util.Collection;%0Aimport java.util.logging.Level;%0Aimport java.util.logging.Logger;%0A%0Apublic class Utils %7B%0A%0A%09private final static Logger log = Logger.getLogger(Utils.class.getName());
 %0A%0A%09p
@@ -1537,50 +1537,488 @@
 %7B%0A%09%09
-// TODO Auto-generated method stub%0A%09%09%0A%09%7D%09%0A%09
+assertTrue(string, obj == null);%0A%09%7D%0A%0A%09public static String md5(String value) %7B%0A%09%09String digest = null;%0A%09%09try %7B%0A%09%09%09MessageDigest md = MessageDigest.getInstance(%22MD5%22);%0A%09%09%09byte%5B%5D hash = md.digest(value.getBytes(%22UTF-8%22));%0A%09%09%09StringBuilder sb = new StringBuilder(2*hash.length);%0A%09%09%09for (byte b : hash) %7B%0A%09%09%09%09sb.append(String.format(%22%2502x%22, b&0xff));%0A%09%09%09%7D%0A%09%09%09digest = sb.toString();%0A%09%09%7D catch(Exception e) %7B%0A%09%09%09log.log(Level.SEVERE, %22Cannot calculate MD5%22, e);%0A%09%09%7D%0A%09%09return digest;%0A%09%7D%0A
 %0A%7D%0A

Add Logging Add md5() method Add implementation for assertNull()