Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.ArrayList;
- import java.util.regex.Matcher;
- import java.util.regex.Pattern;
- public class Driver
- {
- ArrayList dataList = new ArrayList(0);
- public Driver()
- {
- }
- public Driver(ArrayList l)
- {
- dataList = l;
- }
- public ArrayList getData()
- {
- return dataList;
- }
- public void setData(ArrayList l)
- {
- if(dataList != null)
- {
- dataList = l;
- }
- }
- public ArrayList run(ArrayList<String> data)
- {
- OrderForm ordersample = new OrderForm();
- OrderForm last = new OrderForm();
- ReviewForm reviewsample = new ReviewForm();
- ArrayList<String> unproc = new ArrayList<String>(0);
- for(int x = 0; x < data.size(); x++)
- {
- String rfreg = "(.*),?#([0-9]*)";
- Pattern p2 = Pattern.compile(rfreg);
- Matcher m2 = p2.matcher(data.get(x).toString());
- ordersample = new OrderForm();
- if(ordersample.process(data.get(x)))
- {
- last = new OrderForm();
- last.process(data.get(x));
- dataList.add(last);
- }
- else if(data.get(x).startsWith("#"))
- {
- String ireg = "#(\\w*.*),(\\d*\\.\\d*),(\\d*)";
- Pattern p = Pattern.compile(ireg);
- Matcher m = p.matcher(data.get(x));
- if(m.matches())
- {
- String itemname = m.group(1);
- String price = m.group(2);
- String quantity = m.group(3);
- Item thing = new Item(itemname, Double.parseDouble(price), Integer.parseInt(quantity));
- last.addItem(thing);
- dataList.remove(dataList.size()-1);
- dataList.add(last);
- }
- }
- if(m2.matches())
- {
- String rev = m2.group(1);
- String stars = m2.group(2);
- reviewsample.setStars(Integer.parseInt(stars));
- reviewsample.setReview(rev);
- }
- else
- {
- unproc.add(data.get(x).toString());
- }
- }
- //returns unprocessable elements in the list back to the user
- return unproc;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement