MultiHashKey
This commit is contained in:
@@ -29,7 +29,7 @@ class MultiHashKeys {
|
|||||||
for (int i = 0; i < chars.length; i++) {
|
for (int i = 0; i < chars.length; i++) {
|
||||||
char ch = chars[i];
|
char ch = chars[i];
|
||||||
if (ch == '{') {
|
if (ch == '{') {
|
||||||
if (paraming || i < 1) {
|
if (paraming) {
|
||||||
throw new RedkaleException(MultiHashKey.class.getSimpleName() + " parse error, key: " + key);
|
throw new RedkaleException(MultiHashKey.class.getSimpleName() + " parse error, key: " + key);
|
||||||
}
|
}
|
||||||
if (last == '#') {
|
if (last == '#') {
|
||||||
@@ -43,15 +43,12 @@ class MultiHashKeys {
|
|||||||
sb.deleteCharAt(sb.length() - 1);
|
sb.deleteCharAt(sb.length() - 1);
|
||||||
sb.append(ch);
|
sb.append(ch);
|
||||||
} else {
|
} else {
|
||||||
throw new RedkaleException(MultiHashKey.class.getSimpleName() + " parse error, key: " + key);
|
sb.append(ch);
|
||||||
}
|
}
|
||||||
} else if (last == '\\' && ch == '}') {
|
} else if (ch == '}' && last == '\\') {
|
||||||
sb.deleteCharAt(sb.length() - 1);
|
sb.deleteCharAt(sb.length() - 1);
|
||||||
sb.append(ch);
|
sb.append(ch);
|
||||||
} else if (ch == '}') {
|
} else if (ch == '}' && paraming) {
|
||||||
if (!paraming) {
|
|
||||||
throw new RedkaleException(MultiHashKey.class.getSimpleName() + " parse error, key: " + key);
|
|
||||||
}
|
|
||||||
String name = sb.toString();
|
String name = sb.toString();
|
||||||
sb.delete(0, sb.length());
|
sb.delete(0, sb.length());
|
||||||
if (name.indexOf('.') > 0) {
|
if (name.indexOf('.') > 0) {
|
||||||
@@ -65,6 +62,9 @@ class MultiHashKeys {
|
|||||||
}
|
}
|
||||||
last = ch;
|
last = ch;
|
||||||
}
|
}
|
||||||
|
if (sb.length() > 0) {
|
||||||
|
list.add(new StringKey(sb.toString()));
|
||||||
|
}
|
||||||
if (list.size() == 1) {
|
if (list.size() == 1) {
|
||||||
return list.get(0);
|
return list.get(0);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -86,7 +86,11 @@ public class MultiHashKeyTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void run6() throws Exception {
|
public void run6() throws Exception {
|
||||||
|
String[] paramNames = {"map", "id"};
|
||||||
|
String key = "{key_#{map.name}_#{id}_#{map.index}}";
|
||||||
|
MultiHashKey rs = MultiHashKey.create(paramNames, key);
|
||||||
|
Map<String, Object> map = Utility.ofMap("name", "me", "index", 123);
|
||||||
|
Assertions.assertEquals("{key_me_123_123}", rs.keyFor(map, 123));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
Reference in New Issue
Block a user