Ejemplo n.º 1
0
 public T next() {
   if (!hasNext()) {
     throw new NoSuchElementException();
   }
   T temp = current.getData();
   current = current.getNext();
   return temp;
 }
Ejemplo n.º 2
0
  @Override
  public Object render(RenderingContext context) {

    Object a = lhs.render(context);
    Object b = rhs.render(context);

    return !LValue.areEqual(a, b);
  }
Ejemplo n.º 3
0
  @Override
  public Object render(Map<String, Object> context) {

    Object a = lhs.render(context);
    Object b = rhs.render(context);

    return super.asBoolean(a) && super.asBoolean(b);
  }
Ejemplo n.º 4
0
 public T next() {
   T ans;
   if (hasNext()) {
     ans = next.getValue();
     next = next.getNext();
     return ans;
   } else {
     throw new NoSuchElementException();
   }
 }
Ejemplo n.º 5
0
 public String toString() {
   return title
       + "@"
       + hashCode()
       + " ["
       + ((tail != null) ? tail.getTitle() + "@" + tail.hashCode() : "NULL")
       + ((directed) ? LEdge.DIRECTED_STR : LEdge.UNDIRECTED_STR)
       + ((head != null) ? head.getTitle() + "@" + head.hashCode() : "NULL")
       + "]";
 }
Ejemplo n.º 6
0
  public boolean add(int index, T value) {
    if (index < 0 || index > size) {
      throw new IndexOutOfBoundsException();
    }

    if (index == size) {
      add(value);
    } else {
      if (index == 0) {
        LNode ad = new LNode(value);
        ad.setNext(start);
        start = ad;
        if (start == null) {
          end = ad;
        }
      } else {
        LNode current = start;
        for (int i = 0; i < index - 1; i++) {
          current = current.getNext();
        }
        LNode ad = new LNode(value);
        LNode move = current.getNext();
        ad.setNext(move);
        current.setNext(ad);

        if (index == size) {
          end = current.getNext();
        }
      }
      size++;
    }

    return true;
  }
Ejemplo n.º 7
0
  public T remove(int index) {
    if (index < 0 || index > size - 1) {
      throw new IndexOutOfBoundsException();
    }
    T s = start.getData();
    if (index == 0) {
      start = start.getNext();
      if (index == size - 1) {
        end = start;
      }
    } else {
      LNode current = start;
      for (int i = 0; i < index - 1; i++) {
        current = current.getNext();
      }
      LNode temp = current.getNext();
      s = temp.getData();

      temp = temp.getNext();
      current.setNext(temp);
      if (index == size - 1) {
        end = current;
      }
    }
    size--;

    return s;
  }
Ejemplo n.º 8
0
 public T next() {
   if (!hasNext()) {
     throw new NoSuchElementException();
   }
   if (current == null) {
     current = start;
   } else {
     current = current.getNext();
   }
   return current.getValue();
 }
Ejemplo n.º 9
0
  public T get(int index) {
    if (index < 0 || index > size - 1) {
      throw new IndexOutOfBoundsException();
    }

    LNode current = start;
    for (int i = 0; i < index; i++) {
      current = current.getNext();
    }
    return current.getData();
  }
Ejemplo n.º 10
0
 public int indexOf(T value) {
   LNode current = start;
   for (int i = 0; i < size; i++) {
     if (current.getValue().equals(value)) {
       return i;
     } else {
       current = current.getNext();
     }
   }
   return -1;
 }
Ejemplo n.º 11
0
 public String toString() {
   String ans = "[";
   LNode temp = start;
   while (temp != null) {
     ans += temp.getValue();
     if (temp.getNext() != null) {
       ans += ", ";
     }
     temp = temp.getNext();
   }
   return ans + "]";
 }
Ejemplo n.º 12
0
 public String toString(boolean t) {
   if (t) {
     String s = "Head: " + start.getValue();
     LNode current = start;
     while (current.getNext() != null) {
       current = current.getNext();
     }
     s += "\tTail: " + current.getValue();
     return s;
   }
   return "";
 }
Ejemplo n.º 13
0
 public int indexOf(T value) {
   LNode current = start;
   int counter = 0;
   while (current.getData() != value && current.getNext() != null) {
     current = current.getNext();
     counter++;
   }
   if (current.getNext() == null) {
     return -1;
   }
   return counter;
 }
Ejemplo n.º 14
0
  public boolean add(T value) {

    if (size == 0) {
      start = new LNode(value);
      end = start;
    } else {
      end.setNext(new LNode(value));
      end = end.getNext();
    }
    size++;
    return true;
  }
Ejemplo n.º 15
0
 public T set(int index, T newValue) {
   if (index >= size || index < 0) {
     throw new IndexOutOfBoundsException();
   }
   LNode current = start;
   for (int i = 0; i < index; i++) {
     current = current.getNext();
   }
   T oldValue = current.getValue();
   current.setValue(newValue);
   return oldValue;
 }
Ejemplo n.º 16
0
 public int indexOf(T value) {
   LNode temp = start;
   int index = 0;
   while (index < getSize()) {
     if (temp.getValue().equals(value)) {
       return index;
     } else {
       temp = temp.getNext();
       index++;
     }
   }
   return -1;
 }
Ejemplo n.º 17
0
 public String toString(boolean extra) {
   if (extra) {
     return toString()
         + " size:"
         + getSize()
         + " head:"
         + start.getValue()
         + " tail:"
         + end.getValue();
   } else {
     return toString();
   }
 }
Ejemplo n.º 18
0
 public String toString() {
   String total = "[ ";
   if (size != 0) {
     total += start.getData();
   }
   LNode tracker = start;
   for (int i = 0; i < size - 1; i++) {
     tracker = tracker.getNext();
     total += ", " + tracker.getData();
   }
   total += " ]";
   return total;
 }
Ejemplo n.º 19
0
 private LNode<Integer> addRecursive(LNode<Integer> n1, LNode<Integer> n2, int carry)
     throws Exception {
   if ((n1 != null && (n1.data < 0 || n1.data > 9))
       || (n2 != null && (n2.data < 0 || n2.data > 9))) throw new Exception("Bad List.");
   if (n1 == null && n2 == null && carry == 0) {
     return null;
   } else {
     int sum = (n1 != null ? n1.data : 0) + (n2 != null ? n2.data : 0) + carry;
     LNode<Integer> ret = new LNode<Integer>(sum % 10);
     ret.next = addRecursive(n1 != null ? n1.next : null, n2 != null ? n2.next : null, sum / 10);
     return ret;
   }
 }
Ejemplo n.º 20
0
 public String toString() {
   String s = "[";
   LNode current = start;
   while (current != null) {
     if (current.getNext() == null) {
       s += current.getValue();
     } else {
       s += (current.getValue() + ",");
     }
     current = current.getNext();
   }
   s += "]";
   return s;
 }
Ejemplo n.º 21
0
  public T remove(int index) {
    if (index >= size || index < 0) {
      throw new IndexOutOfBoundsException();
    } else if (index == 0) {
      T removed = start.getValue();
      start = start.getNext();
      size--;
      return removed;
    } else {

      LNode current = start;
      int h;
      T removed = current.getValue();
      for (h = 0; h < index - 1; h++) {
        current = current.getNext();
      }
      if (index == size - 1) {
        end = current;
      }
      removed = current.getNext().getValue();

      current.setNext(current.getNext().getNext());
      size--;
      return removed;
    }
  }
Ejemplo n.º 22
0
 public T get(int index) {
   if (index >= size || index < 0) {
     throw new IndexOutOfBoundsException();
   }
   LNode current = start;
   for (int i = 0; i < size; i++) {
     if (i == index) {
       return current.getValue();
     } else {
       current = current.getNext();
     }
   }
   return null;
 }
Ejemplo n.º 23
0
  public T set(int index, T indexValue) {
    if (index < 0 || index > size - 1) {
      throw new IndexOutOfBoundsException();
    }
    LNode current = start;
    // int tracker=0;
    for (int i = 0; i < index; i++) {
      current = current.getNext();
    }
    T save = current.getData();
    current.setData(indexValue);

    return save;
  }
Ejemplo n.º 24
0
 public T get(int pos) {
   if (size == 0) {
     throw new NoSuchElementException();
   }
   if (pos < 0 || pos >= getSize()) {
     throw new IndexOutOfBoundsException();
   }
   int index = 0;
   LNode temp = start;
   while (index != pos) {
     index++;
     temp = temp.getNext();
   }
   return temp.getValue();
 }
Ejemplo n.º 25
0
 public void set(int pos, T value) {
   int index = 0;
   LNode temp = start;
   if (size == 0) {
     throw new NoSuchElementException();
   }
   if (pos < 0 || pos >= getSize()) {
     throw new IndexOutOfBoundsException();
   }
   while (index != pos) {
     index++;
     temp = temp.getNext();
   }
   temp.setValue(value);
 }
Ejemplo n.º 26
0
 public boolean add(T value) {
   if (getSize() == 0) {
     start = new LNode(value);
     end = start;
     size++;
   } else {
     // new
     LNode newNode = new LNode(value);
     newNode.setPrevious(end);
     end.setNext(newNode);
     //	    end.getNext().setPrevious(end);
     end = end.getNext();
     size++;
   }
   return true;
 }
Ejemplo n.º 27
0
  @Override
  public Object render(Context context) {

    Object collection = lhs.render(context);
    Object needle = rhs.render(context);

    if (super.isArray(collection)) {
      Object[] array = super.asArray(collection);
      return Arrays.asList(array).contains(needle);
    }

    if (super.isString(collection)) {
      return super.asString(collection).contains(super.asString(needle));
    }

    return false;
  }
Ejemplo n.º 28
0
  public void update(LGraphObject lGraphObj) {
    // this node is a compound, so calculate its size
    this.calculateSizeUp();

    // if this is the root model then animate the graph
    if (this.isRoot()) {
      LayoutManager.getInstance().animate();
    } else
    // otherwise input graph object must be an LNode
    {
      LNode lNode = (LNode) lGraphObj;

      // in case it's an empty compound, update its location as well
      if (lNode.getChild() == null || lNode.getChild().getNodes().size() == 0) {
        this.setLocationAbs(new Point(lNode.getRect().x, lNode.getRect().y));
      }
    }
  }
Ejemplo n.º 29
0
 public T remove(int pos) {
   int index = 0;
   LNode temp = start;
   T removed;
   if (size == 0) {
     throw new NoSuchElementException();
   } else if (pos >= 0 && pos < getSize()) {
     while (index < pos - 1) {
       temp = temp.getNext();
       index++;
     }
     if (pos == 0) {
       removed = start.getValue();
       if (getSize() == 1) {
         start = new LNode(item);
         end = start;
       } else {
         // new
         start.getNext().setPrevious(null);
         start = start.getNext();
       }
       size--;
     } else {
       if (pos == getSize() - 1) {
         end = temp;
       }
       removed = temp.getNext().getValue();
       // new
       temp.getNext().getNext().setPrevious(temp);
       temp.setNext(temp.getNext().getNext());
       size--;
     }
     return removed;
   } else {
     throw new IndexOutOfBoundsException();
   }
 }
Ejemplo n.º 30
0
  public String toString(boolean choice) {
    String total = "";
    if (choice) {
      String copy = "[ ";
      if (size != 0) {
        copy += start.getData();
      }

      LNode current = start;
      for (int i = 0; i < size - 1; i++) {
        current = current.getNext();
        copy += ", " + current.getData();
      }
      copy += " ]";
      total += "Start: " + (String) start.getData() + " End: " + (String) end.getData();

      total = copy + total;
    }
    return total;
  }