| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| ReadingsKey |
|
| 1.8571428571428572;1.857 |
| 1 | /** | |
| 2 | * Distribution License: | |
| 3 | * JSword is free software; you can redistribute it and/or modify it under | |
| 4 | * the terms of the GNU Lesser General Public License, version 2.1 or later | |
| 5 | * as published by the Free Software Foundation. This program is distributed | |
| 6 | * in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even | |
| 7 | * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | |
| 8 | * See the GNU Lesser General Public License for more details. | |
| 9 | * | |
| 10 | * The License is available on the internet at: | |
| 11 | * http://www.gnu.org/copyleft/lgpl.html | |
| 12 | * or by writing to: | |
| 13 | * Free Software Foundation, Inc. | |
| 14 | * 59 Temple Place - Suite 330 | |
| 15 | * Boston, MA 02111-1307, USA | |
| 16 | * | |
| 17 | * © CrossWire Bible Society, 2005 - 2016 | |
| 18 | * | |
| 19 | */ | |
| 20 | package org.crosswire.jsword.book.readings; | |
| 21 | ||
| 22 | import java.text.MessageFormat; | |
| 23 | import java.util.Calendar; | |
| 24 | import java.util.Date; | |
| 25 | ||
| 26 | import org.crosswire.common.icu.DateFormatter; | |
| 27 | import org.crosswire.jsword.passage.DefaultLeafKeyList; | |
| 28 | import org.crosswire.jsword.passage.Key; | |
| 29 | ||
| 30 | /** | |
| 31 | * For a readings dictionary the keys are dates. | |
| 32 | * | |
| 33 | * @see gnu.lgpl.License The GNU Lesser General Public License for details. | |
| 34 | * @author Joe Walker | |
| 35 | * @author DM Smith | |
| 36 | */ | |
| 37 | 0 | public class ReadingsKey extends DefaultLeafKeyList { |
| 38 | /** | |
| 39 | * Simple Constructor. | |
| 40 | * | |
| 41 | * @param text | |
| 42 | * The textual version of the date for these readings in the | |
| 43 | * format "d mmmm" | |
| 44 | * @param osisName | |
| 45 | * The OSIS id of this Key | |
| 46 | * @param parent | |
| 47 | * This Key's parent (or null of this Key has no parent) | |
| 48 | */ | |
| 49 | protected ReadingsKey(String text, String osisName, Key parent) { | |
| 50 | 0 | super(text, osisName, parent); |
| 51 | ||
| 52 | 0 | DateFormatter formatter = DateFormatter.getDateInstance(); |
| 53 | 0 | formatter.setLenient(true); |
| 54 | 0 | date = formatter.parse(text); |
| 55 | 0 | } |
| 56 | ||
| 57 | /** | |
| 58 | * Simple Constructor. | |
| 59 | * | |
| 60 | * @param date | |
| 61 | * The date for this key | |
| 62 | */ | |
| 63 | protected ReadingsKey(Date date) { | |
| 64 | 0 | super(DateFormatter.getDateInstance().format(date), DateFormatter.getSimpleDateInstance("d.MMMM").format(date)); |
| 65 | 0 | this.date = date; |
| 66 | 0 | } |
| 67 | ||
| 68 | @Override | |
| 69 | public boolean equals(Object obj) { | |
| 70 | 0 | if (this == obj) { |
| 71 | 0 | return true; |
| 72 | } | |
| 73 | ||
| 74 | // Since this can not be null | |
| 75 | 0 | if (obj == null) { |
| 76 | 0 | return false; |
| 77 | } | |
| 78 | ||
| 79 | // Check that that is the same as this | |
| 80 | // Don't use instanceof since that breaks inheritance | |
| 81 | 0 | if (!obj.getClass().equals(this.getClass())) { |
| 82 | 0 | return false; |
| 83 | } | |
| 84 | ||
| 85 | // The real bit ... | |
| 86 | 0 | ReadingsKey that = (ReadingsKey) obj; |
| 87 | ||
| 88 | 0 | return getName().equals(that.getName()); |
| 89 | } | |
| 90 | ||
| 91 | @Override | |
| 92 | public int hashCode() { | |
| 93 | 0 | return date.hashCode(); |
| 94 | } | |
| 95 | ||
| 96 | @Override | |
| 97 | public int compareTo(Key obj) { | |
| 98 | 0 | ReadingsKey that = (ReadingsKey) obj; |
| 99 | 0 | return this.date.compareTo(that.date); |
| 100 | } | |
| 101 | ||
| 102 | @Override | |
| 103 | public ReadingsKey clone() { | |
| 104 | 0 | return (ReadingsKey) super.clone(); |
| 105 | } | |
| 106 | ||
| 107 | /** | |
| 108 | * Convert the Gregorian Calendar to a string. | |
| 109 | * | |
| 110 | * @param externalKey | |
| 111 | * @return the internal representation of the key | |
| 112 | */ | |
| 113 | public static String external2internal(Calendar externalKey) { | |
| 114 | 0 | Object[] objs = { |
| 115 | Integer.valueOf(1 + externalKey.get(Calendar.MONTH)), Integer.valueOf(externalKey.get(Calendar.DATE)) | |
| 116 | }; | |
| 117 | 0 | return KEY_FORMAT.format(objs); |
| 118 | ||
| 119 | } | |
| 120 | ||
| 121 | /** | |
| 122 | * The day of the year for the readings | |
| 123 | */ | |
| 124 | private Date date; | |
| 125 | ||
| 126 | /** | |
| 127 | * Date formatter | |
| 128 | */ | |
| 129 | 0 | private static final MessageFormat KEY_FORMAT = new MessageFormat("{0,number,00}.{1,number,00}"); |
| 130 | ||
| 131 | /** | |
| 132 | * Serialization ID | |
| 133 | */ | |
| 134 | private static final long serialVersionUID = -5500401548068844993L; | |
| 135 | } |