Exemplo n.º 1
0
 /** @see FunctionalList#rest() */
 @Override
 public FunctionalList rest() {
   if (size() == 0) {
     return new FunctionalArrayList();
   } else {
     FunctionalList tempList = new FunctionalArrayList();
     for (int i = 1; i < size(); i++) {
       tempList.add(get(i).getReturnValue());
     }
     return tempList;
   }
 }
  /**
   * Returns a list with the elements in this list except the head. The elements must be in the same
   * order. The original list must not change or be affected by changes in the new list.
   *
   * <p>If the list is empty, another empty list is returned.
   */
  public FunctionalList rest() {

    ErrorMessage error1 = errortype(0);
    FunctionalList list1 = new FunctionalLinkedList();

    if (error1.equals(ErrorMessage.NO_ERROR)) {
      // list1.setList(this.getList());
      list1.remove(0);
      return list1;
    } else {
      return list1;
    }
  }
Exemplo n.º 3
0
 @Test
 public void testsGetRestArray() {
   FunctionalList testList = new FunctionalArrayList();
   assertEquals("get Rest on empty", 0, testList.rest().size());
   testList.add("zero");
   assertEquals("get Rest on list of one", 0, testList.rest().size());
   testList.add("one");
   testList.add("two");
   testList.add("three");
   assertEquals("get Rest on list of 4", 3, testList.rest().size());
   assertEquals("test specific elements", "one", testList.rest().get(0).getReturnValue());
   assertEquals("test specific elements", "two", testList.rest().get(1).getReturnValue());
   assertEquals("test specific elements", "three", testList.rest().get(2).getReturnValue());
 }
Exemplo n.º 4
0
 @Test
 public void testsGetHeadLinked() {
   FunctionalList testList = new FunctionalLinkedList();
   assertEquals("get Head on empty", ErrorMessage.EMPTY_STRUCTURE, testList.head().getError());
   testList.add("zero");
   testList.add("one");
   testList.add("two");
   assertEquals(
       "get Head when not empty, no error", ErrorMessage.NO_ERROR, testList.head().getError());
   assertEquals("get Head when not empty, correct item", "zero", testList.head().getReturnValue());
 }