2 * Copyright (c) 2010-2024 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
7 * This program and the accompanying materials are made available under the
8 * terms of the Eclipse Public License 2.0 which is available at
9 * http://www.eclipse.org/legal/epl-2.0
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.icalendar.internal.logic;
15 import java.time.Instant;
16 import java.util.ArrayList;
17 import java.util.List;
19 import org.eclipse.jdt.annotation.NonNullByDefault;
20 import org.eclipse.jdt.annotation.Nullable;
25 * @author Michael Wodniok - Initial contribution
26 * @author Andrew Fiddian-Green - Added support for event description
29 public class Event implements Comparable<Event> {
30 public final List<CommandTag> commandTags = new ArrayList<CommandTag>();
31 public final Instant end;
32 public final Instant start;
33 public final String title;
35 public Event(String title, Instant start, Instant end, String description) {
40 if (description.isEmpty()) {
44 String[] lines = description.replace("<p>", "").replace("</p>", "\n").split("\n");
45 for (String line : lines) {
46 CommandTag tag = CommandTag.createCommandTag(line);
54 public String toString() {
55 String[] tagStrings = new String[this.commandTags.size()];
56 for (int i = 0; i < tagStrings.length; i++) {
57 tagStrings[i] = this.commandTags.get(i).toString();
59 return "Event(title: " + this.title + ", start: " + this.start.toString() + ", end: " + this.end.toString()
60 + ", commandTags: List(" + String.join(", ", tagStrings) + ")";
64 public boolean equals(@Nullable Object other) {
65 if (other == null || other.getClass() != this.getClass()) {
68 final Event otherEvent = (Event) other;
69 return (this.title.equals(otherEvent.title) && this.start.equals(otherEvent.start)
70 && this.end.equals(otherEvent.end));
74 public int compareTo(Event o) {
75 return start.compareTo(o.start);