Java Code Examples for org.eclipse.collections.api.list.MutableList#collect()

The following examples show how to use org.eclipse.collections.api.list.MutableList#collect() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: InMemoryTranslator.java    From obevo with Apache License 2.0 6 votes vote down vote up
@Override
public final String prepare(String sql, final ChangeInput change, final Environment env) {
    if (change != null && Objects.equals(change.getChangeKey().getChangeType().getName(), ChangeType.STATICDATA_STR)
            && !StaticDataChangeTypeBehavior.isInsertModeStaticData(sql)) {
        return sql;
    }

    sql = CommentRemover.removeComments(sql, change != null ? change.getChangeKey().toString() : sql);
    MutableList<String> sqls = MultiLineStringSplitter.createSplitterOnSpaceAndLine("GO").valueOf(sql);

    MutableList<String> convertedSqls = sqls.collect(new Function<String, String>() {
        @Override
        public String valueOf(String object) {
            return InMemoryTranslator.this.translateStatement(object, change);
        }
    });

    return convertedSqls.makeString("\n\nGO\n\n");
}
 
Example 2
Source File: CsvReaderDataSource.java    From obevo with Apache License 2.0 6 votes vote down vote up
/**
 * Putting this init here so that we can discover the file fields before running the actual rec
 */
public void init() {
    if (!this.initialized) {
        try {
            MutableList<String> fields;
            if (csvVersion == CsvStaticDataReader.CSV_V2) {
                CSVFormat csvFormat = CsvStaticDataReader.getCsvFormat(delim, nullToken);
                this.csvreaderV2 = new CSVParser(reader, csvFormat);
                this.iteratorV2 = csvreaderV2.iterator();
                fields = ListAdapter.adapt(IteratorUtils.toList(iteratorV2.next().iterator()));
            } else {
                this.csvreaderV1 = new au.com.bytecode.opencsv.CSVReader(this.reader, this.delim);
                fields = ArrayAdapter.adapt(this.csvreaderV1.readNext());
            }

            this.fields = fields.collect(this.convertDbObjectName);
        } catch (Exception e) {
            throw new DeployerRuntimeException(e);
        }
        this.initialized = true;
    }
}
 
Example 3
Source File: AquaRevengMain.java    From obevo with Apache License 2.0 6 votes vote down vote up
private MutableList<File> preprocessSchemaTokens(MutableList<File> files, String dbSchema, final File interimFolder, DbPlatform dbPlatform) {
    // adding DBO to help w/ Sybase ASE; we should make this code more polymorphic
    String schemaSeparatorRegex = dbPlatform.isSubschemaSupported() ? "\\.(?:dbo)?\\." : "\\.";

    final Pattern dbSchemaPattern = Pattern.compile(String.format("(?i)%1$s%2$s(\\w+)", dbSchema, schemaSeparatorRegex));
    return files.collect(new Function<File, File>() {
        @Override
        public File valueOf(File file) {
            String fileContent = FileUtilsCobra.readFileToString(file);
            final Matcher matcher = dbSchemaPattern.matcher(fileContent);
            StringBuffer sb = new StringBuffer(fileContent.length());

            while (matcher.find()) {
                matcher.appendReplacement(sb, matcher.group(1));
            }
            matcher.appendTail(sb);

            File tempFile = new File(interimFolder, file.getName());
            FileUtilsCobra.writeStringToFile(tempFile, sb.toString());
            return tempFile;
        }
    });
}
 
Example 4
Source File: PlatformConfigReader.java    From obevo with Apache License 2.0 5 votes vote down vote up
public ImmutableHierarchicalConfiguration readPlatformProperties(RichIterable<String> configPackages) {
    MutableList<PropertyInput> prioritizedProperties = readConfigPackages(configPackages);

    validate(prioritizedProperties);

    // order properties by priority: higher-numbered files will replace properties of lower-numbered files
    prioritizedProperties.sortThisBy(new Function<PropertyInput, Integer>() {
        @Override
        public Integer valueOf(PropertyInput propertyInput1) {
            return propertyInput1.getPriority();
        }
    }).reverseThis();  // needs to be reversed as CombinedConfiguration takes the higher-priority files first

    // merge properties
    CombinedConfiguration combinedConfiguration = new CombinedConfiguration(new OverrideCombiner());
    for (HierarchicalConfiguration<ImmutableNode> properties : prioritizedProperties.collect(new Function<PropertyInput, HierarchicalConfiguration<ImmutableNode>>() {
        @Override
        public HierarchicalConfiguration<ImmutableNode> valueOf(PropertyInput propertyInput) {
            return propertyInput.getProps();
        }
    })) {
        combinedConfiguration.addConfiguration(properties);
    }

    // remove the configPriority property
    combinedConfiguration.clearTree(PROP_CONFIG_PRIORITY);

    return combinedConfiguration;
}
 
Example 5
Source File: CollectPatternUnitTest.java    From tutorials with MIT License 5 votes vote down vote up
@Test
public void whenCollect_thenCorrect() {
    Student student1 = new Student("John", "Hopkins");
    Student student2 = new Student("George", "Adams");

    MutableList<Student> students = FastList.newListWith(student1, student2);

    MutableList<String> lastNames = students.collect(Student::getLastName);

    Assertions.assertThat(lastNames).containsExactly("Hopkins", "Adams");
}
 
Example 6
Source File: AbstractReveng.java    From obevo with Apache License 2.0 4 votes vote down vote up
private void revengMain(File inputPath, final AquaRevengArgs args) {
        // First, collect all files in the directory together. We will consider this as one set of objects to go through.
        final MutableList<File> files;
        if (inputPath.isFile()) {
            files = Lists.mutable.of(inputPath);
        } else {
            files = Lists.mutable.empty();
            try {
                Files.walkFileTree(inputPath.toPath(), new SimpleFileVisitor<Path>() {
                    @Override
                    public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
                        File fileObj = file.toFile();
                        if (fileObj.isFile()) {
                            files.add(fileObj);
                        }
                        return super.visitFile(file, attrs);
                    }
                });
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }

        // next - extract all the objects that we've matched based on the reverse engineering inputs and the schema
        MutableList<FileProcessingContext> fileProcessingContexts = files.collect(file -> {
            MutableList<String> sqlSnippets = getSqlSnippets(file);

            PartitionList<Pair<String, RevengPatternOutput>> snippetPatternMatchPairs = sqlSnippets
                    .collect(patternMatchSnippet)
                    .partition(each -> {
                        RevengPatternOutput patternMatch = each.getTwo();
                        return !skipSchemaValidation
                                && patternMatch != null
                                && (args.isExplicitSchemaRequired() || patternMatch.getSchema() != null)
                                && patternMatch.getSubSchema() == null
                                && !args.getDbSchema().equalsIgnoreCase(patternMatch.getSchema());
                    });

            return new FileProcessingContext(file, snippetPatternMatchPairs);
        });

        // add those pattern matches to the schema object replacer. This is there to replace all references of the schema in other objects
        final SchemaObjectReplacer schemaObjectReplacer = new SchemaObjectReplacer();
        for (FileProcessingContext fileProcessingContext : fileProcessingContexts) {
            for (Pair<String, RevengPatternOutput> snippetPatternMatchPair : fileProcessingContext.getSnippetPatternMatchPairs()) {
                schemaObjectReplacer.addPatternMatch(snippetPatternMatchPair.getTwo());
            }
        }

        final MutableList<ChangeEntry> changeEntries = fileProcessingContexts.flatCollect(fileProcessingContext -> {
            String schema = getObjectSchema(args.getDbSchema(), fileProcessingContext.getFile().getName());

            return revengFile(schemaObjectReplacer, fileProcessingContext.getSnippetPatternMatchPairs(), schema, args.isDebugLogEnabled());
        });

//        final MutableList<ChangeEntry> invalidEntries = fileProcessingContexts.flatCollect(new Function<FileProcessingContext, Iterable<ChangeEntry>>() {
//            @Override
//            public Iterable<ChangeEntry> valueOf(FileProcessingContext fileProcessingContext) {
//                String schema = "UNMAPPEDSCHEMA";
//
//                return revengFile(schemaObjectReplacer, fileProcessingContext.getDiffSchemaSnippetPatternMatchPairs(), schema, args.isDebugLogEnabled());
//            }
//        });

        new RevengWriter().write(platform, changeEntries, new File(args.getOutputPath(), "final"), args.isGenerateBaseline(), RevengWriter.defaultShouldOverwritePredicate(), args.getExcludeObjects());
        new RevengWriter().writeConfig("deployer/reveng/system-config-template.xml.ftl", platform, new File(args.getOutputPath(), "final"), Lists.mutable.of(args.getDbSchema()),
                Maps.immutable.of(
                        "jdbcUrl", args.getJdbcUrl(),
                        "dbHost", args.getDbHost(),
                        "dbPort", args.getDbPort() != null ? args.getDbPort().toString() : null,
                        "dbServer", args.getDbServer()
                ).toMap()
        );
    }
 
Example 7
Source File: AbstractReveng.java    From obevo with Apache License 2.0 4 votes vote down vote up
private MutableList<String> getSqlSnippets(File file) {
    final MutableList<String> dataLines;
    dataLines = FileUtilsCobra.readLines(file);

    dataLines.forEachWithIndex(new ObjectIntProcedure<String>() {
        @Override
        public void value(String line, int i) {
            if (!line.isEmpty() && line.charAt(0) == '\uFEFF') {
                dataLines.set(i, dataLines.get(i).substring(1));
            }
            if (line.startsWith("--------------------")
                    && dataLines.get(i + 1).startsWith("-- DDL Statements")
                    && dataLines.get(i + 2).startsWith("--------------------")) {
                dataLines.set(i, "");
                dataLines.set(i + 1, "");
                dataLines.set(i + 2, "");
            } else if (line.startsWith("--------------------")
                    && dataLines.get(i + 2).startsWith("-- DDL Statements")
                    && dataLines.get(i + 4).startsWith("--------------------")) {
                dataLines.set(i, "");
                dataLines.set(i + 1, "");
                dataLines.set(i + 2, "");
                dataLines.set(i + 3, "");
                dataLines.set(i + 4, "");
            } else if (line.startsWith("-- DDL Statements for ")) {
                dataLines.set(i, "");
            }

            // For PostgreSQL
            if ((line.equals("--")
                    && dataLines.get(i + 1).startsWith("-- Name: ")
                    && dataLines.get(i + 2).equals("--"))) {
                dataLines.set(i, "");
                dataLines.set(i + 1, "GO");
                dataLines.set(i + 2, "");
            }
        }
    });

    MutableList<String> sqlSnippets;
    if (stringSplitter != null) {
        String data = dataLines
                .reject(skipLinePredicates != null ? Predicates.or(skipLinePredicates) : (Predicate) Predicates.alwaysFalse())
                .makeString(SystemUtils.LINE_SEPARATOR);

        sqlSnippets = stringSplitter.valueOf(data);
    } else {
        // If null, then default each line to being its own parsable statement
        sqlSnippets = dataLines
                .reject(skipLinePredicates != null ? Predicates.or(skipLinePredicates) : (Predicate) Predicates.alwaysFalse());
    }

    sqlSnippets = sqlSnippets.collect(new Function<String, String>() {
        @Override
        public String valueOf(String sqlSnippet) {
            return StringUtils.stripStart(sqlSnippet, "\r\n \t");
        }
    });
    sqlSnippets = sqlSnippets.select(StringPredicates.notBlank().and(Predicates.noneOf(skipPredicates)));
    return sqlSnippets;
}