Question: Java Program to code a Middleware Router. You are asked to design a middleware router that allows you to create new paths and associate them

Java Program to code a Middleware Router.
You are asked to design a middleware router that allows you to create new paths and associate them with different values.
The format of a path is one or more concatenated strings of the form: / followed by one or more lowercase English letters
void addRoute(String path, String result) : Creates a newpathand associates avalue
String callRoute(String path): Returns the value associated withpathor returns-1if the path doesn't exist.
e.g:
Router.addRoute("/bar", "result")
Router.callRoute("/bar")-> output : "result"
Router.addRoute("/foo/bar/aa, "result2")
Router.callRoute("/foo/bar/aa)-> output: "result2"
Follow up 1:
Handle wildcard char e.g *. For example, if addRoute is ("/a/*/b", result3) and someone calls with callRoute("/a/x/y/b") it should return result3.
As the wildcard char will match with "/x/y" part. Expectation was to use a pattern matching library and somehow handle it in addRoute method
Follow up 2:
Handle wildcard char e.g *. For example, if addRoute is addRoute("/foo/bar/xxx/yyy", "result4) and someone calls with callRoute("/foo/*/yyy") it should return result4.
As the wildcard char will match with "/xxx/yyy part.
Consider the following:
1] Use the Design principles and design patterns in the code
2] Write Executable code with Junit Tests and Console Tests.
3] How can we use this code in concurrent environment?

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Finance Questions!