Java Code Examples for org.eclipse.collections.impl.map.mutable.UnifiedMap#newMapWith()

The following examples show how to use org.eclipse.collections.impl.map.mutable.UnifiedMap#newMapWith() . 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: ExercisesAdvancedFinder.java    From reladomo-kata with Apache License 2.0 6 votes vote down vote up
@Test
public void testQ18()
{
    AllTypes allTypes = new AllTypes();

    // Test no changes
    this.applyChanges(allTypes, UnifiedMap.<Integer, Object>newMap());

    Assert.assertEquals(0, allTypes.getIntValue());
    Assert.assertNull(allTypes.getStringValue());
    Assert.assertFalse(allTypes.isBooleanValue());
    Assert.assertEquals(0.0, allTypes.getDoubleValue(), 0.0);

    MutableMap<Integer, Object> changes = UnifiedMap.newMapWith(
            Tuples.<Integer, Object>pair(124, 65536),  // int
            Tuples.<Integer, Object>pair(237, "Charlie Croker"), // String
            Tuples.<Integer, Object>pair(874, true),  // boolean
            Tuples.<Integer, Object>pair(765, 1.2358));  // double
    this.applyChanges(allTypes, changes);

    Assert.assertEquals(65536, allTypes.getIntValue());
    Assert.assertEquals("Charlie Croker", allTypes.getStringValue());
    Assert.assertTrue(allTypes.isBooleanValue());
    Assert.assertEquals(1.2358, allTypes.getDoubleValue(), 0.0);
}
 
Example 2
Source File: ForEachPatternUnitTest.java    From tutorials with MIT License 6 votes vote down vote up
@SuppressWarnings("unchecked")
@Test
public void whenInstantiateAndChangeValues_thenCorrect() {
    Pair<Integer, String> pair1 = Tuples.pair(1, "One");
    Pair<Integer, String> pair2 = Tuples.pair(2, "Two");
    Pair<Integer, String> pair3 = Tuples.pair(3, "Three");

    UnifiedMap<Integer, String> map = UnifiedMap.newMapWith(pair1, pair2, pair3);

    for (int i = 0; i < map.size(); i++) {
        map.put(i + 1, "New Value");
    }

    for (int i = 0; i < map.size(); i++) {
        Assert.assertEquals("New Value", map.get(i + 1));
    }
}
 
Example 3
Source File: ExercisesAdvancedFinder.java    From reladomo-kata with Apache License 2.0 5 votes vote down vote up
@Test
public void testQ7()
{
    MutableMap<String, Integer> peopleByCountry = this.getCountOfPeopleByCountry();

    MutableMap<String, Integer> expectedResult = UnifiedMap.newMapWith(
            Tuples.pair("USA", 4),
            Tuples.pair("AU", 3),
            Tuples.pair("DE", 2),
            Tuples.pair("UK", 2),
            Tuples.pair("JPN", 4),
            Tuples.pair("MA", 1)
    );
    Verify.assertMapsEqual(expectedResult, peopleByCountry);
}
 
Example 4
Source File: ExercisesAdvancedFinder.java    From reladomo-kata with Apache License 2.0 5 votes vote down vote up
@Test
public void testQ17()
{
    MutableMap<Integer, Attribute> actualMap = this.getMyIdToAttributeMap();

    MutableMap<Integer, Attribute> expectedMap = UnifiedMap.newMapWith(
            Tuples.<Integer, Attribute>pair(Integer.valueOf(124), AllTypesFinder.intValue()),
            Tuples.<Integer, Attribute>pair(Integer.valueOf(237), AllTypesFinder.stringValue()),
            Tuples.<Integer, Attribute>pair(Integer.valueOf(874), AllTypesFinder.booleanValue()),
            Tuples.<Integer, Attribute>pair(Integer.valueOf(765), AllTypesFinder.doubleValue()));

    Verify.assertMapsEqual(expectedMap, actualMap);
}