Skip to content

Commit

Permalink
Fix documentation and simplify logic
Browse files Browse the repository at this point in the history
  • Loading branch information
Obolrom committed Apr 27, 2024
1 parent f17328d commit 5adcdb8
Showing 1 changed file with 19 additions and 14 deletions.
33 changes: 19 additions & 14 deletions lib/src/main/java/de/siegmar/fastcsv/util/Limits.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@
/**
* The {@code Limits} class defines the maximum limits for various fields and records in a CSV file.
* <p>
* Properties can be overridden by using
* <p>
* Example use:
* {@snippet : System.setProperty("fastcsv.max.field.size", "1024"); }
* <pre>{@code
* System.setProperty("fastcsv.max.field.size", "1024");
* }</pre>
* <p>
* Or using VM options: {@snippet : -Dfastcsv.max.field.count=1024 }
* Or using VM options:
* <pre>{@code
* -Dfastcsv.max.field.count=1024
* }</pre>
*/
public final class Limits {

Expand All @@ -35,23 +38,25 @@ private Limits() {
}

/**
* Retrieves the system property value as an integer, with a fallback to a default value.
* If the property is not set or cannot be parsed, the default value is returned.
* Retrieves the system property value if presented, otherwise default value is returned.
* If the property cannot be parsed as an integer, an {@code IllegalArgumentException} is thrown.
*
* @param key The system property key.
* @param defaultValue The default value to use if the system property is not set or is invalid.
* @return The system property value as an integer or the default value if the property is not set or is invalid.
* @throws IllegalArgumentException If the system property value cannot be parsed as an integer.
*/
private static int getIntProperty(String key, int defaultValue) {
String value = System.getProperty(key);
if (value != null) {
try {
return Integer.parseInt(value);
} catch (NumberFormatException e) {
System.err.println("Invalid format for system property " + key);
throw e;
}

if (value == null) {
return defaultValue;
}

try {
return Integer.parseInt(value);
} catch (NumberFormatException e) {
throw new IllegalArgumentException("Invalid format for system property " + key, e);
}
return defaultValue;
}
}

0 comments on commit 5adcdb8

Please sign in to comment.