1717import io .nats .client .support .JsonUtils ;
1818import io .nats .client .support .JsonValue ;
1919
20+ import java .util .Map ;
2021import java .util .Objects ;
2122
2223import static io .nats .client .support .ApiConstants .*;
2324import static io .nats .client .support .JsonUtils .endJson ;
24- import static io .nats .client .support .JsonValueUtils .readString ;
25- import static io .nats .client .support .JsonValueUtils .readValue ;
25+ import static io .nats .client .support .JsonValueUtils .*;
2626import static io .nats .client .support .Validator .validateIsRestrictedTerm ;
2727import static io .nats .client .support .Validator .validateSubject ;
2828
@@ -33,25 +33,26 @@ public class Endpoint implements JsonSerializable {
3333 private final String name ;
3434 private final String subject ;
3535 private final Schema schema ;
36+ private final Map <String , String > metadata ;
3637
3738 public Endpoint (String name , String subject , Schema schema ) {
38- this (name , subject , schema , true );
39+ this (name , subject , schema , null , true );
3940 }
4041
4142 public Endpoint (String name ) {
42- this (name , null , null , true );
43+ this (name , null , null , null , true );
4344 }
4445
4546 public Endpoint (String name , String subject ) {
46- this (name , subject , null , true );
47+ this (name , subject , null , null , true );
4748 }
4849
4950 public Endpoint (String name , String subject , String schemaRequest , String schemaResponse ) {
50- this (name , subject , Schema .optionalInstance (schemaRequest , schemaResponse ), true );
51+ this (name , subject , Schema .optionalInstance (schemaRequest , schemaResponse ), null , true );
5152 }
5253
5354 // internal use constructors
54- Endpoint (String name , String subject , Schema schema , boolean validate ) {
55+ Endpoint (String name , String subject , Schema schema , Map < String , String > metadata , boolean validate ) {
5556 if (validate ) {
5657 this .name = validateIsRestrictedTerm (name , "Endpoint Name" , true );
5758 if (subject == null ) {
@@ -66,16 +67,18 @@ public Endpoint(String name, String subject, String schemaRequest, String schema
6667 this .subject = subject ;
6768 }
6869 this .schema = schema ;
70+ this .metadata = metadata == null || metadata .size () == 0 ? null : metadata ;
6971 }
7072
7173 Endpoint (JsonValue vEndpoint ) {
7274 name = readString (vEndpoint , NAME );
7375 subject = readString (vEndpoint , SUBJECT );
7476 schema = Schema .optionalInstance (readValue (vEndpoint , SCHEMA ));
77+ metadata = readStringStringMap (vEndpoint , METADATA );
7578 }
7679
7780 Endpoint (Builder b ) {
78- this (b .name , b .subject , Schema .optionalInstance (b .schemaRequest , b .schemaResponse ));
81+ this (b .name , b .subject , Schema .optionalInstance (b .schemaRequest , b .schemaResponse ), b . metadata , true );
7982 }
8083
8184 @ Override
@@ -84,6 +87,7 @@ public String toJson() {
8487 JsonUtils .addField (sb , NAME , name );
8588 JsonUtils .addField (sb , SUBJECT , subject );
8689 JsonUtils .addField (sb , SCHEMA , schema );
90+ JsonUtils .addField (sb , METADATA , metadata );
8791 return endJson (sb ).toString ();
8892 }
8993
@@ -104,6 +108,10 @@ public Schema getSchema() {
104108 return schema ;
105109 }
106110
111+ public Map <String , String > getMetadata () {
112+ return metadata ;
113+ }
114+
107115 public static Builder builder () {
108116 return new Builder ();
109117 }
@@ -113,6 +121,7 @@ public static class Builder {
113121 private String subject ;
114122 private String schemaRequest ;
115123 private String schemaResponse ;
124+ private Map <String , String > metadata ;
116125
117126 public Builder endpoint (Endpoint endpoint ) {
118127 name = endpoint .getName ();
@@ -161,6 +170,11 @@ public Builder schema(Schema schema) {
161170 return this ;
162171 }
163172
173+ public Builder metadata (Map <String , String > metadata ) {
174+ this .metadata = metadata ;
175+ return this ;
176+ }
177+
164178 public Endpoint build () {
165179 return new Endpoint (this );
166180 }
@@ -171,18 +185,20 @@ public boolean equals(Object o) {
171185 if (this == o ) return true ;
172186 if (o == null || getClass () != o .getClass ()) return false ;
173187
174- Endpoint endpoint = (Endpoint ) o ;
188+ Endpoint that = (Endpoint ) o ;
175189
176- if (!Objects .equals (name , endpoint .name )) return false ;
177- if (!Objects .equals (subject , endpoint .subject )) return false ;
178- return Objects .equals (schema , endpoint .schema );
190+ if (!Objects .equals (name , that .name )) return false ;
191+ if (!Objects .equals (subject , that .subject )) return false ;
192+ if (!Objects .equals (schema , that .schema )) return false ;
193+ return JsonUtils .mapEquals (metadata , that .metadata );
179194 }
180195
181196 @ Override
182197 public int hashCode () {
183198 int result = name != null ? name .hashCode () : 0 ;
184199 result = 31 * result + (subject != null ? subject .hashCode () : 0 );
185200 result = 31 * result + (schema != null ? schema .hashCode () : 0 );
201+ result = 31 * result + (metadata != null ? metadata .hashCode () : 0 );
186202 return result ;
187203 }
188204}
0 commit comments