Skip to content

Commit 8af263e

Browse files
author
Alexander Litus
committed
Fix an example.
1 parent 1cdb3c7 commit 8af263e

File tree

2 files changed

+16
-31
lines changed

2 files changed

+16
-31
lines changed

examples/src/main/java/org/spine3/examples/aggregate/Client.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535

3636
import java.util.List;
3737

38-
import static com.google.common.collect.Lists.newArrayList;
38+
import static com.google.common.collect.Lists.newLinkedList;
3939
import static java.util.concurrent.TimeUnit.SECONDS;
4040
import static org.spine3.client.UserUtil.newUserId;
4141
import static org.spine3.examples.aggregate.ConnectionConstants.DEFAULT_CLIENT_SERVICE_PORT;
@@ -120,7 +120,7 @@ public static void main(String[] args) throws InterruptedException {
120120
* Creates several test requests.
121121
*/
122122
public static List<Command> generateRequests() {
123-
final List<Command> result = newArrayList();
123+
final List<Command> result = newLinkedList();
124124

125125
for (int i = 0; i < 10; i++) {
126126
final OrderId orderId = OrderId.newBuilder().setValue(String.valueOf(i)).build();

examples/src/main/java/org/spine3/examples/aggregate/Requests.java

Lines changed: 14 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
*/
2020
package org.spine3.examples.aggregate;
2121

22-
import com.google.protobuf.Message;
2322
import org.spine3.base.Command;
2423
import org.spine3.base.CommandContext;
2524
import org.spine3.base.Commands;
@@ -35,14 +34,15 @@
3534
*
3635
* @author Mikhail Melnik
3736
*/
38-
class Requests {
37+
/*package*/ class Requests {
3938

4039
public static Command createOrder(UserId userId, OrderId orderId) {
41-
final CreateOrder command = CreateOrder.newBuilder()
40+
final CreateOrder msg = CreateOrder.newBuilder()
4241
.setOrderId(orderId)
4342
.build();
44-
final Command request = newCommand(userId, command);
45-
return request;
43+
final CommandContext context = Commands.createContext(userId, ZoneOffset.getDefaultInstance());
44+
final Command cmd = Commands.create(msg, context);
45+
return cmd;
4646
}
4747

4848
public static Command addOrderLine(UserId userId, OrderId orderId) {
@@ -60,39 +60,24 @@ public static Command addOrderLine(UserId userId, OrderId orderId) {
6060
.setQuantity(quantity)
6161
.setTotal(totalPrice)
6262
.build();
63-
final AddOrderLine command = AddOrderLine.newBuilder()
63+
final AddOrderLine msg = AddOrderLine.newBuilder()
6464
.setOrderId(orderId)
6565
.setOrderLine(orderLine).build();
66-
final Command result = newCommand(userId, command);
67-
return result;
66+
final CommandContext context = Commands.createContext(userId, ZoneOffset.getDefaultInstance());
67+
final Command cmd = Commands.create(msg, context);
68+
return cmd;
6869
}
6970

7071
public static Command payForOrder(UserId userId, OrderId orderId) {
7172
final BillingInfo billingInfo = BillingInfo.newBuilder().setInfo("Payment info is here.").build();
72-
final PayForOrder command = PayForOrder.newBuilder()
73+
final PayForOrder msg = PayForOrder.newBuilder()
7374
.setOrderId(orderId)
7475
.setBillingInfo(billingInfo)
7576
.build();
76-
final Command result = newCommand(userId, command);
77-
return result;
77+
final CommandContext context = Commands.createContext(userId, ZoneOffset.getDefaultInstance());
78+
final Command cmd = Commands.create(msg, context);
79+
return cmd;
7880
}
7981

80-
//TODO:2016-01-14:alexander.yevsyukov: Use real utility method.
81-
public static Command newCommand(UserId userId, Message command) {
82-
final CommandContext context = createCommandContext(userId);
83-
final Command request = Commands.create(command, context);
84-
return request;
85-
}
86-
87-
//TODO:2016-01-14:alexander.yevsyukov: Use real method, which obtains TimeZone.
88-
public static CommandContext createCommandContext(UserId userId) {
89-
final CommandContext.Builder context = CommandContext.newBuilder()
90-
.setCommandId(Commands.generateId())
91-
.setActor(userId)
92-
.setZoneOffset(ZoneOffset.getDefaultInstance());
93-
return context.build();
94-
}
95-
96-
private Requests() {
97-
}
82+
private Requests() {}
9883
}

0 commit comments

Comments
 (0)