Java tutorial
//package com.java2s; import java.io.File; import java.util.ArrayList; import java.util.List; public class Main { /** * Retorna el nombre del grupo y la constante de la pagina * a partir del path de la pagina (preferentemente el absoluto) * ej "UseCaseGroup.MI_PAGINA" */ public static String getGroupPageConstant(String path) { File original = new File(path); String pageName = original.getName(); pageName = pageName.substring(0, pageName.indexOf(".")); return getGroupData(path) + "." + toConstantFormat(pageName); } /** * Retorna el nombre del grupo de un caso de uso, a partir * del path de la pagina (preferentemente absoluto). * Ej: "UseCaseGroup" */ public static String getGroupData(String path) { File original = new File(path); String useCaseName = original.getParentFile().getParentFile().getName(); return capitalize(useCaseName) + "Group"; } public static String toConstantFormat(String str) { int n = str.length(); List<Character> list = new ArrayList<Character>(); char c; for (int i = 0; i < n; i++) { c = str.charAt(i); if (i != 0 && Character.isUpperCase(c)) { list.add('_'); } list.add(Character.toUpperCase(c)); } StringBuffer buffer = new StringBuffer(); for (Character character : list) { buffer.append(character); } return buffer.toString(); } public static String capitalize(String str) { return (str == null || str.length() == 0) ? "" : Character.toUpperCase(str.charAt(0)) + str.substring(1); } public static String toUpperCase(String str) { return str.toUpperCase(); } }