Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members  

Validatable.java

Go to the documentation of this file.
00001 package net.threebit.utils.sosc ; 
00002 
00008 public abstract class Validatable {   
00009 
00013         private final String type;
00014 
00018         protected final String number;
00019 
00023         private boolean isValid;
00024 
00029         private boolean validated;    
00030 
00037         public String getNumber() {
00038                 return number;
00039         }
00040 
00047         public String getType() {
00048                 return type;
00049         }
00050 
00057         public String toString() {
00058                 return number;
00059         }
00060 
00068         protected Validatable(final String num, final String typ) {        
00069                 number = num;
00070                 type = typ;
00071         }
00072 
00080         public boolean equals(Object o)
00081         {
00082                 final Validatable other;          
00083                 other = (Validatable)o;
00084                 return ((number.compareTo(other.number) == 0));
00085         }
00086 
00094         public final boolean validate()
00095         {         
00096                 if (!validated)
00097                 {       
00098                         validated = true;
00099 
00100                         if ((!checkSize()) || (!checkPrefix()))
00101                         {               
00102                                 isValid = false;
00103                         }            
00104                         else
00105                         {
00106                                 isValid = checkDigits(Utils.toDigits(number));
00107                         }            
00108                 }
00109                 return isValid;
00110         }     
00111 
00120         protected boolean checkPrefix()
00121         {
00122                 return (true);
00123         }
00124 
00131         protected abstract boolean checkSize();
00132         protected abstract boolean checkDigits(int[] digits);    
00133 }

Generated on Mon Jul 14 17:19:20 2003 for SOSC by doxygen1.2.15