001    package stringtransformers;
002    
003    import cs101.io.Console;
004    
005    public class WordSplitter extends StringTransformer
006    {
007      public WordSplitter ()
008      {
009        super();
010      }
011    
012      private String line;
013    
014      public void act () 
015      {
016        
017        if ( ( this.in != null ) && ( this.out != null ) )
018          {
019            
020            if (( this.line == null ) || ( this.line == "" ))
021              {
022                this.line = this.in.readInput();
023                Console.println( this + " reading a new line" );
024              }
025    
026            int splitPos = this.line.indexOf( ' ' );
027            String word;
028    
029            if ( splitPos < 0 )
030              {
031                word = this.line;
032                this.line = null;
033              }
034            else 
035              {
036                word = this.line.substring( 0, splitPos );
037                this.line = this.line.substring( splitPos ).trim();
038              }
039            this.out.writeOutput( this.transform( word ) );
040          }
041      }
042    
043      public String transform ( String input ) {
044        return input;
045      }
046    }
047