所以我正在使用票务系统,但由于某种原因,我似乎无法在我的活动中获得一个位置。
TicketingSystem类有一些我将数据添加到的哈希图。 它还有阅读器方法,我遇到的问题是readEvents()。
public TicketSystem() {
queueService = new QueueService();
users = new HashMap<>();
locations = new HashMap<>();
events = new HashMap<>();
readData();
}
public void addLocation(Venue location) {
locations.put(location.getId(), location);
}
public void addEvent(Event event) {
events.put(event.getId(), event);
}
public static Event getEvent(String eventId) {
return events.get(eventId);
}
public static Venue getLocation(String locationId) {
return locations.get(locationId);
}
public void readLocations() {
try (BufferedReader reader = new BufferedReader(new FileReader("venuedata.txt"))) {
String line = "";
VenueMapper mapper = new VenueMapper();
while ((line = reader.readLine()) != null) {
Venue venue = mapper.map(line.split(";"));
locations.put(venue.getId(), venue);
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
public void readEvents() {
try (BufferedReader reader = new BufferedReader(new FileReader("eventdata.txt"))) {
String line = "";
EventMapper mapper = new EventMapper();
while ((line = reader.readLine()) != null) {
Event event = mapper.map(line.split(";"));
events.put(event.getId(), event);
reader.readLine();
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
public void readData() {
readEvents();
readLocations();
}
使用EventMapper类通过TicketingSystem类从文本文件中读取数据&#34;;&#34; data [5]是我的locationId。
@Override
public Event map(String[] data) {
String dateAndTime = data[1];
StringBuilder date = new StringBuilder(dateAndTime.substring(0, 8));
StringBuilder time = new StringBuilder(dateAndTime.substring(8));
return new Event(data[0], data[2], date.toString(), time.toString(), data[3], Double.parseDouble(data[4]), data[5]);
}
}
这是我的事件类,它包含我使用在EventMapper类中返回事件的构造函数
public Event(String id, String name, String date, String time, String description,
double price, String locationId) {
this(name, LocalDate.parse(date, DateTimeFormatter.ofPattern("ddMMyyyy")),
LocalTime.parse(time, DateTimeFormatter.ofPattern("HHmm")), description, price);
this.id = id;
*setLocation(TicketSystem.getLocation(locationId));*
}
public void setLocation(Venue location) {
this.location = location;
}
每次我在位置列表中调试那些数据时,但出于某种原因,我的事件并没有找到我想要获取的位置。