Coverage Report - org.jtheque.core.utils.ui.constraints.NotNullConstraint
 
Classes in this File Line Coverage Branch Coverage Complexity
NotNullConstraint
0 %
0/10
0 %
0/2
1.167
 
 1  
 package org.jtheque.core.utils.ui.constraints;
 2  
 
 3  
 import org.jtheque.core.managers.Managers;
 4  
 import org.jtheque.core.managers.error.InternationalizedError;
 5  
 import org.jtheque.core.managers.error.JThequeError;
 6  
 import org.jtheque.core.managers.language.ILanguageManager;
 7  
 
 8  
 import java.util.Collection;
 9  
 
 10  
 /*
 11  
  * This file is part of JTheque.
 12  
  *
 13  
  * JTheque is free software: you can redistribute it and/or modify
 14  
  * it under the terms of the GNU General Public License as published by
 15  
  * the Free Software Foundation, either version 3 of the License.
 16  
  *
 17  
  * JTheque is distributed in the hope that it will be useful,
 18  
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
 19  
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 20  
  * GNU General Public License for more details.
 21  
  *
 22  
  * You should have received a copy of the GNU General Public License
 23  
  * along with JTheque.  If not, see <http://www.gnu.org/licenses/>.
 24  
  */
 25  
 
 26  
 /**
 27  
  * A constraint to indicate that the field cannot be null.
 28  
  *
 29  
  * @author Baptiste Wicht
 30  
  */
 31  
 public final class NotNullConstraint implements Constraint {
 32  
     private final String fieldName;
 33  
 
 34  
     /**
 35  
      * Construct a new NotNullConstraint.
 36  
      *
 37  
      * @param fieldName The field name.
 38  
      */
 39  
     public NotNullConstraint(String fieldName) {
 40  0
         super();
 41  
 
 42  0
         this.fieldName = fieldName;
 43  0
     }
 44  
 
 45  
     @Override
 46  
     public int maxLength() {
 47  0
         return -1;
 48  
     }
 49  
 
 50  
     @Override
 51  
     public boolean mustBeNumerical() {
 52  0
         return false;
 53  
     }
 54  
 
 55  
     @Override
 56  
     public boolean canBeNullOrEmpty() {
 57  0
         return false;
 58  
     }
 59  
 
 60  
     @Override
 61  
     public boolean mustControlLength() {
 62  0
         return false;
 63  
     }
 64  
 
 65  
     @Override
 66  
     public void validate(Object field, Collection<JThequeError> errors) {
 67  0
         if (field == null) {
 68  0
             errors.add(new InternationalizedError("error.validation.field.empty", new Object[]{Managers.getManager(ILanguageManager.class).getMessage(fieldName)}));
 69  
         }
 70  0
     }
 71  
 }