All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.github.thunderz99.cosmos.CosmosDocumentList Maven / Gradle / Ivy

There is a newer version: 0.7.11
Show newest version
package io.github.thunderz99.cosmos;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import io.github.thunderz99.cosmos.util.JsonUtil;
import org.apache.commons.collections4.CollectionUtils;

/**
 * Represent a list of CosmosDB document.
 *
 * 

* Having toList and toJson util method to convert to {@code List} or String * conveniently. *

*/ public class CosmosDocumentList { List> maps; public CosmosDocumentList() { } public CosmosDocumentList(List objs) { if (CollectionUtils.isEmpty(objs)) { return; } var obj = objs.get(0); if (obj instanceof Map) { this.maps = (List>) objs; } } public List toList(Class classOfT) { if (maps != null) { return maps.stream().map(obj -> JsonUtil.fromMap(obj, classOfT)).collect(Collectors.toList()); } return Lists.newArrayList(); } public List> toMap() { if (maps != null) { return maps.stream().map(obj -> Maps.newLinkedHashMap(obj)).collect(Collectors.toList()); } return Lists.newArrayList(); } public int size() { if (maps != null) { return maps.size(); } return 0; } public String toJson() { if (maps != null) { return JsonUtil.toJson(maps); } return "[]"; } public String toString() { return toJson(); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy