Skip to content

Commit 8050cca

Browse files
author
Ajay Kannan
committed
Cleaner getList return value
1 parent a68a0b6 commit 8050cca

2 files changed

Lines changed: 14 additions & 3 deletions

File tree

gcloud-java-datastore/src/main/java/com/google/gcloud/datastore/BaseEntity.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -437,8 +437,8 @@ public <K extends IncompleteKey> FullEntity<K> getEntity(String name) {
437437
* @throws ClassCastException if value is not a list of values
438438
*/
439439
@SuppressWarnings("unchecked")
440-
public List<? extends Value<?>> getList(String name) {
441-
return ((Value<List<? extends Value<?>>>) getValue(name)).get();
440+
public <T extends Value<?>> List<T> getList(String name) {
441+
return (List<T>) getValue(name).get();
442442
}
443443

444444
/**

gcloud-java-datastore/src/test/java/com/google/gcloud/datastore/BaseEntityTest.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public void setUp() {
7474
builder.set("doubleList", 12.3, 4.56, .789);
7575
builder.set("keyList", KEY, Key.builder("ds2", "k2", "n2").build(),
7676
Key.builder("ds3", "k3", "n3").build());
77-
builder.set("entityList", ENTITY, PARTIAL_ENTITY, ENTITY);
77+
builder.set("entityList", ENTITY, PARTIAL_ENTITY);
7878
builder.set("stringList", "s1", "s2", "s3");
7979
builder.set("longList", 1, 23, 456);
8080
}
@@ -193,6 +193,17 @@ public void testGetList() throws Exception {
193193
assertEquals(Boolean.TRUE, list.get(0).get());
194194
entity = builder.set("list1", ListValue.of(list)).build();
195195
assertEquals(list, entity.getList("list1"));
196+
List<Value<?>> stringList = entity.getList("stringList");
197+
assertEquals(
198+
ImmutableList.of(StringValue.of("s1"), StringValue.of("s2"), StringValue.of("s3")),
199+
stringList);
200+
List<Value<Double>> doubleList = entity.getList("doubleList");
201+
assertEquals(
202+
ImmutableList.of(DoubleValue.of(12.3), DoubleValue.of(4.56), DoubleValue.of(.789)),
203+
doubleList);
204+
List<EntityValue> entityList = entity.getList("entityList");
205+
assertEquals(
206+
ImmutableList.of(EntityValue.of(ENTITY), EntityValue.of(PARTIAL_ENTITY)), entityList);
196207
}
197208

198209
@Test

0 commit comments

Comments
 (0)