Skip to content

Commit 9359498

Browse files
author
Joerg Huber
committed
Added getNamesForEnum() method.
1 parent 905b5ba commit 9359498

1 file changed

Lines changed: 31 additions & 1 deletion

File tree

  • SIF3InfraREST/sif3Common/src/main/java/au/com/systemic/framework/utils

SIF3InfraREST/sif3Common/src/main/java/au/com/systemic/framework/utils/StringUtils.java

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -517,5 +517,35 @@ public static String exceptionToString(Throwable ex)
517517
ex.printStackTrace(new PrintWriter(sw));
518518

519519
return sw.toString();
520-
}
520+
}
521+
522+
/**
523+
* Pure convenience method for pretty print of enum list. If your enum is defined as<br/>
524+
* enum MyEnum {enum1, enum2, ...}<br/>
525+
* then this method will return:<br/>
526+
* "enum1,enum2,..."<br/>
527+
* The call would be getNamesForEnum(MyEnum.class).
528+
*
529+
* @param The enum class to convert into a pretty string.
530+
*
531+
* @return See desc.
532+
*/
533+
public static String getNamesForEnum(Class<? extends Enum<?>> enumClass)
534+
{
535+
StringBuffer prettyEnum = new StringBuffer();
536+
537+
Enum<?>[] enumArray = enumClass.getEnumConstants();
538+
for (Enum<?> enumValue : enumArray)
539+
{
540+
if (prettyEnum.length() > 0)
541+
{
542+
prettyEnum.append(",");
543+
}
544+
prettyEnum.append(enumValue.name());
545+
}
546+
547+
return prettyEnum.toString();
548+
}
549+
550+
521551
}

0 commit comments

Comments
 (0)