8000 Fix nits in pom/README/concept snippets · nagabharat/java-docs-samples@63f756a · GitHub
[go: up one dir, main page]

Skip to content

Commit 63f756a

Browse files
author
Ajay Kannan
committed
Fix nits in pom/README/concept snippets
1 parent 7f34191 commit 63f756a

File tree

3 files changed

+37
-33
lines changed

3 files changed

+37
-33
lines changed

datastore/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@ This directory contains sample code used in Google Cloud Datastore documentation
1111

1212
2. Compile the program by typing `mvn clean compile` in command line.
1313

14-
3. Run the program by typing `mvn exec:java` in command line.
14+
3. Run the program by typing `mvn exec:java` in command line. In addition to listing tasks via this command line interface, you can view tasks you create in the [Google Cloud Developer's Console](https://console.cloud.google.com/).

datastore/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@
3131
<artifactId>maven-compiler-plugin</artifactId>
3232
<version>2.5.1</version>
3333
<configuration>
34-
<source>1.7</source>
35-
<target>1.7</target>
34+
<source>1.8</source>
35+
<target>1.8</target>
3636
</configuration>
3737
</plugin>
3838
<!-- // [END maven]-->

datastore/src/main/java/com/google/datastore/snippets/Concepts.java

Lines changed: 34 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import static org.junit.Assert.assertNull;
2525

2626
import com.google.common.collect.ImmutableList;
27+
import com.google.common.collect.ImmutableMap;
2728
import com.google.common.collect.ImmutableSet;
2829
import com.google.common.collect.Iterators;
2930
import com.google.gcloud.datastore.Cursor;
@@ -49,7 +50,6 @@
4950
import com.google.gcloud.datastore.StructuredQuery.Projection;
5051
import com.google.gcloud.datastore.StructuredQuery.PropertyFilter;
5152
import com.google.gcloud.datastore.Transaction;
52-
import com.google.gcloud.datastore.Value;
5353
import com.google.gcloud.datastore.testing.LocalGcdHelper;
5454

5555
import org.junit.AfterClass;
@@ -715,9 +715,8 @@ private Cursor cursorPaging(int pageSize, Cursor pageCursor) {
715715
queryBuilder.startCursor(pageCursor);
716716
}
717717
QueryResults<Entity> tasks = datastore.run(queryBuilder.build());
718-
Entity task;
719718
while (tasks.hasNext()) {
720-
task = tasks.next();
719+
Entity task = tasks.next();
721720
// do something with the task
722721
}
723722
Cursor nextPageCursor = tasks.cursorAfter();
@@ -919,17 +918,16 @@ public void testPropertyRunQuery() {
919918
Key property = results.next();
920919
String kind = property.ancestors().get(property.ancestors().size() - 1).name();
921920
String propertyName = property.name();
922-
if (!propertiesByKind.containsKey(kind)) {
923-
propertiesByKind.put(kind, new HashSet<String>());
921+
Collection<String> properties = propertiesByKind.get(kind);
922+
if (properties == null) {
923+
properties = new HashSet<>();
924+
propertiesByKind.put(kind, properties);
924925
}
925-
propertiesByKind.get(kind).add(propertyName);
926+
properties.add(propertyName);
926927
}
927928
// [END property_run_query]
928-
Map<String, Collection<String>> expected = new HashMap<>();
929-
expected.put(
930-
"Task",
931-
ImmutableSet.of(
932-
"done", "type", "done", "completed", "priority", "created", "percent_complete", "tag"));
929+
Map<String, ImmutableSet<String>> expected = ImmutableMap.of("Task", ImmutableSet.of(
930+
"done", "type", "done", "completed", "priority", "created", "percent_complete", "tag"));
933931
assertEquals(expected, propertiesByKind);
934932
}
935933

@@ -940,30 +938,34 @@ public void testPropertyByKindRunQuery() {
940938
Key key = datastore.newKeyFactory().kind("__kind__").newKey("Task");
941939
Query<Entity> query = Query.entityQueryBuilder()
942940
.kind("__property__")
943-
.filter(PropertyFilter.hasAncestor(key))
941+
.filter(PropertyFilter.hasAncestor(key))
944942
.build();
945943
QueryResults<Entity> results = datastore.run(query);
946944
Map<String, Collection<String>> representationsByProperty = new HashMap<>();
947945
while (results.hasNext()) {
948946
Entity property = results.next();
949947
String propertyName = property.key().name();
950-
List<? extends Value<?>> representations = property.getList("property_representation");
951-
if (!representationsByProperty.containsKey(propertyName)) {
952-
representationsByProperty.put(propertyName, new HashSet<String>());
948+
List<StringValue> representations =
949+
(List<StringValue>) property.getList("property_representation");
950+
Collection<String> currentRepresentations = representationsByProperty.get(propertyName);
951+
if (currentRepresentations == null) {
952+
currentRepresentations = new HashSet<>();
953+
representationsByProperty.put(propertyName, currentRepresentations);
953954
}
954-
for (Value<?> value : representations) {
955-
representationsByProperty.get(propertyName).add((String) value.get());
955+
for (StringValue value : representations) {
956+
currentRepresentations.add(value.get());
956957
}
957958
}
958959
// [END property_by_kind_run_query]
959-
Map<String, Collection<String>> expected = new HashMap<>();
960-
expected.put("type", Collections.singleton("STRING"));
961-
expected.put("done", Collections.singleton("BOOLEAN"));
962-
expected.put("completed", Collections.singleton("BOOLEAN"));
963-
expected.put("priority", Collections.singleton("INT64"));
964-
expected.put("created", Collections.singleton("INT64"));
965-
expected.put("percent_complete", Collections.singleton("DOUBLE"));
966-
expected.put("tag", Collections.singleton("STRING"));
960+
Map<String, Collection<String>> expected = ImmutableMap.<String, Collection<String>>builder()
961+
.put("type", Collections.singleton("STRING"))
962+
.put("done", Collections.singleton("BOOLEAN"))
963+
.put("completed", Collections.singleton("BOOLEAN"))
964+
.put("priority", Collections.singleton("INT64"))
965+
.put("created", Collections.singleton("INT64"))
966+
.put("percent_complete", Collections.singleton("DOUBLE"))
967+
.put("tag", Collections.singleton("STRING"))
968+
.build();
967969
assertEquals(expected, representationsByProperty);
968970
}
969971

@@ -986,14 +988,16 @@ public void testPropertyFilteringRunQuery() {
986988
Key property = results.next();
987989
String kind = property.ancestors().get(property.ancestors().size() - 1).name();
988990
String propertyName = property.name();
989-
if (!propertiesByKind.containsKey(kind)) {
990-
propertiesByKind.put(kind, new HashSet<String>());
991+
Collection<String> properties = propertiesByKind.get(kind);
992+
if (properties == null) {
993+
properties = new HashSet<String>();
994+
propertiesByKind.put(kind, properties);
991995
}
992-
propertiesByKind.get(kind).add(propertyName);
996+
properties.add(propertyName);
993997
}
994998
// [END property_filtering_run_query]
995-
Map<String, Collection<String>> expected = new HashMap<>();
996-
expected.put("Task", ImmutableSet.of("priority", "tag", "type"));
999+
Map<String, ImmutableSet<String>> expected =
1000+
ImmutableMap.of("Task", ImmutableSet.of("priority", "tag", "type"));
9971001
assertEquals(expected, propertiesByKind);
9981002
}
9991003

0 commit comments

Comments
 (0)
0