]> git.basschouten.com Git - openhab-addons.git/blob
0e3863180934c9be44bdcb2c87564ea1e169e97e
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2020 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
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
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.binding.icalendar.internal.logic;
14
15 import java.time.Instant;
16 import java.util.ArrayList;
17 import java.util.List;
18
19 import org.eclipse.jdt.annotation.NonNullByDefault;
20 import org.eclipse.jdt.annotation.Nullable;
21
22 /**
23  * A single event.
24  *
25  * @author Michael Wodniok - Initial contribution
26  * @author Andrew Fiddian-Green - Added support for event description
27  */
28 @NonNullByDefault
29 public class 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;
34
35     public Event(String title, Instant start, Instant end, String description) {
36         this.title = title;
37         this.start = start;
38         this.end = end;
39
40         if (description.isEmpty()) {
41             return;
42         }
43
44         String[] lines = description.replace("<p>", "").replace("</p>", "\n").split("\n");
45         for (String line : lines) {
46             CommandTag tag = CommandTag.createCommandTag(line);
47             if (tag != null) {
48                 commandTags.add(tag);
49             }
50         }
51     }
52
53     @Override
54     public boolean equals(@Nullable Object other) {
55         if (other == null || other.getClass() != this.getClass()) {
56             return false;
57         }
58         final Event otherEvent = (Event) other;
59         return (this.title.equals(otherEvent.title) && this.start.equals(otherEvent.start)
60                 && this.end.equals(otherEvent.end));
61     }
62 }