package quiniela; import quiniela.PartidoValidado; import java.util.*; import java.io.*; public class Quiniela { Vector partidos= new Vector(); int cursorPartido = -1; public void setInputFile ( String _fn ) throws FileNotFoundException, IOException { BufferedReader is = new BufferedReader( new FileReader( _fn )); String s; while( ( s = is.readLine() ) != null ) { PartidoValidado estePartido = new PartidoValidado(); StringTokenizer st = new StringTokenizer( s, "-" ); estePartido.setJuegaEnCasa( (String) st.nextToken() ); estePartido.setJuegaFuera( (String) st.nextToken() ); partidos.add( estePartido ); // System.out.println( "Insertando : " + estePartido.getAsString() ); // System.out.println( "Partidos.size " + partidos.size() ); } } public int getNumPartidos() { return partidos.size(); } public void setNumPartido( int _i ) { cursorPartido = _i; } public void setJuegaEnCasa( String _s ) throws ArrayIndexOutOfBoundsException{ if (cursorPartido >= 0 && cursorPartido <= partidos.size() ) { ((PartidoValidado) partidos.get( cursorPartido )).setJuegaEnCasa( _s ); } else { throw new ArrayIndexOutOfBoundsException ( "No se ha puesto el cursor de partido: " + cursorPartido ); } } public String getJuegaEnCasa() throws ArrayIndexOutOfBoundsException{ if (cursorPartido >= 0 && cursorPartido <= partidos.size() ) { return ((PartidoValidado)partidos.get( cursorPartido )).getJuegaEnCasa(); } else { throw new ArrayIndexOutOfBoundsException ( "No se ha puesto el cursor de partido" ); } } public void setJuegaFuera( String _s ) throws ArrayIndexOutOfBoundsException{ if (cursorPartido >= 0 && cursorPartido <= partidos.size() ) { ((PartidoValidado) partidos.get( cursorPartido )).setJuegaFuera( _s ); } else { throw new ArrayIndexOutOfBoundsException ( "No se ha puesto el cursor de partido: " + cursorPartido ); } } public String getJuegaFuera() throws ArrayIndexOutOfBoundsException{ if (cursorPartido >= 0 && cursorPartido <= partidos.size() ) { return ((PartidoValidado)partidos.get( cursorPartido )).getJuegaFuera(); } else { throw new ArrayIndexOutOfBoundsException ( "No se ha puesto el cursor de partido" ); } } public boolean[] getPronostico() throws ArrayIndexOutOfBoundsException{ if (cursorPartido >= 0 && cursorPartido <= partidos.size() ) { return ((PartidoValidado)partidos.get( cursorPartido )).getPronostico(); } else { throw new ArrayIndexOutOfBoundsException ( "No se ha puesto el cursor de partido" ); } } public void setPronostico( boolean[] _b ) throws ArrayIndexOutOfBoundsException{ if (cursorPartido >= 0 && cursorPartido <= partidos.size() ) { ((PartidoValidado)partidos.get( cursorPartido )).setPronostico( _b ); } else { throw new ArrayIndexOutOfBoundsException ( "No se ha puesto el cursor de partido" ); } } public void setPronosticoAsString( String _s ) throws ArrayIndexOutOfBoundsException, RuntimeException{ // System.out.println( "Partidos.size " + partidos.size() ); _s = _s.toUpperCase(); // System.out.println( _s ); if ( ( cursorPartido >= 0 ) && ( cursorPartido <= partidos.size()) ) { try { ((PartidoValidado)partidos.get( cursorPartido )).setPronosticoAsString( _s ); } catch ( Exception _e ) { System.err.println( "Error en setPronosticoAsString: " + _e.getMessage() ); } } else { throw new ArrayIndexOutOfBoundsException ( "Error en setPronosticoAsString: No se ha puesto el cursor de partido" + cursorPartido ); } } public void setPronosticosAsArray( String[] _a ){ for ( int i = 0; i < _a.length; i ++ ) { ((PartidoValidado)partidos.get( i ) ).setPronosticoAsString( _a[i] ); // System.out.println( "Insertando : " + estePartido.getAsString() ); } } public String getPronosticoAsString() throws ArrayIndexOutOfBoundsException { if (cursorPartido >= 0 && cursorPartido <= partidos.size() ) { return ((PartidoValidado)partidos.get( cursorPartido )).getPronosticoAsString( ); } else { throw new ArrayIndexOutOfBoundsException ( "No se ha puesto el cursor de partido" ); } } public String getAsString() { Iterator it = partidos.iterator(); String s=""; while (it.hasNext() ) { PartidoValidado estePartido = (PartidoValidado)it.next(); s += estePartido.getAsString() + '\n'; } return s; } }