Bonjour,
j'ai trouvé cette classe et j'essaie de savoir à quoi elle sert mais j'ai du mal. Quelqu'un peut m'expliquer à quoi elle sert?
Pourquoi il y a deux constructeurs StringInterval?
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51 package datavalidations; import datavalidations.exceptions.DataValidationException; import datavalidations.exceptions.StringFieldException; public class StringInterval { public final static int NULLABLE=0; public final static int NOT_NULL=1; public final static int NOT_NULL_NOR_EMPTY=2; protected String fieldName; protected int mode; protected int maxSize=0; public StringInterval(String fieldName,int mode) { this.fieldName=fieldName; this.mode=mode; } public StringInterval(String fieldName,int mode,int maxSize) { this(fieldName,mode); this.maxSize=maxSize; } public int getMaxSize() { return maxSize; } public boolean isValid(String value) { boolean retValue=true; if(mode==NULLABLE) { retValue=(value==null)||((value!=null)&&(value.length()<=maxSize)); } else if(mode==NOT_NULL) { retValue=(value!=null && value.length()<=maxSize); } else if(mode==NOT_NULL_NOR_EMPTY) { retValue=(value!=null)&&(!value.trim().equals(""))&&value.length()<=maxSize; } return retValue; } public void check(String value)throws DataValidationException { if(!isValid(value))throw new StringFieldException(fieldName); } }
Merci de votre aide
Partager