List of usage examples for com.google.common.collect FluentIterable transform
@CheckReturnValue public final <T> FluentIterable<T> transform(Function<? super E, T> function)
From source file:org.opennms.newts.gsod.MergeSort.java
public void execute(String... args) throws IOException { CmdLineParser parser = createCmdLineParser(); try {/* w ww . ja v a2s . c o m*/ parser.parseArgument(args); } catch (CmdLineException e) { // handling of wrong arguments System.err.println(e.getMessage()); parser.printUsage(System.err); return; } final MetricRegistry metrics = new MetricRegistry(); ConsoleReporter reporter = ConsoleReporter.forRegistry(metrics).outputTo(System.err).convertRatesTo(SECONDS) .convertDurationsTo(MILLISECONDS).build(); reporter.start(10, SECONDS); Meter linesMeter = metrics.meter("lines"); Meter filesMeter = metrics.meter("files"); Meter dirsMeter = metrics.meter("dirs"); Meter batchMeter = metrics.meter("batches"); Path root = m_source.toPath(); if (m_targetDir == null) { m_targetDir = Files.createTempDir(); System.err.println("Working Directory: " + m_targetDir); } LOG.debug("Scanning {} for GSOD data files...", root); FluentIterable<KeyedIterable<Path, Path>> dirs = FileIterable.groupFilesByDir(root); for (KeyedIterable<Path, Path> filesInDir : dirs) { Path subdir = root.relativize(filesInDir.getKey()); String dirName = subdir.getFileName().toString(); System.err.println("Sorted dir: " + subdir); FluentIterable<Iterable<String>> contentIterables = filesInDir.transform(this.<Path>meter(filesMeter)) .transform(lines("YEARMODA")); FluentIterable<List<Iterable<String>>> batches = FluentIterable .from(Iterables.partition(contentIterables, m_mergeCount)); FluentIterable<Iterable<GSODLine>> sortedBatches = batches.transform(lift2GsodLines()) .transform(mergeSorter()); Path sortedDir = m_targetDir.toPath().resolve(subdir); sortedDir.toFile().mkdirs(); int count = 1; for (Iterable<GSODLine> batch : sortedBatches) { Path sortedFile = sortedDir.resolve(dirName + "-batch-" + (count++) + ".gz"); System.err.println("Creating " + sortedFile); try (PrintStream out = open(sortedFile)) { out.println(HDR); for (GSODLine line : batch) { out.println(line); linesMeter.mark(); } } batchMeter.mark(); } dirsMeter.mark(); } }
From source file:aeon.compiler.generators.marshaller.PersisterMarshallerGeneratorImpl.java
private MethodSpec getUpdateStatementMethod() { final FluentIterable<SqliteField> fieldsWithoutId = getSqliteContext().getFieldContext() .getFieldsWithoutId();/*from w w w . j a v a2s.c o 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:com.google.api.tools.framework.aspects.naming.NameAbbreviationRule.java
@Override public void run(ProtoElement element) { // This rule applies to all ProtoElements except file names. if (!(element instanceof ProtoFile)) { final String simpleName = element.getSimpleName(); if (!Strings.isNullOrEmpty(simpleName)) { FluentIterable<String> usedLongNames = FluentIterable.from(NAME_ABBREVIATION_MAP.keySet()) .filter(new Predicate<String>() { @Override public boolean apply(String longName) { return simpleName.toLowerCase().contains(longName); }//from w ww. ja v a 2 s. c o m }); if (!usedLongNames.isEmpty()) { FluentIterable<String> abbreviationsToUse = usedLongNames .transform(new Function<String, String>() { @Override @Nullable public String apply(@Nullable String longName) { return NAME_ABBREVIATION_MAP.get(longName); } }); warning(element, "Use of full name(s) '%s' in '%s' is not recommended, use '%s' instead.", Joiner.on(",").join(usedLongNames), element.getSimpleName(), Joiner.on(",").join(abbreviationsToUse)); } } } }
From source file:com.google.api.codegen.csharp.CSharpGapicContext.java
private List<String> docLines(ProtoElement element, final String prefix) { FluentIterable<String> lines = FluentIterable .from(Splitter.on(String.format("%n")).split(DocumentationUtil.getDescription(element))); return lines.transform(new Function<String, String>() { @Override/*from www .j a v a2s. co m*/ public String apply(String line) { return prefix + line.replace("&", "&").replace("<", "<"); } }).toList(); }
From source file:de.zalando.hackweek.bpm.engine.impl.cassandra.db.handler.SelectEventSubscriptionsByNameAndExecution.java
@Override public List<?> selectList(final Session session, final Object parameter) { ListQueryParameterObject listQuery = (ListQueryParameterObject) parameter; Map<String, String> query = (Map<String, String>) listQuery.getParameter(); final String eventType = query.get("eventType"); final String eventName = query.get("eventName"); FluentIterable<Row> rows = from( QueryBuilder.query(QUERY).parameter("execution_id", query.get("executionId")) // .parameter("event_type", query.get("eventType")) // .parameter("event_name", query.get("eventName")) .execute(session).all()); if (eventType != null || eventName != null) { rows = rows.filter(new Predicate<Row>() { @Override/*ww w .ja v a2 s . co m*/ public boolean apply(final Row row) { return Objects.equals(eventType, row.getString("event_type")) && Objects.equals(eventName, row.getString("event_name")); } }); } final List<EventSubscriptionEntity> entities = rows.transform(EventSubscriptionMapping.INSTANCE).toList(); return entities; }
From source file:org.eclipse.tracecompass.tmf.ui.views.histogram.HistogramDataModel.java
/** * Gets the traces names of this model./*from ww w . j a v a2 s . c o m*/ * * @return an array of trace names */ public String[] getTraceNames() { FluentIterable<ITmfTrace> traces = FluentIterable.from(TmfTraceManager.getTraceSet(fTrace)); FluentIterable<String> traceNames = traces.transform(new Function<ITmfTrace, String>() { @Override public String apply(ITmfTrace input) { return input.getName(); } }); return traceNames.toArray(String.class); }
From source file:org.apache.flink.streaming.runtime.operators.windowing.EvictingWindowOperator.java
private void emitWindowContents(W window, Iterable<StreamRecord<IN>> contents, ListState<StreamRecord<IN>> windowState) throws Exception { timestampedCollector.setAbsoluteTimestamp(window.maxTimestamp()); // Work around type system restrictions... FluentIterable<TimestampedValue<IN>> recordsWithTimestamp = FluentIterable.from(contents) .transform(new Function<StreamRecord<IN>, TimestampedValue<IN>>() { @Override//from ww w.ja v a 2 s . c om public TimestampedValue<IN> apply(StreamRecord<IN> input) { return TimestampedValue.from(input); } }); evictorContext.evictBefore(recordsWithTimestamp, Iterables.size(recordsWithTimestamp)); FluentIterable<IN> projectedContents = recordsWithTimestamp .transform(new Function<TimestampedValue<IN>, IN>() { @Override public IN apply(TimestampedValue<IN> input) { return input.getValue(); } }); userFunction.apply(context.key, context.window, projectedContents, timestampedCollector); evictorContext.evictAfter(recordsWithTimestamp, Iterables.size(recordsWithTimestamp)); //work around to fix FLINK-4369, remove the evicted elements from the windowState. //this is inefficient, but there is no other way to remove elements from ListState, which is an AppendingState. windowState.clear(); for (TimestampedValue<IN> record : recordsWithTimestamp) { windowState.add(record.getStreamRecord()); } }
From source file:edu.buaa.satla.analysis.cfa.CProgramScope.java
/** * Creates an object of this class./*from w ww . j a v a 2 s . c o m*/ * * When a single or a block of statements is supposed to be parsed, first a cfa for * the whole program has to be parsed to generate complex types for the variables. * These types and declarations are stored in this scope. * * @param cfa the cfa of the program, where single or block of statements are supposed to be parsed */ public CProgramScope(CFA cfa, LogManager pLogger) { assert cfa.getLanguage() == Language.C; functionName = null; /* Get all nodes, get all edges from nodes, get all declarations from edges, * assign every declaration its name. */ Collection<CFANode> nodes = cfa.getAllNodes(); FluentIterable<CSimpleDeclaration> dcls = FluentIterable.from(nodes) .transformAndConcat(TO_C_SIMPLE_DECLARATIONS).filter(HAS_NAME); FluentIterable<CFunctionDeclaration> functionDcls = dcls.filter(CFunctionDeclaration.class); FluentIterable<CSimpleDeclaration> nonFunctionDcls = dcls .filter(not(instanceOf(CFunctionDeclaration.class))); FluentIterable<CTypeDeclaration> typeDcls = dcls.filter(CTypeDeclaration.class); qualifiedTypes = extractTypes(nonFunctionDcls, pLogger); qualifiedTypeDefs = extractTypeDefs(typeDcls, pLogger); functionDeclarations = functionDcls.index(GET_ORIGINAL_QUALIFIED_NAME); variableNames = nonFunctionDcls.transform(GET_NAME).toSet(); qualifiedDeclarations = extractQualifiedDeclarations(nonFunctionDcls, pLogger); uniqueSimpleDeclarations = extractUniqueSimpleDeclarations(qualifiedDeclarations); }
From source file:de.zalando.hackweek.bpm.engine.impl.cassandra.db.handler.SelectExecutionsByQueryCriteriaHandler.java
@Override public List<?> selectList(final Session session, final Object parameter) { ExecutionQueryImpl query = (ExecutionQueryImpl) parameter; final String processInstanceId = query.getProcessInstanceId(); final QueryBuilder queryBuilder = QueryBuilder.query(QUERY).parameter("proc_inst_id", processInstanceId) .parameter("process_business_key", query.getBusinessKey()); // only supported since cassandra 2.1 if (false && query.getEventSubscriptions() != null) { for (EventSubscriptionQueryValue eventSubscriptionQueryValue : query.getEventSubscriptions()) { final String key = eventSubscriptionQueryValue.getEventType() + ":" + eventSubscriptionQueryValue.getEventName() + ":"; queryBuilder.parameter("event_subscriptions", key, "CONTAINS"); }//from ww w .j a va 2s. c om } FluentIterable<Row> rows = from(queryBuilder.execute(session).all()); if (query.getEventSubscriptions() != null) { for (EventSubscriptionQueryValue eventSubscriptionQueryValue : query.getEventSubscriptions()) { final String eventType = eventSubscriptionQueryValue.getEventType(); final String eventName = eventSubscriptionQueryValue.getEventName(); final String key = eventType + ":" + eventName; rows = rows.filter(new Predicate<Row>() { @Override public boolean apply(final Row row) { final Set<String> subscriptions = row.getSet("event_subscriptions", String.class); return subscriptions.contains(key); } }); } } if (query.getOnlyProcessInstances()) { rows = rows.filter(new Predicate<Row>() { @Override public boolean apply(final Row row) { return row.isNull("parent_id"); } }); } final ImmutableList<ExecutionEntity> executionEntities = rows.transform(ExecutionMapping.INSTANCE).toList(); return executionEntities; }
From source file:com.spectralogic.ds3client.helpers.Ds3ClientHelpers.java
@SafeVarargs public final Iterable<Ds3Object> toDs3Iterable(final Iterable<Contents> objects, final Predicate<Contents>... filters) { FluentIterable<Contents> fluentIterable = FluentIterable.from(objects) .filter(new com.google.common.base.Predicate<Contents>() { @Override// w w w .j a v a 2 s .c o m public boolean apply(@Nullable final Contents input) { return input != null; } }); if (filters != null) { for (final Predicate<Contents> filter : filters) { fluentIterable = fluentIterable.filter(new com.google.common.base.Predicate<Contents>() { @Override public boolean apply(@Nullable final Contents input) { if (filter != null) { return filter.test(input); } else { return true; // do not filter anything if filter is null } } }); } } return fluentIterable.transform(new Function<Contents, Ds3Object>() { @Nullable @Override public Ds3Object apply(@Nullable final Contents input) { return new Ds3Object(input.getKey(), input.getSize()); } }); }