1
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
37 public class ReadingsKey extends DefaultLeafKeyList {
38
49 protected ReadingsKey(String text, String osisName, Key parent) {
50 super(text, osisName, parent);
51
52 DateFormatter formatter = DateFormatter.getDateInstance();
53 formatter.setLenient(true);
54 date = formatter.parse(text);
55 }
56
57
63 protected ReadingsKey(Date date) {
64 super(DateFormatter.getDateInstance().format(date), DateFormatter.getSimpleDateInstance("d.MMMM").format(date));
65 this.date = date;
66 }
67
68 @Override
69 public boolean equals(Object obj) {
70 if (this == obj) {
71 return true;
72 }
73
74 if (obj == null) {
76 return false;
77 }
78
79 if (!obj.getClass().equals(this.getClass())) {
82 return false;
83 }
84
85 ReadingsKey that = (ReadingsKey) obj;
87
88 return getName().equals(that.getName());
89 }
90
91 @Override
92 public int hashCode() {
93 return date.hashCode();
94 }
95
96 @Override
97 public int compareTo(Key obj) {
98 ReadingsKey that = (ReadingsKey) obj;
99 return this.date.compareTo(that.date);
100 }
101
102 @Override
103 public ReadingsKey clone() {
104 return (ReadingsKey) super.clone();
105 }
106
107
113 public static String external2internal(Calendar externalKey) {
114 Object[] objs = {
115 Integer.valueOf(1 + externalKey.get(Calendar.MONTH)), Integer.valueOf(externalKey.get(Calendar.DATE))
116 };
117 return KEY_FORMAT.format(objs);
118
119 }
120
121
124 private Date date;
125
126
129 private static final MessageFormat KEY_FORMAT = new MessageFormat("{0,number,00}.{1,number,00}");
130
131
134 private static final long serialVersionUID = -5500401548068844993L;
135 }
136