static Map<String, String> resolveVariables(String expression, String str) {
      if (expression == null || str == null) return Collections.emptyMap();

      Map<String, String> resolvedVariables = new HashMap<>();
      StringBuilder variableBuilder = new StringBuilder();
      State state = State.TEXT;
      int j = 0;
      int expressionLength = expression.length();

      for (int i = 0; i < expressionLength; i++) {
         char e = expression.charAt(i);

         switch (e) {
            case '{':
               if (state == END_VAR) return Collections.emptyMap();
               state = VAR;
               break;
            case '}':
               if (state != VAR) return Collections.emptyMap();
               state = END_VAR;
               if (i != expressionLength - 1) break;
            default:
               switch (state) {
                  case VAR:
                     variableBuilder.append(e);
                     break;
                  case END_VAR:
                     String replacement;
                     boolean ec = i == expressionLength - 1;
                     if (ec) {
                        replacement = str.substring(j);
                     } else {
                        int k = str.indexOf(e, j);
                        if (k == -1) return Collections.emptyMap();
                        replacement = str.substring(j, str.indexOf(e, j));
                     }
                     resolvedVariables.put(variableBuilder.toString(), replacement);
                     j += replacement.length();
                     if (j == str.length() && ec) return resolvedVariables;
                     variableBuilder.setLength(0);
                     state = TEXT;
                  case TEXT:
                     if (str.charAt(j) != e) return Collections.emptyMap();
                     j++;
               }
         }
      }
      return resolvedVariables;
   }
@Test
   public void testSingleVariable() {
      Map<String, String> res = resolveVariables("{id}", "5435");

      assertEquals(1, res.size());
      assertEquals(res.get("id"), "5435");
   }