List of usage examples for com.google.common.collect ImmutableList iterator
@Override
public UnmodifiableIterator<E> iterator()
From source file:org.caleydo.view.bicluster.sorting.FuzzyClustering.java
public List<IntFloat> filter(float threshold, int maxElements, EThresholdMode mode) { if (threshold == 0 && maxElements == UNBOUND_NUMBER) { switch (mode) { case ABS: return memberships.asList(); case NEGATIVE_ONLY: return negatives(0, UNBOUND_NUMBER); case POSITVE_ONLY: return positives(0, UNBOUND_NUMBER); }/*from w ww. j a v a 2 s. co m*/ } ImmutableList<IntFloat> negatives = mode.includeNegatives() ? negatives(threshold, maxElements) : ImmutableList.<IntFloat>of(); ImmutableList<IntFloat> positives = mode.includePositives() ? positives(threshold, maxElements) : ImmutableList.<IntFloat>of(); if (maxElements == UNBOUND_NUMBER || (negatives.size() + positives.size()) <= maxElements) //just add negatives and positives return ConcatedList.concat(negatives, positives); if (negatives.isEmpty()) { return positives.subList(Math.max(0, positives.size() - maxElements), positives.size()); } if (positives.isEmpty()) return negatives.subList(0, Math.min(negatives.size(), maxElements)); // take the abs top X elements Iterator<IntFloat> negIt = negatives.iterator(); Iterator<IntFloat> posIt = Lists.reverse(positives).iterator(); IntFloat negEnd = null; IntFloat negAct = negIt.next(); IntFloat posStart = null; IntFloat posAct = posIt.next(); for (int i = 0; i < maxElements; ++i) { if (negAct == null || (posAct != null && posAct.getMembership() > -negAct.getMembership())) { posStart = posAct; posAct = posIt.hasNext() ? posIt.next() : null; } else { negEnd = negAct; negAct = negIt.hasNext() ? negIt.next() : null; } } ImmutableSortedSet<IntFloat> headSet = negEnd == null ? ImmutableSortedSet.<IntFloat>of() : memberships.headSet(negEnd, true); ImmutableSortedSet<IntFloat> tailSet = posStart == null ? ImmutableSortedSet.<IntFloat>of() : memberships.tailSet(posStart, true); return ConcatedList.concat(headSet.asList(), tailSet.asList()); }
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>// w w w. j a va2s.c om * 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.//from w w w . j a v a 2s . c o m * <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.facebook.presto.sql.planner.RelationPlanner.java
private RelationPlan planCrossJoinUnnest(RelationPlan leftPlan, Join joinNode, Unnest node) { RelationType outputDescriptor = analysis.getOutputDescriptor(joinNode); RelationType unnestOutputDescriptor = analysis.getOutputDescriptor(node); // Create symbols for the result of unnesting ImmutableList.Builder<Symbol> unnestedSymbolsBuilder = ImmutableList.builder(); for (Field field : unnestOutputDescriptor.getVisibleFields()) { Symbol symbol = symbolAllocator.newSymbol(field); unnestedSymbolsBuilder.add(symbol); }//from www . j a v a 2 s .c o m ImmutableList<Symbol> unnestedSymbols = unnestedSymbolsBuilder.build(); // Add a projection for all the unnest arguments PlanBuilder planBuilder = initializePlanBuilder(leftPlan); planBuilder = appendProjections(planBuilder, node.getExpressions()); TranslationMap translations = planBuilder.getTranslations(); ProjectNode projectNode = checkType(planBuilder.getRoot(), ProjectNode.class, "planBuilder.getRoot()"); ImmutableMap.Builder<Symbol, List<Symbol>> unnestSymbols = ImmutableMap.builder(); UnmodifiableIterator<Symbol> unnestedSymbolsIterator = unnestedSymbols.iterator(); for (Expression expression : node.getExpressions()) { Type type = analysis.getType(expression); Symbol inputSymbol = translations.get(expression); if (type instanceof ArrayType) { unnestSymbols.put(inputSymbol, ImmutableList.of(unnestedSymbolsIterator.next())); } else if (type instanceof MapType) { unnestSymbols.put(inputSymbol, ImmutableList.of(unnestedSymbolsIterator.next(), unnestedSymbolsIterator.next())); } else { throw new IllegalArgumentException("Unsupported type for UNNEST: " + type); } } Optional<Symbol> ordinalitySymbol = node.isWithOrdinality() ? Optional.of(unnestedSymbolsIterator.next()) : Optional.empty(); checkState(!unnestedSymbolsIterator.hasNext(), "Not all output symbols were matched with input symbols"); UnnestNode unnestNode = new UnnestNode(idAllocator.getNextId(), projectNode, leftPlan.getOutputSymbols(), unnestSymbols.build(), ordinalitySymbol); return new RelationPlan(unnestNode, outputDescriptor, unnestNode.getOutputSymbols(), Optional.empty()); }
From source file:com.facebook.buck.cxx.PrebuiltCxxLibraryDescription.java
private static SourcePath getApplicableSourcePath(final BuildTarget target, final CellPathResolver cellRoots, final ProjectFilesystem filesystem, final BuildRuleResolver ruleResolver, final CxxPlatform cxxPlatform, Optional<String> versionSubDir, final String basePathString, final Optional<String> addedPathString) { ImmutableList<BuildRule> deps; MacroHandler handler = getMacroHandler(Optional.of(cxxPlatform)); try {/*from w w w . j a v a 2 s. c o m*/ deps = handler.extractBuildTimeDeps(target, cellRoots, ruleResolver, basePathString); } catch (MacroException e) { deps = ImmutableList.of(); } Path libDirPath = filesystem .getPath(expandMacros(handler, target, cellRoots, ruleResolver, basePathString)); if (versionSubDir.isPresent()) { libDirPath = filesystem.getPath(versionSubDir.get()).resolve(libDirPath); } // If there are no deps then this is just referencing a path that should already be there // So just expand the macros and return a PathSourcePath if (deps.isEmpty()) { Path resultPath = libDirPath; if (addedPathString.isPresent()) { resultPath = libDirPath .resolve(expandMacros(handler, target, cellRoots, ruleResolver, addedPathString.get())); } resultPath = target.getBasePath().resolve(resultPath); return new PathSourcePath(filesystem, resultPath); } // If we get here then this is referencing the output from a build rule. // This always return a BuildTargetSourcePath Path p = filesystem.resolve(libDirPath); if (addedPathString.isPresent()) { p = p.resolve(addedPathString.get()); } p = filesystem.relativize(p); return new BuildTargetSourcePath(deps.iterator().next().getBuildTarget(), p); }
From source file:io.prestosql.sql.planner.RelationPlanner.java
private RelationPlan planCrossJoinUnnest(RelationPlan leftPlan, Join joinNode, Unnest node) { RelationType unnestOutputDescriptor = analysis.getOutputDescriptor(node); // Create symbols for the result of unnesting ImmutableList.Builder<Symbol> unnestedSymbolsBuilder = ImmutableList.builder(); for (Field field : unnestOutputDescriptor.getVisibleFields()) { Symbol symbol = symbolAllocator.newSymbol(field); unnestedSymbolsBuilder.add(symbol); }//w ww . j a v a 2 s .com ImmutableList<Symbol> unnestedSymbols = unnestedSymbolsBuilder.build(); // Add a projection for all the unnest arguments PlanBuilder planBuilder = initializePlanBuilder(leftPlan); planBuilder = planBuilder.appendProjections(node.getExpressions(), symbolAllocator, idAllocator); TranslationMap translations = planBuilder.getTranslations(); ProjectNode projectNode = (ProjectNode) planBuilder.getRoot(); ImmutableMap.Builder<Symbol, List<Symbol>> unnestSymbols = ImmutableMap.builder(); UnmodifiableIterator<Symbol> unnestedSymbolsIterator = unnestedSymbols.iterator(); for (Expression expression : node.getExpressions()) { Type type = analysis.getType(expression); Symbol inputSymbol = translations.get(expression); if (type instanceof ArrayType) { Type elementType = ((ArrayType) type).getElementType(); if (!SystemSessionProperties.isLegacyUnnest(session) && elementType instanceof RowType) { ImmutableList.Builder<Symbol> unnestSymbolBuilder = ImmutableList.builder(); for (int i = 0; i < ((RowType) elementType).getFields().size(); i++) { unnestSymbolBuilder.add(unnestedSymbolsIterator.next()); } unnestSymbols.put(inputSymbol, unnestSymbolBuilder.build()); } else { unnestSymbols.put(inputSymbol, ImmutableList.of(unnestedSymbolsIterator.next())); } } else if (type instanceof MapType) { unnestSymbols.put(inputSymbol, ImmutableList.of(unnestedSymbolsIterator.next(), unnestedSymbolsIterator.next())); } else { throw new IllegalArgumentException("Unsupported type for UNNEST: " + type); } } Optional<Symbol> ordinalitySymbol = node.isWithOrdinality() ? Optional.of(unnestedSymbolsIterator.next()) : Optional.empty(); checkState(!unnestedSymbolsIterator.hasNext(), "Not all output symbols were matched with input symbols"); UnnestNode unnestNode = new UnnestNode(idAllocator.getNextId(), projectNode, leftPlan.getFieldMappings(), unnestSymbols.build(), ordinalitySymbol); return new RelationPlan(unnestNode, analysis.getScope(joinNode), unnestNode.getOutputSymbols()); }
From source file:com.android.contacts.editor.ContactEditorBaseFragment.java
/** * Prepare {@link #mState} for an existing contact. *//* w w w .ja v a 2s. c o m*/ protected void setStateForExistingContact(String readOnlyDisplayName, boolean isUserProfile, ImmutableList<RawContact> rawContacts) { setEnabled(true); mReadOnlyDisplayName = readOnlyDisplayName; mState.addAll(rawContacts.iterator()); setIntentExtras(mIntentExtras); mIntentExtras = null; // For user profile, change the contacts query URI mIsUserProfile = isUserProfile; boolean localProfileExists = false; if (mIsUserProfile) { for (RawContactDelta rawContactDelta : mState) { // For profile contacts, we need a different query URI rawContactDelta.setProfileQueryUri(); // Try to find a local profile contact if (rawContactDelta.getValues().getAsString(RawContacts.ACCOUNT_TYPE) == null) { localProfileExists = true; } } // Editor should always present a local profile for editing if (!localProfileExists) { mState.add(createLocalRawContactDelta()); } } mExistingContactDataReady = true; bindEditors(); }
From source file:com.android.contacts.editor.ContactEditorFragment.java
private void bindEditorsForExistingContact(String displayName, boolean isUserProfile, ImmutableList<RawContact> rawContacts) { setEnabled(true);/* ww w. jav a 2 s . c o m*/ mDefaultDisplayName = displayName; mState.addAll(rawContacts.iterator()); setIntentExtras(mIntentExtras); mIntentExtras = null; // For user profile, change the contacts query URI mIsUserProfile = isUserProfile; boolean localProfileExists = false; if (mIsUserProfile) { for (RawContactDelta state : mState) { // For profile contacts, we need a different query URI state.setProfileQueryUri(); // Try to find a local profile contact if (state.getValues().getAsString(RawContacts.ACCOUNT_TYPE) == null) { localProfileExists = true; } } // Editor should always present a local profile for editing if (!localProfileExists) { final RawContact rawContact = new RawContact(); rawContact.setAccountToLocal(); RawContactDelta insert = new RawContactDelta(ValuesDelta.fromAfter(rawContact.getValues())); insert.setProfileQueryUri(); mState.add(insert); } } mRequestFocus = true; mExistingContactDataReady = true; bindEditors(); }
From source file:com.google.javascript.jscomp.parsing.NewIRFactory.java
private NewIRFactory(String sourceString, StaticSourceFile sourceFile, Config config, ErrorReporter errorReporter, ImmutableList<Comment> comments) { this.sourceString = sourceString; this.nextCommentIter = comments.iterator(); this.currentComment = nextCommentIter.hasNext() ? nextCommentIter.next() : null; this.newlines = Lists.newArrayList(); this.sourceFile = sourceFile; // Pre-generate all the newlines in the file. for (int charNo = 0; true; charNo++) { charNo = sourceString.indexOf('\n', charNo); if (charNo == -1) { break; }//from www. j av a 2 s. c om newlines.add(Integer.valueOf(charNo)); } // Sometimes this will be null in tests. this.sourceName = sourceFile == null ? null : sourceFile.getName(); this.config = config; this.errorReporter = errorReporter; this.transformDispatcher = new TransformDispatcher(); // The template node properties are applied to all nodes in this transform. this.templateNode = createTemplateNode(); switch (config.languageMode) { case ECMASCRIPT3: reservedKeywords = null; // use TokenStream.isKeyword instead break; case ECMASCRIPT5: reservedKeywords = ES5_RESERVED_KEYWORDS; break; case ECMASCRIPT5_STRICT: reservedKeywords = ES5_STRICT_RESERVED_KEYWORDS; break; case ECMASCRIPT6: reservedKeywords = ES5_RESERVED_KEYWORDS; break; case ECMASCRIPT6_STRICT: reservedKeywords = ES5_STRICT_RESERVED_KEYWORDS; break; default: throw new IllegalStateException("unknown language mode"); } }
From source file:com.google.javascript.jscomp.parsing.IRFactory.java
private IRFactory(String sourceString, StaticSourceFile sourceFile, Config config, ErrorReporter errorReporter, ImmutableList<Comment> comments) { this.sourceString = sourceString; this.nextCommentIter = comments.iterator(); this.currentComment = nextCommentIter.hasNext() ? nextCommentIter.next() : null; this.newlines = new ArrayList<>(); this.sourceFile = sourceFile; this.fileLevelJsDocBuilder = new JSDocInfoBuilder(config.parseJsDocDocumentation); // Pre-generate all the newlines in the file. for (int charNo = 0; true; charNo++) { charNo = sourceString.indexOf('\n', charNo); if (charNo == -1) { break; }//from w w w . j a v a 2 s .c om newlines.add(Integer.valueOf(charNo)); } // Sometimes this will be null in tests. this.sourceName = sourceFile == null ? null : sourceFile.getName(); this.config = config; this.errorReporter = errorReporter; this.transformDispatcher = new TransformDispatcher(); // The template node properties are applied to all nodes in this transform. this.templateNode = createTemplateNode(); switch (config.languageMode) { case ECMASCRIPT3: reservedKeywords = null; // use TokenStream.isKeyword instead break; case ECMASCRIPT5: case ECMASCRIPT6: reservedKeywords = ES5_RESERVED_KEYWORDS; break; case ECMASCRIPT5_STRICT: case ECMASCRIPT6_STRICT: case ECMASCRIPT6_TYPED: reservedKeywords = ES5_STRICT_RESERVED_KEYWORDS; break; default: throw new IllegalStateException("unknown language mode: " + config.languageMode); } }