Skip to content

Commit

Permalink
timid reworking of the uri stuff. need to make it a lot better
Browse files Browse the repository at this point in the history
  • Loading branch information
heinousjay committed Jan 20, 2013
1 parent 6f438f2 commit c65f656
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 10 deletions.
Expand Up @@ -21,10 +21,12 @@
import java.util.Collection;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

Expand Down Expand Up @@ -65,7 +67,7 @@ public static UriTemplate fromTemplate(String template) {
*/
public static UriTemplate fromTemplate(UriTemplate base) {
UriTemplate template = fromTemplate(base.getTemplate());
template.set(base.getValues());
template.set(base.values());
return template;
}

Expand Down Expand Up @@ -116,6 +118,8 @@ private static boolean containsOperator(String op) {
private final StringBuilder templateBuffer;

private final Map<String, Object> values = new HashMap<>();

private final Set<String> matches = new HashSet<>();

/**
* Create a new RFC6570UriTemplate.
Expand Down Expand Up @@ -189,9 +193,13 @@ public String getTemplate() {
return templateBuffer.toString();
}

public Map<String, Object> getValues() {
public Map<String, Object> values() {
return values;
}

public Set<String> matches() {
return matches;
}

public String expand() {

Expand All @@ -206,7 +214,8 @@ public String expand() {
while (matcher.find()) {

String token = matcher.group();
String value = buildVarSpecs(token.substring(1, token.length() - 1));
token = token.substring(1, token.length() - 1);
String value = buildVarSpecs(token);
matcher.appendReplacement(buffer, value);
count++;
}
Expand Down
Expand Up @@ -95,9 +95,7 @@ public final class UriUtil {
private static void add(BitSet destination, String toAdd) {

for (char character : toAdd.toCharArray()) {
if (character >= 127) {
throw new IllegalArgumentException("Bitset only works correct with one " + "byte");
}
assert (character < 128) : "Bitset only works correct with one " + "byte";
destination.set(character);
}
}
Expand Down
Expand Up @@ -30,9 +30,9 @@ public void testFromTemplate() throws Exception
.set("thingId","123öä|\\");


assertEquals(3, child.getValues().size());
Map<String, Object> childValues = child.getValues();
for(Entry<String, Object> e : base.getValues().entrySet())
assertEquals(3, child.values().size());
Map<String, Object> childValues = child.values();
for(Entry<String, Object> e : base.values().entrySet())
{
assertTrue(childValues.containsKey(e.getKey()));
assertEquals(e.getValue(), childValues.get(e.getKey()));
Expand All @@ -54,7 +54,7 @@ public void testMultpleExpressions() throws Exception
.set("version","v1")
.set("thingId","12345");

assertEquals(3, template.getValues().size());
assertEquals(3, template.values().size());
assertEquals("http://myhost{/version}{/myId}/things/{thingId}", template.getTemplate());
assertEquals("http://myhost/v1/damnhandy/things/12345", template.expand());
}
Expand Down

0 comments on commit c65f656

Please sign in to comment.