コード例 #1
1
  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
  }
コード例 #2
1
  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);

    */

  }
コード例 #3
1
ファイル: List.java プロジェクト: rcoley93/coursework
 public List concat(List L) {
   List lstOld = this.copy();
   for (int i = 0; i < L.length(); i++) {
     L.moveTo(i);
     lstOld.append(L.getElement());
   }
   return lstOld;
 }
コード例 #4
1
ファイル: MohairMIDlet.java プロジェクト: phamtuanchip/labs
  public void startApp() {
    if (mDisplay == null) {
      mDisplay = Display.getDisplay(this);
    }

    if (mMenu == null) {
      mMenu = new List("MohairMIDlet", List.IMPLICIT);
      mMenu.append(kQuerySlots, null);
      mMenu.append(kSignTest, null);

      mBackCommand = new Command("Back", Command.BACK, 0);
      mExitCommand = new Command("Exit", Command.EXIT, 0);

      mMenu.addCommand(mExitCommand);
      mMenu.setCommandListener(this);
    }

    mDisplay.setCurrent(mMenu);
  }
コード例 #5
1
  public void commandAction(Command command, Item item) {
    if (recentList.isEmpty()) return;
    parentView = display.getCurrent();

    cmdBack = new Command(SR.MS_BACK, Command.BACK, 99);
    cmdSelect = new Command(SR.MS_SELECT, Command.OK, 1);
    cmdClear = new Command(SR.MS_CLEAR, command.SCREEN, 2);

    list = new List(label, List.IMPLICIT);
    list.addCommand(cmdBack);
    list.addCommand(cmdClear);
    list.setSelectCommand(cmdSelect);

    for (Enumeration e = recentList.elements(); e.hasMoreElements(); )
      list.append((String) e.nextElement(), null);

    list.setCommandListener(this);
    display.setCurrent(list);
  }
コード例 #6
1
ファイル: NGCalc.java プロジェクト: revzin/ngcalc
  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();
      }
    }
  }
コード例 #7
0
 public FileAttributes addTag(String tag) {
   return new FileAttributes(user, group, mode, tags.append(single(tag)));
 }
コード例 #8
0
ファイル: FunType.java プロジェクト: clklein/unsafe-imp-poly
 public List<TypeVar> typeVars() {
   List<TypeVar> domTVs = domain.typeVars();
   List<TypeVar> codomTVs = codomain.typeVars();
   return List.append(domain.typeVars(), List.removeAll(codomTVs, domTVs));
 }