import java.util.Random; /* An instance of this class represents a composite regular expression ** whose main operator is Kleene/star closure. */ public class RegExprStar extends RegularExpression { // instance variable // ----------------- private RegularExpression r; // constructor // ----------- /* Establishes this regular expression as being the one obtained by ** applying the Kleene/star operator to the given regular expression. */ public RegExprStar(RegularExpression regExpr) { r = regExpr; } // observer // -------- /* Reports whether or not the given string is a member of the language ** represented by this regular expression. ** A string x is in the language of regular expression r* iff x is the ** empty string or there exist strings y and z, with y being non-empty, ** such that x = yz, y is a member of L(r), and z is a member of L(r*). */ @Override public boolean isMember(String x) { return false; // STUB } @Override public boolean isFinite() { return true; // STUB } @Override public boolean isEmpty() { return false; // STUB } @Override public int minLength() { return 5; // STUB } @Override public int maxLength() { return 3; // STUB } @Override public String randomMember(Random rand) { final int MAX_REPETITIONS = 6; if (r.isEmpty()) { return ""; } else { StringBuilder result = new StringBuilder(""); int k = rand.nextInt(MAX_REPETITIONS + 1); for (int i=0; i != k; i++) { result.append(r.randomMember(rand)); } return result.toString(); } } @Override public String toString() { String rImage = r.toString(); if (rImage.length() > 1) { rImage = '(' + rImage + ')'; } return rImage + RegExprSymbols.STAR_OP; } @Override public RegularExpression reverse() { return null; // STUB } }