List of usage examples for org.apache.commons.lang StringUtils replaceOnce
public static String replaceOnce(String text, String searchString, String replacement)
Replaces a String with another String inside a larger String, once.
From source file:edu.utah.further.core.data.logging.LoggingPreparedStatement.java
/** * Substitute parameter values within the prepared SQL statement. * * @param parameters// w w w. ja va 2 s . c o m * a map of parameter index to value * @return query string with <code>'?'</code> symbols replaced with parameter values */ private String substituteParameters(final Map<Integer, Object> parameters) { // Find largest parameter index int size = -1; for (final Integer p : parameters.keySet()) { final int pValue = p.intValue(); if (pValue > size) { size = pValue; } } // Replace arguments by values String evaluated = query; for (int i = 1; i <= size; i++) { final Object parameterValue = StringUtil.quote(StringUtil.getNullSafeToString(parameters.get(i))); evaluated = StringUtils.replaceOnce(evaluated, PARAMETER_SYMBOL, StringUtil.getNullSafeToString(parameterValue)); } // Escape quote characters; useful when a JDBCAppender INSERTs the string // "evaluated" to a database if (options.isEscapeQuotes()) { evaluated = evaluated.replaceAll("'", "''"); } return evaluated; }
From source file:com.krawler.esp.servlets.deskeramob.java
public static String insertSmiley(String msg, String serverAdd) { String result = ""; String[] smileyStore = { ":)", ":(", ";)", ":D", ";;)", ">:D<", ":-/", ":x", ":>>", ":P", ":-*", "=((", ":-O", "X(", ":>", "B-)", ":-S", "#:-S", ">:)", ":((", ":))", ":|", "/:)", "=))", "O:-)", ":-B", "=;", ":-c" }; java.util.List smileyListArry = java.util.Arrays.asList(smileyStore); String smileyRegx = "(:\\(\\()|(:\\)\\))|(:\\))|(:x)|(:\\()|(:P)|(:D)|(;\\))|(;;\\))|(>:D<)|(:-\\/)|(:>>)|(:-\\*)|(=\\(\\()|(:-O)|(X\\()|(:>)|(B-\\))|(:-S)|(#:-S)|(>:\\))|(:\\|)|(\\/:\\))|(=\\)\\))|(O:-\\))|(:-B)|(=;)|(:-c)"; java.util.regex.Pattern myPattern = java.util.regex.Pattern.compile(smileyRegx); java.util.regex.Matcher myMatcher = myPattern.matcher(msg); int no = 0;// www. j a va 2s . c om String replaceString = ""; try { while (myMatcher.find()) { no = smileyListArry.indexOf(myMatcher.group()) + 1; replaceString = "<img src=\"" + serverAdd + "/images/smiley" + no + ".gif\" style=display:inline;vertical-align:text-top;></img>"; msg = StringUtils.replaceOnce(msg, myMatcher.group(), replaceString); } } catch (Exception e) { System.out.print(e); } return msg; //return result; }
From source file:gov.nih.nci.cabig.caaers.rules.business.service.CaaersRulesEngineService.java
private CtcTerm findTerm(List<CtcTerm> terms, String categoryName) { if (terms == null || terms.isEmpty()) return null; if (StringUtils.isEmpty(categoryName)) return terms.get(0); if (terms.size() == 1) return terms.get(0); String c = StringUtils.replaceOnce(categoryName, "...", ""); for (CtcTerm term : terms) { if (StringUtils.containsIgnoreCase(term.getCategory().getName(), c)) return term; }//from w w w.j a v a2 s. c o m return null; }
From source file:adalid.commons.util.StrUtils.java
public static String replaceOnceRepeatedly(String text, String searchString, Object... replacements) { if (StringUtils.isBlank(text) || StringUtils.isBlank(searchString) || replacements == null || replacements.length == 0) { return text; }//from w ww.j av a 2 s. c o m String replacement; for (Object obj : replacements) { replacement = StringUtils.trimToEmpty(getString(obj)); text = StringUtils.replaceOnce(text, searchString, replacement); } return text; }
From source file:net.sf.firemox.xml.magic.Oracle2Xml.java
private String writeTarget(PrintWriter out, String action, boolean writeTarget) { String tmpString = action;/*from ww w . j a v a 2s. co m*/ if (tmpString.contains("target")) { while (tmpString.indexOf("target ") != -1) { if (tmpString.contains("target attacking or blocking creature")) { if (writeTarget) { out.println("\t\t\t\t<action ref='target-creature'>"); out.println("\t\t\t\t\t<test>"); out.println("\t\t\t\t\t\t<or>"); out.println("\t\t\t\t\t\t\t<test ref='tested-is-attacking'/>"); out.println("\t\t\t\t\t\t\t<test ref='tested-is-blocking'/>"); out.println("\t\t\t\t\t\t</or>"); out.println("\t\t\t\t\t</test>"); out.println("\t\t\t\t</action>"); } tmpString = StringUtils.replaceOnce(tmpString, "target attacking or blocking creature", ""); } else if (tmpString.contains("target creature or player")) { if (writeTarget) { out.println("\t\t\t\t<action ref='target-dealtable'>"); out.println("\t\t\t\t\t<test>"); out.println("\t\t\t\t\t<!-- COMPLETE THIS TEST ON PLAYER/CREATURE TO TARGET -->"); out.println("\t\t\t\t\t</test>"); out.println("\t\t\t\t</action>"); } tmpString = StringUtils.replaceOnce(tmpString, "target creature or player", ""); } else if (tmpString.contains("target player")) { if (writeTarget) { out.println("\t\t\t\t<action ref='target-player'/>"); } tmpString = StringUtils.replaceOnce(tmpString, "target player", ""); } else if (tmpString.contains("target opponent")) { if (writeTarget) { out.println("\t\t\t\t<action ref='target-opponent'/>"); } tmpString = StringUtils.replaceOnce(tmpString, "target opponent", ""); } else if (tmpString.contains("target spell")) { if (writeTarget) { out.println("\t\t\t\t<action ref='target-spell'/>"); } tmpString = StringUtils.replaceOnce(tmpString, "target spell", ""); } else if (tmpString.contains("target activated ability")) { if (writeTarget) { out.println("\t\t\t\t<action ref='target-activated-ability'/>"); } tmpString = StringUtils.replaceOnce(tmpString, "target activated ability", ""); } else if (tmpString.contains("target triggered ability")) { if (writeTarget) { out.println("\t\t\t\t<action ref='target-triggered-ability'/>"); } tmpString = StringUtils.replaceOnce(tmpString, "target triggered ability", ""); } else if (tmpString.contains("target activated or triggered ability")) { if (writeTarget) { out.println("\t\t\t\t<action ref='target-activated-triggered-ability'/>"); } tmpString = StringUtils.replaceOnce(tmpString, "target activated or triggered ability", ""); } else { boolean found = false; for (int sacrificeI = SACRIFICE.length; sacrificeI-- > 0;) { final String thing = SACRIFICE[sacrificeI]; if (tmpString.contains("target " + thing)) { if (writeTarget) { out.println("\t\t\t\t<action ref='target-" + thing + "'>"); out.println("\t\t\t\t\t<test>"); out.println("\t\t\t\t\t<!-- COMPLETE THIS TEST ON " + thing + " TO TARGET -->"); out.println("\t\t\t\t\t</test>"); out.println("\t\t\t\t</action>"); } tmpString = StringUtils.replaceOnce(tmpString, "target " + thing, ""); found = true; break; } } if (!found) { if (writeTarget) { out.println("\t\t\t\t<action ref='target-permanent'>"); out.println("\t\t\t\t\t<test>"); String property = tmpString.substring(tmpString.indexOf("target ")).split(" ")[1]; out.println("\t\t\t\t\t\t<has-property property='" + property + "'/>"); out.println("\t\t\t\t\t</test>"); out.println("\t\t\t\t</action>"); } tmpString = StringUtils.replaceOnce(tmpString, "target ", ""); } } } } return tmpString; }
From source file:net.sf.firemox.xml.magic.Oracle2Xml.java
private void writeActions(PrintWriter out, String pActions, boolean writeTarget, boolean ignoreCost) { String actions = pActions.replaceAll("--", ""); boolean startWithSpc = actions.startsWith(" "); actions = actions.trim();/*from w w w .j a va 2s . com*/ if (actions.matches("add [x]*[0-9]+[ubgrw]* .*") || actions.matches("add [x]*[0-9]*[ubgrw]+ .*")) { // Give mana actions = writeXmanaGive(out, actions, true); } // return to your hand if (actions.indexOf(lowerCard + " to your hand") != -1) { out.println("\t\t\t\t<target type='this' />"); out.println("\t\t\t\t<action ref='return-to-hand'/>"); actions = StringUtils.replaceOnce(actions, lowerCard + " to your hand", ""); } else if (actions.indexOf("to your hand") != -1) { out.println("\t\t\t\t<action ref='return-to-hand'/>"); actions = StringUtils.replaceOnce(actions, "to your hand", ""); } else if (actions.indexOf(lowerCard + " to its owner's hand") != -1) { out.println("\t\t\t\t<target type='this' />"); out.println("\t\t\t\t<action ref='return-to-hand'/>"); actions = StringUtils.replaceOnce(actions, lowerCard + " to its owner's hand", ""); } else if (actions.indexOf("to its owner's hand") != -1) { out.println("\t\t\t\t<action ref='return-to-hand'/>"); actions = StringUtils.replaceOnce(actions, "to its owner's hand", ""); } if (actions.indexOf("regenerate " + lowerCard) != -1) out.println("\t\t\t\t<action ref='regenerate'/>"); if (actions.indexOf("regenerate target") != -1) out.println("\t\t\t\t<action ref='regenerate-target'/>"); // First perform Target action writeTarget(out, actions, writeTarget); if (actions.indexOf("enchanted creature gets ") != -1) { out.println("\t\t\t\t<target type='attachedto'/>"); actions = StringUtils.replaceOnce(actions, "enchanted creature", ""); } else if (actions.indexOf(lowerCard + " gets") != -1) { out.println("\t\t\t\t<target type='this'/>"); actions = StringUtils.replaceOnce(actions, lowerCard, ""); } else if (actions.indexOf(lowerCard + " gains") != -1) { out.println("\t\t\t\t<target type='this'/>"); actions = StringUtils.replaceOnce(actions, lowerCard, ""); } if (actions.indexOf("put") != -1 && actions.indexOf("puts") == -1 && actions.indexOf("creature token") != -1) { if (actions.lastIndexOf("put") < actions.indexOf("creature token")) { final int endIndex = actions.indexOf("creature token"); String tokenAction = actions.substring(actions.lastIndexOf("put") + 4, endIndex - 1); String[] words = tokenAction.split(" "); if (words.length > 3) { out.print("\t\t\t\t<repeat value='"); if (words[0].compareTo("a") == 0) out.println("1'/>"); else if (words[0].compareTo("two") == 0) out.println("2'/>"); else if (words[0].compareTo("x") == 0) out.println("x'/> <!-- NEEDS CODE FOR X TOKENS -->"); else if (words[0].compareTo("three") == 0) out.println("3'/>"); else if (words[0].compareTo("four") == 0) out.println("4'/>"); else if (words[0].compareTo("five") == 0) out.println("5'/>"); else if (words[0].compareTo("six") == 0) out.println("6'/>"); else if (words[0].compareTo("seven") == 0) out.println("7'/>"); out.println("\t\t\t\t<create-card>"); if (words.length == 6) out.println("\t\t\t\t\t<card name='" + StringUtils.capitalize(words[5]) + "'>"); else out.println("\t\t\t\t\t<card name='" + StringUtils.capitalize(words[3]) + "'>"); out.println("\t\t\t\t\t\t<rules-author-comment></rules-author-comment>"); out.println("\t\t\t\t\t\t<init>"); out.println("\t\t\t\t\t\t\t<registers>"); out.println("\t\t\t\t\t\t\t\t<register index='power' value='" + words[1].charAt(0) + "'/>"); out.println("\t\t\t\t\t\t\t\t<register index='toughness' value='" + words[1].charAt(2) + "'/>"); out.println("\t\t\t\t\t\t\t</registers>"); out.print("\t\t\t\t\t\t\t<colors>" + words[2]); List<String> tokenProperties = new ArrayList<String>(); tokenProperties.add("token"); if (words.length == 6) { out.print(" " + words[4]); tokenProperties.add(words[5]); } else { tokenProperties.add(words[3]); } out.println("</colors>"); out.println("\t\t\t\t\t\t\t<idcards>creature</idcards>"); if (actions.indexOf("with", endIndex) != -1 && actions.indexOf("into", endIndex) > actions.indexOf("with", endIndex)) { updateProperties(actions.substring(actions.indexOf("with", endIndex) + "with".length() + 1, actions.indexOf("into", endIndex)), tokenProperties); } out.print("\t\t\t\t\t\t\t<properties>"); for (String property : tokenProperties) { out.print(property); out.print(' '); } out.println("</properties>"); out.println("\t\t\t\t\t\t</init>"); out.println("\t\t\t\t\t</card>"); out.println("\t\t\t\t</create-card>"); String zone = actions.substring(actions.lastIndexOf("put") + 4); zone = zone.substring(zone.indexOf("into") + "into".length()).trim(); int zoneIndex = zone.indexOf('.'); if (zoneIndex > zone.indexOf(' ') && zone.indexOf(' ') >= 0) { zoneIndex = zone.indexOf(' '); } if (actions.indexOf("target opponent") != -1 && actions.indexOf("target opponent") < actions.indexOf('.')) { out.print("\t\t\t\t<move-card controller='target-list.first' destination='"); } else { out.print("\t\t\t\t<move-card controller='you' destination='"); } if (zoneIndex != -1) { out.print(zone.substring(0, zoneIndex).replaceAll(",", "").trim()); } else { out.print("nowhere"); } out.println("'/>"); } } } if (startWithSpc) { actions = " " + actions; } while (actions.length() > 0) { if (actions.startsWith("add [x]*[0-9]+[ubgrw] ") || actions.startsWith("add [x]*[0-9]*[ubgrw]+ ")) { // Give mana actions = writeXmanaGive(out, actions, true); } else if (actions.startsWith("add one mana of any color")) { out.println("\t\t\t\t<give-mana black='1'/>"); out.println( "\t\t\t\t<!-- DUPLICATE THIS ABILITY WITH THE FOLLOWING ACTIONS OR USE <action ref='tap-add-B'/> REF-ABILITY"); out.println("\t\t\t\t<give-mana blue='1'/>"); out.println("\t\t\t\t<give-mana green='1'/>"); out.println("\t\t\t\t<give-mana red='1'/>"); out.println("\t\t\t\t<give-mana white='1'/>"); out.println("\t\t\t\t -->"); actions = actions.substring("add one mana of any color".length()); } else if (actions.startsWith("add two mana of any ")) { out.println("\t\t\t\t<give-mana black='2'/>"); out.println("\t\t\t\t<!-- DUPLICATE THIS ABILITY WITH THE FOLLOWING ACTIONS"); out.println("\t\t\t\t<give-mana blue='2'/>"); out.println("\t\t\t\t<give-mana green='2'/>"); out.println("\t\t\t\t<give-mana red='2'/>"); out.println("\t\t\t\t<give-mana white='2'/>"); out.println("\t\t\t\t -->"); actions = actions.substring("add two mana of any ".length()); } else if (actions.startsWith("add three mana of any ")) { out.println("\t\t\t\t<give-mana black='3'/>"); out.println("\t\t\t\t<!-- DUPLICATE THIS ABILITY WITH THE FOLLOWING ACTIONS"); out.println("\t\t\t\t<give-mana blue='3'/>"); out.println("\t\t\t\t<give-mana green='3'/>"); out.println("\t\t\t\t<give-mana red='3'/>"); out.println("\t\t\t\t<give-mana white='3'/>"); out.println("\t\t\t\t -->"); actions = actions.substring("add three mana of any ".length()); } else if (actions.startsWith("remove it from the game at end of turn")) { out.println("\t\t\t\t<action ref-'remove-from-game-target-eot'/>"); actions = actions.substring("remove it from the game at end of turn".length()); } else if (actions.startsWith("destroy it at end of turn")) { out.println("\t\t\t\t<action ref='destroy-target-eot'/>"); actions = actions.substring("destroy it at end of turn".length()); } else if (actions.startsWith("can attack this turn as though it didn't have defender")) { out.println("\t\t\t\t<action ref='wall-can-attack-until-eot'/>"); actions = actions.substring("can attack this turn as though it didn't have defender".length()); } else if (actions.startsWith("look at ") && actions.indexOf("hand") != -1) { // Look at target opponent's hand out.println("\t\t\t\t<show-zone zone='hand' for='you'/>"); out.println("\t\t\t\t<!-- INSERT HERE ACTIONS PERFORMED WHILE HAND IS VISIBLE -->"); out.println("\t\t\t\t<action ref='restore-hand-visibility'/>"); actions = actions.substring(actions.indexOf("hand") + "hand".length()); continue; } else if (actions.startsWith("choose a creature type")) { // Choose a creature type out.println( "\t\t\t\t<input-property operation='set' index='free0' register='this' values='FIRST_SUB_TYPE..LAST_SUB_TYPE' />"); actions = actions.substring("choose a creature type".length()); continue; } else if (actions.startsWith("choose a color")) { // Choose a color out.println("\t\t\t\t<input-color operation='set' index='free0' register='this'/>"); actions = actions.substring("choose a color".length()); continue; } else if (actions.startsWith("search ")) { // Search in your library for... List<String> idCard = new ArrayList<String>(); List<String> inIdCard = new ArrayList<String>(); List<String> color = new ArrayList<String>(); List<String> property = new ArrayList<String>(); boolean upTo = actions.indexOf("up to ") != -1; if (actions.indexOf("any number of ") != -1) { out.println("\t\t\t\t<target-list operation='clear' name='%'/>"); out.println("\t\t\t\t<target type='you' name='%'/> "); out.println("\t\t\t\t<show-zone zone='library' for='you' name='%'/>"); out.println( "\t\t\t\t<target mode='choose' type='card' raise-event='false' restriction-zone='library' hop='2' cancel='false' name='search-any'>"); out.println("\t\t\t\t\t<test>"); out.println("\t\t\t\t\t\t<controller player='target-list.first'/>"); out.println("\t\t\t\t\t</test>"); out.println("\t\t\t\t</target>"); out.println("\t\t\t\t<hop value='-1' name='%'/>"); out.println("\t\t\t\t<action ref='restore-library-visibility'/>"); out.println("\t\t\t\t<shuffle zone='library'/>"); out.println("\t\t\t\t<target-list operation='remove-first' name='%'/> "); actions = actions.substring("search ".length()); } boolean isYou = actions.startsWith("search your "); if (actions.indexOf("white") != -1) { color.add("white"); } if (actions.indexOf("black") != -1) { color.add("black"); } if (actions.indexOf("blue") != -1) { color.add("blue"); } if (actions.indexOf("green") != -1) { color.add("green"); } if (actions.indexOf("red") != -1) { color.add("red"); } if (actions.indexOf("artifact") != -1) { idCard.add("artifact"); } else if (actions.indexOf("creature") != -1) { idCard.add("creature"); } if (actions.indexOf("enchantment") != -1) { idCard.add("enchantment"); } if (actions.indexOf("sorcery") != -1) { idCard.add("sorcery"); } if (actions.indexOf("instant") != -1) { idCard.add("instant"); } if (actions.indexOf("island") != -1) { idCard.add("island"); } if (actions.indexOf("swamp") != -1) { idCard.add("swamp"); } if (actions.indexOf("forest") != -1) { idCard.add("forest"); } if (actions.indexOf("mountain") != -1) { idCard.add("mountain"); } if (actions.indexOf("plains") != -1) { idCard.add("plains"); } if (actions.indexOf("mercenary") != -1) { property.add("mercenary"); } if (actions.indexOf("nonbasic land") != -1) { inIdCard.add("nonbasic-land"); } if (actions.indexOf("basic land") != -1) { inIdCard.add("basic-land"); } else if (actions.indexOf("land") != -1) { inIdCard.add("land"); } if (actions.indexOf("legend") != -1) { property.add("legend"); } if (actions.indexOf("zombie") != -1) { property.add("zombie"); } if (actions.indexOf("rebel") != -1) { property.add("rebel"); } if (actions.indexOf("dragon") != -1) { property.add("dragon"); } if (actions.indexOf("goblin") != -1) { property.add("goblin"); } if (actions.indexOf("dwarf") != -1) { property.add("dwarf"); } if (isYou && upTo) { out.println("\t\t\t\t<action ref='search-lib-up-to' value='3'>"); } else if (isYou) { out.println("\t\t\t\t<action ref='search-lib'>"); } else { out.println("\t\t\t\t<action ref='target-player'/>"); if (upTo) { out.println("\t\t\t\t<action ref='search-lib-up-to-player' value='3'>"); } else { out.println("\t\t\t\t<action ref='search-lib-player' value='3'>"); } } out.println("\t\t\t\t\t<test>"); out.println("\t\t\t\t\t\t<and>"); out.println("\t\t\t\t\t\t\t<controller player='target-list.first'/>"); if (idCard.size() + inIdCard.size() > 1) { out.println("\t\t\t\t\t\t\t<or>"); } for (String id : idCard) { out.println("\t\t\t\t\t\t\t\t<has-idcard idcard='" + id + "'/>"); } for (String id : inIdCard) { out.println("\t\t\t\t\t\t\t\t<in-idcard idcard='" + id + "'/>"); } if (idCard.size() + inIdCard.size() > 1) { out.println("\t\t\t\t\t\t\t</or>"); } if (property.size() > 1) { out.println("\t\t\t\t\t\t\t<or>"); } for (String id : property) { out.println("\t\t\t\t\t\t\t<has-property property='" + id + "'/>"); } if (property.size() > 1) { out.println("\t\t\t\t\t\t\t</or>"); } if (color.size() > 1) { out.println("\t\t\t\t\t\t\t<or>"); } for (String id : color) { out.println("\t\t\t\t\t\t\t<has-color color='" + id + "'/>"); } if (color.size() > 1) { out.println("\t\t\t\t\t\t\t</or>"); } out.println("\t\t\t\t\t\t</and>"); out.println("\t\t\t\t\t</test>"); out.println("\t\t\t\t</action>"); out.println("\t\t\t\t\t<!-- INSERT HERE ACTIONS PERFORMED WHEN CARDS HAVE BEEN CHOSEN -->"); actions = actions.substring("search ".length()); } else if (actions.startsWith("sacrifice ")) { // Sacrifice if (!ignoreCost) writeSacrifice(out, actions); actions = actions.substring("sacrifice ".length()); } else if (actions.startsWith("untap ")) { // Tap actions = writeActionOnTarget(out, "untap ", actions); out.println("\t\t\t\t<untap/>"); } else if (actions.startsWith("tap ")) { actions = writeActionOnTarget(out, "tap ", actions); out.println("\t\t\t\t<tap/>"); } else if (actions.startsWith("discards")) { // Discard a card from your hand out.println( "\t\t\t\t<!-- UPDATE THE NUMBER OF CARD PLAYER HAVE TO DISCARD, OR REMOVE REPEAT ACTION IF IS ONE -->"); if (actions.contains("at random")) { out.println("\t\t\t\t<action ref='discard-random' value='1'/>"); } else { out.print("\t\t\t\t<action ref='player-discard' "); if (actions.startsWith("discards two")) out.println("value='2'/>"); else out.println("value='1'/>"); } actions = actions.substring("discards ".length()); } else if (actions.startsWith("discard ")) { // Discard a card from your hand out.println( "\t\t\t\t<!-- UPDATE THE NUMBER OF CARD PLAYER HAVE TO DISCARD, OR REMOVE REPEAT ACTION IF IS ONE -->"); if (actions.contains("at random")) { out.println("\t\t\t\t<action ref='discard-random' value='1'/>"); } else { out.print("\t\t\t\t<action ref='discard' "); if (actions.startsWith("discard two")) out.println("value='2'/>"); else out.println("value='1'/>"); } actions = actions.substring("discard ".length()); } else if (actions.startsWith("draw a card at the beginning of the next turn's upkeep.")) { out.println("\t\t\t\t<action ref='draw-a-card-next-upkeep'/>"); actions = actions.replace("draw a card at the beginning of the next turn's upkeep.", ""); } else if (actions.startsWith(" draws")) { // Draw cards if (!actions.startsWith(" draws a card")) { if (actions.startsWith(" draws two cards")) { out.println("\t\t\t\t<repeat value='2'/>"); } else if (actions.startsWith(" draws three card")) { out.println("\t\t\t\t<repeat value='3'/>"); } else if (actions.startsWith(" draws ") && actions.indexOf("cards") != -1) { out.println("\t\t\t\t<!-- UPDATE THE NUMBER OF CARD PLAYER HAVE TO DRAW -->"); out.println("\t\t\t\t<repeat value='1'/>"); } } out.println("\t\t\t\t<action ref='draw-a-card'/>"); actions = actions.substring(" draws".length()); } else if (actions.startsWith("draw ")) { out.println("\t\t\t\t<target type='you'/>"); if (!actions.startsWith("draw a card")) { if (actions.startsWith("draw two cards")) { out.println("\t\t\t\t<repeat value='2'/>"); } else if (actions.startsWith("draw three card")) { out.println("\t\t\t\t<repeat value='3'/>"); } else if (actions.startsWith("draw ") && actions.indexOf("cards") != -1) { out.println("\t\t\t\t<!-- UPDATE THE NUMBER OF CARD YOU HAVE TO DRAW -->"); out.println("\t\t\t\t<repeat value='1'/>"); } } out.println("\t\t\t\t<action ref='draw-a-card'/>"); actions = actions.substring("draw ".length()); } else if (actions.startsWith("destroy ")) { // Destroy actions = writeActionOnTarget(out, "destroy ", actions); if (actions.contains("can't be regenerated")) out.println("\t\t\t\t<action ref='bury'/>"); else out.println("\t\t\t\t<action ref='destroy'/>"); } else if (actions.startsWith("deals ") && actions.indexOf("damage") != -1) { // Damage String toReplace = actions.substring(0, actions.indexOf("damage") + "damage".length()) + " to "; String type = toReplace.indexOf("combat") != -1 ? "damage-combat" : "damage-normal"; String amount = actions .substring(actions.indexOf("deals ") + "deals ".length(), actions.indexOf("damage")).trim(); actions = writeActionOnTarget(out, toReplace, actions); try { out.println("\t\t\t\t<assign-damage value='" + Integer.parseInt(amount) + "' type='" + type + "'/>"); } catch (NumberFormatException e) { out.println("\t\t\t\t<assign-damage type='" + type + "'>"); out.println("\t\t\t\t\t<value register='this' index='power'/>"); out.println("\t\t\t\t</assign-damage>"); } } else if (actions.startsWith("put ") && actions.matches("put [^ ]+ [^ ]+ counter.*")) { // Add objects int counterIndex = actions.indexOf("counter"); String[] counters = actions.substring(0, counterIndex).split(" "); String objectCount = counters[1].trim(); String objectName = counters[2].trim(); if (actions.matches("put [^ ]+ [^ ]+ counter? on " + lowerCard + ".*")) { out.println("\t\t\t\t<target-list operation='clear'/>"); out.println("\t\t\t\t<target type='this'/>"); } try { final int objectCountInt; if ("a".equals(objectCount)) { objectCountInt = 1; } else if ("two".equals(objectCount)) { objectCountInt = 2; } else if ("tree".equals(objectCount)) { objectCountInt = 3; } else if ("four".equals(objectCount)) { objectCountInt = 4; } else if ("five".equals(objectCount)) { objectCountInt = 5; } else { objectCountInt = Integer.parseInt(objectCount); } if (objectCountInt > 1) { out.print("\t\t\t\t<repeat value='"); out.print(objectCountInt); out.println("/>"); } } catch (NumberFormatException e) { out.println("\t\t\t\t<repeat>"); out.println("\t\t\t\t\t<value register='stack' index='0'/>"); out.println("\t\t\t\t</repeat>"); } out.print("\t\t\t\t<add-object object-name='"); out.print(objectName); out.println("'/>"); actions = actions.substring(counterIndex + "counter".length() + 1); } else if (actions.startsWith("counter ")) { // counter a spell out.println("\t\t\t\t<action ref='counter'/>"); actions = actions.substring("counter ".length()); } else if (actions.startsWith("prevent the next ")) { int amount = 1; try { amount = Integer.valueOf( actions.substring("prevent the next ".length(), "prevent the next ".length() + 1)); } catch (NumberFormatException e) { out.println("\t\t\t\t<!-- UPDATE THE DAMAGE PREVENTION NUMBER -->"); } out.println("\t\t\t\t<!-- UPDATE THE DAMAGE PREVENTION OBJECTS -->"); out.println("\t\t\t\t<action ref='prevent-" + amount + "'/>"); actions = actions.substring("prevent the next ".length() + 1); } else if (actions.startsWith("prevent all")) { // Prevent all damage that would be dealt to ... out.println("\t\t\t\t<action ref='prevent-all'/>"); actions = actions.substring("prevent all".length()); } else if (actions.startsWith("redirect the next ")) { int amount = 1; try { amount = Integer.valueOf( actions.substring("redirect the next ".length(), "redirect the next ".length() + 1)); } catch (NumberFormatException e) { out.println("\t\t\t\t<!-- UPDATE THE DAMAGE REDIRECTION NUMBER -->"); } out.println("\t\t\t\t<!-- UPDATE THE DAMAGE REDIRECTION OBJECTS -->"); out.println("\t\t\t\t<action ref='redirect-" + amount + "'/>"); actions = actions.substring("redirect the next ".length() + 1); } else if (actions.startsWith("redirect all")) { // Redirect all damage that would be dealt to ... out.println("\t\t\t\t<action ref='redirect-all'/>"); actions = actions.substring("redirect all".length()); } else if (actions.startsWith("pay ") && actions.indexOf(" life") != -1) { // Pay 2 life try { int value = Integer.parseInt(actions.substring("pay ".length(), "pay ".length() + 2).trim()); out.println("\t\t\t\t<action ref='pay-life' value='" + value + "'/>"); } catch (NumberFormatException e) { out.println("\t\t\t\t<action ref='pay-life'>"); out.println("\t\t\t\t\t<!-- UPDATE THE X VALUE OF LIFE TO PAY -->"); out.println("\t\t\t\t\t<value register='stack' index='0'/>"); out.println("\t\t\t\t</action>"); } actions = actions.substring(actions.indexOf(" life") + " life".length()); } else if (actions.startsWith(" gain ") && actions.indexOf(" life") != -1) { // You gain 2 life try { int value = Integer .parseInt(actions.substring(" gain ".length(), " gain ".length() + 2).trim()); out.println("\t\t\t\t<action ref='gain-life' value='" + value + "'/>"); } catch (NumberFormatException e) { out.println("\t\t\t\t<action ref='gain-life'>"); out.println("\t\t\t\t\t<!-- UPDATE THE X VALUE OF LIFE TO ADD -->"); out.println("\t\t\t\t\t<value register='stack' index='0'/>"); out.println("\t\t\t\t</action>"); } actions = actions.substring(actions.indexOf(" life") + " life".length()); } else if (actions.startsWith(" lose ") && actions.indexOf(" life") != -1) { // You lose 2 life try { int value = Integer .parseInt(actions.substring(" lose ".length(), " lose ".length() + 2).trim()); out.println("\t\t\t\t<action ref='lose-life' value='" + value + "'/>"); } catch (NumberFormatException e) { out.println("\t\t\t\t<action ref='lose-life'>"); out.println("\t\t\t\t\t<!-- UPDATE THE X VALUE OF LIFE TO LOSE -->"); out.println("\t\t\t\t\t<value register='stack' index='0'/>"); out.println("\t\t\t\t</action>"); } actions = actions.substring(actions.indexOf(" life") + " life".length()); } else if (actions.startsWith(" gains ") && actions.indexOf(" life") != -1) { // Player gains 2 life try { int value = Integer .parseInt(actions.substring(" gains ".length(), " gains ".length() + 2).trim()); out.println("\t\t\t\t<action ref='gain-life-target' value='" + value + "'/>"); } catch (NumberFormatException e) { out.println("\t\t\t\t<action ref='gain-life-target'>"); out.println("\t\t\t\t\t<!-- UPDATE THE X VALUE OF LIFE TO ADD -->"); out.println("\t\t\t\t\t<value register='stack' index='0'/>"); out.println("\t\t\t\t</action>"); } actions = actions.substring(actions.indexOf(" life") + " life".length()); } else if (actions.startsWith(" loses ") && actions.indexOf(" life") != -1) { // Player loses 2 life try { int value = Integer .parseInt(actions.substring(" loses ".length(), " loses ".length() + 2).trim()); out.println("\t\t\t\t<action ref='lose-life-target' value='" + value + "'/>"); } catch (NumberFormatException e) { out.println("\t\t\t\t<action ref='lose-life-target'>"); out.println("\t\t\t\t\t<!-- UPDATE THE X VALUE OF LIFE TO LOSE -->"); out.println("\t\t\t\t\t<value register='stack' index='0'/>"); out.println("\t\t\t\t</action>"); } actions = actions.substring(actions.indexOf(" life") + " life".length()); } else if (actions.startsWith(" gets ") || actions.startsWith(" gains ")) { // Gets ... if (actions.indexOf(" poison counter") != -1) { // poison counter out.println("\t\t\t\t<!-- UPDATE THE NB OF POISON TO ADD -->"); out.println( "\t\t\t\t<modify-register register='opponent' index='poison' operation='add' value=''/>"); actions = actions .substring(actions.indexOf(" poison counter") + " poison counter".length() + 1); } else { // Gets String power = null; boolean endOfTurn = actions.indexOf(" until end of turn") != -1; out.println("\t\t\t\t<add-modifier>"); if (actions.indexOf("/") == -1) { out.println("\t\t\t\t\t<!-- UPDATE THE MODIFIER TYPE AND THE LINKED ATTRIBUTE -->"); String property = ""; if (actions.indexOf("gains") != -1) property = actions.substring(actions.indexOf("gains")).split(" ")[1]; else property = "flying"; out.println("\t\t\t\t\t<property-modifier property='" + property + "' linked='false'>"); if (endOfTurn) { out.println("\t\t\t\t\t\t<until>"); out.println("\t\t\t\t\t\t\t<end-of-phase phase='cleanup'/>"); out.println("\t\t\t\t\t\t</until>"); } out.println("\t\t\t\t\t</property-modifier>"); } else { if (actions.startsWith(" gets ")) { power = actions.substring(" gets ".length(), actions.indexOf("/")).trim(); } else { power = actions.substring(" gains ".length(), actions.indexOf("/")).trim(); } String tmpStr = actions.substring(actions.indexOf("/") + 1); int dot = tmpStr.indexOf("."); int space = tmpStr.indexOf(" "); String toughness = tmpStr .substring(0, (space < dot || dot == -1) && space != -1 ? space : dot) .replaceAll(",", "").trim(); if (!power.startsWith("+0")) { out.println("\t\t\t\t\t<!-- CHECK THE LINKED ATTRIBUTE -->"); if (power.indexOf("x") != -1) { out.println("\t\t\t\t\t<register-modifier index='power' operation='" + (power.startsWith("-") ? "minus" : "add") + "' linked='false'>"); if (endOfTurn) { out.println("\t\t\t\t\t\t<until>"); out.println("\t\t\t\t\t\t\t<end-of-phase phase='cleanup'/>"); out.println("\t\t\t\t\t\t</until>"); } out.println("\t\t\t\t\t\t<!-- UPDATE THE POWER X VALUE -->"); out.println("\t\t\t\t\t\t<value register='stack' index='0'/>"); } else { out.println("\t\t\t\t\t<register-modifier index='power' value='" + power.substring(1) + "' operation='" + (power.startsWith("-") ? "minus" : "add") + "' linked='false'>"); if (endOfTurn) { out.println("\t\t\t\t\t\t<until>"); out.println("\t\t\t\t\t\t\t<end-of-phase phase='cleanup'/>"); out.println("\t\t\t\t\t\t</until>"); } } out.println("\t\t\t\t\t</register-modifier>"); } if (!toughness.startsWith("+0")) { out.println("\t\t\t\t\t<!-- CHECK THE LINKED ATTRIBUTE -->"); if (toughness.indexOf("x") != -1) { out.println("\t\t\t\t\t<register-modifier index='toughness' operation='" + (power.startsWith("-") ? "minus" : "add") + "' linked='false'>"); if (endOfTurn) { out.println("\t\t\t\t\t\t<until>"); out.println("\t\t\t\t\t\t\t<end-of-phase phase='cleanup'/>"); out.println("\t\t\t\t\t\t</until>"); } out.println("\t\t\t\t\t\t<!-- UPDATE THE TOUGHNESS X VALUE -->"); out.println("\t\t\t\t\t\t<value register='stack' index='0'/>"); } else { out.println("\t\t\t\t\t<register-modifier index='toughness' value='" + toughness.substring(1) + "' operation='" + (toughness.startsWith("-") ? "minus" : "add") + "' linked='false'>"); if (endOfTurn) { out.println("\t\t\t\t\t\t<until>"); out.println("\t\t\t\t\t\t\t<end-of-phase phase='cleanup'/>"); out.println("\t\t\t\t\t\t</until>"); } } out.println("\t\t\t\t\t</register-modifier>"); } } out.println("\t\t\t\t</add-modifier>"); if (isAura) { out.println("\t\t\t\t<target type='this'/>"); out.println("\t\t\t\t<attachlist>"); out.println("\t\t\t\t\t\t<!-- UPDATE ATTACHMENT CONDITION -->"); out.println("\t\t\t\t<valid-attachment ref='valid-enchant-creature'/>"); out.println("\t\t\t\t</attachlist>"); } actions = actions.substring(" gets ".length()); } } else if (actions.matches("^remove .{1,5} cards? in your graveyard from the game")) { if (actions.startsWith("remove two")) out.println("\t\t\t\t<repeat value='2'/>"); else if (actions.startsWith("remove three")) out.println("\t\t\t\t<repeat value='3'/>"); else if (actions.startsWith("remove four")) out.println("\t\t\t\t<repeat value='4'/>"); out.println("\t\t\t\t<action ref='remove-a-card-from-graveyard'/>"); } if (actions.length() > 0) { actions = actions.substring(1); } } // TODO Enchanted creature has first strike and trample. // At the end of its controller's turn, // TODO Choose one -- You gain 5 life; or prevent the next 5 damage that // would be dealt to target creature this turn. // TODO Entwine {2} (Choose both if you pay the entwine cost.) }
From source file:net.sf.firemox.xml.magic.Oracle2Xml.java
/** * @param line/* w w w .j a va 2 s. c o m*/ * @param properties */ private String updateProperties(String pLine, List<String> properties) { String[] propertiesSTR = pLine.split(", "); // first : validation for (int i = propertiesSTR.length; i-- > 0;) { propertiesSTR[i] = propertiesSTR[i].trim(); if (propertiesSTR[i].length() > 30 || propertiesSTR[i].indexOf(" ") != -1 && propertiesSTR[i].indexOf("strike") == -1 && !propertiesSTR[i].startsWith("protection from")) { return pLine; } } // then : update list String line = pLine; for (String property : propertiesSTR) { if (property.indexOf("cycling") == -1 && property.indexOf("buyback") == -1 && property.indexOf("flashback") == -1 && property.indexOf("echo") == -1 && property.indexOf("deathtouch") == -1 && property.indexOf("lifelink") == -1) { properties.add(property.trim().replaceAll(" ", "-")); line = MToolKit.replaceAll(StringUtils.replaceOnce(line, property + ",", ""), property, "").trim(); } } return line; }
From source file:net.sourceforge.subsonic.util.Util.java
public static String square(String imageUrl) { return StringUtils.replaceOnce(imageUrl, "/126/", "/126s/"); }
From source file:ninja.text.TextImpl.java
@Override public Text replaceOnce(CharSequence text, CharSequence candidate) { return Text.of(StringUtils.replaceOnce(data.toString(), text.toString(), candidate.toString())); }
From source file:ninja.text.TextImpl.java
@Override public Text replaceOnce(Text text, Text candidate) { return Text.of(StringUtils.replaceOnce(data.toString(), text.toString(), candidate.toString())); }