From 8a643bc9abc2aef89b0f8b030ecc6b68b89adb42 Mon Sep 17 00:00:00 2001 From: KosherJava Date: Mon, 27 May 2024 17:55:58 -0400 Subject: [PATCH] Replace StringBuffer with StringBuilder and add toXML() --- .../java/com/kosherjava/zmanim/util/Zman.java | 33 +++++++++++++++++-- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/kosherjava/zmanim/util/Zman.java b/src/main/java/com/kosherjava/zmanim/util/Zman.java index 9c415025..22cde870 100644 --- a/src/main/java/com/kosherjava/zmanim/util/Zman.java +++ b/src/main/java/com/kosherjava/zmanim/util/Zman.java @@ -1,6 +1,6 @@ /* * Zmanim Java API - * Copyright (C) 2004-2020 Eliyahu Hershfeld + * Copyright (C) 2004-2024 Eliyahu Hershfeld * * This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General * Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) @@ -54,7 +54,7 @@ * // will sort shaah 1.6, shaah GRA, sunrise, sunset * * - * @author © Eliyahu Hershfeld 2007-2020 + * @author © Eliyahu Hershfeld 2007-2024 * @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 * {@link java.util.Collection} of zmanim and using the {@link #DATE_ORDER} {@code Comparator} will have the duration based zmanim * 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) { return firstDuration == secondDuration ? 0 : firstDuration > secondDuration ? 1 : -1; } }; + + /** + * A method that returns an XML formatted String representing the serialized Object. Very + * similar to the toString method but the return value is in an xml format. The format currently used (subject to + * change) is: + * + *
+	 * <Zman>
+	 * 	<Label>Sof Zman Krias Shema GRA</Label>
+	 * 	<Zman>1969-02-08T09:37:56.820</Zman>
+	 * 	<Duration>0</Duration>
+	 * 	<Description>Sof Zman Krias Shema GRA is 3 sha'os zmaniyos calculated from sunrise to sunset.</Description>
+	 * </Zman>
+	 * 
+ * @return The XML formatted String. + */ + public String toXML() { + SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS"); + StringBuilder sb = new StringBuilder(); + sb.append("\n"); + sb.append("\t\n"); + sb.append("\t").append(getZman() == null ? "": formatter.format(getZman())).append("\n"); + sb.append("\n\t").append(getDuration()).append("\n"); + sb.append("\t").append(getDescription()).append("\n"); + sb.append(""); + return sb.toString(); + } /** * @see java.lang.Object#toString() */ public String toString() { - StringBuffer sb = new StringBuffer(); + StringBuilder sb = new StringBuilder(); sb.append("\nLabel:\t\t\t").append(this.getLabel()); sb.append("\nZman:\t\t\t").append(getZman()); sb.append("\nDuration:\t\t\t").append(getDuration());