package com.tutego.insel.solutions.util;

import java.util.*;

public class WordFilter
{
  private HashMap<String, String> hm = new HashMap<String, String>();

  public void addWordPair( String find, String replace )
  {
    if ( find != null && replace != null )
      hm.put( find, replace );
  }

  public String replace( String s )
  {
    StringTokenizer st = new StringTokenizer( s );
    String sReturn = "";

    while ( st.hasMoreTokens() )
    {
      String sToken = st.nextToken();
      Object hashVal = hm.get( sToken );

      sReturn += (hashVal == null ? sToken : hashVal) + " ";
    }

    return sReturn.trim();
  }

  public static void main( String args[] )
  {
    WordFilter wf = new WordFilter();
    wf.addWordPair( "doof", "unschlau" );
    wf.addWordPair( "pfusch", "unguenstig" );

    System.out.println( wf.replace( "Das Programm ist doof und das ist alles pfusch" ) );
  }
}
