View Javadoc
1   /*
2    *    Copyright 2012-2022 the original author or authors.
3    *
4    *    Licensed under the Apache License, Version 2.0 (the "License");
5    *    you may not use this file except in compliance with the License.
6    *    You may obtain a copy of the License at
7    *
8    *       https://www.apache.org/licenses/LICENSE-2.0
9    *
10   *    Unless required by applicable law or agreed to in writing, software
11   *    distributed under the License is distributed on an "AS IS" BASIS,
12   *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   *    See the License for the specific language governing permissions and
14   *    limitations under the License.
15   */
16  package org.mybatis.scripting.velocity;
17  
18  import java.io.Serializable;
19  
20  /**
21   * Paranoiac small and fast forward only list
22   */
23  public final class FastLinkedList<E extends Serializable> implements Serializable {
24  
25    private static final long serialVersionUID = 1L;
26  
27    private Node first;
28  
29    private Node last;
30  
31    public FastLinkedList() {
32      this.last = this.first;
33    }
34  
35    public boolean isEmpty() {
36      return this.first == null;
37    }
38  
39    public Node start() {
40      return this.first;
41    }
42  
43    public void add(E e) {
44      final Node n = new Node(e);
45      if (this.first == null) {
46        this.first = n;
47        this.last = this.first;
48      } else {
49        this.last.next = n;
50        this.last = n;
51      }
52    }
53  
54    public final class Node {
55  
56      final E data;
57      Node next;
58  
59      public Node(E newData) {
60        this.data = newData;
61      }
62  
63      public boolean hasNext() {
64        return this.next != null;
65      }
66  
67    }
68  
69  }