Back to project page Joetz-Android-V2.
The source code is released under:
GNU General Public License
If you think the Android project Joetz-Android-V2 listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.example.jens.myapplication.domain.validator; //from w ww . ja v a2s .c o m import com.example.jens.myapplication.R; import java.util.List; /** * Validator class, to validate objects * * A list of Resource IDs for String resources is filled up while validating an object. * After that ErrorConverter class can be used to convert this list of IDs to a nice * list of errors, separated by a newline. */ public abstract class Validator<T> { protected T obj; public Validator(T obj){ setObj(obj); } /** * * @return The object attached to this validator */ public T getObj(){ return obj; } /** * Set the object attached to the validator * @param obj */ public void setObj(T obj){ this.obj = obj; } /** * Helpmethod: <br /> * Add an error if the value is null * @param errors The list of errors * @param value The value to be validated * @return The list of errors */ protected List<Integer> fillIsNull(List<Integer> errors, Object value){ if(value == null){ errors.add(R.string.$_need_filled_in); } return errors; } /** * Helpmethod: <br /> * Add an error if the String is null or empty * @param list The list of errors * @param value The String object to be validated * @return The list of errors */ protected List<Integer> fillIsNullOrEmpty(List<Integer> list, String value){ if(value == null || value.isEmpty()){ list.add(R.string.$_need_filled_in); } return list; } /** * Will return the list if the size is larger than 0<br /> * So that when the list is empty, null should be returned rather than an empty list * @param list * @return */ protected List<Integer> getReturn(List<Integer> list){ if(list.size() > 0){ return list; } return null; } }