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

The following examples show how to use org.eclipse.collections.api.list.MutableList#add() . 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: UnitTestDbBuilder.java    From obevo with Apache License 2.0 6 votes vote down vote up
private MainDeployerArgs getMainDeployerArgs() {
    MainDeployerArgs args = new MainDeployerArgs();

    if (this.tables != null || this.views != null) {
        MutableList<Predicate<? super ChangeKey>> predicates = Lists.mutable.empty();
        if (this.tables != null) {
            predicates.add(ChangeKeyPredicateBuilder.newBuilder()
                    .setChangeTypes(ChangeType.TABLE_STR, ChangeType.FOREIGN_KEY_STR, ChangeType.TRIGGER_INCREMENTAL_OLD_STR, ChangeType.STATICDATA_STR)
                    .setObjectNames(Sets.immutable.withAll(this.tables))
                    .build());
        }
        if (this.views != null) {
            predicates.add(ChangeKeyPredicateBuilder.newBuilder()
                    .setChangeTypes(ChangeType.VIEW_STR)
                    .setObjectNames(Sets.immutable.withAll(this.views))
                    .build());
        }

        args.setChangeInclusionPredicate(Predicates.or(predicates));
    }

    args.setAllChangesets(true);  // for unit tests, we always want all changes to deploy
    return args;
}
 
Example 2
Source File: DbChangeRestrictionsReader.java    From obevo with Apache License 2.0 6 votes vote down vote up
public ImmutableList<ArtifactRestrictions> valueOf(TextMarkupDocumentSection section) {
    if (section == null) {
        return Lists.immutable.of();
    }

    MutableList<ArtifactRestrictions> restrictions = Lists.mutable.empty();

    Twin<MutableSet<String>> envRestrictions = readRestrictions(section, TextMarkupDocumentReader.INCLUDE_ENVS, TextMarkupDocumentReader.EXCLUDE_ENVS);
    if (envRestrictions != null) {
        restrictions.add(new ArtifactEnvironmentRestrictions(envRestrictions.getOne(), envRestrictions.getTwo()));
    }

    Twin<MutableSet<String>> platformRestrictions = readRestrictions(section, TextMarkupDocumentReader.INCLUDE_PLATFORMS, TextMarkupDocumentReader.EXCLUDE_PLATFORMS);
    if (platformRestrictions != null) {
        restrictions.add(new ArtifactPlatformRestrictions(platformRestrictions.getOne(), platformRestrictions.getTwo()));
    }

    return restrictions.toImmutable();
}
 
Example 3
Source File: PostgreSqlDbPlatform.java    From obevo with Apache License 2.0 6 votes vote down vote up
@Override
protected ImmutableList<ChangeType> initializeChangeTypes() {
    MutableList<ChangeType> changeTypes = super.initializeChangeTypes().toList();

    DbChangeType sequenceType = getChangeType(changeTypes, ChangeType.SEQUENCE_STR);
    sequenceType = DbChangeTypeImpl.newDbChangeType(sequenceType).setGrantObjectQualifier("SEQUENCE").build();
    replaceChangeType(changeTypes, sequenceType);

    DbChangeType functionType = getChangeType(changeTypes, ChangeType.FUNCTION_STR);
    functionType = DbChangeTypeImpl.newDbChangeType(functionType).setGrantObjectQualifier("FUNCTION").build();
    replaceChangeType(changeTypes, functionType);

    DbChangeType typeType = DbChangeTypeImpl.newDbChangeType(ChangeType.USERTYPE_STR, true, 1, "TYPE").build();
    changeTypes.add(typeType);

    return changeTypes.toImmutable();
}
 
Example 4
Source File: DAStringUtil.java    From obevo with Apache License 2.0 6 votes vote down vote up
/**
 * See {@link #normalizeWhiteSpaceFromString(String)}. This is the "old" version of that method, with a slightly
 * harder-to-read implementation. I want to switch to {@link #normalizeWhiteSpaceFromString(String)} as it is
 * a more standard implementation and thus easier to vet.
 */
public static String normalizeWhiteSpaceFromStringOld(String content) {
    if (content == null) {
        return null;
    }
    String[] lines = content.split("\\r?\\n");

    MutableList<String> newContent = Lists.mutable.empty();
    for (String line : lines) {
        line = line.trim();
        if (!line.isEmpty()) {
            line = line.replaceAll("\\s+", " ");
            newContent.add(line.trim());
        }
    }

    return newContent.makeString(" ").trim();
}
 
Example 5
Source File: DbDataComparisonUtil.java    From obevo with Apache License 2.0 6 votes vote down vote up
private static MutableList<String> getKeyCols(DaTable tableInfo) {
    MutableList<String> keyCols = Lists.mutable.empty();
    DaIndex pk = tableInfo.getPrimaryKey();
    for (DaIndex index : tableInfo.getIndices()) {
        if (index.isUnique()) {
            pk = index;
            break;
        }
    }
    if (pk != null) {
        for (DaColumn col : pk.getColumns()) {
            keyCols.add(col.getName());
        }
    }
    return keyCols;
}
 
Example 6
Source File: BaselineTableChangeParser.java    From obevo with Apache License 2.0 6 votes vote down vote up
private MutableList<String> sortSqls(MutableList<String> sqls) {
    MutableList<String> orderedSqls = Lists.mutable.empty();
    MutableList<String> fkSqls = Lists.mutable.empty();
    MutableList<String> triggerSqls = Lists.mutable.empty();

    for (String sql : sqls) {
        Matcher matcher = RegexpPatterns.fkPattern.matcher(sql);
        Matcher triggerMatcher = RegexpPatterns.triggerPattern.matcher(sql);
        if (matcher.find()) {
            fkSqls.add(sql);
        } else if (triggerMatcher.find()) {
            triggerSqls.add(sql);
        } else {
            orderedSqls.add(sql);
        }
    }

    orderedSqls.addAll(fkSqls);
    orderedSqls.addAll(triggerSqls);
    return orderedSqls;
}
 
Example 7
Source File: OfficialLeelazAnalyzerV1.java    From mylizzie with GNU General Public License v3.0 5 votes vote down vote up
boolean pushToList(String listKey, String value) {
    MutableMap<String, Object> valueMap = (MutableMap<String, Object>) peek();
    MutableList<String> list = (MutableList<String>) valueMap.get(listKey);
    list.add(value);

    return true;
}
 
Example 8
Source File: DbChecksumCalculator.java    From obevo with Apache License 2.0 5 votes vote down vote up
private ImmutableCollection<ChecksumEntry> getTableChecksums(DaTable table) {
    MutableList<ChecksumEntry> checksums = Lists.mutable.empty();

    String pkContent = table.getPrimaryKey() != null ? table.getPrimaryKey().toString() : "";
    ChecksumEntry tableChecksum = ChecksumEntry.createFromText(table.getSchema().toPhysicalSchema(), ChangeType.TABLE_STR, table.getName(), "primaryKey", pkContent);
    checksums.add(tableChecksum);

    for (DaColumn column : table.getColumns()) {
        checksums.add(getColumnChecksum(table, column));
    }

    return checksums.toImmutable();
}
 
Example 9
Source File: OfficialLeelazAnalyzerV2.java    From mylizzie with GNU General Public License v3.0 5 votes vote down vote up
boolean pushToList(String listKey, String value) {
    MutableMap<String, Object> valueMap = (MutableMap<String, Object>) peek();
    MutableList<String> list = (MutableList<String>) valueMap.get(listKey);
    list.add(value);

    return true;
}
 
Example 10
Source File: FastListMultimap2.java    From alibaba-rsocket-broker with Apache License 2.0 5 votes vote down vote up
public boolean keepOnlyOne(K key, V value) {
    MutableList<V> collection = this.map.get(key);
    if (collection == null) {
        return false;
    }
    int originSize = collection.size();
    collection.removeIf(Predicate.isEqual(value));
    collection.add(value);
    this.totalSize = this.totalSize - (originSize - collection.size());
    return true;
}
 
Example 11
Source File: CollectionUtil.java    From obevo with Apache License 2.0 5 votes vote down vote up
public static <T> ImmutableList<T> iteratorToList(Iterator<T> iterator) {
    MutableList<T> list = Lists.mutable.empty();
    while (iterator.hasNext()) {
        list.add(iterator.next());
    }
    return list.toImmutable();
}
 
Example 12
Source File: SybaseAseMetadataDialect.java    From obevo with Apache License 2.0 5 votes vote down vote up
@Override
public ImmutableCollection<RuleBinding> getRuleBindings(DaSchema schema, Connection conn) {
    String schemaName = schema.getName();
    // return the bindings to columns and bindings to domains
    String sql = "select tab.name 'object', rul.name 'rule', " +
            "'sp_bindrule ' || rul.name || ', ''' || tab.name || '.' || col.name || '''' 'sql'\n" +
            "from " + schemaName + "..syscolumns col, " + schemaName + "..sysobjects rul, " + schemaName + "..sysobjects tab\n" +
            "    , " + schemaName + "..sysusers sch\n" +
            "where col.domain = rul.id and col.id = tab.id and tab.type='U' and col.domain <> 0\n" +
            "    and tab.uid = sch.uid and sch.name = '" + schema.getSubschemaName() + "'\n" +
            "union\n" +
            "select obj.name 'object', rul.name 'rule', " +
            "'sp_bindrule ' || rul.name || ', ' || obj.name 'sql'\n" +
            "from " + schemaName + "..systypes obj, " + schemaName + "..sysobjects rul\n" +
            "    , " + schemaName + "..sysusers sch\n" +
            "where obj.domain = rul.id and obj.domain <> 0\n" +
            "    and obj.uid = sch.uid and sch.name = '" + schema.getSubschemaName() + "'\n";
    PreparedStatement ps = null;
    ResultSet rs = null;
    try {
        ps = conn.prepareStatement(sql);
        rs = ps.executeQuery();

        MutableList<RuleBinding> ruleBindings = Lists.mutable.empty();
        while (rs.next()) {
            RuleBindingImpl ruleBinding = new RuleBindingImpl();
            ruleBinding.setObject(rs.getString("object"));
            ruleBinding.setRule(rs.getString("rule"));
            ruleBinding.setSql(rs.getString("sql"));
            ruleBindings.add(ruleBinding);
        }
        return ruleBindings.toImmutable();
    } catch (SQLException e) {
        throw new RuntimeException(e);
    } finally {
        DbUtils.closeQuietly(rs);
        DbUtils.closeQuietly(ps);
    }
}
 
Example 13
Source File: TextMarkupParser.java    From obevo with Apache License 2.0 5 votes vote down vote up
public static List<Token> parseTokens(String line) {
    TextMarkupLineSyntaxParser parser = new TextMarkupLineSyntaxParser(new StringReader(line));

    MutableList<Token> tokens = Lists.mutable.empty();
    for (Token token = parser.getNextToken(); token.kind != TextMarkupLineSyntaxParserConstants.EOF; token = parser.getNextToken()) {
        tokens.add(token);
    }
    return tokens;
}
 
Example 14
Source File: IqLoadFileCreatorTest.java    From obevo with Apache License 2.0 5 votes vote down vote up
@Test
public void testLoadWithoutDefault() throws Exception {
    StringBuilder sb = new StringBuilder();
    sb.append("DROP TABLE IF EXISTS " + tableName + ";");
    sb.append("CREATE TABLE " + tableName + " (");
    sb.append("intfield integer null,");
    sb.append("stringfield varchar(200) null,");
    sb.append("cm_id bigint not null,");
    sb.append("datefieldjoda date not null,");
    sb.append("datefieldjdk date not null,");
    sb.append("timestampfieldjoda timestamp not null,");
    sb.append("timestampfieldjdk timestamp not null,");
    sb.append("PRIMARY KEY (CM_ID),");
    sb.append(");");
    if (grantEnabled) {
        sb.append("GRANT SELECT ON " + tableName + " TO dbdeploy_ro;");
    }

    MutableList<FieldToColumnMapping> mappings = Lists.mutable.empty();
    mappings.add(new FieldToColumnMapping("myCmId", "CM_ID"));
    mappings.add(new FieldToColumnMapping("myString", "stringfield"));
    mappings.add(new FieldToColumnMapping("myInt", "intfield"));
    mappings.add(new FieldToColumnMapping("dateFieldJoda", "datefieldjoda"));
    mappings.add(new FieldToColumnMapping("timestampFieldJoda", "timestampfieldjoda"));
    mappings.add(new FieldToColumnMapping("dateFieldJdk", "datefieldjdk"));
    mappings.add(new FieldToColumnMapping("timestampFieldJdk", "timestampfieldjdk"));

    this.testLoad(sb.toString(), mappings, "\n", "~"); // single-char
    this.testLoad(sb.toString(), mappings, "\n", "!~!~"); // multi-char
    this.testLoad(sb.toString(), mappings, "####", "~"); // single-char,
    // non-line-break del
    this.testLoad(sb.toString(), mappings, "####", "!~!~"); // multi-char,
    // non-line-break del
}
 
Example 15
Source File: IqLoadFileCreatorTest.java    From obevo with Apache License 2.0 5 votes vote down vote up
@Test
public void testLoadWithDefault() throws Exception {
    StringBuilder sb = new StringBuilder();
    sb.append("DROP TABLE IF EXISTS " + tableName + ";");
    sb.append("CREATE TABLE " + tableName + " (");
    sb.append("intfield integer null,");
    sb.append("default_value_col timestamp not null,");
    sb.append("stringfield varchar(200) null,");
    sb.append("cm_id bigint not null,");
    sb.append("datefieldjoda date not null,");
    sb.append("datefieldjdk date not null,");
    sb.append("timestampfieldjoda timestamp not null,");
    sb.append("timestampfieldjdk timestamp not null,");
    sb.append("PRIMARY KEY (CM_ID),");
    sb.append(");");
    if (grantEnabled) {
        sb.append("GRANT SELECT ON " + tableName + " TO dbdeploy_ro;");
    }

    MutableList<FieldToColumnMapping> mappings = Lists.mutable.empty();
    mappings.add(new FieldToColumnMapping("myCmId", "CM_ID"));
    mappings.add(new FieldToColumnMapping("myString", "stringfield"));
    mappings.add(new FieldToColumnMapping("myInt", "intfield"));
    mappings.add(new FieldToColumnMapping("dateFieldJoda", "datefieldjoda"));
    mappings.add(FieldToColumnMapping.createWithDefaultValue("default_value_col", new LocalDateTime(
            "2011-12-01T05:00:00")));
    mappings.add(new FieldToColumnMapping("timestampFieldJoda", "timestampfieldjoda"));
    mappings.add(new FieldToColumnMapping("dateFieldJdk", "datefieldjdk"));
    mappings.add(new FieldToColumnMapping("timestampFieldJdk", "timestampfieldjdk"));

    this.testLoad(sb.toString(), mappings, "\n", "~"); // single-char
    this.testLoad(sb.toString(), mappings, "\n", "!~!~"); // multi-char
    this.testLoad(sb.toString(), mappings, "####", "~"); // single-char,
    // non-line-break del
    this.testLoad(sb.toString(), mappings, "####", "!~!~"); // multi-char,
    // non-line-break del
}
 
Example 16
Source File: MultiThreadedTx.java    From reladomo with Apache License 2.0 5 votes vote down vote up
@Override
public void prepare(MultiThreadedTx tx) throws SystemException
{
    MutableList<Future<Integer>> futures = FastList.newList(tx.resourceManagers.size());
    int i = -1;
    try
    {
        for(i = 1; i < tx.resourceManagers.size();i++)
        {
            TxGroup branch = tx.resourceManagers.get(i);
            futures.add(branch.prepare());
        }
        int offset = 1;
        for(i = 0; i < futures.size();i++)
        {
            Future<Integer> result = futures.get(i);
            int prepareState = result.get();
            if (prepareState == XAResource.XA_RDONLY)
            {
                tx.resourceManagers.remove(i + offset);
                offset--;
            }
        }
        tx.status.set(COMMITTING);
    }
    catch (Throwable e)
    {
        logger.error("Error preparing. Rolling back instead", e);
        tx.resourceManagers.remove(i); // resource threw an exception and is presumed rolled back
        tx.rollbackCause = e;
        tx.status.set(ROLLING_BACK);
    }
}
 
Example 17
Source File: FastListMultimap2.java    From alibaba-rsocket-broker with Apache License 2.0 5 votes vote down vote up
public boolean putMultiCopies(K key, V value, int count) {
    MutableList<V> collection = this.map.getIfAbsentPutWith(key, this.createCollectionBlock(), this);
    for (int i = 0; i < count; i++) {
        collection.add(value);
    }
    this.totalSize = this.totalSize + count;
    return true;
}
 
Example 18
Source File: TextMarkupDocumentReaderOld.java    From obevo with Apache License 2.0 4 votes vote down vote up
private ImmutableList<TextMarkupDocumentSection> parseString(String text, MutableList<String> elementsToCheck, boolean recurse,
        String elementPrefix) {
    MutableList<TextMarkupDocumentSection> sections = Lists.mutable.empty();
    while (true) {
        int earliestIndex = Integer.MAX_VALUE;

        for (String firstLevelElement : elementsToCheck) {
            int index = text.indexOf(elementPrefix + " " + firstLevelElement, 1);
            if (index != -1 && index < earliestIndex) {
                earliestIndex = index;
            }
        }

        if (earliestIndex == Integer.MAX_VALUE) {
            sections.add(new TextMarkupDocumentSection(null, text));
            break;
        } else {
            sections.add(new TextMarkupDocumentSection(null, text.substring(0, earliestIndex)));
            text = text.substring(earliestIndex);
        }
    }
    for (TextMarkupDocumentSection section : sections) {
        MutableMap<String, String> attrs = Maps.mutable.empty();
        MutableSet<String> toggles = Sets.mutable.empty();
        String content = StringUtils.chomp(section.getContent());

        String[] contents = content.split("\\r?\\n", 2);
        String firstLine = contents[0];

        for (String elementToCheck : elementsToCheck) {
            if (firstLine.startsWith(elementPrefix + " " + elementToCheck)) {
                section.setName(elementToCheck);
                String[] args = StringUtils.splitByWholeSeparator(firstLine, " ");
                for (String arg : args) {
                    if (arg.contains("=")) {
                        String[] attr = arg.split("=");
                        if (attr.length > 2) {
                            throw new IllegalArgumentException("Cannot mark = multiple times in a parameter - "
                                    + firstLine);
                        }
                        String attrVal = attr[1];
                        if (attrVal.startsWith("\"") && attrVal.endsWith("\"")) {
                            attrVal = attrVal.substring(1, attrVal.length() - 1);
                        }
                        attrs.put(attr[0], attrVal);
                    } else {
                        toggles.add(arg);
                    }
                }
                if (contents.length > 1) {
                    content = contents[1];
                } else {
                    content = null;
                }
            }
        }
        section.setAttrs(attrs.toImmutable());
        section.setToggles(toggles.toImmutable());

        if (!recurse) {
            section.setContent(content);
        } else if (content != null) {
            ImmutableList<TextMarkupDocumentSection> subsections = this.parseString(content, this.secondLevelElements, false, "//");
            if (subsections.size() == 1) {
                section.setContent(content);
            } else {
                section.setContent(subsections.get(0).getContent());
                section.setSubsections(subsections.subList(1, subsections.size()));
            }
        } else {
            section.setContent(null);
        }
    }

    return sections.toImmutable();
}
 
Example 19
Source File: SqlTokenParser.java    From obevo with Apache License 2.0 4 votes vote down vote up
public MutableList<SqlToken> parseTokens(String str) {
    str += "\n";  // to handle case where last line entry is // ending comment
    MutableList<SqlToken> tokens = Lists.mutable.empty();

    SqlTokenParserImpl parser = new SqlTokenParserImpl(new StringReader(str));

    boolean inToken = false;
    List<String> queuedTokens = new ArrayList<String>();
    for (Token token = parser.getNextToken(); token.kind != SqlTokenParserImplConstants.EOF;
         token = parser.getNextToken()) {

        SqlTokenType tokenType;
        switch (token.kind) {
        case SqlTokenParserImplConstants.OTHER:
            inToken = true;
            queuedTokens.add(token.image);
            break;
        case SqlTokenParserImplConstants.DOUBLE_QUOTE_STRING:
        case SqlTokenParserImplConstants.SINGLE_QUOTE_STRING:
            tokenType = SqlTokenType.STRING;
            this.processToken(inToken, queuedTokens, tokens, tokenType, token);
            inToken = false;
            break;
        case SqlTokenParserImplConstants.WHITESPACE:
            tokenType = SqlTokenType.WHITESPACE;
            this.processToken(inToken, queuedTokens, tokens, tokenType, token);
            inToken = false;
            break;
        case SqlTokenParserImplConstants.SINGLE_LINE_COMMENT1:
        case SqlTokenParserImplConstants.SINGLE_LINE_COMMENT2:
        case SqlTokenParserImplConstants.MULTI_LINE_COMMENT:
            tokenType = SqlTokenType.COMMENT;
            this.processToken(inToken, queuedTokens, tokens, tokenType, token);
            inToken = false;
            break;
        default:
            throw new IllegalArgumentException("Not expecting this token type: " + token.kind);
        }
    }

    if (inToken) {
        String queuedTokenStr = StringUtils.join(queuedTokens, "");
        queuedTokens.clear();
        tokens.add(new SqlToken(SqlTokenType.TOKEN, queuedTokenStr));
    }

    if (!tokens.isEmpty()) {
        int lastIndex = tokens.size() - 1;
        SqlToken lastToken = tokens.get(lastIndex);
        String lastText = lastToken.getText();
        if (!lastText.isEmpty() && lastText.charAt(lastText.length() - 1) == '\n') {
            lastText = lastText.substring(0, lastText.length() - 1);
            if (lastText.isEmpty()) {
                tokens.remove(lastIndex);
            } else {
                tokens.set(lastIndex, new SqlToken(lastToken.getTokenType(), lastText));
            }
        }
    }
    return tokens;
}
 
Example 20
Source File: MultiLineStringSplitter.java    From obevo with Apache License 2.0 4 votes vote down vote up
@Override
public MutableList<String> valueOf(String inputString) {
    inputString += "\n";  // add sentinel to facilitate line split

    MutableList<SqlToken> sqlTokens = this.tokenParser.parseTokens(inputString);
    sqlTokens = this.collapseWhiteSpaceAndTokens(sqlTokens);

    MutableList<String> finalSplitStrings = Lists.mutable.empty();
    String currentSql = "";

    for (SqlToken sqlToken : sqlTokens) {
        if (sqlToken.getTokenType() == SqlTokenType.COMMENT || sqlToken.getTokenType() == SqlTokenType.STRING) {
            currentSql += sqlToken.getText();
        } else {
            String pattern = splitOnWholeLine ? "(?i)^" + this.splitToken + "$" : this.splitToken;
            MutableList<String> splitStrings =
                    Lists.mutable.with(Pattern.compile(pattern, Pattern.MULTILINE).split(sqlToken.getText()));
            if (splitStrings.isEmpty()) {
                // means that we exactly match
                finalSplitStrings.add(currentSql);
                currentSql = "";
            } else if (splitStrings.size() == 1) {
                currentSql += sqlToken.getText();
            } else {
                splitStrings.set(0, currentSql + splitStrings.get(0));

                if (splitOnWholeLine) {
                    if (splitStrings.size() > 1) {
                        splitStrings.set(0, StringUtils.chomp(splitStrings.get(0)));
                        for (int i = 1; i < splitStrings.size(); i++) {
                            String newSql = splitStrings.get(i);
                            if (newSql.startsWith("\n")) {
                                newSql = newSql.replaceFirst("^\n", "");
                            } else if (newSql.startsWith("\r\n")) {
                                newSql = newSql.replaceFirst("^\r\n", "");
                            }

                            // Chomping the end of each sql due to the split of the GO statement
                            if (i < splitStrings.size() - 1) {
                                newSql = StringUtils.chomp(newSql);
                            }
                            splitStrings.set(i, newSql);
                        }
                    }
                }

                finalSplitStrings.addAll(splitStrings.subList(0, splitStrings.size() - 1));
                currentSql = splitStrings.getLast();
            }
        }
    }

    if (!currentSql.isEmpty()) {
        finalSplitStrings.add(currentSql);
    }

    // accounting for the sentinel
    if (finalSplitStrings.getLast().isEmpty()) {
        finalSplitStrings.remove(finalSplitStrings.size() - 1);
    } else {
        finalSplitStrings.set(finalSplitStrings.size() - 1, StringUtils.chomp(finalSplitStrings.getLast()));
    }

    return finalSplitStrings;
}