예제 #1
0
  /** testowanie przykładowego zadania */
  static void anagramTest() {
    Matcher<Integer> odd =
        new Predicate<Integer>() {
          public boolean apply(Integer item) {
            return item % 2 == 1;
          }
        };

    long l1 = System.nanoTime();
    isAnagramOfPalindrome("ZAble was I ere I saw ElbaZ".toLowerCase().replace(" ", ""));
    long l2 = System.nanoTime();
    System.out.println(
        "result : "
            + isAnagramOfPalindrome("ZAble was I ere I saw ElbaZ".toLowerCase().replace(" ", "")));
    System.out.println(
        "result : "
            + isAnagramOfPalindrome("Rats live on no evil star".toLowerCase().replace(" ", "")));
    System.out.println("result : " + isAnagramOfPalindrome("kayak"));
    System.out.println("result : " + isAnagramOfPalindrome("rraattsslliivveeoonn"));

    System.out.println("=======================================");
    long l3 = System.nanoTime();
    isAnagram_lambda("ZAble was I ere I saw ElbaZ".toLowerCase().replace(" ", ""), odd);
    long l4 = System.nanoTime();
    System.out.println(
        "result : "
            + isAnagram_lambda("ZAble was I ere I saw ElbaZ".toLowerCase().replace(" ", ""), odd));
    System.out.println(
        "result : "
            + isAnagram_lambda("Rats live on no evil star".toLowerCase().replace(" ", ""), odd));
    System.out.println("result : " + isAnagram_lambda("kayak", odd));
    System.out.println("result : " + isAnagram_lambda("rraattsslliivveeoonn", odd));

    System.out.println("lambda/classic : " + (l4 - l3) / (l2 - l1));
  }
예제 #2
0
  /**
   * Łączenie list w jeden łańcuch znakowy
   *
   * @param p lista osób do połączenia
   */
  public static void joinStrings(List<Person> p) {
    long l1 = System.nanoTime();
    String s1 = "";
    for (Person p1 : p) {
      s1 += p1.toString() + "\n";
    }
    long l2 = System.nanoTime();

    // System.out.println(s1);
    // System.out.println("================================================");

    long l3 = System.nanoTime();
    String s2 = joinFrom(p, "\n").toString();
    long l4 = System.nanoTime();
    // System.out.println(s2);

    System.out.println("lambda/classic : " + (l4 - l3) / (l2 - l1));
  }
예제 #3
0
  /**
   * Ekstraktownie zadanej własności do listy
   *
   * @param p
   */
  public static void extraktowanie(List<Person> p) {
    long l1 = System.nanoTime();
    List<String> names1 = new ArrayList<String>();
    for (Person pers : p) {
      names1.add(pers.getName());
    }
    long l2 = System.nanoTime();

    long l3 = System.nanoTime();
    List<String> names2 = extract(p, on(Person.class).getName());
    long l4 = System.nanoTime();

    //		StartLambda.print.each(names1);
    //		System.out.println("===============================================");
    //		StartLambda.print.each(names2);
    //		System.out.println("===============================================");

    System.out.println("lambda/classic : " + (((double) (l4 - l3)) / ((double) (l2 - l1))));
  }
예제 #4
0
  /**
   * sortowanie, klasyczny sposób - sortowanie przez wstawianie - najbardziej przewidywalny algorytm
   *
   * @param p
   */
  public static void sortowanie(List<Person> p) {
    // ArrayList<Object> p1 = new ArrayList<Object>((index(p, on(Person.class).getName() )).values()
    // );
    // ArrayList<Object> p2 = new ArrayList<Object>((index(p, on(Person.class).getName() )).values()
    // );
    ArrayList<Person> p1 = new ArrayList<Person>(p);
    ArrayList<Person> p2 = new ArrayList<Person>(p);

    List<Person> ps2 = null;

    // klasyczne sortowanie przez wstawianie

    StartLambda.print.each(p1);
    System.out.println("===============================================");

    long l1 = System.nanoTime();
    for (int i = 0; i < p1.size(); i++) {
      // System.out.println(((Person)p1.get(i)).getName());
      // System.out.println("==");
      for (int j = i; j > 0; j--) {
        if (((Person) p1.get(j - 1)).getName().compareTo(((Person) p1.get(j)).getName()) > 0) {
          Person tmp = (Person) p1.get(j - 1);
          p1.set(j - 1, p1.get(j));
          p1.set(j, tmp);
        }
      }
    }
    long l2 = System.nanoTime();

    System.out.println("===============================================");
    StartLambda.print.each(p1);
    System.out.println("===============================================");

    long l3 = System.nanoTime();
    ps2 = sort(p2, on(Person.class).getName());
    long l4 = System.nanoTime();

    StartLambda.print.each(ps2);

    System.out.println("lambda/classic : " + (((double) (l4 - l3)) / ((double) (l2 - l1))));
  }