From cf9a274040c8386d77d70e87f2ec01fe986711f9 Mon Sep 17 00:00:00 2001
From: Jun Luo <4catcode@gmail.com>
Date: Wed, 29 May 2024 05:19:20 +0800
Subject: [PATCH] Java: use lombok to simplify the code (#197)
---
lib/xdrgen/generators/java.rb | 417 +++---------------
lib/xdrgen/generators/java/XdrString.erb | 128 +++---
.../java/XdrUnsignedHyperInteger.erb | 30 +-
.../generators/java/XdrUnsignedInteger.erb | 30 +-
.../block_comments.x/AccountFlags.java | 11 +-
.../block_comments.x/XdrString.java | 126 +++---
.../XdrUnsignedHyperInteger.java | 30 +-
.../block_comments.x/XdrUnsignedInteger.java | 30 +-
.../const.x/TestArray.java | 48 +-
.../const.x/TestArray2.java | 50 +--
.../const.x/XdrString.java | 126 +++---
.../const.x/XdrUnsignedHyperInteger.java | 30 +-
.../const.x/XdrUnsignedInteger.java | 30 +-
.../generator_spec_java/enum.x/Color.java | 11 +-
.../generator_spec_java/enum.x/Color2.java | 11 +-
.../enum.x/MessageType.java | 11 +-
.../generator_spec_java/enum.x/XdrString.java | 126 +++---
.../enum.x/XdrUnsignedHyperInteger.java | 30 +-
.../enum.x/XdrUnsignedInteger.java | 30 +-
.../generator_spec_java/nesting.x/Foo.java | 38 +-
.../nesting.x/MyUnion.java | 165 +------
.../nesting.x/UnionKey.java | 11 +-
.../nesting.x/XdrString.java | 126 +++---
.../nesting.x/XdrUnsignedHyperInteger.java | 30 +-
.../nesting.x/XdrUnsignedInteger.java | 30 +-
.../generator_spec_java/optional.x/Arr.java | 48 +-
.../optional.x/HasOptions.java | 72 +--
.../optional.x/XdrString.java | 126 +++---
.../optional.x/XdrUnsignedHyperInteger.java | 30 +-
.../optional.x/XdrUnsignedInteger.java | 30 +-
.../generator_spec_java/struct.x/Int64.java | 38 +-
.../struct.x/MyStruct.java | 109 +----
.../struct.x/XdrString.java | 126 +++---
.../struct.x/XdrUnsignedHyperInteger.java | 30 +-
.../struct.x/XdrUnsignedInteger.java | 30 +-
.../generator_spec_java/test.x/Color.java | 11 +-
.../generator_spec_java/test.x/HasStuff.java | 46 +-
.../generator_spec_java/test.x/Hash.java | 48 +-
.../generator_spec_java/test.x/Hashes1.java | 48 +-
.../generator_spec_java/test.x/Hashes2.java | 50 +--
.../generator_spec_java/test.x/Hashes3.java | 50 +--
.../generator_spec_java/test.x/Int1.java | 38 +-
.../generator_spec_java/test.x/Int2.java | 38 +-
.../generator_spec_java/test.x/Int3.java | 38 +-
.../generator_spec_java/test.x/Int4.java | 38 +-
.../test.x/LotsOfMyStructs.java | 58 +--
.../generator_spec_java/test.x/MyStruct.java | 124 +-----
.../generator_spec_java/test.x/Nester.java | 175 +-------
.../generator_spec_java/test.x/OptHash1.java | 38 +-
.../generator_spec_java/test.x/OptHash2.java | 38 +-
.../generator_spec_java/test.x/Str.java | 38 +-
.../generator_spec_java/test.x/Str2.java | 38 +-
.../generator_spec_java/test.x/Uint512.java | 48 +-
.../generator_spec_java/test.x/Uint513.java | 50 +--
.../generator_spec_java/test.x/Uint514.java | 50 +--
.../generator_spec_java/test.x/XdrString.java | 126 +++---
.../test.x/XdrUnsignedHyperInteger.java | 30 +-
.../test.x/XdrUnsignedInteger.java | 30 +-
.../generator_spec_java/union.x/Error.java | 38 +-
.../generator_spec_java/union.x/IntUnion.java | 87 +---
.../union.x/IntUnion2.java | 38 +-
.../generator_spec_java/union.x/Multi.java | 38 +-
.../generator_spec_java/union.x/MyUnion.java | 87 +---
.../generator_spec_java/union.x/UnionKey.java | 11 +-
.../union.x/XdrString.java | 126 +++---
.../union.x/XdrUnsignedHyperInteger.java | 30 +-
.../union.x/XdrUnsignedInteger.java | 30 +-
67 files changed, 1005 insertions(+), 3072 deletions(-)
diff --git a/lib/xdrgen/generators/java.rb b/lib/xdrgen/generators/java.rb
index e1562cf32..1c82dc8f6 100644
--- a/lib/xdrgen/generators/java.rb
+++ b/lib/xdrgen/generators/java.rb
@@ -48,56 +48,17 @@ def add_imports_for_definition(defn, imports)
imports.add("java.io.ByteArrayOutputStream")
case defn
- when AST::Definitions::Struct ;
- defn.members.each do |m|
- if is_decl_array(m.declaration)
- imports.add('java.util.Arrays')
- else
- imports.add('java.util.Objects')
- end
- end
- # if we have more than one member field then the
- # hash code will be computed by
- # Objects.hash(field1, field2, ..., fieldN)
- # therefore, we should always import java.util.Objects
- if defn.members.length > 1
- imports.add("java.util.Objects")
- end
- when AST::Definitions::Enum ;
- # no imports required for enums
- when AST::Definitions::Union ;
- nonVoidArms = defn.arms.select { |arm| !arm.void? }
- # add 1 because of the discriminant
- totalFields = nonVoidArms.length + 1
-
- if is_type_array(defn.discriminant.type)
- imports.add('java.util.Arrays')
- else
- imports.add('java.util.Objects')
- end
-
- nonVoidArms.each do |a|
- if is_decl_array(a.declaration)
- imports.add('java.util.Arrays')
- else
- imports.add('java.util.Objects')
- end
- end
-
- # if we have more than one field then the
- # hash code will be computed by
- # Objects.hash(field1, field2, ..., fieldN)
- # therefore, we should always import java.util.Objects
- # if we have more than one field
- if totalFields > 1
- imports.add("java.util.Objects")
- end
- when AST::Definitions::Typedef ;
- if is_decl_array(defn.declaration)
- imports.add('java.util.Arrays')
- else
- imports.add('java.util.Objects')
- end
+ when AST::Definitions::Struct, AST::Definitions::Union
+ imports.add("lombok.Data")
+ imports.add("lombok.NoArgsConstructor")
+ imports.add("lombok.AllArgsConstructor")
+ imports.add("lombok.Builder")
+ imports.add("static #{@namespace}.Constants.*")
+ when AST::Definitions::Typedef
+ imports.add("lombok.Data")
+ imports.add("lombok.NoArgsConstructor")
+ imports.add("lombok.AllArgsConstructor")
+ imports.add("static #{@namespace}.Constants.*")
end
if defn.respond_to? :nested_definitions
@@ -111,21 +72,21 @@ def render_definition(defn, constants_container)
case defn
when AST::Definitions::Struct ;
- render_element "public class", imports, defn do |out|
+ render_element defn, imports, defn do |out|
render_struct defn, out
render_nested_definitions defn, out
end
when AST::Definitions::Enum ;
- render_element "public enum", imports, defn do |out|
+ render_element defn, imports, defn do |out|
render_enum defn, out
end
when AST::Definitions::Union ;
- render_element "public class", imports, defn do |out|
+ render_element defn, imports, defn do |out|
render_union defn, out
render_nested_definitions defn, out
end
when AST::Definitions::Typedef ;
- render_element "public class", imports, defn do |out|
+ render_element defn, imports, defn do |out|
render_typedef defn, out
end
when AST::Definitions::Const ;
@@ -142,6 +103,10 @@ def render_nested_definitions(defn, out, post_name="implements XdrElement")
case ndefn
when AST::Definitions::Struct ;
name = name ndefn
+ out.puts "@Data"
+ out.puts "@NoArgsConstructor"
+ out.puts "@AllArgsConstructor"
+ out.puts "@Builder(toBuilder = true)"
out.puts "public static class #{name} #{post_name} {"
out.indent do
render_struct ndefn, out
@@ -157,6 +122,10 @@ def render_nested_definitions(defn, out, post_name="implements XdrElement")
out.puts "}"
when AST::Definitions::Union ;
name = name ndefn
+ out.puts "@Data"
+ out.puts "@NoArgsConstructor"
+ out.puts "@AllArgsConstructor"
+ out.puts "@Builder(toBuilder = true)"
out.puts "public static class #{name} #{post_name} {"
out.indent do
render_union ndefn, out
@@ -165,6 +134,9 @@ def render_nested_definitions(defn, out, post_name="implements XdrElement")
out.puts "}"
when AST::Definitions::Typedef ;
name = name ndefn
+ out.puts "@Data"
+ out.puts "@NoArgsConstructor"
+ out.puts "@AllArgsConstructor"
out.puts "public static class #{name} #{post_name} {"
out.indent do
render_typedef ndefn, out
@@ -174,18 +146,31 @@ def render_nested_definitions(defn, out, post_name="implements XdrElement")
}
end
- def render_element(type, imports, element, post_name="implements XdrElement")
+ def render_element(defn, imports, element, post_name="implements XdrElement")
path = element.name.camelize + ".java"
name = name_string element.name
out = @output.open(path)
render_top_matter out
- out.puts "import static #{@namespace}.Constants.*;"
imports.each do |import|
out.puts "import #{import};"
end
out.puts "\n"
render_source_comment out, element
- out.puts "#{type} #{name} #{post_name} {"
+ case defn
+ when AST::Definitions::Struct, AST::Definitions::Union
+ out.puts "@Data"
+ out.puts "@NoArgsConstructor"
+ out.puts "@AllArgsConstructor"
+ out.puts "@Builder(toBuilder = true)"
+ out.puts "public class #{name} #{post_name} {"
+ when AST::Definitions::Enum
+ out.puts "public enum #{name} #{post_name} {"
+ when AST::Definitions::Typedef
+ out.puts "@Data"
+ out.puts "@NoArgsConstructor"
+ out.puts "@AllArgsConstructor"
+ out.puts "public class #{name} #{post_name} {"
+ end
out.indent do
yield out
out.unbreak
@@ -208,20 +193,20 @@ def render_constants(constants_container)
def render_enum(enum, out)
out.balance_after /,[\s]*/ do
- enum.members.each do |em|
- out.puts "#{em.name}(#{em.value}),"
+ enum.members.each_with_index do |em, index|
+ out.puts "#{em.name}(#{em.value})#{index == enum.members.size - 1 ? ';' : ','}"
end
end
- out.puts ";\n"
+ out.break
out.puts <<-EOS.strip_heredoc
- private int mValue;
+ private final int value;
#{name_string enum.name}(int value) {
- mValue = value;
+ this.value = value;
}
public int getValue() {
- return mValue;
+ return value;
}
public static #{name_string enum.name} decode(XdrDataInputStream stream) throws IOException {
@@ -252,20 +237,10 @@ def render_enum(enum, out)
end
def render_struct(struct, out)
- out.puts "public #{name struct} () {}"
struct.members.each do |m|
- out.puts <<-EOS.strip_heredoc
- private #{decl_string(m.declaration)} #{m.name};
- public #{decl_string(m.declaration)} get#{m.name.slice(0,1).capitalize+m.name.slice(1..-1)}() {
- return this.#{m.name};
- }
- public void set#{m.name.slice(0,1).capitalize+m.name.slice(1..-1)}(#{decl_string m.declaration} value) {
- this.#{m.name} = value;
- }
- EOS
+ out.puts "private #{decl_string(m.declaration)} #{m.name};"
end
-
out.puts "public static void encode(XdrDataOutputStream stream, #{name struct} encoded#{name struct}) throws IOException{"
struct.members.each do |m|
out.indent do
@@ -294,117 +269,12 @@ def render_struct(struct, out)
end
out.puts "}"
- hashCodeExpression = case struct.members.length
- when 0
- "0"
- when 1
- if is_decl_array(struct.members[0].declaration)
- "Arrays.hashCode(this.#{struct.members[0].name})"
- else
- "Objects.hash(this.#{struct.members[0].name})"
- end
- else
- "Objects.hash(#{
- (struct.members.map { |m|
- if is_decl_array(m.declaration)
- "Arrays.hashCode(this.#{m.name})"
- else
- "this.#{m.name}"
- end
- }).join(", ")
- })"
- end
- out.puts <<-EOS.strip_heredoc
- @Override
- public int hashCode() {
- return #{hashCodeExpression};
- }
- EOS
-
- equalParts = struct.members.map { |m|
- if is_decl_array(m.declaration)
- "Arrays.equals(this.#{m.name}, other.#{m.name})"
- else
- "Objects.equals(this.#{m.name}, other.#{m.name})"
- end
- }
- equalExpression = case equalParts.length
- when 0
- "true"
- else
- equalParts.join(" && ")
- end
- type = name struct
- out.puts <<-EOS.strip_heredoc
- @Override
- public boolean equals(Object object) {
- if (!(object instanceof #{type})) {
- return false;
- }
-
- #{type} other = (#{type}) object;
- return #{equalExpression};
- }
-
- EOS
-
render_base64((name struct), out)
-
- out.puts "public static final class Builder {"
- out.indent do
- struct.members.map { |m|
- out.puts "private #{decl_string(m.declaration)} #{m.name};"
- }
-
- struct.members.map { |m|
- out.puts <<-EOS.strip_heredoc
-
- public Builder #{m.name}(#{decl_string(m.declaration)} #{m.name}) {
- this.#{m.name} = #{m.name};
- return this;
- }
- EOS
- }
-
- end
-
-
- out.indent do
- out.break
- out.puts "public #{name struct} build() {"
- out.indent do
- out.puts "#{name struct} val = new #{name struct}();"
- struct.members.map { |m|
- out.puts "val.set#{m.name.slice(0,1).capitalize+m.name.slice(1..-1)}(this.#{m.name});"
- }
- out.puts "return val;"
- end
- out.puts "}"
- end
- out.puts "}"
out.break
end
def render_typedef(typedef, out)
- out.puts <<-EOS.strip_heredoc
- private #{decl_string typedef.declaration} #{typedef.name};
-
- public #{typedef.name.camelize}() {}
-
- public #{typedef.name.camelize}(#{decl_string typedef.declaration} #{typedef.name}) {
- this.#{typedef.name} = #{typedef.name};
- }
-
- public #{decl_string typedef.declaration} get#{typedef.name.slice(0,1).capitalize+typedef.name.slice(1..-1)}() {
- return this.#{typedef.name};
- }
-
- public void set#{typedef.name.slice(0,1).capitalize+typedef.name.slice(1..-1)}(#{decl_string typedef.declaration} value) {
- this.#{typedef.name} = value;
- }
-
- EOS
-
+ out.puts "private #{decl_string typedef.declaration} #{typedef.name};"
out.puts "public static void encode(XdrDataOutputStream stream, #{name typedef} encoded#{name typedef}) throws IOException {"
out.indent do
encode_member "encoded#{name typedef}", typedef, out
@@ -428,113 +298,17 @@ def render_typedef(typedef, out)
end
out.puts "}"
out.break
-
- hash_coder_for_decl =
- if is_decl_array(typedef.declaration)
- "Arrays.hashCode"
- else
- "Objects.hash"
- end
- out.puts <<-EOS.strip_heredoc
- @Override
- public int hashCode() {
- return #{hash_coder_for_decl}(this.#{typedef.name});
- }
-
- EOS
-
- equals_for_decl =
- if is_decl_array(typedef.declaration)
- "Arrays.equals"
- else
- "Objects.equals"
- end
- type = name_string typedef.name
- out.puts <<-EOS.strip_heredoc
- @Override
- public boolean equals(Object object) {
- if (!(object instanceof #{type})) {
- return false;
- }
-
- #{type} other = (#{type}) object;
- return #{equals_for_decl}(this.#{typedef.name}, other.#{typedef.name});
- }
- EOS
render_base64(typedef.name.camelize, out)
end
def render_union(union, out)
- out.puts "public #{name union} () {}"
- out.puts <<-EOS.strip_heredoc
- #{type_string union.discriminant.type} #{union.discriminant.name};
- public #{type_string union.discriminant.type} getDiscriminant() {
- return this.#{union.discriminant.name};
- }
- public void setDiscriminant(#{type_string union.discriminant.type} value) {
- this.#{union.discriminant.name} = value;
- }
- EOS
+ out.puts "private #{type_string union.discriminant.type} discriminant;"
union.arms.each do |arm|
next if arm.void?
- out.puts <<-EOS.strip_heredoc
- private #{decl_string(arm.declaration)} #{arm.name};
- public #{decl_string(arm.declaration)} get#{arm.name.slice(0,1).capitalize+arm.name.slice(1..-1)}() {
- return this.#{arm.name};
- }
- public void set#{arm.name.slice(0,1).capitalize+arm.name.slice(1..-1)}(#{decl_string arm.declaration} value) {
- this.#{arm.name} = value;
- }
- EOS
- end
- out.break
-
- out.puts "public static final class Builder {"
- out.indent do
- out.puts "private #{type_string union.discriminant.type} discriminant;"
- union.arms.each do |arm|
- next if arm.void?
- out.puts "private #{decl_string(arm.declaration)} #{arm.name};"
- end
- out.break
-
- out.puts <<-EOS.strip_heredoc
- public Builder discriminant(#{type_string union.discriminant.type} discriminant) {
- this.discriminant = discriminant;
- return this;
- }
- EOS
-
- union.arms.each do |arm|
- next if arm.void?
- out.puts <<-EOS.strip_heredoc
-
- public Builder #{arm.name}(#{decl_string(arm.declaration)} #{arm.name}) {
- this.#{arm.name} = #{arm.name};
- return this;
- }
- EOS
- end
- end
-
- out.indent do
- out.break
- out.puts "public #{name union} build() {"
- out.indent do
- out.puts "#{name union} val = new #{name union}();"
- out.puts "val.setDiscriminant(discriminant);"
- union.arms.each do |arm|
- next if arm.void?
- out.puts "val.set#{arm.name.slice(0,1).capitalize+arm.name.slice(1..-1)}(this.#{arm.name});"
- end
- out.puts "return val;"
- end
- out.puts "}"
+ out.puts "private #{decl_string(arm.declaration)} #{arm.name};"
end
- out.puts "}"
out.break
-
out.puts "public static void encode(XdrDataOutputStream stream, #{name union} encoded#{name union}) throws IOException {"
out.puts('//' + union.discriminant.type.class.to_s)
out.puts("//" + type_string(union.discriminant.type))
@@ -622,65 +396,6 @@ def render_union(union, out)
out.puts "return decoded#{name union};"
end
out.puts "}"
-
- nonVoidArms = union.arms.select { |arm| !arm.void? }
-
- discriminantPart = if is_type_array(union.discriminant.type)
- "Arrays.hashCode(this.#{union.discriminant.name})"
- else
- "this.#{union.discriminant.name}"
- end
-
- parts = nonVoidArms.map { |a|
- if is_decl_array(a.declaration)
- "Arrays.hashCode(this.#{a.name})"
- else
- "this.#{a.name}"
- end
- }
- parts.append(discriminantPart)
-
- hashCodeExpression = "Objects.hash(#{parts.join(", ")})"
- out.puts <<-EOS.strip_heredoc
- @Override
- public int hashCode() {
- return #{hashCodeExpression};
- }
- EOS
-
- equalParts = nonVoidArms.map { |a|
- if is_decl_array(a.declaration)
- "Arrays.equals(this.#{a.name}, other.#{a.name})"
- else
- "Objects.equals(this.#{a.name}, other.#{a.name})"
- end
- }
- equalParts.append(
- if is_type_array(union.discriminant.type)
- "Arrays.equals(this.#{union.discriminant.name}, other.#{union.discriminant.name})"
- else
- "Objects.equals(this.#{union.discriminant.name}, other.#{union.discriminant.name})"
- end
- )
-
- equalExpression = case equalParts.length
- when 0
- "true"
- else
- equalParts.join(" && ")
- end
- type = name union
- out.puts <<-EOS.strip_heredoc
- @Override
- public boolean equals(Object object) {
- if (!(object instanceof #{type})) {
- return false;
- }
-
- #{type} other = (#{type}) object;
- return #{equalExpression};
- }
- EOS
render_base64((name union), out)
out.break
end
@@ -748,20 +463,20 @@ def encode_member(value, member, out)
end
case member.declaration
when AST::Declarations::Opaque ;
- out.puts "int #{member.name}size = #{value}.#{member.name}.length;"
+ out.puts "int #{member.name}Size = #{value}.#{member.name}.length;"
unless member.declaration.fixed?
- out.puts "stream.writeInt(#{member.name}size);"
+ out.puts "stream.writeInt(#{member.name}Size);"
end
out.puts <<-EOS.strip_heredoc
- stream.write(#{value}.get#{member.name.slice(0,1).capitalize+member.name.slice(1..-1)}(), 0, #{member.name}size);
+ stream.write(#{value}.get#{member.name.slice(0,1).capitalize+member.name.slice(1..-1)}(), 0, #{member.name}Size);
EOS
when AST::Declarations::Array ;
- out.puts "int #{member.name}size = #{value}.get#{member.name.slice(0,1).capitalize+member.name.slice(1..-1)}().length;"
+ out.puts "int #{member.name}Size = #{value}.get#{member.name.slice(0,1).capitalize+member.name.slice(1..-1)}().length;"
unless member.declaration.fixed?
- out.puts "stream.writeInt(#{member.name}size);"
+ out.puts "stream.writeInt(#{member.name}Size);"
end
out.puts <<-EOS.strip_heredoc
- for (int i = 0; i < #{member.name}size; i++) {
+ for (int i = 0; i < #{member.name}Size; i++) {
#{encode_type member.declaration.type, "#{value}.#{member.name}[i]"};
}
EOS
@@ -818,23 +533,23 @@ def decode_member(value, member, out)
case member.declaration
when AST::Declarations::Opaque ;
if (member.declaration.fixed?)
- out.puts "int #{member.name}size = #{member.declaration.size};"
+ out.puts "int #{member.name}Size = #{member.declaration.size};"
else
- out.puts "int #{member.name}size = stream.readInt();"
+ out.puts "int #{member.name}Size = stream.readInt();"
end
out.puts <<-EOS.strip_heredoc
- #{value}.#{member.name} = new byte[#{member.name}size];
- stream.read(#{value}.#{member.name}, 0, #{member.name}size);
+ #{value}.#{member.name} = new byte[#{member.name}Size];
+ stream.read(#{value}.#{member.name}, 0, #{member.name}Size);
EOS
when AST::Declarations::Array ;
if (member.declaration.fixed?)
- out.puts "int #{member.name}size = #{member.declaration.size};"
+ out.puts "int #{member.name}Size = #{member.declaration.size};"
else
- out.puts "int #{member.name}size = stream.readInt();"
+ out.puts "int #{member.name}Size = stream.readInt();"
end
out.puts <<-EOS.strip_heredoc
- #{value}.#{member.name} = new #{type_string member.type}[#{member.name}size];
- for (int i = 0; i < #{member.name}size; i++) {
+ #{value}.#{member.name} = new #{type_string member.type}[#{member.name}Size];
+ for (int i = 0; i < #{member.name}Size; i++) {
#{value}.#{member.name}[i] = #{decode_type member.declaration};
}
EOS
diff --git a/lib/xdrgen/generators/java/XdrString.erb b/lib/xdrgen/generators/java/XdrString.erb
index bfad40c7f..89a2b0931 100644
--- a/lib/xdrgen/generators/java/XdrString.erb
+++ b/lib/xdrgen/generators/java/XdrString.erb
@@ -4,90 +4,72 @@ import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InvalidClassException;
-import java.nio.charset.Charset;
-import java.util.Arrays;
+import java.nio.charset.StandardCharsets;
+import lombok.Value;
import org.stellar.sdk.Base64Factory;
+@Value
public class XdrString implements XdrElement {
- private byte[] bytes;
+ byte[] bytes;
- public XdrString(byte[] bytes) {
- this.bytes = bytes;
- }
+ public XdrString(byte[] bytes) {
+ this.bytes = bytes;
+ }
- public XdrString(String text) {
- this.bytes = text.getBytes(Charset.forName("UTF-8"));
- }
+ public XdrString(String text) {
+ this.bytes = text.getBytes(StandardCharsets.UTF_8);
+ }
- @Override
- public void encode(XdrDataOutputStream stream) throws IOException {
- stream.writeInt(this.bytes.length);
- stream.write(this.bytes, 0, this.bytes.length);
- }
+ @Override
+ public void encode(XdrDataOutputStream stream) throws IOException {
+ stream.writeInt(this.bytes.length);
+ stream.write(this.bytes, 0, this.bytes.length);
+ }
- public static XdrString decode(XdrDataInputStream stream, int maxSize) throws IOException {
- int size = stream.readInt();
- if (size > maxSize) {
- throw new InvalidClassException("String length "+size+" exceeds max size "+maxSize);
- }
- byte[] bytes = new byte[size];
- stream.read(bytes);
- return new XdrString(bytes);
+ public static XdrString decode(XdrDataInputStream stream, int maxSize) throws IOException {
+ int size = stream.readInt();
+ if (size > maxSize) {
+ throw new InvalidClassException("String length " + size + " exceeds max size " + maxSize);
}
+ byte[] bytes = new byte[size];
+ stream.read(bytes);
+ return new XdrString(bytes);
+ }
- public byte[] getBytes() {
- return this.bytes;
- }
+ @Override
+ public String toXdrBase64() throws IOException {
+ return Base64Factory.getInstance().encodeToString(toXdrByteArray());
+ }
- @Override
- public String toXdrBase64() throws IOException {
- return Base64Factory.getInstance().encodeToString(toXdrByteArray());
- }
-
- @Override
- public byte[] toXdrByteArray() throws IOException {
- ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
- XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream);
- encode(xdrDataOutputStream);
- return byteArrayOutputStream.toByteArray();
- }
-
- public static XdrString fromXdrBase64(String xdr, int maxSize) throws IOException {
- byte[] bytes = Base64Factory.getInstance().decode(xdr);
- return fromXdrByteArray(bytes, maxSize);
- }
-
- public static XdrString fromXdrBase64(String xdr) throws IOException {
- return fromXdrBase64(xdr, Integer.MAX_VALUE);
- }
-
- public static XdrString fromXdrByteArray(byte[] xdr, int maxSize) throws IOException {
- ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr);
- XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream);
- return decode(xdrDataInputStream, maxSize);
- }
-
- public static XdrString fromXdrByteArray(byte[] xdr) throws IOException {
- return fromXdrByteArray(xdr, Integer.MAX_VALUE);
- }
+ @Override
+ public byte[] toXdrByteArray() throws IOException {
+ ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
+ XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream);
+ encode(xdrDataOutputStream);
+ return byteArrayOutputStream.toByteArray();
+ }
- @Override
- public int hashCode() {
- return Arrays.hashCode(this.bytes);
- }
+ public static XdrString fromXdrBase64(String xdr, int maxSize) throws IOException {
+ byte[] bytes = Base64Factory.getInstance().decode(xdr);
+ return fromXdrByteArray(bytes, maxSize);
+ }
- @Override
- public boolean equals(Object object) {
- if (object == null || !(object instanceof XdrString)) {
- return false;
- }
+ public static XdrString fromXdrBase64(String xdr) throws IOException {
+ return fromXdrBase64(xdr, Integer.MAX_VALUE);
+ }
- XdrString other = (XdrString) object;
- return Arrays.equals(this.bytes, other.bytes);
- }
+ public static XdrString fromXdrByteArray(byte[] xdr, int maxSize) throws IOException {
+ ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr);
+ XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream);
+ return decode(xdrDataInputStream, maxSize);
+ }
- @Override
- public String toString() {
- return new String(bytes, Charset.forName("UTF-8"));
- }
-}
\ No newline at end of file
+ public static XdrString fromXdrByteArray(byte[] xdr) throws IOException {
+ return fromXdrByteArray(xdr, Integer.MAX_VALUE);
+ }
+
+ @Override
+ public String toString() {
+ return new String(bytes, StandardCharsets.UTF_8);
+ }
+}
diff --git a/lib/xdrgen/generators/java/XdrUnsignedHyperInteger.erb b/lib/xdrgen/generators/java/XdrUnsignedHyperInteger.erb
index 6c05ca57d..6c732ebc9 100644
--- a/lib/xdrgen/generators/java/XdrUnsignedHyperInteger.erb
+++ b/lib/xdrgen/generators/java/XdrUnsignedHyperInteger.erb
@@ -1,10 +1,10 @@
-package org.stellar.sdk.xdr;
+package <%= @namespace %>;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.math.BigInteger;
-import java.util.Objects;
+import lombok.Value;
import org.stellar.sdk.Base64Factory;
/**
@@ -13,10 +13,11 @@ import org.stellar.sdk.Base64Factory;
* @see XDR: External Data
* Representation Standard
*/
+@Value
public class XdrUnsignedHyperInteger implements XdrElement {
public static final BigInteger MAX_VALUE = new BigInteger("18446744073709551615");
public static final BigInteger MIN_VALUE = BigInteger.ZERO;
- private final BigInteger number;
+ BigInteger number;
public XdrUnsignedHyperInteger(BigInteger number) {
if (number.compareTo(MIN_VALUE) < 0 || number.compareTo(MAX_VALUE) > 0) {
@@ -55,10 +56,6 @@ public class XdrUnsignedHyperInteger implements XdrElement {
return paddedBytes;
}
- public BigInteger getNumber() {
- return number;
- }
-
@Override
public String toXdrBase64() throws IOException {
return Base64Factory.getInstance().encodeToString(toXdrByteArray());
@@ -82,23 +79,4 @@ public class XdrUnsignedHyperInteger implements XdrElement {
XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream);
return decode(xdrDataInputStream);
}
-
- @Override
- public int hashCode() {
- return Objects.hash(this.number);
- }
-
- @Override
- public boolean equals(Object object) {
- if (!(object instanceof XdrUnsignedHyperInteger)) {
- return false;
- }
-
- XdrUnsignedHyperInteger other = (XdrUnsignedHyperInteger) object;
- return Objects.equals(this.number, other.number);
- }
-
- public String toString() {
- return "XdrUnsignedInteger(number=" + this.getNumber() + ")";
- }
}
diff --git a/lib/xdrgen/generators/java/XdrUnsignedInteger.erb b/lib/xdrgen/generators/java/XdrUnsignedInteger.erb
index 8f2a52395..223b872e9 100644
--- a/lib/xdrgen/generators/java/XdrUnsignedInteger.erb
+++ b/lib/xdrgen/generators/java/XdrUnsignedInteger.erb
@@ -1,9 +1,9 @@
-package org.stellar.sdk.xdr;
+package <%= @namespace %>;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
-import java.util.Objects;
+import lombok.Value;
import org.stellar.sdk.Base64Factory;
/**
@@ -12,10 +12,11 @@ import org.stellar.sdk.Base64Factory;
* @see XDR: External Data
* Representation Standard
*/
+@Value
public class XdrUnsignedInteger implements XdrElement {
public static final long MAX_VALUE = (1L << 32) - 1;
public static final long MIN_VALUE = 0;
- private final Long number;
+ Long number;
public XdrUnsignedInteger(Long number) {
if (number < MIN_VALUE || number > MAX_VALUE) {
@@ -32,10 +33,6 @@ public class XdrUnsignedInteger implements XdrElement {
this.number = number.longValue();
}
- public Long getNumber() {
- return number;
- }
-
public static XdrUnsignedInteger decode(XdrDataInputStream stream) throws IOException {
int intValue = stream.readInt();
long uint32Value = Integer.toUnsignedLong(intValue);
@@ -70,23 +67,4 @@ public class XdrUnsignedInteger implements XdrElement {
XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream);
return decode(xdrDataInputStream);
}
-
- @Override
- public int hashCode() {
- return Objects.hash(this.number);
- }
-
- @Override
- public boolean equals(Object object) {
- if (!(object instanceof XdrUnsignedInteger)) {
- return false;
- }
-
- XdrUnsignedInteger other = (XdrUnsignedInteger) object;
- return Objects.equals(this.number, other.number);
- }
-
- public String toString() {
- return "XdrUnsignedInteger(number=" + this.getNumber() + ")";
- }
}
diff --git a/spec/output/generator_spec_java/block_comments.x/AccountFlags.java b/spec/output/generator_spec_java/block_comments.x/AccountFlags.java
index 5da6b929d..8ce3d380f 100644
--- a/spec/output/generator_spec_java/block_comments.x/AccountFlags.java
+++ b/spec/output/generator_spec_java/block_comments.x/AccountFlags.java
@@ -5,7 +5,6 @@
import java.io.IOException;
-import static MyXDR.Constants.*;
import org.stellar.sdk.Base64Factory;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
@@ -20,16 +19,16 @@
*
*/
public enum AccountFlags implements XdrElement {
- AUTH_REQUIRED_FLAG(1),
- ;
- private int mValue;
+ AUTH_REQUIRED_FLAG(1);
+
+ private final int value;
AccountFlags(int value) {
- mValue = value;
+ this.value = value;
}
public int getValue() {
- return mValue;
+ return value;
}
public static AccountFlags decode(XdrDataInputStream stream) throws IOException {
diff --git a/spec/output/generator_spec_java/block_comments.x/XdrString.java b/spec/output/generator_spec_java/block_comments.x/XdrString.java
index bb4e81fb4..2d8f8bbc9 100644
--- a/spec/output/generator_spec_java/block_comments.x/XdrString.java
+++ b/spec/output/generator_spec_java/block_comments.x/XdrString.java
@@ -4,90 +4,72 @@
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InvalidClassException;
-import java.nio.charset.Charset;
-import java.util.Arrays;
+import java.nio.charset.StandardCharsets;
+import lombok.Value;
import org.stellar.sdk.Base64Factory;
+@Value
public class XdrString implements XdrElement {
- private byte[] bytes;
+ byte[] bytes;
- public XdrString(byte[] bytes) {
- this.bytes = bytes;
- }
+ public XdrString(byte[] bytes) {
+ this.bytes = bytes;
+ }
- public XdrString(String text) {
- this.bytes = text.getBytes(Charset.forName("UTF-8"));
- }
+ public XdrString(String text) {
+ this.bytes = text.getBytes(StandardCharsets.UTF_8);
+ }
- @Override
- public void encode(XdrDataOutputStream stream) throws IOException {
- stream.writeInt(this.bytes.length);
- stream.write(this.bytes, 0, this.bytes.length);
- }
+ @Override
+ public void encode(XdrDataOutputStream stream) throws IOException {
+ stream.writeInt(this.bytes.length);
+ stream.write(this.bytes, 0, this.bytes.length);
+ }
- public static XdrString decode(XdrDataInputStream stream, int maxSize) throws IOException {
- int size = stream.readInt();
- if (size > maxSize) {
- throw new InvalidClassException("String length "+size+" exceeds max size "+maxSize);
- }
- byte[] bytes = new byte[size];
- stream.read(bytes);
- return new XdrString(bytes);
+ public static XdrString decode(XdrDataInputStream stream, int maxSize) throws IOException {
+ int size = stream.readInt();
+ if (size > maxSize) {
+ throw new InvalidClassException("String length " + size + " exceeds max size " + maxSize);
}
+ byte[] bytes = new byte[size];
+ stream.read(bytes);
+ return new XdrString(bytes);
+ }
- public byte[] getBytes() {
- return this.bytes;
- }
+ @Override
+ public String toXdrBase64() throws IOException {
+ return Base64Factory.getInstance().encodeToString(toXdrByteArray());
+ }
- @Override
- public String toXdrBase64() throws IOException {
- return Base64Factory.getInstance().encodeToString(toXdrByteArray());
- }
-
- @Override
- public byte[] toXdrByteArray() throws IOException {
- ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
- XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream);
- encode(xdrDataOutputStream);
- return byteArrayOutputStream.toByteArray();
- }
-
- public static XdrString fromXdrBase64(String xdr, int maxSize) throws IOException {
- byte[] bytes = Base64Factory.getInstance().decode(xdr);
- return fromXdrByteArray(bytes, maxSize);
- }
-
- public static XdrString fromXdrBase64(String xdr) throws IOException {
- return fromXdrBase64(xdr, Integer.MAX_VALUE);
- }
-
- public static XdrString fromXdrByteArray(byte[] xdr, int maxSize) throws IOException {
- ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr);
- XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream);
- return decode(xdrDataInputStream, maxSize);
- }
-
- public static XdrString fromXdrByteArray(byte[] xdr) throws IOException {
- return fromXdrByteArray(xdr, Integer.MAX_VALUE);
- }
+ @Override
+ public byte[] toXdrByteArray() throws IOException {
+ ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
+ XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream);
+ encode(xdrDataOutputStream);
+ return byteArrayOutputStream.toByteArray();
+ }
- @Override
- public int hashCode() {
- return Arrays.hashCode(this.bytes);
- }
+ public static XdrString fromXdrBase64(String xdr, int maxSize) throws IOException {
+ byte[] bytes = Base64Factory.getInstance().decode(xdr);
+ return fromXdrByteArray(bytes, maxSize);
+ }
- @Override
- public boolean equals(Object object) {
- if (object == null || !(object instanceof XdrString)) {
- return false;
- }
+ public static XdrString fromXdrBase64(String xdr) throws IOException {
+ return fromXdrBase64(xdr, Integer.MAX_VALUE);
+ }
- XdrString other = (XdrString) object;
- return Arrays.equals(this.bytes, other.bytes);
- }
+ public static XdrString fromXdrByteArray(byte[] xdr, int maxSize) throws IOException {
+ ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr);
+ XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream);
+ return decode(xdrDataInputStream, maxSize);
+ }
- @Override
- public String toString() {
- return new String(bytes, Charset.forName("UTF-8"));
- }
+ public static XdrString fromXdrByteArray(byte[] xdr) throws IOException {
+ return fromXdrByteArray(xdr, Integer.MAX_VALUE);
+ }
+
+ @Override
+ public String toString() {
+ return new String(bytes, StandardCharsets.UTF_8);
+ }
}
diff --git a/spec/output/generator_spec_java/block_comments.x/XdrUnsignedHyperInteger.java b/spec/output/generator_spec_java/block_comments.x/XdrUnsignedHyperInteger.java
index 6c05ca57d..204aa83de 100644
--- a/spec/output/generator_spec_java/block_comments.x/XdrUnsignedHyperInteger.java
+++ b/spec/output/generator_spec_java/block_comments.x/XdrUnsignedHyperInteger.java
@@ -1,10 +1,10 @@
-package org.stellar.sdk.xdr;
+package MyXDR;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.math.BigInteger;
-import java.util.Objects;
+import lombok.Value;
import org.stellar.sdk.Base64Factory;
/**
@@ -13,10 +13,11 @@
* @see XDR: External Data
* Representation Standard
*/
+@Value
public class XdrUnsignedHyperInteger implements XdrElement {
public static final BigInteger MAX_VALUE = new BigInteger("18446744073709551615");
public static final BigInteger MIN_VALUE = BigInteger.ZERO;
- private final BigInteger number;
+ BigInteger number;
public XdrUnsignedHyperInteger(BigInteger number) {
if (number.compareTo(MIN_VALUE) < 0 || number.compareTo(MAX_VALUE) > 0) {
@@ -55,10 +56,6 @@ private byte[] getBytes() {
return paddedBytes;
}
- public BigInteger getNumber() {
- return number;
- }
-
@Override
public String toXdrBase64() throws IOException {
return Base64Factory.getInstance().encodeToString(toXdrByteArray());
@@ -82,23 +79,4 @@ public static XdrUnsignedHyperInteger fromXdrByteArray(byte[] xdr) throws IOExce
XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream);
return decode(xdrDataInputStream);
}
-
- @Override
- public int hashCode() {
- return Objects.hash(this.number);
- }
-
- @Override
- public boolean equals(Object object) {
- if (!(object instanceof XdrUnsignedHyperInteger)) {
- return false;
- }
-
- XdrUnsignedHyperInteger other = (XdrUnsignedHyperInteger) object;
- return Objects.equals(this.number, other.number);
- }
-
- public String toString() {
- return "XdrUnsignedInteger(number=" + this.getNumber() + ")";
- }
}
diff --git a/spec/output/generator_spec_java/block_comments.x/XdrUnsignedInteger.java b/spec/output/generator_spec_java/block_comments.x/XdrUnsignedInteger.java
index 8f2a52395..a56ad657d 100644
--- a/spec/output/generator_spec_java/block_comments.x/XdrUnsignedInteger.java
+++ b/spec/output/generator_spec_java/block_comments.x/XdrUnsignedInteger.java
@@ -1,9 +1,9 @@
-package org.stellar.sdk.xdr;
+package MyXDR;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
-import java.util.Objects;
+import lombok.Value;
import org.stellar.sdk.Base64Factory;
/**
@@ -12,10 +12,11 @@
* @see XDR: External Data
* Representation Standard
*/
+@Value
public class XdrUnsignedInteger implements XdrElement {
public static final long MAX_VALUE = (1L << 32) - 1;
public static final long MIN_VALUE = 0;
- private final Long number;
+ Long number;
public XdrUnsignedInteger(Long number) {
if (number < MIN_VALUE || number > MAX_VALUE) {
@@ -32,10 +33,6 @@ public XdrUnsignedInteger(Integer number) {
this.number = number.longValue();
}
- public Long getNumber() {
- return number;
- }
-
public static XdrUnsignedInteger decode(XdrDataInputStream stream) throws IOException {
int intValue = stream.readInt();
long uint32Value = Integer.toUnsignedLong(intValue);
@@ -70,23 +67,4 @@ public static XdrUnsignedInteger fromXdrByteArray(byte[] xdr) throws IOException
XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream);
return decode(xdrDataInputStream);
}
-
- @Override
- public int hashCode() {
- return Objects.hash(this.number);
- }
-
- @Override
- public boolean equals(Object object) {
- if (!(object instanceof XdrUnsignedInteger)) {
- return false;
- }
-
- XdrUnsignedInteger other = (XdrUnsignedInteger) object;
- return Objects.equals(this.number, other.number);
- }
-
- public String toString() {
- return "XdrUnsignedInteger(number=" + this.getNumber() + ")";
- }
}
diff --git a/spec/output/generator_spec_java/const.x/TestArray.java b/spec/output/generator_spec_java/const.x/TestArray.java
index d7cd318e8..50fcb0495 100644
--- a/spec/output/generator_spec_java/const.x/TestArray.java
+++ b/spec/output/generator_spec_java/const.x/TestArray.java
@@ -5,11 +5,13 @@
import java.io.IOException;
-import static MyXDR.Constants.*;
import org.stellar.sdk.Base64Factory;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
-import java.util.Arrays;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+import lombok.AllArgsConstructor;
+import static MyXDR.Constants.*;
/**
* TestArray's original definition in the XDR file is:
@@ -17,26 +19,14 @@
* typedef int TestArray[FOO];
*
*/
+@Data
+@NoArgsConstructor
+@AllArgsConstructor
public class TestArray implements XdrElement {
private Integer[] TestArray;
-
- public TestArray() {}
-
- public TestArray(Integer[] TestArray) {
- this.TestArray = TestArray;
- }
-
- public Integer[] getTestArray() {
- return this.TestArray;
- }
-
- public void setTestArray(Integer[] value) {
- this.TestArray = value;
- }
-
public static void encode(XdrDataOutputStream stream, TestArray encodedTestArray) throws IOException {
- int TestArraysize = encodedTestArray.getTestArray().length;
- for (int i = 0; i < TestArraysize; i++) {
+ int TestArraySize = encodedTestArray.getTestArray().length;
+ for (int i = 0; i < TestArraySize; i++) {
stream.writeInt(encodedTestArray.TestArray[i]);
}
}
@@ -46,28 +36,14 @@ public void encode(XdrDataOutputStream stream) throws IOException {
}
public static TestArray decode(XdrDataInputStream stream) throws IOException {
TestArray decodedTestArray = new TestArray();
- int TestArraysize = FOO;
- decodedTestArray.TestArray = new Integer[TestArraysize];
- for (int i = 0; i < TestArraysize; i++) {
+ int TestArraySize = FOO;
+ decodedTestArray.TestArray = new Integer[TestArraySize];
+ for (int i = 0; i < TestArraySize; i++) {
decodedTestArray.TestArray[i] = stream.readInt();
}
return decodedTestArray;
}
- @Override
- public int hashCode() {
- return Arrays.hashCode(this.TestArray);
- }
-
- @Override
- public boolean equals(Object object) {
- if (!(object instanceof TestArray)) {
- return false;
- }
-
- TestArray other = (TestArray) object;
- return Arrays.equals(this.TestArray, other.TestArray);
- }
@Override
public String toXdrBase64() throws IOException {
return Base64Factory.getInstance().encodeToString(toXdrByteArray());
diff --git a/spec/output/generator_spec_java/const.x/TestArray2.java b/spec/output/generator_spec_java/const.x/TestArray2.java
index ba2fe8cfc..0636dc6df 100644
--- a/spec/output/generator_spec_java/const.x/TestArray2.java
+++ b/spec/output/generator_spec_java/const.x/TestArray2.java
@@ -5,11 +5,13 @@
import java.io.IOException;
-import static MyXDR.Constants.*;
import org.stellar.sdk.Base64Factory;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
-import java.util.Arrays;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+import lombok.AllArgsConstructor;
+import static MyXDR.Constants.*;
/**
* TestArray2's original definition in the XDR file is:
@@ -17,27 +19,15 @@
* typedef int TestArray2<FOO>;
*
*/
+@Data
+@NoArgsConstructor
+@AllArgsConstructor
public class TestArray2 implements XdrElement {
private Integer[] TestArray2;
-
- public TestArray2() {}
-
- public TestArray2(Integer[] TestArray2) {
- this.TestArray2 = TestArray2;
- }
-
- public Integer[] getTestArray2() {
- return this.TestArray2;
- }
-
- public void setTestArray2(Integer[] value) {
- this.TestArray2 = value;
- }
-
public static void encode(XdrDataOutputStream stream, TestArray2 encodedTestArray2) throws IOException {
- int TestArray2size = encodedTestArray2.getTestArray2().length;
- stream.writeInt(TestArray2size);
- for (int i = 0; i < TestArray2size; i++) {
+ int TestArray2Size = encodedTestArray2.getTestArray2().length;
+ stream.writeInt(TestArray2Size);
+ for (int i = 0; i < TestArray2Size; i++) {
stream.writeInt(encodedTestArray2.TestArray2[i]);
}
}
@@ -47,28 +37,14 @@ public void encode(XdrDataOutputStream stream) throws IOException {
}
public static TestArray2 decode(XdrDataInputStream stream) throws IOException {
TestArray2 decodedTestArray2 = new TestArray2();
- int TestArray2size = stream.readInt();
- decodedTestArray2.TestArray2 = new Integer[TestArray2size];
- for (int i = 0; i < TestArray2size; i++) {
+ int TestArray2Size = stream.readInt();
+ decodedTestArray2.TestArray2 = new Integer[TestArray2Size];
+ for (int i = 0; i < TestArray2Size; i++) {
decodedTestArray2.TestArray2[i] = stream.readInt();
}
return decodedTestArray2;
}
- @Override
- public int hashCode() {
- return Arrays.hashCode(this.TestArray2);
- }
-
- @Override
- public boolean equals(Object object) {
- if (!(object instanceof TestArray2)) {
- return false;
- }
-
- TestArray2 other = (TestArray2) object;
- return Arrays.equals(this.TestArray2, other.TestArray2);
- }
@Override
public String toXdrBase64() throws IOException {
return Base64Factory.getInstance().encodeToString(toXdrByteArray());
diff --git a/spec/output/generator_spec_java/const.x/XdrString.java b/spec/output/generator_spec_java/const.x/XdrString.java
index bb4e81fb4..2d8f8bbc9 100644
--- a/spec/output/generator_spec_java/const.x/XdrString.java
+++ b/spec/output/generator_spec_java/const.x/XdrString.java
@@ -4,90 +4,72 @@
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InvalidClassException;
-import java.nio.charset.Charset;
-import java.util.Arrays;
+import java.nio.charset.StandardCharsets;
+import lombok.Value;
import org.stellar.sdk.Base64Factory;
+@Value
public class XdrString implements XdrElement {
- private byte[] bytes;
+ byte[] bytes;
- public XdrString(byte[] bytes) {
- this.bytes = bytes;
- }
+ public XdrString(byte[] bytes) {
+ this.bytes = bytes;
+ }
- public XdrString(String text) {
- this.bytes = text.getBytes(Charset.forName("UTF-8"));
- }
+ public XdrString(String text) {
+ this.bytes = text.getBytes(StandardCharsets.UTF_8);
+ }
- @Override
- public void encode(XdrDataOutputStream stream) throws IOException {
- stream.writeInt(this.bytes.length);
- stream.write(this.bytes, 0, this.bytes.length);
- }
+ @Override
+ public void encode(XdrDataOutputStream stream) throws IOException {
+ stream.writeInt(this.bytes.length);
+ stream.write(this.bytes, 0, this.bytes.length);
+ }
- public static XdrString decode(XdrDataInputStream stream, int maxSize) throws IOException {
- int size = stream.readInt();
- if (size > maxSize) {
- throw new InvalidClassException("String length "+size+" exceeds max size "+maxSize);
- }
- byte[] bytes = new byte[size];
- stream.read(bytes);
- return new XdrString(bytes);
+ public static XdrString decode(XdrDataInputStream stream, int maxSize) throws IOException {
+ int size = stream.readInt();
+ if (size > maxSize) {
+ throw new InvalidClassException("String length " + size + " exceeds max size " + maxSize);
}
+ byte[] bytes = new byte[size];
+ stream.read(bytes);
+ return new XdrString(bytes);
+ }
- public byte[] getBytes() {
- return this.bytes;
- }
+ @Override
+ public String toXdrBase64() throws IOException {
+ return Base64Factory.getInstance().encodeToString(toXdrByteArray());
+ }
- @Override
- public String toXdrBase64() throws IOException {
- return Base64Factory.getInstance().encodeToString(toXdrByteArray());
- }
-
- @Override
- public byte[] toXdrByteArray() throws IOException {
- ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
- XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream);
- encode(xdrDataOutputStream);
- return byteArrayOutputStream.toByteArray();
- }
-
- public static XdrString fromXdrBase64(String xdr, int maxSize) throws IOException {
- byte[] bytes = Base64Factory.getInstance().decode(xdr);
- return fromXdrByteArray(bytes, maxSize);
- }
-
- public static XdrString fromXdrBase64(String xdr) throws IOException {
- return fromXdrBase64(xdr, Integer.MAX_VALUE);
- }
-
- public static XdrString fromXdrByteArray(byte[] xdr, int maxSize) throws IOException {
- ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr);
- XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream);
- return decode(xdrDataInputStream, maxSize);
- }
-
- public static XdrString fromXdrByteArray(byte[] xdr) throws IOException {
- return fromXdrByteArray(xdr, Integer.MAX_VALUE);
- }
+ @Override
+ public byte[] toXdrByteArray() throws IOException {
+ ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
+ XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream);
+ encode(xdrDataOutputStream);
+ return byteArrayOutputStream.toByteArray();
+ }
- @Override
- public int hashCode() {
- return Arrays.hashCode(this.bytes);
- }
+ public static XdrString fromXdrBase64(String xdr, int maxSize) throws IOException {
+ byte[] bytes = Base64Factory.getInstance().decode(xdr);
+ return fromXdrByteArray(bytes, maxSize);
+ }
- @Override
- public boolean equals(Object object) {
- if (object == null || !(object instanceof XdrString)) {
- return false;
- }
+ public static XdrString fromXdrBase64(String xdr) throws IOException {
+ return fromXdrBase64(xdr, Integer.MAX_VALUE);
+ }
- XdrString other = (XdrString) object;
- return Arrays.equals(this.bytes, other.bytes);
- }
+ public static XdrString fromXdrByteArray(byte[] xdr, int maxSize) throws IOException {
+ ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr);
+ XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream);
+ return decode(xdrDataInputStream, maxSize);
+ }
- @Override
- public String toString() {
- return new String(bytes, Charset.forName("UTF-8"));
- }
+ public static XdrString fromXdrByteArray(byte[] xdr) throws IOException {
+ return fromXdrByteArray(xdr, Integer.MAX_VALUE);
+ }
+
+ @Override
+ public String toString() {
+ return new String(bytes, StandardCharsets.UTF_8);
+ }
}
diff --git a/spec/output/generator_spec_java/const.x/XdrUnsignedHyperInteger.java b/spec/output/generator_spec_java/const.x/XdrUnsignedHyperInteger.java
index 6c05ca57d..204aa83de 100644
--- a/spec/output/generator_spec_java/const.x/XdrUnsignedHyperInteger.java
+++ b/spec/output/generator_spec_java/const.x/XdrUnsignedHyperInteger.java
@@ -1,10 +1,10 @@
-package org.stellar.sdk.xdr;
+package MyXDR;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.math.BigInteger;
-import java.util.Objects;
+import lombok.Value;
import org.stellar.sdk.Base64Factory;
/**
@@ -13,10 +13,11 @@
* @see XDR: External Data
* Representation Standard
*/
+@Value
public class XdrUnsignedHyperInteger implements XdrElement {
public static final BigInteger MAX_VALUE = new BigInteger("18446744073709551615");
public static final BigInteger MIN_VALUE = BigInteger.ZERO;
- private final BigInteger number;
+ BigInteger number;
public XdrUnsignedHyperInteger(BigInteger number) {
if (number.compareTo(MIN_VALUE) < 0 || number.compareTo(MAX_VALUE) > 0) {
@@ -55,10 +56,6 @@ private byte[] getBytes() {
return paddedBytes;
}
- public BigInteger getNumber() {
- return number;
- }
-
@Override
public String toXdrBase64() throws IOException {
return Base64Factory.getInstance().encodeToString(toXdrByteArray());
@@ -82,23 +79,4 @@ public static XdrUnsignedHyperInteger fromXdrByteArray(byte[] xdr) throws IOExce
XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream);
return decode(xdrDataInputStream);
}
-
- @Override
- public int hashCode() {
- return Objects.hash(this.number);
- }
-
- @Override
- public boolean equals(Object object) {
- if (!(object instanceof XdrUnsignedHyperInteger)) {
- return false;
- }
-
- XdrUnsignedHyperInteger other = (XdrUnsignedHyperInteger) object;
- return Objects.equals(this.number, other.number);
- }
-
- public String toString() {
- return "XdrUnsignedInteger(number=" + this.getNumber() + ")";
- }
}
diff --git a/spec/output/generator_spec_java/const.x/XdrUnsignedInteger.java b/spec/output/generator_spec_java/const.x/XdrUnsignedInteger.java
index 8f2a52395..a56ad657d 100644
--- a/spec/output/generator_spec_java/const.x/XdrUnsignedInteger.java
+++ b/spec/output/generator_spec_java/const.x/XdrUnsignedInteger.java
@@ -1,9 +1,9 @@
-package org.stellar.sdk.xdr;
+package MyXDR;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
-import java.util.Objects;
+import lombok.Value;
import org.stellar.sdk.Base64Factory;
/**
@@ -12,10 +12,11 @@
* @see XDR: External Data
* Representation Standard
*/
+@Value
public class XdrUnsignedInteger implements XdrElement {
public static final long MAX_VALUE = (1L << 32) - 1;
public static final long MIN_VALUE = 0;
- private final Long number;
+ Long number;
public XdrUnsignedInteger(Long number) {
if (number < MIN_VALUE || number > MAX_VALUE) {
@@ -32,10 +33,6 @@ public XdrUnsignedInteger(Integer number) {
this.number = number.longValue();
}
- public Long getNumber() {
- return number;
- }
-
public static XdrUnsignedInteger decode(XdrDataInputStream stream) throws IOException {
int intValue = stream.readInt();
long uint32Value = Integer.toUnsignedLong(intValue);
@@ -70,23 +67,4 @@ public static XdrUnsignedInteger fromXdrByteArray(byte[] xdr) throws IOException
XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream);
return decode(xdrDataInputStream);
}
-
- @Override
- public int hashCode() {
- return Objects.hash(this.number);
- }
-
- @Override
- public boolean equals(Object object) {
- if (!(object instanceof XdrUnsignedInteger)) {
- return false;
- }
-
- XdrUnsignedInteger other = (XdrUnsignedInteger) object;
- return Objects.equals(this.number, other.number);
- }
-
- public String toString() {
- return "XdrUnsignedInteger(number=" + this.getNumber() + ")";
- }
}
diff --git a/spec/output/generator_spec_java/enum.x/Color.java b/spec/output/generator_spec_java/enum.x/Color.java
index 546993fa8..a56cc062c 100644
--- a/spec/output/generator_spec_java/enum.x/Color.java
+++ b/spec/output/generator_spec_java/enum.x/Color.java
@@ -5,7 +5,6 @@
import java.io.IOException;
-import static MyXDR.Constants.*;
import org.stellar.sdk.Base64Factory;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
@@ -23,16 +22,16 @@
public enum Color implements XdrElement {
RED(0),
GREEN(1),
- BLUE(2),
- ;
- private int mValue;
+ BLUE(2);
+
+ private final int value;
Color(int value) {
- mValue = value;
+ this.value = value;
}
public int getValue() {
- return mValue;
+ return value;
}
public static Color decode(XdrDataInputStream stream) throws IOException {
diff --git a/spec/output/generator_spec_java/enum.x/Color2.java b/spec/output/generator_spec_java/enum.x/Color2.java
index 9662817a0..56496d71c 100644
--- a/spec/output/generator_spec_java/enum.x/Color2.java
+++ b/spec/output/generator_spec_java/enum.x/Color2.java
@@ -5,7 +5,6 @@
import java.io.IOException;
-import static MyXDR.Constants.*;
import org.stellar.sdk.Base64Factory;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
@@ -23,16 +22,16 @@
public enum Color2 implements XdrElement {
RED2(0),
GREEN2(1),
- BLUE2(2),
- ;
- private int mValue;
+ BLUE2(2);
+
+ private final int value;
Color2(int value) {
- mValue = value;
+ this.value = value;
}
public int getValue() {
- return mValue;
+ return value;
}
public static Color2 decode(XdrDataInputStream stream) throws IOException {
diff --git a/spec/output/generator_spec_java/enum.x/MessageType.java b/spec/output/generator_spec_java/enum.x/MessageType.java
index f2be344cc..5043b7b88 100644
--- a/spec/output/generator_spec_java/enum.x/MessageType.java
+++ b/spec/output/generator_spec_java/enum.x/MessageType.java
@@ -5,7 +5,6 @@
import java.io.IOException;
-import static MyXDR.Constants.*;
import org.stellar.sdk.Base64Factory;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
@@ -52,16 +51,16 @@ public enum MessageType implements XdrElement {
JSON_TRANSACTION(10),
GET_FBA_QUORUMSET(11),
FBA_QUORUMSET(12),
- FBA_MESSAGE(13),
- ;
- private int mValue;
+ FBA_MESSAGE(13);
+
+ private final int value;
MessageType(int value) {
- mValue = value;
+ this.value = value;
}
public int getValue() {
- return mValue;
+ return value;
}
public static MessageType decode(XdrDataInputStream stream) throws IOException {
diff --git a/spec/output/generator_spec_java/enum.x/XdrString.java b/spec/output/generator_spec_java/enum.x/XdrString.java
index bb4e81fb4..2d8f8bbc9 100644
--- a/spec/output/generator_spec_java/enum.x/XdrString.java
+++ b/spec/output/generator_spec_java/enum.x/XdrString.java
@@ -4,90 +4,72 @@
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InvalidClassException;
-import java.nio.charset.Charset;
-import java.util.Arrays;
+import java.nio.charset.StandardCharsets;
+import lombok.Value;
import org.stellar.sdk.Base64Factory;
+@Value
public class XdrString implements XdrElement {
- private byte[] bytes;
+ byte[] bytes;
- public XdrString(byte[] bytes) {
- this.bytes = bytes;
- }
+ public XdrString(byte[] bytes) {
+ this.bytes = bytes;
+ }
- public XdrString(String text) {
- this.bytes = text.getBytes(Charset.forName("UTF-8"));
- }
+ public XdrString(String text) {
+ this.bytes = text.getBytes(StandardCharsets.UTF_8);
+ }
- @Override
- public void encode(XdrDataOutputStream stream) throws IOException {
- stream.writeInt(this.bytes.length);
- stream.write(this.bytes, 0, this.bytes.length);
- }
+ @Override
+ public void encode(XdrDataOutputStream stream) throws IOException {
+ stream.writeInt(this.bytes.length);
+ stream.write(this.bytes, 0, this.bytes.length);
+ }
- public static XdrString decode(XdrDataInputStream stream, int maxSize) throws IOException {
- int size = stream.readInt();
- if (size > maxSize) {
- throw new InvalidClassException("String length "+size+" exceeds max size "+maxSize);
- }
- byte[] bytes = new byte[size];
- stream.read(bytes);
- return new XdrString(bytes);
+ public static XdrString decode(XdrDataInputStream stream, int maxSize) throws IOException {
+ int size = stream.readInt();
+ if (size > maxSize) {
+ throw new InvalidClassException("String length " + size + " exceeds max size " + maxSize);
}
+ byte[] bytes = new byte[size];
+ stream.read(bytes);
+ return new XdrString(bytes);
+ }
- public byte[] getBytes() {
- return this.bytes;
- }
+ @Override
+ public String toXdrBase64() throws IOException {
+ return Base64Factory.getInstance().encodeToString(toXdrByteArray());
+ }
- @Override
- public String toXdrBase64() throws IOException {
- return Base64Factory.getInstance().encodeToString(toXdrByteArray());
- }
-
- @Override
- public byte[] toXdrByteArray() throws IOException {
- ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
- XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream);
- encode(xdrDataOutputStream);
- return byteArrayOutputStream.toByteArray();
- }
-
- public static XdrString fromXdrBase64(String xdr, int maxSize) throws IOException {
- byte[] bytes = Base64Factory.getInstance().decode(xdr);
- return fromXdrByteArray(bytes, maxSize);
- }
-
- public static XdrString fromXdrBase64(String xdr) throws IOException {
- return fromXdrBase64(xdr, Integer.MAX_VALUE);
- }
-
- public static XdrString fromXdrByteArray(byte[] xdr, int maxSize) throws IOException {
- ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr);
- XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream);
- return decode(xdrDataInputStream, maxSize);
- }
-
- public static XdrString fromXdrByteArray(byte[] xdr) throws IOException {
- return fromXdrByteArray(xdr, Integer.MAX_VALUE);
- }
+ @Override
+ public byte[] toXdrByteArray() throws IOException {
+ ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
+ XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream);
+ encode(xdrDataOutputStream);
+ return byteArrayOutputStream.toByteArray();
+ }
- @Override
- public int hashCode() {
- return Arrays.hashCode(this.bytes);
- }
+ public static XdrString fromXdrBase64(String xdr, int maxSize) throws IOException {
+ byte[] bytes = Base64Factory.getInstance().decode(xdr);
+ return fromXdrByteArray(bytes, maxSize);
+ }
- @Override
- public boolean equals(Object object) {
- if (object == null || !(object instanceof XdrString)) {
- return false;
- }
+ public static XdrString fromXdrBase64(String xdr) throws IOException {
+ return fromXdrBase64(xdr, Integer.MAX_VALUE);
+ }
- XdrString other = (XdrString) object;
- return Arrays.equals(this.bytes, other.bytes);
- }
+ public static XdrString fromXdrByteArray(byte[] xdr, int maxSize) throws IOException {
+ ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr);
+ XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream);
+ return decode(xdrDataInputStream, maxSize);
+ }
- @Override
- public String toString() {
- return new String(bytes, Charset.forName("UTF-8"));
- }
+ public static XdrString fromXdrByteArray(byte[] xdr) throws IOException {
+ return fromXdrByteArray(xdr, Integer.MAX_VALUE);
+ }
+
+ @Override
+ public String toString() {
+ return new String(bytes, StandardCharsets.UTF_8);
+ }
}
diff --git a/spec/output/generator_spec_java/enum.x/XdrUnsignedHyperInteger.java b/spec/output/generator_spec_java/enum.x/XdrUnsignedHyperInteger.java
index 6c05ca57d..204aa83de 100644
--- a/spec/output/generator_spec_java/enum.x/XdrUnsignedHyperInteger.java
+++ b/spec/output/generator_spec_java/enum.x/XdrUnsignedHyperInteger.java
@@ -1,10 +1,10 @@
-package org.stellar.sdk.xdr;
+package MyXDR;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.math.BigInteger;
-import java.util.Objects;
+import lombok.Value;
import org.stellar.sdk.Base64Factory;
/**
@@ -13,10 +13,11 @@
* @see XDR: External Data
* Representation Standard
*/
+@Value
public class XdrUnsignedHyperInteger implements XdrElement {
public static final BigInteger MAX_VALUE = new BigInteger("18446744073709551615");
public static final BigInteger MIN_VALUE = BigInteger.ZERO;
- private final BigInteger number;
+ BigInteger number;
public XdrUnsignedHyperInteger(BigInteger number) {
if (number.compareTo(MIN_VALUE) < 0 || number.compareTo(MAX_VALUE) > 0) {
@@ -55,10 +56,6 @@ private byte[] getBytes() {
return paddedBytes;
}
- public BigInteger getNumber() {
- return number;
- }
-
@Override
public String toXdrBase64() throws IOException {
return Base64Factory.getInstance().encodeToString(toXdrByteArray());
@@ -82,23 +79,4 @@ public static XdrUnsignedHyperInteger fromXdrByteArray(byte[] xdr) throws IOExce
XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream);
return decode(xdrDataInputStream);
}
-
- @Override
- public int hashCode() {
- return Objects.hash(this.number);
- }
-
- @Override
- public boolean equals(Object object) {
- if (!(object instanceof XdrUnsignedHyperInteger)) {
- return false;
- }
-
- XdrUnsignedHyperInteger other = (XdrUnsignedHyperInteger) object;
- return Objects.equals(this.number, other.number);
- }
-
- public String toString() {
- return "XdrUnsignedInteger(number=" + this.getNumber() + ")";
- }
}
diff --git a/spec/output/generator_spec_java/enum.x/XdrUnsignedInteger.java b/spec/output/generator_spec_java/enum.x/XdrUnsignedInteger.java
index 8f2a52395..a56ad657d 100644
--- a/spec/output/generator_spec_java/enum.x/XdrUnsignedInteger.java
+++ b/spec/output/generator_spec_java/enum.x/XdrUnsignedInteger.java
@@ -1,9 +1,9 @@
-package org.stellar.sdk.xdr;
+package MyXDR;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
-import java.util.Objects;
+import lombok.Value;
import org.stellar.sdk.Base64Factory;
/**
@@ -12,10 +12,11 @@
* @see XDR: External Data
* Representation Standard
*/
+@Value
public class XdrUnsignedInteger implements XdrElement {
public static final long MAX_VALUE = (1L << 32) - 1;
public static final long MIN_VALUE = 0;
- private final Long number;
+ Long number;
public XdrUnsignedInteger(Long number) {
if (number < MIN_VALUE || number > MAX_VALUE) {
@@ -32,10 +33,6 @@ public XdrUnsignedInteger(Integer number) {
this.number = number.longValue();
}
- public Long getNumber() {
- return number;
- }
-
public static XdrUnsignedInteger decode(XdrDataInputStream stream) throws IOException {
int intValue = stream.readInt();
long uint32Value = Integer.toUnsignedLong(intValue);
@@ -70,23 +67,4 @@ public static XdrUnsignedInteger fromXdrByteArray(byte[] xdr) throws IOException
XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream);
return decode(xdrDataInputStream);
}
-
- @Override
- public int hashCode() {
- return Objects.hash(this.number);
- }
-
- @Override
- public boolean equals(Object object) {
- if (!(object instanceof XdrUnsignedInteger)) {
- return false;
- }
-
- XdrUnsignedInteger other = (XdrUnsignedInteger) object;
- return Objects.equals(this.number, other.number);
- }
-
- public String toString() {
- return "XdrUnsignedInteger(number=" + this.getNumber() + ")";
- }
}
diff --git a/spec/output/generator_spec_java/nesting.x/Foo.java b/spec/output/generator_spec_java/nesting.x/Foo.java
index 7c53c1371..9ee721188 100644
--- a/spec/output/generator_spec_java/nesting.x/Foo.java
+++ b/spec/output/generator_spec_java/nesting.x/Foo.java
@@ -5,11 +5,13 @@
import java.io.IOException;
-import static MyXDR.Constants.*;
import org.stellar.sdk.Base64Factory;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
-import java.util.Objects;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+import lombok.AllArgsConstructor;
+import static MyXDR.Constants.*;
/**
* Foo's original definition in the XDR file is:
@@ -17,23 +19,11 @@
* typedef int Foo;
*
*/
+@Data
+@NoArgsConstructor
+@AllArgsConstructor
public class Foo implements XdrElement {
private Integer Foo;
-
- public Foo() {}
-
- public Foo(Integer Foo) {
- this.Foo = Foo;
- }
-
- public Integer getFoo() {
- return this.Foo;
- }
-
- public void setFoo(Integer value) {
- this.Foo = value;
- }
-
public static void encode(XdrDataOutputStream stream, Foo encodedFoo) throws IOException {
stream.writeInt(encodedFoo.Foo);
}
@@ -47,20 +37,6 @@ public static Foo decode(XdrDataInputStream stream) throws IOException {
return decodedFoo;
}
- @Override
- public int hashCode() {
- return Objects.hash(this.Foo);
- }
-
- @Override
- public boolean equals(Object object) {
- if (!(object instanceof Foo)) {
- return false;
- }
-
- Foo other = (Foo) object;
- return Objects.equals(this.Foo, other.Foo);
- }
@Override
public String toXdrBase64() throws IOException {
return Base64Factory.getInstance().encodeToString(toXdrByteArray());
diff --git a/spec/output/generator_spec_java/nesting.x/MyUnion.java b/spec/output/generator_spec_java/nesting.x/MyUnion.java
index ab29d0fbd..f63690615 100644
--- a/spec/output/generator_spec_java/nesting.x/MyUnion.java
+++ b/spec/output/generator_spec_java/nesting.x/MyUnion.java
@@ -5,11 +5,14 @@
import java.io.IOException;
-import static MyXDR.Constants.*;
import org.stellar.sdk.Base64Factory;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
-import java.util.Objects;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import static MyXDR.Constants.*;
/**
* MyUnion's original definition in the XDR file is:
@@ -32,58 +35,14 @@
* };
*
*/
+@Data
+@NoArgsConstructor
+@AllArgsConstructor
+@Builder(toBuilder = true)
public class MyUnion implements XdrElement {
- public MyUnion () {}
- UnionKey type;
- public UnionKey getDiscriminant() {
- return this.type;
- }
- public void setDiscriminant(UnionKey value) {
- this.type = value;
- }
+ private UnionKey discriminant;
private MyUnionOne one;
- public MyUnionOne getOne() {
- return this.one;
- }
- public void setOne(MyUnionOne value) {
- this.one = value;
- }
private MyUnionTwo two;
- public MyUnionTwo getTwo() {
- return this.two;
- }
- public void setTwo(MyUnionTwo value) {
- this.two = value;
- }
-
- public static final class Builder {
- private UnionKey discriminant;
- private MyUnionOne one;
- private MyUnionTwo two;
-
- public Builder discriminant(UnionKey discriminant) {
- this.discriminant = discriminant;
- return this;
- }
-
- public Builder one(MyUnionOne one) {
- this.one = one;
- return this;
- }
-
- public Builder two(MyUnionTwo two) {
- this.two = two;
- return this;
- }
-
- public MyUnion build() {
- MyUnion val = new MyUnion();
- val.setDiscriminant(discriminant);
- val.setOne(this.one);
- val.setTwo(this.two);
- return val;
- }
- }
public static void encode(XdrDataOutputStream stream, MyUnion encodedMyUnion) throws IOException {
//Xdrgen::AST::Identifier
@@ -120,19 +79,6 @@ public static MyUnion decode(XdrDataInputStream stream) throws IOException {
return decodedMyUnion;
}
@Override
- public int hashCode() {
- return Objects.hash(this.one, this.two, this.type);
- }
- @Override
- public boolean equals(Object object) {
- if (!(object instanceof MyUnion)) {
- return false;
- }
-
- MyUnion other = (MyUnion) object;
- return Objects.equals(this.one, other.one) && Objects.equals(this.two, other.two) && Objects.equals(this.type, other.type);
- }
- @Override
public String toXdrBase64() throws IOException {
return Base64Factory.getInstance().encodeToString(toXdrByteArray());
}
@@ -164,15 +110,12 @@ public static MyUnion fromXdrByteArray(byte[] xdr) throws IOException {
* }
*
*/
+ @Data
+ @NoArgsConstructor
+ @AllArgsConstructor
+ @Builder(toBuilder = true)
public static class MyUnionOne implements XdrElement {
- public MyUnionOne () {}
private Integer someInt;
- public Integer getSomeInt() {
- return this.someInt;
- }
- public void setSomeInt(Integer value) {
- this.someInt = value;
- }
public static void encode(XdrDataOutputStream stream, MyUnionOne encodedMyUnionOne) throws IOException{
stream.writeInt(encodedMyUnionOne.someInt);
}
@@ -184,20 +127,6 @@ public static MyUnionOne decode(XdrDataInputStream stream) throws IOException {
decodedMyUnionOne.someInt = stream.readInt();
return decodedMyUnionOne;
}
- @Override
- public int hashCode() {
- return Objects.hash(this.someInt);
- }
- @Override
- public boolean equals(Object object) {
- if (!(object instanceof MyUnionOne)) {
- return false;
- }
-
- MyUnionOne other = (MyUnionOne) object;
- return Objects.equals(this.someInt, other.someInt);
- }
-
@Override
public String toXdrBase64() throws IOException {
return Base64Factory.getInstance().encodeToString(toXdrByteArray());
@@ -221,20 +150,6 @@ public static MyUnionOne fromXdrByteArray(byte[] xdr) throws IOException {
XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream);
return decode(xdrDataInputStream);
}
- public static final class Builder {
- private Integer someInt;
-
- public Builder someInt(Integer someInt) {
- this.someInt = someInt;
- return this;
- }
-
- public MyUnionOne build() {
- MyUnionOne val = new MyUnionOne();
- val.setSomeInt(this.someInt);
- return val;
- }
- }
}
/**
@@ -246,22 +161,13 @@ public MyUnionOne build() {
* }
*
*/
+ @Data
+ @NoArgsConstructor
+ @AllArgsConstructor
+ @Builder(toBuilder = true)
public static class MyUnionTwo implements XdrElement {
- public MyUnionTwo () {}
private Integer someInt;
- public Integer getSomeInt() {
- return this.someInt;
- }
- public void setSomeInt(Integer value) {
- this.someInt = value;
- }
private Foo foo;
- public Foo getFoo() {
- return this.foo;
- }
- public void setFoo(Foo value) {
- this.foo = value;
- }
public static void encode(XdrDataOutputStream stream, MyUnionTwo encodedMyUnionTwo) throws IOException{
stream.writeInt(encodedMyUnionTwo.someInt);
Foo.encode(stream, encodedMyUnionTwo.foo);
@@ -275,20 +181,6 @@ public static MyUnionTwo decode(XdrDataInputStream stream) throws IOException {
decodedMyUnionTwo.foo = Foo.decode(stream);
return decodedMyUnionTwo;
}
- @Override
- public int hashCode() {
- return Objects.hash(this.someInt, this.foo);
- }
- @Override
- public boolean equals(Object object) {
- if (!(object instanceof MyUnionTwo)) {
- return false;
- }
-
- MyUnionTwo other = (MyUnionTwo) object;
- return Objects.equals(this.someInt, other.someInt) && Objects.equals(this.foo, other.foo);
- }
-
@Override
public String toXdrBase64() throws IOException {
return Base64Factory.getInstance().encodeToString(toXdrByteArray());
@@ -312,27 +204,6 @@ public static MyUnionTwo fromXdrByteArray(byte[] xdr) throws IOException {
XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream);
return decode(xdrDataInputStream);
}
- public static final class Builder {
- private Integer someInt;
- private Foo foo;
-
- public Builder someInt(Integer someInt) {
- this.someInt = someInt;
- return this;
- }
-
- public Builder foo(Foo foo) {
- this.foo = foo;
- return this;
- }
-
- public MyUnionTwo build() {
- MyUnionTwo val = new MyUnionTwo();
- val.setSomeInt(this.someInt);
- val.setFoo(this.foo);
- return val;
- }
- }
}
}
diff --git a/spec/output/generator_spec_java/nesting.x/UnionKey.java b/spec/output/generator_spec_java/nesting.x/UnionKey.java
index fb3136582..3118cdb76 100644
--- a/spec/output/generator_spec_java/nesting.x/UnionKey.java
+++ b/spec/output/generator_spec_java/nesting.x/UnionKey.java
@@ -5,7 +5,6 @@
import java.io.IOException;
-import static MyXDR.Constants.*;
import org.stellar.sdk.Base64Factory;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
@@ -23,16 +22,16 @@
public enum UnionKey implements XdrElement {
ONE(1),
TWO(2),
- OFFER(3),
- ;
- private int mValue;
+ OFFER(3);
+
+ private final int value;
UnionKey(int value) {
- mValue = value;
+ this.value = value;
}
public int getValue() {
- return mValue;
+ return value;
}
public static UnionKey decode(XdrDataInputStream stream) throws IOException {
diff --git a/spec/output/generator_spec_java/nesting.x/XdrString.java b/spec/output/generator_spec_java/nesting.x/XdrString.java
index bb4e81fb4..2d8f8bbc9 100644
--- a/spec/output/generator_spec_java/nesting.x/XdrString.java
+++ b/spec/output/generator_spec_java/nesting.x/XdrString.java
@@ -4,90 +4,72 @@
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InvalidClassException;
-import java.nio.charset.Charset;
-import java.util.Arrays;
+import java.nio.charset.StandardCharsets;
+import lombok.Value;
import org.stellar.sdk.Base64Factory;
+@Value
public class XdrString implements XdrElement {
- private byte[] bytes;
+ byte[] bytes;
- public XdrString(byte[] bytes) {
- this.bytes = bytes;
- }
+ public XdrString(byte[] bytes) {
+ this.bytes = bytes;
+ }
- public XdrString(String text) {
- this.bytes = text.getBytes(Charset.forName("UTF-8"));
- }
+ public XdrString(String text) {
+ this.bytes = text.getBytes(StandardCharsets.UTF_8);
+ }
- @Override
- public void encode(XdrDataOutputStream stream) throws IOException {
- stream.writeInt(this.bytes.length);
- stream.write(this.bytes, 0, this.bytes.length);
- }
+ @Override
+ public void encode(XdrDataOutputStream stream) throws IOException {
+ stream.writeInt(this.bytes.length);
+ stream.write(this.bytes, 0, this.bytes.length);
+ }
- public static XdrString decode(XdrDataInputStream stream, int maxSize) throws IOException {
- int size = stream.readInt();
- if (size > maxSize) {
- throw new InvalidClassException("String length "+size+" exceeds max size "+maxSize);
- }
- byte[] bytes = new byte[size];
- stream.read(bytes);
- return new XdrString(bytes);
+ public static XdrString decode(XdrDataInputStream stream, int maxSize) throws IOException {
+ int size = stream.readInt();
+ if (size > maxSize) {
+ throw new InvalidClassException("String length " + size + " exceeds max size " + maxSize);
}
+ byte[] bytes = new byte[size];
+ stream.read(bytes);
+ return new XdrString(bytes);
+ }
- public byte[] getBytes() {
- return this.bytes;
- }
+ @Override
+ public String toXdrBase64() throws IOException {
+ return Base64Factory.getInstance().encodeToString(toXdrByteArray());
+ }
- @Override
- public String toXdrBase64() throws IOException {
- return Base64Factory.getInstance().encodeToString(toXdrByteArray());
- }
-
- @Override
- public byte[] toXdrByteArray() throws IOException {
- ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
- XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream);
- encode(xdrDataOutputStream);
- return byteArrayOutputStream.toByteArray();
- }
-
- public static XdrString fromXdrBase64(String xdr, int maxSize) throws IOException {
- byte[] bytes = Base64Factory.getInstance().decode(xdr);
- return fromXdrByteArray(bytes, maxSize);
- }
-
- public static XdrString fromXdrBase64(String xdr) throws IOException {
- return fromXdrBase64(xdr, Integer.MAX_VALUE);
- }
-
- public static XdrString fromXdrByteArray(byte[] xdr, int maxSize) throws IOException {
- ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr);
- XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream);
- return decode(xdrDataInputStream, maxSize);
- }
-
- public static XdrString fromXdrByteArray(byte[] xdr) throws IOException {
- return fromXdrByteArray(xdr, Integer.MAX_VALUE);
- }
+ @Override
+ public byte[] toXdrByteArray() throws IOException {
+ ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
+ XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream);
+ encode(xdrDataOutputStream);
+ return byteArrayOutputStream.toByteArray();
+ }
- @Override
- public int hashCode() {
- return Arrays.hashCode(this.bytes);
- }
+ public static XdrString fromXdrBase64(String xdr, int maxSize) throws IOException {
+ byte[] bytes = Base64Factory.getInstance().decode(xdr);
+ return fromXdrByteArray(bytes, maxSize);
+ }
- @Override
- public boolean equals(Object object) {
- if (object == null || !(object instanceof XdrString)) {
- return false;
- }
+ public static XdrString fromXdrBase64(String xdr) throws IOException {
+ return fromXdrBase64(xdr, Integer.MAX_VALUE);
+ }
- XdrString other = (XdrString) object;
- return Arrays.equals(this.bytes, other.bytes);
- }
+ public static XdrString fromXdrByteArray(byte[] xdr, int maxSize) throws IOException {
+ ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr);
+ XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream);
+ return decode(xdrDataInputStream, maxSize);
+ }
- @Override
- public String toString() {
- return new String(bytes, Charset.forName("UTF-8"));
- }
+ public static XdrString fromXdrByteArray(byte[] xdr) throws IOException {
+ return fromXdrByteArray(xdr, Integer.MAX_VALUE);
+ }
+
+ @Override
+ public String toString() {
+ return new String(bytes, StandardCharsets.UTF_8);
+ }
}
diff --git a/spec/output/generator_spec_java/nesting.x/XdrUnsignedHyperInteger.java b/spec/output/generator_spec_java/nesting.x/XdrUnsignedHyperInteger.java
index 6c05ca57d..204aa83de 100644
--- a/spec/output/generator_spec_java/nesting.x/XdrUnsignedHyperInteger.java
+++ b/spec/output/generator_spec_java/nesting.x/XdrUnsignedHyperInteger.java
@@ -1,10 +1,10 @@
-package org.stellar.sdk.xdr;
+package MyXDR;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.math.BigInteger;
-import java.util.Objects;
+import lombok.Value;
import org.stellar.sdk.Base64Factory;
/**
@@ -13,10 +13,11 @@
* @see XDR: External Data
* Representation Standard
*/
+@Value
public class XdrUnsignedHyperInteger implements XdrElement {
public static final BigInteger MAX_VALUE = new BigInteger("18446744073709551615");
public static final BigInteger MIN_VALUE = BigInteger.ZERO;
- private final BigInteger number;
+ BigInteger number;
public XdrUnsignedHyperInteger(BigInteger number) {
if (number.compareTo(MIN_VALUE) < 0 || number.compareTo(MAX_VALUE) > 0) {
@@ -55,10 +56,6 @@ private byte[] getBytes() {
return paddedBytes;
}
- public BigInteger getNumber() {
- return number;
- }
-
@Override
public String toXdrBase64() throws IOException {
return Base64Factory.getInstance().encodeToString(toXdrByteArray());
@@ -82,23 +79,4 @@ public static XdrUnsignedHyperInteger fromXdrByteArray(byte[] xdr) throws IOExce
XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream);
return decode(xdrDataInputStream);
}
-
- @Override
- public int hashCode() {
- return Objects.hash(this.number);
- }
-
- @Override
- public boolean equals(Object object) {
- if (!(object instanceof XdrUnsignedHyperInteger)) {
- return false;
- }
-
- XdrUnsignedHyperInteger other = (XdrUnsignedHyperInteger) object;
- return Objects.equals(this.number, other.number);
- }
-
- public String toString() {
- return "XdrUnsignedInteger(number=" + this.getNumber() + ")";
- }
}
diff --git a/spec/output/generator_spec_java/nesting.x/XdrUnsignedInteger.java b/spec/output/generator_spec_java/nesting.x/XdrUnsignedInteger.java
index 8f2a52395..a56ad657d 100644
--- a/spec/output/generator_spec_java/nesting.x/XdrUnsignedInteger.java
+++ b/spec/output/generator_spec_java/nesting.x/XdrUnsignedInteger.java
@@ -1,9 +1,9 @@
-package org.stellar.sdk.xdr;
+package MyXDR;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
-import java.util.Objects;
+import lombok.Value;
import org.stellar.sdk.Base64Factory;
/**
@@ -12,10 +12,11 @@
* @see XDR: External Data
* Representation Standard
*/
+@Value
public class XdrUnsignedInteger implements XdrElement {
public static final long MAX_VALUE = (1L << 32) - 1;
public static final long MIN_VALUE = 0;
- private final Long number;
+ Long number;
public XdrUnsignedInteger(Long number) {
if (number < MIN_VALUE || number > MAX_VALUE) {
@@ -32,10 +33,6 @@ public XdrUnsignedInteger(Integer number) {
this.number = number.longValue();
}
- public Long getNumber() {
- return number;
- }
-
public static XdrUnsignedInteger decode(XdrDataInputStream stream) throws IOException {
int intValue = stream.readInt();
long uint32Value = Integer.toUnsignedLong(intValue);
@@ -70,23 +67,4 @@ public static XdrUnsignedInteger fromXdrByteArray(byte[] xdr) throws IOException
XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream);
return decode(xdrDataInputStream);
}
-
- @Override
- public int hashCode() {
- return Objects.hash(this.number);
- }
-
- @Override
- public boolean equals(Object object) {
- if (!(object instanceof XdrUnsignedInteger)) {
- return false;
- }
-
- XdrUnsignedInteger other = (XdrUnsignedInteger) object;
- return Objects.equals(this.number, other.number);
- }
-
- public String toString() {
- return "XdrUnsignedInteger(number=" + this.getNumber() + ")";
- }
}
diff --git a/spec/output/generator_spec_java/optional.x/Arr.java b/spec/output/generator_spec_java/optional.x/Arr.java
index 860b59f87..a2ff03d6f 100644
--- a/spec/output/generator_spec_java/optional.x/Arr.java
+++ b/spec/output/generator_spec_java/optional.x/Arr.java
@@ -5,11 +5,13 @@
import java.io.IOException;
-import static MyXDR.Constants.*;
import org.stellar.sdk.Base64Factory;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
-import java.util.Arrays;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+import lombok.AllArgsConstructor;
+import static MyXDR.Constants.*;
/**
* Arr's original definition in the XDR file is:
@@ -17,26 +19,14 @@
* typedef int Arr[2];
*
*/
+@Data
+@NoArgsConstructor
+@AllArgsConstructor
public class Arr implements XdrElement {
private Integer[] Arr;
-
- public Arr() {}
-
- public Arr(Integer[] Arr) {
- this.Arr = Arr;
- }
-
- public Integer[] getArr() {
- return this.Arr;
- }
-
- public void setArr(Integer[] value) {
- this.Arr = value;
- }
-
public static void encode(XdrDataOutputStream stream, Arr encodedArr) throws IOException {
- int Arrsize = encodedArr.getArr().length;
- for (int i = 0; i < Arrsize; i++) {
+ int ArrSize = encodedArr.getArr().length;
+ for (int i = 0; i < ArrSize; i++) {
stream.writeInt(encodedArr.Arr[i]);
}
}
@@ -46,28 +36,14 @@ public void encode(XdrDataOutputStream stream) throws IOException {
}
public static Arr decode(XdrDataInputStream stream) throws IOException {
Arr decodedArr = new Arr();
- int Arrsize = 2;
- decodedArr.Arr = new Integer[Arrsize];
- for (int i = 0; i < Arrsize; i++) {
+ int ArrSize = 2;
+ decodedArr.Arr = new Integer[ArrSize];
+ for (int i = 0; i < ArrSize; i++) {
decodedArr.Arr[i] = stream.readInt();
}
return decodedArr;
}
- @Override
- public int hashCode() {
- return Arrays.hashCode(this.Arr);
- }
-
- @Override
- public boolean equals(Object object) {
- if (!(object instanceof Arr)) {
- return false;
- }
-
- Arr other = (Arr) object;
- return Arrays.equals(this.Arr, other.Arr);
- }
@Override
public String toXdrBase64() throws IOException {
return Base64Factory.getInstance().encodeToString(toXdrByteArray());
diff --git a/spec/output/generator_spec_java/optional.x/HasOptions.java b/spec/output/generator_spec_java/optional.x/HasOptions.java
index 4c07e944c..607da9213 100644
--- a/spec/output/generator_spec_java/optional.x/HasOptions.java
+++ b/spec/output/generator_spec_java/optional.x/HasOptions.java
@@ -5,11 +5,14 @@
import java.io.IOException;
-import static MyXDR.Constants.*;
import org.stellar.sdk.Base64Factory;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
-import java.util.Objects;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import static MyXDR.Constants.*;
/**
* HasOptions's original definition in the XDR file is:
@@ -22,29 +25,14 @@
* };
*
*/
+@Data
+@NoArgsConstructor
+@AllArgsConstructor
+@Builder(toBuilder = true)
public class HasOptions implements XdrElement {
- public HasOptions () {}
private Integer firstOption;
- public Integer getFirstOption() {
- return this.firstOption;
- }
- public void setFirstOption(Integer value) {
- this.firstOption = value;
- }
private Integer secondOption;
- public Integer getSecondOption() {
- return this.secondOption;
- }
- public void setSecondOption(Integer value) {
- this.secondOption = value;
- }
private Arr thirdOption;
- public Arr getThirdOption() {
- return this.thirdOption;
- }
- public void setThirdOption(Arr value) {
- this.thirdOption = value;
- }
public static void encode(XdrDataOutputStream stream, HasOptions encodedHasOptions) throws IOException{
if (encodedHasOptions.firstOption != null) {
stream.writeInt(1);
@@ -84,20 +72,6 @@ public static HasOptions decode(XdrDataInputStream stream) throws IOException {
}
return decodedHasOptions;
}
- @Override
- public int hashCode() {
- return Objects.hash(this.firstOption, this.secondOption, this.thirdOption);
- }
- @Override
- public boolean equals(Object object) {
- if (!(object instanceof HasOptions)) {
- return false;
- }
-
- HasOptions other = (HasOptions) object;
- return Objects.equals(this.firstOption, other.firstOption) && Objects.equals(this.secondOption, other.secondOption) && Objects.equals(this.thirdOption, other.thirdOption);
- }
-
@Override
public String toXdrBase64() throws IOException {
return Base64Factory.getInstance().encodeToString(toXdrByteArray());
@@ -121,32 +95,4 @@ public static HasOptions fromXdrByteArray(byte[] xdr) throws IOException {
XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream);
return decode(xdrDataInputStream);
}
- public static final class Builder {
- private Integer firstOption;
- private Integer secondOption;
- private Arr thirdOption;
-
- public Builder firstOption(Integer firstOption) {
- this.firstOption = firstOption;
- return this;
- }
-
- public Builder secondOption(Integer secondOption) {
- this.secondOption = secondOption;
- return this;
- }
-
- public Builder thirdOption(Arr thirdOption) {
- this.thirdOption = thirdOption;
- return this;
- }
-
- public HasOptions build() {
- HasOptions val = new HasOptions();
- val.setFirstOption(this.firstOption);
- val.setSecondOption(this.secondOption);
- val.setThirdOption(this.thirdOption);
- return val;
- }
- }
}
diff --git a/spec/output/generator_spec_java/optional.x/XdrString.java b/spec/output/generator_spec_java/optional.x/XdrString.java
index bb4e81fb4..2d8f8bbc9 100644
--- a/spec/output/generator_spec_java/optional.x/XdrString.java
+++ b/spec/output/generator_spec_java/optional.x/XdrString.java
@@ -4,90 +4,72 @@
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InvalidClassException;
-import java.nio.charset.Charset;
-import java.util.Arrays;
+import java.nio.charset.StandardCharsets;
+import lombok.Value;
import org.stellar.sdk.Base64Factory;
+@Value
public class XdrString implements XdrElement {
- private byte[] bytes;
+ byte[] bytes;
- public XdrString(byte[] bytes) {
- this.bytes = bytes;
- }
+ public XdrString(byte[] bytes) {
+ this.bytes = bytes;
+ }
- public XdrString(String text) {
- this.bytes = text.getBytes(Charset.forName("UTF-8"));
- }
+ public XdrString(String text) {
+ this.bytes = text.getBytes(StandardCharsets.UTF_8);
+ }
- @Override
- public void encode(XdrDataOutputStream stream) throws IOException {
- stream.writeInt(this.bytes.length);
- stream.write(this.bytes, 0, this.bytes.length);
- }
+ @Override
+ public void encode(XdrDataOutputStream stream) throws IOException {
+ stream.writeInt(this.bytes.length);
+ stream.write(this.bytes, 0, this.bytes.length);
+ }
- public static XdrString decode(XdrDataInputStream stream, int maxSize) throws IOException {
- int size = stream.readInt();
- if (size > maxSize) {
- throw new InvalidClassException("String length "+size+" exceeds max size "+maxSize);
- }
- byte[] bytes = new byte[size];
- stream.read(bytes);
- return new XdrString(bytes);
+ public static XdrString decode(XdrDataInputStream stream, int maxSize) throws IOException {
+ int size = stream.readInt();
+ if (size > maxSize) {
+ throw new InvalidClassException("String length " + size + " exceeds max size " + maxSize);
}
+ byte[] bytes = new byte[size];
+ stream.read(bytes);
+ return new XdrString(bytes);
+ }
- public byte[] getBytes() {
- return this.bytes;
- }
+ @Override
+ public String toXdrBase64() throws IOException {
+ return Base64Factory.getInstance().encodeToString(toXdrByteArray());
+ }
- @Override
- public String toXdrBase64() throws IOException {
- return Base64Factory.getInstance().encodeToString(toXdrByteArray());
- }
-
- @Override
- public byte[] toXdrByteArray() throws IOException {
- ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
- XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream);
- encode(xdrDataOutputStream);
- return byteArrayOutputStream.toByteArray();
- }
-
- public static XdrString fromXdrBase64(String xdr, int maxSize) throws IOException {
- byte[] bytes = Base64Factory.getInstance().decode(xdr);
- return fromXdrByteArray(bytes, maxSize);
- }
-
- public static XdrString fromXdrBase64(String xdr) throws IOException {
- return fromXdrBase64(xdr, Integer.MAX_VALUE);
- }
-
- public static XdrString fromXdrByteArray(byte[] xdr, int maxSize) throws IOException {
- ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr);
- XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream);
- return decode(xdrDataInputStream, maxSize);
- }
-
- public static XdrString fromXdrByteArray(byte[] xdr) throws IOException {
- return fromXdrByteArray(xdr, Integer.MAX_VALUE);
- }
+ @Override
+ public byte[] toXdrByteArray() throws IOException {
+ ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
+ XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream);
+ encode(xdrDataOutputStream);
+ return byteArrayOutputStream.toByteArray();
+ }
- @Override
- public int hashCode() {
- return Arrays.hashCode(this.bytes);
- }
+ public static XdrString fromXdrBase64(String xdr, int maxSize) throws IOException {
+ byte[] bytes = Base64Factory.getInstance().decode(xdr);
+ return fromXdrByteArray(bytes, maxSize);
+ }
- @Override
- public boolean equals(Object object) {
- if (object == null || !(object instanceof XdrString)) {
- return false;
- }
+ public static XdrString fromXdrBase64(String xdr) throws IOException {
+ return fromXdrBase64(xdr, Integer.MAX_VALUE);
+ }
- XdrString other = (XdrString) object;
- return Arrays.equals(this.bytes, other.bytes);
- }
+ public static XdrString fromXdrByteArray(byte[] xdr, int maxSize) throws IOException {
+ ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr);
+ XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream);
+ return decode(xdrDataInputStream, maxSize);
+ }
- @Override
- public String toString() {
- return new String(bytes, Charset.forName("UTF-8"));
- }
+ public static XdrString fromXdrByteArray(byte[] xdr) throws IOException {
+ return fromXdrByteArray(xdr, Integer.MAX_VALUE);
+ }
+
+ @Override
+ public String toString() {
+ return new String(bytes, StandardCharsets.UTF_8);
+ }
}
diff --git a/spec/output/generator_spec_java/optional.x/XdrUnsignedHyperInteger.java b/spec/output/generator_spec_java/optional.x/XdrUnsignedHyperInteger.java
index 6c05ca57d..204aa83de 100644
--- a/spec/output/generator_spec_java/optional.x/XdrUnsignedHyperInteger.java
+++ b/spec/output/generator_spec_java/optional.x/XdrUnsignedHyperInteger.java
@@ -1,10 +1,10 @@
-package org.stellar.sdk.xdr;
+package MyXDR;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.math.BigInteger;
-import java.util.Objects;
+import lombok.Value;
import org.stellar.sdk.Base64Factory;
/**
@@ -13,10 +13,11 @@
* @see XDR: External Data
* Representation Standard
*/
+@Value
public class XdrUnsignedHyperInteger implements XdrElement {
public static final BigInteger MAX_VALUE = new BigInteger("18446744073709551615");
public static final BigInteger MIN_VALUE = BigInteger.ZERO;
- private final BigInteger number;
+ BigInteger number;
public XdrUnsignedHyperInteger(BigInteger number) {
if (number.compareTo(MIN_VALUE) < 0 || number.compareTo(MAX_VALUE) > 0) {
@@ -55,10 +56,6 @@ private byte[] getBytes() {
return paddedBytes;
}
- public BigInteger getNumber() {
- return number;
- }
-
@Override
public String toXdrBase64() throws IOException {
return Base64Factory.getInstance().encodeToString(toXdrByteArray());
@@ -82,23 +79,4 @@ public static XdrUnsignedHyperInteger fromXdrByteArray(byte[] xdr) throws IOExce
XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream);
return decode(xdrDataInputStream);
}
-
- @Override
- public int hashCode() {
- return Objects.hash(this.number);
- }
-
- @Override
- public boolean equals(Object object) {
- if (!(object instanceof XdrUnsignedHyperInteger)) {
- return false;
- }
-
- XdrUnsignedHyperInteger other = (XdrUnsignedHyperInteger) object;
- return Objects.equals(this.number, other.number);
- }
-
- public String toString() {
- return "XdrUnsignedInteger(number=" + this.getNumber() + ")";
- }
}
diff --git a/spec/output/generator_spec_java/optional.x/XdrUnsignedInteger.java b/spec/output/generator_spec_java/optional.x/XdrUnsignedInteger.java
index 8f2a52395..a56ad657d 100644
--- a/spec/output/generator_spec_java/optional.x/XdrUnsignedInteger.java
+++ b/spec/output/generator_spec_java/optional.x/XdrUnsignedInteger.java
@@ -1,9 +1,9 @@
-package org.stellar.sdk.xdr;
+package MyXDR;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
-import java.util.Objects;
+import lombok.Value;
import org.stellar.sdk.Base64Factory;
/**
@@ -12,10 +12,11 @@
* @see XDR: External Data
* Representation Standard
*/
+@Value
public class XdrUnsignedInteger implements XdrElement {
public static final long MAX_VALUE = (1L << 32) - 1;
public static final long MIN_VALUE = 0;
- private final Long number;
+ Long number;
public XdrUnsignedInteger(Long number) {
if (number < MIN_VALUE || number > MAX_VALUE) {
@@ -32,10 +33,6 @@ public XdrUnsignedInteger(Integer number) {
this.number = number.longValue();
}
- public Long getNumber() {
- return number;
- }
-
public static XdrUnsignedInteger decode(XdrDataInputStream stream) throws IOException {
int intValue = stream.readInt();
long uint32Value = Integer.toUnsignedLong(intValue);
@@ -70,23 +67,4 @@ public static XdrUnsignedInteger fromXdrByteArray(byte[] xdr) throws IOException
XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream);
return decode(xdrDataInputStream);
}
-
- @Override
- public int hashCode() {
- return Objects.hash(this.number);
- }
-
- @Override
- public boolean equals(Object object) {
- if (!(object instanceof XdrUnsignedInteger)) {
- return false;
- }
-
- XdrUnsignedInteger other = (XdrUnsignedInteger) object;
- return Objects.equals(this.number, other.number);
- }
-
- public String toString() {
- return "XdrUnsignedInteger(number=" + this.getNumber() + ")";
- }
}
diff --git a/spec/output/generator_spec_java/struct.x/Int64.java b/spec/output/generator_spec_java/struct.x/Int64.java
index d5029d25d..1c0f9a595 100644
--- a/spec/output/generator_spec_java/struct.x/Int64.java
+++ b/spec/output/generator_spec_java/struct.x/Int64.java
@@ -5,11 +5,13 @@
import java.io.IOException;
-import static MyXDR.Constants.*;
import org.stellar.sdk.Base64Factory;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
-import java.util.Objects;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+import lombok.AllArgsConstructor;
+import static MyXDR.Constants.*;
/**
* Int64's original definition in the XDR file is:
@@ -17,23 +19,11 @@
* typedef hyper int64;
*
*/
+@Data
+@NoArgsConstructor
+@AllArgsConstructor
public class Int64 implements XdrElement {
private Long int64;
-
- public Int64() {}
-
- public Int64(Long int64) {
- this.int64 = int64;
- }
-
- public Long getInt64() {
- return this.int64;
- }
-
- public void setInt64(Long value) {
- this.int64 = value;
- }
-
public static void encode(XdrDataOutputStream stream, Int64 encodedInt64) throws IOException {
stream.writeLong(encodedInt64.int64);
}
@@ -47,20 +37,6 @@ public static Int64 decode(XdrDataInputStream stream) throws IOException {
return decodedInt64;
}
- @Override
- public int hashCode() {
- return Objects.hash(this.int64);
- }
-
- @Override
- public boolean equals(Object object) {
- if (!(object instanceof Int64)) {
- return false;
- }
-
- Int64 other = (Int64) object;
- return Objects.equals(this.int64, other.int64);
- }
@Override
public String toXdrBase64() throws IOException {
return Base64Factory.getInstance().encodeToString(toXdrByteArray());
diff --git a/spec/output/generator_spec_java/struct.x/MyStruct.java b/spec/output/generator_spec_java/struct.x/MyStruct.java
index 6396b1fe9..11972e22c 100644
--- a/spec/output/generator_spec_java/struct.x/MyStruct.java
+++ b/spec/output/generator_spec_java/struct.x/MyStruct.java
@@ -5,12 +5,14 @@
import java.io.IOException;
-import static MyXDR.Constants.*;
import org.stellar.sdk.Base64Factory;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
-import java.util.Objects;
-import java.util.Arrays;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import static MyXDR.Constants.*;
/**
* MyStruct's original definition in the XDR file is:
@@ -25,48 +27,21 @@
* };
*
*/
+@Data
+@NoArgsConstructor
+@AllArgsConstructor
+@Builder(toBuilder = true)
public class MyStruct implements XdrElement {
- public MyStruct () {}
private Integer someInt;
- public Integer getSomeInt() {
- return this.someInt;
- }
- public void setSomeInt(Integer value) {
- this.someInt = value;
- }
private Int64 aBigInt;
- public Int64 getABigInt() {
- return this.aBigInt;
- }
- public void setABigInt(Int64 value) {
- this.aBigInt = value;
- }
private byte[] someOpaque;
- public byte[] getSomeOpaque() {
- return this.someOpaque;
- }
- public void setSomeOpaque(byte[] value) {
- this.someOpaque = value;
- }
private XdrString someString;
- public XdrString getSomeString() {
- return this.someString;
- }
- public void setSomeString(XdrString value) {
- this.someString = value;
- }
private XdrString maxString;
- public XdrString getMaxString() {
- return this.maxString;
- }
- public void setMaxString(XdrString value) {
- this.maxString = value;
- }
public static void encode(XdrDataOutputStream stream, MyStruct encodedMyStruct) throws IOException{
stream.writeInt(encodedMyStruct.someInt);
Int64.encode(stream, encodedMyStruct.aBigInt);
- int someOpaquesize = encodedMyStruct.someOpaque.length;
- stream.write(encodedMyStruct.getSomeOpaque(), 0, someOpaquesize);
+ int someOpaqueSize = encodedMyStruct.someOpaque.length;
+ stream.write(encodedMyStruct.getSomeOpaque(), 0, someOpaqueSize);
encodedMyStruct.someString.encode(stream);
encodedMyStruct.maxString.encode(stream);
}
@@ -77,27 +52,13 @@ public static MyStruct decode(XdrDataInputStream stream) throws IOException {
MyStruct decodedMyStruct = new MyStruct();
decodedMyStruct.someInt = stream.readInt();
decodedMyStruct.aBigInt = Int64.decode(stream);
- int someOpaquesize = 10;
- decodedMyStruct.someOpaque = new byte[someOpaquesize];
- stream.read(decodedMyStruct.someOpaque, 0, someOpaquesize);
+ int someOpaqueSize = 10;
+ decodedMyStruct.someOpaque = new byte[someOpaqueSize];
+ stream.read(decodedMyStruct.someOpaque, 0, someOpaqueSize);
decodedMyStruct.someString = XdrString.decode(stream, Integer.MAX_VALUE);
decodedMyStruct.maxString = XdrString.decode(stream, 100);
return decodedMyStruct;
}
- @Override
- public int hashCode() {
- return Objects.hash(this.someInt, this.aBigInt, Arrays.hashCode(this.someOpaque), this.someString, this.maxString);
- }
- @Override
- public boolean equals(Object object) {
- if (!(object instanceof MyStruct)) {
- return false;
- }
-
- MyStruct other = (MyStruct) object;
- return Objects.equals(this.someInt, other.someInt) && Objects.equals(this.aBigInt, other.aBigInt) && Arrays.equals(this.someOpaque, other.someOpaque) && Objects.equals(this.someString, other.someString) && Objects.equals(this.maxString, other.maxString);
- }
-
@Override
public String toXdrBase64() throws IOException {
return Base64Factory.getInstance().encodeToString(toXdrByteArray());
@@ -121,46 +82,4 @@ public static MyStruct fromXdrByteArray(byte[] xdr) throws IOException {
XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream);
return decode(xdrDataInputStream);
}
- public static final class Builder {
- private Integer someInt;
- private Int64 aBigInt;
- private byte[] someOpaque;
- private XdrString someString;
- private XdrString maxString;
-
- public Builder someInt(Integer someInt) {
- this.someInt = someInt;
- return this;
- }
-
- public Builder aBigInt(Int64 aBigInt) {
- this.aBigInt = aBigInt;
- return this;
- }
-
- public Builder someOpaque(byte[] someOpaque) {
- this.someOpaque = someOpaque;
- return this;
- }
-
- public Builder someString(XdrString someString) {
- this.someString = someString;
- return this;
- }
-
- public Builder maxString(XdrString maxString) {
- this.maxString = maxString;
- return this;
- }
-
- public MyStruct build() {
- MyStruct val = new MyStruct();
- val.setSomeInt(this.someInt);
- val.setABigInt(this.aBigInt);
- val.setSomeOpaque(this.someOpaque);
- val.setSomeString(this.someString);
- val.setMaxString(this.maxString);
- return val;
- }
- }
}
diff --git a/spec/output/generator_spec_java/struct.x/XdrString.java b/spec/output/generator_spec_java/struct.x/XdrString.java
index bb4e81fb4..2d8f8bbc9 100644
--- a/spec/output/generator_spec_java/struct.x/XdrString.java
+++ b/spec/output/generator_spec_java/struct.x/XdrString.java
@@ -4,90 +4,72 @@
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InvalidClassException;
-import java.nio.charset.Charset;
-import java.util.Arrays;
+import java.nio.charset.StandardCharsets;
+import lombok.Value;
import org.stellar.sdk.Base64Factory;
+@Value
public class XdrString implements XdrElement {
- private byte[] bytes;
+ byte[] bytes;
- public XdrString(byte[] bytes) {
- this.bytes = bytes;
- }
+ public XdrString(byte[] bytes) {
+ this.bytes = bytes;
+ }
- public XdrString(String text) {
- this.bytes = text.getBytes(Charset.forName("UTF-8"));
- }
+ public XdrString(String text) {
+ this.bytes = text.getBytes(StandardCharsets.UTF_8);
+ }
- @Override
- public void encode(XdrDataOutputStream stream) throws IOException {
- stream.writeInt(this.bytes.length);
- stream.write(this.bytes, 0, this.bytes.length);
- }
+ @Override
+ public void encode(XdrDataOutputStream stream) throws IOException {
+ stream.writeInt(this.bytes.length);
+ stream.write(this.bytes, 0, this.bytes.length);
+ }
- public static XdrString decode(XdrDataInputStream stream, int maxSize) throws IOException {
- int size = stream.readInt();
- if (size > maxSize) {
- throw new InvalidClassException("String length "+size+" exceeds max size "+maxSize);
- }
- byte[] bytes = new byte[size];
- stream.read(bytes);
- return new XdrString(bytes);
+ public static XdrString decode(XdrDataInputStream stream, int maxSize) throws IOException {
+ int size = stream.readInt();
+ if (size > maxSize) {
+ throw new InvalidClassException("String length " + size + " exceeds max size " + maxSize);
}
+ byte[] bytes = new byte[size];
+ stream.read(bytes);
+ return new XdrString(bytes);
+ }
- public byte[] getBytes() {
- return this.bytes;
- }
+ @Override
+ public String toXdrBase64() throws IOException {
+ return Base64Factory.getInstance().encodeToString(toXdrByteArray());
+ }
- @Override
- public String toXdrBase64() throws IOException {
- return Base64Factory.getInstance().encodeToString(toXdrByteArray());
- }
-
- @Override
- public byte[] toXdrByteArray() throws IOException {
- ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
- XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream);
- encode(xdrDataOutputStream);
- return byteArrayOutputStream.toByteArray();
- }
-
- public static XdrString fromXdrBase64(String xdr, int maxSize) throws IOException {
- byte[] bytes = Base64Factory.getInstance().decode(xdr);
- return fromXdrByteArray(bytes, maxSize);
- }
-
- public static XdrString fromXdrBase64(String xdr) throws IOException {
- return fromXdrBase64(xdr, Integer.MAX_VALUE);
- }
-
- public static XdrString fromXdrByteArray(byte[] xdr, int maxSize) throws IOException {
- ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr);
- XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream);
- return decode(xdrDataInputStream, maxSize);
- }
-
- public static XdrString fromXdrByteArray(byte[] xdr) throws IOException {
- return fromXdrByteArray(xdr, Integer.MAX_VALUE);
- }
+ @Override
+ public byte[] toXdrByteArray() throws IOException {
+ ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
+ XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream);
+ encode(xdrDataOutputStream);
+ return byteArrayOutputStream.toByteArray();
+ }
- @Override
- public int hashCode() {
- return Arrays.hashCode(this.bytes);
- }
+ public static XdrString fromXdrBase64(String xdr, int maxSize) throws IOException {
+ byte[] bytes = Base64Factory.getInstance().decode(xdr);
+ return fromXdrByteArray(bytes, maxSize);
+ }
- @Override
- public boolean equals(Object object) {
- if (object == null || !(object instanceof XdrString)) {
- return false;
- }
+ public static XdrString fromXdrBase64(String xdr) throws IOException {
+ return fromXdrBase64(xdr, Integer.MAX_VALUE);
+ }
- XdrString other = (XdrString) object;
- return Arrays.equals(this.bytes, other.bytes);
- }
+ public static XdrString fromXdrByteArray(byte[] xdr, int maxSize) throws IOException {
+ ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr);
+ XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream);
+ return decode(xdrDataInputStream, maxSize);
+ }
- @Override
- public String toString() {
- return new String(bytes, Charset.forName("UTF-8"));
- }
+ public static XdrString fromXdrByteArray(byte[] xdr) throws IOException {
+ return fromXdrByteArray(xdr, Integer.MAX_VALUE);
+ }
+
+ @Override
+ public String toString() {
+ return new String(bytes, StandardCharsets.UTF_8);
+ }
}
diff --git a/spec/output/generator_spec_java/struct.x/XdrUnsignedHyperInteger.java b/spec/output/generator_spec_java/struct.x/XdrUnsignedHyperInteger.java
index 6c05ca57d..204aa83de 100644
--- a/spec/output/generator_spec_java/struct.x/XdrUnsignedHyperInteger.java
+++ b/spec/output/generator_spec_java/struct.x/XdrUnsignedHyperInteger.java
@@ -1,10 +1,10 @@
-package org.stellar.sdk.xdr;
+package MyXDR;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.math.BigInteger;
-import java.util.Objects;
+import lombok.Value;
import org.stellar.sdk.Base64Factory;
/**
@@ -13,10 +13,11 @@
* @see XDR: External Data
* Representation Standard
*/
+@Value
public class XdrUnsignedHyperInteger implements XdrElement {
public static final BigInteger MAX_VALUE = new BigInteger("18446744073709551615");
public static final BigInteger MIN_VALUE = BigInteger.ZERO;
- private final BigInteger number;
+ BigInteger number;
public XdrUnsignedHyperInteger(BigInteger number) {
if (number.compareTo(MIN_VALUE) < 0 || number.compareTo(MAX_VALUE) > 0) {
@@ -55,10 +56,6 @@ private byte[] getBytes() {
return paddedBytes;
}
- public BigInteger getNumber() {
- return number;
- }
-
@Override
public String toXdrBase64() throws IOException {
return Base64Factory.getInstance().encodeToString(toXdrByteArray());
@@ -82,23 +79,4 @@ public static XdrUnsignedHyperInteger fromXdrByteArray(byte[] xdr) throws IOExce
XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream);
return decode(xdrDataInputStream);
}
-
- @Override
- public int hashCode() {
- return Objects.hash(this.number);
- }
-
- @Override
- public boolean equals(Object object) {
- if (!(object instanceof XdrUnsignedHyperInteger)) {
- return false;
- }
-
- XdrUnsignedHyperInteger other = (XdrUnsignedHyperInteger) object;
- return Objects.equals(this.number, other.number);
- }
-
- public String toString() {
- return "XdrUnsignedInteger(number=" + this.getNumber() + ")";
- }
}
diff --git a/spec/output/generator_spec_java/struct.x/XdrUnsignedInteger.java b/spec/output/generator_spec_java/struct.x/XdrUnsignedInteger.java
index 8f2a52395..a56ad657d 100644
--- a/spec/output/generator_spec_java/struct.x/XdrUnsignedInteger.java
+++ b/spec/output/generator_spec_java/struct.x/XdrUnsignedInteger.java
@@ -1,9 +1,9 @@
-package org.stellar.sdk.xdr;
+package MyXDR;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
-import java.util.Objects;
+import lombok.Value;
import org.stellar.sdk.Base64Factory;
/**
@@ -12,10 +12,11 @@
* @see XDR: External Data
* Representation Standard
*/
+@Value
public class XdrUnsignedInteger implements XdrElement {
public static final long MAX_VALUE = (1L << 32) - 1;
public static final long MIN_VALUE = 0;
- private final Long number;
+ Long number;
public XdrUnsignedInteger(Long number) {
if (number < MIN_VALUE || number > MAX_VALUE) {
@@ -32,10 +33,6 @@ public XdrUnsignedInteger(Integer number) {
this.number = number.longValue();
}
- public Long getNumber() {
- return number;
- }
-
public static XdrUnsignedInteger decode(XdrDataInputStream stream) throws IOException {
int intValue = stream.readInt();
long uint32Value = Integer.toUnsignedLong(intValue);
@@ -70,23 +67,4 @@ public static XdrUnsignedInteger fromXdrByteArray(byte[] xdr) throws IOException
XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream);
return decode(xdrDataInputStream);
}
-
- @Override
- public int hashCode() {
- return Objects.hash(this.number);
- }
-
- @Override
- public boolean equals(Object object) {
- if (!(object instanceof XdrUnsignedInteger)) {
- return false;
- }
-
- XdrUnsignedInteger other = (XdrUnsignedInteger) object;
- return Objects.equals(this.number, other.number);
- }
-
- public String toString() {
- return "XdrUnsignedInteger(number=" + this.getNumber() + ")";
- }
}
diff --git a/spec/output/generator_spec_java/test.x/Color.java b/spec/output/generator_spec_java/test.x/Color.java
index 8b64c3648..fd00aeaa9 100644
--- a/spec/output/generator_spec_java/test.x/Color.java
+++ b/spec/output/generator_spec_java/test.x/Color.java
@@ -5,7 +5,6 @@
import java.io.IOException;
-import static MyXDR.Constants.*;
import org.stellar.sdk.Base64Factory;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
@@ -23,16 +22,16 @@
public enum Color implements XdrElement {
RED(0),
BLUE(5),
- GREEN(6),
- ;
- private int mValue;
+ GREEN(6);
+
+ private final int value;
Color(int value) {
- mValue = value;
+ this.value = value;
}
public int getValue() {
- return mValue;
+ return value;
}
public static Color decode(XdrDataInputStream stream) throws IOException {
diff --git a/spec/output/generator_spec_java/test.x/HasStuff.java b/spec/output/generator_spec_java/test.x/HasStuff.java
index 3015f1726..33b21798c 100644
--- a/spec/output/generator_spec_java/test.x/HasStuff.java
+++ b/spec/output/generator_spec_java/test.x/HasStuff.java
@@ -5,11 +5,14 @@
import java.io.IOException;
-import static MyXDR.Constants.*;
import org.stellar.sdk.Base64Factory;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
-import java.util.Objects;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import static MyXDR.Constants.*;
/**
* HasStuff's original definition in the XDR file is:
@@ -20,15 +23,12 @@
* };
*
*/
+@Data
+@NoArgsConstructor
+@AllArgsConstructor
+@Builder(toBuilder = true)
public class HasStuff implements XdrElement {
- public HasStuff () {}
private LotsOfMyStructs data;
- public LotsOfMyStructs getData() {
- return this.data;
- }
- public void setData(LotsOfMyStructs value) {
- this.data = value;
- }
public static void encode(XdrDataOutputStream stream, HasStuff encodedHasStuff) throws IOException{
LotsOfMyStructs.encode(stream, encodedHasStuff.data);
}
@@ -40,20 +40,6 @@ public static HasStuff decode(XdrDataInputStream stream) throws IOException {
decodedHasStuff.data = LotsOfMyStructs.decode(stream);
return decodedHasStuff;
}
- @Override
- public int hashCode() {
- return Objects.hash(this.data);
- }
- @Override
- public boolean equals(Object object) {
- if (!(object instanceof HasStuff)) {
- return false;
- }
-
- HasStuff other = (HasStuff) object;
- return Objects.equals(this.data, other.data);
- }
-
@Override
public String toXdrBase64() throws IOException {
return Base64Factory.getInstance().encodeToString(toXdrByteArray());
@@ -77,18 +63,4 @@ public static HasStuff fromXdrByteArray(byte[] xdr) throws IOException {
XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream);
return decode(xdrDataInputStream);
}
- public static final class Builder {
- private LotsOfMyStructs data;
-
- public Builder data(LotsOfMyStructs data) {
- this.data = data;
- return this;
- }
-
- public HasStuff build() {
- HasStuff val = new HasStuff();
- val.setData(this.data);
- return val;
- }
- }
}
diff --git a/spec/output/generator_spec_java/test.x/Hash.java b/spec/output/generator_spec_java/test.x/Hash.java
index e5cd4e551..e7851f9b9 100644
--- a/spec/output/generator_spec_java/test.x/Hash.java
+++ b/spec/output/generator_spec_java/test.x/Hash.java
@@ -5,11 +5,13 @@
import java.io.IOException;
-import static MyXDR.Constants.*;
import org.stellar.sdk.Base64Factory;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
-import java.util.Arrays;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+import lombok.AllArgsConstructor;
+import static MyXDR.Constants.*;
/**
* Hash's original definition in the XDR file is:
@@ -17,26 +19,14 @@
* typedef opaque Hash[32];
*
*/
+@Data
+@NoArgsConstructor
+@AllArgsConstructor
public class Hash implements XdrElement {
private byte[] Hash;
-
- public Hash() {}
-
- public Hash(byte[] Hash) {
- this.Hash = Hash;
- }
-
- public byte[] getHash() {
- return this.Hash;
- }
-
- public void setHash(byte[] value) {
- this.Hash = value;
- }
-
public static void encode(XdrDataOutputStream stream, Hash encodedHash) throws IOException {
- int Hashsize = encodedHash.Hash.length;
- stream.write(encodedHash.getHash(), 0, Hashsize);
+ int HashSize = encodedHash.Hash.length;
+ stream.write(encodedHash.getHash(), 0, HashSize);
}
public void encode(XdrDataOutputStream stream) throws IOException {
@@ -44,26 +34,12 @@ public void encode(XdrDataOutputStream stream) throws IOException {
}
public static Hash decode(XdrDataInputStream stream) throws IOException {
Hash decodedHash = new Hash();
- int Hashsize = 32;
- decodedHash.Hash = new byte[Hashsize];
- stream.read(decodedHash.Hash, 0, Hashsize);
+ int HashSize = 32;
+ decodedHash.Hash = new byte[HashSize];
+ stream.read(decodedHash.Hash, 0, HashSize);
return decodedHash;
}
- @Override
- public int hashCode() {
- return Arrays.hashCode(this.Hash);
- }
-
- @Override
- public boolean equals(Object object) {
- if (!(object instanceof Hash)) {
- return false;
- }
-
- Hash other = (Hash) object;
- return Arrays.equals(this.Hash, other.Hash);
- }
@Override
public String toXdrBase64() throws IOException {
return Base64Factory.getInstance().encodeToString(toXdrByteArray());
diff --git a/spec/output/generator_spec_java/test.x/Hashes1.java b/spec/output/generator_spec_java/test.x/Hashes1.java
index f69adbcba..e40e91a47 100644
--- a/spec/output/generator_spec_java/test.x/Hashes1.java
+++ b/spec/output/generator_spec_java/test.x/Hashes1.java
@@ -5,11 +5,13 @@
import java.io.IOException;
-import static MyXDR.Constants.*;
import org.stellar.sdk.Base64Factory;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
-import java.util.Arrays;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+import lombok.AllArgsConstructor;
+import static MyXDR.Constants.*;
/**
* Hashes1's original definition in the XDR file is:
@@ -17,26 +19,14 @@
* typedef Hash Hashes1[12];
*
*/
+@Data
+@NoArgsConstructor
+@AllArgsConstructor
public class Hashes1 implements XdrElement {
private Hash[] Hashes1;
-
- public Hashes1() {}
-
- public Hashes1(Hash[] Hashes1) {
- this.Hashes1 = Hashes1;
- }
-
- public Hash[] getHashes1() {
- return this.Hashes1;
- }
-
- public void setHashes1(Hash[] value) {
- this.Hashes1 = value;
- }
-
public static void encode(XdrDataOutputStream stream, Hashes1 encodedHashes1) throws IOException {
- int Hashes1size = encodedHashes1.getHashes1().length;
- for (int i = 0; i < Hashes1size; i++) {
+ int Hashes1Size = encodedHashes1.getHashes1().length;
+ for (int i = 0; i < Hashes1Size; i++) {
Hash.encode(stream, encodedHashes1.Hashes1[i]);
}
}
@@ -46,28 +36,14 @@ public void encode(XdrDataOutputStream stream) throws IOException {
}
public static Hashes1 decode(XdrDataInputStream stream) throws IOException {
Hashes1 decodedHashes1 = new Hashes1();
- int Hashes1size = 12;
- decodedHashes1.Hashes1 = new Hash[Hashes1size];
- for (int i = 0; i < Hashes1size; i++) {
+ int Hashes1Size = 12;
+ decodedHashes1.Hashes1 = new Hash[Hashes1Size];
+ for (int i = 0; i < Hashes1Size; i++) {
decodedHashes1.Hashes1[i] = Hash.decode(stream);
}
return decodedHashes1;
}
- @Override
- public int hashCode() {
- return Arrays.hashCode(this.Hashes1);
- }
-
- @Override
- public boolean equals(Object object) {
- if (!(object instanceof Hashes1)) {
- return false;
- }
-
- Hashes1 other = (Hashes1) object;
- return Arrays.equals(this.Hashes1, other.Hashes1);
- }
@Override
public String toXdrBase64() throws IOException {
return Base64Factory.getInstance().encodeToString(toXdrByteArray());
diff --git a/spec/output/generator_spec_java/test.x/Hashes2.java b/spec/output/generator_spec_java/test.x/Hashes2.java
index 11ff7b448..04675d3bd 100644
--- a/spec/output/generator_spec_java/test.x/Hashes2.java
+++ b/spec/output/generator_spec_java/test.x/Hashes2.java
@@ -5,11 +5,13 @@
import java.io.IOException;
-import static MyXDR.Constants.*;
import org.stellar.sdk.Base64Factory;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
-import java.util.Arrays;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+import lombok.AllArgsConstructor;
+import static MyXDR.Constants.*;
/**
* Hashes2's original definition in the XDR file is:
@@ -17,27 +19,15 @@
* typedef Hash Hashes2<12>;
*
*/
+@Data
+@NoArgsConstructor
+@AllArgsConstructor
public class Hashes2 implements XdrElement {
private Hash[] Hashes2;
-
- public Hashes2() {}
-
- public Hashes2(Hash[] Hashes2) {
- this.Hashes2 = Hashes2;
- }
-
- public Hash[] getHashes2() {
- return this.Hashes2;
- }
-
- public void setHashes2(Hash[] value) {
- this.Hashes2 = value;
- }
-
public static void encode(XdrDataOutputStream stream, Hashes2 encodedHashes2) throws IOException {
- int Hashes2size = encodedHashes2.getHashes2().length;
- stream.writeInt(Hashes2size);
- for (int i = 0; i < Hashes2size; i++) {
+ int Hashes2Size = encodedHashes2.getHashes2().length;
+ stream.writeInt(Hashes2Size);
+ for (int i = 0; i < Hashes2Size; i++) {
Hash.encode(stream, encodedHashes2.Hashes2[i]);
}
}
@@ -47,28 +37,14 @@ public void encode(XdrDataOutputStream stream) throws IOException {
}
public static Hashes2 decode(XdrDataInputStream stream) throws IOException {
Hashes2 decodedHashes2 = new Hashes2();
- int Hashes2size = stream.readInt();
- decodedHashes2.Hashes2 = new Hash[Hashes2size];
- for (int i = 0; i < Hashes2size; i++) {
+ int Hashes2Size = stream.readInt();
+ decodedHashes2.Hashes2 = new Hash[Hashes2Size];
+ for (int i = 0; i < Hashes2Size; i++) {
decodedHashes2.Hashes2[i] = Hash.decode(stream);
}
return decodedHashes2;
}
- @Override
- public int hashCode() {
- return Arrays.hashCode(this.Hashes2);
- }
-
- @Override
- public boolean equals(Object object) {
- if (!(object instanceof Hashes2)) {
- return false;
- }
-
- Hashes2 other = (Hashes2) object;
- return Arrays.equals(this.Hashes2, other.Hashes2);
- }
@Override
public String toXdrBase64() throws IOException {
return Base64Factory.getInstance().encodeToString(toXdrByteArray());
diff --git a/spec/output/generator_spec_java/test.x/Hashes3.java b/spec/output/generator_spec_java/test.x/Hashes3.java
index 09fd6afce..7901f81dd 100644
--- a/spec/output/generator_spec_java/test.x/Hashes3.java
+++ b/spec/output/generator_spec_java/test.x/Hashes3.java
@@ -5,11 +5,13 @@
import java.io.IOException;
-import static MyXDR.Constants.*;
import org.stellar.sdk.Base64Factory;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
-import java.util.Arrays;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+import lombok.AllArgsConstructor;
+import static MyXDR.Constants.*;
/**
* Hashes3's original definition in the XDR file is:
@@ -17,27 +19,15 @@
* typedef Hash Hashes3<>;
*
*/
+@Data
+@NoArgsConstructor
+@AllArgsConstructor
public class Hashes3 implements XdrElement {
private Hash[] Hashes3;
-
- public Hashes3() {}
-
- public Hashes3(Hash[] Hashes3) {
- this.Hashes3 = Hashes3;
- }
-
- public Hash[] getHashes3() {
- return this.Hashes3;
- }
-
- public void setHashes3(Hash[] value) {
- this.Hashes3 = value;
- }
-
public static void encode(XdrDataOutputStream stream, Hashes3 encodedHashes3) throws IOException {
- int Hashes3size = encodedHashes3.getHashes3().length;
- stream.writeInt(Hashes3size);
- for (int i = 0; i < Hashes3size; i++) {
+ int Hashes3Size = encodedHashes3.getHashes3().length;
+ stream.writeInt(Hashes3Size);
+ for (int i = 0; i < Hashes3Size; i++) {
Hash.encode(stream, encodedHashes3.Hashes3[i]);
}
}
@@ -47,28 +37,14 @@ public void encode(XdrDataOutputStream stream) throws IOException {
}
public static Hashes3 decode(XdrDataInputStream stream) throws IOException {
Hashes3 decodedHashes3 = new Hashes3();
- int Hashes3size = stream.readInt();
- decodedHashes3.Hashes3 = new Hash[Hashes3size];
- for (int i = 0; i < Hashes3size; i++) {
+ int Hashes3Size = stream.readInt();
+ decodedHashes3.Hashes3 = new Hash[Hashes3Size];
+ for (int i = 0; i < Hashes3Size; i++) {
decodedHashes3.Hashes3[i] = Hash.decode(stream);
}
return decodedHashes3;
}
- @Override
- public int hashCode() {
- return Arrays.hashCode(this.Hashes3);
- }
-
- @Override
- public boolean equals(Object object) {
- if (!(object instanceof Hashes3)) {
- return false;
- }
-
- Hashes3 other = (Hashes3) object;
- return Arrays.equals(this.Hashes3, other.Hashes3);
- }
@Override
public String toXdrBase64() throws IOException {
return Base64Factory.getInstance().encodeToString(toXdrByteArray());
diff --git a/spec/output/generator_spec_java/test.x/Int1.java b/spec/output/generator_spec_java/test.x/Int1.java
index ca647afa9..f1dfad8fa 100644
--- a/spec/output/generator_spec_java/test.x/Int1.java
+++ b/spec/output/generator_spec_java/test.x/Int1.java
@@ -5,11 +5,13 @@
import java.io.IOException;
-import static MyXDR.Constants.*;
import org.stellar.sdk.Base64Factory;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
-import java.util.Objects;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+import lombok.AllArgsConstructor;
+import static MyXDR.Constants.*;
/**
* Int1's original definition in the XDR file is:
@@ -17,23 +19,11 @@
* typedef int int1;
*
*/
+@Data
+@NoArgsConstructor
+@AllArgsConstructor
public class Int1 implements XdrElement {
private Integer int1;
-
- public Int1() {}
-
- public Int1(Integer int1) {
- this.int1 = int1;
- }
-
- public Integer getInt1() {
- return this.int1;
- }
-
- public void setInt1(Integer value) {
- this.int1 = value;
- }
-
public static void encode(XdrDataOutputStream stream, Int1 encodedInt1) throws IOException {
stream.writeInt(encodedInt1.int1);
}
@@ -47,20 +37,6 @@ public static Int1 decode(XdrDataInputStream stream) throws IOException {
return decodedInt1;
}
- @Override
- public int hashCode() {
- return Objects.hash(this.int1);
- }
-
- @Override
- public boolean equals(Object object) {
- if (!(object instanceof Int1)) {
- return false;
- }
-
- Int1 other = (Int1) object;
- return Objects.equals(this.int1, other.int1);
- }
@Override
public String toXdrBase64() throws IOException {
return Base64Factory.getInstance().encodeToString(toXdrByteArray());
diff --git a/spec/output/generator_spec_java/test.x/Int2.java b/spec/output/generator_spec_java/test.x/Int2.java
index f7cf4e5b5..bcfc76480 100644
--- a/spec/output/generator_spec_java/test.x/Int2.java
+++ b/spec/output/generator_spec_java/test.x/Int2.java
@@ -5,11 +5,13 @@
import java.io.IOException;
-import static MyXDR.Constants.*;
import org.stellar.sdk.Base64Factory;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
-import java.util.Objects;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+import lombok.AllArgsConstructor;
+import static MyXDR.Constants.*;
/**
* Int2's original definition in the XDR file is:
@@ -17,23 +19,11 @@
* typedef hyper int2;
*
*/
+@Data
+@NoArgsConstructor
+@AllArgsConstructor
public class Int2 implements XdrElement {
private Long int2;
-
- public Int2() {}
-
- public Int2(Long int2) {
- this.int2 = int2;
- }
-
- public Long getInt2() {
- return this.int2;
- }
-
- public void setInt2(Long value) {
- this.int2 = value;
- }
-
public static void encode(XdrDataOutputStream stream, Int2 encodedInt2) throws IOException {
stream.writeLong(encodedInt2.int2);
}
@@ -47,20 +37,6 @@ public static Int2 decode(XdrDataInputStream stream) throws IOException {
return decodedInt2;
}
- @Override
- public int hashCode() {
- return Objects.hash(this.int2);
- }
-
- @Override
- public boolean equals(Object object) {
- if (!(object instanceof Int2)) {
- return false;
- }
-
- Int2 other = (Int2) object;
- return Objects.equals(this.int2, other.int2);
- }
@Override
public String toXdrBase64() throws IOException {
return Base64Factory.getInstance().encodeToString(toXdrByteArray());
diff --git a/spec/output/generator_spec_java/test.x/Int3.java b/spec/output/generator_spec_java/test.x/Int3.java
index ac255140c..79434be85 100644
--- a/spec/output/generator_spec_java/test.x/Int3.java
+++ b/spec/output/generator_spec_java/test.x/Int3.java
@@ -5,11 +5,13 @@
import java.io.IOException;
-import static MyXDR.Constants.*;
import org.stellar.sdk.Base64Factory;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
-import java.util.Objects;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+import lombok.AllArgsConstructor;
+import static MyXDR.Constants.*;
/**
* Int3's original definition in the XDR file is:
@@ -17,23 +19,11 @@
* typedef unsigned int int3;
*
*/
+@Data
+@NoArgsConstructor
+@AllArgsConstructor
public class Int3 implements XdrElement {
private XdrUnsignedInteger int3;
-
- public Int3() {}
-
- public Int3(XdrUnsignedInteger int3) {
- this.int3 = int3;
- }
-
- public XdrUnsignedInteger getInt3() {
- return this.int3;
- }
-
- public void setInt3(XdrUnsignedInteger value) {
- this.int3 = value;
- }
-
public static void encode(XdrDataOutputStream stream, Int3 encodedInt3) throws IOException {
encodedInt3.int3.encode(stream);
}
@@ -47,20 +37,6 @@ public static Int3 decode(XdrDataInputStream stream) throws IOException {
return decodedInt3;
}
- @Override
- public int hashCode() {
- return Objects.hash(this.int3);
- }
-
- @Override
- public boolean equals(Object object) {
- if (!(object instanceof Int3)) {
- return false;
- }
-
- Int3 other = (Int3) object;
- return Objects.equals(this.int3, other.int3);
- }
@Override
public String toXdrBase64() throws IOException {
return Base64Factory.getInstance().encodeToString(toXdrByteArray());
diff --git a/spec/output/generator_spec_java/test.x/Int4.java b/spec/output/generator_spec_java/test.x/Int4.java
index a3df9c1c9..023e58021 100644
--- a/spec/output/generator_spec_java/test.x/Int4.java
+++ b/spec/output/generator_spec_java/test.x/Int4.java
@@ -5,11 +5,13 @@
import java.io.IOException;
-import static MyXDR.Constants.*;
import org.stellar.sdk.Base64Factory;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
-import java.util.Objects;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+import lombok.AllArgsConstructor;
+import static MyXDR.Constants.*;
/**
* Int4's original definition in the XDR file is:
@@ -17,23 +19,11 @@
* typedef unsigned hyper int4;
*
*/
+@Data
+@NoArgsConstructor
+@AllArgsConstructor
public class Int4 implements XdrElement {
private XdrUnsignedHyperInteger int4;
-
- public Int4() {}
-
- public Int4(XdrUnsignedHyperInteger int4) {
- this.int4 = int4;
- }
-
- public XdrUnsignedHyperInteger getInt4() {
- return this.int4;
- }
-
- public void setInt4(XdrUnsignedHyperInteger value) {
- this.int4 = value;
- }
-
public static void encode(XdrDataOutputStream stream, Int4 encodedInt4) throws IOException {
encodedInt4.int4.encode(stream);
}
@@ -47,20 +37,6 @@ public static Int4 decode(XdrDataInputStream stream) throws IOException {
return decodedInt4;
}
- @Override
- public int hashCode() {
- return Objects.hash(this.int4);
- }
-
- @Override
- public boolean equals(Object object) {
- if (!(object instanceof Int4)) {
- return false;
- }
-
- Int4 other = (Int4) object;
- return Objects.equals(this.int4, other.int4);
- }
@Override
public String toXdrBase64() throws IOException {
return Base64Factory.getInstance().encodeToString(toXdrByteArray());
diff --git a/spec/output/generator_spec_java/test.x/LotsOfMyStructs.java b/spec/output/generator_spec_java/test.x/LotsOfMyStructs.java
index 71ac2c54c..5e24fd883 100644
--- a/spec/output/generator_spec_java/test.x/LotsOfMyStructs.java
+++ b/spec/output/generator_spec_java/test.x/LotsOfMyStructs.java
@@ -5,11 +5,14 @@
import java.io.IOException;
-import static MyXDR.Constants.*;
import org.stellar.sdk.Base64Factory;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
-import java.util.Arrays;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import static MyXDR.Constants.*;
/**
* LotsOfMyStructs's original definition in the XDR file is:
@@ -20,19 +23,16 @@
* };
*
*/
+@Data
+@NoArgsConstructor
+@AllArgsConstructor
+@Builder(toBuilder = true)
public class LotsOfMyStructs implements XdrElement {
- public LotsOfMyStructs () {}
private MyStruct[] members;
- public MyStruct[] getMembers() {
- return this.members;
- }
- public void setMembers(MyStruct[] value) {
- this.members = value;
- }
public static void encode(XdrDataOutputStream stream, LotsOfMyStructs encodedLotsOfMyStructs) throws IOException{
- int memberssize = encodedLotsOfMyStructs.getMembers().length;
- stream.writeInt(memberssize);
- for (int i = 0; i < memberssize; i++) {
+ int membersSize = encodedLotsOfMyStructs.getMembers().length;
+ stream.writeInt(membersSize);
+ for (int i = 0; i < membersSize; i++) {
MyStruct.encode(stream, encodedLotsOfMyStructs.members[i]);
}
}
@@ -41,27 +41,13 @@ public void encode(XdrDataOutputStream stream) throws IOException {
}
public static LotsOfMyStructs decode(XdrDataInputStream stream) throws IOException {
LotsOfMyStructs decodedLotsOfMyStructs = new LotsOfMyStructs();
- int memberssize = stream.readInt();
- decodedLotsOfMyStructs.members = new MyStruct[memberssize];
- for (int i = 0; i < memberssize; i++) {
+ int membersSize = stream.readInt();
+ decodedLotsOfMyStructs.members = new MyStruct[membersSize];
+ for (int i = 0; i < membersSize; i++) {
decodedLotsOfMyStructs.members[i] = MyStruct.decode(stream);
}
return decodedLotsOfMyStructs;
}
- @Override
- public int hashCode() {
- return Arrays.hashCode(this.members);
- }
- @Override
- public boolean equals(Object object) {
- if (!(object instanceof LotsOfMyStructs)) {
- return false;
- }
-
- LotsOfMyStructs other = (LotsOfMyStructs) object;
- return Arrays.equals(this.members, other.members);
- }
-
@Override
public String toXdrBase64() throws IOException {
return Base64Factory.getInstance().encodeToString(toXdrByteArray());
@@ -85,18 +71,4 @@ public static LotsOfMyStructs fromXdrByteArray(byte[] xdr) throws IOException {
XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream);
return decode(xdrDataInputStream);
}
- public static final class Builder {
- private MyStruct[] members;
-
- public Builder members(MyStruct[] members) {
- this.members = members;
- return this;
- }
-
- public LotsOfMyStructs build() {
- LotsOfMyStructs val = new LotsOfMyStructs();
- val.setMembers(this.members);
- return val;
- }
- }
}
diff --git a/spec/output/generator_spec_java/test.x/MyStruct.java b/spec/output/generator_spec_java/test.x/MyStruct.java
index 09015e925..385e713a9 100644
--- a/spec/output/generator_spec_java/test.x/MyStruct.java
+++ b/spec/output/generator_spec_java/test.x/MyStruct.java
@@ -5,11 +5,14 @@
import java.io.IOException;
-import static MyXDR.Constants.*;
import org.stellar.sdk.Base64Factory;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
-import java.util.Objects;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import static MyXDR.Constants.*;
/**
* MyStruct's original definition in the XDR file is:
@@ -26,57 +29,18 @@
* };
*
*/
+@Data
+@NoArgsConstructor
+@AllArgsConstructor
+@Builder(toBuilder = true)
public class MyStruct implements XdrElement {
- public MyStruct () {}
private Uint512 field1;
- public Uint512 getField1() {
- return this.field1;
- }
- public void setField1(Uint512 value) {
- this.field1 = value;
- }
private OptHash1 field2;
- public OptHash1 getField2() {
- return this.field2;
- }
- public void setField2(OptHash1 value) {
- this.field2 = value;
- }
private Int1 field3;
- public Int1 getField3() {
- return this.field3;
- }
- public void setField3(Int1 value) {
- this.field3 = value;
- }
private XdrUnsignedInteger field4;
- public XdrUnsignedInteger getField4() {
- return this.field4;
- }
- public void setField4(XdrUnsignedInteger value) {
- this.field4 = value;
- }
private Float field5;
- public Float getField5() {
- return this.field5;
- }
- public void setField5(Float value) {
- this.field5 = value;
- }
private Double field6;
- public Double getField6() {
- return this.field6;
- }
- public void setField6(Double value) {
- this.field6 = value;
- }
private Boolean field7;
- public Boolean getField7() {
- return this.field7;
- }
- public void setField7(Boolean value) {
- this.field7 = value;
- }
public static void encode(XdrDataOutputStream stream, MyStruct encodedMyStruct) throws IOException{
Uint512.encode(stream, encodedMyStruct.field1);
OptHash1.encode(stream, encodedMyStruct.field2);
@@ -100,20 +64,6 @@ public static MyStruct decode(XdrDataInputStream stream) throws IOException {
decodedMyStruct.field7 = stream.readInt() == 1 ? true : false;
return decodedMyStruct;
}
- @Override
- public int hashCode() {
- return Objects.hash(this.field1, this.field2, this.field3, this.field4, this.field5, this.field6, this.field7);
- }
- @Override
- public boolean equals(Object object) {
- if (!(object instanceof MyStruct)) {
- return false;
- }
-
- MyStruct other = (MyStruct) object;
- return Objects.equals(this.field1, other.field1) && Objects.equals(this.field2, other.field2) && Objects.equals(this.field3, other.field3) && Objects.equals(this.field4, other.field4) && Objects.equals(this.field5, other.field5) && Objects.equals(this.field6, other.field6) && Objects.equals(this.field7, other.field7);
- }
-
@Override
public String toXdrBase64() throws IOException {
return Base64Factory.getInstance().encodeToString(toXdrByteArray());
@@ -137,60 +87,4 @@ public static MyStruct fromXdrByteArray(byte[] xdr) throws IOException {
XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream);
return decode(xdrDataInputStream);
}
- public static final class Builder {
- private Uint512 field1;
- private OptHash1 field2;
- private Int1 field3;
- private XdrUnsignedInteger field4;
- private Float field5;
- private Double field6;
- private Boolean field7;
-
- public Builder field1(Uint512 field1) {
- this.field1 = field1;
- return this;
- }
-
- public Builder field2(OptHash1 field2) {
- this.field2 = field2;
- return this;
- }
-
- public Builder field3(Int1 field3) {
- this.field3 = field3;
- return this;
- }
-
- public Builder field4(XdrUnsignedInteger field4) {
- this.field4 = field4;
- return this;
- }
-
- public Builder field5(Float field5) {
- this.field5 = field5;
- return this;
- }
-
- public Builder field6(Double field6) {
- this.field6 = field6;
- return this;
- }
-
- public Builder field7(Boolean field7) {
- this.field7 = field7;
- return this;
- }
-
- public MyStruct build() {
- MyStruct val = new MyStruct();
- val.setField1(this.field1);
- val.setField2(this.field2);
- val.setField3(this.field3);
- val.setField4(this.field4);
- val.setField5(this.field5);
- val.setField6(this.field6);
- val.setField7(this.field7);
- return val;
- }
- }
}
diff --git a/spec/output/generator_spec_java/test.x/Nester.java b/spec/output/generator_spec_java/test.x/Nester.java
index 6867dbf2e..876704528 100644
--- a/spec/output/generator_spec_java/test.x/Nester.java
+++ b/spec/output/generator_spec_java/test.x/Nester.java
@@ -5,11 +5,14 @@
import java.io.IOException;
-import static MyXDR.Constants.*;
import org.stellar.sdk.Base64Factory;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
-import java.util.Objects;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import static MyXDR.Constants.*;
/**
* Nester's original definition in the XDR file is:
@@ -36,29 +39,14 @@
* };
*
*/
+@Data
+@NoArgsConstructor
+@AllArgsConstructor
+@Builder(toBuilder = true)
public class Nester implements XdrElement {
- public Nester () {}
private NesterNestedEnum nestedEnum;
- public NesterNestedEnum getNestedEnum() {
- return this.nestedEnum;
- }
- public void setNestedEnum(NesterNestedEnum value) {
- this.nestedEnum = value;
- }
private NesterNestedStruct nestedStruct;
- public NesterNestedStruct getNestedStruct() {
- return this.nestedStruct;
- }
- public void setNestedStruct(NesterNestedStruct value) {
- this.nestedStruct = value;
- }
private NesterNestedUnion nestedUnion;
- public NesterNestedUnion getNestedUnion() {
- return this.nestedUnion;
- }
- public void setNestedUnion(NesterNestedUnion value) {
- this.nestedUnion = value;
- }
public static void encode(XdrDataOutputStream stream, Nester encodedNester) throws IOException{
NesterNestedEnum.encode(stream, encodedNester.nestedEnum);
NesterNestedStruct.encode(stream, encodedNester.nestedStruct);
@@ -74,20 +62,6 @@ public static Nester decode(XdrDataInputStream stream) throws IOException {
decodedNester.nestedUnion = NesterNestedUnion.decode(stream);
return decodedNester;
}
- @Override
- public int hashCode() {
- return Objects.hash(this.nestedEnum, this.nestedStruct, this.nestedUnion);
- }
- @Override
- public boolean equals(Object object) {
- if (!(object instanceof Nester)) {
- return false;
- }
-
- Nester other = (Nester) object;
- return Objects.equals(this.nestedEnum, other.nestedEnum) && Objects.equals(this.nestedStruct, other.nestedStruct) && Objects.equals(this.nestedUnion, other.nestedUnion);
- }
-
@Override
public String toXdrBase64() throws IOException {
return Base64Factory.getInstance().encodeToString(toXdrByteArray());
@@ -111,34 +85,6 @@ public static Nester fromXdrByteArray(byte[] xdr) throws IOException {
XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream);
return decode(xdrDataInputStream);
}
- public static final class Builder {
- private NesterNestedEnum nestedEnum;
- private NesterNestedStruct nestedStruct;
- private NesterNestedUnion nestedUnion;
-
- public Builder nestedEnum(NesterNestedEnum nestedEnum) {
- this.nestedEnum = nestedEnum;
- return this;
- }
-
- public Builder nestedStruct(NesterNestedStruct nestedStruct) {
- this.nestedStruct = nestedStruct;
- return this;
- }
-
- public Builder nestedUnion(NesterNestedUnion nestedUnion) {
- this.nestedUnion = nestedUnion;
- return this;
- }
-
- public Nester build() {
- Nester val = new Nester();
- val.setNestedEnum(this.nestedEnum);
- val.setNestedStruct(this.nestedStruct);
- val.setNestedUnion(this.nestedUnion);
- return val;
- }
- }
/**
* NesterNestedEnum's original definition in the XDR file is:
@@ -151,16 +97,16 @@ public Nester build() {
*/
public static enum NesterNestedEnum implements XdrElement {
BLAH_1(0),
- BLAH_2(1),
- ;
- private int mValue;
+ BLAH_2(1);
+
+ private final int value;
NestedEnum(int value) {
- mValue = value;
+ this.value = value;
}
public int getValue() {
- return mValue;
+ return value;
}
public static NestedEnum decode(XdrDataInputStream stream) throws IOException {
@@ -213,15 +159,12 @@ public static NestedEnum fromXdrByteArray(byte[] xdr) throws IOException {
* }
*
*/
+ @Data
+ @NoArgsConstructor
+ @AllArgsConstructor
+ @Builder(toBuilder = true)
public static class NesterNestedStruct implements XdrElement {
- public NesterNestedStruct () {}
private Integer blah;
- public Integer getBlah() {
- return this.blah;
- }
- public void setBlah(Integer value) {
- this.blah = value;
- }
public static void encode(XdrDataOutputStream stream, NesterNestedStruct encodedNesterNestedStruct) throws IOException{
stream.writeInt(encodedNesterNestedStruct.blah);
}
@@ -233,20 +176,6 @@ public static NesterNestedStruct decode(XdrDataInputStream stream) throws IOExce
decodedNesterNestedStruct.blah = stream.readInt();
return decodedNesterNestedStruct;
}
- @Override
- public int hashCode() {
- return Objects.hash(this.blah);
- }
- @Override
- public boolean equals(Object object) {
- if (!(object instanceof NesterNestedStruct)) {
- return false;
- }
-
- NesterNestedStruct other = (NesterNestedStruct) object;
- return Objects.equals(this.blah, other.blah);
- }
-
@Override
public String toXdrBase64() throws IOException {
return Base64Factory.getInstance().encodeToString(toXdrByteArray());
@@ -270,20 +199,6 @@ public static NesterNestedStruct fromXdrByteArray(byte[] xdr) throws IOException
XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream);
return decode(xdrDataInputStream);
}
- public static final class Builder {
- private Integer blah;
-
- public Builder blah(Integer blah) {
- this.blah = blah;
- return this;
- }
-
- public NesterNestedStruct build() {
- NesterNestedStruct val = new NesterNestedStruct();
- val.setBlah(this.blah);
- return val;
- }
- }
}
/**
@@ -297,44 +212,13 @@ public NesterNestedStruct build() {
* }
*
*/
+ @Data
+ @NoArgsConstructor
+ @AllArgsConstructor
+ @Builder(toBuilder = true)
public static class NesterNestedUnion implements XdrElement {
- public NesterNestedUnion () {}
- Color color;
- public Color getDiscriminant() {
- return this.color;
- }
- public void setDiscriminant(Color value) {
- this.color = value;
- }
+ private Color discriminant;
private Integer blah2;
- public Integer getBlah2() {
- return this.blah2;
- }
- public void setBlah2(Integer value) {
- this.blah2 = value;
- }
-
- public static final class Builder {
- private Color discriminant;
- private Integer blah2;
-
- public Builder discriminant(Color discriminant) {
- this.discriminant = discriminant;
- return this;
- }
-
- public Builder blah2(Integer blah2) {
- this.blah2 = blah2;
- return this;
- }
-
- public NesterNestedUnion build() {
- NesterNestedUnion val = new NesterNestedUnion();
- val.setDiscriminant(discriminant);
- val.setBlah2(this.blah2);
- return val;
- }
- }
public static void encode(XdrDataOutputStream stream, NesterNestedUnion encodedNesterNestedUnion) throws IOException {
//Xdrgen::AST::Identifier
@@ -365,19 +249,6 @@ public static NesterNestedUnion decode(XdrDataInputStream stream) throws IOExcep
return decodedNesterNestedUnion;
}
@Override
- public int hashCode() {
- return Objects.hash(this.blah2, this.color);
- }
- @Override
- public boolean equals(Object object) {
- if (!(object instanceof NesterNestedUnion)) {
- return false;
- }
-
- NesterNestedUnion other = (NesterNestedUnion) object;
- return Objects.equals(this.blah2, other.blah2) && Objects.equals(this.color, other.color);
- }
- @Override
public String toXdrBase64() throws IOException {
return Base64Factory.getInstance().encodeToString(toXdrByteArray());
}
diff --git a/spec/output/generator_spec_java/test.x/OptHash1.java b/spec/output/generator_spec_java/test.x/OptHash1.java
index fd8cb2bf8..57eec6dee 100644
--- a/spec/output/generator_spec_java/test.x/OptHash1.java
+++ b/spec/output/generator_spec_java/test.x/OptHash1.java
@@ -5,11 +5,13 @@
import java.io.IOException;
-import static MyXDR.Constants.*;
import org.stellar.sdk.Base64Factory;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
-import java.util.Objects;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+import lombok.AllArgsConstructor;
+import static MyXDR.Constants.*;
/**
* OptHash1's original definition in the XDR file is:
@@ -17,23 +19,11 @@
* typedef Hash *optHash1;
*
*/
+@Data
+@NoArgsConstructor
+@AllArgsConstructor
public class OptHash1 implements XdrElement {
private Hash optHash1;
-
- public OptHash1() {}
-
- public OptHash1(Hash optHash1) {
- this.optHash1 = optHash1;
- }
-
- public Hash getOptHash1() {
- return this.optHash1;
- }
-
- public void setOptHash1(Hash value) {
- this.optHash1 = value;
- }
-
public static void encode(XdrDataOutputStream stream, OptHash1 encodedOptHash1) throws IOException {
if (encodedOptHash1.optHash1 != null) {
stream.writeInt(1);
@@ -55,20 +45,6 @@ public static OptHash1 decode(XdrDataInputStream stream) throws IOException {
return decodedOptHash1;
}
- @Override
- public int hashCode() {
- return Objects.hash(this.optHash1);
- }
-
- @Override
- public boolean equals(Object object) {
- if (!(object instanceof OptHash1)) {
- return false;
- }
-
- OptHash1 other = (OptHash1) object;
- return Objects.equals(this.optHash1, other.optHash1);
- }
@Override
public String toXdrBase64() throws IOException {
return Base64Factory.getInstance().encodeToString(toXdrByteArray());
diff --git a/spec/output/generator_spec_java/test.x/OptHash2.java b/spec/output/generator_spec_java/test.x/OptHash2.java
index 0cacea821..0f853d807 100644
--- a/spec/output/generator_spec_java/test.x/OptHash2.java
+++ b/spec/output/generator_spec_java/test.x/OptHash2.java
@@ -5,11 +5,13 @@
import java.io.IOException;
-import static MyXDR.Constants.*;
import org.stellar.sdk.Base64Factory;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
-import java.util.Objects;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+import lombok.AllArgsConstructor;
+import static MyXDR.Constants.*;
/**
* OptHash2's original definition in the XDR file is:
@@ -17,23 +19,11 @@
* typedef Hash* optHash2;
*
*/
+@Data
+@NoArgsConstructor
+@AllArgsConstructor
public class OptHash2 implements XdrElement {
private Hash optHash2;
-
- public OptHash2() {}
-
- public OptHash2(Hash optHash2) {
- this.optHash2 = optHash2;
- }
-
- public Hash getOptHash2() {
- return this.optHash2;
- }
-
- public void setOptHash2(Hash value) {
- this.optHash2 = value;
- }
-
public static void encode(XdrDataOutputStream stream, OptHash2 encodedOptHash2) throws IOException {
if (encodedOptHash2.optHash2 != null) {
stream.writeInt(1);
@@ -55,20 +45,6 @@ public static OptHash2 decode(XdrDataInputStream stream) throws IOException {
return decodedOptHash2;
}
- @Override
- public int hashCode() {
- return Objects.hash(this.optHash2);
- }
-
- @Override
- public boolean equals(Object object) {
- if (!(object instanceof OptHash2)) {
- return false;
- }
-
- OptHash2 other = (OptHash2) object;
- return Objects.equals(this.optHash2, other.optHash2);
- }
@Override
public String toXdrBase64() throws IOException {
return Base64Factory.getInstance().encodeToString(toXdrByteArray());
diff --git a/spec/output/generator_spec_java/test.x/Str.java b/spec/output/generator_spec_java/test.x/Str.java
index b0ab22de2..9bd9154e5 100644
--- a/spec/output/generator_spec_java/test.x/Str.java
+++ b/spec/output/generator_spec_java/test.x/Str.java
@@ -5,11 +5,13 @@
import java.io.IOException;
-import static MyXDR.Constants.*;
import org.stellar.sdk.Base64Factory;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
-import java.util.Objects;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+import lombok.AllArgsConstructor;
+import static MyXDR.Constants.*;
/**
* Str's original definition in the XDR file is:
@@ -17,23 +19,11 @@
* typedef string str<64>;
*
*/
+@Data
+@NoArgsConstructor
+@AllArgsConstructor
public class Str implements XdrElement {
private XdrString str;
-
- public Str() {}
-
- public Str(XdrString str) {
- this.str = str;
- }
-
- public XdrString getStr() {
- return this.str;
- }
-
- public void setStr(XdrString value) {
- this.str = value;
- }
-
public static void encode(XdrDataOutputStream stream, Str encodedStr) throws IOException {
encodedStr.str.encode(stream);
}
@@ -47,20 +37,6 @@ public static Str decode(XdrDataInputStream stream) throws IOException {
return decodedStr;
}
- @Override
- public int hashCode() {
- return Objects.hash(this.str);
- }
-
- @Override
- public boolean equals(Object object) {
- if (!(object instanceof Str)) {
- return false;
- }
-
- Str other = (Str) object;
- return Objects.equals(this.str, other.str);
- }
@Override
public String toXdrBase64() throws IOException {
return Base64Factory.getInstance().encodeToString(toXdrByteArray());
diff --git a/spec/output/generator_spec_java/test.x/Str2.java b/spec/output/generator_spec_java/test.x/Str2.java
index 7e820409f..766a54a12 100644
--- a/spec/output/generator_spec_java/test.x/Str2.java
+++ b/spec/output/generator_spec_java/test.x/Str2.java
@@ -5,11 +5,13 @@
import java.io.IOException;
-import static MyXDR.Constants.*;
import org.stellar.sdk.Base64Factory;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
-import java.util.Objects;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+import lombok.AllArgsConstructor;
+import static MyXDR.Constants.*;
/**
* Str2's original definition in the XDR file is:
@@ -17,23 +19,11 @@
* typedef string str2<>;
*
*/
+@Data
+@NoArgsConstructor
+@AllArgsConstructor
public class Str2 implements XdrElement {
private XdrString str2;
-
- public Str2() {}
-
- public Str2(XdrString str2) {
- this.str2 = str2;
- }
-
- public XdrString getStr2() {
- return this.str2;
- }
-
- public void setStr2(XdrString value) {
- this.str2 = value;
- }
-
public static void encode(XdrDataOutputStream stream, Str2 encodedStr2) throws IOException {
encodedStr2.str2.encode(stream);
}
@@ -47,20 +37,6 @@ public static Str2 decode(XdrDataInputStream stream) throws IOException {
return decodedStr2;
}
- @Override
- public int hashCode() {
- return Objects.hash(this.str2);
- }
-
- @Override
- public boolean equals(Object object) {
- if (!(object instanceof Str2)) {
- return false;
- }
-
- Str2 other = (Str2) object;
- return Objects.equals(this.str2, other.str2);
- }
@Override
public String toXdrBase64() throws IOException {
return Base64Factory.getInstance().encodeToString(toXdrByteArray());
diff --git a/spec/output/generator_spec_java/test.x/Uint512.java b/spec/output/generator_spec_java/test.x/Uint512.java
index f8819f2ab..568e60a95 100644
--- a/spec/output/generator_spec_java/test.x/Uint512.java
+++ b/spec/output/generator_spec_java/test.x/Uint512.java
@@ -5,11 +5,13 @@
import java.io.IOException;
-import static MyXDR.Constants.*;
import org.stellar.sdk.Base64Factory;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
-import java.util.Arrays;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+import lombok.AllArgsConstructor;
+import static MyXDR.Constants.*;
/**
* Uint512's original definition in the XDR file is:
@@ -17,26 +19,14 @@
* typedef opaque uint512[64];
*
*/
+@Data
+@NoArgsConstructor
+@AllArgsConstructor
public class Uint512 implements XdrElement {
private byte[] uint512;
-
- public Uint512() {}
-
- public Uint512(byte[] uint512) {
- this.uint512 = uint512;
- }
-
- public byte[] getUint512() {
- return this.uint512;
- }
-
- public void setUint512(byte[] value) {
- this.uint512 = value;
- }
-
public static void encode(XdrDataOutputStream stream, Uint512 encodedUint512) throws IOException {
- int uint512size = encodedUint512.uint512.length;
- stream.write(encodedUint512.getUint512(), 0, uint512size);
+ int uint512Size = encodedUint512.uint512.length;
+ stream.write(encodedUint512.getUint512(), 0, uint512Size);
}
public void encode(XdrDataOutputStream stream) throws IOException {
@@ -44,26 +34,12 @@ public void encode(XdrDataOutputStream stream) throws IOException {
}
public static Uint512 decode(XdrDataInputStream stream) throws IOException {
Uint512 decodedUint512 = new Uint512();
- int uint512size = 64;
- decodedUint512.uint512 = new byte[uint512size];
- stream.read(decodedUint512.uint512, 0, uint512size);
+ int uint512Size = 64;
+ decodedUint512.uint512 = new byte[uint512Size];
+ stream.read(decodedUint512.uint512, 0, uint512Size);
return decodedUint512;
}
- @Override
- public int hashCode() {
- return Arrays.hashCode(this.uint512);
- }
-
- @Override
- public boolean equals(Object object) {
- if (!(object instanceof Uint512)) {
- return false;
- }
-
- Uint512 other = (Uint512) object;
- return Arrays.equals(this.uint512, other.uint512);
- }
@Override
public String toXdrBase64() throws IOException {
return Base64Factory.getInstance().encodeToString(toXdrByteArray());
diff --git a/spec/output/generator_spec_java/test.x/Uint513.java b/spec/output/generator_spec_java/test.x/Uint513.java
index 6c2df51b7..7f9c35e2c 100644
--- a/spec/output/generator_spec_java/test.x/Uint513.java
+++ b/spec/output/generator_spec_java/test.x/Uint513.java
@@ -5,11 +5,13 @@
import java.io.IOException;
-import static MyXDR.Constants.*;
import org.stellar.sdk.Base64Factory;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
-import java.util.Arrays;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+import lombok.AllArgsConstructor;
+import static MyXDR.Constants.*;
/**
* Uint513's original definition in the XDR file is:
@@ -17,27 +19,15 @@
* typedef opaque uint513<64>;
*
*/
+@Data
+@NoArgsConstructor
+@AllArgsConstructor
public class Uint513 implements XdrElement {
private byte[] uint513;
-
- public Uint513() {}
-
- public Uint513(byte[] uint513) {
- this.uint513 = uint513;
- }
-
- public byte[] getUint513() {
- return this.uint513;
- }
-
- public void setUint513(byte[] value) {
- this.uint513 = value;
- }
-
public static void encode(XdrDataOutputStream stream, Uint513 encodedUint513) throws IOException {
- int uint513size = encodedUint513.uint513.length;
- stream.writeInt(uint513size);
- stream.write(encodedUint513.getUint513(), 0, uint513size);
+ int uint513Size = encodedUint513.uint513.length;
+ stream.writeInt(uint513Size);
+ stream.write(encodedUint513.getUint513(), 0, uint513Size);
}
public void encode(XdrDataOutputStream stream) throws IOException {
@@ -45,26 +35,12 @@ public void encode(XdrDataOutputStream stream) throws IOException {
}
public static Uint513 decode(XdrDataInputStream stream) throws IOException {
Uint513 decodedUint513 = new Uint513();
- int uint513size = stream.readInt();
- decodedUint513.uint513 = new byte[uint513size];
- stream.read(decodedUint513.uint513, 0, uint513size);
+ int uint513Size = stream.readInt();
+ decodedUint513.uint513 = new byte[uint513Size];
+ stream.read(decodedUint513.uint513, 0, uint513Size);
return decodedUint513;
}
- @Override
- public int hashCode() {
- return Arrays.hashCode(this.uint513);
- }
-
- @Override
- public boolean equals(Object object) {
- if (!(object instanceof Uint513)) {
- return false;
- }
-
- Uint513 other = (Uint513) object;
- return Arrays.equals(this.uint513, other.uint513);
- }
@Override
public String toXdrBase64() throws IOException {
return Base64Factory.getInstance().encodeToString(toXdrByteArray());
diff --git a/spec/output/generator_spec_java/test.x/Uint514.java b/spec/output/generator_spec_java/test.x/Uint514.java
index e1ad5a6fe..18a2ca997 100644
--- a/spec/output/generator_spec_java/test.x/Uint514.java
+++ b/spec/output/generator_spec_java/test.x/Uint514.java
@@ -5,11 +5,13 @@
import java.io.IOException;
-import static MyXDR.Constants.*;
import org.stellar.sdk.Base64Factory;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
-import java.util.Arrays;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+import lombok.AllArgsConstructor;
+import static MyXDR.Constants.*;
/**
* Uint514's original definition in the XDR file is:
@@ -17,27 +19,15 @@
* typedef opaque uint514<>;
*
*/
+@Data
+@NoArgsConstructor
+@AllArgsConstructor
public class Uint514 implements XdrElement {
private byte[] uint514;
-
- public Uint514() {}
-
- public Uint514(byte[] uint514) {
- this.uint514 = uint514;
- }
-
- public byte[] getUint514() {
- return this.uint514;
- }
-
- public void setUint514(byte[] value) {
- this.uint514 = value;
- }
-
public static void encode(XdrDataOutputStream stream, Uint514 encodedUint514) throws IOException {
- int uint514size = encodedUint514.uint514.length;
- stream.writeInt(uint514size);
- stream.write(encodedUint514.getUint514(), 0, uint514size);
+ int uint514Size = encodedUint514.uint514.length;
+ stream.writeInt(uint514Size);
+ stream.write(encodedUint514.getUint514(), 0, uint514Size);
}
public void encode(XdrDataOutputStream stream) throws IOException {
@@ -45,26 +35,12 @@ public void encode(XdrDataOutputStream stream) throws IOException {
}
public static Uint514 decode(XdrDataInputStream stream) throws IOException {
Uint514 decodedUint514 = new Uint514();
- int uint514size = stream.readInt();
- decodedUint514.uint514 = new byte[uint514size];
- stream.read(decodedUint514.uint514, 0, uint514size);
+ int uint514Size = stream.readInt();
+ decodedUint514.uint514 = new byte[uint514Size];
+ stream.read(decodedUint514.uint514, 0, uint514Size);
return decodedUint514;
}
- @Override
- public int hashCode() {
- return Arrays.hashCode(this.uint514);
- }
-
- @Override
- public boolean equals(Object object) {
- if (!(object instanceof Uint514)) {
- return false;
- }
-
- Uint514 other = (Uint514) object;
- return Arrays.equals(this.uint514, other.uint514);
- }
@Override
public String toXdrBase64() throws IOException {
return Base64Factory.getInstance().encodeToString(toXdrByteArray());
diff --git a/spec/output/generator_spec_java/test.x/XdrString.java b/spec/output/generator_spec_java/test.x/XdrString.java
index bb4e81fb4..2d8f8bbc9 100644
--- a/spec/output/generator_spec_java/test.x/XdrString.java
+++ b/spec/output/generator_spec_java/test.x/XdrString.java
@@ -4,90 +4,72 @@
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InvalidClassException;
-import java.nio.charset.Charset;
-import java.util.Arrays;
+import java.nio.charset.StandardCharsets;
+import lombok.Value;
import org.stellar.sdk.Base64Factory;
+@Value
public class XdrString implements XdrElement {
- private byte[] bytes;
+ byte[] bytes;
- public XdrString(byte[] bytes) {
- this.bytes = bytes;
- }
+ public XdrString(byte[] bytes) {
+ this.bytes = bytes;
+ }
- public XdrString(String text) {
- this.bytes = text.getBytes(Charset.forName("UTF-8"));
- }
+ public XdrString(String text) {
+ this.bytes = text.getBytes(StandardCharsets.UTF_8);
+ }
- @Override
- public void encode(XdrDataOutputStream stream) throws IOException {
- stream.writeInt(this.bytes.length);
- stream.write(this.bytes, 0, this.bytes.length);
- }
+ @Override
+ public void encode(XdrDataOutputStream stream) throws IOException {
+ stream.writeInt(this.bytes.length);
+ stream.write(this.bytes, 0, this.bytes.length);
+ }
- public static XdrString decode(XdrDataInputStream stream, int maxSize) throws IOException {
- int size = stream.readInt();
- if (size > maxSize) {
- throw new InvalidClassException("String length "+size+" exceeds max size "+maxSize);
- }
- byte[] bytes = new byte[size];
- stream.read(bytes);
- return new XdrString(bytes);
+ public static XdrString decode(XdrDataInputStream stream, int maxSize) throws IOException {
+ int size = stream.readInt();
+ if (size > maxSize) {
+ throw new InvalidClassException("String length " + size + " exceeds max size " + maxSize);
}
+ byte[] bytes = new byte[size];
+ stream.read(bytes);
+ return new XdrString(bytes);
+ }
- public byte[] getBytes() {
- return this.bytes;
- }
+ @Override
+ public String toXdrBase64() throws IOException {
+ return Base64Factory.getInstance().encodeToString(toXdrByteArray());
+ }
- @Override
- public String toXdrBase64() throws IOException {
- return Base64Factory.getInstance().encodeToString(toXdrByteArray());
- }
-
- @Override
- public byte[] toXdrByteArray() throws IOException {
- ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
- XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream);
- encode(xdrDataOutputStream);
- return byteArrayOutputStream.toByteArray();
- }
-
- public static XdrString fromXdrBase64(String xdr, int maxSize) throws IOException {
- byte[] bytes = Base64Factory.getInstance().decode(xdr);
- return fromXdrByteArray(bytes, maxSize);
- }
-
- public static XdrString fromXdrBase64(String xdr) throws IOException {
- return fromXdrBase64(xdr, Integer.MAX_VALUE);
- }
-
- public static XdrString fromXdrByteArray(byte[] xdr, int maxSize) throws IOException {
- ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr);
- XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream);
- return decode(xdrDataInputStream, maxSize);
- }
-
- public static XdrString fromXdrByteArray(byte[] xdr) throws IOException {
- return fromXdrByteArray(xdr, Integer.MAX_VALUE);
- }
+ @Override
+ public byte[] toXdrByteArray() throws IOException {
+ ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
+ XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream);
+ encode(xdrDataOutputStream);
+ return byteArrayOutputStream.toByteArray();
+ }
- @Override
- public int hashCode() {
- return Arrays.hashCode(this.bytes);
- }
+ public static XdrString fromXdrBase64(String xdr, int maxSize) throws IOException {
+ byte[] bytes = Base64Factory.getInstance().decode(xdr);
+ return fromXdrByteArray(bytes, maxSize);
+ }
- @Override
- public boolean equals(Object object) {
- if (object == null || !(object instanceof XdrString)) {
- return false;
- }
+ public static XdrString fromXdrBase64(String xdr) throws IOException {
+ return fromXdrBase64(xdr, Integer.MAX_VALUE);
+ }
- XdrString other = (XdrString) object;
- return Arrays.equals(this.bytes, other.bytes);
- }
+ public static XdrString fromXdrByteArray(byte[] xdr, int maxSize) throws IOException {
+ ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr);
+ XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream);
+ return decode(xdrDataInputStream, maxSize);
+ }
- @Override
- public String toString() {
- return new String(bytes, Charset.forName("UTF-8"));
- }
+ public static XdrString fromXdrByteArray(byte[] xdr) throws IOException {
+ return fromXdrByteArray(xdr, Integer.MAX_VALUE);
+ }
+
+ @Override
+ public String toString() {
+ return new String(bytes, StandardCharsets.UTF_8);
+ }
}
diff --git a/spec/output/generator_spec_java/test.x/XdrUnsignedHyperInteger.java b/spec/output/generator_spec_java/test.x/XdrUnsignedHyperInteger.java
index 6c05ca57d..204aa83de 100644
--- a/spec/output/generator_spec_java/test.x/XdrUnsignedHyperInteger.java
+++ b/spec/output/generator_spec_java/test.x/XdrUnsignedHyperInteger.java
@@ -1,10 +1,10 @@
-package org.stellar.sdk.xdr;
+package MyXDR;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.math.BigInteger;
-import java.util.Objects;
+import lombok.Value;
import org.stellar.sdk.Base64Factory;
/**
@@ -13,10 +13,11 @@
* @see XDR: External Data
* Representation Standard
*/
+@Value
public class XdrUnsignedHyperInteger implements XdrElement {
public static final BigInteger MAX_VALUE = new BigInteger("18446744073709551615");
public static final BigInteger MIN_VALUE = BigInteger.ZERO;
- private final BigInteger number;
+ BigInteger number;
public XdrUnsignedHyperInteger(BigInteger number) {
if (number.compareTo(MIN_VALUE) < 0 || number.compareTo(MAX_VALUE) > 0) {
@@ -55,10 +56,6 @@ private byte[] getBytes() {
return paddedBytes;
}
- public BigInteger getNumber() {
- return number;
- }
-
@Override
public String toXdrBase64() throws IOException {
return Base64Factory.getInstance().encodeToString(toXdrByteArray());
@@ -82,23 +79,4 @@ public static XdrUnsignedHyperInteger fromXdrByteArray(byte[] xdr) throws IOExce
XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream);
return decode(xdrDataInputStream);
}
-
- @Override
- public int hashCode() {
- return Objects.hash(this.number);
- }
-
- @Override
- public boolean equals(Object object) {
- if (!(object instanceof XdrUnsignedHyperInteger)) {
- return false;
- }
-
- XdrUnsignedHyperInteger other = (XdrUnsignedHyperInteger) object;
- return Objects.equals(this.number, other.number);
- }
-
- public String toString() {
- return "XdrUnsignedInteger(number=" + this.getNumber() + ")";
- }
}
diff --git a/spec/output/generator_spec_java/test.x/XdrUnsignedInteger.java b/spec/output/generator_spec_java/test.x/XdrUnsignedInteger.java
index 8f2a52395..a56ad657d 100644
--- a/spec/output/generator_spec_java/test.x/XdrUnsignedInteger.java
+++ b/spec/output/generator_spec_java/test.x/XdrUnsignedInteger.java
@@ -1,9 +1,9 @@
-package org.stellar.sdk.xdr;
+package MyXDR;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
-import java.util.Objects;
+import lombok.Value;
import org.stellar.sdk.Base64Factory;
/**
@@ -12,10 +12,11 @@
* @see XDR: External Data
* Representation Standard
*/
+@Value
public class XdrUnsignedInteger implements XdrElement {
public static final long MAX_VALUE = (1L << 32) - 1;
public static final long MIN_VALUE = 0;
- private final Long number;
+ Long number;
public XdrUnsignedInteger(Long number) {
if (number < MIN_VALUE || number > MAX_VALUE) {
@@ -32,10 +33,6 @@ public XdrUnsignedInteger(Integer number) {
this.number = number.longValue();
}
- public Long getNumber() {
- return number;
- }
-
public static XdrUnsignedInteger decode(XdrDataInputStream stream) throws IOException {
int intValue = stream.readInt();
long uint32Value = Integer.toUnsignedLong(intValue);
@@ -70,23 +67,4 @@ public static XdrUnsignedInteger fromXdrByteArray(byte[] xdr) throws IOException
XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream);
return decode(xdrDataInputStream);
}
-
- @Override
- public int hashCode() {
- return Objects.hash(this.number);
- }
-
- @Override
- public boolean equals(Object object) {
- if (!(object instanceof XdrUnsignedInteger)) {
- return false;
- }
-
- XdrUnsignedInteger other = (XdrUnsignedInteger) object;
- return Objects.equals(this.number, other.number);
- }
-
- public String toString() {
- return "XdrUnsignedInteger(number=" + this.getNumber() + ")";
- }
}
diff --git a/spec/output/generator_spec_java/union.x/Error.java b/spec/output/generator_spec_java/union.x/Error.java
index 1fe8a9d43..33888a051 100644
--- a/spec/output/generator_spec_java/union.x/Error.java
+++ b/spec/output/generator_spec_java/union.x/Error.java
@@ -5,11 +5,13 @@
import java.io.IOException;
-import static MyXDR.Constants.*;
import org.stellar.sdk.Base64Factory;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
-import java.util.Objects;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+import lombok.AllArgsConstructor;
+import static MyXDR.Constants.*;
/**
* Error's original definition in the XDR file is:
@@ -17,23 +19,11 @@
* typedef int Error;
*
*/
+@Data
+@NoArgsConstructor
+@AllArgsConstructor
public class Error implements XdrElement {
private Integer Error;
-
- public Error() {}
-
- public Error(Integer Error) {
- this.Error = Error;
- }
-
- public Integer getError() {
- return this.Error;
- }
-
- public void setError(Integer value) {
- this.Error = value;
- }
-
public static void encode(XdrDataOutputStream stream, Error encodedError) throws IOException {
stream.writeInt(encodedError.Error);
}
@@ -47,20 +37,6 @@ public static Error decode(XdrDataInputStream stream) throws IOException {
return decodedError;
}
- @Override
- public int hashCode() {
- return Objects.hash(this.Error);
- }
-
- @Override
- public boolean equals(Object object) {
- if (!(object instanceof Error)) {
- return false;
- }
-
- Error other = (Error) object;
- return Objects.equals(this.Error, other.Error);
- }
@Override
public String toXdrBase64() throws IOException {
return Base64Factory.getInstance().encodeToString(toXdrByteArray());
diff --git a/spec/output/generator_spec_java/union.x/IntUnion.java b/spec/output/generator_spec_java/union.x/IntUnion.java
index 0b3a6081f..2ae33c648 100644
--- a/spec/output/generator_spec_java/union.x/IntUnion.java
+++ b/spec/output/generator_spec_java/union.x/IntUnion.java
@@ -5,12 +5,14 @@
import java.io.IOException;
-import static MyXDR.Constants.*;
import org.stellar.sdk.Base64Factory;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
-import java.util.Objects;
-import java.util.Arrays;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import static MyXDR.Constants.*;
/**
* IntUnion's original definition in the XDR file is:
@@ -25,58 +27,14 @@
* };
*
*/
+@Data
+@NoArgsConstructor
+@AllArgsConstructor
+@Builder(toBuilder = true)
public class IntUnion implements XdrElement {
- public IntUnion () {}
- Integer type;
- public Integer getDiscriminant() {
- return this.type;
- }
- public void setDiscriminant(Integer value) {
- this.type = value;
- }
+ private Integer discriminant;
private Error error;
- public Error getError() {
- return this.error;
- }
- public void setError(Error value) {
- this.error = value;
- }
private Multi[] things;
- public Multi[] getThings() {
- return this.things;
- }
- public void setThings(Multi[] value) {
- this.things = value;
- }
-
- public static final class Builder {
- private Integer discriminant;
- private Error error;
- private Multi[] things;
-
- public Builder discriminant(Integer discriminant) {
- this.discriminant = discriminant;
- return this;
- }
-
- public Builder error(Error error) {
- this.error = error;
- return this;
- }
-
- public Builder things(Multi[] things) {
- this.things = things;
- return this;
- }
-
- public IntUnion build() {
- IntUnion val = new IntUnion();
- val.setDiscriminant(discriminant);
- val.setError(this.error);
- val.setThings(this.things);
- return val;
- }
- }
public static void encode(XdrDataOutputStream stream, IntUnion encodedIntUnion) throws IOException {
//Xdrgen::AST::Typespecs::Int
@@ -87,9 +45,9 @@ public static void encode(XdrDataOutputStream stream, IntUnion encodedIntUnion)
Error.encode(stream, encodedIntUnion.error);
break;
case 1:
- int thingssize = encodedIntUnion.getThings().length;
- stream.writeInt(thingssize);
- for (int i = 0; i < thingssize; i++) {
+ int thingsSize = encodedIntUnion.getThings().length;
+ stream.writeInt(thingsSize);
+ for (int i = 0; i < thingsSize; i++) {
Multi.encode(stream, encodedIntUnion.things[i]);
}
break;
@@ -107,9 +65,9 @@ public static IntUnion decode(XdrDataInputStream stream) throws IOException {
decodedIntUnion.error = Error.decode(stream);
break;
case 1:
- int thingssize = stream.readInt();
- decodedIntUnion.things = new Multi[thingssize];
- for (int i = 0; i < thingssize; i++) {
+ int thingsSize = stream.readInt();
+ decodedIntUnion.things = new Multi[thingsSize];
+ for (int i = 0; i < thingsSize; i++) {
decodedIntUnion.things[i] = Multi.decode(stream);
}
break;
@@ -117,19 +75,6 @@ public static IntUnion decode(XdrDataInputStream stream) throws IOException {
return decodedIntUnion;
}
@Override
- public int hashCode() {
- return Objects.hash(this.error, Arrays.hashCode(this.things), this.type);
- }
- @Override
- public boolean equals(Object object) {
- if (!(object instanceof IntUnion)) {
- return false;
- }
-
- IntUnion other = (IntUnion) object;
- return Objects.equals(this.error, other.error) && Arrays.equals(this.things, other.things) && Objects.equals(this.type, other.type);
- }
- @Override
public String toXdrBase64() throws IOException {
return Base64Factory.getInstance().encodeToString(toXdrByteArray());
}
diff --git a/spec/output/generator_spec_java/union.x/IntUnion2.java b/spec/output/generator_spec_java/union.x/IntUnion2.java
index 45ddec6d7..730be0ffd 100644
--- a/spec/output/generator_spec_java/union.x/IntUnion2.java
+++ b/spec/output/generator_spec_java/union.x/IntUnion2.java
@@ -5,11 +5,13 @@
import java.io.IOException;
-import static MyXDR.Constants.*;
import org.stellar.sdk.Base64Factory;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
-import java.util.Objects;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+import lombok.AllArgsConstructor;
+import static MyXDR.Constants.*;
/**
* IntUnion2's original definition in the XDR file is:
@@ -17,23 +19,11 @@
* typedef IntUnion IntUnion2;
*
*/
+@Data
+@NoArgsConstructor
+@AllArgsConstructor
public class IntUnion2 implements XdrElement {
private IntUnion IntUnion2;
-
- public IntUnion2() {}
-
- public IntUnion2(IntUnion IntUnion2) {
- this.IntUnion2 = IntUnion2;
- }
-
- public IntUnion getIntUnion2() {
- return this.IntUnion2;
- }
-
- public void setIntUnion2(IntUnion value) {
- this.IntUnion2 = value;
- }
-
public static void encode(XdrDataOutputStream stream, IntUnion2 encodedIntUnion2) throws IOException {
IntUnion.encode(stream, encodedIntUnion2.IntUnion2);
}
@@ -47,20 +37,6 @@ public static IntUnion2 decode(XdrDataInputStream stream) throws IOException {
return decodedIntUnion2;
}
- @Override
- public int hashCode() {
- return Objects.hash(this.IntUnion2);
- }
-
- @Override
- public boolean equals(Object object) {
- if (!(object instanceof IntUnion2)) {
- return false;
- }
-
- IntUnion2 other = (IntUnion2) object;
- return Objects.equals(this.IntUnion2, other.IntUnion2);
- }
@Override
public String toXdrBase64() throws IOException {
return Base64Factory.getInstance().encodeToString(toXdrByteArray());
diff --git a/spec/output/generator_spec_java/union.x/Multi.java b/spec/output/generator_spec_java/union.x/Multi.java
index 281454e04..637de5bce 100644
--- a/spec/output/generator_spec_java/union.x/Multi.java
+++ b/spec/output/generator_spec_java/union.x/Multi.java
@@ -5,11 +5,13 @@
import java.io.IOException;
-import static MyXDR.Constants.*;
import org.stellar.sdk.Base64Factory;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
-import java.util.Objects;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+import lombok.AllArgsConstructor;
+import static MyXDR.Constants.*;
/**
* Multi's original definition in the XDR file is:
@@ -17,23 +19,11 @@
* typedef int Multi;
*
*/
+@Data
+@NoArgsConstructor
+@AllArgsConstructor
public class Multi implements XdrElement {
private Integer Multi;
-
- public Multi() {}
-
- public Multi(Integer Multi) {
- this.Multi = Multi;
- }
-
- public Integer getMulti() {
- return this.Multi;
- }
-
- public void setMulti(Integer value) {
- this.Multi = value;
- }
-
public static void encode(XdrDataOutputStream stream, Multi encodedMulti) throws IOException {
stream.writeInt(encodedMulti.Multi);
}
@@ -47,20 +37,6 @@ public static Multi decode(XdrDataInputStream stream) throws IOException {
return decodedMulti;
}
- @Override
- public int hashCode() {
- return Objects.hash(this.Multi);
- }
-
- @Override
- public boolean equals(Object object) {
- if (!(object instanceof Multi)) {
- return false;
- }
-
- Multi other = (Multi) object;
- return Objects.equals(this.Multi, other.Multi);
- }
@Override
public String toXdrBase64() throws IOException {
return Base64Factory.getInstance().encodeToString(toXdrByteArray());
diff --git a/spec/output/generator_spec_java/union.x/MyUnion.java b/spec/output/generator_spec_java/union.x/MyUnion.java
index 90cdebe61..8f9b1daf2 100644
--- a/spec/output/generator_spec_java/union.x/MyUnion.java
+++ b/spec/output/generator_spec_java/union.x/MyUnion.java
@@ -5,12 +5,14 @@
import java.io.IOException;
-import static MyXDR.Constants.*;
import org.stellar.sdk.Base64Factory;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
-import java.util.Objects;
-import java.util.Arrays;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import static MyXDR.Constants.*;
/**
* MyUnion's original definition in the XDR file is:
@@ -26,58 +28,14 @@
* };
*
*/
+@Data
+@NoArgsConstructor
+@AllArgsConstructor
+@Builder(toBuilder = true)
public class MyUnion implements XdrElement {
- public MyUnion () {}
- UnionKey type;
- public UnionKey getDiscriminant() {
- return this.type;
- }
- public void setDiscriminant(UnionKey value) {
- this.type = value;
- }
+ private UnionKey discriminant;
private Error error;
- public Error getError() {
- return this.error;
- }
- public void setError(Error value) {
- this.error = value;
- }
private Multi[] things;
- public Multi[] getThings() {
- return this.things;
- }
- public void setThings(Multi[] value) {
- this.things = value;
- }
-
- public static final class Builder {
- private UnionKey discriminant;
- private Error error;
- private Multi[] things;
-
- public Builder discriminant(UnionKey discriminant) {
- this.discriminant = discriminant;
- return this;
- }
-
- public Builder error(Error error) {
- this.error = error;
- return this;
- }
-
- public Builder things(Multi[] things) {
- this.things = things;
- return this;
- }
-
- public MyUnion build() {
- MyUnion val = new MyUnion();
- val.setDiscriminant(discriminant);
- val.setError(this.error);
- val.setThings(this.things);
- return val;
- }
- }
public static void encode(XdrDataOutputStream stream, MyUnion encodedMyUnion) throws IOException {
//Xdrgen::AST::Identifier
@@ -88,9 +46,9 @@ public static void encode(XdrDataOutputStream stream, MyUnion encodedMyUnion) th
Error.encode(stream, encodedMyUnion.error);
break;
case MULTI:
- int thingssize = encodedMyUnion.getThings().length;
- stream.writeInt(thingssize);
- for (int i = 0; i < thingssize; i++) {
+ int thingsSize = encodedMyUnion.getThings().length;
+ stream.writeInt(thingsSize);
+ for (int i = 0; i < thingsSize; i++) {
Multi.encode(stream, encodedMyUnion.things[i]);
}
break;
@@ -108,9 +66,9 @@ public static MyUnion decode(XdrDataInputStream stream) throws IOException {
decodedMyUnion.error = Error.decode(stream);
break;
case MULTI:
- int thingssize = stream.readInt();
- decodedMyUnion.things = new Multi[thingssize];
- for (int i = 0; i < thingssize; i++) {
+ int thingsSize = stream.readInt();
+ decodedMyUnion.things = new Multi[thingsSize];
+ for (int i = 0; i < thingsSize; i++) {
decodedMyUnion.things[i] = Multi.decode(stream);
}
break;
@@ -118,19 +76,6 @@ public static MyUnion decode(XdrDataInputStream stream) throws IOException {
return decodedMyUnion;
}
@Override
- public int hashCode() {
- return Objects.hash(this.error, Arrays.hashCode(this.things), this.type);
- }
- @Override
- public boolean equals(Object object) {
- if (!(object instanceof MyUnion)) {
- return false;
- }
-
- MyUnion other = (MyUnion) object;
- return Objects.equals(this.error, other.error) && Arrays.equals(this.things, other.things) && Objects.equals(this.type, other.type);
- }
- @Override
public String toXdrBase64() throws IOException {
return Base64Factory.getInstance().encodeToString(toXdrByteArray());
}
diff --git a/spec/output/generator_spec_java/union.x/UnionKey.java b/spec/output/generator_spec_java/union.x/UnionKey.java
index 0ca6d26fa..245f4b969 100644
--- a/spec/output/generator_spec_java/union.x/UnionKey.java
+++ b/spec/output/generator_spec_java/union.x/UnionKey.java
@@ -5,7 +5,6 @@
import java.io.IOException;
-import static MyXDR.Constants.*;
import org.stellar.sdk.Base64Factory;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
@@ -21,16 +20,16 @@
*/
public enum UnionKey implements XdrElement {
ERROR(0),
- MULTI(1),
- ;
- private int mValue;
+ MULTI(1);
+
+ private final int value;
UnionKey(int value) {
- mValue = value;
+ this.value = value;
}
public int getValue() {
- return mValue;
+ return value;
}
public static UnionKey decode(XdrDataInputStream stream) throws IOException {
diff --git a/spec/output/generator_spec_java/union.x/XdrString.java b/spec/output/generator_spec_java/union.x/XdrString.java
index bb4e81fb4..2d8f8bbc9 100644
--- a/spec/output/generator_spec_java/union.x/XdrString.java
+++ b/spec/output/generator_spec_java/union.x/XdrString.java
@@ -4,90 +4,72 @@
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InvalidClassException;
-import java.nio.charset.Charset;
-import java.util.Arrays;
+import java.nio.charset.StandardCharsets;
+import lombok.Value;
import org.stellar.sdk.Base64Factory;
+@Value
public class XdrString implements XdrElement {
- private byte[] bytes;
+ byte[] bytes;
- public XdrString(byte[] bytes) {
- this.bytes = bytes;
- }
+ public XdrString(byte[] bytes) {
+ this.bytes = bytes;
+ }
- public XdrString(String text) {
- this.bytes = text.getBytes(Charset.forName("UTF-8"));
- }
+ public XdrString(String text) {
+ this.bytes = text.getBytes(StandardCharsets.UTF_8);
+ }
- @Override
- public void encode(XdrDataOutputStream stream) throws IOException {
- stream.writeInt(this.bytes.length);
- stream.write(this.bytes, 0, this.bytes.length);
- }
+ @Override
+ public void encode(XdrDataOutputStream stream) throws IOException {
+ stream.writeInt(this.bytes.length);
+ stream.write(this.bytes, 0, this.bytes.length);
+ }
- public static XdrString decode(XdrDataInputStream stream, int maxSize) throws IOException {
- int size = stream.readInt();
- if (size > maxSize) {
- throw new InvalidClassException("String length "+size+" exceeds max size "+maxSize);
- }
- byte[] bytes = new byte[size];
- stream.read(bytes);
- return new XdrString(bytes);
+ public static XdrString decode(XdrDataInputStream stream, int maxSize) throws IOException {
+ int size = stream.readInt();
+ if (size > maxSize) {
+ throw new InvalidClassException("String length " + size + " exceeds max size " + maxSize);
}
+ byte[] bytes = new byte[size];
+ stream.read(bytes);
+ return new XdrString(bytes);
+ }
- public byte[] getBytes() {
- return this.bytes;
- }
+ @Override
+ public String toXdrBase64() throws IOException {
+ return Base64Factory.getInstance().encodeToString(toXdrByteArray());
+ }
- @Override
- public String toXdrBase64() throws IOException {
- return Base64Factory.getInstance().encodeToString(toXdrByteArray());
- }
-
- @Override
- public byte[] toXdrByteArray() throws IOException {
- ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
- XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream);
- encode(xdrDataOutputStream);
- return byteArrayOutputStream.toByteArray();
- }
-
- public static XdrString fromXdrBase64(String xdr, int maxSize) throws IOException {
- byte[] bytes = Base64Factory.getInstance().decode(xdr);
- return fromXdrByteArray(bytes, maxSize);
- }
-
- public static XdrString fromXdrBase64(String xdr) throws IOException {
- return fromXdrBase64(xdr, Integer.MAX_VALUE);
- }
-
- public static XdrString fromXdrByteArray(byte[] xdr, int maxSize) throws IOException {
- ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr);
- XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream);
- return decode(xdrDataInputStream, maxSize);
- }
-
- public static XdrString fromXdrByteArray(byte[] xdr) throws IOException {
- return fromXdrByteArray(xdr, Integer.MAX_VALUE);
- }
+ @Override
+ public byte[] toXdrByteArray() throws IOException {
+ ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
+ XdrDataOutputStream xdrDataOutputStream = new XdrDataOutputStream(byteArrayOutputStream);
+ encode(xdrDataOutputStream);
+ return byteArrayOutputStream.toByteArray();
+ }
- @Override
- public int hashCode() {
- return Arrays.hashCode(this.bytes);
- }
+ public static XdrString fromXdrBase64(String xdr, int maxSize) throws IOException {
+ byte[] bytes = Base64Factory.getInstance().decode(xdr);
+ return fromXdrByteArray(bytes, maxSize);
+ }
- @Override
- public boolean equals(Object object) {
- if (object == null || !(object instanceof XdrString)) {
- return false;
- }
+ public static XdrString fromXdrBase64(String xdr) throws IOException {
+ return fromXdrBase64(xdr, Integer.MAX_VALUE);
+ }
- XdrString other = (XdrString) object;
- return Arrays.equals(this.bytes, other.bytes);
- }
+ public static XdrString fromXdrByteArray(byte[] xdr, int maxSize) throws IOException {
+ ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(xdr);
+ XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream);
+ return decode(xdrDataInputStream, maxSize);
+ }
- @Override
- public String toString() {
- return new String(bytes, Charset.forName("UTF-8"));
- }
+ public static XdrString fromXdrByteArray(byte[] xdr) throws IOException {
+ return fromXdrByteArray(xdr, Integer.MAX_VALUE);
+ }
+
+ @Override
+ public String toString() {
+ return new String(bytes, StandardCharsets.UTF_8);
+ }
}
diff --git a/spec/output/generator_spec_java/union.x/XdrUnsignedHyperInteger.java b/spec/output/generator_spec_java/union.x/XdrUnsignedHyperInteger.java
index 6c05ca57d..204aa83de 100644
--- a/spec/output/generator_spec_java/union.x/XdrUnsignedHyperInteger.java
+++ b/spec/output/generator_spec_java/union.x/XdrUnsignedHyperInteger.java
@@ -1,10 +1,10 @@
-package org.stellar.sdk.xdr;
+package MyXDR;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.math.BigInteger;
-import java.util.Objects;
+import lombok.Value;
import org.stellar.sdk.Base64Factory;
/**
@@ -13,10 +13,11 @@
* @see XDR: External Data
* Representation Standard
*/
+@Value
public class XdrUnsignedHyperInteger implements XdrElement {
public static final BigInteger MAX_VALUE = new BigInteger("18446744073709551615");
public static final BigInteger MIN_VALUE = BigInteger.ZERO;
- private final BigInteger number;
+ BigInteger number;
public XdrUnsignedHyperInteger(BigInteger number) {
if (number.compareTo(MIN_VALUE) < 0 || number.compareTo(MAX_VALUE) > 0) {
@@ -55,10 +56,6 @@ private byte[] getBytes() {
return paddedBytes;
}
- public BigInteger getNumber() {
- return number;
- }
-
@Override
public String toXdrBase64() throws IOException {
return Base64Factory.getInstance().encodeToString(toXdrByteArray());
@@ -82,23 +79,4 @@ public static XdrUnsignedHyperInteger fromXdrByteArray(byte[] xdr) throws IOExce
XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream);
return decode(xdrDataInputStream);
}
-
- @Override
- public int hashCode() {
- return Objects.hash(this.number);
- }
-
- @Override
- public boolean equals(Object object) {
- if (!(object instanceof XdrUnsignedHyperInteger)) {
- return false;
- }
-
- XdrUnsignedHyperInteger other = (XdrUnsignedHyperInteger) object;
- return Objects.equals(this.number, other.number);
- }
-
- public String toString() {
- return "XdrUnsignedInteger(number=" + this.getNumber() + ")";
- }
}
diff --git a/spec/output/generator_spec_java/union.x/XdrUnsignedInteger.java b/spec/output/generator_spec_java/union.x/XdrUnsignedInteger.java
index 8f2a52395..a56ad657d 100644
--- a/spec/output/generator_spec_java/union.x/XdrUnsignedInteger.java
+++ b/spec/output/generator_spec_java/union.x/XdrUnsignedInteger.java
@@ -1,9 +1,9 @@
-package org.stellar.sdk.xdr;
+package MyXDR;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
-import java.util.Objects;
+import lombok.Value;
import org.stellar.sdk.Base64Factory;
/**
@@ -12,10 +12,11 @@
* @see XDR: External Data
* Representation Standard
*/
+@Value
public class XdrUnsignedInteger implements XdrElement {
public static final long MAX_VALUE = (1L << 32) - 1;
public static final long MIN_VALUE = 0;
- private final Long number;
+ Long number;
public XdrUnsignedInteger(Long number) {
if (number < MIN_VALUE || number > MAX_VALUE) {
@@ -32,10 +33,6 @@ public XdrUnsignedInteger(Integer number) {
this.number = number.longValue();
}
- public Long getNumber() {
- return number;
- }
-
public static XdrUnsignedInteger decode(XdrDataInputStream stream) throws IOException {
int intValue = stream.readInt();
long uint32Value = Integer.toUnsignedLong(intValue);
@@ -70,23 +67,4 @@ public static XdrUnsignedInteger fromXdrByteArray(byte[] xdr) throws IOException
XdrDataInputStream xdrDataInputStream = new XdrDataInputStream(byteArrayInputStream);
return decode(xdrDataInputStream);
}
-
- @Override
- public int hashCode() {
- return Objects.hash(this.number);
- }
-
- @Override
- public boolean equals(Object object) {
- if (!(object instanceof XdrUnsignedInteger)) {
- return false;
- }
-
- XdrUnsignedInteger other = (XdrUnsignedInteger) object;
- return Objects.equals(this.number, other.number);
- }
-
- public String toString() {
- return "XdrUnsignedInteger(number=" + this.getNumber() + ")";
- }
}