Java code snippet: Enumeration to return String value

I probably should be adding this kind of stuff on GitHub, but I’m lazy. 🙂

public enum TokenType {


    private String tokenType;

    TokenType(String tokenType) {
        this.tokenType = tokenType;

    public String getTokenType() {
        return tokenType;

    public boolean isTicket() {
        return this == TICKET;

    public boolean isValidType() {
        return this == TICKET;

    public static TokenType getByTokenType(String tokenType) {
        String safeTokenType = (tokenType != null) ? tokenType.toLowerCase().trim() : "";

        for (TokenType tt : values()) {
            if (tt.getTokenType().equals(safeTokenType)) {
                return tt;

        return UNKNOWN;

    public boolean isUnknown() {
        return this == UNKNOWN;

Maven error with Java 6 on OS X: “Unsupported major.minor version 51.0”

If you encounter the error below with Java 6 on OS X, make sure you’re using Maven 3.2.5 or older.

$ mvn
Exception in thread "main" java.lang.UnsupportedClassVersionError: org/apache/maven/cli/MavenCli : Unsupported major.minor version 51.0
  at java.lang.ClassLoader.defineClass1(Native Method)
  at java.lang.ClassLoader.defineClassCond(
  at java.lang.ClassLoader.defineClass(
  at Method)
  at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClassFromSelf(
  at org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy.loadClass(
  at org.codehaus.plexus.classworlds.realm.ClassRealm.unsynchronizedLoadClass(
  at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(
  at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(
  at org.codehaus.plexus.classworlds.launcher.Launcher.getMainClass(
  at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(
  at org.codehaus.plexus.classworlds.launcher.Launcher.launch(
  at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(
  at org.codehaus.plexus.classworlds.launcher.Launcher.main(

Seven performance metrics for Java applications

I came across this in this blog post and am adding it here as a checklist. It’s a worthwhile list to have so you can understand how your Java app behaves in production.

  1. Response times and throughput
  2. Load Average
  3. Error Rates (and how to solve them)
  4. GC rate and pause duration
  5. Business Metrics
  6. Uptime and service health
  7. Log size