diff --git a/accessors-smart/src/main/java/net/minidev/asm/Accessor.java b/accessors-smart/src/main/java/net/minidev/asm/Accessor.java index 464bd598..459a05cc 100644 --- a/accessors-smart/src/main/java/net/minidev/asm/Accessor.java +++ b/accessors-smart/src/main/java/net/minidev/asm/Accessor.java @@ -134,7 +134,6 @@ public boolean isWritable() { * @param c the handled class * @param field the field to access * @param filter field filter - * */ public Accessor(Class c, Field field, FieldFilter filter) { this.fieldName = field.getName(); diff --git a/accessors-smart/src/main/java/net/minidev/asm/BasicFiledFilter.java b/accessors-smart/src/main/java/net/minidev/asm/BasicFiledFilter.java index f878bd33..5f32217d 100644 --- a/accessors-smart/src/main/java/net/minidev/asm/BasicFiledFilter.java +++ b/accessors-smart/src/main/java/net/minidev/asm/BasicFiledFilter.java @@ -3,24 +3,58 @@ import java.lang.reflect.Field; import java.lang.reflect.Method; +/** + * A basic implementation of the {@link FieldFilter} interface that permits all operations on fields. + * This implementation returns {@code true} for all checks, indicating that any field can be used, read, and written. + * It serves as a default or fallback strategy when no specific field filtering logic is required. + */ public class BasicFiledFilter implements FieldFilter { + /** + * A singleton instance of {@code BasicFieldFilter}. + * Since the filter does not maintain any state and allows all operations, it can be reused across the application. + */ public final static BasicFiledFilter SINGLETON = new BasicFiledFilter(); + /** + * Always allows using the specified field. + * + * @param field The field to check. + * @return Always returns {@code true}. + */ @Override public boolean canUse(Field field) { return true; } + /** + * Always allows using the specified field in conjunction with a method. + * + * @param field The field to check. + * @param method The method to check. This parameter is not used in the current implementation. + * @return Always returns {@code true}. + */ @Override public boolean canUse(Field field, Method method) { return true; } + /** + * Always allows reading the specified field. + * + * @param field The field to check. + * @return Always returns {@code true}. + */ @Override public boolean canRead(Field field) { return true; } + /** + * Always allows writing to the specified field. + * + * @param field The field to check. + * @return Always returns {@code true}. + */ @Override public boolean canWrite(Field field) { return true; diff --git a/accessors-smart/src/main/java/net/minidev/asm/ConvertDate.java b/accessors-smart/src/main/java/net/minidev/asm/ConvertDate.java index 3c9f859a..d79cbd4c 100644 --- a/accessors-smart/src/main/java/net/minidev/asm/ConvertDate.java +++ b/accessors-smart/src/main/java/net/minidev/asm/ConvertDate.java @@ -11,14 +11,21 @@ import java.util.TimeZone; import java.util.TreeMap; +/** + * Utility class for converting strings into {@link Date} objects, considering various global date formats. + * It handles different month and day names across languages, and supports timezone adjustments. + */ public class ConvertDate { static TreeMap monthsTable = new TreeMap(new StringCmpNS()); // StringCmpNS.COMP static TreeMap daysTable = new TreeMap(new StringCmpNS()); // StringCmpNS.COMP private static HashSet voidData = new HashSet(); /** - * overwrite system time zone - */ + * Default TimeZone used for date conversions. Can be overwritten to change the default time zone. + */ public static TimeZone defaultTimeZone; + /** + * Comparator for case-insensitive string comparison. Used for sorting and comparing month and day names. + */ public static class StringCmpNS implements Comparator { @Override public int compare(String o1, String o2) { @@ -26,6 +33,12 @@ public int compare(String o1, String o2) { } } + /** + * Retrieves the month's integer representation based on the provided month name. + * + * @param month the name of the month + * @return the integer value of the month, or null if the month name is unrecognized + */ public static Integer getMonth(String month) { return monthsTable.get(month); } diff --git a/accessors-smart/src/main/java/net/minidev/asm/DefaultConverter.java b/accessors-smart/src/main/java/net/minidev/asm/DefaultConverter.java index 621c4f24..dc112c38 100644 --- a/accessors-smart/src/main/java/net/minidev/asm/DefaultConverter.java +++ b/accessors-smart/src/main/java/net/minidev/asm/DefaultConverter.java @@ -2,7 +2,20 @@ import net.minidev.asm.ex.ConvertException; +/** + * Provides utility methods to convert objects to different primitive types and their wrapper classes. + * It supports conversion from {@link Number} instances and {@link String} representations of numbers + * to their corresponding primitive types or wrapper classes. Conversion from types that are not supported + * will result in a {@link ConvertException}. + */ public class DefaultConverter { + /** + * Converts the given object to an {@code int}. + * + * @param obj the object to convert + * @return the converted int value, or 0 if the object is {@code null} + * @throws ConvertException if the object cannot be converted to an int + */ public static int convertToint(Object obj) { if (obj == null) return 0; @@ -13,6 +26,13 @@ public static int convertToint(Object obj) { throw new ConvertException("Primitive: Can not convert " + obj.getClass().getName() + " to int"); } + /** + * Converts the given object to an {@link Integer}. + * + * @param obj the object to convert + * @return the converted Integer, or {@code null} if the object is {@code null} + * @throws ConvertException if the object cannot be converted to an Integer + */ public static Integer convertToInt(Object obj) { if (obj == null) return null; @@ -24,6 +44,13 @@ public static Integer convertToInt(Object obj) { throw new ConvertException("Primitive: Can not convert " + obj.getClass().getName() + " to Integer"); } + /** + * Converts the given object to a {@code short}. + * + * @param obj the object to convert + * @return the converted short value, or 0 if the object is {@code null} + * @throws ConvertException if the object cannot be converted to a short + */ public static short convertToshort(Object obj) { if (obj == null) return 0; @@ -34,6 +61,13 @@ public static short convertToshort(Object obj) { throw new ConvertException("Primitive: Can not convert " + obj.getClass().getName() + " to short"); } + /** + * Converts the given object to a {@code short}. + * + * @param obj the object to convert + * @return the converted short value, or 0 if the object is {@code null} + * @throws ConvertException if the object cannot be converted to a short + */ public static Short convertToShort(Object obj) { if (obj == null) return null; @@ -45,6 +79,13 @@ public static Short convertToShort(Object obj) { throw new ConvertException("Primitive: Can not convert " + obj.getClass().getName() + " to Short"); } + /** + * Converts the given object to a {@code long}. + * + * @param obj the object to convert + * @return the converted long value, or 0 if the object is {@code null} + * @throws ConvertException if the object cannot be converted to a long + */ public static long convertTolong(Object obj) { if (obj == null) return 0; @@ -55,6 +96,13 @@ public static long convertTolong(Object obj) { throw new ConvertException("Primitive: Can not convert " + obj.getClass().getName() + " to long"); } + /** + * Converts the given object to a {@link Long}. + * + * @param obj the object to convert + * @return the converted Long, or {@code null} if the object is {@code null} + * @throws ConvertException if the object cannot be converted to a Long + */ public static Long convertToLong(Object obj) { if (obj == null) return null; @@ -66,6 +114,13 @@ public static Long convertToLong(Object obj) { throw new ConvertException("Primitive: Can not convert value '" + obj+ "' As " + obj.getClass().getName() + " to Long"); } + /** + * Converts the given object to a {@code byte}. + * + * @param obj the object to convert + * @return the converted byte value, or 0 if the object is {@code null} + * @throws ConvertException if the object cannot be converted to a byte + */ public static byte convertTobyte(Object obj) { if (obj == null) return 0; @@ -76,6 +131,13 @@ public static byte convertTobyte(Object obj) { throw new ConvertException("Primitive: Can not convert " + obj.getClass().getName() + " to byte"); } + /** + * Converts the given object to a {@link Byte}. + * + * @param obj the object to convert + * @return the converted Byte, or {@code null} if the object is {@code null} + * @throws ConvertException if the object cannot be converted to a Byte + */ public static Byte convertToByte(Object obj) { if (obj == null) return null; @@ -87,6 +149,13 @@ public static Byte convertToByte(Object obj) { throw new ConvertException("Primitive: Can not convert " + obj.getClass().getName() + " to Byte"); } + /** + * Converts the given object to a {@code float}. + * + * @param obj the object to convert + * @return the converted float value, or 0f if the object is {@code null} + * @throws ConvertException if the object cannot be converted to a float + */ public static float convertTofloat(Object obj) { if (obj == null) return 0f; @@ -97,6 +166,13 @@ public static float convertTofloat(Object obj) { throw new ConvertException("Primitive: Can not convert " + obj.getClass().getName() + " to float"); } + /** + * Converts the given object to a {@link Byte}. + * + * @param obj the object to convert + * @return the converted Byte, or {@code null} if the object is {@code null} + * @throws ConvertException if the object cannot be converted to a Byte + */ public static Float convertToFloat(Object obj) { if (obj == null) return null; @@ -108,6 +184,13 @@ public static Float convertToFloat(Object obj) { throw new ConvertException("Primitive: Can not convert " + obj.getClass().getName() + " to Float"); } + /** + * Converts the given object to a {@code double}. + * + * @param obj the object to convert + * @return the converted double value, or 0.0 if the object is {@code null} + * @throws ConvertException if the object cannot be converted to a double + */ public static double convertTodouble(Object obj) { if (obj == null) return 0.0; @@ -118,6 +201,13 @@ public static double convertTodouble(Object obj) { throw new ConvertException("Primitive: Can not convert " + obj.getClass().getName() + " to float"); } + /** + * Converts the given object to a {@link Double}. + * + * @param obj the object to convert + * @return the converted Double, or {@code null} if the object is {@code null} + * @throws ConvertException if the object cannot be converted to a Double + */ public static Double convertToDouble(Object obj) { if (obj == null) return null; @@ -129,6 +219,13 @@ public static Double convertToDouble(Object obj) { throw new ConvertException("Primitive: Can not convert " + obj.getClass().getName() + " to Float"); } + /** + * Converts the given object to a {@code char}. + * + * @param obj the object to convert + * @return the converted char value, or a space character if the object is {@code null} or the string is empty + * @throws ConvertException if the object cannot be converted to a char + */ public static char convertTochar(Object obj) { if (obj == null) return ' '; @@ -140,6 +237,13 @@ public static char convertTochar(Object obj) { throw new ConvertException("Primitive: Can not convert " + obj.getClass().getName() + " to char"); } + /** + * Converts the given object to a {@link Character}. + * + * @param obj the object to convert + * @return the converted Character, or {@code null} if the object is {@code null} + * @throws ConvertException if the object cannot be converted to a Character + */ public static Character convertToChar(Object obj) { if (obj == null) return null; @@ -154,6 +258,13 @@ public static Character convertToChar(Object obj) { throw new ConvertException("Primitive: Can not convert " + obj.getClass().getName() + " to Character"); } + /** + * Converts the given object to a {@code boolean}. + * + * @param obj the object to convert + * @return the converted boolean value, false if the object is {@code null} or represents the numeric value 0 + * @throws ConvertException if the object cannot be converted to a boolean + */ public static boolean convertTobool(Object obj) { if (obj == null) return false; @@ -170,6 +281,13 @@ public static boolean convertTobool(Object obj) { throw new ConvertException("Primitive: Can not convert " + obj.getClass().getName() + " to boolean"); } + /** + * Converts the given object to a {@link Boolean}. + * + * @param obj the object to convert + * @return the converted Boolean, or {@code null} if the object is {@code null} + * @throws ConvertException if the object cannot be converted to a Boolean + */ public static Boolean convertToBool(Object obj) { if (obj == null) return null; diff --git a/accessors-smart/src/main/java/net/minidev/asm/ex/ConvertException.java b/accessors-smart/src/main/java/net/minidev/asm/ex/ConvertException.java index 8104c5b2..6646aa19 100644 --- a/accessors-smart/src/main/java/net/minidev/asm/ex/ConvertException.java +++ b/accessors-smart/src/main/java/net/minidev/asm/ex/ConvertException.java @@ -1,12 +1,27 @@ package net.minidev.asm.ex; +/** + * An exception that is thrown to indicate a problem occurred during a conversion process. + * This class extends {@link RuntimeException} and is used to signify errors encountered + * while converting between types, typically within a dynamic type conversion framework or library. + */ public class ConvertException extends RuntimeException { private static final long serialVersionUID = 1L; + /** + * Constructs a new {@code ConvertException} with {@code null} as its detail message. + * The cause is not initialized, and may subsequently be initialized by a call to {@link #initCause}. + */ public ConvertException() { super(); } - + + /** + * Constructs a new {@code ConvertException} with the specified detail message. + * The cause is not initialized, and may subsequently be initialized by a call to {@link #initCause}. + * + * @param message the detail message. The detail message is saved for later retrieval by the {@link #getMessage()} method. + */ public ConvertException(String message) { super(message); } diff --git a/accessors-smart/src/main/java/net/minidev/asm/ex/NoSuchFieldException.java b/accessors-smart/src/main/java/net/minidev/asm/ex/NoSuchFieldException.java index 49766d22..eb6d2c91 100644 --- a/accessors-smart/src/main/java/net/minidev/asm/ex/NoSuchFieldException.java +++ b/accessors-smart/src/main/java/net/minidev/asm/ex/NoSuchFieldException.java @@ -13,6 +13,10 @@ public NoSuchFieldException() { super(); } + /** + * @param message the detail message. The detail message is saved for + * later retrieval by the Throwable.getMessage() method. + */ public NoSuchFieldException(String message) { super(message); }