title: String token suffix replacement
body: <p>Have posted below a method I've written for suffix replacement of string tokens.</p>
  
  <pre><code>public static String suffix_replacement(String string) {
      String[] tokens = string.split("\\s");
      String new_string = "";
      String suffix = "";
      String replacement = "";
  
      for (String token : tokens) {            
          suffix = GetElements.suffix_replacement_map.containsKey(getSuffix(token, 7)) ? getSuffix(token, 7) : 
                  GetElements.suffix_replacement_map.containsKey(getSuffix(token, 6)) ? getSuffix(token, 6) : 
                  GetElements.suffix_replacement_map.containsKey(getSuffix(token, 5)) ? getSuffix(token, 5) : 
                  GetElements.suffix_replacement_map.containsKey(getSuffix(token, 4)) ? getSuffix(token, 4) : 
                  GetElements.suffix_replacement_map.containsKey(getSuffix(token, 3)) ? getSuffix(token, 3) : "";  
  
          replacement = suffix.equals("") ? "" : GetElements.suffix_replacement_map.get(suffix);
  
          if (!suffix.equals("")) 
              token = token.substring(0, token.length()-suffix.length())+replacement;
  
          new_string += token+" ";
      }
  
      new_string = new_string.trim();
  
      if (!new_string.equals(string)) {
          System.out.println(string);
          System.out.println(new_string);
      }        
      return new_string;
  }
  </code></pre>
  
  <hr>
  
  <pre><code>Test case 1
  
  string: hemisphere hemorrhage
  
  new_string: hemisphere hemorrh
  
  It works fine.
  </code></pre>
  
  <hr>
  
  <pre><code>Test case 2:
  
  string: cardiac arrhythmia
  
  new_string: arrhythmia
  
  It does not give desired string.
  </code></pre>
  
  <hr>
  
  <p>The function seems to return incorrect <code>Strings</code> if any token other than the last token in the <code>String</code> gets a suffix replacement.</p>
  
  <p>Appreciate any help with locating the bug in the function. </p>
  
  <p>Thank you.</p>
  
  <hr>
  
  <p>Added Info:</p>
  
  <p>suffix_replacement_map is populated with contents below:</p>
  
  <pre>
  tic:sis
  sis:tic
  oneal:ineum
  age:
  cular:cal
  cardiac:cardia
  nic:nia
  ages:ed
  evi:evus
  cular:cal
  cardiac:cardia
  nic:nia
  ages:ed
  evi:evus
  tachy:tachicardia
  cral:crum
  cancer:carcinoma
  sillar:sil
  </pre>
  
  <hr>
  
  <p>Function used:</p>
  
  <pre><code>public static String getSuffix(String str, int len) {
      if (str.length() &lt; len) {
          return "";
      }
      return str.substring(str.length() - len);
  }   
  </code></pre>