Skip to content
This repository has been archived by the owner on May 23, 2023. It is now read-only.

Commit

Permalink
Merge pull request #34 from opentracing/bhs/iterable_textmap
Browse files Browse the repository at this point in the history
Support Iterable via a method rename
  • Loading branch information
bensigelman authored Aug 7, 2016
2 parents 29bfcc1 + 4927ba6 commit 1c20ac3
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
* @see io.opentracing.Tracer#inject(SpanContext, Format, Object)
* @see io.opentracing.Tracer#extract(Format, Object)
*/
public interface TextMap {
public interface TextMap extends Iterable<Map.Entry<String, String>> {
/**
* Gets an iterator over arbitrary key:value pairs from the TextMapReader.
*
Expand All @@ -36,7 +36,7 @@ public interface TextMap {
* @see Format.Builtin#TEXT_MAP
* @see Format.Builtin#HTTP_HEADERS
*/
Iterator<Map.Entry<String,String>> getEntries();
Iterator<Map.Entry<String,String>> iterator();

/**
* Puts a key:value pair into the TextMapWriter's backing store.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public TextMapExtractAdapter(final Map<String,String> map) {
}

@Override
public Iterator<Map.Entry<String, String>> getEntries() {
public Iterator<Map.Entry<String, String>> iterator() {
return map.entrySet().iterator();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public TextMapInjectAdapter(final Map<String,String> map) {
}

@Override
public Iterator<Map.Entry<String, String>> getEntries() {
public Iterator<Map.Entry<String, String>> iterator() {
throw new UnsupportedOperationException(
"TextMapInjectAdapter should only be used with Tracer.inject()");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,12 @@
import io.opentracing.SpanContext;
import io.opentracing.TestSpanContextImpl;

import java.util.Iterator;
import java.util.Map;

public class TestTextMapExtractorImpl implements Extractor<TextMap> {
public SpanContext extract(TextMap carrier) {
String marker = null;
for (Iterator<Map.Entry<String,String>> iter = carrier.getEntries(); iter.hasNext();) {
Map.Entry<String, String> entry = iter.next();
for (Map.Entry<String,String> entry : carrier) {
if (entry.getKey().equals("test-marker")) {
marker = entry.getValue();
}
Expand Down

0 comments on commit 1c20ac3

Please sign in to comment.