/ org.htmlparser / src / org / htmlparser / util / sort / Sortable.java
Sortable.java
 1  // HTMLParser Library $Name: v1_6_20060319 $ - A java-based parser for HTML
 2  // http://sourceforge.org/projects/htmlparser
 3  // Copyright (C) 2004 Derrick Oswald
 4  //
 5  // Revision Control Information
 6  //
 7  // $Source: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/util/sort/Sortable.java,v $
 8  // $Author: derrickoswald $
 9  // $Date: 2004/01/02 16:24:58 $
10  // $Revision: 1.11 $
11  //
12  // This library is free software; you can redistribute it and/or
13  // modify it under the terms of the GNU Lesser General Public
14  // License as published by the Free Software Foundation; either
15  // version 2.1 of the License, or (at your option) any later version.
16  //
17  // This library is distributed in the hope that it will be useful,
18  // but WITHOUT ANY WARRANTY; without even the implied warranty of
19  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20  // Lesser General Public License for more details.
21  //
22  // You should have received a copy of the GNU Lesser General Public
23  // License along with this library; if not, write to the Free Software
24  // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25  //
26  
27  package org.htmlparser.util.sort;
28  
29  /**
30   * Provides a mechanism to abstract the sort process.
31   * Classes implementing this interface are collections of Ordered objects
32   * that are to be sorted by the Sort class and are
33   * not necessarily Vectors or Arrays of Ordered objects.
34   * @see Sort
35   */
36  public interface Sortable
37  {
38      /**
39       * Returns the first index of the Sortable.
40       * @return The index of the first element.
41       */
42      public int first ();
43  
44      /**
45       * Returns the last index of the Sortable.
46       * @return The index of the last element.
47       * If this were an array object this would be (object.length - 1).
48       */
49      public int last ();
50  
51      /**
52       * Fetch the object at the given index.
53       * @param index The item number to get.
54       * @param reuse If this argument is not null, it is an object
55       * acquired from a previous fetch that is no longer needed and
56       * may be returned as the result if it makes mores sense to alter
57       * and return it than to fetch or create a new element. That is, the
58       * reuse object is garbage and may be used to avoid allocating a new
59       * object if that would normally be the strategy.
60       * @return The Ordered object at that index.
61       */
62      public Ordered fetch (int index, Ordered reuse);
63  
64      /**
65       * Swaps the elements at the given indicies.
66       * @param i One index.
67       * @param j The other index.
68       */
69      public void swap (int i, int j);
70  }