List of usage examples for com.google.common.collect Iterators peekingIterator
@Deprecated public static <T> PeekingIterator<T> peekingIterator(PeekingIterator<T> iterator)
From source file:com.techcavern.pircbotz.InputParser.java
/** * Called when the mode of a channel is set. We process this in * order to call the appropriate onOp, onDeop, etc method before * finally calling the override-able onMode method. * <p>//from www.java 2 s .c o m * Note that this method is private and is not intended to appear * in the javadoc generated documentation. * * @param target The channel or nick that the mode operation applies to. * @param sourceNick The nick of the user that set the mode. * @param sourceLogin The login of the user that set the mode. * @param sourceHostname The hostname of the user that set the mode. * @param mode The mode that has been set. */ public void processMode(User user, String target, String mode) { if (configuration.getChannelPrefixes().indexOf(target.charAt(0)) >= 0) { // The mode of a channel is being changed. Channel channel = bot.getUserChannelDao().getChannel(target); channel.parseMode(mode); ImmutableList<String> modeParsed = ImmutableList.copyOf(StringUtils.split(mode, ' ')); PeekingIterator<String> params = Iterators.peekingIterator(modeParsed.iterator()); //Process modes letter by letter, grabbing paramaters as needed boolean adding = true; String modeLetters = params.next(); for (int i = 0; i < modeLetters.length(); i++) { char curModeChar = modeLetters.charAt(i); if (curModeChar == '+') adding = true; else if (curModeChar == '-') adding = false; else { ChannelModeHandler modeHandler = configuration.getChannelModeHandlers().get(curModeChar); if (modeHandler != null) modeHandler.handleMode(bot, channel, user, params, adding, true); } } configuration.getListenerManager() .dispatchEvent(new ModeEvent<PircBotZ>(bot, channel, user, mode, modeParsed)); } else // The mode of a user is being changed. configuration.getListenerManager().dispatchEvent( new UserModeEvent<PircBotZ>(bot, user, bot.getUserChannelDao().getUser(target), mode)); }
From source file:org.pircbotx.InputParser.java
/** * Called when the mode of a channel is set. We process this in order to * call the appropriate onOp, onDeop, etc method before finally calling the * override-able onMode method.// w w w . j av a 2s.c om * <p> * Note that this method is private and is not intended to appear in the * javadoc generated documentation. * * @param target The channel or nick that the mode operation applies to. * @param mode The mode that has been set. */ public void processMode(UserHostmask userHostmask, User user, String target, String mode) { if (configuration.getChannelPrefixes().indexOf(target.charAt(0)) >= 0) { // The mode of a channel is being changed. Channel channel = bot.getUserChannelDao().getChannel(target); channel.parseMode(mode); ImmutableList<String> modeParsed = ImmutableList.copyOf(StringUtils.split(mode, ' ')); PeekingIterator<String> params = Iterators.peekingIterator(modeParsed.iterator()); //Process modes letter by letter, grabbing paramaters as needed boolean adding = true; String modeLetters = params.next(); for (int i = 0; i < modeLetters.length(); i++) { char curModeChar = modeLetters.charAt(i); if (curModeChar == '+') adding = true; else if (curModeChar == '-') adding = false; else { ChannelModeHandler modeHandler = configuration.getChannelModeHandlers().get(curModeChar); if (modeHandler != null) modeHandler.handleMode(bot, channel, userHostmask, user, params, adding, true); } } configuration.getListenerManager() .dispatchEvent(new ModeEvent(bot, channel, userHostmask, user, mode, modeParsed)); } else { // The mode of a user is being changed. UserHostmask targetHostmask = bot.getConfiguration().getBotFactory().createUserHostmask(bot, target); User targetUser = bot.getUserChannelDao().getUser(target); configuration.getListenerManager() .dispatchEvent(new UserModeEvent(bot, userHostmask, user, targetHostmask, targetUser, mode)); } }
From source file:com.google.googlejavaformat.java.JavaInputAstVisitor.java
private void visitStatements(List<? extends StatementTree> statements) { boolean first = true; PeekingIterator<StatementTree> it = Iterators.peekingIterator(statements.iterator()); dropEmptyDeclarations();//from w w w. j a v a 2s . com while (it.hasNext()) { StatementTree tree = it.next(); builder.forcedBreak(); if (!first) { builder.blankLineWanted(BlankLineWanted.PRESERVE); } markForPartialFormat(); first = false; List<VariableTree> fragments = variableFragments(it, tree); if (!fragments.isEmpty()) { visitVariables(fragments, DeclarationKind.NONE, canLocalHaveHorizontalAnnotations(fragments.get(0).getModifiers())); } else { scan(tree, null); } } }
From source file:com.google.googlejavaformat.java.JavaInputAstVisitor.java
/** Returns the number of columns if the arguments arg laid out in a grid, or else {@code -1}. */ private int argumentsAreTabular(List<? extends ExpressionTree> arguments) { if (arguments.isEmpty()) { return -1; }//from ww w. jav a 2s . c o m List<List<ExpressionTree>> rows = new ArrayList<>(); PeekingIterator<ExpressionTree> it = Iterators.peekingIterator(arguments.iterator()); int start0 = actualColumn(it.peek()); { List<ExpressionTree> row = new ArrayList<>(); row.add(it.next()); while (it.hasNext() && actualColumn(it.peek()) > start0) { row.add(it.next()); } if (!it.hasNext()) { return -1; } if (rowLength(row) <= 1) { return -1; } rows.add(row); } while (it.hasNext()) { List<ExpressionTree> row = new ArrayList<>(); int start = actualColumn(it.peek()); if (start != start0) { return -1; } row.add(it.next()); while (it.hasNext() && actualColumn(it.peek()) > start0) { row.add(it.next()); } rows.add(row); } int size0 = rows.get(0).size(); if (!expressionsAreParallel(rows, 0, rows.size())) { return -1; } for (int i = 1; i < size0; i++) { if (!expressionsAreParallel(rows, i, rows.size() / 2 + 1)) { return -1; } } // if there are only two rows, they must be the same length if (rows.size() == 2) { if (size0 == rows.get(1).size()) { return size0; } return -1; } // allow a ragged trailing row for >= 3 columns for (int i = 1; i < rows.size() - 1; i++) { if (size0 != rows.get(i).size()) { return -1; } } if (size0 < getLast(rows).size()) { return -1; } return size0; }
From source file:com.google.googlejavaformat.java.JavaInputAstVisitor.java
/** Add a list of declarations. */ void addBodyDeclarations(List<? extends Tree> bodyDeclarations, BracesOrNot braces, FirstDeclarationsOrNot first0) { if (bodyDeclarations.isEmpty()) { if (braces.isYes()) { builder.space();// w w w . ja v a 2s. c o m tokenBreakTrailingComment("{", plusTwo); builder.blankLineWanted(BlankLineWanted.NO); builder.open(ZERO); token("}", plusTwo); builder.close(); } } else { if (braces.isYes()) { builder.space(); tokenBreakTrailingComment("{", plusTwo); builder.open(ZERO); } builder.open(plusTwo); boolean first = first0.isYes(); boolean lastOneGotBlankLineBefore = false; PeekingIterator<Tree> it = Iterators.peekingIterator(bodyDeclarations.iterator()); while (it.hasNext()) { Tree bodyDeclaration = it.next(); dropEmptyDeclarations(); builder.forcedBreak(); boolean thisOneGetsBlankLineBefore = bodyDeclaration.getKind() != VARIABLE || hasJavaDoc(bodyDeclaration); if (first) { builder.blankLineWanted(PRESERVE); } else if (!first && (thisOneGetsBlankLineBefore || lastOneGotBlankLineBefore)) { builder.blankLineWanted(YES); } markForPartialFormat(); if (bodyDeclaration.getKind() == VARIABLE) { visitVariables(variableFragments(it, bodyDeclaration), DeclarationKind.FIELD, fieldAnnotationDirection(((VariableTree) bodyDeclaration).getModifiers())); } else { scan(bodyDeclaration, null); } first = false; lastOneGotBlankLineBefore = thisOneGetsBlankLineBefore; } dropEmptyDeclarations(); builder.forcedBreak(); builder.close(); builder.forcedBreak(); markForPartialFormat(); if (braces.isYes()) { builder.blankLineWanted(BlankLineWanted.NO); token("}", plusTwo); builder.close(); } } }