1.- por tanto hay que crear un archivo properties el cual contenga las restricciones
apellidoL = 20
edadL = 2
telefonoL = 8
#espacio (Espa)
nombreS =Espa
apellidoS =Espa
edadS = 0
telefonoS =Espa
2.- modificamos el constructor de nuestra clase Bean
creamos una variable properties y en el contructor
Properties properties;
public Bean() {
properties = new Properties();
FileInputStream fis = null;
try {
fis = new FileInputStream("rutaProperties"+File.separator+"propiedades.properties");
properties.load(fis);
} catch (FileNotFoundException e) {
System.out.println("Archivo de configuracion no encontrado ");
} catch (IOException e) {
System.out.println("No se pudo leer el archivo");
}
}
3.- modificamos nuestros metodos set, solo pondre el ejemplo de 1
public void setNombre(String nombre) {
if(nombre==null){
nombre = " ";
}
else if(nombre.length()<Integer.parseInt ( properties.getProperty( nombreL ) ) ){
do{
if(properties.getProperty( nombreL ) .equals("Espa")){
nombre = nombre.concat(" ");
}else{
nombre = properties.getProperty( nombreL );
}
}while(nombre.length()<=Integer.parseInt ( properties.getProperty( nombreL ) ) );
}
if(nombre.length()>Integer.parseInt ( properties.getProperty( nombreL ) ) ){
nombre = nombre.substring(0,Integer.parseInt ( properties.getProperty( nombreL ) ) );
}
this.nombre = nombre;
}
NOTA: SI OBSERVAMOS AHORA LA INFORMACION LA TOMAMOS DEL PROPERTIES, Y EL SEGUNDO ELSE IF, CAMBIA A IF, ESTO POR QUE TAL VES NUESTRO SEPARADOR QUE HEMOS CREADO ES DE MAS DE 1 CARACTER
YA HA CAMBIADO LA APLICACION, YA NO TENEMOS QUE RECOMPILAR LA APLICACION PARA CUANDO CAMBIAN LAS LONGITUDES, PERO AUN SIGUE SIN GUSTARME, ADEMAS SI DEPENDEMOS DE OTRAS REGLAS COMO ALINEAR A ALGUN LADO, PS SALE LO MISMO
SEGUIREMOS MODIFICANDO EL CODIGO...
No hay comentarios:
Publicar un comentario