List of usage examples for org.joda.time LocalDate parse
public static LocalDate parse(String str, DateTimeFormatter formatter)
From source file:de.l3s.content.timex.extracting.utils.DateUtil.java
License:Apache License
/** * // ww w . ja v a 2 s .c o m * @param content * @param url * @param docid * @return * @throws ParseException */ public LocalDate extractDate(String[] content_lines, String url, String docId) throws ParseException { LocalDate extractedUrlDate = null; LocalDate extractedDocIdDate = null; LocalDate extractedContentDate = null; // extract date from content extractedContentDate = extractDateFromContent(content_lines[0]); if (extractedContentDate == null && content_lines.length > 1) extractedContentDate = extractDateFromContent(content_lines[1]); if (extractedContentDate == null) { //extract date from blog url extractedUrlDate = extractDateFromURL(url); //extract date from docid extractedDocIdDate = LocalDate.parse(docId.substring(7, 15), dateFormat); if (extractedUrlDate != null && extractedUrlDate.getMonthOfYear() == extractedDocIdDate.getMonthOfYear() && extractedUrlDate.getYear() == extractedDocIdDate.getYear() && extractedUrlDate.getDayOfMonth() == 15) { return extractedDocIdDate; } //case url contains exact date yyyyMMdd else if (extractedUrlDate != null && extractedUrlDate.getDayOfMonth() != 15) return extractedUrlDate; else if (extractedUrlDate == null) return extractedDocIdDate; else return extractedUrlDate; } else { return extractedContentDate; } }
From source file:de.l3s.content.timex.extracting.utils.DateUtil.java
License:Apache License
/** * /*w w w . j a va2 s . c om*/ * @param url * @return */ public static LocalDate extractDateFromURL(String url) { LocalDate extractedDate = null; if (url.contains("_")) url = url.replace("_", "/"); Pattern p = Pattern.compile(p1); Matcher date = p.matcher(url); if (date.find()) { String[] token = date.group().substring(1).split("/"); String month = token[0]; if (month.contains("January") || month.contains("Jan")) { month = "01"; } else if (month.contains("February") || month.contains("Feb")) { month = "02"; } else if (month.contains("March") || month.contains("Mar")) { month = "03"; } else if (month.contains("April") || month.contains("Apr")) { month = "04"; } else if (month.contains("May")) { month = "05"; } else if (month.contains("June") || month.contains("Jun")) { month = "06"; } else if (month.contains("July") || month.contains("Jul")) { month = "07"; } else if (month.contains("August") || month.contains("Aug")) { month = "08"; } else if (month.contains("September") || month.contains("Sep")) { month = "09"; } else if (month.contains("October") || month.contains("Oct")) { month = "10"; } else if (month.contains("November") || month.contains("Nov")) { month = "11"; } else if (month.contains("December") || month.contains("Dec")) { month = "12"; } extractedDate = LocalDate.parse((token[1] + month + "15").toString(), dateFormat); } else { p = Pattern.compile(p2); date = p.matcher(url); if (date.find()) { String[] token = date.group().substring(1).split("/"); String month = token[0]; if (month.contains("January") || month.contains("Jan")) { month = "01"; } else if (month.contains("February") || month.contains("Feb")) { month = "02"; } else if (month.contains("March") || month.contains("Mar")) { month = "03"; } else if (month.contains("April") || month.contains("Apr")) { month = "04"; } else if (month.contains("May")) { month = "05"; } else if (month.contains("June") || month.contains("Jun")) { month = "06"; } else if (month.contains("July") || month.contains("Jul")) { month = "07"; } else if (month.contains("August") || month.contains("Aug")) { month = "08"; } else if (month.contains("September") || month.contains("Sep")) { month = "09"; } else if (month.contains("October") || month.contains("Oct")) { month = "10"; } else if (month.contains("November") || month.contains("Nov")) { month = "11"; } else if (month.contains("December") || month.contains("Dec")) { month = "12"; } extractedDate = LocalDate.parse((token[1] + month + "15").toString(), dateFormat); } else { p = Pattern.compile(p3); date = p.matcher(url); if (date.find()) { String[] token = date.group().substring(1).split("/"); try { extractedDate = LocalDate.parse((token[1] + token[0] + "15").toString(), dateFormat); } catch (IllegalFieldValueException e) { return null; } } else { p = Pattern.compile(p4); date = p.matcher(url); if (date.find()) { String[] token = date.group().substring(1).split("/"); try { extractedDate = LocalDate.parse((token[1] + "0" + token[0] + "15").toString(), dateFormat); } catch (IllegalFieldValueException e) { return null; } } else { p = Pattern.compile(p7); date = p.matcher(url); if (date.find()) { String[] token = date.group().substring(1).split("/"); try { extractedDate = LocalDate.parse(token[0] + token[1] + token[2], dateFormat); } catch (IllegalFieldValueException e) { return null; } } else { p = Pattern.compile(p6); date = p.matcher(url); if (date.find()) { String[] token = date.group().substring(1).split("/"); try { extractedDate = LocalDate.parse((token[0] + token[1] + "15").toString(), dateFormat); } catch (IllegalFieldValueException e) { return null; } } else { p = Pattern.compile(p5); date = p.matcher(url); if (date.find()) { String[] token = date.group().substring(1).split("/"); try { extractedDate = LocalDate.parse((token[0] + token[1] + "15").toString(), dateFormat); } catch (IllegalFieldValueException e) { return null; } } else { p = Pattern.compile(p8); date = p.matcher(url); if (date.find()) { String[] token = date.group().substring(1).split("_"); try { extractedDate = LocalDate.parse(token[0] + token[1] + token[2], dateFormat); } catch (IllegalFieldValueException e) { return null; } } else { p = Pattern.compile(p9); date = p.matcher(url); if (date.find()) { String[] token = date.group().substring(1).split("_"); try { extractedDate = LocalDate.parse(token[0] + token[1] + "15", dateFormat); } catch (IllegalFieldValueException e) { return null; } } } } } } } } } } return extractedDate; }
From source file:de.l3s.content.timex.extracting.utils.DateUtil.java
License:Apache License
public static Pair<String, String> extractDateFromURL_(String url) { Pair<String, String> extractedDate = null; if (url.contains("_")) url = url.replace("_", "/"); Pattern p = Pattern.compile(p1); Matcher date = p.matcher(url); if (date.find()) { String[] token = date.group().substring(1).split("/"); String month = token[0];/*from ww w . ja v a 2s . c o m*/ if (month.contains("January") || month.contains("Jan")) { month = "01"; } else if (month.contains("February") || month.contains("Feb")) { month = "02"; } else if (month.contains("March") || month.contains("Mar")) { month = "03"; } else if (month.contains("April") || month.contains("Apr")) { month = "04"; } else if (month.contains("May")) { month = "05"; } else if (month.contains("June") || month.contains("Jun")) { month = "06"; } else if (month.contains("July") || month.contains("Jul")) { month = "07"; } else if (month.contains("August") || month.contains("Aug")) { month = "08"; } else if (month.contains("September") || month.contains("Sep")) { month = "09"; } else if (month.contains("October") || month.contains("Oct")) { month = "10"; } else if (month.contains("November") || month.contains("Nov")) { month = "11"; } else if (month.contains("December") || month.contains("Dec")) { month = "12"; } extractedDate = Pair.makePair( LocalDate.parse((token[1] + month + "15").toString(), dateFormat).toString(), "strong"); } else { p = Pattern.compile(p2); date = p.matcher(url); if (date.find()) { String[] token = date.group().substring(1).split("/"); String month = token[0]; if (month.contains("January") || month.contains("Jan")) { month = "01"; } else if (month.contains("February") || month.contains("Feb")) { month = "02"; } else if (month.contains("March") || month.contains("Mar")) { month = "03"; } else if (month.contains("April") || month.contains("Apr")) { month = "04"; } else if (month.contains("May")) { month = "05"; } else if (month.contains("June") || month.contains("Jun")) { month = "06"; } else if (month.contains("July") || month.contains("Jul")) { month = "07"; } else if (month.contains("August") || month.contains("Aug")) { month = "08"; } else if (month.contains("September") || month.contains("Sep")) { month = "09"; } else if (month.contains("October") || month.contains("Oct")) { month = "10"; } else if (month.contains("November") || month.contains("Nov")) { month = "11"; } else if (month.contains("December") || month.contains("Dec")) { month = "12"; } extractedDate = Pair.makePair( LocalDate.parse((token[1] + month + "15").toString(), dateFormat).toString(), "mildly strong"); } else { p = Pattern.compile(p3); date = p.matcher(url); if (date.find()) { String[] token = date.group().substring(1).split("/"); try { extractedDate = Pair.makePair( LocalDate.parse((token[1] + token[0] + "15").toString(), dateFormat).toString(), "mildy strong"); } catch (IllegalFieldValueException e) { return null; } } else { p = Pattern.compile(p4); date = p.matcher(url); if (date.find()) { String[] token = date.group().substring(1).split("/"); try { extractedDate = Pair.makePair(LocalDate .parse((token[1] + "0" + token[0] + "15").toString(), dateFormat).toString(), "mildly strong"); } catch (IllegalFieldValueException e) { return null; } } else { p = Pattern.compile(p7); date = p.matcher(url); if (date.find()) { String[] token = date.group().substring(1).split("/"); try { extractedDate = Pair.makePair( LocalDate.parse(token[0] + token[1] + token[2], dateFormat).toString(), "very strong"); } catch (IllegalFieldValueException e) { return null; } } else { p = Pattern.compile(p6); date = p.matcher(url); if (date.find()) { String[] token = date.group().substring(1).split("/"); try { extractedDate = Pair.makePair(LocalDate .parse((token[0] + token[1] + "15").toString(), dateFormat).toString(), "mildly strong"); } catch (IllegalFieldValueException e) { return null; } } else { p = Pattern.compile(p5); date = p.matcher(url); if (date.find()) { String[] token = date.group().substring(1).split("/"); try { extractedDate = Pair.makePair( LocalDate.parse((token[0] + token[1] + "15").toString(), dateFormat) .toString(), "mildly strong"); } catch (IllegalFieldValueException e) { return null; } } else { p = Pattern.compile(p8); date = p.matcher(url); if (date.find()) { String[] token = date.group().substring(1).split("_"); try { extractedDate = Pair.makePair(LocalDate .parse(token[0] + token[1] + token[2], dateFormat).toString(), "very strong"); } catch (IllegalFieldValueException e) { return null; } } else { p = Pattern.compile(p9); date = p.matcher(url); if (date.find()) { String[] token = date.group().substring(1).split("_"); try { extractedDate = Pair.makePair(LocalDate .parse(token[0] + token[1] + "15", dateFormat).toString(), "mildly strong"); } catch (IllegalFieldValueException e) { return null; } } } } } } } } } } return extractedDate; }
From source file:es.usc.citius.servando.calendula.activities.ConfirmActivity.java
License:Open Source License
private void processIntent() { Intent i = getIntent();/*from w w w.j a v a 2s . co m*/ Long routineId = i.getLongExtra("routine_id", -1); Long scheduleId = i.getLongExtra("schedule_id", -1); String dateStr = i.getStringExtra("date"); String timeStr = i.getStringExtra("schedule_time"); String actionType = i.getIntExtra("actionType", AlarmIntentParams.AUTO) == AlarmIntentParams.USER ? "user" : "auto"; action = i.getStringExtra("action"); position = i.getIntExtra("position", -1); fromNotification = position == -1; if (dateStr != null) { date = LocalDate.parse(dateStr, dateFormatter); } else { // this should never happen, but, just in case, redirect to home and show error Intent intent = new Intent(this, HomePagerActivity.class); intent.putExtra("invalid_notification_error", true); startActivity(intent); finish(); } Log.d("Confirm", timeStr + ", " + dateStr + ", " + routineId + ", " + scheduleId + ", " + date); if (routineId != -1) { isRoutine = true; routine = Routine.findById(routineId); time = routine.time(); patient = routine.patient(); } else { time = LocalTime.parse(timeStr, timeFormatter); schedule = Schedule.findById(scheduleId); patient = schedule.patient(); } }
From source file:es.usc.citius.servando.calendula.activities.SummaryCalendarActivity.java
License:Open Source License
private void setupCalendar() { calendar = (CalendarPickerView) findViewById(R.id.calendar_view); calendar.setVerticalScrollBarEnabled(false); RepetitionRule r;/*w w w. jav a2 s .com*/ String rule = getIntent().getStringExtra("rule"); String date = getIntent().getStringExtra("start"); int activeDays = getIntent().getIntExtra("active_days", -1); int restDays = getIntent().getIntExtra("rest_days", -1); LocalDate from = date != null ? LocalDate.parse(date, fmt) : LocalDate.now(); LocalDate to = from.plusMonths(6); if (rule != null) { r = new RepetitionRule(rule); List<DateTime> dates = r.occurrencesBetween(from.toDateTimeAtStartOfDay(), to.toDateTimeAtStartOfDay(), from.toDateTimeAtStartOfDay()); Set<Date> hdates = new HashSet<>(); for (DateTime d : dates) hdates.add(d.toDate()); List<CalendarCellDecorator> decorators = new ArrayList<>(); DateValue v = r.iCalRule().getUntil(); Date start = date != null ? from.toDate() : null; Date end = v != null ? new LocalDate(v.year(), v.month(), v.day()).toDate() : null; decorators.add(new HighlightDecorator(new ArrayList<>(hdates), start, end, color)); calendar.setDecorators(decorators); } else if (activeDays > 0 && restDays > 0) { List<Date> hdates = new ArrayList<>(); LocalDate d = from.plusDays(0); // copy while (d.isBefore(to)) { if (ScheduleHelper.cycleEnabledForDate(d, from, activeDays, restDays)) { hdates.add(d.toDate()); } d = d.plusDays(1); } List<CalendarCellDecorator> decorators = new ArrayList<>(); //DateValue v = r.iCalRule().getUntil(); //Date start = date != null ? from.toDate() : null; //Date end = v != null ? new LocalDate(v.year(), v.month(), v.day()).toDate() : null; decorators.add(new HighlightDecorator(hdates, from.toDate(), to.toDate(), color)); calendar.setDecorators(decorators); } calendar.init(from.toDate(), to.toDate()) .setShortWeekdays(getResources().getStringArray(R.array.calendar_weekday_names)); }
From source file:eu.edisonproject.classification.prepare.controller.DataPrepare.java
License:Apache License
private LocalDate getCreationDate(File file) { Path p = Paths.get(file.getAbsolutePath()); BasicFileAttributes attr = null; try {/*from ww w . j a va 2 s.com*/ attr = Files.readAttributes(p, BasicFileAttributes.class); } catch (IOException ex) { Logger.getLogger(Text2Avro.class.getName()).log(Level.SEVERE, null, ex); } FileTime ct = attr.creationTime(); DateTimeFormatter formatter; // // LocalDate.parse("2016-09-18T11:40:03.750522Z", formatter); formatter = DateTimeFormat.forPattern("yyyy-MM-dd'T'HH:mm:ss'Z'"); LocalDate date = null; try { date = LocalDate.parse(ct.toString(), formatter); } catch (java.lang.IllegalArgumentException ex) { formatter = DateTimeFormat.forPattern("yyyy-MM-dd'T'HH:mm:ss.SSSSSS'Z'"); date = LocalDate.parse(ct.toString(), formatter); } Logger.getLogger(Text2Avro.class.getName()).log(Level.INFO, "CreationDate: {0}", date); return date; }
From source file:eu.europa.ec.grow.espd.xml.LocalDateAdapter.java
License:EUPL
public static LocalDate unmarshal(String v) { if (v == null || v.trim().isEmpty()) { return null; }/*from w w w.ja v a 2 s. c o m*/ return LocalDate.parse(v, DATE_FORMAT); }
From source file:google.registry.tools.params.LocalDateParameter.java
License:Open Source License
@Override public LocalDate convert(String value) { return LocalDate.parse(value, ISODateTimeFormat.date()); }
From source file:hotelmgmt.UserView.java
/** * The Customer Menu/*from ww w. j a va2s .c om*/ * @param ID the customer's id */ public void customerMenu(int ID) { JFrame frame = new JFrame(); frame.setTitle("Customer Menu"); frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); frame.setLayout(new BorderLayout()); JPanel cusPanel = new JPanel(); list = new JList(listModel); list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); list.setPreferredSize(new Dimension(600, 550)); //cusPanel.add(list); cusPanel.add(new JScrollPane(list)); frame.add(cusPanel, BorderLayout.CENTER); //This is all creating the bottom row of buttons JButton leftButton = new JButton("Left"); leftButton.setVisible(false); leftButton.setPreferredSize(new Dimension(150, 26)); JButton rightButton = new JButton("Right"); rightButton.setVisible(false); rightButton.setPreferredSize(new Dimension(150, 25)); JButton logoutButton = new JButton("Logout"); logoutButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { logout(); listModel.clear(); frame.dispose(); } }); JPanel bottomPanel = new JPanel(); bottomPanel.add(leftButton); bottomPanel.add(logoutButton); frame.add(bottomPanel, BorderLayout.SOUTH); //This is creating the top row of the frame and setting there TextField start, end; start = new TextField("", 20); end = new TextField("", 20); JButton roomsButton = new JButton("Display Rooms"); roomsButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { listModel.clear(); String startd = checkDate(start.getText()); String endd = checkDate(end.getText()); if (startd != "" && endd != "") { LocalDate startdate = LocalDate.parse(startd, DateTimeFormat.forPattern("MM/dd/yyyy")); LocalDate enddate = LocalDate.parse(endd, DateTimeFormat.forPattern("MM/dd/yyyy")); int numdays = Days.daysBetween(startdate, enddate).getDays(); if (numdays <= 0) speakError("Check out date must be after check in date"); else hotel.displayRoomsAvailable(startdate, enddate); leftButton.setText("Reserve Room"); leftButton.setVisible(true); for (ActionListener al : leftButton.getActionListeners()) leftButton.removeActionListener(al); leftButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { try { //Note here how to parse a string //This line will find a string and return the position of first character int priceindex = list.getSelectedValue().indexOf("Price:"); //String.substring(first, last) creates a substring from first position to the last position hotel.bookRoom(true, ID, list.getSelectedValue().substring(11, priceindex - 2), startdate, enddate); listModel.clear(); hotel.displayRoomsAvailable(startdate, enddate); } catch (NullPointerException error) { speakError("Error: please select a room"); } } }); } } }); JButton reserveButton = new JButton("Display Reservations"); reserveButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { listModel.clear(); hotel.displayCustomerBalance(ID); leftButton.setText("Delete Reservation"); leftButton.setVisible(true); for (ActionListener al : leftButton.getActionListeners()) leftButton.removeActionListener(al); leftButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { System.out.println(list.getSelectedIndex()); hotel.removeBookRoom(ID, list.getSelectedIndex()); listModel.clear(); hotel.displayCustomerBalance(ID); } }); } }); JPanel buttonPanel = new JPanel(); buttonPanel.add(roomsButton); buttonPanel.add(reserveButton); JLabel startLabel = new JLabel("Start Date: "); buttonPanel.add(startLabel); buttonPanel.add(start); JLabel endLabel = new JLabel("End Date: "); buttonPanel.add(endLabel); buttonPanel.add(end); frame.add(buttonPanel, BorderLayout.NORTH); //Setting some final settings for the frame itself frame.setPreferredSize(new Dimension(800, 600)); frame.pack(); frame.setVisible(true); frame.addWindowListener(new WindowAdapter() { @Override public void windowClosing(WindowEvent event) { logout(); listModel.clear(); frame.dispose(); } }); }
From source file:hotelmgmt.UserView.java
/** * The Employee Menu//from w w w . j a v a2 s .co m */ public void employeeMenu() { JFrame frame = new JFrame(); frame.setTitle("Employee Menu"); frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); frame.setLayout(new BorderLayout()); JPanel empPanel = new JPanel(); list = new JList(listModel); list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); list.setPreferredSize(new Dimension(600, 550)); //empPanel.add(list); empPanel.add(new JScrollPane(list)); frame.add(empPanel, BorderLayout.CENTER); TextField name; name = new TextField("", 20); JLabel nameLabel = new JLabel(" Customer Name: "); nameLabel.setVisible(true); name.setVisible(true); TextField start, end; start = new TextField("", 15); end = new TextField("", 15); JButton leftButton = new JButton("Left"); leftButton.setVisible(false); JButton blankButton = new JButton("Blank"); blankButton.setVisible(false); JButton logoutButton = new JButton("Logout"); JButton checkInButton = new JButton("Check In"); JButton checkOutButton = new JButton("Check Out"); JButton roomsButton = new JButton("Display Rooms"); checkInButton.setVisible(false); checkOutButton.setVisible(false); JButton displayCustomersButton = new JButton("Display All Customers"); JButton displayAllReservationsButton = new JButton("Display All Reservations"); JButton reserveButton = new JButton("Display Reservations"); reserveButton.setPreferredSize(new Dimension(150, 26)); JButton addcustomerButton = new JButton("Add Customer"); JButton editCustomerButton = new JButton("Edit Customer"); JButton deleteCustomerButton = new JButton("Delete Customer"); editCustomerButton.setVisible(false); deleteCustomerButton.setVisible(false); JPanel bottomPanel = new JPanel(); bottomPanel.add(displayCustomersButton); bottomPanel.add(displayAllReservationsButton); bottomPanel.add(addcustomerButton); bottomPanel.add(logoutButton); frame.add(bottomPanel, BorderLayout.SOUTH); JPanel buttonPanel = new JPanel(); buttonPanel.setLayout(new GridLayout(0, 6, 2, 10)); buttonPanel.add(roomsButton); buttonPanel.add(reserveButton); buttonPanel.add(leftButton); buttonPanel.add(blankButton); buttonPanel.add(checkInButton); buttonPanel.add(checkOutButton); JLabel startLabel = new JLabel(" Start Date:"); buttonPanel.add(startLabel); buttonPanel.add(start); JLabel endLabel = new JLabel(" End Date:"); buttonPanel.add(endLabel); buttonPanel.add(end); buttonPanel.add(nameLabel); buttonPanel.add(name); buttonPanel.add(editCustomerButton); buttonPanel.add(deleteCustomerButton); frame.add(buttonPanel, BorderLayout.NORTH); addcustomerButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { editCustomerButton.setVisible(false); deleteCustomerButton.setVisible(false); addEmployeeorCustomer(false, true); } }); logoutButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { logout(); listModel.clear(); frame.dispose(); } }); displayAllReservationsButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { editCustomerButton.setVisible(false); deleteCustomerButton.setVisible(false); listModel.clear(); hotel.displayReservations(); } }); displayCustomersButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { editCustomerButton.setVisible(true); deleteCustomerButton.setVisible(true); listModel.clear(); hotel.displayCusList(); } }); editCustomerButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { // editPerson(false, true); EditCustomer edCus = new EditCustomer(hotel); edCus.setVisible(true); } }); deleteCustomerButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { try { int idIndex = list.getSelectedValue().indexOf("ID:"); int paymentIndex = list.getSelectedValue().indexOf("Payment"); String cusId = list.getSelectedValue().substring(idIndex + 4, paymentIndex - 1); hotel.deleteCustomerManual(Integer.parseInt(cusId)); listModel.clear(); } catch (NullPointerException error) { speakError(error.toString()); } catch (StringIndexOutOfBoundsException error) { speakError(error.toString()); } } }); roomsButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { editCustomerButton.setVisible(false); deleteCustomerButton.setVisible(false); listModel.clear(); checkOutButton.setVisible(false); String startd = checkDate(start.getText()); String endd = checkDate(end.getText()); if (startd != "" && endd != "") { LocalDate startdate = LocalDate.parse(startd, DateTimeFormat.forPattern("MM/dd/yyyy")); LocalDate enddate = LocalDate.parse(endd, DateTimeFormat.forPattern("MM/dd/yyyy")); int numdays = Days.daysBetween(startdate, enddate).getDays(); if (numdays <= 0) speakError("Check out date must be after check in date"); else hotel.displayRoomsAvailable(startdate, enddate); checkInButton.setVisible(true); leftButton.setText("Reserve Room"); leftButton.setVisible(true); for (ActionListener al : leftButton.getActionListeners()) leftButton.removeActionListener(al); leftButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { try { int priceindex = list.getSelectedValue().indexOf("Price:"); int ID = -1; String username = name.getText(); if (hotel.findCustomer(username) > 0) { ID = hotel.findCustomer(username); hotel.bookRoom(true, ID, list.getSelectedValue().substring(11, priceindex - 2), startdate, enddate); listModel.clear(); hotel.displayRoomsAvailable(startdate, enddate); } else { hotel.displayCusList(); idFrame(false, true, false, false, false, priceindex, startdate, enddate, "noType"); } } catch (NullPointerException error) { speakError("Error"); } } }); for (ActionListener al : checkInButton.getActionListeners()) checkInButton.removeActionListener(al); checkInButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { try { int priceindex = list.getSelectedValue().indexOf("Price:"); int ID = -1; String username = name.getText(); if (hotel.findCustomer(username) > 0) { ID = hotel.findCustomer(username); hotel.bookRoom(true, ID, list.getSelectedValue().substring(11, priceindex - 2), startdate, enddate); hotel.bookRoom(false, ID, list.getSelectedValue().substring(11, priceindex - 2), startdate, enddate); listModel.clear(); hotel.displayRoomsAvailable(startdate, enddate); } else { hotel.displayCusList(); idFrame(false, false, false, true, false, priceindex, startdate, enddate, "noType"); } } catch (NullPointerException error) { speakError("Error"); } } }); } } }); reserveButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { editCustomerButton.setVisible(false); deleteCustomerButton.setVisible(false); listModel.clear(); nameLabel.setVisible(true); name.setVisible(true); checkInButton.setVisible(false); checkOutButton.setVisible(true); for (ActionListener al : checkInButton.getActionListeners()) checkInButton.removeActionListener(al); String username = name.getText(); if (username != " ") { if (hotel.findCustomer(username) > 0) { int ID = hotel.findCustomer(username); hotel.displayCustomerBalance(ID); } else { hotel.displayCusList(); String empty = "03/01/2015"; LocalDate emptydate = LocalDate.parse(empty, DateTimeFormat.forPattern("MM/dd/yyyy")); idFrame(true, false, false, false, false, 0, emptydate, emptydate, "noType"); } } else speakError("Enter a customer name"); leftButton.setText("Delete Reservation"); leftButton.setVisible(true); for (ActionListener al : leftButton.getActionListeners()) leftButton.removeActionListener(al); leftButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { System.out.println(list.getSelectedIndex()); String username = name.getText(); if (hotel.findCustomer(username) > 0) { int ID = hotel.findCustomer(username); hotel.removeBookRoom(ID, list.getSelectedIndex()); listModel.clear(); //hotel.displayCustomerBalance(ID); } else { hotel.removeBookRoom(customerID, list.getSelectedIndex()); listModel.clear(); } } }); checkOutButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { System.out.println(list.getSelectedIndex()); String username = name.getText(); if (hotel.findCustomer(username) > 0) { int ID = hotel.findCustomer(username); hotel.removeBookRoom(ID, list.getSelectedIndex()); listModel.clear(); //hotel.displayCustomerBalance(ID); } else { hotel.removeBookRoom(customerID, list.getSelectedIndex()); listModel.clear(); } } }); checkInButton.setVisible(true); for (ActionListener al : checkInButton.getActionListeners()) checkInButton.removeActionListener(al); checkInButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { try { System.out.println(list.getSelectedIndex()); String username = name.getText(); int startIndex = list.getSelectedValue().indexOf("Start:"); int endIndex = list.getSelectedValue().indexOf("End:"); int typeIndex = list.getSelectedValue().indexOf("Type:"); int balanceIndex = list.getSelectedValue().indexOf("Balance:"); String startString = list.getSelectedValue().substring(startIndex + 7, endIndex - 1); LocalDate startdate = LocalDate.parse(startString, DateTimeFormat.forPattern("yyyy-MM-dd")); String endString = list.getSelectedValue().substring(endIndex + 5, endIndex + 15); LocalDate enddate = LocalDate.parse(endString, DateTimeFormat.forPattern("yyyy-MM-dd")); String type = list.getSelectedValue().substring(typeIndex + 6, balanceIndex - 4); if (hotel.findCustomer(username) > 0) { int ID = hotel.findCustomer(username); hotel.bookRoom(false, ID, type, startdate, enddate); listModel.clear(); hotel.displayCustomerBalance(ID); } else { hotel.displayCusList(); idFrame(false, false, false, false, true, 0, startdate, enddate, type); } } catch (NullPointerException error) { speakError("Error"); } } }); } }); frame.setPreferredSize(new Dimension(950, 600)); frame.pack(); frame.setVisible(true); frame.addWindowListener(new WindowAdapter() { @Override public void windowClosing(WindowEvent event) { logout(); listModel.clear(); frame.dispose(); } }); }