From 89bac8d346d821e17caf2d53a56727685736fd4c Mon Sep 17 00:00:00 2001 From: Vladimir Eliezer Tokarev Date: Fri, 22 Jan 2016 08:14:13 -0800 Subject: [PATCH] Re-organized the voter-registry Since there no need for basicMessage i have removed it, and changed few methods to be in language level 7 --- .../main/java/meerkat/ProtobufsMessages.java | 1318 ----------------- .../src/main/java/meerkat/SimpleRegistry.java | 8 +- .../java/util/CollectionMessagesUtils.java | 45 +- .../src/main/proto/ProtobufsMessages.proto | 12 - 4 files changed, 23 insertions(+), 1360 deletions(-) delete mode 100644 voter-registry/src/main/java/meerkat/ProtobufsMessages.java delete mode 100644 voter-registry/src/main/proto/ProtobufsMessages.proto diff --git a/voter-registry/src/main/java/meerkat/ProtobufsMessages.java b/voter-registry/src/main/java/meerkat/ProtobufsMessages.java deleted file mode 100644 index 9f4a612..0000000 --- a/voter-registry/src/main/java/meerkat/ProtobufsMessages.java +++ /dev/null @@ -1,1318 +0,0 @@ -// Generated by the protocol buffer compiler. DO NOT EDIT! -// source: ProtobufsMessages.proto - -package meerkat; - -public final class ProtobufsMessages { - private ProtobufsMessages() {} - public static void registerAllExtensions( - com.google.protobuf.ExtensionRegistry registry) { - } - public interface TagOrBuilder extends - // @@protoc_insertion_point(interface_extends:meerkat.Tag) - com.google.protobuf.MessageOrBuilder { - - /** - * required string content = 1; - */ - boolean hasContent(); - /** - * required string content = 1; - */ - java.lang.String getContent(); - /** - * required string content = 1; - */ - com.google.protobuf.ByteString - getContentBytes(); - } - /** - * Protobuf type {@code meerkat.Tag} - */ - public static final class Tag extends - com.google.protobuf.GeneratedMessage implements - // @@protoc_insertion_point(message_implements:meerkat.Tag) - TagOrBuilder { - // Use Tag.newBuilder() to construct. - private Tag(com.google.protobuf.GeneratedMessage.Builder builder) { - super(builder); - this.unknownFields = builder.getUnknownFields(); - } - private Tag(boolean noInit) { this.unknownFields = com.google.protobuf.UnknownFieldSet.getDefaultInstance(); } - - private static final Tag defaultInstance; - public static Tag getDefaultInstance() { - return defaultInstance; - } - - public Tag getDefaultInstanceForType() { - return defaultInstance; - } - - private final com.google.protobuf.UnknownFieldSet unknownFields; - @java.lang.Override - public final com.google.protobuf.UnknownFieldSet - getUnknownFields() { - return this.unknownFields; - } - private Tag( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - initFields(); - int mutable_bitField0_ = 0; - com.google.protobuf.UnknownFieldSet.Builder unknownFields = - com.google.protobuf.UnknownFieldSet.newBuilder(); - try { - boolean done = false; - while (!done) { - int tag = input.readTag(); - switch (tag) { - case 0: - done = true; - break; - default: { - if (!parseUnknownField(input, unknownFields, - extensionRegistry, tag)) { - done = true; - } - break; - } - case 10: { - com.google.protobuf.ByteString bs = input.readBytes(); - bitField0_ |= 0x00000001; - content_ = bs; - break; - } - } - } - } catch (com.google.protobuf.InvalidProtocolBufferException e) { - throw e.setUnfinishedMessage(this); - } catch (java.io.IOException e) { - throw new com.google.protobuf.InvalidProtocolBufferException( - e.getMessage()).setUnfinishedMessage(this); - } finally { - this.unknownFields = unknownFields.build(); - makeExtensionsImmutable(); - } - } - public static final com.google.protobuf.Descriptors.Descriptor - getDescriptor() { - return meerkat.ProtobufsMessages.internal_static_meerkat_Tag_descriptor; - } - - protected com.google.protobuf.GeneratedMessage.FieldAccessorTable - internalGetFieldAccessorTable() { - return meerkat.ProtobufsMessages.internal_static_meerkat_Tag_fieldAccessorTable - .ensureFieldAccessorsInitialized( - meerkat.ProtobufsMessages.Tag.class, meerkat.ProtobufsMessages.Tag.Builder.class); - } - - public static com.google.protobuf.Parser PARSER = - new com.google.protobuf.AbstractParser() { - public Tag parsePartialFrom( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return new Tag(input, extensionRegistry); - } - }; - - @java.lang.Override - public com.google.protobuf.Parser getParserForType() { - return PARSER; - } - - private int bitField0_; - public static final int CONTENT_FIELD_NUMBER = 1; - private java.lang.Object content_; - /** - * required string content = 1; - */ - public boolean hasContent() { - return ((bitField0_ & 0x00000001) == 0x00000001); - } - /** - * required string content = 1; - */ - public java.lang.String getContent() { - java.lang.Object ref = content_; - if (ref instanceof java.lang.String) { - return (java.lang.String) ref; - } else { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - if (bs.isValidUtf8()) { - content_ = s; - } - return s; - } - } - /** - * required string content = 1; - */ - public com.google.protobuf.ByteString - getContentBytes() { - java.lang.Object ref = content_; - if (ref instanceof java.lang.String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - content_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } - } - - private void initFields() { - content_ = ""; - } - private byte memoizedIsInitialized = -1; - public final boolean isInitialized() { - byte isInitialized = memoizedIsInitialized; - if (isInitialized == 1) return true; - if (isInitialized == 0) return false; - - if (!hasContent()) { - memoizedIsInitialized = 0; - return false; - } - memoizedIsInitialized = 1; - return true; - } - - public void writeTo(com.google.protobuf.CodedOutputStream output) - throws java.io.IOException { - getSerializedSize(); - if (((bitField0_ & 0x00000001) == 0x00000001)) { - output.writeBytes(1, getContentBytes()); - } - getUnknownFields().writeTo(output); - } - - private int memoizedSerializedSize = -1; - public int getSerializedSize() { - int size = memoizedSerializedSize; - if (size != -1) return size; - - size = 0; - if (((bitField0_ & 0x00000001) == 0x00000001)) { - size += com.google.protobuf.CodedOutputStream - .computeBytesSize(1, getContentBytes()); - } - size += getUnknownFields().getSerializedSize(); - memoizedSerializedSize = size; - return size; - } - - private static final long serialVersionUID = 0L; - @java.lang.Override - protected java.lang.Object writeReplace() - throws java.io.ObjectStreamException { - return super.writeReplace(); - } - - public static meerkat.ProtobufsMessages.Tag parseFrom( - com.google.protobuf.ByteString data) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data); - } - public static meerkat.ProtobufsMessages.Tag parseFrom( - com.google.protobuf.ByteString data, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data, extensionRegistry); - } - public static meerkat.ProtobufsMessages.Tag parseFrom(byte[] data) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data); - } - public static meerkat.ProtobufsMessages.Tag parseFrom( - byte[] data, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data, extensionRegistry); - } - public static meerkat.ProtobufsMessages.Tag parseFrom(java.io.InputStream input) - throws java.io.IOException { - return PARSER.parseFrom(input); - } - public static meerkat.ProtobufsMessages.Tag parseFrom( - java.io.InputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - return PARSER.parseFrom(input, extensionRegistry); - } - public static meerkat.ProtobufsMessages.Tag parseDelimitedFrom(java.io.InputStream input) - throws java.io.IOException { - return PARSER.parseDelimitedFrom(input); - } - public static meerkat.ProtobufsMessages.Tag parseDelimitedFrom( - java.io.InputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - return PARSER.parseDelimitedFrom(input, extensionRegistry); - } - public static meerkat.ProtobufsMessages.Tag parseFrom( - com.google.protobuf.CodedInputStream input) - throws java.io.IOException { - return PARSER.parseFrom(input); - } - public static meerkat.ProtobufsMessages.Tag parseFrom( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - return PARSER.parseFrom(input, extensionRegistry); - } - - public static Builder newBuilder() { return Builder.create(); } - public Builder newBuilderForType() { return newBuilder(); } - public static Builder newBuilder(meerkat.ProtobufsMessages.Tag prototype) { - return newBuilder().mergeFrom(prototype); - } - public Builder toBuilder() { return newBuilder(this); } - - @java.lang.Override - protected Builder newBuilderForType( - com.google.protobuf.GeneratedMessage.BuilderParent parent) { - Builder builder = new Builder(parent); - return builder; - } - /** - * Protobuf type {@code meerkat.Tag} - */ - public static final class Builder extends - com.google.protobuf.GeneratedMessage.Builder implements - // @@protoc_insertion_point(builder_implements:meerkat.Tag) - meerkat.ProtobufsMessages.TagOrBuilder { - public static final com.google.protobuf.Descriptors.Descriptor - getDescriptor() { - return meerkat.ProtobufsMessages.internal_static_meerkat_Tag_descriptor; - } - - protected com.google.protobuf.GeneratedMessage.FieldAccessorTable - internalGetFieldAccessorTable() { - return meerkat.ProtobufsMessages.internal_static_meerkat_Tag_fieldAccessorTable - .ensureFieldAccessorsInitialized( - meerkat.ProtobufsMessages.Tag.class, meerkat.ProtobufsMessages.Tag.Builder.class); - } - - // Construct using meerkat.ProtobufsMessages.Tag.newBuilder() - private Builder() { - maybeForceBuilderInitialization(); - } - - private Builder( - com.google.protobuf.GeneratedMessage.BuilderParent parent) { - super(parent); - maybeForceBuilderInitialization(); - } - private void maybeForceBuilderInitialization() { - if (com.google.protobuf.GeneratedMessage.alwaysUseFieldBuilders) { - } - } - private static Builder create() { - return new Builder(); - } - - public Builder clear() { - super.clear(); - content_ = ""; - bitField0_ = (bitField0_ & ~0x00000001); - return this; - } - - public Builder clone() { - return create().mergeFrom(buildPartial()); - } - - public com.google.protobuf.Descriptors.Descriptor - getDescriptorForType() { - return meerkat.ProtobufsMessages.internal_static_meerkat_Tag_descriptor; - } - - public meerkat.ProtobufsMessages.Tag getDefaultInstanceForType() { - return meerkat.ProtobufsMessages.Tag.getDefaultInstance(); - } - - public meerkat.ProtobufsMessages.Tag build() { - meerkat.ProtobufsMessages.Tag result = buildPartial(); - if (!result.isInitialized()) { - throw newUninitializedMessageException(result); - } - return result; - } - - public meerkat.ProtobufsMessages.Tag buildPartial() { - meerkat.ProtobufsMessages.Tag result = new meerkat.ProtobufsMessages.Tag(this); - int from_bitField0_ = bitField0_; - int to_bitField0_ = 0; - if (((from_bitField0_ & 0x00000001) == 0x00000001)) { - to_bitField0_ |= 0x00000001; - } - result.content_ = content_; - result.bitField0_ = to_bitField0_; - onBuilt(); - return result; - } - - public Builder mergeFrom(com.google.protobuf.Message other) { - if (other instanceof meerkat.ProtobufsMessages.Tag) { - return mergeFrom((meerkat.ProtobufsMessages.Tag)other); - } else { - super.mergeFrom(other); - return this; - } - } - - public Builder mergeFrom(meerkat.ProtobufsMessages.Tag other) { - if (other == meerkat.ProtobufsMessages.Tag.getDefaultInstance()) return this; - if (other.hasContent()) { - bitField0_ |= 0x00000001; - content_ = other.content_; - onChanged(); - } - this.mergeUnknownFields(other.getUnknownFields()); - return this; - } - - public final boolean isInitialized() { - if (!hasContent()) { - - return false; - } - return true; - } - - public Builder mergeFrom( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - meerkat.ProtobufsMessages.Tag parsedMessage = null; - try { - parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry); - } catch (com.google.protobuf.InvalidProtocolBufferException e) { - parsedMessage = (meerkat.ProtobufsMessages.Tag) e.getUnfinishedMessage(); - throw e; - } finally { - if (parsedMessage != null) { - mergeFrom(parsedMessage); - } - } - return this; - } - private int bitField0_; - - private java.lang.Object content_ = ""; - /** - * required string content = 1; - */ - public boolean hasContent() { - return ((bitField0_ & 0x00000001) == 0x00000001); - } - /** - * required string content = 1; - */ - public java.lang.String getContent() { - java.lang.Object ref = content_; - if (!(ref instanceof java.lang.String)) { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - if (bs.isValidUtf8()) { - content_ = s; - } - return s; - } else { - return (java.lang.String) ref; - } - } - /** - * required string content = 1; - */ - public com.google.protobuf.ByteString - getContentBytes() { - java.lang.Object ref = content_; - if (ref instanceof String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - content_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } - } - /** - * required string content = 1; - */ - public Builder setContent( - java.lang.String value) { - if (value == null) { - throw new NullPointerException(); - } - bitField0_ |= 0x00000001; - content_ = value; - onChanged(); - return this; - } - /** - * required string content = 1; - */ - public Builder clearContent() { - bitField0_ = (bitField0_ & ~0x00000001); - content_ = getDefaultInstance().getContent(); - onChanged(); - return this; - } - /** - * required string content = 1; - */ - public Builder setContentBytes( - com.google.protobuf.ByteString value) { - if (value == null) { - throw new NullPointerException(); - } - bitField0_ |= 0x00000001; - content_ = value; - onChanged(); - return this; - } - - // @@protoc_insertion_point(builder_scope:meerkat.Tag) - } - - static { - defaultInstance = new Tag(true); - defaultInstance.initFields(); - } - - // @@protoc_insertion_point(class_scope:meerkat.Tag) - } - - public interface BasicMessageOrBuilder extends - // @@protoc_insertion_point(interface_extends:meerkat.BasicMessage) - com.google.protobuf.MessageOrBuilder { - - /** - * repeated .meerkat.Tag tag = 1; - */ - java.util.List - getTagList(); - /** - * repeated .meerkat.Tag tag = 1; - */ - meerkat.ProtobufsMessages.Tag getTag(int index); - /** - * repeated .meerkat.Tag tag = 1; - */ - int getTagCount(); - /** - * repeated .meerkat.Tag tag = 1; - */ - java.util.List - getTagOrBuilderList(); - /** - * repeated .meerkat.Tag tag = 1; - */ - meerkat.ProtobufsMessages.TagOrBuilder getTagOrBuilder( - int index); - - /** - * optional bytes data = 2; - */ - boolean hasData(); - /** - * optional bytes data = 2; - */ - com.google.protobuf.ByteString getData(); - } - /** - * Protobuf type {@code meerkat.BasicMessage} - */ - public static final class BasicMessage extends - com.google.protobuf.GeneratedMessage implements - // @@protoc_insertion_point(message_implements:meerkat.BasicMessage) - BasicMessageOrBuilder { - // Use BasicMessage.newBuilder() to construct. - private BasicMessage(com.google.protobuf.GeneratedMessage.Builder builder) { - super(builder); - this.unknownFields = builder.getUnknownFields(); - } - private BasicMessage(boolean noInit) { this.unknownFields = com.google.protobuf.UnknownFieldSet.getDefaultInstance(); } - - private static final BasicMessage defaultInstance; - public static BasicMessage getDefaultInstance() { - return defaultInstance; - } - - public BasicMessage getDefaultInstanceForType() { - return defaultInstance; - } - - private final com.google.protobuf.UnknownFieldSet unknownFields; - @java.lang.Override - public final com.google.protobuf.UnknownFieldSet - getUnknownFields() { - return this.unknownFields; - } - private BasicMessage( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - initFields(); - int mutable_bitField0_ = 0; - com.google.protobuf.UnknownFieldSet.Builder unknownFields = - com.google.protobuf.UnknownFieldSet.newBuilder(); - try { - boolean done = false; - while (!done) { - int tag = input.readTag(); - switch (tag) { - case 0: - done = true; - break; - default: { - if (!parseUnknownField(input, unknownFields, - extensionRegistry, tag)) { - done = true; - } - break; - } - case 10: { - if (!((mutable_bitField0_ & 0x00000001) == 0x00000001)) { - tag_ = new java.util.ArrayList(); - mutable_bitField0_ |= 0x00000001; - } - tag_.add(input.readMessage(meerkat.ProtobufsMessages.Tag.PARSER, extensionRegistry)); - break; - } - case 18: { - bitField0_ |= 0x00000001; - data_ = input.readBytes(); - break; - } - } - } - } catch (com.google.protobuf.InvalidProtocolBufferException e) { - throw e.setUnfinishedMessage(this); - } catch (java.io.IOException e) { - throw new com.google.protobuf.InvalidProtocolBufferException( - e.getMessage()).setUnfinishedMessage(this); - } finally { - if (((mutable_bitField0_ & 0x00000001) == 0x00000001)) { - tag_ = java.util.Collections.unmodifiableList(tag_); - } - this.unknownFields = unknownFields.build(); - makeExtensionsImmutable(); - } - } - public static final com.google.protobuf.Descriptors.Descriptor - getDescriptor() { - return meerkat.ProtobufsMessages.internal_static_meerkat_BasicMessage_descriptor; - } - - protected com.google.protobuf.GeneratedMessage.FieldAccessorTable - internalGetFieldAccessorTable() { - return meerkat.ProtobufsMessages.internal_static_meerkat_BasicMessage_fieldAccessorTable - .ensureFieldAccessorsInitialized( - meerkat.ProtobufsMessages.BasicMessage.class, meerkat.ProtobufsMessages.BasicMessage.Builder.class); - } - - public static com.google.protobuf.Parser PARSER = - new com.google.protobuf.AbstractParser() { - public BasicMessage parsePartialFrom( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return new BasicMessage(input, extensionRegistry); - } - }; - - @java.lang.Override - public com.google.protobuf.Parser getParserForType() { - return PARSER; - } - - private int bitField0_; - public static final int TAG_FIELD_NUMBER = 1; - private java.util.List tag_; - /** - * repeated .meerkat.Tag tag = 1; - */ - public java.util.List getTagList() { - return tag_; - } - /** - * repeated .meerkat.Tag tag = 1; - */ - public java.util.List - getTagOrBuilderList() { - return tag_; - } - /** - * repeated .meerkat.Tag tag = 1; - */ - public int getTagCount() { - return tag_.size(); - } - /** - * repeated .meerkat.Tag tag = 1; - */ - public meerkat.ProtobufsMessages.Tag getTag(int index) { - return tag_.get(index); - } - /** - * repeated .meerkat.Tag tag = 1; - */ - public meerkat.ProtobufsMessages.TagOrBuilder getTagOrBuilder( - int index) { - return tag_.get(index); - } - - public static final int DATA_FIELD_NUMBER = 2; - private com.google.protobuf.ByteString data_; - /** - * optional bytes data = 2; - */ - public boolean hasData() { - return ((bitField0_ & 0x00000001) == 0x00000001); - } - /** - * optional bytes data = 2; - */ - public com.google.protobuf.ByteString getData() { - return data_; - } - - private void initFields() { - tag_ = java.util.Collections.emptyList(); - data_ = com.google.protobuf.ByteString.EMPTY; - } - private byte memoizedIsInitialized = -1; - public final boolean isInitialized() { - byte isInitialized = memoizedIsInitialized; - if (isInitialized == 1) return true; - if (isInitialized == 0) return false; - - for (int i = 0; i < getTagCount(); i++) { - if (!getTag(i).isInitialized()) { - memoizedIsInitialized = 0; - return false; - } - } - memoizedIsInitialized = 1; - return true; - } - - public void writeTo(com.google.protobuf.CodedOutputStream output) - throws java.io.IOException { - getSerializedSize(); - for (int i = 0; i < tag_.size(); i++) { - output.writeMessage(1, tag_.get(i)); - } - if (((bitField0_ & 0x00000001) == 0x00000001)) { - output.writeBytes(2, data_); - } - getUnknownFields().writeTo(output); - } - - private int memoizedSerializedSize = -1; - public int getSerializedSize() { - int size = memoizedSerializedSize; - if (size != -1) return size; - - size = 0; - for (int i = 0; i < tag_.size(); i++) { - size += com.google.protobuf.CodedOutputStream - .computeMessageSize(1, tag_.get(i)); - } - if (((bitField0_ & 0x00000001) == 0x00000001)) { - size += com.google.protobuf.CodedOutputStream - .computeBytesSize(2, data_); - } - size += getUnknownFields().getSerializedSize(); - memoizedSerializedSize = size; - return size; - } - - private static final long serialVersionUID = 0L; - @java.lang.Override - protected java.lang.Object writeReplace() - throws java.io.ObjectStreamException { - return super.writeReplace(); - } - - public static meerkat.ProtobufsMessages.BasicMessage parseFrom( - com.google.protobuf.ByteString data) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data); - } - public static meerkat.ProtobufsMessages.BasicMessage parseFrom( - com.google.protobuf.ByteString data, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data, extensionRegistry); - } - public static meerkat.ProtobufsMessages.BasicMessage parseFrom(byte[] data) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data); - } - public static meerkat.ProtobufsMessages.BasicMessage parseFrom( - byte[] data, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws com.google.protobuf.InvalidProtocolBufferException { - return PARSER.parseFrom(data, extensionRegistry); - } - public static meerkat.ProtobufsMessages.BasicMessage parseFrom(java.io.InputStream input) - throws java.io.IOException { - return PARSER.parseFrom(input); - } - public static meerkat.ProtobufsMessages.BasicMessage parseFrom( - java.io.InputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - return PARSER.parseFrom(input, extensionRegistry); - } - public static meerkat.ProtobufsMessages.BasicMessage parseDelimitedFrom(java.io.InputStream input) - throws java.io.IOException { - return PARSER.parseDelimitedFrom(input); - } - public static meerkat.ProtobufsMessages.BasicMessage parseDelimitedFrom( - java.io.InputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - return PARSER.parseDelimitedFrom(input, extensionRegistry); - } - public static meerkat.ProtobufsMessages.BasicMessage parseFrom( - com.google.protobuf.CodedInputStream input) - throws java.io.IOException { - return PARSER.parseFrom(input); - } - public static meerkat.ProtobufsMessages.BasicMessage parseFrom( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - return PARSER.parseFrom(input, extensionRegistry); - } - - public static Builder newBuilder() { return Builder.create(); } - public Builder newBuilderForType() { return newBuilder(); } - public static Builder newBuilder(meerkat.ProtobufsMessages.BasicMessage prototype) { - return newBuilder().mergeFrom(prototype); - } - public Builder toBuilder() { return newBuilder(this); } - - @java.lang.Override - protected Builder newBuilderForType( - com.google.protobuf.GeneratedMessage.BuilderParent parent) { - Builder builder = new Builder(parent); - return builder; - } - /** - * Protobuf type {@code meerkat.BasicMessage} - */ - public static final class Builder extends - com.google.protobuf.GeneratedMessage.Builder implements - // @@protoc_insertion_point(builder_implements:meerkat.BasicMessage) - meerkat.ProtobufsMessages.BasicMessageOrBuilder { - public static final com.google.protobuf.Descriptors.Descriptor - getDescriptor() { - return meerkat.ProtobufsMessages.internal_static_meerkat_BasicMessage_descriptor; - } - - protected com.google.protobuf.GeneratedMessage.FieldAccessorTable - internalGetFieldAccessorTable() { - return meerkat.ProtobufsMessages.internal_static_meerkat_BasicMessage_fieldAccessorTable - .ensureFieldAccessorsInitialized( - meerkat.ProtobufsMessages.BasicMessage.class, meerkat.ProtobufsMessages.BasicMessage.Builder.class); - } - - // Construct using meerkat.ProtobufsMessages.BasicMessage.newBuilder() - private Builder() { - maybeForceBuilderInitialization(); - } - - private Builder( - com.google.protobuf.GeneratedMessage.BuilderParent parent) { - super(parent); - maybeForceBuilderInitialization(); - } - private void maybeForceBuilderInitialization() { - if (com.google.protobuf.GeneratedMessage.alwaysUseFieldBuilders) { - getTagFieldBuilder(); - } - } - private static Builder create() { - return new Builder(); - } - - public Builder clear() { - super.clear(); - if (tagBuilder_ == null) { - tag_ = java.util.Collections.emptyList(); - bitField0_ = (bitField0_ & ~0x00000001); - } else { - tagBuilder_.clear(); - } - data_ = com.google.protobuf.ByteString.EMPTY; - bitField0_ = (bitField0_ & ~0x00000002); - return this; - } - - public Builder clone() { - return create().mergeFrom(buildPartial()); - } - - public com.google.protobuf.Descriptors.Descriptor - getDescriptorForType() { - return meerkat.ProtobufsMessages.internal_static_meerkat_BasicMessage_descriptor; - } - - public meerkat.ProtobufsMessages.BasicMessage getDefaultInstanceForType() { - return meerkat.ProtobufsMessages.BasicMessage.getDefaultInstance(); - } - - public meerkat.ProtobufsMessages.BasicMessage build() { - meerkat.ProtobufsMessages.BasicMessage result = buildPartial(); - if (!result.isInitialized()) { - throw newUninitializedMessageException(result); - } - return result; - } - - public meerkat.ProtobufsMessages.BasicMessage buildPartial() { - meerkat.ProtobufsMessages.BasicMessage result = new meerkat.ProtobufsMessages.BasicMessage(this); - int from_bitField0_ = bitField0_; - int to_bitField0_ = 0; - if (tagBuilder_ == null) { - if (((bitField0_ & 0x00000001) == 0x00000001)) { - tag_ = java.util.Collections.unmodifiableList(tag_); - bitField0_ = (bitField0_ & ~0x00000001); - } - result.tag_ = tag_; - } else { - result.tag_ = tagBuilder_.build(); - } - if (((from_bitField0_ & 0x00000002) == 0x00000002)) { - to_bitField0_ |= 0x00000001; - } - result.data_ = data_; - result.bitField0_ = to_bitField0_; - onBuilt(); - return result; - } - - public Builder mergeFrom(com.google.protobuf.Message other) { - if (other instanceof meerkat.ProtobufsMessages.BasicMessage) { - return mergeFrom((meerkat.ProtobufsMessages.BasicMessage)other); - } else { - super.mergeFrom(other); - return this; - } - } - - public Builder mergeFrom(meerkat.ProtobufsMessages.BasicMessage other) { - if (other == meerkat.ProtobufsMessages.BasicMessage.getDefaultInstance()) return this; - if (tagBuilder_ == null) { - if (!other.tag_.isEmpty()) { - if (tag_.isEmpty()) { - tag_ = other.tag_; - bitField0_ = (bitField0_ & ~0x00000001); - } else { - ensureTagIsMutable(); - tag_.addAll(other.tag_); - } - onChanged(); - } - } else { - if (!other.tag_.isEmpty()) { - if (tagBuilder_.isEmpty()) { - tagBuilder_.dispose(); - tagBuilder_ = null; - tag_ = other.tag_; - bitField0_ = (bitField0_ & ~0x00000001); - tagBuilder_ = - com.google.protobuf.GeneratedMessage.alwaysUseFieldBuilders ? - getTagFieldBuilder() : null; - } else { - tagBuilder_.addAllMessages(other.tag_); - } - } - } - if (other.hasData()) { - setData(other.getData()); - } - this.mergeUnknownFields(other.getUnknownFields()); - return this; - } - - public final boolean isInitialized() { - for (int i = 0; i < getTagCount(); i++) { - if (!getTag(i).isInitialized()) { - - return false; - } - } - return true; - } - - public Builder mergeFrom( - com.google.protobuf.CodedInputStream input, - com.google.protobuf.ExtensionRegistryLite extensionRegistry) - throws java.io.IOException { - meerkat.ProtobufsMessages.BasicMessage parsedMessage = null; - try { - parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry); - } catch (com.google.protobuf.InvalidProtocolBufferException e) { - parsedMessage = (meerkat.ProtobufsMessages.BasicMessage) e.getUnfinishedMessage(); - throw e; - } finally { - if (parsedMessage != null) { - mergeFrom(parsedMessage); - } - } - return this; - } - private int bitField0_; - - private java.util.List tag_ = - java.util.Collections.emptyList(); - private void ensureTagIsMutable() { - if (!((bitField0_ & 0x00000001) == 0x00000001)) { - tag_ = new java.util.ArrayList(tag_); - bitField0_ |= 0x00000001; - } - } - - private com.google.protobuf.RepeatedFieldBuilder< - meerkat.ProtobufsMessages.Tag, meerkat.ProtobufsMessages.Tag.Builder, meerkat.ProtobufsMessages.TagOrBuilder> tagBuilder_; - - /** - * repeated .meerkat.Tag tag = 1; - */ - public java.util.List getTagList() { - if (tagBuilder_ == null) { - return java.util.Collections.unmodifiableList(tag_); - } else { - return tagBuilder_.getMessageList(); - } - } - /** - * repeated .meerkat.Tag tag = 1; - */ - public int getTagCount() { - if (tagBuilder_ == null) { - return tag_.size(); - } else { - return tagBuilder_.getCount(); - } - } - /** - * repeated .meerkat.Tag tag = 1; - */ - public meerkat.ProtobufsMessages.Tag getTag(int index) { - if (tagBuilder_ == null) { - return tag_.get(index); - } else { - return tagBuilder_.getMessage(index); - } - } - /** - * repeated .meerkat.Tag tag = 1; - */ - public Builder setTag( - int index, meerkat.ProtobufsMessages.Tag value) { - if (tagBuilder_ == null) { - if (value == null) { - throw new NullPointerException(); - } - ensureTagIsMutable(); - tag_.set(index, value); - onChanged(); - } else { - tagBuilder_.setMessage(index, value); - } - return this; - } - /** - * repeated .meerkat.Tag tag = 1; - */ - public Builder setTag( - int index, meerkat.ProtobufsMessages.Tag.Builder builderForValue) { - if (tagBuilder_ == null) { - ensureTagIsMutable(); - tag_.set(index, builderForValue.build()); - onChanged(); - } else { - tagBuilder_.setMessage(index, builderForValue.build()); - } - return this; - } - /** - * repeated .meerkat.Tag tag = 1; - */ - public Builder addTag(meerkat.ProtobufsMessages.Tag value) { - if (tagBuilder_ == null) { - if (value == null) { - throw new NullPointerException(); - } - ensureTagIsMutable(); - tag_.add(value); - onChanged(); - } else { - tagBuilder_.addMessage(value); - } - return this; - } - /** - * repeated .meerkat.Tag tag = 1; - */ - public Builder addTag( - int index, meerkat.ProtobufsMessages.Tag value) { - if (tagBuilder_ == null) { - if (value == null) { - throw new NullPointerException(); - } - ensureTagIsMutable(); - tag_.add(index, value); - onChanged(); - } else { - tagBuilder_.addMessage(index, value); - } - return this; - } - /** - * repeated .meerkat.Tag tag = 1; - */ - public Builder addTag( - meerkat.ProtobufsMessages.Tag.Builder builderForValue) { - if (tagBuilder_ == null) { - ensureTagIsMutable(); - tag_.add(builderForValue.build()); - onChanged(); - } else { - tagBuilder_.addMessage(builderForValue.build()); - } - return this; - } - /** - * repeated .meerkat.Tag tag = 1; - */ - public Builder addTag( - int index, meerkat.ProtobufsMessages.Tag.Builder builderForValue) { - if (tagBuilder_ == null) { - ensureTagIsMutable(); - tag_.add(index, builderForValue.build()); - onChanged(); - } else { - tagBuilder_.addMessage(index, builderForValue.build()); - } - return this; - } - /** - * repeated .meerkat.Tag tag = 1; - */ - public Builder addAllTag( - java.lang.Iterable values) { - if (tagBuilder_ == null) { - ensureTagIsMutable(); - com.google.protobuf.AbstractMessageLite.Builder.addAll( - values, tag_); - onChanged(); - } else { - tagBuilder_.addAllMessages(values); - } - return this; - } - /** - * repeated .meerkat.Tag tag = 1; - */ - public Builder clearTag() { - if (tagBuilder_ == null) { - tag_ = java.util.Collections.emptyList(); - bitField0_ = (bitField0_ & ~0x00000001); - onChanged(); - } else { - tagBuilder_.clear(); - } - return this; - } - /** - * repeated .meerkat.Tag tag = 1; - */ - public Builder removeTag(int index) { - if (tagBuilder_ == null) { - ensureTagIsMutable(); - tag_.remove(index); - onChanged(); - } else { - tagBuilder_.remove(index); - } - return this; - } - /** - * repeated .meerkat.Tag tag = 1; - */ - public meerkat.ProtobufsMessages.Tag.Builder getTagBuilder( - int index) { - return getTagFieldBuilder().getBuilder(index); - } - /** - * repeated .meerkat.Tag tag = 1; - */ - public meerkat.ProtobufsMessages.TagOrBuilder getTagOrBuilder( - int index) { - if (tagBuilder_ == null) { - return tag_.get(index); } else { - return tagBuilder_.getMessageOrBuilder(index); - } - } - /** - * repeated .meerkat.Tag tag = 1; - */ - public java.util.List - getTagOrBuilderList() { - if (tagBuilder_ != null) { - return tagBuilder_.getMessageOrBuilderList(); - } else { - return java.util.Collections.unmodifiableList(tag_); - } - } - /** - * repeated .meerkat.Tag tag = 1; - */ - public meerkat.ProtobufsMessages.Tag.Builder addTagBuilder() { - return getTagFieldBuilder().addBuilder( - meerkat.ProtobufsMessages.Tag.getDefaultInstance()); - } - /** - * repeated .meerkat.Tag tag = 1; - */ - public meerkat.ProtobufsMessages.Tag.Builder addTagBuilder( - int index) { - return getTagFieldBuilder().addBuilder( - index, meerkat.ProtobufsMessages.Tag.getDefaultInstance()); - } - /** - * repeated .meerkat.Tag tag = 1; - */ - public java.util.List - getTagBuilderList() { - return getTagFieldBuilder().getBuilderList(); - } - private com.google.protobuf.RepeatedFieldBuilder< - meerkat.ProtobufsMessages.Tag, meerkat.ProtobufsMessages.Tag.Builder, meerkat.ProtobufsMessages.TagOrBuilder> - getTagFieldBuilder() { - if (tagBuilder_ == null) { - tagBuilder_ = new com.google.protobuf.RepeatedFieldBuilder< - meerkat.ProtobufsMessages.Tag, meerkat.ProtobufsMessages.Tag.Builder, meerkat.ProtobufsMessages.TagOrBuilder>( - tag_, - ((bitField0_ & 0x00000001) == 0x00000001), - getParentForChildren(), - isClean()); - tag_ = null; - } - return tagBuilder_; - } - - private com.google.protobuf.ByteString data_ = com.google.protobuf.ByteString.EMPTY; - /** - * optional bytes data = 2; - */ - public boolean hasData() { - return ((bitField0_ & 0x00000002) == 0x00000002); - } - /** - * optional bytes data = 2; - */ - public com.google.protobuf.ByteString getData() { - return data_; - } - /** - * optional bytes data = 2; - */ - public Builder setData(com.google.protobuf.ByteString value) { - if (value == null) { - throw new NullPointerException(); - } - bitField0_ |= 0x00000002; - data_ = value; - onChanged(); - return this; - } - /** - * optional bytes data = 2; - */ - public Builder clearData() { - bitField0_ = (bitField0_ & ~0x00000002); - data_ = getDefaultInstance().getData(); - onChanged(); - return this; - } - - // @@protoc_insertion_point(builder_scope:meerkat.BasicMessage) - } - - static { - defaultInstance = new BasicMessage(true); - defaultInstance.initFields(); - } - - // @@protoc_insertion_point(class_scope:meerkat.BasicMessage) - } - - private static final com.google.protobuf.Descriptors.Descriptor - internal_static_meerkat_Tag_descriptor; - private static - com.google.protobuf.GeneratedMessage.FieldAccessorTable - internal_static_meerkat_Tag_fieldAccessorTable; - private static final com.google.protobuf.Descriptors.Descriptor - internal_static_meerkat_BasicMessage_descriptor; - private static - com.google.protobuf.GeneratedMessage.FieldAccessorTable - internal_static_meerkat_BasicMessage_fieldAccessorTable; - - public static com.google.protobuf.Descriptors.FileDescriptor - getDescriptor() { - return descriptor; - } - private static com.google.protobuf.Descriptors.FileDescriptor - descriptor; - static { - java.lang.String[] descriptorData = { - "\n\027ProtobufsMessages.proto\022\007meerkat\"\026\n\003Ta" + - "g\022\017\n\007content\030\001 \002(\t\"7\n\014BasicMessage\022\031\n\003ta" + - "g\030\001 \003(\0132\014.meerkat.Tag\022\014\n\004data\030\002 \001(\014B\023B\021P" + - "rotobufsMessages" - }; - com.google.protobuf.Descriptors.FileDescriptor.InternalDescriptorAssigner assigner = - new com.google.protobuf.Descriptors.FileDescriptor. InternalDescriptorAssigner() { - public com.google.protobuf.ExtensionRegistry assignDescriptors( - com.google.protobuf.Descriptors.FileDescriptor root) { - descriptor = root; - return null; - } - }; - com.google.protobuf.Descriptors.FileDescriptor - .internalBuildGeneratedFileFrom(descriptorData, - new com.google.protobuf.Descriptors.FileDescriptor[] { - }, assigner); - internal_static_meerkat_Tag_descriptor = - getDescriptor().getMessageTypes().get(0); - internal_static_meerkat_Tag_fieldAccessorTable = new - com.google.protobuf.GeneratedMessage.FieldAccessorTable( - internal_static_meerkat_Tag_descriptor, - new java.lang.String[] { "Content", }); - internal_static_meerkat_BasicMessage_descriptor = - getDescriptor().getMessageTypes().get(1); - internal_static_meerkat_BasicMessage_fieldAccessorTable = new - com.google.protobuf.GeneratedMessage.FieldAccessorTable( - internal_static_meerkat_BasicMessage_descriptor, - new java.lang.String[] { "Tag", "Data", }); - } - - // @@protoc_insertion_point(outer_class_scope) -} diff --git a/voter-registry/src/main/java/meerkat/SimpleRegistry.java b/voter-registry/src/main/java/meerkat/SimpleRegistry.java index b17b4db..97ca02f 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.Tag; import meerkat.bulletinboard.SimpleBulletinBoardClient; import meerkat.comm.CommunicationException; import meerkat.crypto.Encryption; @@ -193,9 +192,10 @@ public class SimpleRegistry { * @throws CommunicationException */ public List GetPersonIDDetails(String id) throws CommunicationException, InvalidProtocolBufferException, ParseException { - List GroupsActionsTags = new ArrayList<>(); - GroupsActionsTags.add(Tag.newBuilder().setContent(RegistryTags.ID_TAG + " " + id).build()); - GroupsActionsTags.add(Tag.newBuilder().setContent(RegistryTags.VOTER_ENTRY_TAG.toString()).build()); + List GroupsActionsTags = new ArrayList(){{ + add(RegistryTags.ID_TAG + " " + id); + add(RegistryTags.VOTER_ENTRY_TAG.toString()); + }}; List voterRegistryMessages = GetRelevantVoterRegistryMessages(GroupsActionsTags); VoterRegistryMessage LatestMessage = voterRegistryMessages.get(0); diff --git a/voter-registry/src/main/java/util/CollectionMessagesUtils.java b/voter-registry/src/main/java/util/CollectionMessagesUtils.java index e4113ad..3c8ebd0 100644 --- a/voter-registry/src/main/java/util/CollectionMessagesUtils.java +++ b/voter-registry/src/main/java/util/CollectionMessagesUtils.java @@ -1,7 +1,6 @@ package util; import com.google.protobuf.InvalidProtocolBufferException; -import meerkat.ProtobufsMessages; import meerkat.VoterRegistryMessage; import meerkat.protobuf.BulletinBoardAPI; @@ -19,38 +18,34 @@ import java.util.stream.Collectors; public abstract class CollectionMessagesUtils { /** - * Converts lost of BasicMessages to VoterRegistryMessags - * @param messages list + * Converts lost of UnsignedBulletinBoardMessage to VoterRegistryMessags + * @param messages list * @return List */ - public static List ConvertToVoterRegistryMessages(List messages){ - List voterRegistryMessages = new ArrayList(); - for (ProtobufsMessages.BasicMessage message : messages){ - voterRegistryMessages.add(new VoterRegistryMessage(message)); - } - return voterRegistryMessages; + public static List ConvertToVoterRegistryMessages(List messages){ + return messages.stream().map(VoterRegistryMessage::new).collect(Collectors.toList()); } - + /** * Gets map of GroupId to basicMessage, where the basicMessages are the last actions for those groups - * @param messages List - * @return Map + * @param messages List + * @return Map{String:VoterRegistryMessage} * @throws ParseException */ public static Map GetLatestGroupsActions(List messages) throws ParseException { - Map groupIdToMessage = new HashMap(); + Map groupIdToMessage = new HashMap<>(); // iterate trough all the messages and put into the map the last updated groups actions - for (int i = 0; i < messages.size(); i++) { - String groupId = messages.get(i).GetWantedTagFromBasicMessage(RegistryTags.GROUP_ID_TAG); + for (VoterRegistryMessage message : messages) { + String groupId = message.GetWantedTagFromBasicMessage(RegistryTags.GROUP_ID_TAG); VoterRegistryMessage temp = groupIdToMessage.get(groupId); if (temp != null) { - if (temp != messages.get(i)) { - if (temp.GetBasicMessageActionTimestamp().before(messages.get(i).GetBasicMessageActionTimestamp())) { - groupIdToMessage.put(groupId, messages.get(i)); + if (temp != message) { + if (temp.GetBasicMessageActionTimestamp().before(message.GetBasicMessageActionTimestamp())) { + groupIdToMessage.put(groupId, message); } } } @@ -61,18 +56,16 @@ public abstract class CollectionMessagesUtils { /** * Gets list of groups ids of the basicMessages that carried the adding to group tag - * @param groupIdToMessage Map + * @param groupIdToMessage Map * @return List */ public static List GetListOfGroupIds(Map groupIdToMessage) { - List groupsIds = new ArrayList(); + List groupsIds = new ArrayList<>(); - for (VoterRegistryMessage message : groupIdToMessage.values()) { - if (message.IsGroupAdding()) { - String groupId = message.GetWantedTagFromBasicMessage(RegistryTags.GROUP_ID_TAG); - groupsIds.add(groupId); - } - } + groupIdToMessage.values().stream().filter(VoterRegistryMessage::IsGroupAdding).forEach(message -> { + String groupId = message.GetWantedTagFromBasicMessage(RegistryTags.GROUP_ID_TAG); + groupsIds.add(groupId); + }); return groupsIds; } diff --git a/voter-registry/src/main/proto/ProtobufsMessages.proto b/voter-registry/src/main/proto/ProtobufsMessages.proto deleted file mode 100644 index b66c001..0000000 --- a/voter-registry/src/main/proto/ProtobufsMessages.proto +++ /dev/null @@ -1,12 +0,0 @@ -package meerkat; - -option java_outer_classname = "ProtobufsMessages"; - -message Tag { - required string content = 1; -} - -message BasicMessage { - repeated Tag tag = 1; - optional bytes data = 2; -}