本文整理汇总了Java中com.google.gson.internal.LinkedTreeMap类的典型用法代码示例。如果您正苦于以下问题:Java LinkedTreeMap类的具体用法?Java LinkedTreeMap怎么用?Java LinkedTreeMap使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
LinkedTreeMap类属于com.google.gson.internal包,在下文中一共展示了LinkedTreeMap类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: readOptimizedFilter
import com.google.gson.internal.LinkedTreeMap; //导入依赖的package包/类
@Test
public void readOptimizedFilter() throws Exception {
GetEntitySetUriInfo uriInfo = createMockedUriInfo("Rooms");
Edm edm = EdmMock.createMockEdm();
FilterExpression exp = UriParserImpl.parseFilter(edm, edm.getEntityType("RefScenario", "Room"), "Version gt 105");
Mockito.when(uriInfo.getFilter()).thenReturn(exp);
List<Room> results = createRooms(1, 10);
ReadResult<Room> readResult = ReadResult.forResult(results).filterApplied().build();
Mockito.when(mockedDataSource.readData(Mockito.any(EdmEntitySet.class), Mockito.any(ReadOptions.class)))
.thenReturn((ReadResult)readResult);
ODataResponse result = dataSourceProcessor.readEntitySet(uriInfo, "application/json");
StringHelper.Stream resultStream = StringHelper.toStream(result.getEntityAsStream());
List<LinkedTreeMap<?, ?>> parsedResults = JsonHelper.getResults(resultStream.asString());
Assert.assertEquals(10, parsedResults.size());
Assert.assertEquals("Room with id: 1", parsedResults.get(0).get("Name"));
Assert.assertEquals("Room with id: 9", parsedResults.get(9).get("Name"));
}
示例2: loadHospitals
import com.google.gson.internal.LinkedTreeMap; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public static void loadHospitals() {
String filename = "geography/healthcare_facilities.json";
try {
String json = Utilities.readResource(filename);
Gson g = new Gson();
HashMap<String, LinkedTreeMap> gson = g.fromJson(json, HashMap.class);
for (Entry<String, LinkedTreeMap> entry : gson.entrySet()) {
LinkedTreeMap value = entry.getValue();
String resourceID = UUID.randomUUID().toString();
value.put("resourceID", resourceID);
Hospital h = new Hospital(value);
hospitalList.add(h);
}
} catch (Exception e) {
System.err.println("ERROR: unable to load json: " + filename);
e.printStackTrace();
throw new ExceptionInInitializerError(e);
}
}
示例3: deserializesMapsDueToTypeErasure
import com.google.gson.internal.LinkedTreeMap; //导入依赖的package包/类
@Test
@SuppressWarnings("unchecked")
public void deserializesMapsDueToTypeErasure() {
List<TextAnnotation> initialValue = Collections.singletonList(anno("n", "t"));
Class<List<TextAnnotation>> valueType = (Class<List<TextAnnotation>>)
initialValue.getClass();
List<TextAnnotation> readValue = writeThenRead(initialValue, valueType);
assertThat(readValue, is(not(initialValue)));
LinkedTreeMap<String, LinkedTreeMap<String, String>> deserialized =
new LinkedTreeMap<>();
LinkedTreeMap<String, String> deserializedAnno =
new LinkedTreeMap<>();
deserializedAnno.put("fst", "n");
deserializedAnno.put("snd", "t");
deserialized.put("wrappedValue", deserializedAnno);
assertThat(readValue, is(Collections.singletonList(deserialized))); // (*)
}
示例4: deserializesMapsDueToTypeErasure
import com.google.gson.internal.LinkedTreeMap; //导入依赖的package包/类
@Test
@SuppressWarnings("unchecked")
public void deserializesMapsDueToTypeErasure() {
List<PositiveN> initialValue = Collections.singletonList(posN(1));
Class<List<PositiveN>> valueType = (Class<List<PositiveN>>)
initialValue.getClass();
List<PositiveN> readValue = writeThenRead(initialValue, valueType);
assertThat(readValue, is(not(initialValue)));
LinkedTreeMap<String, Double> deserialized =
new LinkedTreeMap<>();
deserialized.put("wrappedValue", 1.0);
assertThat(readValue, is(Collections.singletonList(deserialized))); // (*)
}
示例5: constructDeviceMetaDataFromJSON
import com.google.gson.internal.LinkedTreeMap; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public static Map<String, String> constructDeviceMetaDataFromJSON(String parentKey,
Map<String, Object> result) {
Map<String, String> metaDataMap = new HashMap<>(1);
String currentKey;
for (String key : result.keySet()) {
Object object = result.get(key);
currentKey = key;
if (parentKey != null) {
currentKey = parentKey + "." + key;
}
if (object != null) {
if (object instanceof LinkedTreeMap) {
metaDataMap.putAll(constructDeviceMetaDataFromJSON(currentKey, (LinkedTreeMap) object));
} else {
metaDataMap.put(currentKey, object.toString());
}
}
}
return metaDataMap;
}
示例6: shouldParseUpdateSummaryState
import com.google.gson.internal.LinkedTreeMap; //导入依赖的package包/类
@Test
public void shouldParseUpdateSummaryState() throws IOException{
bittrexExchange.connectToWebSocket(() -> System.out.println("Connected"));
verify(mockHubProxy).on(eq("updateSummaryState"),subscriptionHandlerArgumentCaptor.capture(),eq(Object.class));
bittrexExchange.onUpdateSummaryState(exchangeSummaryState -> {
assertThat(exchangeSummaryState.getNounce(), equalTo(24724L));
assertThat(exchangeSummaryState.getDeltas().length, equalTo(56));
lambdaCalled=true;
});
subscriptionHandlerArgumentCaptor.getValue().run(new Gson().fromJson(loadTestResourceAsString("/UpdateSummaryState.json"),LinkedTreeMap.class));
assertThat(lambdaCalled,is(true));
}
示例7: getAttachmentList
import com.google.gson.internal.LinkedTreeMap; //导入依赖的package包/类
private JsonArray getAttachmentList(LinkedTreeMap<String, Object> attachmentList, String docID) {
JsonArray attachmentArray = new JsonArray();
for (Object key : attachmentList.keySet()) {
LinkedTreeMap<String, Object> attach = (LinkedTreeMap<String, Object>) attachmentList.get(key);
JsonObject attachedObject = new JsonObject();
// set the content type of the attachment
attachedObject.addProperty("content_type", attach.get("content_type").toString());
// append the document id and attachment key to the URL
attachedObject.addProperty("url", "attach?id=" + docID + "&key=" + key);
// set the key of the attachment
attachedObject.addProperty("key", key + "");
// add the attachment object to the array
attachmentArray.add(attachedObject);
}
return attachmentArray;
}
示例8: formatListForPopcorn
import com.google.gson.internal.LinkedTreeMap; //导入依赖的package包/类
public ArrayList<Media> formatListForPopcorn(ArrayList<Media> existingList) {
for (LinkedTreeMap<String, Object> item : showsList) {
Media media;
if (item.get("type").toString().equalsIgnoreCase("movie")) {
media = new Movie(sMediaProvider, null);
} else {
media = new Show(sMediaProvider, null);
}
media.title = (String) item.get("name");
media.videoId = item.get("id").toString();
media.imdbId = "mal-" + media.videoId;
String year = item.get("aired").toString();
if (year.contains(", ")) {
year = year.split(", ")[1];
}
if (year.contains(" ")) {
year = year.split(" ")[0];
}
media.year = year;
media.image = media.headerImage = item.get("malimg").toString();
existingList.add(media);
}
return existingList;
}
示例9: formatListForPopcorn
import com.google.gson.internal.LinkedTreeMap; //导入依赖的package包/类
public ArrayList<Media> formatListForPopcorn(ArrayList<Media> existingList) {
for (LinkedTreeMap<String, Object> item : showsList) {
Show show = new Show(sMediaProvider, sSubsProvider);
show.title = (String) item.get("title");
show.videoId = (String) item.get("imdb_id");
show.seasons = (Integer) item.get("seasons");
show.tvdbId = (String) item.get("tvdb_id");
show.year = (String) item.get("year");
LinkedTreeMap<String, String> images = (LinkedTreeMap<String, String>) item.get("images");
if(!images.get("poster").contains("images/posterholder.png"))
show.image = images.get("poster").replace("/original/", "/medium/");
if(!images.get("poster").contains("images/posterholder.png"))
show.headerImage = images.get("fanart").replace("/original/", "/medium/");
existingList.add(show);
}
return existingList;
}
示例10: DataBase
import com.google.gson.internal.LinkedTreeMap; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public DataBase(Main plugin) {
this.plugin = plugin;
plugin.getDataFolder().mkdirs();
initMessage();
initDB();
registerCommands();
Skyblock.skyblocklist = new LinkedHashMap<String, Skyblock>();
Skyblock.plugin = plugin;
for (Entry<String, Object> v1 : skyblockDB.entrySet()) {
String player = v1.getKey();
LinkedTreeMap<String, Object> shares = (LinkedTreeMap<String, Object>) ((LinkedTreeMap<String, Object>)v1.getValue()).get("shares");
int num = Skyblock.getInt((double)((LinkedTreeMap<String, Object>)v1.getValue()).get("num"));
Position spawn = stringToPos((String)((LinkedTreeMap<String, Object>)v1.getValue()).get("spawn"));
LinkedTreeMap<String, Object> invites = (LinkedTreeMap<String, Object>) ((LinkedTreeMap<String, Object>)v1.getValue()).get("invites");
boolean isInviteAll = (boolean) ((LinkedTreeMap<String, Object>)v1.getValue()).getOrDefault("inviteAll", false);
boolean pvp = (boolean) ((LinkedTreeMap<String, Object>)v1.getValue()).getOrDefault("pvp", false);
Skyblock.skyblocklist.put(player, new Skyblock(player, shares, invites, num, spawn, isInviteAll, pvp));
}
if (instance == null) {
instance = this;
}
}
示例11: NodeBodyUpdate
import com.google.gson.internal.LinkedTreeMap; //导入依赖的package包/类
public NodeBodyUpdate(String name, String nodeType, LinkedTreeMap<String, Object> properties,
List<String> aspectNames)
{
this.name = name;
this.nodeType = nodeType;
if (properties != null && !properties.isEmpty())
{
this.properties = properties;
}
else
{
this.properties = null;
}
this.aspectNames = aspectNames;
this.permissions = null;
}
示例12: execute_JSON_to_Map
import com.google.gson.internal.LinkedTreeMap; //导入依赖的package包/类
@Test
public void execute_JSON_to_Map() throws Exception {
String json =
"{" +
"\"string\":\"String\"," +
"\"boolean\":true," +
"\"double\":1.0" +
"}";
Map<?,?> jsonMap = new JsonSerializer().deserialize(json, Map.class);
Map<String, Object> map = new LinkedTreeMap<>();
assertEquals(map.getClass(), jsonMap.getClass());
map = (Map<String, Object>)jsonMap;
Assert.assertTrue(getMessageForClassMismatch(String.class, map.get("string").getClass()), map.get("string") instanceof String);
Assert.assertTrue(getMessageForClassMismatch(Boolean.class, map.get("boolean").getClass()), map.get("boolean") instanceof Boolean);
Assert.assertTrue(getMessageForClassMismatch(Double.class, map.get("double").getClass()), map.get("double") instanceof Double);
}
示例13: coord
import com.google.gson.internal.LinkedTreeMap; //导入依赖的package包/类
@Nullable
public Coordinate coord() {
try {
if (data == null) return null;
Object locObj = data.get("location");
if (!(locObj instanceof LinkedTreeMap)) return null;
//noinspection unchecked
Object coordObj = ((LinkedTreeMap<String, Object>) locObj).get("coordinates");
Object[] coords;
if (coordObj instanceof Collection) {
coords = ((Collection) coordObj).toArray();
} else if (coordObj instanceof Object[]) {
coords = (Object[]) coordObj;
} else {
return null;
}
return Coordinate.builder()
.lat(((Number) coords[1]).floatValue())
.lon(((Number) coords[0]).floatValue())
.build();
} catch (Exception ignored) {
}
return null;
}
示例14: convertLinkedTreeMapToJSON
import com.google.gson.internal.LinkedTreeMap; //导入依赖的package包/类
@NonNull
private static JSONObject convertLinkedTreeMapToJSON(LinkedTreeMap<String, Object> ltm) {
JSONObject jo = new JSONObject();
Object[] objs = ltm.entrySet().toArray();
for (Object obj : objs) {
Map.Entry o = (Map.Entry) obj;
try {
if (o.getValue() instanceof LinkedTreeMap) {
//noinspection unchecked
jo.put(o.getKey().toString(),
convertLinkedTreeMapToJSON((LinkedTreeMap<String, Object>) o.getValue()));
} else {
jo.put(o.getKey().toString(), o.getValue());
}
} catch (JSONException ignored) {
}
}
return jo;
}
示例15: coord
import com.google.gson.internal.LinkedTreeMap; //导入依赖的package包/类
@Nullable
public Coordinate coord() {
try {
if (payload == null || payload.data == null) return null;
Object locObj = payload.data.get("location");
if (!(locObj instanceof LinkedTreeMap)) return null;
//noinspection unchecked
Object coordObj = ((LinkedTreeMap<String, Object>) locObj).get("coordinates");
Object[] coords;
if (coordObj instanceof Collection) {
coords = ((Collection) coordObj).toArray();
} else if (coordObj instanceof Object[]) {
coords = (Object[]) coordObj;
} else {
return null;
}
return Coordinate.builder() //
.lat(((Number) coords[1]).floatValue()) //
.lon(((Number) coords[0]).floatValue()) //
.build();
} catch (Exception ignored) {
}
return null;
}