Add the MessagesUtil file

This file contain helpfull methods for working with messages (such as basicMessage and BulletinBoardMessage)
vote-registry
Vladimir Eliezer Tokarev 2016-01-15 06:52:05 -08:00
parent 65bc8bc160
commit 8546a347ca
1 changed files with 51 additions and 0 deletions

View File

@ -0,0 +1,51 @@
package util;
import com.google.protobuf.InvalidProtocolBufferException;
import meerkat.ProtobufsMessages;
import meerkat.protobuf.BulletinBoardAPI;
import java.util.ArrayList;
import java.util.List;
/**
* Created by Dasha on 1/15/2016.
*/
public abstract class MessagesUtils {
/**
* Gets all the basic messages from bulletin board messages
* @param listOfMessages
* @return List<BasicMessage> G
* @throws InvalidProtocolBufferException
*/
public static final List<ProtobufsMessages.BasicMessage> GetBasicMessagesFromBulletinBoardMessages(
List<BulletinBoardAPI.BulletinBoardMessage> listOfMessages) throws InvalidProtocolBufferException {
List<ProtobufsMessages.BasicMessage> basicMessages = new ArrayList<ProtobufsMessages.BasicMessage>();
for (BulletinBoardAPI.BulletinBoardMessage bulletinBoardMessage : listOfMessages){
ProtobufsMessages.BasicMessage.Builder basicMessage =
ProtobufsMessages.BasicMessage.newBuilder().mergeFrom(bulletinBoardMessage.getMsg().getData());
basicMessages.add(basicMessage.build());
}
return basicMessages;
}
/**
* Gets the wanted tag from given basic message
* @param message
* @param tagName
* @return string
*/
public static final String GetWantedTagFromBasicMessage(ProtobufsMessages.BasicMessage message, Tags tagName){
List<ProtobufsMessages.Tag> tags = message.getTagList();
for (ProtobufsMessages.Tag tag : tags) {
if ( tag.getContent().contains(tagName.toString())) {
return tag.getContent();
}
}
return null;
}
}