class CommunityVar extends SymbolicRegex implements Comparable<CommunityVar> {

  @Override
  public Automaton toAutomaton() {
    String regex = _regex;
    if (_type == EXACT) {
      // to turn a literal into a regex, add the start-of-string and end-of-string characters
      regex = "^" + "(" + regex + ")" + "$";
    } else {
      /**
       * A regex need only match a portion of a given community string. For example, the regex
       * "^40:" matches the community 40:11. But to properly relate community regexes to one
       * another, for example to find their intersection, we need regexes that match completely.
       *
       * <p>The simple approach below converts a possibly-partial regex into a complete one. It
       * works because below we intersect the resulting automaton with COMMUNITY_FSM, which notably
       * includes the start-of-string and end-of-string characters. Note that the automaton library
       * treats these as ordinary characters.
       *
       * <p>For example, the regex "^40:" becomes ".*(^40:).*", and the final automaton after
       * intersecting with COMMUNITY_FSM accepts the language of the regex "^40:[0-9]+$" as desired.
       */
      regex = ".*" + "(" + regex + ")" + ".*";
    }
    return new RegExp(regex).toAutomaton().intersection(COMMUNITY_FSM);
  }

  private  CommunityVar(Type type, String regex, @Nullable Community literalValue);

}