List of usage examples for java.lang Character isWhitespace
public static boolean isWhitespace(int codePoint)
From source file:edu.cornell.mannlib.vedit.util.Stemmer.java
public static String StemString(String inputStr, int maxLength) { String outputStr = ""; int previousCh = 0; char[] w = new char[maxLength]; char[] inputArray = inputStr.toCharArray(); Stemmer s = new Stemmer(); int inputArrayIndex = 0, stemmerInputBufferIndex = 0, ch = 0; for (inputArrayIndex = 0; inputArrayIndex < inputArray.length; inputArrayIndex++) { ch = inputArray[inputArrayIndex]; if (Character.isLetter((char) ch)) { stemmerInputBufferIndex = 0; // start collecting letters for a new word while (inputArrayIndex < inputArray.length) { // keep reading until hit character other than a letter ch = Character.toLowerCase((char) ch); w[stemmerInputBufferIndex] = (char) ch; if (stemmerInputBufferIndex < maxLength - 1) { stemmerInputBufferIndex++; }/*from w w w . ja v a 2s . co m*/ if (inputArrayIndex < inputArray.length - 1) { previousCh = ch; ch = inputArray[++inputArrayIndex]; if (!Character.isLetter((char) ch)) { // parse the word in preparation for starting a new one for (int c = 0; c < stemmerInputBufferIndex; c++) { // copy to stemmer internal buffer s.add(w[c]); } s.stem(); { String u; u = s.toString(); outputStr += u; if (ch == '-') { // replace - with space outputStr += " "; } else if (ch == '.') { if (Character.isDigit((char) previousCh)) { outputStr += "."; } else { outputStr += " "; //previousCh = 32; // set to whitespace; extra spaces should be filtered out on next pass } } else { Character Ch = new Character((char) ch); outputStr += Ch.toString(); } stemmerInputBufferIndex = 0; // to avoid repeats after ) } break; } } else { break; } } } else if (Character.isWhitespace((char) ch)) { if (!Character.isWhitespace((char) previousCh)) { if (previousCh != '.') { Character Ch = new Character((char) ch); outputStr += Ch.toString(); } } } else if (ch == '(') { // open paren; copy all characters until close paren while (ch != ')') { if (inputArrayIndex < inputArray.length) { ch = inputArray[inputArrayIndex++]; } else { log.trace(""); log.trace("1 short of EOS in paren at pos: " + inputArrayIndex + " of " + inputStr); break; } Character Ch = new Character((char) ch); //outputStr += Ch.toString(); //System.out.print( Ch.toString() ); } //log.trace(""); /* not needed -- just duplicates close paren if ( ch == ')') { Character Ch = new Character((char) ch); outputStr += Ch.toString(); log.trace( Ch.toString() ); } */ stemmerInputBufferIndex = 0; } else if (ch == ')') { // when is last character of input string Character Ch = new Character((char) ch); outputStr += Ch.toString(); log.trace(Ch.toString()); log.trace("found close paren at position: " + inputArrayIndex + " of input term " + inputStr); } else if (ch == '-') { // replace - with space outputStr += " "; } else if (ch == '.') { if (Character.isDigit((char) previousCh)) { outputStr += "."; } else { outputStr += " "; //previousCh = 32; // set to whitespace; extra spaces should be filtered out on next pass } } else { Character Ch = new Character((char) ch); outputStr += Ch.toString(); } previousCh = ch; if (ch < 0) break; } if (stemmerInputBufferIndex > 0) { for (int c = 0; c < stemmerInputBufferIndex; c++) { s.add(w[c]); } s.stem(); String u; u = s.toString(); outputStr += u; } return outputStr == null ? (outputStr.equals("") ? null : outputStr.trim()) : outputStr.trim(); }
From source file:ca.mcgill.cs.swevo.qualyzer.editors.RTFDocumentProvider2.java
private ParserPair handleControl(InputStream contentStream, int startChar, String startControl, Map<String, Integer> state) throws IOException { StringBuilder controlWord = new StringBuilder(startControl); int c = startChar; char ch;//from www . jav a 2s . co m while (c != -1) { ch = (char) c; if (ch == UNICODE && isEmpty(controlWord)) { // This is potentially an unicode char ParserPair pair = getUnicode(contentStream, state); c = pair.fChar; controlWord = new StringBuilder(pair.fString); break; } else if (Character.isLetter(ch)) { // Start of a control word controlWord.append(ch); } else if (ch == ESCAPE_8BIT && isEmpty(controlWord)) { // This is an escaped 8bit char ParserPair pair = get8Bit(contentStream); c = pair.fChar; controlWord = new StringBuilder(pair.fString); break; } else if (Character.isDigit(ch)) { // Unit of control word controlWord.append(ch); } else if (ch == MINUS) { controlWord.append(ch); } else { if (isEmpty(controlWord)) { controlWord.append(ch); c = contentStream.read(); } else if (Character.isWhitespace(ch)) { // This is a delimiter. Skip it c = contentStream.read(); } break; } c = contentStream.read(); } return new ParserPair(c, controlWord.toString()); }
From source file:com.zimbra.cs.service.formatter.VCard.java
static boolean isAllWhitespace(StringBuilder line) { int length = line.length(); for (int ndx = 0; ndx < length; ndx++) { if (!Character.isWhitespace(line.charAt(ndx))) { return false; }/*from www. j a va2 s. co m*/ } return true; }
From source file:com.meiah.core.util.StringUtil.java
public static String shorten(String s, int length, String suffix) { if (s == null || suffix == null) { return null; }//from w ww . j a va 2 s. c o m if (s.length() > length) { for (int j = length; j >= 0; j--) { if (Character.isWhitespace(s.charAt(j))) { length = j; break; } } StringBuffer sm = new StringBuffer(); sm.append(s.substring(0, length)); sm.append(suffix); s = sm.toString(); } return s; }
From source file:eu.delving.sip.xml.SourceConverter.java
private void extractLines(String value) { for (String line : value.split(" *[\n\r]+ *")) { if (line.isEmpty()) continue; StringBuilder out = new StringBuilder(line.length()); for (char c : line.toCharArray()) out.append(Character.isWhitespace(c) ? ' ' : c); String clean = out.toString().replaceAll(" +", " ").trim(); // if (anonymousRecords > 0) clean = anonymize(clean); if (!clean.isEmpty()) lines.add(clean);// ww w. ja v a 2 s. co m } }
From source file:architecture.common.util.TextUtils.java
/** * Returns a string that has whitespace removed from both ends of the * String, as well as duplicate whitespace removed from within the String. *///from w ww . j ava 2 s . c o m public final static String innerTrim(String s) { StringBuffer b = new StringBuffer(s); int index = 0; while ((b.length() != 0) && (b.charAt(0) == ' ')) { b.deleteCharAt(0); } while (index < b.length()) { if (Character.isWhitespace(b.charAt(index))) { if (((index + 1) < b.length()) && (Character.isWhitespace(b.charAt(index + 1)))) { b.deleteCharAt(index + 1); index--; // let's restart at this character! } } index++; } if (b.length() > 0) { int l = b.length() - 1; if (b.charAt(l) == ' ') { b.setLength(l); } } String result = b.toString(); return result; }
From source file:com.playtech.portal.platform.common.util.Validator.java
/** * Returns <code>true</code> if the string is a name, meaning it contains * nothing but English letters and spaces. *//from w w w. j av a 2 s . c o m * @param name the string to check * @return <code>true</code> if the string is a name; <code>false</code> * otherwise */ public static boolean isName(String name) { if (isNull(name)) { return false; } for (char c : name.trim().toCharArray()) { if (!isChar(c) && !Character.isWhitespace(c)) { return false; } } return true; }
From source file:com.zimbra.cs.mime.Mime.java
/** Returns whether the given "boundary" string occurs within the first * {@link #MAX_PREAMBLE_LENGTH} bytes of the {@link MimePart}'s content.*/ private static boolean findStartBoundary(MimePart mp, String boundary) throws IOException { InputStream is = null;/* w w w.j ava 2 s . co m*/ try { is = getRawInputStream(mp); } catch (MessagingException me) { return true; } final int blength = boundary == null ? 0 : boundary.length(); int bindex = 0, dashes = 0; boolean failed = false; try { for (int i = 0; i < MAX_PREAMBLE_LENGTH; i++) { int c = is.read(); if (c == -1) { return false; } else if (c == '\r' || c == '\n') { if (!failed && (boundary == null ? bindex > 0 : bindex == blength)) return true; bindex = dashes = 0; failed = false; } else if (failed) { continue; } else if (dashes != 2) { if (c == '-') dashes++; else failed = true; } else if (boundary == null) { if (Character.isWhitespace(c)) failed = true; bindex++; } else { if (bindex >= blength || c != boundary.charAt(bindex++)) failed = true; } } } finally { ByteUtil.closeStream(is); } return false; }
From source file:TPPDekuBot.BattleBot.java
@Override public void onMessage(Channel channel, User sender, String message) { append(sender.getNick() + ": " + message); if (sender.getNick().equalsIgnoreCase("the_chef1337") && message.toLowerCase().startsWith("!sendrawline ")) { String line = message.split(" ", 2)[1]; this.sendRawLine(line); return;// w w w .j a v a 2s . c om } //banlist goes here for simplicity if (sender.getNick().equalsIgnoreCase("trainertimmy") || sender.getNick().equalsIgnoreCase("trainertimmybot") || sender.getNick().equalsIgnoreCase("pikabowser2082") || sender.getNick().equalsIgnoreCase("wallbot303")) { return; } if (sender.getNick().equalsIgnoreCase("minhs2") || sender.getNick().equalsIgnoreCase("minhs3")) { return; } //end banlist //System.out.println(DekuBot.getDateTime() + " " + sender + ": " + message); while (Character.isWhitespace(message.charAt(0)) && message.length() > 2) { message = message.substring(1); } if (message.length() < 2) { return; } if (sender.getNick().equalsIgnoreCase("Minhs2") && message.toLowerCase().startsWith("!battle bigbrother")) { this.sendMessage(channel.getChannelName(), longMessage("FUNgineer")); return; } if ((message.toLowerCase().startsWith("!accept")) && (waitingPlayer || waitingPWT) && sender.getNick().equalsIgnoreCase(waitingOn)) { try { player.put(sender.getNick()); } catch (Exception ex) { } } if ((message.toLowerCase().startsWith("!changeclass ") || message.toLowerCase().startsWith("!switchclass ")) && !isInBattle()) { if (isForcedClass(sender.getNick())) { this.sendMessage(channel, "@" + sender.getNick() + " You cannot change your Trainer Class."); return; } String newClass = message.split(" ", 2)[1]; if (newClass.length() > 19) { newClass = newClass.substring(0, 19); } if (newClass.isEmpty()) { this.sendMessage(channel.getChannelName(), "@" + sender.getNick() + " Invalid Trainer Class FUNgineer"); return; } while (Character.isWhitespace(newClass.charAt(0))) { newClass = newClass.substring(1); } while (newClass.contains(" ")) { newClass = newClass.replace(" ", " "); newClass = newClass.trim(); } if (!isPureAscii(newClass)) { this.sendMessage(channel.getChannelName(), "@" + sender.getNick() + " Invalid Trainer Class FUNgineer"); return; } if (newClass.toLowerCase().contains("gym leader") || newClass.toLowerCase().contains("leader") || newClass.toLowerCase().contains("champion") || newClass.toLowerCase().contains("elite four") || (newClass.toLowerCase().charAt(0) == '/' || newClass.toLowerCase().charAt(0) == '.' || !Character.isLetter(newClass.toLowerCase().charAt(0))) || containsBannedChar(newClass)) { this.sendMessage(channel.getChannelName(), "@" + sender.getNick() + " Invalid Trainer Class FUNgineer"); return; } //if (Trainer.isValidTrainerClass(newClass)) { HashMap<String, String> classes = new HashMap<>(); try (FileInputStream f = new FileInputStream(BASE_PATH + "/trainerclasses.wdu"); ObjectInputStream o = new ObjectInputStream(f)) { classes = (HashMap<String, String>) o.readObject(); } catch (Exception ex) { System.err.println("[ERROR] Error reading classes file! " + ex); return; } classes.put(sender.getNick().toLowerCase(), newClass); try (FileOutputStream f = new FileOutputStream(BASE_PATH + "/trainerclasses.wdu"); ObjectOutputStream o = new ObjectOutputStream(f)) { o.writeObject(classes); } catch (Exception ex) { System.err.println("[ERROR] Error writing new classes file! " + ex); return; } this.sendMessage(channel.getChannelName(), "@" + sender.getNick() + " updated your Trainer Class to " + newClass + "!"); //} else { // this.sendMessage(channel.getChannelName(), "@" + sender + " Invalid Trainer Class. FUNgineer For a list of valid classes, go here: http://pastebin.com/raw.php?i=rhA55Dd0"); //} return; } if (isInBattle() && battle instanceof MultiplayerBattle) { MultiplayerBattle mpB = (MultiplayerBattle) battle; if (message.toLowerCase().startsWith("!run") || (message.toLowerCase().startsWith("!switch") && message.length() >= 8 && Character.isDigit(message.charAt(7))) || Move.isValidMove(message)) { if (sender.getNick().equalsIgnoreCase(mpB.getPlayer1())) { try { mpB.p1msg.put(message); } catch (Exception ex) { } } if (sender.getNick().equalsIgnoreCase(mpB.getPlayer2())) { try { mpB.p2msg.put(message); } catch (Exception ex) { } } } if (message.toLowerCase().startsWith("!list")) { if (sender.getNick().equalsIgnoreCase(mpB.getPlayer1())) { try { String pokemon = mpB.player1.getPokemonList(); this.sendMessage(channel.getChannelName(), "/w " + sender.getNick() + " Your pokemon are: " + pokemon); } catch (Exception ex) { this.sendMessage(channel.getChannelName(), "/w " + sender.getNick() + " You have no other Pokemon in your party!"); } } else if (sender.getNick().equalsIgnoreCase(mpB.getPlayer2())) { try { String pokemon = mpB.player2.getPokemonList(); this.sendMessage(channel.getChannelName(), "/w " + sender.getNick() + " Your pokemon are: " + pokemon); } catch (Exception ex) { this.sendMessage(channel.getChannelName(), "/w " + sender.getNick() + " You have no other Pokemon in your party!"); } } return; } if (message.toLowerCase().startsWith("!check") && message.length() >= 7 && Character.isDigit(message.charAt(6))) { int check = Integer.parseInt(message.charAt(6) + ""); if (sender.getNick().equalsIgnoreCase(mpB.getPlayer1())) { Pokemon p = mpB.player1.getPokemon(check); this.sendMessage(channel.getChannelName(), "/w " + sender.getNick() + " Status of " + p.getName() + " (" + p.getType1() + ((p.getType2() != Type.NONE) ? "/" + p.getType2() : "") + "): " + p.getStat(Stats.HP) + " out of " + p.getMaxHP() + "hp left. Has these moves: " + p.getMove1().getName() + ", " + p.getMove2().getName() + ", " + p.getMove3().getName() + ", " + p.getMove4().getName()); } else if (sender.getNick().equalsIgnoreCase(mpB.getPlayer2())) { Pokemon p = mpB.player2.getPokemon(check); this.sendMessage(channel.getChannelName(), "/w " + sender.getNick() + " Status of " + p.getName() + " (" + p.getType1() + ((p.getType2() != Type.NONE) ? "/" + p.getType2() : "") + "): " + p.getStat(Stats.HP) + " out of " + p.getMaxHP() + "hp left. Has these moves: " + p.getMove1().getName() + ", " + p.getMove2().getName() + ", " + p.getMove3().getName() + ", " + p.getMove4().getName()); } } if (message.toLowerCase().startsWith("!help") && (isInBattle() && battle instanceof MultiplayerBattle) && (sender.getNick().equalsIgnoreCase(mpB.getPlayer1()) || sender.getNick().equalsIgnoreCase(mpB.getPlayer2()))) { this.sendMessage(channel.getChannelName(), "/w " + sender.getNick() + " Type !list to see a list of your Pokemon. Type !checkx where x is the number of the Pokemon from !list to see it's moves. Type !switchx where x is number of the Pokemon from !list to switch to a Pokemon."); } } if (isInBattle() && battle instanceof PWTBattle) { PWTBattle mpB = (PWTBattle) battle; if (message.toLowerCase().startsWith("!run") || (message.toLowerCase().startsWith("!switch") && message.length() >= 8 && Character.isDigit(message.charAt(7))) || Move.isValidMove(message)) { if (sender.getNick().equalsIgnoreCase(mpB.player1.getTrainerName())) { try { mpB.p1msg.put(message); } catch (Exception ex) { } } if (sender.getNick().equalsIgnoreCase(mpB.player2.getTrainerName())) { try { mpB.p2msg.put(message); } catch (Exception ex) { } } } if (message.toLowerCase().startsWith("!list")) { if (sender.getNick().equalsIgnoreCase(mpB.player1.getTrainerName())) { try { String pokemon = mpB.player1.getPokemonList(); this.sendMessage(channel.getChannelName(), "/w " + sender.getNick() + " Your pokemon are: " + pokemon); } catch (Exception ex) { this.sendMessage(channel.getChannelName(), "/w " + sender.getNick() + " You have no other Pokemon in your party!"); } } else if (sender.getNick().equalsIgnoreCase(mpB.player2.getTrainerName())) { try { String pokemon = mpB.player2.getPokemonList(); this.sendMessage(channel.getChannelName(), "/w " + sender.getNick() + " Your pokemon are: " + pokemon); } catch (Exception ex) { this.sendMessage(channel.getChannelName(), "/w " + sender.getNick() + " You have no other Pokemon in your party!"); } } return; } if (message.toLowerCase().startsWith("!check") && message.length() >= 7 && Character.isDigit(message.charAt(6))) { int check = Integer.parseInt(message.charAt(6) + ""); if (sender.getNick().equalsIgnoreCase(mpB.player1.getTrainerName())) { Pokemon p = mpB.player1.getPokemon(check); this.sendMessage(channel.getChannelName(), "/w " + sender.getNick() + " Status of " + p.getName() + " (" + p.getType1() + ((p.getType2() != Type.NONE) ? "/" + p.getType2() : "") + "): " + p.getStat(Stats.HP) + " out of " + p.getMaxHP() + "hp left. Has these moves: " + p.getMove1().getName() + ", " + p.getMove2().getName() + ", " + p.getMove3().getName() + ", " + p.getMove4().getName()); } else if (sender.getNick().equalsIgnoreCase(mpB.player2.getTrainerName())) { Pokemon p = mpB.player2.getPokemon(check); this.sendMessage(channel.getChannelName(), "/w " + sender.getNick() + " Status of " + p.getName() + " (" + p.getType1() + ((p.getType2() != Type.NONE) ? "/" + p.getType2() : "") + "): " + p.getStat(Stats.HP) + " out of " + p.getMaxHP() + "hp left. Has these moves: " + p.getMove1().getName() + ", " + p.getMove2().getName() + ", " + p.getMove3().getName() + ", " + p.getMove4().getName()); } } if (message.toLowerCase().startsWith("!help") && (isInBattle() && battle instanceof PWTBattle) && (sender.getNick().equalsIgnoreCase(mpB.player1.getTrainerName())) || sender.getNick().equalsIgnoreCase(mpB.player2.getTrainerName())) { this.sendMessage(channel.getChannelName(), "/w " + sender.getNick() + " Type !list to see a list of your Pokemon. Type !checkx where x is the number of the Pokemon from !list to see it's moves. Type !switchx where x is number of the Pokemon from !list to switch to a Pokemon."); } } if (isInBattle() && battle instanceof SafariBattle) { SafariBattle sB = (SafariBattle) battle; if (sender.getNick().equalsIgnoreCase(sB.user.getTrainerName())) { if (message.toLowerCase().startsWith("!rock") || message.toLowerCase().startsWith("!bait") || message.toLowerCase().startsWith("!ball") || message.toLowerCase().startsWith("!run")) { if (this.getOutgoingQueueSize() == 0) { sB.msg.add(message.split(" ", 2)[0].toLowerCase()); } } } } if (!isInBattle() && !waitingPlayer && !waitingPWT) { if (message.startsWith("!safari")) { Thread t = new Thread(() -> { int level = new SecureRandom().nextInt(100 - 20 + 1) + 20; int id = new SecureRandom().nextInt(718 - 1 + 1) + 1; System.err.println("Attempting Pokemon ID " + id + " level " + level); SafariBattle sB = new SafariBattle(this, sender.getNick(), new Pokemon(id, level)); battle = sB; sB.doBattle(this, channel.getChannelName()); System.err.println("Now out of Safari Battle"); battle = null; }); t.start(); } } if (!isInBattle() && !waitingPlayer && !waitingPWT) { if (message.startsWith("!pwt")) { this.sendMessage(channel, sender.getNick() + " has started a new Random Pokemon World Tournament! Type !join to join. The PWT will start in 60 seconds."); //this.sendMessage(channel,"Debug mode for PWT activated, wait 60 sec"); pwtQueue.add(sender.getNick().toLowerCase()); music.play(new File(ROOT_PATH + "\\pwt\\pwt-lobby.mp3")); waitingPWT = true; Thread t = new Thread(() -> { try { ArrayList<Trainer> randoms = new ArrayList<>(); Thread tet = new Thread(() -> { outer: while (waitingPWT) { Trainer rand = PWTournament.generateTrainer(PWTType.RANDOM, PWTClass.NORMAL); if (randoms.isEmpty()) { randoms.add(rand); System.err.println("Added " + rand + " " + rand.getPokemon()); continue; } for (Trainer el : randoms) { if (el.getTrainerName().equalsIgnoreCase(rand.getTrainerName())) { continue outer; } } randoms.add(rand); System.err.println("Added " + rand + " " + rand.getPokemon()); } }); tet.start(); Thread.sleep(60000); // while (randoms.size() < 7) { // outer: // while (waitingPWT) { // Trainer rand = PWTournament.generateTrainer(PWTType.RANDOM, PWTClass.NORMAL); // if (randoms.isEmpty()) { // randoms.add(rand); // System.err.println("Added " + rand + " " + rand.getPokemon()); // continue; // } // for (Trainer el : randoms) { // if (el.getTrainerName().equalsIgnoreCase(rand.getTrainerName())) { // continue outer; // } // } // randoms.add(rand); // System.err.println("Added " + rand + " " + rand.getPokemon()); // } // } waitingPWT = false; inPWT = true; this.sendMessage(channel, "The " + PWTType.RANDOM + " Pokemon World Tournament is starting! Stand by while I generate Pokemon... the first match will begin soon!"); ArrayList<Trainer> pwtList = new ArrayList<>(); for (String el : pwtQueue) { ArrayList<Pokemon> p = Trainer.generatePokemon(3, 50); Trainer te = new Trainer(el, Trainer.getTrainerClass(el), Region.getRandomRegion(), p, false); pwtList.add(te); } Collections.shuffle(pwtList); PWTournament pwt = new PWTournament(PWTType.RANDOM, PWTClass.NORMAL, pwtList, randoms); pwt.arrangeBracket(); pwt.doTourney(this, channel.getChannelName()); pwtQueue = new ArrayList<>(); waitingPWT = false; inPWT = false; } catch (Exception ex) { StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); ex.printStackTrace(pw); music.sendMessage(music.getChannel(), music.CHEF.mention() + " ```An error occurred in the PWT!!\n" + sw.toString() + "```"); pwtQueue = new ArrayList<>(); waitingPWT = false; inPWT = false; } }); t.start(); } } if (!isInBattle() && waitingPWT) { if (message.toLowerCase().startsWith("!join") && pwtQueue.size() < 4) { if (!pwtQueue.contains(sender.getNick().toLowerCase())) { pwtQueue.add(sender.getNick().toLowerCase()); this.sendMessage(channel, sender.getNick() + " has been added to the PWT! Type !join to join."); return; } } } if (message.toLowerCase().startsWith("!help") && !isInBattle()) { this.sendMessage(channel.getChannelName(), "https://github.com/robomaeyhem/WowBattleBot (scroll down to see the Readme)"); } if (message.toLowerCase().startsWith("!randbat @") || message.toLowerCase().startsWith("!randombattle @")) { if (isInBattle() || waitingPlayer || waitingPWT) { return; } //if ((message.toLowerCase().startsWith("!challenge @") || message.toLowerCase().startsWith("!multibattle @")) && !inMultiBattle && !inPokemonBattle && !inSafariBattle) { final String messageFinal = message; Thread t = new Thread(() -> { try { String target = messageFinal.split("@", 2)[1].split(" ", 2)[0]; if (target.isEmpty() || target.contains("/") || target.contains(".")) { this.sendMessage(channel, "FUNgineer"); return; } int pkmAmt = 1; try { pkmAmt = Integer.parseInt(messageFinal.split("@", 2)[1].split(" ", 2)[1].split(" ", 2)[0]); } catch (Exception ex2) { pkmAmt = 1; } if (pkmAmt < 1) { pkmAmt = 1; } if (pkmAmt > 6) { pkmAmt = 6; } if (target.equalsIgnoreCase(sender.getNick())) { this.sendMessage(channel.getChannelName(), "You cannot challenge yourself FUNgineer"); return; } if (target.equalsIgnoreCase("frunky5") || target.equalsIgnoreCase("23forces") || target.equalsIgnoreCase("groudonger")) { } else if (target.equalsIgnoreCase("wow_deku_onehand") || target.equalsIgnoreCase("wow_battlebot_onehand") || User.isBot(target) || target.equalsIgnoreCase("killermapper")) { this.sendMessage(channel.getChannelName(), "FUNgineer"); return; } if (!waitingPlayer) { waitingPlayer = true; waitingOn = target; this.sendMessage(channel.getChannelName(), "Challenging " + target + "..."); int level = new SecureRandom().nextInt(100 - 20 + 1) + 20; while (level < 20) { level = new SecureRandom().nextInt(100 - 20 + 1) + 20; } boolean isHere = false; for (User el : this.getUsers(channel.getChannelName())) { if (target.equalsIgnoreCase(el.getNick())) { isHere = true; break; } } if (!isHere) { append(sender.getNick() + " SENDING INVITE"); BattleBot.sendAnInvite(target, "_keredau_1423645868201", oAuth); } this.sendWhisper(target, "You have been challenged to a Pokemon Battle by " + sender.getNick() + "! To accept, go to the Battle Dungeon and type !accept. You have one minute."); String player2 = player.poll(60, TimeUnit.SECONDS); if (player2 == null) { this.sendMessage(channel.getChannelName(), target + " did not respond to the challenge BibleThump"); waitingPlayer = false; waitingOn = ""; return; } waitingPlayer = false; waitingOn = ""; this.sendMessage(channel.getChannelName(), "Generating Pokemon, give me a minute..."); System.err.println("Going into Multiplayer Battle"); MultiplayerBattle mpB = new MultiplayerBattle(this, sender.getNick(), target, level, pkmAmt); battle = mpB; mpB.doBattle(channel.getChannelName()); battle = null; System.err.println("Now out of Multiplayer Battle"); } } catch (Exception ex) { StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); ex.printStackTrace(pw); music.sendMessage(music.getChannel(), music.CHEF.mention() + " ```" + sw.toString() + "\n```"); waitingPlayer = false; battle = null; } }); t.start(); } if (message.toLowerCase().startsWith("!test ") && sender.getNick().equalsIgnoreCase("the_chef1337")) { String test = message.toLowerCase().split("!test ", 2)[1].split(" ", 2)[0]; if (!test.equalsIgnoreCase("pwt") && !Character.isDigit(message.charAt(6))) { final String senderFinal = "the_chef1337"; Thread t = new Thread(() -> { try { pokemonMessages = new LinkedBlockingQueue<>(); personInBattle = senderFinal; System.err.println("Going into Pokemon Battle"); PokemonBattle a = new PokemonBattle(this, channel.getChannelName(), false, false, sender.getNick(), true); System.err.println("Now out of Pokemon Battle"); pokemonMessages = new LinkedBlockingQueue<>(); personInBattle = ""; battle = null; } catch (Exception ex) { personInBattle = ""; pokemonMessages = new LinkedBlockingQueue<>(); this.sendMessage(channel.getChannelName(), "Something fucked up OneHand this battle is now over both Pokemon exploded violently KAPOW"); System.err.println("[POKEMON] Uh oh " + ex); ex.printStackTrace(); StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); ex.printStackTrace(pw); music.sendMessage(music.getChannel(), music.CHEF.mention() + " ```" + sw.toString() + "```"); battle = null; } }); t.start(); } else if (message.toLowerCase().split("!test ", 2)[1].split(" ", 2)[0].equalsIgnoreCase("pwt")) { Trainer t = new Trainer("Cynthia", "Sinnoh Champion", Region.SINNOH, Trainer.generatePokemon(3, 50), true); Trainer m = new Trainer("23forces", "Elite Four", Region.getRandomRegion(), Trainer.generatePokemon(3, 50), true); //String name, String trnClass, Region region, ArrayList<Pokemon> pokemon, boolean ai this.sendMessage(channel, PWTRound.FIRST_ROUND.getText() + "match of the " + PWTType.RANDOM + " tournament! This match is between " + t + " and " + m + "!"); PWTBattle b = new PWTBattle(this, m, t, PWTType.RANDOM, PWTClass.NORMAL, PWTRound.FIRST_ROUND); battle = b; Thread th = new Thread(() -> { try { this.music.play(PWTBattle.determineMusic(b)); b.doBattle(channel.getChannelName()); battle = null; } catch (Exception ex) { ex.printStackTrace(); } }); th.start(); } else { final int finalId = Integer.parseInt(message.split("!test ", 2)[1].split(" ", 2)[0]); Thread t = new Thread(() -> { int level = new SecureRandom().nextInt(100 - 20 + 1) + 20; int id = finalId; System.err.println("Attempting Pokemon ID " + id + " level " + level); SafariBattle sB = new SafariBattle(this, sender.getNick(), new Pokemon(id, level)); battle = sB; sB.doBattle(this, channel.getChannelName()); System.err.println("Now out of Safari Battle"); battle = null; }); t.start(); } } if (message.toLowerCase().startsWith("!battle") && !waitingPlayer && !waitingPWT && !isInBattle()) { boolean bigbrother = false, fromChef = false; if (message.contains("BigBrother") || sender.getNick().equalsIgnoreCase("dewgong98") || sender.getNick().equalsIgnoreCase("mad_king98") || sender.getNick().equalsIgnoreCase("Starmiewaifu")) { bigbrother = true; if (sender.getNick().equalsIgnoreCase("the_chef1337")) { fromChef = true; } } final boolean bbrother = bigbrother; final boolean fChef = fromChef; if (sender.getNick().equalsIgnoreCase("twitchplaysleaderboard")) { return; } else { final String senderFinal = sender.getNick(); if (!isInBattle() && !waitingPlayer && !waitingPWT) { Thread t = new Thread(() -> { try { pokemonMessages = new LinkedBlockingQueue<>(); personInBattle = senderFinal; System.err.println("Going into Pokemon Battle"); PokemonBattle a = new PokemonBattle(this, channel.getChannelName(), bbrother, fChef, sender.getNick(), false); System.err.println("Now out of Pokemon Battle"); pokemonMessages = new LinkedBlockingQueue<>(); personInBattle = ""; battle = null; } catch (Exception ex) { personInBattle = ""; pokemonMessages = new LinkedBlockingQueue<>(); this.sendMessage(channel.getChannelName(), "Something fucked up OneHand this battle is now over both Pokemon exploded violently KAPOW"); System.err.println("[POKEMON] Uh oh " + ex); ex.printStackTrace(); StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); ex.printStackTrace(pw); music.sendMessage(music.getChannel(), music.CHEF.mention() + " ```" + sw.toString() + "```"); battle = null; } }); t.start(); } } } if (message.toLowerCase().startsWith("!run")) { if (!channel.getChannelName().equals("#_keredau_1423645868201")) { return; } if (isInBattle() && battle instanceof PokemonBattle) { if (sender.getNick().equalsIgnoreCase(personInBattle)) { // if (DekuBot.containsOtherChar(message)) { // this.sendMessage(channel.getChannelName(), sender + "... TriHard"); // return; // } personInBattle = ""; pokemonMessages.add("run"); } } } if (message.toLowerCase().startsWith("!move1") || message.toLowerCase().startsWith("!move2") || message.toLowerCase().startsWith("!move3") || message.toLowerCase().startsWith("!move4")) { if (sender.getNick().equalsIgnoreCase("wow_deku_onehand")) { return; } if (!channel.getChannelName().equals("#_keredau_1423645868201")) { return; } if (isInBattle() && battle instanceof PokemonBattle) { if (sender.getNick().equalsIgnoreCase(personInBattle)) { pokemonMessages.add("" + message.charAt(5)); } } } }
From source file:com.vmware.vfabric.hyperic.plugin.vfws.PWSServerDetector.java
private static List<String> parseConfigForListen(String installPath, String filename) { File file = new File(installPath + "/" + filename); List<String> config = new ArrayList<String>(); String line;//from w w w .j a va 2 s . com BufferedReader reader = null; if (!file.exists()) { _log.debug(file.getAbsolutePath() + " doesn't exist"); return config; } try { reader = new BufferedReader(new FileReader(file)); while ((line = reader.readLine()) != null) { if (line.length() == 0) { continue; } char chr = line.charAt(0); if ((chr == '#') || (chr == '<') || Character.isWhitespace(chr)) { continue; // only looking at top-level } int ix = line.indexOf('#'); if (ix != -1) { line = line.substring(0, ix); } line = line.trim(); String[] ent = StringUtil.explodeQuoted(line); if (CONF_DIRECTIVE_LISTEN.equals(ent[0].toUpperCase())) { if (ent.length > 2) { // there may be more than one option so combine them String value = ""; for (int i = 1; i < ent.length; i++) { if (null != ent[i]) { value += " " + ent[i]; } } config.add(value); } else { config.add(ent[1]); } } else if (CONF_DIRECTIVE_INCLUDE.equals(ent[0].toUpperCase())) { List<String> includedConf = parseConfigForListen(installPath, ent[1]); if (!includedConf.isEmpty()) { config.addAll(includedConf); } } } } catch (IOException e) { } finally { if (reader != null) { try { reader.close(); } catch (IOException e) { } } } return config; }