Skip to content

Commit 7f5b751

Browse files
Addressed comments
1 parent 987af6d commit 7f5b751

File tree

2 files changed

+49
-4
lines changed

2 files changed

+49
-4
lines changed

google-cloud-spanner/clirr-ignored-differences.xml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1008,4 +1008,24 @@
10081008
<className>com/google/cloud/spanner/TransactionManager</className>
10091009
<method>com.google.cloud.spanner.TransactionContext begin(com.google.cloud.spanner.AbortedException)</method>
10101010
</difference>
1011+
<difference>
1012+
<differenceType>7012</differenceType>
1013+
<className>com/google/cloud/spanner/StructReader</className>
1014+
<method>java.lang.Object getOrNull(int, java.util.function.Function)</method>
1015+
</difference>
1016+
<difference>
1017+
<differenceType>7012</differenceType>
1018+
<className>com/google/cloud/spanner/StructReader</className>
1019+
<method>java.lang.Object getOrNull(java.lang.String, java.util.function.Function)</method>
1020+
</difference>
1021+
<difference>
1022+
<differenceType>7012</differenceType>
1023+
<className>com/google/cloud/spanner/StructReader</className>
1024+
<method>java.lang.Object getOrDefault(int, java.util.function.Function, java.lang.Object)</method>
1025+
</difference>
1026+
<difference>
1027+
<differenceType>7012</differenceType>
1028+
<className>com/google/cloud/spanner/StructReader</className>
1029+
<method>java.lang.Object getOrDefault(java.lang.String, java.util.function.Function, java.lang.Object)</method>
1030+
</difference>
10111031
</differences>

google-cloud-spanner/src/main/java/com/google/cloud/spanner/StructReader.java

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -178,31 +178,56 @@ default float getFloat(String columnName) {
178178

179179
/**
180180
* @param columnIndex index of the column
181-
* @return the value of a column with type T. return value(T) can be null.
181+
* @return the value of a column with type T or null if the column contains a null value
182+
* <p>Example
183+
*
184+
* <pre>{@code
185+
* Struct row = ...
186+
* String name = row.getOrNull(1, row::getString)
187+
* }</pre>
182188
*/
183189
default <T> T getOrNull(int columnIndex, Function<Integer, T> function) {
184190
return isNull(columnIndex) ? null : function.apply(columnIndex);
185191
}
186192

187193
/**
188194
* @param columnName index of the column
189-
* @return the value of a column with type T. return value(T) can be null.
195+
* @return the value of a column with type T or null if the column contains a null value
196+
* <p>Example
197+
*
198+
* <pre>{@code
199+
* Struct row = ...
200+
* String name = row.getOrNull("name", row::getString)
201+
* }</pre>
190202
*/
191203
default <T> T getOrNull(String columnName, Function<String, T> function) {
192204
return isNull(columnName) ? null : function.apply(columnName);
193205
}
194206

195207
/**
196208
* @param columnIndex index of the column
197-
* @return the value of a column with type T. if column value is null, returns default value.
209+
* @return the value of a column with type T, or the given default if the column value is null
210+
* <p>Example
211+
*
212+
* <pre>{@code
213+
* Struct row = ...
214+
* String name = row.getOrDefault(1, row::getString, "")
215+
* }</pre>
198216
*/
199217
default <T> T getOrDefault(int columnIndex, Function<Integer, T> function, T defaultValue) {
200218
return isNull(columnIndex) ? defaultValue : function.apply(columnIndex);
201219
}
202220

203221
/**
204222
* @param columnName name of the column
205-
* @return the value of a column with type T. if column value is null, returns default value.
223+
* @return the value of a column with type T, or the given default if the column value is null
224+
*
225+
* <p>Example
226+
*
227+
* <pre>{@code
228+
* Struct row = ...
229+
* String name = row.getOrDefault("name", row::getString, "")
230+
* }</pre>
206231
*/
207232
default <T> T getOrDefault(String columnName, Function<String, T> function, T defaultValue) {
208233
return isNull(columnName) ? defaultValue : function.apply(columnName);

0 commit comments

Comments
 (0)