package de.hpi.bpt.chimera.validation;

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.lang3.StringUtils;

import de.hpi.bpt.chimera.model.Nameable;

public class NameValidation {
	private NameValidation() {
	}

	/**
	 * Check if name contains only unicode letters, numbers or spaces (' ').
	 * 
	 * @param name
	 */
	public static void validateName(String name) {
		if (!StringUtils.isAlphanumericSpace(name)) {
			throw new IllegalArgumentException(String.format("%s is not a valid name", name));
		}
	}

	/**
	 * Check if name of an Nameable Object occurs more than once in a List of
	 * Nameable Objects.
	 * 
	 * @param nameables
	 *            List of nameable Objects
	 */
	public static void validateNameFrequency(List<? extends Nameable> nameables) {
		List<String> names = new ArrayList<>();

		for (Nameable nameable : nameables) {
			String name = nameable.getName();
			if (names.contains(name)) {
				throw new IllegalArgumentException(String.format("%s occurs more than once", name));
			}
			names.add(name);
		}
	}
}

@@ -83,16 +83,80 @@
 il.List;
+%0Aimport java.util.regex.Matcher;%0Aimport java.util.regex.Pattern;
 %0A%0Aimport
@@ -281,109 +281,482 @@
 ate 
-NameValidation() %7B%0A%09%7D%0A%0A%09/**%0A%09 * Check if name contains only unicode letters, numbers or spaces (' ').
+static final Pattern NAME_PATTERN = Pattern.compile(%22%5E%5Ba-zA-Z0-9%5D(?!%5Ba-zA-Z0-9 _%5D*?%5B _%5D%7B2%7D.*)%5Ba-zA-Z0-9 _%5D*?%5Ba-zA-Z0-9%5D$%22);%0A%09%0A%09private NameValidation() %7B%0A%09%7D%0A%0A%09/**%0A%09 * Check if name is valid. %0A%09 * Valid names start and end with an alpha-numeric character and can contain alpha-numeric characters, spaces and%0A%09 * underscores. However, no two spaces or underscores can follow each other.%0A%09 * Examples:%0A%09 * %22a_b_c%22 valid%0A%09 * %22a__z%22 invalid%0A%09 * %22%C3%A4%C2%B5%E2%82%AC%22 invalid (no unicode support)
 %0A%09 *
@@ -837,45 +837,46 @@
 f (!
-StringUtils.isAlphanumericSpace(name)
+ NAME_PATTERN.matcher(name).matches() 
 ) %7B%0A

Use RegEx to check validity of names in Chimera