package utilities; import java.util.UUID; /** * Class to enforce the game rule * of generating unique names * * @author Rukmal Fernando * @author Hardik Kotecha * @author Radhika Srinivasan */ public class NameGenerator { private final static String _PLAYER_FLAG = "FKS"; //marker for derivatives created by this player //private final static String _PLAYER_FLAG = "MP"; /** * generate a new name and return the string * * @return string */ public static String getNewName() { UUID newID = UUID.randomUUID(); //generate a new UUID String uuidString = newID.toString(); //convert the UUID to a String char oldChar = '-'; //the hyphen character is not legal in the class dictionary char newChar = '_'; //the hyphens are therefore replaced with an _. uuidString = uuidString.replace(oldChar, newChar); String retName = _PLAYER_FLAG.concat( uuidString ); //combine our branding and uuid return retName; //return the resulting String } }