|
1 | 1 | /*
|
2 | 2 | * Zmanim Java API
|
3 |
| - * Copyright (C) 2004-2020 Eliyahu Hershfeld |
| 3 | + * Copyright (C) 2004-2024 Eliyahu Hershfeld |
4 | 4 | *
|
5 | 5 | * This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General
|
6 | 6 | * Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option)
|
|
54 | 54 | * // will sort shaah 1.6, shaah GRA, sunrise, sunset
|
55 | 55 | * </pre>
|
56 | 56 | *
|
57 |
| - * @author © Eliyahu Hershfeld 2007-2020 |
| 57 | + * @author © Eliyahu Hershfeld 2007-2024 |
58 | 58 | * @todo Add secondary sorting. As of now the {@code Comparator}s in this class do not sort by secondary order. This means that when sorting a
|
59 | 59 | * {@link java.util.Collection} of <em>zmanim</em> and using the {@link #DATE_ORDER} {@code Comparator} will have the duration based <em>zmanim</em>
|
60 | 60 | * at the end, but they will not be sorted by duration. This should be N/A for label based sorting.
|
@@ -230,12 +230,39 @@ public int compare(Zman zman1, Zman zman2) {
|
230 | 230 | return firstDuration == secondDuration ? 0 : firstDuration > secondDuration ? 1 : -1;
|
231 | 231 | }
|
232 | 232 | };
|
| 233 | + |
| 234 | + /** |
| 235 | + * A method that returns an XML formatted <code>String</code> representing the serialized <code>Object</code>. Very |
| 236 | + * similar to the toString method but the return value is in an xml format. The format currently used (subject to |
| 237 | + * change) is: |
| 238 | + * |
| 239 | + * <pre> |
| 240 | + * <Zman> |
| 241 | + * <Label>Sof Zman Krias Shema GRA</Label> |
| 242 | + * <Zman>1969-02-08T09:37:56.820</Zman> |
| 243 | + * <Duration>0</Duration> |
| 244 | + * <Description>Sof Zman Krias Shema GRA is 3 sha'os zmaniyos calculated from sunrise to sunset.</Description> |
| 245 | + * </Zman> |
| 246 | + * </pre> |
| 247 | + * @return The XML formatted <code>String</code>. |
| 248 | + */ |
| 249 | + public String toXML() { |
| 250 | + SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS"); |
| 251 | + StringBuilder sb = new StringBuilder(); |
| 252 | + sb.append("<Zman>\n"); |
| 253 | + sb.append("\t<Label>").append(getLabel()).append("</Label>\n"); |
| 254 | + sb.append("\t<Zman>").append(getZman() == null ? "": formatter.format(getZman())).append("</Zman>\n"); |
| 255 | + sb.append("\n\t<Duration>").append(getDuration()).append("</Duration>\n"); |
| 256 | + sb.append("\t<Description>").append(getDescription()).append("</Description>\n"); |
| 257 | + sb.append("</Zman>"); |
| 258 | + return sb.toString(); |
| 259 | + } |
233 | 260 |
|
234 | 261 | /**
|
235 | 262 | * @see java.lang.Object#toString()
|
236 | 263 | */
|
237 | 264 | public String toString() {
|
238 |
| - StringBuffer sb = new StringBuffer(); |
| 265 | + StringBuilder sb = new StringBuilder(); |
239 | 266 | sb.append("\nLabel:\t\t\t").append(this.getLabel());
|
240 | 267 | sb.append("\nZman:\t\t\t").append(getZman());
|
241 | 268 | sb.append("\nDuration:\t\t\t").append(getDuration());
|
|
0 commit comments