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


Java Maps类代码示例

本文整理汇总了Java中com.gs.collections.impl.factory.Maps的典型用法代码示例。如果您正苦于以下问题:Java Maps类的具体用法?Java Maps怎么用?Java Maps使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Maps类属于com.gs.collections.impl.factory包,在下文中一共展示了Maps类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getTotalAgeOfAllSmithPets

import com.gs.collections.impl.factory.Maps; //导入依赖的package包/类
/**
 * Sum the ages of all {@code Pet}s.
 * Use Reladomo's aggregation methods.
 * <p>
 * <p>Name {@code groupBy} column as "personId</p>
 * <p>Name {@code sum} column as "petAge"</p>
 * <p>Use appropriate methods on {@link AggregateList}</p>
 */
@Test
public void getTotalAgeOfAllSmithPets()
{
    AggregateList aggregateList = null;

    aggregateList.addAggregateAttribute("petAge", PetFinder.petAge().sum());
    aggregateList.addGroupBy("personId", PetFinder.personId());

    MutableMap<Integer, Integer> personIdToTotalPetAgeMap = Iterate.toMap(
            aggregateList,
            aggregateData -> aggregateData.getAttributeAsInteger("personId"),
            aggregateData -> aggregateData.getAttributeAsInteger("petAge")
    );

    Verify.assertMapsEqual(
            Maps.mutable.with(1, 3, 2, 20, 3, 4),
            personIdToTotalPetAgeMap
    );
}
 
开发者ID:goldmansachs,项目名称:reladomo-kata,代码行数:28,代码来源:Exercise3Test.java

示例2: getNumberOfPetsPerPerson

import com.gs.collections.impl.factory.Maps; //导入依赖的package包/类
/**
 * Similar to {@link Exercise3Test#getTotalAgeOfAllSmithPets()} only get the number of {@code Pet}s per {@code Person}.
 * <p>
 * Use Reladomo's aggregation methods.
 * </p>
 */
@Test
public void getNumberOfPetsPerPerson()
{
    AggregateList aggregateList = null;

    MutableMap<Integer, Integer> personIdToPetCountMap = Iterate.toMap(
            aggregateList,
            aggregateData -> aggregateData.getAttributeAsInteger("personId"),
            aggregateData -> aggregateData.getAttributeAsInteger("petCount"));

    Verify.assertMapsEqual(Maps.mutable.with(Tuples.pair(1, 1), Tuples.pair(2, 2), Tuples.pair(3, 1), Tuples.pair(5, 1), Tuples.pair(6, 1), Tuples.pair(7, 2)),
            personIdToPetCountMap);
}
 
开发者ID:goldmansachs,项目名称:reladomo-kata,代码行数:20,代码来源:Exercise4Test.java

示例3: findMapDeserializer

import com.gs.collections.impl.factory.Maps; //导入依赖的package包/类
@Override
public JsonDeserializer<?> findMapDeserializer(final MapType type, final DeserializationConfig config, BeanDescription beanDesc, final KeyDeserializer keyDeserializer,
        final TypeDeserializer elementTypeDeserializer, final JsonDeserializer<?> elementDeserializer) throws JsonMappingException {

    if (ImmutableMap.class.isAssignableFrom(type.getRawClass())) {
        return new StdDeserializer<Object>(type) {
            private static final long serialVersionUID = 1L;

            @Override
            public Object deserialize(JsonParser jp, DeserializationContext context) throws IOException {

                JsonToken t = jp.getCurrentToken();
                if (t == JsonToken.START_OBJECT) {
                    t = jp.nextToken();
                }
                if (t != JsonToken.FIELD_NAME && t != JsonToken.END_OBJECT) {
                    throw context.mappingException(type.getRawClass());
                }

                MutableMap<Object, Object> m = Maps.mutable.of();

                for (; jp.getCurrentToken() == JsonToken.FIELD_NAME; jp.nextToken()) {
                    // Pointing to field name
                    String fieldName = jp.getCurrentName();
                    Object key = (keyDeserializer == null) ? fieldName : keyDeserializer.deserializeKey(fieldName, context);
                    t = jp.nextToken();

                    Object value;
                    if (t == JsonToken.VALUE_NULL) {
                        value = null;
                    }
                    else if (elementDeserializer == null) {
                        value = jp.readValueAs(type.getContentType().getRawClass());
                    }
                    else if (elementTypeDeserializer == null) {
                        value = elementDeserializer.deserialize(jp, context);
                    }
                    else {
                        value = elementDeserializer.deserializeWithType(jp, context, elementTypeDeserializer);
                    }
                    m.put(key, value);
                }
                return m.toImmutable();
            }
        };
    }

    return super.findMapDeserializer(type, config, beanDesc, keyDeserializer, elementTypeDeserializer, elementDeserializer);
}
 
开发者ID:kaaprotech,项目名称:satu,代码行数:50,代码来源:SatuDeserializers.java


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