public static String toString(int flags) {
        if (flags == TMNOFLAGS) {
            return "TMNOFLAGS";
        }

        StringBuilder result = new StringBuilder();
        if (hasFlag(flags, TMENDRSCAN)) {
            add(result, "TMENDRSCAN");
        }
        if (hasFlag(flags, TMFAIL)) {
            add(result, "TMFAIL");
        }
        if (hasFlag(flags, TMJOIN)) {
            add(result, "TMJOIN");
        }
        if (hasFlag(flags, TMONEPHASE)) {
            add(result, "TMONEPHASE");
        }
        if (hasFlag(flags, TMRESUME)) {
            add(result, "TMRESUME");
        }
        if (hasFlag(flags, TMSTARTRSCAN)) {
            add(result, "TMSTARTRSCAN");
        }
        if (hasFlag(flags, TMSUCCESS)) {
            add(result, "TMSUCCESS");
        }
        if (hasFlag(flags, TMSUSPEND)) {
            add(result, "TMSUSPEND");
        }

        int nonStandardFlags = flags
                & ~TMENDRSCAN
                & ~TMFAIL
                & ~TMJOIN
                & ~TMONEPHASE
                & ~TMRESUME
                & ~TMSTARTRSCAN
                & ~TMSUCCESS
                & ~TMSUSPEND;

        if (nonStandardFlags != 0) {
            add(result, String.format("0x%08x", nonStandardFlags));
        }

        return result.toString();
    }
@Test
    public void test() throws Exception {
        assertThat(XASupport.toString(flags), is(expectedResult));
    }