Debian Codegraph @

src/ch/poole/openinghoursparser/VariableTime.java

raw symbols SCIP
1 package ch.poole.openinghoursparser;
2
3 import java.util.Locale;
4
5 import org.jetbrains.annotations.NotNull;
6
7 /**
8 * Container for objects from the opening_hours specification
9 *
10 * @author Simon Poole
11 *
12 * Copyright (c) 2015 Simon Poole
13 *
14 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
15 * documentation files (the "Software"), to deal in the Software without restriction, including without
16 * limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
17 * Software, and to permit persons to whom the Software is furnished to do so, subject to the following
18 * conditions:
19 *
20 * The above copyright notice and this permission notice shall be included in all copies or substantial portions
21 * of the Software.
22 *
23 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
24 * TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
25 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
26 * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE " OR THE USE OR OTHER
27 * DEALINGS IN THE SOFTWARE.
28 */
29 public class VariableTime extends Element {
30
31 Event event = null;
32 /** offset in minutes */
33 int offset = 0;
34
35 /**
36 * Default constructor
37 */
38 public VariableTime() {
39 // empty
40 }
41
42 /**
43 * Construct a new VariableTime with the same contents
44 *
45 * @param vt the original VariableTime
46 */
47 public VariableTime(@NotNull VariableTime vt) {
48 event = vt.event;
49 offset = vt.offset;
50 }
51
52 @Override
53 public String toString() {
54 StringBuilder b = new StringBuilder();
55 if (event != null) {
56 if (offset != 0) {
57 b.append("(");
58 b.append(event);
59 b.append(offset >= 0 ? '+' : '-');
60 int absOffset = Math.abs(offset);
61 b.append(String.format(Locale.US, "%02d", absOffset / 60));
62 b.append(":");
63 b.append(String.format(Locale.US, "%02d", absOffset % 60));
64 b.append(")");
65 } else {
66 b.append(event);
67 }
68 }
69 return b.toString();
70 }
71
72 @Override
73 public boolean equals(Object other) {
74 if (this == other) {
75 return true;
76 }
77 if (other instanceof VariableTime) {
78 VariableTime o = (VariableTime) other;
79 return Util.equals(event, o.event) && offset == o.offset;
80 }
81 return false;
82 }
83
84 @Override
85 public int hashCode() {
86 int result = 1;
87 result = 37 * result + (event == null ? 0 : event.hashCode());
88 result = 37 * result + offset;
89 return result;
90 }
91
92 /**
93 * @return the event
94 */
95 public Event getEvent() {
96 return event;
97 }
98
99 /**
100 * @return the offset
101 */
102 public int getOffset() {
103 return offset;
104 }
105
106 /**
107 * Set the day the range starts on
108 *
109 * @param event the event to set
110 */
111 public void setEvent(Event event) {
112 this.event = event;
113 }
114
115 /**
116 * Set the day the range starts on
117 *
118 * @param event the event to set
119 */
120 public void setEvent(String event) {
121 this.event = Event.getValue(event);
122 }
123
124 /**
125 * @param offset the offset to set
126 */
127 public void setOffset(int offset) {
128 this.offset = offset;
129 }
130
131 @Override
132 public VariableTime copy() {
133 return new VariableTime(this);
134 }
135 }