/* * JFLAP - Formal Languages and Automata Package * * * Susan H. Rodger * Computer Science Department * Duke University * August 27, 2009 * Copyright (c) 2002-2009 * All rights reserved. * JFLAP is open source software. Please see the LICENSE for terms. * */ package pumping; /** * A Case is an object that lets the user or program * know if certain cases had been done, depending on the conditions * of the case, specified in {@link #isCase(String, String)}. * * It is the programmer's responsibility to write individual cases * for each class of {@link pumping.PumpingLemma}. * * @author Jinghui Lim * */ public abstract class Case { /** * The i of this case. */ protected int i; /** * Previously entered user input. It is null if the * user has not entered any input. */ protected int[] userInput; /** * Constructs a new case with no user input. * */ public Case() { reset(); } /** * Determines if a certain decomposition is an example of this case. * For a {@link RegularPumpingLemma}, both v and y * should hold the y segment of the decomposition. For a * {@link ContextFreePumpingLemma}, v and y * should hold their respective segments of the decomposition. * * @param v the v segment of string w * @param y the y segment of string w * @return true if this decomposition is an example * of this case, false otherwise */ public abstract boolean isCase(String v, String y); /** * Given a w value, returns in an int[] the dividers separating * u, v, x, y, & z * Used by the computer when it goes first. * public int[] chooseDecompositionOfCase(String s) { int size = s.length(); for (int w=0; wtrue if they * are the the same, and false otherwise. Thus, * Cases should not be compared between two different * pumping lemmas. * * @return true if the two cases are equivalent, * false otherwise */ public boolean equals(Object o) { try { return toString().equals(((Case)o).toString()); } catch(ClassCastException e) { return false; } } /** * Get a preset decomposition of this case. In most subclasses of * {@link pumping.Case}, this method should have access to m * of the {@link pumping.PumpingLemma} either as an internal * class or through {@link PumpingLemma#getM()}. * * @return a preset decomposition of this case */ public abstract int[] getPreset(); /** * Returns a decomposition that suits this case, a previously set * user decomposition (set by {@link #setUserInput(int[])}) or if * that has not been done, the preset decomposition we would get * if we called {@link #getPreset()}. * * @return a previously set user decomposition or a preset decomposition */ public int[] getInput() { if(userInput == null) return getPreset(); else return userInput; } /** * Sets the user's decomposition. This will subsequently be retrieved * when {@link #getInput()} is called. * * @param n the user's decomposition of w */ public void setUserInput(int[] n) { userInput = n; } /** * Sets the i of this case. * * @param num the number to set i to */ public void setI(int num) { i = num; } /** * Returns the i of this case. * * @return the i of this case */ public int getI() { return i; } /** * Resets the case, clearing user input and i. * */ public void reset() { userInput = null; i = -1; } }