Skip to content

Commit 7ec66cb

Browse files
Merge pull request #244 from SpineEventEngine/yet-more-style
Yet more style
2 parents d6e8dd8 + fd5d4ca commit 7ec66cb

37 files changed

+291
-158
lines changed

.idea/inspectionProfiles/Project_Default.xml

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

client/src/main/java/org/spine3/base/Commands.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
import org.spine3.client.CommandFactory;
3131
import org.spine3.protobuf.AnyPacker;
3232
import org.spine3.protobuf.Timestamps;
33-
import org.spine3.protobuf.TypeUrl;
33+
import org.spine3.protobuf.TypeName;
3434
import org.spine3.time.ZoneOffset;
3535
import org.spine3.users.TenantId;
3636
import org.spine3.users.UserId;
@@ -229,8 +229,7 @@ public static String formatMessageTypeAndId(String format, Message commandMessag
229229
checkNotNull(format);
230230
checkNotEmptyOrBlank(format, "format string");
231231

232-
final String cmdType = TypeUrl.of(commandMessage)
233-
.getTypeName();
232+
final String cmdType = TypeName.of(commandMessage);
234233
final String id = idToString(commandId);
235234
final String result = String.format(format, cmdType, id);
236235
return result;

client/src/main/java/org/spine3/base/Events.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
import com.google.protobuf.Timestamp;
2828
import org.spine3.protobuf.AnyPacker;
2929
import org.spine3.protobuf.Timestamps;
30-
import org.spine3.protobuf.TypeUrl;
30+
import org.spine3.protobuf.TypeName;
3131
import org.spine3.users.UserId;
3232

3333
import javax.annotation.Nullable;
@@ -275,8 +275,7 @@ public static <E extends Message> Optional<E> getEnrichment(Class<E> enrichmentC
275275
return Optional.absent();
276276
}
277277
final Enrichments enrichments = value.get();
278-
final String typeName = TypeUrl.of(enrichmentClass)
279-
.getTypeName();
278+
final String typeName = TypeName.of(enrichmentClass);
280279
final Any any = enrichments.getMapMap()
281280
.get(typeName);
282281
if (any == null) {

client/src/main/java/org/spine3/base/Queries.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import org.spine3.client.Target;
3030
import org.spine3.protobuf.AnyPacker;
3131
import org.spine3.protobuf.KnownTypes;
32+
import org.spine3.protobuf.TypeName;
3233
import org.spine3.protobuf.TypeUrl;
3334

3435
import javax.annotation.Nullable;
@@ -191,11 +192,9 @@ public static Target allOf(Class<? extends Message> entityClass) {
191192
return result;
192193
}
193194

194-
/* package */
195-
static Target composeTarget(Class<? extends Message> entityClass, @Nullable Set<? extends Message> ids) {
196-
final TypeUrl type = TypeUrl.of(entityClass);
197-
198-
final boolean includeAll = ids == null;
195+
/* package */ static Target composeTarget(Class<? extends Message> entityClass,
196+
@Nullable Set<? extends Message> ids) {
197+
final boolean includeAll = (ids == null);
199198

200199
final EntityIdFilter.Builder idFilterBuilder = EntityIdFilter.newBuilder();
201200

@@ -213,7 +212,7 @@ static Target composeTarget(Class<? extends Message> entityClass, @Nullable Set<
213212
.setIdFilter(idFilter)
214213
.build();
215214
final Target.Builder builder = Target.newBuilder()
216-
.setType(type.getTypeName());
215+
.setType(TypeName.of(entityClass));
217216
if (includeAll) {
218217
builder.setIncludeAll(true);
219218
} else {

client/src/main/java/org/spine3/change/Mismatches.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,15 @@
3030
*/
3131
/* package */ class Mismatches {
3232

33+
private static final String ERR_CANNOT_BE_EQUAL = "`expected` and `actual` cannot be equal in ValueMismatch";
34+
3335
private Mismatches() {
3436
// Prevent instantiations.
3537
}
3638

3739
/* package */ static void checkNotNullOrEqual(Object expected, Object actual) {
3840
checkNotNull(expected);
3941
checkNotNull(actual);
40-
checkArgument(!expected.equals(actual), ErrorMessage.EXPECTED_AND_ACTUAL_CANNOT_BE_EQUAL);
42+
checkArgument(!expected.equals(actual), ERR_CANNOT_BE_EQUAL);
4143
}
4244
}

client/src/main/java/org/spine3/client/ConnectionConstants.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,14 @@
2525
*
2626
* @author Alexander Yevsyukov
2727
*/
28-
public interface ConnectionConstants {
28+
public class ConnectionConstants {
2929

30-
/** The default port number on which a client server runs. */
31-
int DEFAULT_CLIENT_SERVICE_PORT = 50051;
30+
/**
31+
* The default port number on which a client server runs.
32+
*/
33+
public static final int DEFAULT_CLIENT_SERVICE_PORT = 50051;
3234

35+
private ConnectionConstants() {
36+
// Prevent instantiation.
37+
}
3338
}

client/src/main/java/org/spine3/protobuf/AnyPacker.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ private AnyPacker() {}
4545
* @return the instance of {@link Any} object that wraps given message
4646
*/
4747
public static Any pack(Message message) {
48-
final TypeUrl typeUrl = TypeUrl.of(message.getDescriptorForType());
48+
final TypeUrl typeUrl = TypeUrl.from(message.getDescriptorForType());
4949
final String typeUrlPrefix = typeUrl.getPrefix();
5050
final Any result = Any.pack(message, typeUrlPrefix);
5151
return result;

client/src/main/java/org/spine3/protobuf/KnownTypes.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ private void put(Class<? extends GeneratedMessageV3> clazz) {
309309
}
310310

311311
private void putEnum(EnumDescriptor desc, Class<? extends EnumLite> enumClass) {
312-
final TypeUrl typeUrl = TypeUrl.of(desc);
312+
final TypeUrl typeUrl = TypeUrl.from(desc);
313313
final ClassName className = ClassName.of(enumClass);
314314
put(typeUrl, className);
315315
}

client/src/main/java/org/spine3/protobuf/Messages.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ public static Class<?> getFieldClass(FieldDescriptor field) {
177177
final Class<? extends Message> enumClass = toMessageClass(TypeUrl.of(enumTypeName));
178178
return enumClass;
179179
case MESSAGE:
180-
final TypeUrl typeUrl = TypeUrl.of(field.getMessageType());
180+
final TypeUrl typeUrl = TypeUrl.from(field.getMessageType());
181181
final Class<? extends Message> msgClass = toMessageClass(typeUrl);
182182
return msgClass;
183183
default:

client/src/main/java/org/spine3/protobuf/Timestamps.java

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131

3232
import static com.google.common.base.Preconditions.checkArgument;
3333
import static com.google.common.base.Preconditions.checkNotNull;
34+
import static com.google.protobuf.util.Timestamps.add;
35+
import static com.google.protobuf.util.Timestamps.fromMillis;
3436
import static com.google.protobuf.util.Timestamps.subtract;
3537

3638
/**
@@ -120,7 +122,7 @@ public static Timestamp getCurrentTime() {
120122
* @return current system time
121123
*/
122124
public static Timestamp systemTime() {
123-
return com.google.protobuf.util.Timestamps.fromMillis(System.currentTimeMillis());
125+
return fromMillis(System.currentTimeMillis());
124126
}
125127

126128
/**
@@ -162,7 +164,7 @@ public static void resetProvider() {
162164
private static class SystemTimeProvider implements Provider {
163165
@Override
164166
public Timestamp getCurrentTime() {
165-
final Timestamp result = com.google.protobuf.util.Timestamps.fromMillis(System.currentTimeMillis());
167+
final Timestamp result = fromMillis(System.currentTimeMillis());
166168
return result;
167169
}
168170
}
@@ -274,12 +276,13 @@ public static long convertToNanos(TimestampOrBuilder timestamp) {
274276
}
275277

276278
private static class TimestampComparator implements Comparator<Timestamp>, Serializable {
279+
280+
private static final long serialVersionUID = 0;
281+
277282
@Override
278283
public int compare(Timestamp t1, Timestamp t2) {
279284
return Timestamps.compare(t1, t2);
280285
}
281-
282-
private static final long serialVersionUID = 0;
283286
}
284287

285288

@@ -313,7 +316,9 @@ public static Timestamp secondsAgo(long value) {
313316
}
314317

315318
private static void checkPositive(long value) {
316-
checkArgument(value > 0, "value must be positive");
319+
if (value <= 0) {
320+
throw new IllegalArgumentException(String.format("value must be positive. Passed: %d", value));
321+
}
317322
}
318323

319324
/**
@@ -326,7 +331,7 @@ private static void checkPositive(long value) {
326331
public static Timestamp secondsFromNow(int seconds) {
327332
checkPositive(seconds);
328333
final Timestamp currentTime = getCurrentTime();
329-
final Timestamp result = com.google.protobuf.util.Timestamps.add(currentTime, Durations.ofSeconds(seconds));
334+
final Timestamp result = add(currentTime, Durations.ofSeconds(seconds));
330335
return result;
331336
}
332337
}

0 commit comments

Comments
 (0)