package dungeonmania.util;
import java.util.Arrays;
import java.util.Iterator;
Copyright By PowCoder代写 加微信 powcoder
import dungeonmania.entities.Door;
import dungeonmania.entities.Entity;
import dungeonmania.entities.Portal;
public class NameConverter {
public static String toSnakeCase(Entity entity) {
String nameBasic = toSnakeCase(entity.getClass().getSimpleName());
if (entity instanceof Portal) {
String color = “_” + ((Portal) entity).getColor().toLowerCase();
return nameBasic + color;
if (entity instanceof Door) {
String open = ((Door) entity).isOpen() ? “_open” : “”;
return nameBasic + open;
return nameBasic;
public static String toSnakeCase(String name) {
String[] words = name.split(“(?=[A-Z])”);
if (words.length == 1)
return words[0].toLowerCase();
StringBuilder builder = new StringBuilder();
Iterator
builder.append(iter.next().toLowerCase());
while (iter.hasNext())
builder.append(“_”).append(iter.next().toLowerCase());
return builder.toString();
public static String toSnakeCase(Class> clazz) {
return toSnakeCase(clazz.getSimpleName());
程序代写 CS代考 加微信: powcoder QQ: 1823890830 Email: powcoder@163.com