Elffuss BraidHub

kikocis/java-driver public

Merge pull request #506 from datastax/java921

Add SimpleStatement.getValuesCount() (JAVA-921).
Changeset4a4ffe7ce8ed6523ed65b8ec8157344631174447c0db834e5e380b2e02df364a
AuthorOlivier Michallat <olim7t@users.noreply.github.com> · 2015-10-30 16:35 +01:00
CommitterOlivier Michallat <olim7t@users.noreply.github.com> · 2015-10-30 16:35 +01:00
Parents93c7dfb4d9c2, b4617e6d2b80

Browse the files at this changeset

3 files changed

modified changelog/README.md +1 −0
@@ -6,6 +6,7 @@
66 - [improvement] JAVA-920: Downgrade "error creating pool" message to WARN.
77 - [bug] JAVA-954: Don't trigger reconnection before initialization complete.
88 - [improvement] JAVA-914: Avoid rejected tasks at shutdown.
9+- [improvement] JAVA-921: Add SimpleStatement.getValuesCount().
910
1011
1112 ### 2.0.11
modified driver-core/src/main/java/com/datastax/driver/core/SimpleStatement.java +12 −0
@@ -117,6 +117,18 @@
117117 return values == null ? null : convert(values);
118118 }
119119
120+ /**
121+ * Returns the number of values provided for this statement.
122+ * <p>
123+ * This is more efficient than calling {@link #getValues()} and getting the length
124+ * of the returned array, because {@code getValues()} does some internal conversions.
125+ *
126+ * @return the number of values.
127+ */
128+ public int getValuesCount() {
129+ return values == null ? 0 : values.length;
130+ }
131+
120132 /**
121133 * Returns the {@code i}th value as the Java type matching its CQL type.
122134 *
modified driver-core/src/test/java/com/datastax/driver/core/SimpleStatementTest.java +10 −0
@@ -48,4 +48,14 @@
4848 assertThat(actual).isSameAs(expected);
4949 }
5050
51+ @Test(groups = "unit")
52+ public void should_return_number_of_values() {
53+ assertThat(
54+ new SimpleStatement("doesn't matter").getValuesCount()
55+ ).isEqualTo(0);
56+ assertThat(
57+ new SimpleStatement("doesn't matter", 1, 2).getValuesCount()
58+ ).isEqualTo(2);
59+ }
60+
5161 }