/** 
 * Ilustracni priklad na metody tridy String
 * prace s s retezci
 * @author netrvalo&spol
 */

public class StringPresentation {
   /**
   * Ilustruje praci s retezci metodami tridy String
   * @param args nepouzito
   * <p> Oproti zvyklostem jsou pouzity identifikatory promennych 
   *      reprezentujici osobni jmena s pocatecnimi velkymi pismeny
   * </p>
   */
  public static void main(String[] args) {
    String othelo = "othelo";
    String Othelo = "Othelo";
    String Desdemona = "Desdemona";
    System.out.println("CompareTo othelo & Othelo: " + othelo.compareTo(Othelo));
    System.out.println("CompareToIgnoreCase othelo & Othelo: " + othelo.compareToIgnoreCase(Othelo));
    System.out.println("Equals othelo & Othelo: " + othelo.equals(Othelo));
    System.out.println("EqualsIgnoreCase othelo & Othelo: " + othelo.equalsIgnoreCase(Othelo));     
    
    System.out.println("Concat Othelo & Desdemona: " + Othelo.concat(" & " + Desdemona));     
    
    String OTHELO = Othelo.toUpperCase();
    System.out.println(OTHELO);
    
    System.out.println("Desdemona:");
    System.out.println("Znak na indexu 6: " + Desdemona.charAt(6));
    System.out.println("Index pismene e: " + Desdemona.indexOf('e'));
    
    int pocet = 0;
    int index;
    String d = Desdemona.toUpperCase();
    while ((index = d.indexOf('D')) != -1) {
      pocet++;
      d = d.substring(index+1);
    }
    System.out.println("Pocet vyskytu pismene D,d = " + pocet);
       
    String Jago = "  \tJago\n"; // oriznuti bilych znaku
    System.out.print(Jago);
    System.out.println(Jago.trim());
    
    String _63 = "63";
    int cislo = Integer.parseInt(_63);
    System.out.println("cislo = " + cislo);
    cislo++;
    System.out.println("cislo = " + cislo);
    String _64 = "" + cislo;
    System.out.println(_64);
    
    System.out.println("Znak na indexu 0: " + _64.charAt(0));
    System.out.println("Znak na indexu 0 je cislice? " + Character.isDigit(_64.charAt(0)));
    
    cislo = Integer.parseInt(_63, 16);
    System.out.println("cislo 63(16) = " + cislo + "(10)");
    
    System.out.println("\n ============= NECO NAVIC, CO NA PREDNASCE NEBYLO =============");
    
    System.out.println("\n TRIDA StringBuffer = tzv. menitelny retezec (pouziva jine metody)\n");
    
    StringBuffer spojeni = new StringBuffer(Desdemona + " & ");
    System.out.println(spojeni);
    System.out.println("spojeni.append(Othelo): " + spojeni.append(Othelo));
    System.out.println("Nahrazeni: " + spojeni.replace(9,12," nebo "));
    System.out.println("Delka = " + spojeni.length());
    
    StringBuffer obraceni = new StringBuffer("Kobylamamalybok");
    System.out.println("Obraceni Kobylamamalybok: " + obraceni.reverse());
    
    StringBuffer Desdemonka = new StringBuffer(Desdemona);
    Desdemonka.insert(8, 'K');
    System.out.println("Vlozeni K Desdemonka.insert(8, 'K'): " + Desdemonka);
    Desdemonka.deleteCharAt(8);
    System.out.println("Vypusteni K Desdemonka.deleteCharAt(8): " + Desdemonka);
    
    System.out.println("Character.isDigit(Desdemonka.charAt(0)): " + Character.isDigit(Desdemonka.charAt(0)));
    System.out.println("Character.isLetter: " + Character.isLetter(Desdemonka.charAt(0)));
    System.out.println("Character.isLetterOrDigit: " + Character.isLetterOrDigit(Desdemonka.charAt(0)));
    System.out.println("Character.isLowerCase: " + Character.isLowerCase(Desdemonka.charAt(0)));
    System.out.println("Character.isUpperCase: " + Character.isUpperCase(Desdemonka.charAt(0)));
    System.out.println("Character.isWhitespace: " + Character.isWhitespace(Desdemonka.charAt(0)));
    
  }
}