package it.f2informatica.webapp.menu;

import it.f2informatica.webapp.security.Authority;
import org.apache.commons.lang.NotImplementedException;
import org.springframework.util.Assert;

import java.util.Map;
import java.util.Set;

public abstract class Menu {

	private static final String METHOD_NOT_IMPLEMENTED = "Method not yet implemented. Called method from: "
			+ Menu.class.getName();

	protected String label;
	protected String url;

	public Menu() {
	}

	public Menu(String label, String url) {
		Assert.notNull(label);
		Assert.notNull(url);
		this.label = label;
		this.url = url;
	}

	public void add(Menu menu) {
		checkIfOperationIsSupported();
	}

	public void add(Menu item, Authority role) {
		checkIfOperationIsSupported();
	}

	public void addWithAuthorities(Menu menu, Set<Authority> authorities) {
		checkIfOperationIsSupported();
	}

	public Map<Menu, Set<Authority>> getMenuItems() {
		checkIfOperationIsSupported();
		throw new NotImplementedException(METHOD_NOT_IMPLEMENTED);
	}

	public Menu getItemByLabel(String label) {
		throw new NotImplementedException(METHOD_NOT_IMPLEMENTED);
	}

	public Menu getItemByUrl(String url) {
		throw new NotImplementedException(METHOD_NOT_IMPLEMENTED);
	}

	public Set<Menu> getItemsByAuthority(Authority role) {
		throw new NotImplementedException(METHOD_NOT_IMPLEMENTED);
	}

	public Set<Menu> getItemsByAuthorities(Set<Authority> authorities) {
		throw new NotImplementedException(METHOD_NOT_IMPLEMENTED);
	}

	public Set<Menu> getExactlyItemsByAuthorities(Set<Authority> authorities) {
		throw new NotImplementedException(METHOD_NOT_IMPLEMENTED);
	}

	public String getLabel() {
		return label;
	}

	public String getUrl() {
		return url;
	}

	private void checkIfOperationIsSupported() {
		if (this instanceof MenuItem || this instanceof EmptyMenuItem) {
			throw new MenuItemException("Unsupported Operation");
		}
	}

	@Override
	public String toString() {
		final StringBuilder sb = new StringBuilder();
		sb.append("Menu");
		sb.append("{label='").append(label).append('\'');
		sb.append(", url='").append(url).append('\'');
		sb.append('}');
		return sb.toString();
	}
}

@@ -143,48 +143,30 @@
 on;%0A
+%0A
 import 
-org.springframework.util.Assert;%0A
+java.util.Map;
 %0Aimp
@@ -175,36 +175,37 @@
 t java.util.
-Map;
+Set;%0A
 %0Aimport 
 java.util.Se
@@ -192,29 +192,72 @@
 %0Aimport 
-java.util.Set
+static com.google.common.base.Preconditions.checkNotNull
 ;%0A%0Apubli
@@ -531,74 +531,40 @@
 %7B%0A%09%09
-Assert.notNull(label);%0A%09%09Assert.notNull(url);%0A%09%09this.label = label
+this.label = checkNotNull(label)
 ;%0A%09%09
@@ -574,19 +574,33 @@
 s.url = 
+checkNotNull(
 url
+)
 ;%0A%09%7D%0A%0A%09p

Switch checking of not null from Assert to Precondition.checkNotNull