Skip to content

Commit 28c5d62

Browse files
committed
change Value generics
1 parent 63c28d4 commit 28c5d62

22 files changed

Lines changed: 366 additions & 147 deletions

checkstyle.xml

Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE module PUBLIC "-//Puppy Crawl//DTD Check Configuration 1.3//EN" "http://www.puppycrawl.com/dtds/configuration_1_3.dtd">
3+
4+
<!--
5+
This configuration file was written by the eclipse-cs plugin configuration editor
6+
-->
7+
<!--
8+
Checkstyle-Configuration: Copy of Google Checks
9+
Description:
10+
Checkstyle configurartion that checks the Google coding conventions (https://google-styleguide.googlecode.com/svn-history/r130/trunk/javaguide.html).
11+
-->
12+
<module name="Checker">
13+
<property name="severity" value="warning"/>
14+
<property name="charset" value="UTF-8"/>
15+
<module name="TreeWalker">
16+
<module name="OuterTypeFilename"/>
17+
<module name="IllegalTokenText">
18+
<property name="tokens" value="STRING_LITERAL, CHAR_LITERAL"/>
19+
<property name="format" value="\\u00(08|09|0(a|A)|0(c|C)|0(d|D)|22|27|5(C|c))|\\(0(10|11|12|14|15|42|47)|134)"/>
20+
<property name="message" value="Avoid using corresponding octal or Unicode escape."/>
21+
</module>
22+
<module name="AvoidEscapedUnicodeCharacters">
23+
<property name="allowEscapesForControlCharacters" value="true"/>
24+
<property name="allowByTailComment" value="true"/>
25+
<property name="allowNonPrintableEscapes" value="true"/>
26+
</module>
27+
<module name="LineLength">
28+
<property name="ignorePattern" value="^package.*|^import.*|a href|href|http://|https://|ftp://"/>
29+
<property name="max" value="100"/>
30+
</module>
31+
<module name="AvoidStarImport"/>
32+
<module name="OneTopLevelClass"/>
33+
<module name="NoLineWrap"/>
34+
<module name="EmptyBlock">
35+
<property name="option" value="TEXT"/>
36+
<property name="tokens" value="LITERAL_TRY, LITERAL_CATCH, LITERAL_FINALLY, LITERAL_IF, LITERAL_ELSE, LITERAL_SWITCH"/>
37+
</module>
38+
<module name="NeedBraces"/>
39+
<module name="LeftCurly">
40+
<property name="maxLineLength" value="100"/>
41+
</module>
42+
<module name="RightCurly"/>
43+
<module name="RightCurly">
44+
<property name="option" value="alone"/>
45+
<property name="tokens" value="CLASS_DEF, METHOD_DEF, CTOR_DEF, LITERAL_FOR, LITERAL_WHILE, LITERAL_DO, STATIC_INIT, INSTANCE_INIT"/>
46+
</module>
47+
<module name="WhitespaceAround">
48+
<property name="allowEmptyConstructors" value="true"/>
49+
<property name="allowEmptyMethods" value="true"/>
50+
<property name="allowEmptyTypes" value="true"/>
51+
<property name="allowEmptyLoops" value="true"/>
52+
<message key="ws.notFollowed" value="WhitespaceAround: ''{0}'' is not followed by whitespace."/>
53+
<message key="ws.notPreceded" value="WhitespaceAround: ''{0}'' is not preceded with whitespace."/>
54+
</module>
55+
<module name="OneStatementPerLine"/>
56+
<module name="MultipleVariableDeclarations"/>
57+
<module name="ArrayTypeStyle"/>
58+
<module name="MissingSwitchDefault"/>
59+
<module name="FallThrough"/>
60+
<module name="UpperEll"/>
61+
<module name="ModifierOrder"/>
62+
<module name="EmptyLineSeparator">
63+
<property name="allowNoEmptyLineBetweenFields" value="true"/>
64+
</module>
65+
<module name="SeparatorWrap">
66+
<property name="option" value="nl"/>
67+
<property name="tokens" value="DOT"/>
68+
</module>
69+
<module name="SeparatorWrap">
70+
<property name="option" value="EOL"/>
71+
<property name="tokens" value="COMMA"/>
72+
</module>
73+
<module name="PackageName">
74+
<property name="format" value="^[a-z]+(\.[a-z][a-z0-9]*)*$"/>
75+
<message key="name.invalidPattern" value="Package name ''{0}'' must match pattern ''{1}''."/>
76+
</module>
77+
<module name="TypeName">
78+
<message key="name.invalidPattern" value="Type name ''{0}'' must match pattern ''{1}''."/>
79+
</module>
80+
<module name="MemberName">
81+
<property name="format" value="^[a-z][a-z0-9][a-zA-Z0-9]*$"/>
82+
<message key="name.invalidPattern" value="Member name ''{0}'' must match pattern ''{1}''."/>
83+
</module>
84+
<module name="ParameterName">
85+
<property name="format" value="^[a-z][a-z0-9][a-zA-Z0-9]*$"/>
86+
<message key="name.invalidPattern" value="Parameter name ''{0}'' must match pattern ''{1}''."/>
87+
</module>
88+
<module name="LocalVariableName">
89+
<property name="format" value="^[a-z][a-z0-9][a-zA-Z0-9]*$"/>
90+
<property name="allowOneCharVarInForLoop" value="true"/>
91+
<property name="tokens" value="VARIABLE_DEF"/>
92+
<message key="name.invalidPattern" value="Local variable name ''{0}'' must match pattern ''{1}''."/>
93+
</module>
94+
<module name="ClassTypeParameterName">
95+
<property name="format" value="(^[A-Z][0-9]?)$|([A-Z][a-zA-Z0-9]*[T]$)"/>
96+
<message key="name.invalidPattern" value="Class type name ''{0}'' must match pattern ''{1}''."/>
97+
</module>
98+
<module name="MethodTypeParameterName">
99+
<property name="format" value="(^[A-Z][0-9]?)$|([A-Z][a-zA-Z0-9]*[T]$)"/>
100+
<message key="name.invalidPattern" value="Method type name ''{0}'' must match pattern ''{1}''."/>
101+
</module>
102+
<module name="NoFinalizer"/>
103+
<module name="GenericWhitespace">
104+
<message key="ws.followed" value="GenericWhitespace ''{0}'' is followed by whitespace."/>
105+
<message key="ws.illegalFollow" value="GenericWhitespace ''{0}'' should followed by whitespace."/>
106+
<message key="ws.preceded" value="GenericWhitespace ''{0}'' is preceded with whitespace."/>
107+
<message key="ws.notPreceded" value="GenericWhitespace ''{0}'' is not preceded with whitespace."/>
108+
</module>
109+
<module name="Indentation">
110+
<property name="basicOffset" value="2"/>
111+
<property name="caseIndent" value="2"/>
112+
<property name="arrayInitIndent" value="2"/>
113+
</module>
114+
<module name="AbbreviationAsWordInName">
115+
<property name="allowedAbbreviationLength" value="1"/>
116+
<property name="ignoreFinal" value="false"/>
117+
</module>
118+
<module name="OverloadMethodsDeclarationOrder"/>
119+
<module name="VariableDeclarationUsageDistance"/>
120+
<module name="CustomImportOrder">
121+
<property name="customImportOrderRules" value="STATIC###SPECIAL_IMPORTS###THIRD_PARTY_PACKAGE###STANDARD_JAVA_PACKAGE"/>
122+
<property name="thirdPartyPackageRegExp" value=".*"/>
123+
<property name="specialImportsRegExp" value="com.google"/>
124+
<property name="sortImportsInGroupAlphabetically" value="true"/>
125+
</module>
126+
<module name="MethodParamPad"/>
127+
<module name="OperatorWrap">
128+
<property name="option" value="NL"/>
129+
<property name="tokens" value="BAND, BOR, BSR, BXOR, DIV, EQUAL, GE, GT, LAND, LE, LITERAL_INSTANCEOF, LOR, LT, MINUS, MOD, NOT_EQUAL, PLUS, QUESTION, SL, SR, STAR "/>
130+
</module>
131+
<module name="AnnotationLocation">
132+
<property name="tokens" value="CLASS_DEF, INTERFACE_DEF, ENUM_DEF, METHOD_DEF, CTOR_DEF"/>
133+
</module>
134+
<module name="AnnotationLocation">
135+
<property name="tokens" value="VARIABLE_DEF"/>
136+
<property name="allowSamelineMultipleAnnotations" value="true"/>
137+
</module>
138+
<module name="NonEmptyAtclauseDescription"/>
139+
<module name="JavadocTagContinuationIndentation"/>
140+
<module name="SummaryJavadocCheck"/>
141+
<module name="JavadocParagraph"/>
142+
<module name="AtclauseOrder">
143+
<property name="target" value="CLASS_DEF, INTERFACE_DEF, ENUM_DEF, METHOD_DEF, CTOR_DEF, VARIABLE_DEF"/>
144+
<property name="tagOrder" value="@param, @return, @throws, @deprecated"/>
145+
</module>
146+
<module name="JavadocMethod">
147+
<property name="minLineCount" value="2"/>
148+
<property name="allowedAnnotations" value="Override, Test"/>
149+
<property name="scope" value="public"/>
150+
<property name="allowThrowsTagsForSubclasses" value="true"/>
151+
<property name="allowMissingParamTags" value="true"/>
152+
<property name="allowMissingThrowsTags" value="true"/>
153+
<property name="allowMissingReturnTag" value="true"/>
154+
</module>
155+
<module name="MethodName">
156+
<property name="format" value="^[a-z][a-z0-9][a-zA-Z0-9_]*$"/>
157+
<message key="name.invalidPattern" value="Method name ''{0}'' must match pattern ''{1}''."/>
158+
</module>
159+
<module name="SingleLineJavadoc"/>
160+
<module name="ImportOrder"/>
161+
</module>
162+
<module name="FileTabCharacter">
163+
<property name="eachLine" value="true"/>
164+
</module>
165+
</module>

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

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ abstract class BaseEntity extends Serializable<DatastoreV1.Entity> {
1717

1818
private static final long serialVersionUID = 8175618724683792766L;
1919

20-
private final transient ImmutableSortedMap<String, Value<?, ?, ?>> properties;
20+
private final transient ImmutableSortedMap<String, Value<?>> properties;
2121

2222
protected abstract static class Builder<E extends BaseEntity, B extends Builder<E, B>> {
2323

24-
private final Map<String, Value<?, ?, ?>> properties;
24+
private final Map<String, Value<?>> properties;
2525

2626
protected Builder() {
2727
properties = new HashMap<>();
@@ -46,7 +46,7 @@ public B removeProperty(String name) {
4646
return self();
4747
}
4848

49-
public B setProperty(String name, Value<?, ?, ?> value) {
49+
public B setProperty(String name, Value<?> value) {
5050
properties.put(name, value);
5151
return self();
5252
}
@@ -91,12 +91,12 @@ public B setEntityProperty(String name, PartialEntity value) {
9191
return self();
9292
}
9393

94-
public B setListProperty(String name, List<? extends Value<?, ?, ?>> values) {
94+
public B setListProperty(String name, List<? extends Value<?>> values) {
9595
properties.put(name, new ListValue(values));
9696
return self();
9797
}
9898

99-
public B setListProperty(String name, Value<?, ?, ?>... value) {
99+
public B setListProperty(String name, Value<?>... value) {
100100
properties.put(name, new ListValue(Arrays.asList(value)));
101101
return self();
102102
}
@@ -110,10 +110,10 @@ public E build() {
110110
return build(ImmutableSortedMap.copyOf(properties));
111111
}
112112

113-
protected abstract E build(ImmutableSortedMap<String, Value<?, ?, ?>> properties);
113+
protected abstract E build(ImmutableSortedMap<String, Value<?>> properties);
114114
}
115115

116-
protected BaseEntity(ImmutableSortedMap<String, Value<?, ?, ?>> properties) {
116+
protected BaseEntity(ImmutableSortedMap<String, Value<?>> properties) {
117117
this.properties = properties;
118118
}
119119

@@ -129,7 +129,7 @@ public boolean hasProperty(String name) {
129129
*
130130
* @throws DatastoreServiceException if not such property.
131131
*/
132-
public <V extends Value<?, ?, ?>> V property(String name) {
132+
public <V extends Value<?>> V property(String name) {
133133
@SuppressWarnings("unchecked")
134134
V property = (V) properties.get(name);
135135
if (property == null) {
@@ -175,7 +175,7 @@ public <T extends PartialEntity> T entityProperty(String name) {
175175
return (T) ((EntityValue) property(name)).get();
176176
}
177177

178-
public List<? extends Value<?, ?, ?>> listProperty(String name) {
178+
public List<? extends Value<?>> listProperty(String name) {
179179
return ((ListValue) property(name)).get();
180180
}
181181

@@ -187,7 +187,7 @@ public Blob blobProperty(String name) {
187187
* Returns the property's value as a {@link RawValue}.
188188
*/
189189
public RawValue asRawValueProperty(String name) {
190-
Value<?, ?, ?> value = property(name);
190+
Value<?> value = property(name);
191191
if (value instanceof RawValue) {
192192
return (RawValue) value;
193193
}
@@ -198,14 +198,14 @@ public Set<String> propertyNames() {
198198
return properties.keySet();
199199
}
200200

201-
ImmutableSortedMap<String, Value<?, ?, ?>> properties() {
201+
ImmutableSortedMap<String, Value<?>> properties() {
202202
return properties;
203203
}
204204

205205
@Override
206206
protected final DatastoreV1.Entity toPb() {
207207
DatastoreV1.Entity.Builder entityPb = DatastoreV1.Entity.newBuilder();
208-
for (Map.Entry<String, Value<?, ?, ?>> entry : properties.entrySet()) {
208+
for (Map.Entry<String, Value<?>> entry : properties.entrySet()) {
209209
DatastoreV1.Property.Builder propertyPb = DatastoreV1.Property.newBuilder();
210210
propertyPb.setName(entry.getKey());
211211
propertyPb.setValue(entry.getValue().toPb());

src/main/java/com/google/gcloud/datastore/BaseKey.java

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,15 @@ abstract class BaseKey extends Serializable<DatastoreV1.Key> {
2121

2222
private final transient String dataset;
2323
private final transient String namespace;
24-
private final transient ImmutableList<KeyPathElement> ancestors;
24+
private final transient ImmutableList<PathElement> ancestors;
2525
private final transient String kind;
2626

2727
abstract static class Builder<K extends PartialKey, B extends Builder<K, B>> {
2828

2929
private String dataset;
3030
private String namespace;
3131
private String kind;
32-
private final List<KeyPathElement> ancestors;
32+
private final List<PathElement> ancestors;
3333

3434
private static final int MAX_PATH = 100;
3535

@@ -53,26 +53,26 @@ protected B self() {
5353

5454
public B addAncestor(String kind, long id) {
5555
checkArgument(id != 0, "id must not be equal to zero");
56-
return addAncestor(new KeyPathElement(kind, id));
56+
return addAncestor(new PathElement(kind, id));
5757
}
5858

5959
public B addAncestor(String kind, String name) {
6060
checkArgument(Strings.isNullOrEmpty(name) , "name must not be empty or null");
6161
checkArgument(name.length() <= 500, "name must not exceed 500 characters");
62-
return addAncestor(new KeyPathElement(kind, name));
62+
return addAncestor(new PathElement(kind, name));
6363
}
6464

65-
public B addAncestor(KeyPathElement... ancestor) {
65+
public B addAncestor(PathElement... ancestor) {
6666
Preconditions.checkState(ancestors.size() + ancestor.length <= MAX_PATH,
6767
"path can have at most 100 elements");
68-
for (KeyPathElement pathElement : ancestor) {
68+
for (PathElement pathElement : ancestor) {
6969
ancestors.add(pathElement);
7070
}
7171
return self();
7272
}
7373

74-
public B addAncestors(Iterable<KeyPathElement> ancestors) {
75-
for (KeyPathElement pathElement : ancestors) {
74+
public B addAncestors(Iterable<PathElement> ancestors) {
75+
for (PathElement pathElement : ancestors) {
7676
addAncestor(pathElement);
7777
}
7878
return self();
@@ -109,10 +109,10 @@ public K build() {
109109
}
110110

111111
protected abstract K build(
112-
String dataset, String namespace, ImmutableList<KeyPathElement> ancestors, String kind);
112+
String dataset, String namespace, ImmutableList<PathElement> ancestors, String kind);
113113
}
114114

115-
BaseKey(String dataset, String namespace, ImmutableList<KeyPathElement> ancestors, String kind) {
115+
BaseKey(String dataset, String namespace, ImmutableList<PathElement> ancestors, String kind) {
116116
this.dataset = dataset;
117117
this.namespace = namespace;
118118
this.ancestors = ancestors;
@@ -136,7 +136,7 @@ public String namespace() {
136136
/**
137137
* Returns an immutable list with the key's ancestors.
138138
*/
139-
public List<KeyPathElement> ancestors() {
139+
public List<PathElement> ancestors() {
140140
return ancestors;
141141
}
142142

@@ -160,16 +160,12 @@ protected DatastoreV1.Key toPb() {
160160
if (partitionIdPb.hasDatasetId() || partitionIdPb.hasNamespace()) {
161161
keyPb.setPartitionId(partitionIdPb.build());
162162
}
163-
for (KeyPathElement pathEntry : ancestors) {
163+
for (PathElement pathEntry : ancestors) {
164164
keyPb.addPathElement(pathEntry.toPb());
165165
}
166166
addLeaf(keyPb);
167167
return keyPb.build();
168168
}
169169

170-
protected void addLeaf(DatastoreV1.Key.Builder keyPb) {
171-
if (kind != null) {
172-
keyPb.addPathElement(new KeyPathElement(kind).toPb());
173-
}
174-
}
170+
protected abstract void addLeaf(DatastoreV1.Key.Builder keyPb);
175171
}

src/main/java/com/google/gcloud/datastore/BlobValue.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
import com.google.api.services.datastore.DatastoreV1;
66

7-
public final class BlobValue extends Value<Blob, BlobValue, BlobValue.Builder> {
7+
public final class BlobValue extends Value<Blob> {
88

99
private static final long serialVersionUID = -5096238337676649540L;
1010

@@ -52,6 +52,11 @@ private BlobValue(Builder builder) {
5252
super(builder);
5353
}
5454

55+
@Override
56+
public Builder toBuilder() {
57+
return new Builder().mergeFrom(this);
58+
}
59+
5560
public static Builder builder(Blob blob) {
5661
return new Builder().set(blob);
5762
}

src/main/java/com/google/gcloud/datastore/BooleanValue.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
import com.google.api.services.datastore.DatastoreV1;
66

7-
public final class BooleanValue extends Value<Boolean, BooleanValue, BooleanValue.Builder> {
7+
public final class BooleanValue extends Value<Boolean> {
88

99
private static final long serialVersionUID = -542649497897250340L;
1010

@@ -52,6 +52,11 @@ private BooleanValue(Builder builder) {
5252
super(builder);
5353
}
5454

55+
@Override
56+
public Builder toBuilder() {
57+
return new Builder().mergeFrom(this);
58+
}
59+
5560
public static Builder builder(boolean value) {
5661
return new Builder().set(value);
5762
}

0 commit comments

Comments
 (0)