org.eclipse.collections.api.map.ImmutableMap Java Examples

The following examples show how to use org.eclipse.collections.api.map.ImmutableMap. 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: DeserializerTest.java    From jackson-datatypes-collections with Apache License 2.0 6 votes vote down vote up
@Test
public void objectObjectMaps() throws IOException {
    Assert.assertEquals(
            mapperWithModule().readValue("{\"abc\":\"def\"}", new TypeReference<MutableMap<String, String>>() {}),
            Maps.mutable.of("abc", "def")
    );
    Assert.assertEquals(
            mapperWithModule().readValue("{\"abc\":\"def\"}", new TypeReference<ImmutableMap<String, String>>() {}),
            Maps.immutable.of("abc", "def")
    );
    Assert.assertEquals(
            mapperWithModule().readValue("{\"abc\":\"def\"}", new TypeReference<MapIterable<String, String>>() {}),
            Maps.mutable.of("abc", "def")
    );
    Assert.assertEquals(
            mapperWithModule().readValue("{\"abc\":\"def\"}",
                                         new TypeReference<UnsortedMapIterable<String, String>>() {}),
            Maps.mutable.of("abc", "def")
    );
}
 
Example #2
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 #3
Source File: TextMarkupDocumentReaderTest.java    From obevo with Apache License 2.0 6 votes vote down vote up
@Test
public void testQuotedSplitWithEqualSign() {
    String input = "attr=1234 attr2=\"56=78\" mytog1";
    if (legacyMode) {
        try {
            textMarkupDocumentReader.parseAttrsAndToggles(input);
            fail("Should have failed here");
        } catch (IllegalArgumentException e) {
            assertThat(e.getMessage(), containsString("Cannot mark = multiple times"));
        }
    } else {
        Pair<ImmutableMap<String, String>, ImmutableSet<String>> results = textMarkupDocumentReader.parseAttrsAndToggles(input);

        assertEquals(Maps.mutable.of("attr", "1234", "attr2", "56=78"), results.getOne());
        assertEquals(Sets.mutable.of("mytog1"), results.getTwo());
    }
}
 
Example #4
Source File: TextMarkupDocumentReaderTest.java    From obevo with Apache License 2.0 6 votes vote down vote up
@Test
public void testQuotedSplitWithEqualSignAndSpace() {
    String input = "attr=1234 attr2=\"56 = 78\" mytog1";
    if (legacyMode) {
        try {
            textMarkupDocumentReader.parseAttrsAndToggles(input);
            fail("Should have failed here");
        } catch (ArrayIndexOutOfBoundsException e) {
            assertThat(e.getMessage(), notNullValue());
        }
    } else {
        Pair<ImmutableMap<String, String>, ImmutableSet<String>> results = textMarkupDocumentReader.parseAttrsAndToggles(input);

        assertEquals(Maps.mutable.of("attr", "1234", "attr2", "56 = 78"), results.getOne());
        assertEquals(Sets.mutable.of("mytog1"), results.getTwo());
    }
}
 
Example #5
Source File: TextMarkupDocumentReaderTest.java    From obevo with Apache License 2.0 6 votes vote down vote up
@Test
public void testWordEndingInEqualSignWillFailInLegacy() {
    String input = "   attr= abc";
    if (legacyMode) {
        try {
            textMarkupDocumentReader.parseAttrsAndToggles(input);
            fail("Should have failed here");
        } catch (ArrayIndexOutOfBoundsException expected) {
        }
    } else {
        Pair<ImmutableMap<String, String>, ImmutableSet<String>> results = textMarkupDocumentReader.parseAttrsAndToggles(input);

        assertEquals(Maps.mutable.of("attr", ""), results.getOne());
        assertEquals(Sets.mutable.of("abc"), results.getTwo());
    }
}
 
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: TextMarkupDocumentReaderTest.java    From obevo with Apache License 2.0 5 votes vote down vote up
@Test
public void testQuoteWithinStringIsStillPreservedEvenIfStringIsntClosedForBackwardsCompatibility() {
    Pair<ImmutableMap<String, String>, ImmutableSet<String>> results = textMarkupDocumentReader.parseAttrsAndToggles(
            "   =attr  1234 attr2=\"56\"78 mytog1  "
    );

    if (legacyMode) {
        assertEquals(Maps.mutable.of("", "attr", "attr2", "\"56\"78"), results.getOne());
        assertEquals(Sets.mutable.of("1234", "mytog1"), results.getTwo());
    } else {
        assertEquals(Maps.mutable.of("attr2", "\"56\"78"), results.getOne());
        assertEquals(Sets.mutable.of("=", "attr", "1234", "mytog1"), results.getTwo());
    }
}
 
Example #8
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 #9
Source File: TextMarkupDocumentReaderTest.java    From obevo with Apache License 2.0 5 votes vote down vote up
@Test
public void testSimpleLineParsing() {
    Pair<ImmutableMap<String, String>, ImmutableSet<String>> results = textMarkupDocumentReader.parseAttrsAndToggles(
            "attr=1234 attr2=\"5678\" mytog1"
    );

    assertEquals(Maps.mutable.of("attr", "1234", "attr2", "5678"), results.getOne());
    assertEquals(Sets.mutable.of("mytog1"), results.getTwo());
}
 
Example #10
Source File: TextMarkupDocumentReaderTest.java    From obevo with Apache License 2.0 5 votes vote down vote up
@Test
public void testEqualSignInQuoteValueWillFailInLegacy() {
    String input = "   attr=\"abc=123\" ";
    if (legacyMode) {
        try {
            textMarkupDocumentReader.parseAttrsAndToggles(input);
            fail("Should throw exception here");
        } catch (IllegalArgumentException expected) {
        }
    } else {
        Pair<ImmutableMap<String, String>, ImmutableSet<String>> results = textMarkupDocumentReader.parseAttrsAndToggles(input);
        assertEquals(Maps.mutable.of("attr", "abc=123"), results.getOne());
        assertEquals(Sets.mutable.empty(), results.getTwo());
    }
}
 
Example #11
Source File: TextMarkupDocumentReaderTest.java    From obevo with Apache License 2.0 5 votes vote down vote up
@Test
public void testEqualSignAloneWillFailInLegacy() {
    String input = " a = b ";
    if (legacyMode) {
        try {
            textMarkupDocumentReader.parseAttrsAndToggles(input);
            fail("Should throw exception here");
        } catch (ArrayIndexOutOfBoundsException expected) {
        }
    } else {
        Pair<ImmutableMap<String, String>, ImmutableSet<String>> results = textMarkupDocumentReader.parseAttrsAndToggles(input);
        assertEquals(Maps.mutable.empty(), results.getOne());
        assertEquals(Sets.mutable.of("a", "b", "="), results.getTwo());
    }
}
 
Example #12
Source File: TextMarkupDocumentReaderTest.java    From obevo with Apache License 2.0 5 votes vote down vote up
@Test
public void testQuoteWithinQuotedStringIsPreservedIfNoSpace() {
    Pair<ImmutableMap<String, String>, ImmutableSet<String>> results = textMarkupDocumentReader.parseAttrsAndToggles(
            "   abc=attr  1234 attr2=\"56\"78\" mytog1  "
    );

    assertEquals(Maps.mutable.of("abc", "attr", "attr2", "56\"78"), results.getOne());
    assertEquals(Sets.mutable.of("1234", "mytog1"), results.getTwo());
}
 
Example #13
Source File: PackageMetadataReader.java    From obevo with Apache License 2.0 5 votes vote down vote up
public PackageMetadata getPackageMetadata(String fileContent) {
    TextMarkupDocument textMarkupDocument = textMarkupDocumentReader.parseString(fileContent, null);
    TextMarkupDocumentSection metadataSection = textMarkupDocument.findSectionWithElementName(TextMarkupDocumentReader.TAG_METADATA);
    String packageMetadataContent = textMarkupDocument.getSections()
            .select(new Predicate<TextMarkupDocumentSection>() {
                @Override
                public boolean accept(TextMarkupDocumentSection it) {
                    return it.getName() == null;
                }
            })
            .toReversed()
            .collect(new Function<TextMarkupDocumentSection, String>() {
                @Override
                public String valueOf(TextMarkupDocumentSection section) {
                    return section.getContent();
                }
            })
            .collect(StringFunctions.trim())
            .detect(StringPredicates.notEmpty());

    ImmutableMap<String, String> sourceEncodingsMap = getSourceEncodings(getConfig(packageMetadataContent));

    if (metadataSection != null || sourceEncodingsMap.notEmpty()) {
        return new PackageMetadata(metadataSection, sourceEncodingsMap);
    } else {
        return null;
    }
}
 
Example #14
Source File: TextMarkupDocumentReaderTest.java    From obevo with Apache License 2.0 5 votes vote down vote up
@Test
public void testBehaviorOfStringStartingWithEqualSign() {
    Pair<ImmutableMap<String, String>, ImmutableSet<String>> results = textMarkupDocumentReader.parseAttrsAndToggles(
            " e  q =attr  1234 attr2=\"5678\"\" \"\"mytog1\"  "
    );

    if (legacyMode) {
        assertEquals(Maps.mutable.of("", "attr", "attr2", "5678\""), results.getOne());
        assertEquals(Sets.mutable.of("1234", "\"\"mytog1\"", "e", "q"), results.getTwo());
    } else {
        assertEquals(Maps.mutable.of("attr2", "5678\""), results.getOne());
        assertEquals(Sets.mutable.of("=", "attr", "1234", "\"\"mytog1\"", "e", "q"), results.getTwo());
    }
}
 
Example #15
Source File: TextMarkupDocumentReaderTest.java    From obevo with Apache License 2.0 5 votes vote down vote up
@Test
public void testSlash() {
    Pair<ImmutableMap<String, String>, ImmutableSet<String>> results = textMarkupDocumentReader.parseAttrsAndToggles(
            " 123  attr=\"abc\\def\"  \\  456=789"
    );

    if (legacyMode) {
        assertEquals(Maps.mutable.of("attr", "abc\\def", "456", "789"), results.getOne());
        assertEquals(Sets.mutable.of("123", "\\"), results.getTwo());
    } else {
        assertEquals(Maps.mutable.of("attr", "abc\\def", "456", "789"), results.getOne());
        assertEquals(Sets.mutable.of("123", "\\"), results.getTwo());
    }
}
 
Example #16
Source File: TextMarkupDocumentReaderTest.java    From obevo with Apache License 2.0 5 votes vote down vote up
@Test
public void testSlashWithQuoteNoEscaping2() {
    Pair<ImmutableMap<String, String>, ImmutableSet<String>> results = textMarkupDocumentReader.parseAttrsAndToggles(
            " 123  attr=\"abc\\d ef\"  \\  456=789"
    );

    if (legacyMode) {
        assertEquals(Maps.mutable.of("attr", "\"abc\\d", "456", "789"), results.getOne());
        assertEquals(Sets.mutable.of("123", "\\", "ef\""), results.getTwo());
    } else {
        assertEquals(Maps.mutable.of("attr", "abc\\d ef", "456", "789"), results.getOne());
        assertEquals(Sets.mutable.of("123", "\\"), results.getTwo());
    }
}
 
Example #17
Source File: TextMarkupDocumentReaderTest.java    From obevo with Apache License 2.0 5 votes vote down vote up
@Test
public void testSlashWithQuoteNoEscaping() {
    Pair<ImmutableMap<String, String>, ImmutableSet<String>> results = textMarkupDocumentReader.parseAttrsAndToggles(
            " 123  attr=\"abc\\\"d ef\"  \\  456=789"
    );

    if (legacyMode) {
        assertEquals(Maps.mutable.of("attr", "\"abc\\\"d", "456", "789"), results.getOne());
        assertEquals(Sets.mutable.of("123", "\\", "ef\""), results.getTwo());
    } else {
        assertEquals(Maps.mutable.of("attr", "abc\"d ef", "456", "789"), results.getOne());
        assertEquals(Sets.mutable.of("123", "\\"), results.getTwo());
    }
}
 
Example #18
Source File: SerializerTest.java    From jackson-datatypes-collections with Apache License 2.0 5 votes vote down vote up
@Test
public void objectObjectMaps() throws IOException {
    Assert.assertEquals(
            "{\"abc\":\"def\"}",
            mapperWithModule().writerFor(MutableMap.class).writeValueAsString(Maps.mutable.of("abc", "def"))
    );
    Assert.assertEquals(
            "{\"abc\":\"def\"}",
            mapperWithModule().writerFor(ImmutableMap.class).writeValueAsString(Maps.immutable.of("abc", "def"))
    );
    Assert.assertEquals(
            "{\"abc\":\"def\"}",
            mapperWithModule().writerFor(MapIterable.class).writeValueAsString(Maps.immutable.of("abc", "def"))
    );
    Assert.assertEquals(
            "{\"abc\":\"def\"}",
            mapperWithModule().writerFor(MutableMapIterable.class).writeValueAsString(Maps.mutable.of("abc", "def"))
    );
    Assert.assertEquals(
            "{\"abc\":\"def\"}",
            mapperWithModule().writeValueAsString(Maps.immutable.of("abc", "def"))
    );
    Assert.assertEquals(
            "{\"abc\":\"def\"}",
            mapperWithModule().writerFor(new TypeReference<MapIterable<String, String>>() {})
                    .writeValueAsString(Maps.immutable.of("abc", "def"))
    );
}
 
Example #19
Source File: RawDeserializationTest.java    From jackson-datatypes-collections with Apache License 2.0 5 votes vote down vote up
@Test
public void objectObjectMap() throws IOException {
    testCollection(Maps.mutable.of("a", 1, "b", Collections.emptyMap()), "{\"a\":1, \"b\":{}}",
            new TypeReference<MutableMap>() {},
            new TypeReference<ImmutableMap>() {});
    testCollection(Maps.mutable.of("a", 1, "b", Collections.emptyMap()), "{\"a\":1, \"b\":{}}",
            MutableMap.class,
            ImmutableMap.class);
}
 
Example #20
Source File: TextMarkupDocumentSection.java    From obevo with Apache License 2.0 4 votes vote down vote up
public ImmutableMap<String, String> getAttrs() {
    return attrs;
}
 
Example #21
Source File: IssuesStatistics.java    From warnings-ng-plugin with MIT License 4 votes vote down vote up
public ImmutableMap<Severity, Integer> getNewSizePerSeverity() {
    return Maps.immutable.ofMap(newSizeBySeverity);
}
 
Example #22
Source File: DbEnvironment.java    From obevo with Apache License 2.0 4 votes vote down vote up
public ImmutableMap<String, String> getExtraEnvAttrs() {
    return extraEnvAttrs == null ? Maps.immutable.<String, String>empty() : extraEnvAttrs;
}
 
Example #23
Source File: DbEnvironment.java    From obevo with Apache License 2.0 4 votes vote down vote up
public void setExtraEnvAttrs(ImmutableMap<String, String> extraEnvAttrs) {
    this.extraEnvAttrs = extraEnvAttrs;
}
 
Example #24
Source File: ChangeRestrictionsReaderTest.java    From obevo with Apache License 2.0 4 votes vote down vote up
private TextMarkupDocumentSection doc(String sectionName, String sectionContent, ImmutableMap<String, String> attrs) {
    return new TextMarkupDocumentSection(sectionName, sectionContent, attrs);
}
 
Example #25
Source File: Environment.java    From obevo with Apache License 2.0 4 votes vote down vote up
public ImmutableMap<String, String> getTokens() {
    return this.tokens;
}
 
Example #26
Source File: Environment.java    From obevo with Apache License 2.0 4 votes vote down vote up
public void setTokens(ImmutableMap<String, String> tokens) {
    this.tokens = tokens != null ? tokens : Maps.immutable.<String, String>empty();
}
 
Example #27
Source File: Environment.java    From obevo with Apache License 2.0 4 votes vote down vote up
public void setSchemaNameOverrides(ImmutableMap<String, String> schemaNameOverrides) {
    this.schemaNameOverrides = schemaNameOverrides;
}
 
Example #28
Source File: TextMarkupDocumentSection.java    From obevo with Apache License 2.0 4 votes vote down vote up
public TextMarkupDocumentSection(String name, String content, ImmutableMap<String, String> attrs) {
    this.name = name;
    this.content = content;
    this.toggles = Sets.immutable.empty();
    this.setAttrs(attrs);
}
 
Example #29
Source File: IssuesStatistics.java    From warnings-ng-plugin with MIT License 4 votes vote down vote up
public ImmutableMap<Severity, Integer> getTotalSizePerSeverity() {
    return Maps.immutable.ofMap(totalSizeBySeverity);
}
 
Example #30
Source File: TextMarkupDocumentSection.java    From obevo with Apache License 2.0 4 votes vote down vote up
public void setAttrs(ImmutableMap<String, String> attrs) {
    this.attrs = attrs != null ? attrs : Maps.immutable.<String, String>empty();
}