import lombok.Getter;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Iterator;
-import java.util.stream.Collectors;
-
public class ShardNotOwnedException extends IllegalStateException
{
- @Getter
- private final ChatHomeService chatHomeService;
- @Getter
- private final ChatRoomInfo chatRoomInfo;
@Getter
private final int shard;
- @Getter
- private final int[] ownedShards;
- public ShardNotOwnedException(
- ChatHomeService chatHomeService,
- ChatRoomInfo chatRoomInfo,
- int shard,
- Collection<Integer> ownedShards)
+ public ShardNotOwnedException(int shard)
{
- this(
- chatHomeService,
- chatRoomInfo,
- shard,
- ShardNotOwnedException.toArray(ownedShards));
- }
-
- public ShardNotOwnedException(
- ChatHomeService chatHomeService,
- ChatRoomInfo chatRoomInfo,
- int shard,
- int[] ownedShards)
- {
- super(
- chatHomeService +
- " does not own the shard " +
- shard +
- " for ChatRoom " +
- chatRoomInfo +
- " owned shards: " +
- Arrays
- .stream(ownedShards)
- .mapToObj(ownedShard -> Integer.toString(ownedShard))
- .collect(Collectors.joining(", ")));
- this.chatHomeService = chatHomeService;
- this.chatRoomInfo = chatRoomInfo;
+ super("This instance does not own the shard " + shard);
this.shard = shard;
- this.ownedShards = ownedShards;
- }
-
-
- private static int[] toArray(Collection<Integer> collection)
- {
- int[] array = new int[collection.size()];
- Iterator<Integer> iterator = collection.iterator();
- for (int i = 0; iterator.hasNext(); i++)
- array[i] = iterator.next();
- return array;
}
}