Permalink
Browse files

timid reworking of the uri stuff. need to make it a lot better

  • Loading branch information...
1 parent 6f438f2 commit c65f656f50225c04f582eb949e49a443bd195de5 @heinousjay committed Jan 20, 2013
@@ -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;
@@ -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;
}
@@ -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.
@@ -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() {
@@ -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++;
}
@@ -95,9 +95,7 @@
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);
}
}
@@ -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()));
@@ -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());
}

0 comments on commit c65f656

Please sign in to comment.