Permalink
Browse files

Add some convenience methods for the enums

  • Loading branch information...
1 parent c4f20ea commit 5effbd3e9baaf2d52c4ce31713e77818570d5732 @dmlloyd dmlloyd committed Jun 6, 2012
Showing with 60 additions and 0 deletions.
  1. +60 −0 src/main/java/org/jboss/msc/service/ServiceController.java
@@ -219,6 +219,21 @@
*/
REMOVED,
;
+
+ /**
+ * Determine if this state is one of the given states.
+ *
+ * @param states the states to check
+ * @return {@code true} if this state is in the set; {@code false} otherwise
+ */
+ public boolean in(State... states) {
+ for (State test : states) {
+ if (this == test) {
+ return true;
+ }
+ }
+ return false;
+ }
}
/**
@@ -252,6 +267,21 @@
*/
ACTIVE,
;
+
+ /**
+ * Determine if this mode is one of the given modes.
+ *
+ * @param modes the modes to check
+ * @return {@code true} if this mode is in the set; {@code false} otherwise
+ */
+ public boolean in(Mode... modes) {
+ for (Mode test : modes) {
+ if (this == test) {
+ return true;
+ }
+ }
+ return false;
+ }
}
/**
@@ -353,6 +383,21 @@ public boolean isRestState() {
public State getState() {
return state;
}
+
+ /**
+ * Determine if this substate is one of the given substates.
+ *
+ * @param substates the substates to check
+ * @return {@code true} if this substate is in the set; {@code false} otherwise
+ */
+ public boolean in(Substate... substates) {
+ for (Substate test : substates) {
+ if (this == test) {
+ return true;
+ }
+ }
+ return false;
+ }
}
/**
@@ -560,6 +605,21 @@ public Substate getAfter() {
}
/**
+ * Determine if this transition is one of the given transitions.
+ *
+ * @param transitions the transitions to check
+ * @return {@code true} if this transition is in the set; {@code false} otherwise
+ */
+ public boolean in(Transition... transitions) {
+ for (Transition test : transitions) {
+ if (this == test) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /**
* Get the string representation of this transition.
*
* @return the string

0 comments on commit 5effbd3

Please sign in to comment.