本文整理汇总了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
);
}
示例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);
}
示例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);
}