Advertisement
Guest User

Untitled

a guest
Jan 19th, 2017
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.14 KB | None | 0 0
  1. //client public class AmazonClient { private InterpreterContext context; public AmazonClient(InterpreterContext context) {this.context = context; } /** * Interprets a string input of the form * movies | books by title | year | name '<string>' */ public String interpret(String expression) {//we need to parse the string to determine which expression to use AbstractExpression exp = null; String[] stringParts = expression.split(" ");String main = stringParts[0];String sub = stringParts[2];//get the query partString query = expression.substring(expression.firstIndexOf("'"), expression.lastIndexOf("'"));if(main.equals("books")){if(sub.equals("title"){ exp = new BookTitleExpression(query);}if(sub.equals("year"){ exp = new BookYearExpression(query);}}else if(main.equals("movie")) {//similar statements to create movie expressions } if(exp != null){exp.interpret(context);} } public static void main(String[] args) {InterpreterContext context = new InterpreterContext("http://aws.amazon.com/");AmazonClient client = new AmazonClient();//run a queryString result = client.interpret("books by author 'John Connolly'");System.out.println(result); }}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement