Skip to content

Commit

Permalink
Split method chaining
Browse files Browse the repository at this point in the history
  • Loading branch information
Sanghou committed Mar 1, 2023
1 parent 32d0bde commit 155cf3d
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/main/java/subway/sections/Sections.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ public boolean isStationContained(Station station) {
return false;
}

if (Objects.equals(station.getId(), getDownStation().getId())) {
if (getDownStation().equals(station)) {
return true;
}
return sections.stream().anyMatch(s -> Objects.equals(s.getUpStation().getId(), station.getId()));
return sections.stream().anyMatch(s -> s.getUpStation().equals(station));
}
}
4 changes: 2 additions & 2 deletions src/main/java/subway/sections/SectionsValidator.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ static void validateRemoveSection(Sections sections, Station station) {
}

private static boolean isUpStationNotMatchesLastDownStation(Sections sections,Section section) {
return sections.getSize() != 0 && !Objects.equals(sections.getDownStation().getId(), section.getUpStation().getId());
return sections.getSize() != 0 && !sections.getDownStation().equals(section.getUpStation());
}

private static boolean isAlreadyAddedSection(Sections sections, Section section) {
return sections.isStationContained(section.getDownStation()) && isStationNotLastDownStation(sections, section.getDownStation());
}

private static boolean isStationNotLastDownStation(Sections sections, Station station) {
return !Objects.equals(sections.getDownStation().getId(), station.getId());
return !sections.getDownStation().equals(station);
}
}
4 changes: 4 additions & 0 deletions src/main/java/subway/station/Station.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ public String getName() {
return name;
}

public boolean equals(Station station) {
return station != null && id.equals(station.getId());
}

@Override
public String toString() {
return "id : " + id + ", name : " + name;
Expand Down

0 comments on commit 155cf3d

Please sign in to comment.