import java.util.Random; /* An instance of this class models a composite regular expression ** whose main operator is union (i.e. of the form alpha + beta). */ public class RegExprUnion extends RegularExpression { // instance variables // ------------------ private RegularExpression alpha, beta; // This regular expression is // alpha + beta // constructor // ----------- /* Establishes this regular expression as being the one obtained by ** applying the union operator to the given regular expressions. */ public RegExprUnion(RegularExpression first, RegularExpression second) { // Stub } // observer // -------- /* Reports whether or not the given string is a member of the language ** represented by this regular expression. ** A string x is a member of L(alpha + beta) iff either x is a member of ** L(alpha) or x is a member of L(beta). */ @Override public boolean isMember(String x) { return true; // Stub } @Override public boolean isFinite() { return true; // Stub } @Override public boolean isEmpty() { return true; // Stub } @Override public int minLength() { return 0; // Stub } @Override public int maxLength() { return 0; // Stub } @Override public String randomMember(Random rand) { if (rand.nextBoolean()) { return alpha.randomMember(rand); } else { return beta.randomMember(rand); } } @Override public String toString() { return '(' + alpha.toString() + ' ' + RegExprSymbols.UNION_OP + ' ' + beta.toString() + ')'; } @Override public RegularExpression reverse() { return null; // STUB } }