List of usage examples for com.google.common.collect FluentIterable size
@CheckReturnValue public final int size()
From source file:org.codeseed.common.config.PropertySources.java
/** * Returns a source which returns the first non-{@code null} value from a * series of sources.// w w w .j av a 2s . com * * @param sources * the ordered sources to combine * @return property source that considers multiple sources */ public static PropertySource compose(Iterable<PropertySource> sources) { FluentIterable<PropertySource> s = FluentIterable.from(sources) .filter(Predicates.not(Predicates.equalTo(empty()))); if (s.isEmpty()) { return empty(); } else if (s.size() == 1) { return s.first().get(); } else { return new CompositionSource(s.toList()); } }
From source file:com.google.devtools.build.lib.skyframe.serialization.FluentIterableCodec.java
@Override public void serialize(SerializationContext context, FluentIterable object, CodedOutputStream codedOut) throws IOException, SerializationException { codedOut.writeInt32NoTag(object.size()); for (Object obj : object) { context.serialize(obj, codedOut); }//from w w w. jav a 2 s. c o m }
From source file:org.obm.imap.sieve.commands.SieveGetScript.java
@Override public void responseReceived(List<SieveResponse> rs) { if (commandSucceeded(rs)) { String data = rs.get(0).getData(); Iterable<String> splitData = Splitter.on(SieveConstants.SPLIT_EXPR).split(data); FluentIterable<String> splitDataNoByteCount = FluentIterable.from(splitData).skip(1); FluentIterable<String> splitDataNoByteCountAndNoReturnCode = splitDataNoByteCount .limit(splitDataNoByteCount.size() - 1); if (!splitDataNoByteCountAndNoReturnCode.isEmpty()) { this.retVal = Joiner.on(SieveConstants.SEP).join(splitDataNoByteCountAndNoReturnCode) + "\r\n"; } else {// w w w . j a va 2 s . c om this.retVal = ""; } } else { reportErrors(rs); } logger.info("returning a sieve script"); }
From source file:de.monticore.symboltable.ArtifactScope.java
protected String getRemainingNameForResolveDown(String symbolName) { final String packageAS = this.getPackageName(); final FluentIterable<String> packageASNameParts = FluentIterable .from(Splitters.DOT.omitEmptyStrings().split(packageAS)); final FluentIterable<String> symbolNameParts = FluentIterable.from(Splitters.DOT.split(symbolName)); String remainingSymbolName = symbolName; if (symbolNameParts.size() > packageASNameParts.size()) { remainingSymbolName = Joiners.DOT.join(symbolNameParts.skip(packageASNameParts.size())); }//w ww . ja v a 2 s . com return remainingSymbolName; }
From source file:org.sosy_lab.cpachecker.cpa.termination.TerminationARGPath.java
@Override public List<CFAEdge> getFullPath() { if (terminationFullPath != null) { return terminationFullPath; }/*ww w . j av a 2s. c o m*/ ImmutableList.Builder<CFAEdge> fullPathBuilder = ImmutableList.builder(); PathIterator it = pathIterator(); Set<CFAEdge> intermediateTermiantionEdges = Sets.newHashSet(); while (it.hasNext()) { ARGState prev = it.getAbstractState(); CFAEdge curOutgoingEdge = it.getOutgoingEdge(); it.advance(); ARGState succ = it.getAbstractState(); TerminationState terminationPrev = extractStateByType(prev, TerminationState.class); TerminationState terminationSucc = extractStateByType(succ, TerminationState.class); // insert transition from loop to stem if (terminationPrev.isPartOfStem() && terminationSucc.isPartOfLoop()) { CFANode curNode = extractLocation(prev); List<CFAEdge> stemToLoopTransition = terminationInformation.createStemToLoopTransition(curNode, curNode); intermediateTermiantionEdges.addAll(stemToLoopTransition); fullPathBuilder.addAll(stemToLoopTransition); } // compute path between cur and next node if (curOutgoingEdge == null) { CFANode curNode = extractLocation(prev); CFANode nextNode = extractLocation(succ); // add negated ranking relation before target state (non-termination label) if (AbstractStates.isTargetState(succ)) { CFAEdge negatedRankingRelationAssumeEdge = terminationInformation .createRankingRelationAssumeEdge(curNode, nextNode, false); intermediateTermiantionEdges.add(negatedRankingRelationAssumeEdge); fullPathBuilder.add(negatedRankingRelationAssumeEdge); nextNode = curNode; } // we assume a linear chain of edges from 'prev' to 'succ' while (curNode != nextNode) { FluentIterable<CFAEdge> leavingEdges = CFAUtils.leavingEdges(curNode) .filter(not(in(intermediateTermiantionEdges))); if (!(leavingEdges.size() == 1 && curNode.getLeavingSummaryEdge() == null)) { return Collections.emptyList(); } CFAEdge intermediateEdge = leavingEdges.get(0); fullPathBuilder.add(intermediateEdge); curNode = intermediateEdge.getSuccessor(); } // we have a normal connection without hole in the edges } else { fullPathBuilder.add(curOutgoingEdge); } } terminationFullPath = fullPathBuilder.build(); terminationInformation.resetCfa(); return terminationFullPath; }
From source file:com.torodb.mongowp.server.encoder.ReplyMessageEncoder.java
public void encodeMessageBody(ByteBuf buffer, ReplyMessage message) { FluentIterable<? extends BsonDocument> docs = message.getDocuments().getIterable(AllocationType.HEAP); buffer.writeInt(EnumInt32FlagsUtil.getInt32Flags(extractFlags(message))); buffer.writeLong(message.getCursorId()); buffer.writeInt(message.getStartingFrom()); buffer.writeInt(docs.size()); for (BsonDocument document : docs) { writer.writeInto(buffer, document); }//from ww w.j a v a 2 s. co m }
From source file:com.lyndir.lanterna.view.TextView.java
@Override protected void drawForeground(final Screen screen) { super.drawForeground(screen); FluentIterable<String> lines = FluentIterable.from(getTextLines()); Box contentBox = getContentBoxOnScreen(); int from = getTextOffset(); switch (getTextCrop()) { case SHOW_FIRST: break;//w w w . ja v a2 s .co m case SHOW_LAST: from = Math.max(0, lines.size() - 1 - contentBox.getSize().getHeight() - getTextOffset()); break; } Iterator<String> linesIt = lines.skip(from).iterator(); for (int row = contentBox.getTop(); linesIt.hasNext() && row <= contentBox.getBottom(); ++row) screen.putString(contentBox.getLeft(), row, linesIt.next(), getTextColor(), getBackgroundColor()); if (getTextOffset() > 0) { String offsetText = String.format("%+d", getTextOffset()); screen.putString(contentBox.getRight() - offsetText.length(), contentBox.getTop(), offsetText, // getInfoTextColor(), getInfoBackgroundColor()); } }
From source file:aeon.compiler.generators.marshaller.PersisterMarshallerGeneratorImpl.java
private MethodSpec getUpdateStatementMethod() { final FluentIterable<SqliteField> fieldsWithoutId = getSqliteContext().getFieldContext() .getFieldsWithoutId();//from w ww .j av a 2 s .co m final String stmt; if (fieldsWithoutId.size() == 0) { stmt = ""; } else { final FluentIterable<String> assignments = fieldsWithoutId .transform(new Function<SqliteField, String>() { @Override public String apply(final SqliteField input) { return input.getName().asEscapedName() + " = ?"; } }); stmt = String.format("UPDATE %s SET %s WHERE %s = ?", getSqliteContext().getTableName().asEscapedName(), Joiner.on(", ").join(assignments), getSqliteContext().getFieldContext().getIdField().getName().asEscapedName()); } return MethodSpec.methodBuilder("getUpdateStatement").addAnnotation(Override.class) .addModifiers(Modifier.PROTECTED).returns(String.class).addStatement("return $S", stmt).build(); }
From source file:aeon.compiler.generators.marshaller.PersisterMarshallerGeneratorImpl.java
private MethodSpec bindUpdateStatementMethod() { final FluentIterable<Field> fieldsWithoutId = getContext().getFieldContext().getFieldsWithoutId(); final CodeBlock.Builder builder = CodeBlock.builder(); if (fieldsWithoutId.size() == 0) { builder.addStatement("throw new $T($S)", UnsupportedOperationException.class, String.format("Class %s cannot be updated. Only has one field (the ID field).", getContext().getTargetClassName().simpleName())); } else {//from w w w . ja va2s . c o m final Field idField = getContext().getFieldContext().getIdField(); if (idField.getType().isReferenceType()) { builder.beginControlFlow("if ($L.$L == null)", OBJ_PARAM, idField.getName()) .addStatement("throw new $T($S)", NullPointerException.class, "ID field cannot be null") .endControlFlow(); } buildBindings(builder, fieldsWithoutId, 1, false); buildBindings(builder, Lists.newArrayList(idField), fieldsWithoutId.size() + 1, false); builder.addStatement("return $L", STMT_PARAM); } return MethodSpec.methodBuilder("bindUpdateStatement").addAnnotation(Override.class) .addModifiers(Modifier.PROTECTED).returns(SQLiteStatement()) .addParameter(SQLiteStatement(), STMT_PARAM, Modifier.FINAL) .addParameter(getContext().getTargetClassName(), OBJ_PARAM, Modifier.FINAL).addCode(builder.build()) .build(); }
From source file:com.brq.wallet.pdf.ExportPdfParameters.java
public int entriesWithEncryptedKeys() { Iterable<ExportDistiller.ExportEntry> entries = Iterables.concat(active, archived); FluentIterable<ExportDistiller.ExportEntry> entryWithKey = FluentIterable.from(entries) .filter(new Predicate<ExportDistiller.ExportEntry>() { @Override/* w ww.j a va 2 s . c o m*/ public boolean apply(ExportDistiller.ExportEntry input) { return input.encryptedKey != null; } }); return entryWithKey.size(); }