diff --git a/voter-registry/src/main/java/meerkat/SimpleRegistry.java b/voter-registry/src/main/java/meerkat/SimpleRegistry.java index ed391c9..b17b4db 100644 --- a/voter-registry/src/main/java/meerkat/SimpleRegistry.java +++ b/voter-registry/src/main/java/meerkat/SimpleRegistry.java @@ -2,7 +2,6 @@ package meerkat; import com.google.protobuf.ByteString; import com.google.protobuf.InvalidProtocolBufferException; -import meerkat.ProtobufsMessages.BasicMessage; import meerkat.ProtobufsMessages.Tag; import meerkat.bulletinboard.SimpleBulletinBoardClient; import meerkat.comm.CommunicationException; @@ -60,13 +59,13 @@ public class SimpleRegistry { * @param tags the tags based on which the messages will be filtered * @return List */ - private List GetRelevantMessages(List tags) { + private List GetRelevantMessages(List tags) { BulletinBoardAPI.MessageFilterList.Builder filters = BulletinBoardAPI.MessageFilterList.newBuilder(); - for (Tag tag : tags) { + for (String tag : tags) { BulletinBoardAPI.MessageFilter.Builder idFilter = - BulletinBoardAPI.MessageFilter.newBuilder().setTag(tag.getContent()); + BulletinBoardAPI.MessageFilter.newBuilder().setTag(tag); filters.addFilter(idFilter); } @@ -79,9 +78,10 @@ public class SimpleRegistry { * @param tags list of tags that will be used as filters * @return List */ - private List GetRelevantVoterRegistryMessages(List tags) throws InvalidProtocolBufferException { + private List GetRelevantVoterRegistryMessages(List tags) throws InvalidProtocolBufferException { List relevantMessages = GetRelevantMessages(tags); - List messages = CollectionMessagesUtils.GetBasicMessagesFromBulletinBoardMessages(relevantMessages); + List messages = + CollectionMessagesUtils.GetUnsignedBulletinBoardMessages(relevantMessages); return CollectionMessagesUtils.ConvertToVoterRegistryMessages(messages); } @@ -169,10 +169,11 @@ public class SimpleRegistry { * @throws CommunicationException, InvalidProtocolBufferException */ public List GetGroups(String id) throws CommunicationException, InvalidProtocolBufferException { - List GroupsActionsTags = new ArrayList<>(); - GroupsActionsTags.add(Tag.newBuilder().setContent(RegistryTags.ID_TAG + " " + id).build()); - GroupsActionsTags.add(Tag.newBuilder().setContent(RegistryTags.GROUP_ACTION_TAG + " " + RegistryTags.REMOVE_FROM_GROUP_TAG).build()); - GroupsActionsTags.add(Tag.newBuilder().setContent(RegistryTags.GROUP_ACTION_TAG + " " + RegistryTags.ADD_TO_GROUP_TAG).build()); + List GroupsActionsTags = new ArrayList(){{ + add(RegistryTags.ID_TAG + " " + id); + add(RegistryTags.GROUP_ACTION_TAG + " " + RegistryTags.REMOVE_FROM_GROUP_TAG); + add(RegistryTags.GROUP_ACTION_TAG + " " + RegistryTags.ADD_TO_GROUP_TAG); + }}; List voterRegistryMessages = GetRelevantVoterRegistryMessages(GroupsActionsTags); diff --git a/voter-registry/src/main/java/util/CollectionMessagesUtils.java b/voter-registry/src/main/java/util/CollectionMessagesUtils.java index 50ba0bd..e4113ad 100644 --- a/voter-registry/src/main/java/util/CollectionMessagesUtils.java +++ b/voter-registry/src/main/java/util/CollectionMessagesUtils.java @@ -10,6 +10,7 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.stream.Collectors; /** * Created by Vladimir Eliezer Tokarev on 1/15/2016. @@ -77,21 +78,12 @@ public abstract class CollectionMessagesUtils { /** * Gets all the basic messages from bulletin board messages - * @param listOfMessages - * @return List G + * @param listOfMessages list of bulletin board messages + * @return List * @throws InvalidProtocolBufferException */ - public static final List GetBasicMessagesFromBulletinBoardMessages( + public static List GetUnsignedBulletinBoardMessages( List listOfMessages) throws InvalidProtocolBufferException { - - List basicMessages = new ArrayList(); - - for (BulletinBoardAPI.BulletinBoardMessage bulletinBoardMessage : listOfMessages){ - ProtobufsMessages.BasicMessage.Builder basicMessage = - ProtobufsMessages.BasicMessage.newBuilder().mergeFrom(bulletinBoardMessage.getMsg().getData()); - basicMessages.add(basicMessage.build()); - } - - return basicMessages; + return listOfMessages.stream().map(BulletinBoardAPI.BulletinBoardMessage::getMsg).collect(Collectors.toList()); } }