Java Code Examples for org.eclipse.collections.api.map.MutableMap#put()

The following examples show how to use org.eclipse.collections.api.map.MutableMap#put() . 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: OptionDialog.java    From mylizzie with GNU General Public License v3.0 6 votes vote down vote up
private void initOtherComponents() {
    getRootPane().registerKeyboardAction(e -> setVisible(false),
            KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0),
            JComponent.WHEN_IN_FOCUSED_WINDOW);

    getRootPane().registerKeyboardAction(e -> doApplySettings(),
            KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0),
            JComponent.WHEN_IN_FOCUSED_WINDOW);

    MutableMap<OptionSetting.BoardSize, JRadioButton> m = Maps.mutable.empty();
    m.put(new OptionSetting.BoardSize(19, 19), radioButtonBoard19x19);
    m.put(new OptionSetting.BoardSize(15, 15), radioButtonBoard15x15);
    m.put(new OptionSetting.BoardSize(13, 13), radioButtonBoard13x13);
    m.put(new OptionSetting.BoardSize(9, 9), radioButtonBoard9x9);
    m.put(new OptionSetting.BoardSize(7, 7), radioButtonBoard7x7);
    m.put(new OptionSetting.BoardSize(5, 5), radioButtonBoard5x5);

    boardSizeToRadioButtonMap = m.toImmutable();
}
 
Example 2
Source File: PrepareDbChangeForDb.java    From obevo with Apache License 2.0 6 votes vote down vote up
@Override
public String prepare(String content, ChangeInput change, DbEnvironment env) {
    MutableMap<String, String> tokens = Maps.mutable.<String, String>empty()
            .withKeyValue("dbSchemaSuffix", env.getDbSchemaSuffix())
            .withKeyValue("dbSchemaPrefix", env.getDbSchemaPrefix());

    for (Schema schema : env.getSchemas()) {
        PhysicalSchema physicalSchema = env.getPhysicalSchema(schema.getName());
        tokens.put(schema.getName() + "_physicalName", physicalSchema.getPhysicalName());
        if (env.getPlatform() != null) {
            tokens.put(schema.getName() + "_schemaSuffixed", env.getPlatform().getSchemaPrefix(physicalSchema));
            tokens.put(schema.getName() + "_subschemaSuffixed", env.getPlatform().getSubschemaPrefix(physicalSchema));
        }
    }

    if (env.getDefaultTablespace() != null) {
        tokens.put("defaultTablespace", env.getDefaultTablespace());
    }

    tokens.putAll(env.getTokens().castToMap());  // allow clients to override these values if needed

    return new Tokenizer(tokens, env.getTokenPrefix(), env.getTokenSuffix()).tokenizeString(content);
}
 
Example 3
Source File: AquaRevengMain.java    From obevo with Apache License 2.0 6 votes vote down vote up
private ImmutableMap<ChangeType, Pattern> initPatternMap(Platform platform) {
    MutableMap<String, Pattern> params = Maps.mutable.<String, Pattern>with()
            .withKeyValue(ChangeType.SP_STR, Pattern.compile("(?i)create\\s+proc(?:edure)?\\s+(\\w+)", Pattern.DOTALL))
            .withKeyValue(ChangeType.FUNCTION_STR, Pattern.compile("(?i)create\\s+func(?:tion)?\\s+(\\w+)", Pattern.DOTALL))
            .withKeyValue(ChangeType.VIEW_STR, Pattern.compile("(?i)create\\s+view\\s+(\\w+)", Pattern.DOTALL))
            .withKeyValue(ChangeType.SEQUENCE_STR, Pattern.compile("(?i)create\\s+seq(?:uence)?\\s+(\\w+)", Pattern.DOTALL))
            .withKeyValue(ChangeType.TABLE_STR, Pattern.compile("(?i)create\\s+table\\s+(\\w+)", Pattern.DOTALL))
            .withKeyValue(ChangeType.DEFAULT_STR, Pattern.compile("(?i)create\\s+default\\s+(\\w+)", Pattern.DOTALL))
            .withKeyValue(ChangeType.RULE_STR, Pattern.compile("(?i)create\\s+rule\\s+(\\w+)", Pattern.DOTALL))
            .withKeyValue(ChangeType.USERTYPE_STR, Pattern.compile("(?i)^\\s*sp_addtype\\s+", Pattern.DOTALL))
            .withKeyValue(ChangeType.INDEX_STR, Pattern.compile("(?i)create\\s+(?:unique\\s+)?(?:\\w+\\s+)?index\\s+\\w+\\s+on\\s+(\\w+)", Pattern.DOTALL));

    MutableMap<ChangeType, Pattern> patternMap = Maps.mutable.<ChangeType, Pattern>with();
    for (String changeTypeName : params.keysView()) {
        if (platform.hasChangeType(changeTypeName)) {
            ChangeType changeType = platform.getChangeType(changeTypeName);
            patternMap.put(changeType, params.get(changeTypeName));
        }
    }

    return patternMap.toImmutable();
}
 
Example 4
Source File: IqDataSource.java    From obevo with Apache License 2.0 6 votes vote down vote up
public IqDataSource(DbEnvironment env, Credential userCredential, int numThreads, IqDataSourceFactory subDataSourceFactory) {
    this.env = env;
    this.subDataSourceFactory = subDataSourceFactory;

    MutableMap<PhysicalSchema, DataSource> dsMap = Maps.mutable.empty();
    for (PhysicalSchema physicalSchema : env.getPhysicalSchemas()) {
        String schema = physicalSchema.getPhysicalName();
        LOG.info("Creating datasource against schema {}", schema);
        DataSource ds = subDataSourceFactory.createDataSource(env,
                userCredential,
                schema,
                numThreads
        );

        dsMap.put(physicalSchema, ds);
    }

    this.dsMap = dsMap.toImmutable();
    this.setCurrentSchema(this.env.getPhysicalSchemas().getFirst());  // set one arbitrarily as the default
}
 
Example 5
Source File: SchemaGenerator.java    From obevo with Apache License 2.0 6 votes vote down vote up
private void generate(String schema) {
    MutableSet<MyInput> inputs = Sets.mutable.empty();

    inputs.withAll(getUserTypes(numTypes));
    inputs.withAll(getTables());
    inputs.withAll(getViews());
    inputs.withAll(getSps());

    MutableSet<String> types = Sets.mutable.of("table", "view", "sp", "usertype");
    File outputDir = new File("./target/testoutput");
    FileUtils.deleteQuietly(outputDir);
    outputDir.mkdirs();
    for (MyInput input : inputs) {
        MutableMap<String, Object> params = Maps.mutable.<String, Object>empty().withKeyValue(
                "name", input.getName()
        );
        for (String type : types) {
            params.put("dependent" + type + "s", input.getDependenciesByType().get(type));
        }

        File outputFile = new File(outputDir, schema + "/" + input.getType() + "/" + input.getName() + ".sql");
        outputFile.getParentFile().mkdirs();
        TestTemplateUtil.getInstance().writeTemplate("schemagen/" + input.getType() + ".sql.ftl", params, outputFile);
    }
}
 
Example 6
Source File: PlatformConfiguration.java    From obevo with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the default name-to-platform mappings. We put this in a separate protected method to allow external
 * distributions to override these values as needed.
 */
private ImmutableMap<String, ImmutableHierarchicalConfiguration> getDbPlatformMap() {
    final String platformKey = "db.platforms";

    ListIterable<ImmutableHierarchicalConfiguration> platformConfigs = ListAdapter.adapt(config.immutableChildConfigurationsAt("db.platforms"));

    MutableMap<String, ImmutableHierarchicalConfiguration> platformByName = Maps.mutable.empty();

    for (ImmutableHierarchicalConfiguration platformConfig : platformConfigs) {
        String platformName = platformConfig.getRootElementName();
        String platformClass = platformConfig.getString("class");
        if (platformClass == null) {
            LOG.warn("Improper platform config under {} for platform {}: missing class property. Will skip", platformKey, platformName);
        } else {
            platformByName.put(platformName, platformConfig);
            LOG.debug("Registering platform {} at class {}", platformName, platformClass);
        }
    }

    return platformByName.toImmutable();
}
 
Example 7
Source File: PackageMetadataReader.java    From obevo with Apache License 2.0 5 votes vote down vote up
private ImmutableMap<String, String> getSourceEncodings(ImmutableHierarchicalConfiguration metadataConfig) {
    MutableList<ImmutableHierarchicalConfiguration> encodingConfigs = ListAdapter.adapt(metadataConfig.immutableChildConfigurationsAt("sourceEncodings"));
    MutableMap<String, String> encodingsMap = Maps.mutable.empty();

    for (ImmutableHierarchicalConfiguration encodingConfig : encodingConfigs) {
        String fileList = encodingConfig.getString("");
        for (String file : fileList.split(",")) {
            encodingsMap.put(file, encodingConfig.getRootElementName());
        }
    }

    return encodingsMap.toImmutable();
}
 
Example 8
Source File: PhoenixGoAnalyzer.java    From mylizzie with GNU General Public License v3.0 4 votes vote down vote up
boolean saveAttrToValueMap(String key, Object value) {
    MutableMap<String, Object> valueMap = (MutableMap<String, Object>) peek();
    valueMap.put(key, value);

    return true;
}
 
Example 9
Source File: OfficialLeelazAnalyzerV2.java    From mylizzie with GNU General Public License v3.0 4 votes vote down vote up
boolean saveAttrToValueMap(String key, Object value) {
    MutableMap<String, Object> valueMap = (MutableMap<String, Object>) peek();
    valueMap.put(key, value);

    return true;
}
 
Example 10
Source File: OfficialLeelazAnalyzerV1.java    From mylizzie with GNU General Public License v3.0 4 votes vote down vote up
boolean saveAttrToValueMap(String key, Object value) {
    MutableMap<String, Object> valueMap = (MutableMap<String, Object>) peek();
    valueMap.put(key, value);

    return true;
}
 
Example 11
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 12
Source File: TextMarkupDocumentReader.java    From obevo with Apache License 2.0 4 votes vote down vote up
Pair<ImmutableMap<String, String>, ImmutableSet<String>> parseAttrsAndToggles(String line) {
    MutableMap<String, String> attrs = Maps.mutable.empty();
    MutableSet<String> toggles = Sets.mutable.empty();

    if (!legacyMode) {
        List<Token> tokens = TextMarkupParser.parseTokens(line);
        Token curToken = !tokens.isEmpty() ? tokens.get(0) : null;
        while (curToken != null && curToken.kind != TextMarkupLineSyntaxParserConstants.EOF) {
            switch (curToken.kind) {
            case TextMarkupLineSyntaxParserConstants.WHITESPACE:
                // skip whitespace if encountered
                break;
            case TextMarkupLineSyntaxParserConstants.QUOTED_LITERAL:
            case TextMarkupLineSyntaxParserConstants.STRING_LITERAL:
                // let's check if this is a toggle or an attribute
                if (curToken.next.kind == TextMarkupLineSyntaxParserConstants.ASSIGN) {
                    Token keyToken = curToken;
                    curToken = curToken.next;  // to ASSIGN
                    curToken = curToken.next;  // to the following token
                    switch (curToken.kind) {
                    case TextMarkupLineSyntaxParserConstants.QUOTED_LITERAL:
                    case TextMarkupLineSyntaxParserConstants.STRING_LITERAL:
                        // in this case, we have an attribute value
                        String value = curToken.image;
                        if (value.charAt(0) == '"' && value.charAt(value.length() - 1) == '"') {
                            value = curToken.image.substring(1, curToken.image.length() - 1);
                        }
                        value = value.replaceAll("\\\\\"", "\"");
                        attrs.put(keyToken.image, value);
                        break;
                    case TextMarkupLineSyntaxParserConstants.WHITESPACE:
                    case TextMarkupLineSyntaxParserConstants.EOF:
                        // in this case, we will assume a blank value
                        attrs.put(keyToken.image, "");
                        break;
                    case TextMarkupLineSyntaxParserConstants.ASSIGN:
                    default:
                        throw new IllegalStateException("Not allowed here");
                    }
                } else {
                    toggles.add(curToken.image);
                }
                break;
            case TextMarkupLineSyntaxParserConstants.ASSIGN:
                toggles.add(curToken.image);
                break;
            case TextMarkupLineSyntaxParserConstants.EOF:
            default:
                throw new IllegalStateException("Should not arise");
            }

            curToken = curToken.next;
        }
    } else {
        // keeping this mode for backwards-compatibility until we can guarantee all clients are fine without it
        // This way cannot handle spaces in quotes
        String[] args = StringUtils.splitByWholeSeparator(line, " ");

        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 - " + line);
                }
                String attrVal = attr[1];
                if (attrVal.startsWith("\"") && attrVal.endsWith("\"")) {
                    attrVal = attrVal.substring(1, attrVal.length() - 1);
                }
                attrs.put(attr[0], attrVal);
            } else if (StringUtils.isNotBlank(arg)) {
                toggles.add(arg);
            }
        }
    }

    return Tuples.pair(attrs.toImmutable(), toggles.toImmutable());
}
 
Example 13
Source File: AbstractReveng.java    From obevo with Apache License 2.0 4 votes vote down vote up
private MutableList<ChangeEntry> revengFile(SchemaObjectReplacer schemaObjectReplacer, List<Pair<String, RevengPatternOutput>> snippetPatternMatchPairs, String inputSchema, boolean debugLogEnabled) {
    final MutableList<ChangeEntry> changeEntries = Lists.mutable.empty();

    MutableMap<String, AtomicInteger> countByObject = Maps.mutable.empty();

    int selfOrder = 0;
    String candidateObject = "UNKNOWN";
    ChangeType candidateObjectType = UnclassifiedChangeType.INSTANCE;
    for (Pair<String, RevengPatternOutput> snippetPatternMatchPair : snippetPatternMatchPairs) {
        String sqlSnippet = snippetPatternMatchPair.getOne();
        try {
            sqlSnippet = removeQuotesFromProcxmode(sqlSnippet);  // sybase ASE

            MutableMap<String, Object> debugComments = Maps.mutable.empty();

            RevengPattern chosenRevengPattern = null;
            String secondaryName = null;
            final RevengPatternOutput patternMatch = snippetPatternMatchPair.getTwo();

            debugComments.put("newPatternMatch", patternMatch != null);

            if (patternMatch != null) {
                chosenRevengPattern = patternMatch.getRevengPattern();

                if (chosenRevengPattern.isShouldBeIgnored()) {
                    continue;
                }

                debugComments.put("objectType", patternMatch.getRevengPattern().getChangeType());
                // we add this here to allow post-processing to occur on RevengPatterns but still not define the object to write to
                if (patternMatch.getRevengPattern().getChangeType() != null) {
                    candidateObject = patternMatch.getPrimaryName();
                    debugComments.put("originalObjectName", candidateObject);
                    candidateObject = chosenRevengPattern.remapObjectName(candidateObject);

                    debugComments.put("secondaryName", patternMatch.getSecondaryName());
                    if (patternMatch.getSecondaryName() != null) {
                        secondaryName = patternMatch.getSecondaryName();
                    }
                    if (patternMatch.getRevengPattern().getChangeType().equalsIgnoreCase(UnclassifiedChangeType.INSTANCE.getName())) {
                        candidateObjectType = UnclassifiedChangeType.INSTANCE;
                    } else {
                        candidateObjectType = platform.getChangeType(patternMatch.getRevengPattern().getChangeType());
                    }
                }
            }

            // Ignore other schemas that may have been found in your parsing (came up during HSQLDB use case)

            sqlSnippet = schemaObjectReplacer.replaceSnippet(sqlSnippet);

            AtomicInteger objectOrder2 = countByObject.getIfAbsentPut(candidateObject, new Function0<AtomicInteger>() {
                @Override
                public AtomicInteger value() {
                    return new AtomicInteger(0);
                }
            });

            if (secondaryName == null) {
                secondaryName = "change" + objectOrder2.getAndIncrement();
            }

            RevEngDestination destination = new RevEngDestination(inputSchema, candidateObjectType, candidateObject, false, Optional.ofNullable(chosenRevengPattern).map(RevengPattern::isKeepLastOnly).orElse(false));

            String annotation = chosenRevengPattern != null ? chosenRevengPattern.getAnnotation() : null;
            MutableList<Function<String, LineParseOutput>> postProcessSqls = chosenRevengPattern != null ? chosenRevengPattern.getPostProcessSqls() : Lists.mutable.<Function<String, LineParseOutput>>empty();

            for (Function<String, LineParseOutput> postProcessSql : postProcessSqls) {
                LineParseOutput lineParseOutput = postProcessSql.valueOf(sqlSnippet);
                sqlSnippet = lineParseOutput.getLineOutput();
            }

            Integer suggestedOrder = patternMatch != null ? patternMatch.getRevengPattern().getSuggestedOrder() : null;

            if (debugLogEnabled && debugComments.notEmpty()) {
                String debugCommentsStr = debugComments.keyValuesView().collect(new Function<Pair<String, Object>, String>() {
                    @Override
                    public String valueOf(Pair<String, Object> object) {
                        return object.getOne() + "=" + object.getTwo();
                    }
                }).makeString("; ");
                sqlSnippet = "-- DEBUG COMMENT: " + debugCommentsStr + "\n" + sqlSnippet;
            }
            ChangeEntry change = new ChangeEntry(destination, sqlSnippet + "\nGO", secondaryName, annotation, ObjectUtils.firstNonNull(suggestedOrder, selfOrder++));

            postProcessChange.value(change, sqlSnippet);

            changeEntries.add(change);
        } catch (RuntimeException e) {
            throw new RuntimeException("Failed parsing on statement " + sqlSnippet, e);
        }
    }

    return changeEntries;
}