本文整理汇总了Java中com.google.gson.internal.LinkedTreeMap.put方法的典型用法代码示例。如果您正苦于以下问题:Java LinkedTreeMap.put方法的具体用法?Java LinkedTreeMap.put怎么用?Java LinkedTreeMap.put使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.gson.internal.LinkedTreeMap
的用法示例。
在下文中一共展示了LinkedTreeMap.put方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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);
}
}
示例2: 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))); // (*)
}
示例3: 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))); // (*)
}
示例4: convertListTest
import com.google.gson.internal.LinkedTreeMap; //导入方法依赖的package包/类
@Test
public void convertListTest(){
listConverter.setListClass(Attachment.class);
Class type = List.class;
List value = new ArrayList();
LinkedTreeMap ltm = new LinkedTreeMap();
ltm.put("id","id0001");
ltm.put("url","http://test.com");
ltm.put("filename","filename.txt");
ltm.put("size","10");
ltm.put("type","image/jpeg");
Map<String,Thumbnail> thumbnails = new HashedMap<>();
Thumbnail tmb = new Thumbnail();
tmb.setName("Thumbnail");
tmb.setUrl("http:example.com");
tmb.setWidth(Float.valueOf(10));
tmb.setHeight(Float.valueOf(10));
thumbnails.put("small", tmb);
ltm.put("thumbnails",thumbnails);
value.add(0, ltm);
List<Attachment> list = (List<Attachment>) listConverter.convert(type, value);
assertNotNull(list);
assertNotNull(list.get(0).getId());
assertNotNull(list.get(0).getFilename());
assertNotNull(list.get(0).getSize());
assertNotNull(list.get(0).getType());
assertNotNull(list.get(0).getUrl());
assertNotNull(list.get(0).getThumbnails());
}
示例5: deserializesMapDueToTypeErasure
import com.google.gson.internal.LinkedTreeMap; //导入方法依赖的package包/类
@Test
@SuppressWarnings("unchecked")
public void deserializesMapDueToTypeErasure() {
PositiveN one = positiveInt("1").getRight();
Optional<PositiveN> initialValue = Optional.of(one);
Class<Optional<PositiveN>> valueType = (Class<Optional<PositiveN>>)
initialValue.getClass();
Optional<PositiveN> readValue = writeThenRead(initialValue, valueType);
assertThat(readValue, is(not(initialValue)));
LinkedTreeMap<String, Double> deserialized = new LinkedTreeMap<>();
deserialized.put("wrappedValue", 1.0);
assertThat(readValue, is(Optional.of(deserialized))); // (*)
}
示例6: MapToHasSetTest
import com.google.gson.internal.LinkedTreeMap; //导入方法依赖的package包/类
@Test(timeout = 1000)
@Category({UnitTest.class})
public void MapToHasSetTest() {
Assert.assertTrue(HashMapHelper.mapToHashSet("", null).size() == 0);
LinkedTreeMap linkedTreeMap = new LinkedTreeMap();
linkedTreeMap.put("mapLevel3", "string value");
HashMap table = new HashMap<String, Object>() {
{
put("aString", "string value");
put("aBool", true);
put("aNumber", 12.3);
put("map1Level1", new HashMap<String, String>() {{
put("aString", "string value");
}});
put("map2Level1", new HashMap<String, Object>() {{
put("map2Level2-1", new HashMap<String, Object>() {
{
put("aString", "string value");
}
});
put("map2Level2-2", linkedTreeMap);
}});
}
};
HashSet<String> set = HashMapHelper.mapToHashSet("Tags", table);
List<String> expectedList = Arrays.asList(
"Tags.aString",
"Tags.aBool",
"Tags.aNumber",
"Tags.map1Level1.aString",
"Tags.map2Level1.map2Level2-1.aString",
"Tags.map2Level1.map2Level2-2.mapLevel3"
);
Assert.assertTrue(set.containsAll(expectedList));
Assert.assertTrue(expectedList.containsAll(set));
}
示例7: read
import com.google.gson.internal.LinkedTreeMap; //导入方法依赖的package包/类
public Object read(JsonReader jsonreader)
{
JsonToken jsontoken = jsonreader.peek();
switch (h.a[jsontoken.ordinal()])
{
default:
throw new IllegalStateException();
case 1: // '\001'
ArrayList arraylist = new ArrayList();
jsonreader.beginArray();
for (; jsonreader.hasNext(); arraylist.add(read(jsonreader))) { }
jsonreader.endArray();
return arraylist;
case 2: // '\002'
LinkedTreeMap linkedtreemap = new LinkedTreeMap();
jsonreader.beginObject();
for (; jsonreader.hasNext(); linkedtreemap.put(jsonreader.nextName(), read(jsonreader))) { }
jsonreader.endObject();
return linkedtreemap;
case 3: // '\003'
return jsonreader.nextString();
case 4: // '\004'
return Double.valueOf(jsonreader.nextDouble());
case 5: // '\005'
return Boolean.valueOf(jsonreader.nextBoolean());
case 6: // '\006'
jsonreader.nextNull();
return null;
}
}
示例8: getVolume
import com.google.gson.internal.LinkedTreeMap; //导入方法依赖的package包/类
/**
* Get volume of player
* @param callback Callback for the request
* @return ResponseFuture
*/
public Call getVolume(Callback callback) {
RpcRequest request;
if(Version.compare(mVersion, ZERO_VERSION)) {
request = new RpcRequest(VOLUME, RequestId.GET_VOLUME);
} else {
RpcResponse response = new RpcResponse();
LinkedTreeMap<String, Object> map = new LinkedTreeMap<String, Object>();
map.put(VOLUME, 1);
response.result = map;
callback.onCompleted(null, response);
return null;
}
return request(request, callback);
}
示例9: convertMapTest
import com.google.gson.internal.LinkedTreeMap; //导入方法依赖的package包/类
@Test
public void convertMapTest(){
mapConverter.setMapClass(Thumbnail.class);
Class type = Map.class;
LinkedTreeMap<String, Object> value = new LinkedTreeMap<>();
LinkedTreeMap<String, Object> innerMap = new LinkedTreeMap<>();
innerMap.put("url","http://example.com");
value.put("small",innerMap);
Map<String,Thumbnail> thumb = (Map<String,Thumbnail>) mapConverter.convert(type,value);
System.out.println(thumb);
assertNotNull(thumb);
assertNotNull(thumb.get("small"));
assertNotNull(thumb.get("small").getUrl());
}