| 1 | package ch.poole.openinghoursparser; |
| 2 | |
| 3 | /** |
| 4 | * Container for objects from the opening_hours specification |
| 5 | * |
| 6 | * @author Simon Poole |
| 7 | * |
| 8 | * Copyright (c) 2015 Simon Poole |
| 9 | * |
| 10 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated |
| 11 | * documentation files (the "Software"), to deal in the Software without restriction, including without |
| 12 | * limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the |
| 13 | * Software, and to permit persons to whom the Software is furnished to do so, subject to the following |
| 14 | * conditions: |
| 15 | * |
| 16 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions |
| 17 | * of the Software. |
| 18 | * |
| 19 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED |
| 20 | * TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 21 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF |
| 22 | * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE " OR THE USE OR OTHER |
| 23 | * DEALINGS IN THE SOFTWARE. |
| 24 | */ |
| 25 | public class Nth extends Element { |
| 26 | public static final int INVALID_NTH = Integer.MIN_VALUE; |
| 27 | int startNth = INVALID_NTH; |
| 28 | int endNth = INVALID_NTH; |
| 29 | |
| 30 | /** |
| 31 | * Default constructor |
| 32 | */ |
| 33 | public Nth() { |
| 34 | // empty |
| 35 | } |
| 36 | |
| 37 | /** |
| 38 | * Construct a new Nth with the same content |
| 39 | * |
| 40 | * @param n original Nth |
| 41 | */ |
| 42 | public Nth(Nth n) { |
| 43 | startNth = n.startNth; |
| 44 | endNth = n.endNth; |
| 45 | } |
| 46 | |
| 47 | @Override |
| 48 | public String toString() { |
| 49 | StringBuilder b = new StringBuilder(); |
| 50 | |
| 51 | if (startNth != INVALID_NTH) { |
| 52 | b.append(startNth); |
| 53 | } |
| 54 | if (endNth != INVALID_NTH) { |
| 55 | b.append("-"); |
| 56 | b.append(endNth); |
| 57 | } |
| 58 | return b.toString(); |
| 59 | } |
| 60 | |
| 61 | @Override |
| 62 | public boolean equals(Object other) { |
| 63 | if (this == other) { |
| 64 | return true; |
| 65 | } |
| 66 | if (other instanceof Nth) { |
| 67 | Nth o = (Nth) other; |
| 68 | if (startNth == o.startNth && endNth == o.endNth) { |
| 69 | return true; |
| 70 | } |
| 71 | } |
| 72 | return false; |
| 73 | } |
| 74 | |
| 75 | @Override |
| 76 | public int hashCode() { |
| 77 | int result = 1; |
| 78 | result = 37 * result + startNth; |
| 79 | result = 37 * result + endNth; |
| 80 | return result; |
| 81 | } |
| 82 | |
| 83 | /** |
| 84 | * @return the startNth |
| 85 | */ |
| 86 | public int getStartNth() { |
| 87 | return startNth; |
| 88 | } |
| 89 | |
| 90 | /** |
| 91 | * @return the endNth of Nth.INVALID_NTH if not set/not a range |
| 92 | */ |
| 93 | public int getEndNth() { |
| 94 | return endNth; |
| 95 | } |
| 96 | |
| 97 | /** |
| 98 | * @param startNth the startNth to set |
| 99 | */ |
| 100 | public void setStartNth(int startNth) { |
| 101 | this.startNth = startNth; |
| 102 | } |
| 103 | |
| 104 | /** |
| 105 | * @param endNth the endNth to set |
| 106 | */ |
| 107 | public void setEndNth(int endNth) { |
| 108 | this.endNth = endNth; |
| 109 | } |
| 110 | |
| 111 | @Override |
| 112 | public Nth copy() { |
| 113 | return new Nth(this); |
| 114 | } |
| 115 | } |