@Test public void testParse() throws IOException { LunchParser lp = LunchParser.getInstance(); lp.parse(); Assert.assertTrue(lp.mensaList.size()==4); Assert.assertTrue(lp.mensaList.get(0).getLunchOffers().size()>0); }
public void parse() throws IOException { mensaList = new ArrayList<>(); URL mensaUrl = new URL("http: URLConnection connection = mensaUrl.openConnection(); org.jsoup.nodes.Document mensaDoc = Jsoup.parse(connection.getInputStream(),"UTF-8","http: int i=0; for (Element mensaElement: mensaDoc.children().select("mensa > name")) { String mensaName = mensaElement.text(); mensaList.add(new Mensa(mensaName, new ArrayList<LunchOffer>())); for (Element lunchOffer: mensaElement.parent().children().select("theke > gericht")) { Lunch lunch; String date = lunchOffer.children().select("datum").text(); String lunchOfferName = ""; String foodAdditives = ""; boolean isMensaVital = lunchOffer.parent().select("name").text().contains("Mensa Vital"); try { float studentPrice = df.parse(lunchOffer.children().select("preisStudent").text()).floatValue(); float employeePrice = df.parse(lunchOffer.children().select("preisMitarbeiter").text()).floatValue(); float guestPrice = df.parse(lunchOffer.children().select("preisGast").text()).floatValue(); for(Element name: lunchOffer.children().select("name")) { if(name.parent().tagName().equals("gericht")) { lunchOfferName = name.text(); } else { foodAdditives+=name.text()+" "; } } lunch = new Lunch(lunchOfferName, studentPrice, employeePrice, guestPrice, isMensaVital); boolean lunchOfferNotExists = true; for(LunchOffer existentLunchOffers: mensaList.get(i).getLunchOffers()) { if(existentLunchOffers.getMydate().equals(date)) { existentLunchOffers.getLunchList().add(lunch); lunchOfferNotExists=false; break; } } if (lunchOfferNotExists) { ArrayList<Lunch> lunchList = new ArrayList<>(); lunchList.add(lunch); LunchOffer lunchOfferDay = new LunchOffer(date, lunchList); mensaList.get(i).getLunchOffers().add(lunchOfferDay); } } catch (ParseException e) { System.out.println(e.getMessage()); } } i++; } }
LunchParser { public void parse() throws IOException { mensaList = new ArrayList<>(); URL mensaUrl = new URL("http: URLConnection connection = mensaUrl.openConnection(); org.jsoup.nodes.Document mensaDoc = Jsoup.parse(connection.getInputStream(),"UTF-8","http: int i=0; for (Element mensaElement: mensaDoc.children().select("mensa > name")) { String mensaName = mensaElement.text(); mensaList.add(new Mensa(mensaName, new ArrayList<LunchOffer>())); for (Element lunchOffer: mensaElement.parent().children().select("theke > gericht")) { Lunch lunch; String date = lunchOffer.children().select("datum").text(); String lunchOfferName = ""; String foodAdditives = ""; boolean isMensaVital = lunchOffer.parent().select("name").text().contains("Mensa Vital"); try { float studentPrice = df.parse(lunchOffer.children().select("preisStudent").text()).floatValue(); float employeePrice = df.parse(lunchOffer.children().select("preisMitarbeiter").text()).floatValue(); float guestPrice = df.parse(lunchOffer.children().select("preisGast").text()).floatValue(); for(Element name: lunchOffer.children().select("name")) { if(name.parent().tagName().equals("gericht")) { lunchOfferName = name.text(); } else { foodAdditives+=name.text()+" "; } } lunch = new Lunch(lunchOfferName, studentPrice, employeePrice, guestPrice, isMensaVital); boolean lunchOfferNotExists = true; for(LunchOffer existentLunchOffers: mensaList.get(i).getLunchOffers()) { if(existentLunchOffers.getMydate().equals(date)) { existentLunchOffers.getLunchList().add(lunch); lunchOfferNotExists=false; break; } } if (lunchOfferNotExists) { ArrayList<Lunch> lunchList = new ArrayList<>(); lunchList.add(lunch); LunchOffer lunchOfferDay = new LunchOffer(date, lunchList); mensaList.get(i).getLunchOffers().add(lunchOfferDay); } } catch (ParseException e) { System.out.println(e.getMessage()); } } i++; } } }
LunchParser { public void parse() throws IOException { mensaList = new ArrayList<>(); URL mensaUrl = new URL("http: URLConnection connection = mensaUrl.openConnection(); org.jsoup.nodes.Document mensaDoc = Jsoup.parse(connection.getInputStream(),"UTF-8","http: int i=0; for (Element mensaElement: mensaDoc.children().select("mensa > name")) { String mensaName = mensaElement.text(); mensaList.add(new Mensa(mensaName, new ArrayList<LunchOffer>())); for (Element lunchOffer: mensaElement.parent().children().select("theke > gericht")) { Lunch lunch; String date = lunchOffer.children().select("datum").text(); String lunchOfferName = ""; String foodAdditives = ""; boolean isMensaVital = lunchOffer.parent().select("name").text().contains("Mensa Vital"); try { float studentPrice = df.parse(lunchOffer.children().select("preisStudent").text()).floatValue(); float employeePrice = df.parse(lunchOffer.children().select("preisMitarbeiter").text()).floatValue(); float guestPrice = df.parse(lunchOffer.children().select("preisGast").text()).floatValue(); for(Element name: lunchOffer.children().select("name")) { if(name.parent().tagName().equals("gericht")) { lunchOfferName = name.text(); } else { foodAdditives+=name.text()+" "; } } lunch = new Lunch(lunchOfferName, studentPrice, employeePrice, guestPrice, isMensaVital); boolean lunchOfferNotExists = true; for(LunchOffer existentLunchOffers: mensaList.get(i).getLunchOffers()) { if(existentLunchOffers.getMydate().equals(date)) { existentLunchOffers.getLunchList().add(lunch); lunchOfferNotExists=false; break; } } if (lunchOfferNotExists) { ArrayList<Lunch> lunchList = new ArrayList<>(); lunchList.add(lunch); LunchOffer lunchOfferDay = new LunchOffer(date, lunchList); mensaList.get(i).getLunchOffers().add(lunchOfferDay); } } catch (ParseException e) { System.out.println(e.getMessage()); } } i++; } } private  LunchParser(); }
LunchParser { public void parse() throws IOException { mensaList = new ArrayList<>(); URL mensaUrl = new URL("http: URLConnection connection = mensaUrl.openConnection(); org.jsoup.nodes.Document mensaDoc = Jsoup.parse(connection.getInputStream(),"UTF-8","http: int i=0; for (Element mensaElement: mensaDoc.children().select("mensa > name")) { String mensaName = mensaElement.text(); mensaList.add(new Mensa(mensaName, new ArrayList<LunchOffer>())); for (Element lunchOffer: mensaElement.parent().children().select("theke > gericht")) { Lunch lunch; String date = lunchOffer.children().select("datum").text(); String lunchOfferName = ""; String foodAdditives = ""; boolean isMensaVital = lunchOffer.parent().select("name").text().contains("Mensa Vital"); try { float studentPrice = df.parse(lunchOffer.children().select("preisStudent").text()).floatValue(); float employeePrice = df.parse(lunchOffer.children().select("preisMitarbeiter").text()).floatValue(); float guestPrice = df.parse(lunchOffer.children().select("preisGast").text()).floatValue(); for(Element name: lunchOffer.children().select("name")) { if(name.parent().tagName().equals("gericht")) { lunchOfferName = name.text(); } else { foodAdditives+=name.text()+" "; } } lunch = new Lunch(lunchOfferName, studentPrice, employeePrice, guestPrice, isMensaVital); boolean lunchOfferNotExists = true; for(LunchOffer existentLunchOffers: mensaList.get(i).getLunchOffers()) { if(existentLunchOffers.getMydate().equals(date)) { existentLunchOffers.getLunchList().add(lunch); lunchOfferNotExists=false; break; } } if (lunchOfferNotExists) { ArrayList<Lunch> lunchList = new ArrayList<>(); lunchList.add(lunch); LunchOffer lunchOfferDay = new LunchOffer(date, lunchList); mensaList.get(i).getLunchOffers().add(lunchOfferDay); } } catch (ParseException e) { System.out.println(e.getMessage()); } } i++; } } private  LunchParser(); static LunchParser getInstance(); void parse(); ArrayList<LunchOffer> getLunchData(int mensaLocation); List<Mensa> getLunchDataForAllMensas(); }
LunchParser { public void parse() throws IOException { mensaList = new ArrayList<>(); URL mensaUrl = new URL("http: URLConnection connection = mensaUrl.openConnection(); org.jsoup.nodes.Document mensaDoc = Jsoup.parse(connection.getInputStream(),"UTF-8","http: int i=0; for (Element mensaElement: mensaDoc.children().select("mensa > name")) { String mensaName = mensaElement.text(); mensaList.add(new Mensa(mensaName, new ArrayList<LunchOffer>())); for (Element lunchOffer: mensaElement.parent().children().select("theke > gericht")) { Lunch lunch; String date = lunchOffer.children().select("datum").text(); String lunchOfferName = ""; String foodAdditives = ""; boolean isMensaVital = lunchOffer.parent().select("name").text().contains("Mensa Vital"); try { float studentPrice = df.parse(lunchOffer.children().select("preisStudent").text()).floatValue(); float employeePrice = df.parse(lunchOffer.children().select("preisMitarbeiter").text()).floatValue(); float guestPrice = df.parse(lunchOffer.children().select("preisGast").text()).floatValue(); for(Element name: lunchOffer.children().select("name")) { if(name.parent().tagName().equals("gericht")) { lunchOfferName = name.text(); } else { foodAdditives+=name.text()+" "; } } lunch = new Lunch(lunchOfferName, studentPrice, employeePrice, guestPrice, isMensaVital); boolean lunchOfferNotExists = true; for(LunchOffer existentLunchOffers: mensaList.get(i).getLunchOffers()) { if(existentLunchOffers.getMydate().equals(date)) { existentLunchOffers.getLunchList().add(lunch); lunchOfferNotExists=false; break; } } if (lunchOfferNotExists) { ArrayList<Lunch> lunchList = new ArrayList<>(); lunchList.add(lunch); LunchOffer lunchOfferDay = new LunchOffer(date, lunchList); mensaList.get(i).getLunchOffers().add(lunchOfferDay); } } catch (ParseException e) { System.out.println(e.getMessage()); } } i++; } } private  LunchParser(); static LunchParser getInstance(); void parse(); ArrayList<LunchOffer> getLunchData(int mensaLocation); List<Mensa> getLunchDataForAllMensas();  }