Skip to content

Commit d91a117

Browse files
committed
feat: added classes
1 parent c1f0f58 commit d91a117

26 files changed

+576
-93
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
* Copyright (C) 2024-2024 OnixByte.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
*
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package com.onixbyte.icalendar.calendar.property;
19+
20+
import com.onixbyte.icalendar.property.CalendarResolvable;
21+
22+
public interface CalendarProperty extends CalendarResolvable {
23+
}

webcal/src/main/java/com/onixbyte/icalendar/property/calendar/CalendarScale.java renamed to webcal/src/main/java/com/onixbyte/icalendar/calendar/property/CalendarScale.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,14 @@
1515
* limitations under the License.
1616
*/
1717

18-
package com.onixbyte.icalendar.property.calendar;
19-
20-
import com.onixbyte.icalendar.property.Prop;
18+
package com.onixbyte.icalendar.calendar.property;
2119

2220
/**
2321
* CalendarScale
2422
*
2523
* @author Zihlu WANG
2624
*/
27-
public enum CalendarScale implements Prop {
25+
public enum CalendarScale implements CalendarProperty {
2826

2927
GREGORIAN,
3028
;

webcal/src/main/java/com/onixbyte/icalendar/property/calendar/Method.java renamed to webcal/src/main/java/com/onixbyte/icalendar/calendar/property/Method.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,9 @@
1515
* limitations under the License.
1616
*/
1717

18-
package com.onixbyte.icalendar.property.calendar;
18+
package com.onixbyte.icalendar.calendar.property;
1919

20-
import com.onixbyte.icalendar.property.Prop;
21-
22-
public enum Method implements Prop {
20+
public enum Method implements CalendarProperty {
2321

2422
PUBLISH("PUBLISH"),
2523
REQUEST("REQUEST"),

webcal/src/main/java/com/onixbyte/icalendar/property/calendar/ProductIdentifier.java renamed to webcal/src/main/java/com/onixbyte/icalendar/calendar/property/ProductIdentifier.java

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,48 +15,45 @@
1515
* limitations under the License.
1616
*/
1717

18-
package com.onixbyte.icalendar.property.calendar;
19-
20-
import com.onixbyte.icalendar.property.Prop;
18+
package com.onixbyte.icalendar.calendar.property;
2119

2220
/**
2321
* ProductIdentifier
2422
*
2523
* @author Zihlu WANG
2624
*/
27-
public final class ProductIdentifier implements Prop {
25+
public final class ProductIdentifier implements CalendarProperty {
2826

29-
private String value;
27+
private final String value;
3028

3129
@Override
3230
public String resolve() {
3331
return PROPERTY_NAME + ":" + value + '\n';
3432
}
3533

3634
public static class Builder {
37-
private final ProductIdentifier productIdentifier;
35+
private String productIdentifier;
3836

3937
private Builder() {
40-
this.productIdentifier = new ProductIdentifier();
4138
}
4239

4340
public Builder productIdentifier(String productIdentifier) {
44-
this.productIdentifier.value = productIdentifier;
41+
this.productIdentifier = productIdentifier;
4542
return this;
4643
}
4744

4845
public Builder productIdentifier(String companyName, String productName) {
49-
this.productIdentifier.value = "-//" + companyName + "//" + productName + "//EN";
46+
this.productIdentifier = "-//" + companyName + "//" + productName + "//EN";
5047
return this;
5148
}
5249

5350
public Builder productIdentifier(String companyName, String productName, String languageTag) {
54-
this.productIdentifier.value = "-//" + companyName + "//" + productName + "//" + languageTag;
51+
this.productIdentifier = "-//" + companyName + "//" + productName + "//" + languageTag;
5552
return this;
5653
}
5754

5855
public ProductIdentifier build() {
59-
return productIdentifier;
56+
return new ProductIdentifier(productIdentifier);
6057
}
6158
}
6259

@@ -66,6 +63,7 @@ public static Builder builder() {
6663

6764
private static final String PROPERTY_NAME = "PRODID";
6865

69-
private ProductIdentifier() {
66+
private ProductIdentifier(String value) {
67+
this.value = value;
7068
}
7169
}

webcal/src/main/java/com/onixbyte/icalendar/property/calendar/Version.java renamed to webcal/src/main/java/com/onixbyte/icalendar/calendar/property/Version.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,14 @@
1515
* limitations under the License.
1616
*/
1717

18-
package com.onixbyte.icalendar.property.calendar;
19-
20-
import com.onixbyte.icalendar.property.Prop;
18+
package com.onixbyte.icalendar.calendar.property;
2119

2220
/**
2321
* Version
2422
*
2523
* @author Zihlu WANG
2624
*/
27-
public enum Version implements Prop {
25+
public enum Version implements CalendarProperty {
2826

2927
VERSION_2_0,
3028
;

webcal/src/main/java/com/onixbyte/icalendar/component/Calendar.java

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@
1717

1818
package com.onixbyte.icalendar.component;
1919

20-
import com.onixbyte.icalendar.property.calendar.CalendarScale;
21-
import com.onixbyte.icalendar.property.calendar.Method;
22-
import com.onixbyte.icalendar.property.calendar.ProductIdentifier;
23-
import com.onixbyte.icalendar.property.calendar.Version;
20+
import com.onixbyte.icalendar.calendar.property.CalendarScale;
21+
import com.onixbyte.icalendar.calendar.property.Method;
22+
import com.onixbyte.icalendar.calendar.property.ProductIdentifier;
23+
import com.onixbyte.icalendar.calendar.property.Version;
2424

2525
import java.util.ArrayList;
2626
import java.util.List;
@@ -100,9 +100,7 @@ public String resolve() {
100100
.ifPresent((_method) -> calendarBuilder.append(_method.resolve()).append('\n'));
101101

102102
if (!components.isEmpty()) {
103-
for (var component : components) {
104-
calendarBuilder.append(component.resolve()).append('\n');
105-
}
103+
components.forEach(((component) -> calendarBuilder.append(component.resolve()).append('\n')));
106104
}
107105

108106
calendarBuilder.append("END:").append(COMPONENT_NAME).append('\n');

webcal/src/main/java/com/onixbyte/icalendar/component/CalendarComponent.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,12 @@
1818
package com.onixbyte.icalendar.component;
1919

2020
/**
21-
* The abstract sealed class {@code WebCalendarNode} represents a node in a web calendar, such as an <a href="">event</a>, a to-do
22-
* item, or an alarm. It provides common properties and methods for all calendar components and events.
21+
* The abstract sealed class {@code WebCalendarNode} represents a node in a web calendar, such as an
22+
* <a href="some_link">event</a>, a to-do item, or an alarm. It provides common properties and
23+
* methods for all calendar components and events.
2324
* <p>
24-
* Subclasses of {@code WebCalendarNode} should implement the {@link #resolve()} method to generate the corresponding iCalendar content for the specific calendar component or event.
25+
* Subclasses of {@code WebCalendarNode} should implement the {@link #resolve()} method to generate
26+
* the corresponding iCalendar content for the specific calendar component or event.
2527
*
2628
* @author Zihlu Wang
2729
* @version 1.1.0

webcal/src/main/java/com/onixbyte/icalendar/component/Event.java

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@
1717

1818
package com.onixbyte.icalendar.component;
1919

20-
import com.onixbyte.icalendar.property.component.DateTimeStamp;
21-
import com.onixbyte.icalendar.property.component.UniqueIdentifier;
20+
import com.onixbyte.icalendar.component.property.Classification;
21+
import com.onixbyte.icalendar.component.property.DateTimeStamp;
22+
import com.onixbyte.icalendar.component.property.UniqueIdentifier;
2223

2324
/**
2425
* Event
@@ -27,11 +28,39 @@
2728
*/
2829
public class Event extends CalendarComponent {
2930

31+
/*
32+
* The following properties are REQUIRED, but MUST NOT occur more than once.
33+
*/
34+
35+
/**
36+
*
37+
*/
3038
private DateTimeStamp dtStamp;
3139

40+
/**
41+
*
42+
*/
3243
private UniqueIdentifier uid;
3344

45+
/*
46+
* The following property is REQUIRED if the component appears in an iCalendar object that
47+
* doesn't specify the "METHOD" property; otherwise, it is OPTIONAL; in any case, it MUST NOT
48+
* occur more than once.
49+
*/
50+
51+
/**
52+
*
53+
*/
54+
private DateTimeStamp dtStart;
55+
56+
/*
57+
* The following properties are OPTIONAL, but MUST NOT occur more than once.
58+
*/
3459

60+
/**
61+
*
62+
*/
63+
private Classification classification;
3564

3665
@Override
3766
public String resolve() {

webcal/src/main/java/com/onixbyte/icalendar/property/component/Attach.java renamed to webcal/src/main/java/com/onixbyte/icalendar/component/property/Attachment.java

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,26 +15,34 @@
1515
* limitations under the License.
1616
*/
1717

18-
package com.onixbyte.icalendar.property.component;
18+
package com.onixbyte.icalendar.component.property;
1919

20-
import com.onixbyte.icalendar.property.Prop;
2120
import com.onixbyte.icalendar.property.parameter.FormatType;
2221

2322
import java.net.URI;
23+
import java.util.Optional;
2424

2525
/**
26-
* Attach
26+
* Attachment
2727
*
2828
* @author Zihlu WANG
2929
*/
30-
public final class Attach implements Prop {
30+
public final class Attachment implements ComponentProperty {
3131

3232
private FormatType formatType;
3333

3434
private URI uri;
3535

3636
@Override
3737
public String resolve() {
38-
return "";
38+
final var attachmentBuilder = new StringBuilder("ATTACH");
39+
40+
Optional.ofNullable(formatType)
41+
.ifPresent((fmtType) -> attachmentBuilder.append(fmtType.resolve()));
42+
43+
attachmentBuilder.append(":")
44+
.append(uri.toString());
45+
46+
return attachmentBuilder.toString();
3947
}
4048
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/*
2+
* Copyright (C) 2024-2024 OnixByte.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
*
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package com.onixbyte.icalendar.component.property;
19+
20+
public class Categories {
21+
}

0 commit comments

Comments
 (0)