List of usage examples for org.apache.commons.lang StringUtils startsWithIgnoreCase
public static boolean startsWithIgnoreCase(String str, String prefix)
Case insensitive check if a String starts with a specified prefix.
From source file:org.zoolu.tools.Parser.java
/** * Whether next chars equal to any string of array <i>ss</i> ignoring case. * * @param ss//from w w w .j av a2 s .c o m * @return */ public boolean startsWithIgnoreCase(String[] ss) { for (String s : ss) { final boolean equal; equal = StringUtils.startsWithIgnoreCase(str, s); if (equal) { return true; } } return false; }
From source file:raptor.alias.ActivateScriptAlias.java
@Override public RaptorAliasResult apply(final ChatConsoleController controller, String command) { if (StringUtils.startsWithIgnoreCase(command, "+script")) { RaptorStringTokenizer tok = new RaptorStringTokenizer(command, " ", true); tok.nextToken();/*from w w w . j a v a 2 s. c o m*/ String scriptName = tok.getWhatsLeft(); ChatEventScript script = ScriptService.getInstance().getChatEventScript(scriptName); if (script == null) { return new RaptorAliasResult("", "Script '" + scriptName + "' not found. Type \"=scripts\" to get a list of all available scripts."); } else { if (!script.isActive()) { script.setActive(true); ScriptService.getInstance().save(script); return new RaptorAliasResult("", "Script '" + scriptName + "' is now active."); } else { return new RaptorAliasResult("", "Script '" + scriptName + "' is all ready active."); } } } return null; }
From source file:raptor.alias.AddExtendedCensorAlias.java
@Override public RaptorAliasResult apply(ChatConsoleController controller, String command) { if (StringUtils.startsWithIgnoreCase(command, "+extcensor")) { if (command.length() < 13) { return new RaptorAliasResult(null, "Invalid command: " + command + "\n" + getUsage()); }/*w w w . j a va 2s . c om*/ String whatsLeft = command.substring(10).trim(); if (whatsLeft.length() < 3) { return new RaptorAliasResult(null, "Invalid username: " + whatsLeft + "\n" + getUsage()); } else if (!controller.getConnector().isOnExtendedCensor(whatsLeft)) { controller.getConnector().addExtendedCensor(whatsLeft); return new RaptorAliasResult(null, "Added " + whatsLeft + " to extended censor."); } else { return new RaptorAliasResult(null, whatsLeft + " is already on your extended censor list."); } } else { return null; } }
From source file:raptor.alias.AddTabAlias.java
@Override public RaptorAliasResult apply(ChatConsoleController controller, String command) { if (StringUtils.startsWithIgnoreCase(command, "+tab")) { String whatsLeft = command.substring(5).trim(); if (whatsLeft.contains(" ")) { return new RaptorAliasResult(null, "Invalid command: " + command + "\n" + getUsage()); } else if (whatsLeft.equalsIgnoreCase("games") || whatsLeft.equalsIgnoreCase("game")) { SWTUtils.openGamesWindowItem(controller.getConnector()); return new RaptorAliasResult(null, "Added games tab."); } else if (whatsLeft.equalsIgnoreCase("bugwho") || whatsLeft.equalsIgnoreCase("bug")) { SWTUtils.openBugWhoWindowItem(controller.getConnector()); return new RaptorAliasResult(null, "Added bugwho tab."); } else if (whatsLeft.equalsIgnoreCase("bugbuttons") || whatsLeft.equalsIgnoreCase("buttons")) { SWTUtils.openBugButtonsWindowItem(controller.getConnector()); return new RaptorAliasResult(null, "Added bugbuttons tab."); } else if (whatsLeft.equalsIgnoreCase("seeks") || whatsLeft.equalsIgnoreCase("seek")) { SWTUtils.openSeekTableWindowItem(controller.getConnector()); return new RaptorAliasResult(null, "Added seeks tab."); } else if (NumberUtils.isDigits(whatsLeft)) { ChatUtils.openChannelTab(controller.getConnector(), whatsLeft, false); return new RaptorAliasResult(null, "Added channel tab: " + whatsLeft + "."); } else {/*from w w w . j a v a2s . c om*/ ChatUtils.openPersonTab(controller.getConnector(), whatsLeft, false); return new RaptorAliasResult(null, "Added person tab: " + whatsLeft + "."); } } else { return null; } }
From source file:raptor.alias.AddTagAlias.java
@Override public RaptorAliasResult apply(ChatConsoleController controller, String command) { if (StringUtils.startsWithIgnoreCase(command, "+tag")) { RaptorStringTokenizer tok = new RaptorStringTokenizer(command, " ", true); tok.nextToken();//from w w w.j av a2 s . c om String user = tok.nextToken(); String tag = tok.nextToken(); if (tag == null || user == null) { return new RaptorAliasResult(null, "Invalid command: " + command + "\n" + getUsage()); } else { UserTagService.getInstance().addUser(tag, user); return new RaptorAliasResult(null, user + " is now tagged as " + tag); } } else { return null; } }
From source file:raptor.alias.AliasHelpAlias.java
@Override public RaptorAliasResult apply(ChatConsoleController controller, String command) { if (StringUtils.startsWithIgnoreCase(command, "aliashelp")) { RaptorStringTokenizer tok = new RaptorStringTokenizer(command, " ", true); tok.nextToken();//from ww w .j a v a2 s. c o m String aliasName = null; if (tok.hasMoreTokens()) { aliasName = tok.getWhatsLeft(); } if (StringUtils.isBlank(aliasName)) { StringBuilder aliasHelp = new StringBuilder(2000); aliasHelp.append("Raptor aliases (Type \"aliashelp aliasName\" for a description and usage.):\n"); RaptorAlias[] aliases = AliasService.getInstance().getAliases(); int count = 0; for (RaptorAlias alias : aliases) { if (!alias.isHidden) { aliasHelp.append(StringUtils.rightPad(alias.getName(), 20)); count++; if (count == 3) { aliasHelp.append("\n"); count = 0; } } } return new RaptorAliasResult(null, aliasHelp.toString()); } else { RaptorAlias alias = AliasService.getInstance().getAlias(aliasName); if (alias == null) { return new RaptorAliasResult(null, "Alias '" + aliasName + " 'not found."); } else { StringBuilder aliasHelp = new StringBuilder(2000); aliasHelp.append("Alias '").append(aliasName).append("':\n"); aliasHelp.append(" Description: ").append(alias.getDescription()).append("\n"); aliasHelp.append("\n"); aliasHelp.append(" Usage: ").append(alias.getUsage()).append("\n"); return new RaptorAliasResult(null, aliasHelp.toString()); } } } else { return null; } }
From source file:raptor.alias.DeactivateScriptAlias.java
@Override public RaptorAliasResult apply(final ChatConsoleController controller, String command) { if (StringUtils.startsWithIgnoreCase(command, "-script")) { RaptorStringTokenizer tok = new RaptorStringTokenizer(command, " ", true); tok.nextToken();//from w ww .j av a 2 s.c o m String scriptName = tok.getWhatsLeft(); ChatEventScript script = ScriptService.getInstance().getChatEventScript(scriptName); if (script == null) { return new RaptorAliasResult("", "Script '" + scriptName + "' not found. Type \"=scripts\" to get a list of all available scripts."); } else { if (!script.isActive()) { return new RaptorAliasResult("", "Script '" + scriptName + "' is all ready deactivated."); } else { script.setActive(false); ScriptService.getInstance().save(script); return new RaptorAliasResult("", "Script '" + scriptName + "' is no longer active."); } } } return null; }
From source file:raptor.alias.DumpGamesAlias.java
@Override public RaptorAliasResult apply(ChatConsoleController controller, String command) { if (StringUtils.startsWithIgnoreCase(command, "dumpgames")) { StringBuilder output = new StringBuilder(8000); output.append("dumpgames output:\n"); Game[] games = controller.getConnector().getGameService().getAllActiveGames(); for (Game game : games) { output.append("Game ").append(game.getId()).append(":\n").append(game.toString()); }/* ww w.java2s .com*/ return new RaptorAliasResult(null, output.toString()); } return null; }
From source file:raptor.alias.ListScriptsAlias.java
@Override public RaptorAliasResult apply(final ChatConsoleController controller, String command) { if (StringUtils.startsWithIgnoreCase(command, "=script")) { ChatEventScript[] scripts = ScriptService.getInstance().getChatEventScripts(); StringBuilder text = new StringBuilder(2000); List<ChatEventScript> activeScripts = new ArrayList<ChatEventScript>(10); List<ChatEventScript> inactiveScripts = new ArrayList<ChatEventScript>(10); for (ChatEventScript script : scripts) { if (script.isActive()) { activeScripts.add(script); } else { inactiveScripts.add(script); }//from ww w .j a v a 2 s. com } Collections.sort(activeScripts); Collections.sort(inactiveScripts); text.append("Active Scripts:\n"); for (ChatEventScript script : activeScripts) { text.append(" ").append(script.getName()).append("\n"); } text.append("\n\n"); text.append("Inactive Scripts:\n"); for (ChatEventScript script : inactiveScripts) { text.append(" ").append(script.getName()).append("\n"); } return new RaptorAliasResult("", text.toString()); } return null; }
From source file:raptor.alias.OpenBoardAlias.java
@Override public RaptorAliasResult apply(ChatConsoleController controller, String command) { if (StringUtils.startsWithIgnoreCase(command, "openboard")) { String whatsLeft = command.substring(9).trim(); String variant = Variant.classic.toString(); String fen = null;/*from w w w .j a v a 2 s .co m*/ if (!StringUtils.isBlank(whatsLeft)) { RaptorStringTokenizer tok = new RaptorStringTokenizer(whatsLeft, " ", true); variant = tok.nextToken(); try { if (Variant.valueOf(variant) == null) { fen = whatsLeft; variant = Variant.classic.toString(); } if (tok.hasMoreTokens()) { fen = tok.getWhatsLeft(); } } catch (Throwable t) { fen = whatsLeft; variant = Variant.classic.toString(); } } try { Game game = null; if (fen == null) { game = GameFactory.createStartingPosition(Variant.valueOf(variant)); } else { game = GameFactory.createFromFen(fen, Variant.valueOf(variant)); } game.addState(Game.UNTIMED_STATE); game.addState(Game.UPDATING_ECO_HEADERS_STATE); game.addState(Game.UPDATING_SAN_STATE); ChessBoardUtils .openBoard(new InactiveController(game, "openboard " + variant + " Position", false)); return new RaptorAliasResult(null, "Position created."); } catch (Throwable t) { LOG.info("Error parsing openboard:", t); return new RaptorAliasResult(null, "Invalid command: " + getUsage()); } } return null; }