/** * Gets the first running command that matches the given regular expression. * * @param commandSearch the regular expression to match. * @return the found command or null. */ public synchronized CommandMock getRunningCommand(String commandSearch) { if (commandHistory != null) { Pattern p = Pattern.compile(commandSearch); for (CommandMock command : commandHistory) { if (!command.isDestroyed() && p.matcher(command.getCommand()).find()) { return command; } } } return null; }
/** * Gets the number of commands that match the given regular expression from the command history. * * @param commandSearch the regular expression to match. * @return number of found commands. */ public synchronized int getNrCommandsHistory(String commandSearch) { int matches = 0; if (commandHistory != null) { Pattern p = Pattern.compile(commandSearch, Pattern.MULTILINE); for (CommandMock command : commandHistory) { Matcher matcher = p.matcher(command.getCommand()); if (matcher.find()) { matches++; } } } return matches; }