当前位置: 首页>>代码示例>>Java>>正文


Java MutableMap.get方法代码示例

本文整理汇总了Java中org.eclipse.collections.api.map.MutableMap.get方法的典型用法代码示例。如果您正苦于以下问题:Java MutableMap.get方法的具体用法?Java MutableMap.get怎么用?Java MutableMap.get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.eclipse.collections.api.map.MutableMap的用法示例。


在下文中一共展示了MutableMap.get方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getPeopleByLastName

import org.eclipse.collections.api.map.MutableMap; //导入方法依赖的package包/类
@Test
public void getPeopleByLastName()
{
    // Do you recognize this pattern?
    MutableMap<String, MutableList<Person>> lastNamesToPeople = Maps.mutable.empty();
    for (Person person : this.people)
    {
        String lastName = person.getLastName();
        MutableList<Person> peopleWithLastName = lastNamesToPeople.get(lastName);
        if (peopleWithLastName == null)
        {
            peopleWithLastName = Lists.mutable.empty();
            lastNamesToPeople.put(lastName, peopleWithLastName);
        }
        peopleWithLastName.add(person);
    }
    Verify.assertIterableSize(3, lastNamesToPeople.get("Smith"));

    // Hint: use the appropriate method on this.people to create a Multimap<String, Person>
    Multimap<String, Person> byLastNameMultimap = null;

    Verify.assertIterableSize(3, byLastNameMultimap.get("Smith"));
}
 
开发者ID:eclipse,项目名称:eclipse-collections-kata,代码行数:24,代码来源:Exercise3Test.java

示例2: match

import org.eclipse.collections.api.map.MutableMap; //导入方法依赖的package包/类
@Override
public void match(MutableList<UnmatchedIndexMap> allMissingRows, MutableList<UnmatchedIndexMap> allSurplusRows, MutableList<IndexMap> matchedColumns)
{
    List<IndexMap> keyColumnIndices = this.getKeyColumnIndexMaps(matchedColumns);
    if (keyColumnIndices.isEmpty())
    {
        LOGGER.warn("No key columns found!");
        return;
    }
    MutableMap<RowView, MutableList<UnmatchedIndexMap>> missingByKey = UnifiedMap.newMap(allMissingRows.size());
    for (UnmatchedIndexMap expected : allMissingRows)
    {
        ExpectedRowView expectedRowView = new ExpectedRowView(this.expectedData, keyColumnIndices, this.columnComparators, expected.getExpectedIndex());
        missingByKey.getIfAbsentPut(expectedRowView, NEW_LIST).add(expected);
    }
    MutableMap<RowView, MutableList<UnmatchedIndexMap>> surplusByKey = UnifiedMap.newMap(allSurplusRows.size());
    for (UnmatchedIndexMap actual : allSurplusRows)
    {
        ActualRowView actualRowView = new ActualRowView(this.actualData, keyColumnIndices, this.columnComparators, actual.getActualIndex());
        surplusByKey.getIfAbsentPut(actualRowView, NEW_LIST).add(actual);
    }
    for (RowView rowView : missingByKey.keysView())
    {
        MutableList<UnmatchedIndexMap> missing = missingByKey.get(rowView);
        MutableList<UnmatchedIndexMap> surplus = surplusByKey.get(rowView);
        if (Iterate.notEmpty(missing) && Iterate.notEmpty(surplus))
        {
            this.keyGroupPartialMatcher.match(missing, surplus, matchedColumns);
        }
    }
}
 
开发者ID:goldmansachs,项目名称:tablasco,代码行数:32,代码来源:KeyColumnPartialMatcher.java

示例3: getCountsByPetType

import org.eclipse.collections.api.map.MutableMap; //导入方法依赖的package包/类
@Test
public void getCountsByPetType()
{
    MutableList<PetType> petTypes = this.people.flatCollect(Person::getPets).collect(Pet::getType);

    // Do you recognize this pattern?
    MutableMap<PetType, Integer> petTypeCounts = Maps.mutable.empty();
    for (PetType petType : petTypes)
    {
        Integer count = petTypeCounts.get(petType);
        if (count == null)
        {
            count = 0;
        }
        petTypeCounts.put(petType, count + 1);
    }

    Assert.assertEquals(Integer.valueOf(2), petTypeCounts.get(PetType.CAT));
    Assert.assertEquals(Integer.valueOf(2), petTypeCounts.get(PetType.DOG));
    Assert.assertEquals(Integer.valueOf(2), petTypeCounts.get(PetType.HAMSTER));
    Assert.assertEquals(Integer.valueOf(1), petTypeCounts.get(PetType.SNAKE));
    Assert.assertEquals(Integer.valueOf(1), petTypeCounts.get(PetType.TURTLE));
    Assert.assertEquals(Integer.valueOf(1), petTypeCounts.get(PetType.BIRD));

    // Hint: use the appropriate method on this.people to create a Bag<PetType>
    Bag<PetType> counts = null;
    Assert.assertEquals(2, counts.occurrencesOf(PetType.CAT));
    Assert.assertEquals(2, counts.occurrencesOf(PetType.DOG));
    Assert.assertEquals(2, counts.occurrencesOf(PetType.HAMSTER));
    Assert.assertEquals(1, counts.occurrencesOf(PetType.SNAKE));
    Assert.assertEquals(1, counts.occurrencesOf(PetType.TURTLE));
    Assert.assertEquals(1, counts.occurrencesOf(PetType.BIRD));
}
 
开发者ID:eclipse,项目名称:eclipse-collections-kata,代码行数:34,代码来源:Exercise3Test.java

示例4: getPeopleByTheirPets

import org.eclipse.collections.api.map.MutableMap; //导入方法依赖的package包/类
@Test
public void getPeopleByTheirPets()
{
    // Do you recognize this pattern?
    MutableMap<PetType, MutableSet<Person>> peopleByPetType = Maps.mutable.empty();

    for (Person person : this.people)
    {
        MutableList<Pet> pets = person.getPets();
        for (Pet pet : pets)
        {
            PetType petType = pet.getType();
            MutableSet<Person> peopleWithPetType = peopleByPetType.get(petType);
            if (peopleWithPetType == null)
            {
                peopleWithPetType = Sets.mutable.empty();
                peopleByPetType.put(petType, peopleWithPetType);
            }
            peopleWithPetType.add(person);
        }
    }

    Verify.assertIterableSize(2, peopleByPetType.get(PetType.CAT));
    Verify.assertIterableSize(2, peopleByPetType.get(PetType.DOG));
    Verify.assertIterableSize(1, peopleByPetType.get(PetType.HAMSTER));
    Verify.assertIterableSize(1, peopleByPetType.get(PetType.TURTLE));
    Verify.assertIterableSize(1, peopleByPetType.get(PetType.BIRD));
    Verify.assertIterableSize(1, peopleByPetType.get(PetType.SNAKE));

    // Hint: use the appropriate method on this.people with a target collection to create a MutableSetMultimap<String, Person>
    // Hint: this.people is a MutableList, so it will return a MutableListMultimap without a target collection
    MutableSetMultimap<PetType, Person> multimap = null;

    Verify.assertIterableSize(2, multimap.get(PetType.CAT));
    Verify.assertIterableSize(2, multimap.get(PetType.DOG));
    Verify.assertIterableSize(1, multimap.get(PetType.HAMSTER));
    Verify.assertIterableSize(1, multimap.get(PetType.TURTLE));
    Verify.assertIterableSize(1, multimap.get(PetType.BIRD));
    Verify.assertIterableSize(1, multimap.get(PetType.SNAKE));
}
 
开发者ID:eclipse,项目名称:eclipse-collections-kata,代码行数:41,代码来源:Exercise3Test.java

示例5: ordersByCustomerUsingAsMap

import org.eclipse.collections.api.map.MutableMap; //导入方法依赖的package包/类
/**
 * Extra credit. Look into the {@link MutableList#toMap(Function, Function)} method.
 */
@Test
public void ordersByCustomerUsingAsMap()
{
    MutableMap<String, MutableList<Order>> customerNameToOrders =
            this.company.getCustomers().toMap(null, null);

    Assert.assertNotNull("customer name to orders", customerNameToOrders);
    Verify.assertSize("customer names", 3, customerNameToOrders);
    MutableList<Order> ordersForBill = customerNameToOrders.get("Bill");
    Verify.assertSize("Bill orders", 3, ordersForBill);
}
 
开发者ID:eclipse,项目名称:eclipse-collections-kata,代码行数:15,代码来源:Exercise8Test.java


注:本文中的org.eclipse.collections.api.map.MutableMap.get方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。