Browse Source

Amend some validators to cope with null. Add validatable interface.

Change-Id: Ic952dfc1c8d2d25da366445d0f40bf573cb76c39
Reviewed-on: http://gerrit.dmdirc.com/2237
Reviewed-by: Chris Smith <chris@dmdirc.com>
Automatic-Compile: DMDirc Build Manager
tags/0.7rc1
Greg Holmes 12 years ago
parent
commit
7f34f9a7f7

+ 2
- 3
src/com/dmdirc/util/validators/FileNameValidator.java View File

35
     /** {@inheritDoc} */
35
     /** {@inheritDoc} */
36
     @Override
36
     @Override
37
     public ValidationResponse validate(final String object) {
37
     public ValidationResponse validate(final String object) {
38
-        if (object.matches(FILENAME_REGEX)) {
39
-            return new ValidationResponse();
40
-        } else {
38
+        if (object == null || !object.matches(FILENAME_REGEX)) {
41
             return new ValidationResponse(FAILURE_REASON);
39
             return new ValidationResponse(FAILURE_REASON);
42
         }
40
         }
41
+        return new ValidationResponse();
43
     }
42
     }
44
 }
43
 }

+ 2
- 3
src/com/dmdirc/util/validators/IdentValidator.java View File

36
     /** {@inheritDoc} */
36
     /** {@inheritDoc} */
37
     @Override
37
     @Override
38
     public ValidationResponse validate(final String object) {
38
     public ValidationResponse validate(final String object) {
39
-        if (object.matches(IDENT_REGEX)) {
40
-            return new ValidationResponse();
41
-        } else {
39
+        if (object == null || !object.matches(IDENT_REGEX)) {
42
             return new ValidationResponse(FAILURE_REASON);
40
             return new ValidationResponse(FAILURE_REASON);
43
         }
41
         }
42
+        return new ValidationResponse();
44
     }
43
     }
45
 }
44
 }

+ 3
- 3
src/com/dmdirc/util/validators/NicknameValidator.java View File

37
     /** {@inheritDoc} */
37
     /** {@inheritDoc} */
38
     @Override
38
     @Override
39
     public ValidationResponse validate(final String object) {
39
     public ValidationResponse validate(final String object) {
40
-        if (object.matches(NICKNAME_REGEX)) {
41
-            return new ValidationResponse();
42
-        } else {
40
+        if (object == null || !object.matches(NICKNAME_REGEX)) {
43
             return new ValidationResponse(FAILURE_REASON);
41
             return new ValidationResponse(FAILURE_REASON);
42
+        } else {
43
+            return new ValidationResponse();
44
         }
44
         }
45
     }
45
     }
46
 }
46
 }

+ 37
- 0
src/com/dmdirc/util/validators/Validatable.java View File

1
+/*
2
+ * Copyright (c) 2006-2010 Chris Smith, Shane Mc Cormack, Gregory Holmes
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to deal
6
+ * in the Software without restriction, including without limitation the rights
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ * copies of the Software, and to permit persons to whom the Software is
9
+ * furnished to do so, subject to the following conditions:
10
+ *
11
+ * The above copyright notice and this permission notice shall be included in
12
+ * all copies or substantial portions of the Software.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ * SOFTWARE.
21
+ */
22
+
23
+package com.dmdirc.util.validators;
24
+
25
+/**
26
+ * Marks a component as validatable.
27
+ */
28
+public interface Validatable {
29
+
30
+    /**
31
+     * Sets the validation response for a component.
32
+     *
33
+     * @param validation Validation response to show
34
+     */
35
+    void setValidation(ValidationResponse validation);
36
+
37
+}

Loading…
Cancel
Save