public static void main(String[] args) {
    System.out.println("ListTest Compiled and running");

    List A = new List();
    List B = new List();

    for (int i = 1; i <= 20; i++) {
      A.append(i);
      B.prepend(i);
    }
    System.out.println(A);
    System.out.println(B);

    for (A.moveTo(0); A.getIndex() >= 0; A.moveNext()) {
      System.out.print(A.getElement() + " ");
    }
    System.out.println();
    for (B.moveTo(B.length() - 1); B.getIndex() >= 0; B.movePrev()) {
      System.out.print(B.getElement() + " ");
    }
    System.out.println();

    /*List C = A.copy();
    System.out.println(A.equals(B));
    System.out.println(B.equals(C));
    System.out.println(C.equals(A));*/

    A.moveTo(5);
    A.insertBefore(-1);
    A.moveTo(15);
    A.insertAfter(-2);
    A.moveTo(10);
    A.delete();
    System.out.println(A);
    A.clear();
    System.out.println(A.length());

    /*
    	List A = new List();
        List B = new List();
        List D = new List();

    	System.out.println(A.equals(D));
    	A.moveTo(5);
        System.out.println(D.equals(A));


        for(int i=1; i<=20; i++){
             A.append(i);
             B.prepend(i);
             D.append(i);
          }

          System.out.println(A);
          System.out.println(B);

    */

  }
  private static void command(String input) {

    if (commander.equals("PRINT")) {
      movieList.printListAll(movieList);
    } else if (commander.equals("SEARCH")) {
      keyword = genre;
      // 리스트 중 keyword 를 포함하는 것이 있으면 다 출력한다.
      movieList.search(keyword);
    } else if (commander.equals("INSERT")) {
      movieList.insert(genre, title);
    } else if (commander.equals("DELETE")) {
      movieList.delete(genre, title);
    }
  }
  public static void main(String args[]) {
    List A = new List();
    for (int i = 1; i < 16; i++) {
      A.append(i);
    }
    System.out.println(A.toString());
    System.out.println(A.length());
    List B = new List();
    for (A.moveTo(0); A.getIndex() > -1; A.moveNext()) {
      B.prepend(A.getElement());
    }
    System.out.println(B.toString());
    System.out.println(B.length());
    System.out.println((int) A.front() + (int) B.front());
    System.out.println(A.back() == B.back());
    System.out.println(A.equals(B));
    System.out.println(A.equals(A));
    A.clear();
    System.out.println(A.length());
    A.append(3);
    A.prepend(1);
    A.prepend(1);
    A.append(7);
    A.moveTo(3);
    A.insertAfter(8);
    A.insertBefore(5);
    A.moveNext();
    A.insertAfter(13);
    A.movePrev();
    A.delete();
    System.out.println(A.toString());
    A.deleteFront();
    A.deleteBack();
    System.out.println(A.toString());

    // Should output:
    // 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
    // 15
    // 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1
    // 15
    // 16
    // false
    // false
    // true
    // 0
    // 1 1 3 5 8 13
    // 1 3 5 8
  }
Exemple #4
1
  public void commandAction(Command command, Displayable displayable) {
    if ((displayable == D_MAIN) && D_MAIN.Responds()) {
      if (command == c_exit) {
        exitMIDlet();
      }
      if (command == c_history) {
        switchDisplayable(null, getL_history());
        Stack st = D_MAIN.getEqHS();
        Enumeration en = st.elements();
        l_history.deleteAll();
        while (en.hasMoreElements()) {
          l_history.append((String) en.nextElement(), null);
        }
      }
      if (command == c_tovars) {
        getL_vars().deleteAll();
        StringBuffer sb;
        Enumeration values = D_MAIN.getEqVars().elements();
        Enumeration names = D_MAIN.getEqVars().keys();
        String name;
        Real value;
        while ((values.hasMoreElements()) && (names.hasMoreElements())) {
          name = String.valueOf(names.nextElement());
          value = new Real(String.valueOf((values.nextElement())));
          Real.NumberFormat n = new Real.NumberFormat();
          n.maxwidth = 17;
          n.fse = Real.NumberFormat.FSE_NONE;
          sb = new StringBuffer(value.toString(n));
          if (chartools.contains(sb, 'e')) {
            StringBuffer ev = new StringBuffer();
            for (int i = sb.length() - 1; i > -1; --i) {
              if (sb.charAt(i) == 'e') {
                sb.deleteCharAt(i);
                break;
              }
              ev.append(sb.charAt(i));
              sb.deleteCharAt(i);
            }
            ev.reverse();
            sb.append(" * 10^(" + ev + ")");
            if ((!(sb.equals(new StringBuffer(""))))
                && (!(name.equals("")))
                && (!(sb.equals(new StringBuffer("null"))))
                && (!(name.equals("null")))) {
              l_vars.append(name + " = " + sb.toString(), null);
            }
          } else {
            if ((!(sb.equals(new StringBuffer(""))))
                && (!(name.equals("")))
                && (!(sb.equals(new StringBuffer("null"))))
                && (!(name.equals("null")))) {
              getL_vars().append(name + " = " + sb.toString(), null);
            }
          }
        }
        switchDisplayable(null, getL_vars());
      }
    }
    if (displayable == f_welcome) {
      if (command == c_canvas) {
        switchDisplayable(null, D_MAIN);
      }
    } else if (displayable == form) {
      if (command == c_history) {

      } else if (command == c_tovars) {

      }
    } else if (displayable == l_history) {
      if (command == List.SELECT_COMMAND) {

        l_historyAction();

      } else if (command == c_canvas) {
        switchDisplayable(null, D_MAIN);

      } else if (command == c_insert) {

        if (l_history.size() != 0) {
          StringBuffer sb = new StringBuffer();
          String his = l_history.getString(l_history.getSelectedIndex());
          boolean p_end = false;
          for (int i = 0; i < his.length(); i++) {
            if (his.charAt(i) == '=') {
              break;
            }
            if (p_end) {
              sb.append(his.charAt(i));
            }
            if (his.charAt(i) == ':') {
              p_end = true;
            }
          }
          sb.deleteCharAt(sb.length() - 1);
          D_MAIN.appendDispCont(" " + sb.toString());
        }
        switchDisplayable(null, D_MAIN);
        D_MAIN.repaint();
      }
    } else if (displayable == l_vars) {
      if (command == List.SELECT_COMMAND) {

        l_varsAction();

      } else if (command == c_canvas) {
        switchDisplayable(null, D_MAIN);

      } else if (command == c_delvar) {
        try {
          StringBuffer sb = new StringBuffer();
          String his = l_vars.getString(l_vars.getSelectedIndex());
          for (int i = 0; i < his.length(); i++) {
            if (his.charAt(i) == '=') {
              break;
            }
            sb.append(his.charAt(i));
          }
          D_MAIN.deletevar(sb.toString().trim());
          l_vars.delete(l_vars.getSelectedIndex());
        } catch (error er) {
          switchDisplayable(null, getA_error());
          a_error.setString(er.getMessage());
        }

      } else if (command == c_insert) {
        StringBuffer sb = new StringBuffer();
        String his = l_vars.getString(l_vars.getSelectedIndex());
        for (int i = 0; i < his.length(); i++) {
          if (his.charAt(i) == '=') {
            break;
          }
          sb.append(his.charAt(i));
        }
        D_MAIN.appendDispCont(sb.toString());
        switchDisplayable(null, D_MAIN);

        D_MAIN.repaint();
      }
    }
  }