Skip to content

Commit 9aafb0e

Browse files
committed
Add missing Javadocs
1 parent 6210cb6 commit 9aafb0e

File tree

5 files changed

+63
-7
lines changed

5 files changed

+63
-7
lines changed

src/main/java/xyz/srnyx/javautilities/manipulation/Mapper.java

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,18 +112,45 @@ public static <T extends Enum<T>> Optional<T> toEnum(@Nullable String name, @Not
112112
return name == null || name.isEmpty() ? Optional.empty() : MiscUtility.handleException(() -> Enum.valueOf(enumClass, name.toUpperCase()), IllegalArgumentException.class);
113113
}
114114

115+
/**
116+
* Converts an {@link Object} to a {@link JsonElement}
117+
*
118+
* @param object the {@link Object} to convert
119+
*
120+
* @return the converted {@link JsonElement} or {@link Optional#empty()} if parsing failed
121+
*/
115122
@NotNull
116123
public static Optional<JsonElement> toJson(@Nullable Object object) {
117124
if (object == null) return Optional.of(JsonNull.INSTANCE);
118125
if (object instanceof JsonElement) return Optional.of((JsonElement) object);
119126
return MiscUtility.handleException(() -> MiscUtility.JSON_PARSER.parse(object.toString()), IllegalStateException.class);
120127
}
121128

129+
/**
130+
* Converts a {@link JsonElement} to the specified subclass
131+
*
132+
* @param element the {@link JsonElement} to convert
133+
* @param jsonClass the subclass of {@link JsonElement} to convert to
134+
*
135+
* @return an {@link Optional} containing the converted {@link JsonElement} if it is of the specified subclass, otherwise {@link Optional#empty()}
136+
*
137+
* @param <T> the type of the {@link JsonElement} subclass
138+
*/
122139
@NotNull
123140
public static <T extends JsonElement> Optional<T> convertJsonElement(@Nullable JsonElement element, @NotNull Class<T> jsonClass) {
124141
return !jsonClass.isInstance(element) ? Optional.empty() : Optional.of(jsonClass.cast(element));
125142
}
126143

144+
/**
145+
* Converts a {@link JsonPrimitive} to the specified primitive wrapper class
146+
*
147+
* @param primitive the {@link JsonPrimitive} to convert
148+
* @param primitiveClass the primitive wrapper {@link Class} to convert to
149+
*
150+
* @return an {@link Optional} containing the converted value if successful, otherwise {@link Optional#empty()}
151+
*
152+
* @param <T> the type of the primitive wrapper class
153+
*/
127154
@NotNull
128155
public static <T> Optional<T> convertJsonPrimitive(@Nullable JsonPrimitive primitive, @NotNull Class<T> primitiveClass) {
129156
// Check if primitive is null or class not supported
@@ -160,6 +187,9 @@ public static <T> Optional<T> convertJsonPrimitive(@Nullable JsonPrimitive primi
160187
}, IllegalStateException.class).map(primitiveClass::cast);
161188
}
162189

190+
/**
191+
* Private constructor to prevent instantiation
192+
*/
163193
private Mapper() {
164194
throw new UnsupportedOperationException("This is a utility class and cannot be instantiated");
165195
}

src/main/java/xyz/srnyx/javautilities/objects/encryptor/Encryptor.java

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,13 @@ public class Encryptor {
6767
/**
6868
* Creates a new {@link Encryptor}
6969
*
70-
* @param secret {@link #secret}
71-
* @param maxAge {@link #maxAge}
70+
* @param secret {@link #secret}
71+
* @param maxAge {@link #maxAge}
7272
*
73-
* @throws NoSuchAlgorithmException if the specified algorithm is not available
74-
* @throws InvalidKeyException if the provided secret is invalid
75-
* @throws NoSuchPaddingException if the specified padding scheme is not available
73+
* @throws NoSuchAlgorithmException if the specified algorithm is not available
74+
* @throws InvalidKeyException if the provided secret is invalid
75+
* @throws NoSuchPaddingException if the specified padding scheme is not available
76+
* @throws InvalidAlgorithmParameterException if the provided algorithm parameters are invalid
7677
*/
7778
public Encryptor(@NotNull byte[] secret, @Nullable Duration maxAge) throws NoSuchAlgorithmException, InvalidKeyException, NoSuchPaddingException, InvalidAlgorithmParameterException {
7879
this.secret = new SecretKeySpec(secret, ALGORITHM);
@@ -142,9 +143,12 @@ public String encrypt(@NotNull JsonElement value) {
142143
/**
143144
* Decrypts a Base64 URL-safe string token and returns the original {@link JsonElement} value
144145
*
145-
* @param token the Base64 URL-safe string token to decrypt
146+
* @param token the Base64 URL-safe string token to decrypt
146147
*
147-
* @return the decrypted {@link JsonElement} value, or null if decryption fails or token is invalid
148+
* @return the decrypted {@link JsonElement} value, or null if decryption fails or token is invalid
149+
*
150+
* @throws TokenExpiredException if the token has expired based on {@link #maxAge}
151+
* @throws TokenInvalidException if the token is invalid or tampered with
148152
*/
149153
@Nullable
150154
public JsonElement decrypt(@NotNull String token) throws TokenExpiredException, TokenInvalidException {

src/main/java/xyz/srnyx/javautilities/objects/encryptor/exceptions/DecryptionException.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,15 @@
33
import org.jetbrains.annotations.NotNull;
44

55

6+
/**
7+
* Exception thrown when {@link xyz.srnyx.javautilities.objects.encryptor.Encryptor#decrypt(String) decryption} fails
8+
*/
69
public class DecryptionException extends Exception {
10+
/**
11+
* Constructs a new {@link DecryptionException} with the specified detail message
12+
*
13+
* @param message the detail message
14+
*/
715
public DecryptionException(@NotNull String message) {
816
super(message);
917
}

src/main/java/xyz/srnyx/javautilities/objects/encryptor/exceptions/TokenExpiredException.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
package xyz.srnyx.javautilities.objects.encryptor.exceptions;
22

33

4+
/**
5+
* Exception thrown when a token has expired during {@link xyz.srnyx.javautilities.objects.encryptor.Encryptor#decrypt(String) decryption}
6+
*/
47
public class TokenExpiredException extends DecryptionException {
8+
/**
9+
* Constructs a new {@link TokenExpiredException} with the default message
10+
*/
511
public TokenExpiredException() {
612
super("Token has expired");
713
}

src/main/java/xyz/srnyx/javautilities/objects/encryptor/exceptions/TokenInvalidException.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,15 @@
33
import org.jetbrains.annotations.NotNull;
44

55

6+
/**
7+
* Exception thrown when a token is invalid during {@link xyz.srnyx.javautilities.objects.encryptor.Encryptor#decrypt(String) decryption}
8+
*/
69
public class TokenInvalidException extends DecryptionException {
10+
/**
11+
* Constructs a new {@link TokenInvalidException} with the specified detail message
12+
*
13+
* @param message the detail message
14+
*/
715
public TokenInvalidException(@NotNull String message) {
816
super(message);
917
}

0 commit comments

Comments
 (0)