package net.etalia.client.utils;

import java.security.MessageDigest;
import java.util.Collection;
import java.util.logging.Level;
import java.util.logging.Logger;

public class Utils {

	private final static Logger log = Logger.getLogger(Utils.class.getName());

	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) {
		assertTrue(string, obj == null);
	}

	public static String md5(String value) {
		String digest = null;
		try {
			MessageDigest md = MessageDigest.getInstance("MD5");
			byte[] hash = md.digest(value.getBytes("UTF-8"));
			StringBuilder sb = new StringBuilder(2*hash.length);
			for (byte b : hash) {
				sb.append(String.format("%02x", b&0xff));
			}
			digest = sb.toString();
		} catch(Exception e) {
			log.log(Level.SEVERE, "Cannot calculate MD5", e);
		}
		return digest;
	}

}

@@ -43,224 +43,46 @@
 ava.
-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());
+util.Collection;%0A%0Apublic class Utils %7B
 %0A%0A%09p
@@ -1396,451 +1396,6 @@
 %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

Implement empty method