OPENDJ-1932 Code cleanup
* NewBaseDNPanel.java
** validateAutomaticallyGenerated(final Set<LocalizableMessage> errors)
*** Extract local constants
*** Add final keyword
* StatusGenericPanel.java
** checkIntValue(Collection<LocalizableMessage> errors, String stringValue,int minValue, int maxValue, LocalizableMessage errMsg)
*** Now return a boolean to allow client code to use conditionnal code after call
*** Don't throw runtime exception anymore (Thanks Jean-Noël for refactoring advices!)
* ExportLDIFPanel.java
** okClicked()
** Consequences of checkIntValue changes
| | |
| | | addScheduleErrors(getSchedule(), errors, lExportOptions); |
| | | if (wrapText.isSelected()) |
| | | { |
| | | String cols = wrapColumn.getText(); |
| | | int minValue = 1; |
| | | int maxValue = 1000; |
| | | LocalizableMessage errMsg = ERR_CTRL_PANEL_INVALID_WRAP_COLUMN.get(minValue, |
| | | maxValue); |
| | | int size1 = errors.size(); |
| | | checkIntValue(errors, cols, minValue, maxValue, errMsg); |
| | | if (errors.size() > size1) |
| | | final String cols = wrapColumn.getText(); |
| | | final int minValue = 1; |
| | | final int maxValue = 1000; |
| | | final LocalizableMessage errMsg = ERR_CTRL_PANEL_INVALID_WRAP_COLUMN.get(minValue, maxValue); |
| | | if (!checkIntValue(errors, cols, minValue, maxValue, errMsg)) |
| | | { |
| | | setPrimaryInvalid(lExportOptions); |
| | | } |
| | |
| | | */ |
| | | public class NewBaseDNPanel extends StatusGenericPanel |
| | | { |
| | | private static final int MAX_ENTRIES_NUMBER_GENERATED = 1000; |
| | | private static final int MAX_ENTRIES_NUMBER_GENERATED_LOCAL = 20000; |
| | | private static final long serialVersionUID = -2680821576362341119L; |
| | | private static final LocalizableMessage NEW_BACKEND_TEXT = INFO_CTRL_PANEL_NEW_BACKEND_LABEL.get(); |
| | | |
| | |
| | | { |
| | | if (importAutomaticallyGenerated.isSelected()) |
| | | { |
| | | String nEntries = numberOfEntries.getText(); |
| | | int minValue = 1; |
| | | int maxValue = isLocal() ? 20000 : 1000; |
| | | LocalizableMessage errMsg = ERR_NUMBER_OF_ENTRIES_INVALID.get(minValue, maxValue); |
| | | checkIntValue(errors, nEntries, minValue, maxValue, errMsg); |
| | | final int minValue = 1; |
| | | final int maxValue = isLocal() ? MAX_ENTRIES_NUMBER_GENERATED_LOCAL |
| | | : MAX_ENTRIES_NUMBER_GENERATED; |
| | | final LocalizableMessage errorMsg = ERR_NUMBER_OF_ENTRIES_INVALID.get(minValue, maxValue); |
| | | if (!checkIntValue(errors, numberOfEntries.getText(), minValue, maxValue, errorMsg)) |
| | | { |
| | | setSecondaryInvalid(lNumberOfEntries); |
| | | } |
| | | } |
| | | } |
| | | |
| | |
| | | /** |
| | | * Checks that the provided string value is a valid integer and if it is not |
| | | * updates a list of error messages with an error. |
| | | * @param errors the list of error messages to be updated. |
| | | * @param stringValue the string value to analyze. |
| | | * @param minValue the minimum integer value accepted. |
| | | * @param maxValue the maximum integer value accepted. |
| | | * @param errMsg the error message to use to update the error list if the |
| | | * provided value is not valid. |
| | | * |
| | | * @param errors |
| | | * the list of error messages to be updated. |
| | | * @param stringValue |
| | | * the string value to analyze. |
| | | * @param minValue |
| | | * the minimum integer value accepted. |
| | | * @param maxValue |
| | | * the maximum integer value accepted. |
| | | * @param errMsg |
| | | * the error message to use to update the error list if the provided |
| | | * value is not valid. |
| | | * @return {@code true} if the provided string value is a valid integer and if |
| | | * it is not updates a list of error messages with an error. |
| | | */ |
| | | protected void checkIntValue(Collection<LocalizableMessage> errors, String stringValue, |
| | | protected boolean checkIntValue(Collection<LocalizableMessage> errors, String stringValue, |
| | | int minValue, int maxValue, LocalizableMessage errMsg) |
| | | { |
| | | try |
| | | { |
| | | int n = Integer.parseInt(stringValue); |
| | | if (n > maxValue || n < minValue) |
| | | if (minValue <= n && n <= maxValue) |
| | | { |
| | | throw new RuntimeException("Invalid value"); |
| | | return true; |
| | | } |
| | | } |
| | | catch (Throwable t) |
| | | { |
| | | catch (NumberFormatException ignored) {} |
| | | |
| | | errors.add(errMsg); |
| | | } |
| | | return false; |
| | | } |
| | | |
| | | /** |