Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
gh-204 Implement new functions in DefaultServiceInstance
Implement putMetadata(String key, String value) and
 setMetadata(Map<String, String> metadata) in DefaultServiceInstance to
 comply with the interface adjustment.
The setMetadata() will be somewhat lengthy as we are dealing with a
 final map.
  • Loading branch information
smcvb committed May 16, 2017
commit 160efaeb2c2cf0353fda3e240989a378b320b964
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.net.URI;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Set;

import lombok.Data;
import lombok.RequiredArgsConstructor;
Expand All @@ -27,6 +28,7 @@
* Default implementation of {@link ServiceInstance}.
*
* @author Spencer Gibb
* @author Steven van Beelen
*/
@Data
@RequiredArgsConstructor
Expand Down Expand Up @@ -57,6 +59,23 @@ public Map<String, String> getMetadata() {
return this.metadata;
}

@Override
public void putMetadata(String key, String value) {
this.metadata.put(key, value);
}

@Override
public void setMetadata(Map<String, String> metadata) {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I took the approach of removing all the old fields and adding them because metadata is final for this class.

Removing final from the field seemed more problematic because of the @RequiredArgsConstructor.

Set<String> keySet = this.metadata.keySet();
for (String key : keySet) {
this.metadata.remove(key);
}

for (Map.Entry<String, String> newEntry : metadata.entrySet()) {
this.metadata.put(newEntry.getKey(), newEntry.getValue());
}
}

/**
* Create a uri from the given ServiceInstance's host:port
* @param instance
Expand Down