For ease of maintenance, you should formalize string comparators when possible, either as named constants or as an enumeration. The benefit to the programmer is that you can localize the changes. Even with the refactoring tool, finding all the places where the string is used can be tedious and error prone. You can have only one place where you do this comparison today, but you or the future maintainer can extend this to other parts of the code. In addition, the class itself can grow and must be broken down. These things tend to creep along the program over time.
I would simply declare these lines as constants close to where they are used, but together. Do not worry about a new abstraction, like Roles, until you know that you need it. If the number of roles you need to compare is growing or is required outside this class, then you can create a class of roles or roles depending on the complexity of the comparison.
In addition, using constants, you signal the intended use of the compiler, so you get some minor memory management benefits, which, given that your comparison is in a loop, are usually good practice.
pfries
source share