diff --git a/webcal/src/main/java/cn/org/codecrafters/webcal/WebCalendar.java b/webcal/src/main/java/cn/org/codecrafters/webcal/WebCalendar.java index c96e64a..f36603f 100644 --- a/webcal/src/main/java/cn/org/codecrafters/webcal/WebCalendar.java +++ b/webcal/src/main/java/cn/org/codecrafters/webcal/WebCalendar.java @@ -21,71 +21,74 @@ import java.util.ArrayList; import java.util.List; /** - * WebCalendar + * The WebCalendar class represents a web calendar in iCalendar format. + * + *
+ * It allows users to create and customize calendar components and events and + * generate an iCalendar string containing all the calendar information. + * + *
Usage Example: + *
+ * WebCalendar calendar = new WebCalendar()
+ * .setName("My Web Calendar")
+ * .setCompanyName("CodeCrafters Inc.")
+ * .setProductName("WebCal")
+ * .setDomainName("codecrafters.org.cn")
+ * .setMethod("PUBLISH")
+ * .addEvent(event1)
+ * .addEvent(event2);
+ * String iCalendarString = calendar.resolve();
+ *
+ *
+ *
+ * The WebCalendar class is designed to generate an iCalendar string conforming
+ * to the iCalendar specification, which can be used to share calendar data
+ * with other calendar applications or services.
*
* @author Zihlu Wang
+ * @version 1.0.0
+ * @since 1.0.0
*/
public final class WebCalendar {
- //
- // Constants
- //
-
- // Tag
+ /**
+ * The VCALENDAR tag for iCalendar format
+ */
private final static String TAG = "VCALENDAR";
- //
- // Fields
- //
-
+ // Calendar properties
private String name;
- /**
- * Company name. This value is to specify the {@code productIdentifier}
- * property.
- */
private String companyName;
- /**
- * Product name. This value is to specify the {@code productIdentifier}
- * property.
- */
private String productName;
private String domainName;
- /**
- * Calendar scale, referenced from RFC 5545 - 3.7.1. Calendar Scale.
- */
private final String scale = "GREGORIAN";
- /**
- * Method, referenced from RFC 5545 - 3.7.2. Method.
- */
private String method;
private final String version = "2.0";
- private List
+ * Users can use the methods in this class to add categories, set the
+ * classification, add comments, descriptions, locations, set percent complete
+ * , set priority, set summary, set start time, set end time, set duration, set
+ * URL, set UID, and set timezone for the event. After setting the properties,
+ * users can call the {@link #resolve()} method to generate the corresponding
+ * iCalendar content for the event.
*
* @author Zihlu Wang
+ * @version 1.0.0
+ * @since 1.0.0
*/
public final class WebCalendarEvent extends WebCalendarNode {
private final static String TAG = "VEVENT";
/**
- * Add a batch of categories.
+ * Add categories to the event.
*
- * @param categories A batch of categories.
- * @return The Event instance.
+ * @param categories the categories to add
+ * @return the WebCalendarEvent object
*/
public WebCalendarEvent addCategories(String... categories) {
this.categories.addAll(Arrays.asList(categories));
@@ -48,10 +60,10 @@ public final class WebCalendarEvent extends WebCalendarNode {
}
/**
- * Add a batch of categories.
+ * Add a collection of categories to the event.
*
- * @param categories A batch of categories.
- * @return The Event instance.
+ * @param categories the collection of categories to add
+ * @return the WebCalendarEvent object
*/
public WebCalendarEvent addCategories(Collection
+ * Subclasses of WebCalendarNode should implement the {@link #resolve()} method
+ * to generate the corresponding iCalendar content for the specific calendar
+ * component or event.
*
* @author Zihlu Wang
+ * @version 1.0.0
+ * @since 1.0.0
*/
public abstract sealed class WebCalendarNode
permits WebCalendarEvent {
- /**
- *
- * Categories, is used to specify categories or subtypes of the calendar component. The categories are useful in
- * searching for a calendar component of a particular type and category.
- * Referenced from RFC-5545 - 3.8.1.2. Categories
- * Classification, An access classification is only one component of the general security system within a calendar
- * application. It provides a method of capturing the scope of the access the calendar owner intends for information
- * within an individual calendar entry.
- * Referenced from RFC-5545 - 3.8.1.3. Classification
- * Comment, is used to specify a comment to the calendar user.
- * Referenced from RFC-5545 - 3.8.1.4. Comment
- * Description is used in the {@link WebCalendarEvent} and to-do to capture lengthy extual descriptions associated with
- * the activity.
- *
- * Description is used in the Journal calendar component to capture one or more textual journal entries.
- *
- * Description is used in the Alarm calendar component to capture the display text for a DISPLAY category of
- * alarm, and to capture the body text for an EMAIL category of alarm.
- * Referenced from RFC-5545 - 3.8.1.5. Description
- * Location, Specific venues such as conference or meeting rooms may be explicitly specified using this property.
- *
- * Note Referenced from RFC-5545 - 3.8.1.7. Location
- * Percent Complete, is a positive integer between 0 and 100. A value of "0" indicates the to-do has not yet been
- * started. A value of "100" indicates that the to-do has been completed. Integer values in between indicate the
- * percent partially complete.
- * Referenced from RFC-5545 - 3.8.1.8. Percent Complete
- * Priority, is specified as an integer in the range 0 to 9. A value of 0 specifies an undefined priority. A value
- * of 1 is the highest priority. A value of 2 is the second-highest priority. Subsequent numbers specify a
- * decreasing ordinal priority. A value of 9 is the lowest priority.
- *
- * Summary, is used to capture a short, one-line summary about the activity or journal entry.
- *
- // * Example:
- // *
+ * Calendar events or components can be classified as one of the following
+ * levels:
+ *
+ * Indicates that the calendar content is public and can be freely
+ * distributed.
+ */
PUBLIC("PUBLIC"),
+ /**
+ * Private classification level.
+ *
+ *
+ * Indicates that the calendar content is private and should not be shared
+ * with others.
+ */
PRIVATE("PRIVATE"),
+ /**
+ * Confidential classification level.
+ *
+ *
+ * Indicates that the calendar content is confidential and should be kept
+ * strictly private.
+ */
CONFIDENTIAL("CONFIDENTIAL"),
;
private final String classification;
+ /**
+ * Constructor for Classification enum.
+ *
+ * @param classification the classification level as a string representation
+ */
Classification(String classification) {
this.classification = classification;
}
+ /**
+ * Get the string representation of the classification level.
+ *
+ * @return the string representation of the classification level
+ */
public String getClassification() {
return classification;
}
diff --git a/webcal/src/main/java/cn/org/codecrafters/webcal/config/package-info.java b/webcal/src/main/java/cn/org/codecrafters/webcal/config/package-info.java
new file mode 100644
index 0000000..894709e
--- /dev/null
+++ b/webcal/src/main/java/cn/org/codecrafters/webcal/config/package-info.java
@@ -0,0 +1,34 @@
+/*
+ * Copyright (C) 2023 CodeCraftersCN.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * The package cn.org.codecrafters.webcal.config contains classes related to
+ * the configuration and settings of the web calendar module. It provides
+ * various configurations and constants used in the generation and resolution
+ * of iCalendar content.
+ *
+ * The classes in this package include:
+ * The main classes and modules in this package include:
+ * CATEGORIES:APPOINTMENT,EDUCATION
- * CATEGORIES:MEETING
- *
- * CLASS:protected
- *
- *
- * COMMENT:The meeting really needs to include both ourselves
- * and the customer. We can't hold this meeting without them.
- * As a matter of fact\, the venue for the meeting ought to be at
- * their site. - - John
- *
- *
- *
- * DESCRIPTION:Meeting to provide technical review for "Phoenix"
- * design.\nHappy Face Conference Room. Phoenix design team
- * MUST attend this meeting.\nRSVP to team leader.
- *
- *
- *
- * This location has not implement the URI of the location.
- * LOCATION:Conference Room - F123\, Bldg. 002
- * LOCATION;ALTREP="http://xyzcorp.com/conf-rooms/f123.vcf":
- * Conference Room - F123\, Bldg. 002
- *
- * PERCENT-COMPLETE:39
- *
- *
- *
- */
protected Integer priority;
-
-
- /**
- * PRIORITY:1
- * PRIORITY:2
- * SUMMARY:Department Party
- */
protected String summary;
-
-
- // /**
- // * Completed defines the date and time that a to-do was actually completed.
- // *
- // * COMPLETED:19960401T150000Z
- // * DTEND:19960401T150000Z
- * DTEND;VALUE=DATE:19980704
- */
protected LocalDateTime end;
-
-
- /**
- * Start defines the start date and time for the event.
- *
- * Example:
- * DTSTART:19980118T073000Z
- * DTSTART;VALUE=DATE:19980118
- */
protected LocalDateTime start;
-
-
- /**
- * Duration may be used to specify a duration of the event, instead of an explicit end DATE-TIME.
- *
- * Example:
- * DURATION:PT100000S
- */
protected Duration duration;
-
-
- /**
- * URL may be used in a calendar component to convey a location where a more dynamic rendition of the calendar
- * information associated with the calendar component can be found.
- *
- * Example:
- * URL:http://example.com/pub/calendars/jsmith/mytime.ics
- */
protected String url;
protected String uid;
@@ -247,23 +72,30 @@ public abstract sealed class WebCalendarNode
protected String timezone;
-
-
- //
- // Constructors
- //
+ /**
+ * Constructor for WebCalendarNode class, initializes the list of
+ * categories associated with the calendar component or event.
+ */
protected WebCalendarNode() {
this.categories = new ArrayList<>();
}
+ /**
+ * Set the domain name associated with the calendar component or event.
+ *
+ * @param domainName the domain name
+ * @return the WebCalendarNode object
+ */
public WebCalendarNode setDomainName(String domainName) {
this.domainName = domainName;
return this;
}
- //
- // Protected methods
- //
+ /**
+ * Resolve the list of categories into a comma-separated string.
+ *
+ * @return the comma-separated string of categories
+ */
protected String resolveCategories() {
var builder = new StringBuilder();
if (categories != null && !categories.isEmpty()) {
@@ -273,9 +105,12 @@ public abstract sealed class WebCalendarNode
return builder.toString();
}
- //
- // Abstract methods
- //
+ /**
+ * Generate and resolve the iCalendar content for the calendar component or
+ * event.
+ *
+ * @return the resolved iCalendar content
+ */
public abstract String resolve();
}
diff --git a/webcal/src/main/java/cn/org/codecrafters/webcal/config/Classification.java b/webcal/src/main/java/cn/org/codecrafters/webcal/config/Classification.java
index 94a5588..102a0c1 100644
--- a/webcal/src/main/java/cn/org/codecrafters/webcal/config/Classification.java
+++ b/webcal/src/main/java/cn/org/codecrafters/webcal/config/Classification.java
@@ -18,25 +18,77 @@
package cn.org.codecrafters.webcal.config;
/**
- * WebCalClassification
+ * The Classification enum represents the classification levels of calendar
+ * content based on RFC 5545.
+ *
+ *
+ *
*
* @author Zihlu Wang
+ * @version 1.0.0
+ * @since 1.0.0
*/
public enum Classification {
+ /**
+ * Public classification level.
+ *
+ *
+ *
+ *
+ * @since 1.0.0
+ */
+package cn.org.codecrafters.webcal.config;
\ No newline at end of file
diff --git a/webcal/src/main/java/cn/org/codecrafters/webcal/package-info.java b/webcal/src/main/java/cn/org/codecrafters/webcal/package-info.java
new file mode 100644
index 0000000..0091201
--- /dev/null
+++ b/webcal/src/main/java/cn/org/codecrafters/webcal/package-info.java
@@ -0,0 +1,44 @@
+/*
+ * Copyright (C) 2023 CodeCraftersCN.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * The package {@code cn.org.codecrafters.webcal} contains classes and modules
+ * related to web calendar generation and resolution. It provides functionality
+ * to create and manage iCalendar content for web-based calendar applications.
+ *
+ *
+ *
+ *
+ * @since 1.0.0
+ */
+package cn.org.codecrafters.webcal;
\ No newline at end of file