2020
2121package org .spine3 .base ;
2222
23- import com .google .protobuf .Any ;
2423import com .google .protobuf .Message ;
2524import org .spine3 .protobuf .AnyPacker ;
2625
2726import javax .annotation .Nullable ;
2827
2928import static org .spine3 .protobuf .Values .pack ;
3029
31-
32- /** Factories for constructing {@link ValueMismatch} instances for different types of attributes. */
30+ /**
31+ * Factories for constructing {@link ValueMismatch} instances for different types of attributes.
32+ *
33+ * @author Alexander Yevsyukov
34+ * @author Andrey Lavrov
35+ */
3336public class Mismatch {
3437
3538 private Mismatch () {
@@ -38,148 +41,120 @@ private Mismatch() {
3841 /**
3942 * Creates a {@link ValueMismatch} instance for a string attribute.
4043 *
41- * @param expected the value expected by a command, or {@code null} if the command expects not populated field
42- * @param actual the value found in an entity, or {@code null} if the value is not set
43- * @param requested the value requested as new one in the original command
44- * @param version the current version of the entity
44+ * @param expected the value expected by a command, or {@code null} if the command expects not populated field
45+ * @param actual the value found in an entity, or {@code null} if the value is not set
46+ * @param version the current version of the entity
4547 * @return info on the mismatch
4648 */
47- public static ValueMismatch of (@ Nullable String expected , @ Nullable String actual , String requested , int version ) {
49+ public static ValueMismatch of (@ Nullable String expected , @ Nullable String actual , int version ) {
4850 final ValueMismatch .Builder builder = ValueMismatch .newBuilder ();
4951 if (expected != null ) {
5052 builder .setExpected (pack (expected ));
5153 }
52-
5354 if (actual != null ) {
5455 builder .setActual (pack (actual ));
5556 }
56-
57- builder .setRequested (pack (requested ));
5857 builder .setVersion (version );
59-
6058 return builder .build ();
6159 }
6260
6361 /**
6462 * Creates a {@link ValueMismatch} instance for a integer attribute.
6563 *
66- * @param expected the value expected by a command
67- * @param actual the value actual in an entity
68- * @param requested the value requested as new one in the original command
69- * @param version the current version of the entity
64+ * @param expected the value expected by a command
65+ * @param actual the value actual in an entity
66+ * @param version the current version of the entity
7067 * @return info on the mismatch
7168 */
72- public static ValueMismatch of (int expected , int actual , int requested , int version ) {
73- final ValueMismatch .Builder builder = ValueMismatch .newBuilder ();
74- builder .setExpected (pack (expected ));
75- builder .setActual (pack (actual ));
76- builder .setRequested (pack (requested ));
77- builder .setVersion (version );
78-
69+ public static ValueMismatch of (int expected , int actual , int version ) {
70+ final ValueMismatch .Builder builder = ValueMismatch .newBuilder ()
71+ .setExpected (pack (expected ))
72+ .setActual (pack (actual ))
73+ .setVersion (version );
7974 return builder .build ();
8075 }
8176
8277 /**
8378 * Creates a {@link ValueMismatch} instance for a long integer attribute.
8479 *
85- * @param expected the value expected by a command
86- * @param actual the value actual in an entity
87- * @param requested the value requested as new one in the original command
88- * @param version the current version of the entity
80+ * @param expected the value expected by a command
81+ * @param actual the value actual in an entity
82+ * @param version the current version of the entity
8983 * @return info on the mismatch
9084 */
91- public static ValueMismatch of (long expected , long actual , long requested , int version ) {
92- final ValueMismatch .Builder builder = ValueMismatch .newBuilder ();
93- builder .setExpected (pack (expected ));
94- builder .setActual (pack (actual ));
95- builder .setRequested (pack (requested ));
96- builder .setVersion (version );
97-
85+ public static ValueMismatch of (long expected , long actual , int version ) {
86+ final ValueMismatch .Builder builder = ValueMismatch .newBuilder ()
87+ .setExpected (pack (expected ))
88+ .setActual (pack (actual ))
89+ .setVersion (version );
9890 return builder .build ();
9991 }
10092
10193 /**
10294 * Creates a {@link ValueMismatch} instance for a float attribute.
10395 *
104- * @param expected the value expected by a command
105- * @param actual the value actual in an entity
106- * @param requested the value requested as new one in the original command
107- * @param version the current version of the entity
96+ * @param expected the value expected by a command
97+ * @param actual the value actual in an entity
98+ * @param version the current version of the entity
10899 * @return info on the mismatch
109100 */
110- public static ValueMismatch of (float expected , float actual , float requested , int version ) {
111- final ValueMismatch .Builder builder = ValueMismatch .newBuilder ();
112- builder .setExpected (pack (expected ));
113- builder .setActual (pack (actual ));
114- builder .setRequested (pack (requested ));
115- builder .setVersion (version );
116-
101+ public static ValueMismatch of (float expected , float actual , int version ) {
102+ final ValueMismatch .Builder builder = ValueMismatch .newBuilder ()
103+ .setExpected (pack (expected ))
104+ .setActual (pack (actual ))
105+ .setVersion (version );
117106 return builder .build ();
118107 }
119108
120109 /**
121110 * Creates a {@link ValueMismatch} instance for a double attribute.
122111 *
123- * @param expected the value expected by a command
124- * @param actual the value actual in an entity
125- * @param requested the value requested as new one in the original command
126- * @param version the current version of the entity
112+ * @param expected the value expected by a command
113+ * @param actual the value actual in an entity
114+ * @param version the current version of the entity
127115 * @return info on the mismatch
128116 */
129- public static ValueMismatch of (double expected , double actual , double requested , int version ) {
130- final ValueMismatch .Builder builder = ValueMismatch .newBuilder ();
131- builder .setExpected (pack (expected ));
132- builder .setActual (pack (actual ));
133- builder .setRequested (pack (requested ));
134- builder .setVersion (version );
135-
117+ public static ValueMismatch of (double expected , double actual , int version ) {
118+ final ValueMismatch .Builder builder = ValueMismatch .newBuilder ()
119+ .setExpected (pack (expected ))
120+ .setActual (pack (actual ))
121+ .setVersion (version );
136122 return builder .build ();
137123 }
138124
139125 /**
140126 * Creates a {@link ValueMismatch} instance for a boolean attribute.
141127 *
142- * @param expected the value expected by a command
143- * @param actual the value actual in an entity
144- * @param requested the value requested as new one in the original command
145- * @param version the current version of the entity
128+ * @param expected the value expected by a command
129+ * @param actual the value actual in an entity
130+ * @param version the current version of the entity
146131 * @return info on the mismatch
147132 */
148- public static ValueMismatch of (boolean expected , boolean actual , boolean requested , int version ) {
149- final ValueMismatch .Builder builder = ValueMismatch .newBuilder ();
150- builder .setExpected (pack (expected ));
151- builder .setActual (pack (actual ));
152- builder .setRequested (pack (requested ));
153- builder .setVersion (version );
154-
133+ public static ValueMismatch of (boolean expected , boolean actual , int version ) {
134+ final ValueMismatch .Builder builder = ValueMismatch .newBuilder ()
135+ .setExpected (pack (expected ))
136+ .setActual (pack (actual ))
137+ .setVersion (version );
155138 return builder .build ();
156139 }
157140
158141 /**
159142 * Creates a {@link ValueMismatch} instance for a Message attribute.
160143 *
161- * @param expected the value expected by a command, or {@code null} if the command expects not populated field
162- * @param actual the value actual in an entity, or {@code null} if the value is not set
163- * @param requested the value requested as new one in the original command
164- * @param version the current version of the entity
144+ * @param expected the value expected by a command, or {@code null} if the command expects not populated field
145+ * @param actual the value actual in an entity, or {@code null} if the value is not set
146+ * @param version the current version of the entity
165147 * @return info on the mismatch
166148 */
167- public static ValueMismatch of (@ Nullable Message expected , @ Nullable Message actual , Message requested , int version ) {
149+ public static ValueMismatch of (@ Nullable Message expected , @ Nullable Message actual , int version ) {
168150 final ValueMismatch .Builder builder = ValueMismatch .newBuilder ();
169-
170151 if (expected != null ) {
171152 builder .setExpected (AnyPacker .pack (expected ));
172153 }
173-
174154 if (actual != null ) {
175155 builder .setActual (AnyPacker .pack (actual ));
176156 }
177-
178- final Any requestedAny = AnyPacker .pack (requested );
179-
180- builder .setRequested (requestedAny );
181157 builder .setVersion (version );
182-
183158 return builder .build ();
184159 }
185160}
0 commit comments