View Javadoc
1   /*
2    * Copyright 2008 FatWire Corporation. All Rights Reserved.
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    *    http://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  
17  package tools.gsf.facade.sql;
18  
19  import COM.FutureTense.Interfaces.IList;
20  
21  /**
22   * Base IList class supporting navigation and naming.
23   *
24   * @author Tony Field
25   * @since Aug 13, 2010
26   */
27  public abstract class AbstractIList implements IList {
28      private String name;
29      private int currentRow;
30  
31      protected AbstractIList(final String name) {
32          this.name = name;
33      }
34  
35      public final String getName() {
36          return name;
37      }
38  
39      public final void rename(final String newname) {
40          name = newname;
41      }
42  
43      public final boolean moveTo(final int i) {
44          if (1 <= i && i <= numRows()) {
45              currentRow = i;
46              return true;
47          } else {
48              return false;
49          }
50      }
51  
52      public final boolean moveToRow(final int how, final int row) {
53          if (numRows() == 0) {
54              return false;
55          }
56          switch (how) {
57              case first:
58                  currentRow = 1;
59                  return true;
60              case gotorow:
61                  return moveTo(row);
62              case last:
63                  currentRow = numRows();
64                  return true;
65              case next:
66                  if (currentRow == -1) {
67                      return false;
68                  }
69                  ++currentRow;
70                  if (currentRow > numRows()) {
71                      currentRow = -1;
72                      return false;
73                  }
74                  return true;
75              case prev:
76                  if (currentRow == -1) {
77                      return false;
78                  }
79                  --currentRow;
80                  if (currentRow == 0) {
81                      currentRow = -1;
82                      return false;
83                  }
84                  return true;
85              default:
86                  return false;
87          }
88      }
89  
90      public final boolean atEnd() {
91          return currentRow == -1;
92      }
93  
94      public final boolean hasData() {
95          return numRows() > 0;
96      }
97  
98      public final int currentRow() {
99          return currentRow;
100     }
101 
102 }