-
Notifications
You must be signed in to change notification settings - Fork 0
Feedback #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
github-classroom
wants to merge
2
commits into
feedback
Choose a base branch
from
master
base: feedback
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Feedback #1
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
package com.redi.j2; | ||
|
||
import java.time.LocalDateTime; | ||
|
||
public class Appointment implements Comparable{ | ||
|
||
private String title; | ||
private LocalDateTime date; | ||
private int duration; | ||
private String location; | ||
|
||
public String getTitle() { | ||
return title; | ||
} | ||
|
||
public void setTitle(String title) { | ||
this.title = title; | ||
} | ||
|
||
public LocalDateTime getDate() { | ||
return date; | ||
} | ||
|
||
public void setDate(LocalDateTime date) { | ||
this.date = date; | ||
} | ||
|
||
public int getDuration() { | ||
return duration; | ||
} | ||
|
||
public void setDuration(int duration) { | ||
this.duration = duration; | ||
} | ||
|
||
public String getLocation() { | ||
return location; | ||
} | ||
|
||
public void setLocation(String location) { | ||
this.location = location; | ||
} | ||
|
||
public Appointment(String title, LocalDateTime date, int duration, String location) { | ||
this.title = title; | ||
this.date = date; | ||
this.duration = duration; | ||
this.location = location; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
final StringBuilder sb = new StringBuilder("Appointment{"); | ||
sb.append("title='").append(title).append('\''); | ||
sb.append(", date=").append(date); | ||
sb.append(", duration=").append(duration); | ||
sb.append(", location='").append(location).append('\''); | ||
sb.append('}'); | ||
return sb.toString(); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (o == null || getClass() != o.getClass()) return false; | ||
|
||
Appointment that = (Appointment) o; | ||
|
||
if (getDuration() != that.getDuration()) return false; | ||
if (getTitle() != null ? !getTitle().equals(that.getTitle()) : that.getTitle() != null) return false; | ||
if (getDate() != null ? !getDate().equals(that.getDate()) : that.getDate() != null) return false; | ||
return getLocation() != null ? getLocation().equals(that.getLocation()) : that.getLocation() == null; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
int result = getTitle() != null ? getTitle().hashCode() : 0; | ||
result = 31 * result + (getDate() != null ? getDate().hashCode() : 0); | ||
result = 31 * result + getDuration(); | ||
result = 31 * result + (getLocation() != null ? getLocation().hashCode() : 0); | ||
return result; | ||
} | ||
|
||
@Override | ||
public int compareTo(Object o) { | ||
if (! (o instanceof Appointment)) return -1; | ||
return date.compareTo(((Appointment)o).getDate()); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package com.redi.j2; | ||
|
||
import java.util.*; | ||
|
||
public class Calendar { | ||
|
||
private String owner; | ||
private List<Appointment> appointments; | ||
|
||
public String getOwner() { | ||
return owner; | ||
} | ||
|
||
public void setOwner(String owner) { | ||
this.owner = owner; | ||
} | ||
|
||
public Calendar(String owner) { | ||
this.owner = owner; | ||
this.appointments = new ArrayList<>(); | ||
} | ||
|
||
public void addAppointment(Appointment a) { | ||
if (appointments.contains(a) == false) { | ||
appointments.add(a); | ||
} | ||
} | ||
|
||
public List<Appointment> getAllAppointments() { | ||
Collections.sort(appointments); | ||
return appointments; | ||
} | ||
|
||
public List<Appointment> getAppointmentsOrderByTitle() { | ||
appointments.sort(Comparator.comparing(Appointment::getTitle)); | ||
return appointments; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (o == null || getClass() != o.getClass()) return false; | ||
|
||
Calendar calendar = (Calendar) o; | ||
|
||
if (getOwner() != null ? !getOwner().equals(calendar.getOwner()) : calendar.getOwner() != null) return false; | ||
return Objects.equals(appointments, calendar.appointments); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
int result = getOwner() != null ? getOwner().hashCode() : 0; | ||
result = 31 * result + (appointments != null ? appointments.hashCode() : 0); | ||
return result; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
final StringBuilder sb = new StringBuilder("Calendar{"); | ||
sb.append("owner='").append(owner).append('\''); | ||
sb.append(", appointments=").append(appointments); | ||
sb.append('}'); | ||
return sb.toString(); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package com.redi.j2; | ||
|
||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
public class CalendarService { | ||
|
||
private List<Calendar> calendars; | ||
|
||
public CalendarService() { | ||
calendars = new ArrayList<>(); | ||
} | ||
|
||
public void addCalendar(Calendar c) { | ||
if (calendars.contains(c)) return; | ||
calendars.add(c); | ||
} | ||
|
||
public List<Appointment> getAppointmentsOrderByDateAndOwner() { | ||
|
||
Map<Appointment, String> ownerMapping = new HashMap<>(); | ||
List<Appointment> allAppointments = new ArrayList<>(); | ||
|
||
for (Calendar c : calendars) { | ||
for (Appointment a: c.getAllAppointments()) { | ||
ownerMapping.put(a, c.getOwner()); | ||
allAppointments.add(a); | ||
} | ||
} | ||
|
||
allAppointments.sort((o1, o2) -> { | ||
return o1.getDate().compareTo(o2.getDate()) * 10 + | ||
ownerMapping.get(o1).compareTo(ownerMapping.get(o2)); | ||
}); | ||
|
||
return allAppointments; | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Solution would be much better using a Map, which will be shown in future classes