| 1 | /* This file is part of the project "Hilbert II" - http://www.qedeq.org |
| 2 | * |
| 3 | * Copyright 2000-2014, Michael Meyling <mime@qedeq.org>. |
| 4 | * |
| 5 | * "Hilbert II" is free software; you can redistribute |
| 6 | * it and/or modify it under the terms of the GNU General Public |
| 7 | * License as published by the Free Software Foundation; either |
| 8 | * version 2 of the License, or (at your option) any later version. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | */ |
| 15 | |
| 16 | package org.qedeq.base.utility; |
| 17 | |
| 18 | /** |
| 19 | * An object of this class represents a number, that could be |
| 20 | * compared and increased. |
| 21 | * |
| 22 | * @author Michael Meyling |
| 23 | */ |
| 24 | public final class Enumerator { |
| 25 | |
| 26 | /** The plain number. */ |
| 27 | private int number; |
| 28 | |
| 29 | /** |
| 30 | * Constructs an object with 0 as start number. |
| 31 | */ |
| 32 | public Enumerator() { |
| 33 | number = 0; |
| 34 | } |
| 35 | |
| 36 | /** |
| 37 | * Constructs an object with given start number. |
| 38 | * |
| 39 | * @param number Start value. |
| 40 | */ |
| 41 | public Enumerator(final int number) { |
| 42 | this.number = number; |
| 43 | } |
| 44 | |
| 45 | /** |
| 46 | * Gets current number. |
| 47 | * |
| 48 | * @return Current number. |
| 49 | */ |
| 50 | public final int getNumber() { |
| 51 | return number; |
| 52 | } |
| 53 | |
| 54 | /** |
| 55 | * Reset counter to zero. |
| 56 | */ |
| 57 | public final void reset() { |
| 58 | number = 0; |
| 59 | } |
| 60 | |
| 61 | /** |
| 62 | * Increases current number by one. |
| 63 | */ |
| 64 | public final void increaseNumber() { |
| 65 | number++; |
| 66 | } |
| 67 | |
| 68 | public final boolean equals(final Object object) { |
| 69 | if (object == null || !(object instanceof Enumerator)) { |
| 70 | return false; |
| 71 | } |
| 72 | return getNumber() == ((Enumerator) object).getNumber(); |
| 73 | } |
| 74 | |
| 75 | public final int hashCode() { |
| 76 | return number; |
| 77 | } |
| 78 | |
| 79 | /** |
| 80 | * Return number in <code>String</code> format. |
| 81 | * |
| 82 | * @return Number as <code>String</code>. |
| 83 | */ |
| 84 | public final String toString() { |
| 85 | return Integer.toString(number); |
| 86 | } |
| 87 | |
| 88 | } |