2323import com .google .protobuf .ByteString ;
2424import com .google .protobuf .Timestamp ;
2525
26- import static com .google .common .base .Preconditions .checkArgument ;
2726import static com .google .common .base .Preconditions .checkNotNull ;
27+ import static org .spine3 .change .Preconditions .checkNewValueNotEmpty ;
28+ import static org .spine3 .change .Preconditions .checkNotEqual ;
2829
2930/**
3031 * Utility class for working with field changes.
3536@ SuppressWarnings ("OverlyCoupledClass" ) /* ... because we want one utility class for all the Changes classes. */
3637public class Changes {
3738
38- public interface ErrorMessage {
39- String VALUES_CANNOT_BE_EQUAL = "newValue cannot be equal to previousValue" ;
40- String NEW_VALUE_CANNOT_BE_EMPTY = "newValue cannot be empty" ;
41- String MUST_BE_A_POSITIVE_VALUE = "%s must be a positive value" ;
42- }
43-
4439 private Changes () {
4540 }
4641
@@ -52,8 +47,8 @@ private Changes() {
5247 public static StringChange of (String previousValue , String newValue ) {
5348 checkNotNull (previousValue );
5449 checkNotNull (newValue );
55- checkArgument (! newValue . isEmpty (), ErrorMessage . NEW_VALUE_CANNOT_BE_EMPTY );
56- checkArgument (! newValue . equals ( previousValue ), ErrorMessage . VALUES_CANNOT_BE_EQUAL );
50+ checkNewValueNotEmpty ( newValue );
51+ checkNotEqual ( previousValue , newValue );
5752
5853 final StringChange result = StringChange .newBuilder ()
5954 .setPreviousValue (previousValue )
@@ -70,7 +65,7 @@ public static StringChange of(String previousValue, String newValue) {
7065 public static TimestampChange of (Timestamp previousValue , Timestamp newValue ) {
7166 checkNotNull (previousValue );
7267 checkNotNull (newValue );
73- checkArgument (! newValue . equals ( previousValue ), ErrorMessage . VALUES_CANNOT_BE_EQUAL );
68+ checkNotEqual ( previousValue , newValue );
7469
7570 final TimestampChange result = TimestampChange .newBuilder ()
7671 .setPreviousValue (previousValue )
@@ -85,7 +80,7 @@ public static TimestampChange of(Timestamp previousValue, Timestamp newValue) {
8580 * <p>Passed values cannot be equal.
8681 */
8782 public static DoubleChange of (double previousValue , double newValue ) {
88- checkArgument ( Double . compare ( newValue , previousValue ) != 0 , ErrorMessage . VALUES_CANNOT_BE_EQUAL );
83+ checkNotEqual ( previousValue , newValue );
8984
9085 final DoubleChange result = DoubleChange .newBuilder ()
9186 .setPreviousValue (previousValue )
@@ -100,7 +95,7 @@ public static DoubleChange of(double previousValue, double newValue) {
10095 * <p>Passed values cannot be equal.
10196 */
10297 public static FloatChange of (float previousValue , float newValue ) {
103- checkArgument ( Float . compare ( newValue , previousValue ) != 0 , ErrorMessage . VALUES_CANNOT_BE_EQUAL );
98+ checkNotEqual ( previousValue , newValue );
10499
105100 final FloatChange result = FloatChange .newBuilder ()
106101 .setPreviousValue (previousValue )
@@ -115,7 +110,7 @@ public static FloatChange of(float previousValue, float newValue) {
115110 * <p>Passed values cannot be equal.
116111 */
117112 public static Int32Change ofInt32 (int previousValue , int newValue ) {
118- checkArgument ( Integer . compare ( newValue , previousValue ) != 0 , ErrorMessage . VALUES_CANNOT_BE_EQUAL );
113+ checkNotEqual ( previousValue , newValue );
119114
120115 final Int32Change result = Int32Change .newBuilder ()
121116 .setPreviousValue (previousValue )
@@ -130,7 +125,7 @@ public static Int32Change ofInt32(int previousValue, int newValue) {
130125 * <p>Passed values cannot be equal.
131126 */
132127 public static Int64Change ofInt64 (long previousValue , long newValue ) {
133- checkArgument ( Long . compare ( newValue , previousValue ) != 0 , ErrorMessage . VALUES_CANNOT_BE_EQUAL );
128+ checkNotEqual ( previousValue , newValue );
134129
135130 final Int64Change result = Int64Change .newBuilder ()
136131 .setPreviousValue (previousValue )
@@ -145,7 +140,7 @@ public static Int64Change ofInt64(long previousValue, long newValue) {
145140 * <p>Passed values cannot be equal.
146141 */
147142 public static UInt32Change ofUInt32 (int previousValue , int newValue ) {
148- checkArgument ( Integer . compare ( newValue , previousValue ) != 0 , ErrorMessage . VALUES_CANNOT_BE_EQUAL );
143+ checkNotEqual ( previousValue , newValue );
149144
150145 final UInt32Change result = UInt32Change .newBuilder ()
151146 .setPreviousValue (previousValue )
@@ -160,7 +155,7 @@ public static UInt32Change ofUInt32(int previousValue, int newValue) {
160155 * <p>Passed values cannot be equal.
161156 */
162157 public static UInt64Change ofUInt64 (long previousValue , long newValue ) {
163- checkArgument ( Long . compare ( newValue , previousValue ) != 0 , ErrorMessage . VALUES_CANNOT_BE_EQUAL );
158+ checkNotEqual ( previousValue , newValue );
164159
165160 final UInt64Change result = UInt64Change .newBuilder ()
166161 .setPreviousValue (previousValue )
@@ -175,7 +170,7 @@ public static UInt64Change ofUInt64(long previousValue, long newValue) {
175170 * <p>Passed values cannot be equal.
176171 */
177172 public static SInt32Change ofSInt32 (int previousValue , int newValue ) {
178- checkArgument ( Integer . compare ( newValue , previousValue ) != 0 , ErrorMessage . VALUES_CANNOT_BE_EQUAL );
173+ checkNotEqual ( previousValue , newValue );
179174
180175 final SInt32Change result = SInt32Change .newBuilder ()
181176 .setPreviousValue (previousValue )
@@ -190,7 +185,7 @@ public static SInt32Change ofSInt32(int previousValue, int newValue) {
190185 * <p>Passed values cannot be equal.
191186 */
192187 public static SInt64Change ofSInt64 (long previousValue , long newValue ) {
193- checkArgument ( Long . compare ( newValue , previousValue ) != 0 , ErrorMessage . VALUES_CANNOT_BE_EQUAL );
188+ checkNotEqual ( previousValue , newValue );
194189
195190 final SInt64Change result = SInt64Change .newBuilder ()
196191 .setPreviousValue (previousValue )
@@ -205,7 +200,7 @@ public static SInt64Change ofSInt64(long previousValue, long newValue) {
205200 * <p>Passed values cannot be equal.
206201 */
207202 public static Fixed32Change ofFixed32 (int previousValue , int newValue ) {
208- checkArgument ( Integer . compare ( newValue , previousValue ) != 0 , ErrorMessage . VALUES_CANNOT_BE_EQUAL );
203+ checkNotEqual ( previousValue , newValue );
209204
210205 final Fixed32Change result = Fixed32Change .newBuilder ()
211206 .setPreviousValue (previousValue )
@@ -220,7 +215,7 @@ public static Fixed32Change ofFixed32(int previousValue, int newValue) {
220215 * <p>Passed values cannot be equal.
221216 */
222217 public static Fixed64Change ofFixed64 (long previousValue , long newValue ) {
223- checkArgument ( Long . compare ( newValue , previousValue ) != 0 , ErrorMessage . VALUES_CANNOT_BE_EQUAL );
218+ checkNotEqual ( previousValue , newValue );
224219
225220 final Fixed64Change result = Fixed64Change .newBuilder ()
226221 .setPreviousValue (previousValue )
@@ -235,7 +230,7 @@ public static Fixed64Change ofFixed64(long previousValue, long newValue) {
235230 * <p>Passed values cannot be equal.
236231 */
237232 public static Sfixed32Change ofSfixed32 (int previousValue , int newValue ) {
238- checkArgument ( Integer . compare ( newValue , previousValue ) != 0 , ErrorMessage . VALUES_CANNOT_BE_EQUAL );
233+ checkNotEqual ( previousValue , newValue );
239234
240235 final Sfixed32Change result = Sfixed32Change .newBuilder ()
241236 .setPreviousValue (previousValue )
@@ -250,7 +245,7 @@ public static Sfixed32Change ofSfixed32(int previousValue, int newValue) {
250245 * <p>Passed values cannot be equal.
251246 */
252247 public static Sfixed64Change ofSfixed64 (long previousValue , long newValue ) {
253- checkArgument ( Long . compare ( newValue , previousValue ) != 0 , ErrorMessage . VALUES_CANNOT_BE_EQUAL );
248+ checkNotEqual ( previousValue , newValue );
254249
255250 final Sfixed64Change result = Sfixed64Change .newBuilder ()
256251 .setPreviousValue (previousValue )
@@ -267,8 +262,8 @@ public static Sfixed64Change ofSfixed64(long previousValue, long newValue) {
267262 public static BytesChange of (ByteString previousValue , ByteString newValue ) {
268263 checkNotNull (previousValue );
269264 checkNotNull (newValue );
270- checkArgument (! newValue . isEmpty (), ErrorMessage . NEW_VALUE_CANNOT_BE_EMPTY );
271- checkArgument (! newValue . equals ( previousValue ), ErrorMessage . VALUES_CANNOT_BE_EQUAL );
265+ checkNewValueNotEmpty ( newValue );
266+ checkNotEqual ( previousValue , newValue );
272267
273268 final BytesChange result = BytesChange .newBuilder ()
274269 .setPreviousValue (previousValue )
@@ -283,7 +278,7 @@ public static BytesChange of(ByteString previousValue, ByteString newValue) {
283278 * <p>Passed values cannot be equal.
284279 */
285280 public static BooleanChange of (boolean previousValue , boolean newValue ) {
286- checkArgument ( Boolean . compare ( newValue , previousValue ) != 0 , ErrorMessage . VALUES_CANNOT_BE_EQUAL );
281+ checkNotEqual ( previousValue , newValue );
287282
288283 final BooleanChange result = BooleanChange .newBuilder ()
289284 .setPreviousValue (previousValue )
0 commit comments