01: /*
02: * @(#)RandomAccess.java 1.8 06/10/10
03: *
04: * Copyright 1990-2006 Sun Microsystems, Inc. All Rights Reserved.
05: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
06: *
07: * This program is free software; you can redistribute it and/or
08: * modify it under the terms of the GNU General Public License version
09: * 2 only, as published by the Free Software Foundation.
10: *
11: * This program is distributed in the hope that it will be useful, but
12: * WITHOUT ANY WARRANTY; without even the implied warranty of
13: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14: * General Public License version 2 for more details (a copy is
15: * included at /legal/license.txt).
16: *
17: * You should have received a copy of the GNU General Public License
18: * version 2 along with this work; if not, write to the Free Software
19: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20: * 02110-1301 USA
21: *
22: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
23: * Clara, CA 95054 or visit www.sun.com if you need additional
24: * information or have any questions.
25: */
26:
27: package java.util;
28:
29: /**
30: * Marker interface used by <tt>List</tt> implementations to indicate that
31: * they support fast (generally constant time) random access. The primary
32: * purpose of this interface is to allow generic algorithms to alter their
33: * behavior to provide good performance when applied to either random or
34: * sequential access lists.
35: *
36: * <p>The best algorithms for manipulating random access lists (such as
37: * <tt>ArrayList</tt>) can produce quadratic behavior when applied to
38: * sequential access lists (such as <tt>LinkedList</tt>). Generic list
39: * algorithms are encouraged to check whether the given list is an
40: * <tt>instanceof</tt> this interface before applying an algorithm that would
41: * provide poor performance if it were applied to a sequential access list,
42: * and to alter their behavior if necessary to guarantee acceptable
43: * performance.
44: *
45: * <p>It is recognized that the distinction between random and sequential
46: * access is often fuzzy. For example, some <tt>List</tt> implementations
47: * provide asymptotically linear access times if they get huge, but constant
48: * access times in practice. Such a <tt>List</tt> implementation
49: * should generally implement this interface. As a rule of thumb, a
50: * <tt>List</tt> implementation should implement this interface if,
51: * for typical instances of the class, this loop:
52: * <pre>
53: * for (int i=0, n=list.size(); i < n; i++)
54: * list.get(i);
55: * </pre>
56: * runs faster than this loop:
57: * <pre>
58: * for (Iterator i=list.iterator(); i.hasNext(); )
59: * i.next();
60: * </pre>
61: *
62: * <p>This interface is a member of the
63: * <a href="{@docRoot}/../guide/collections/index.html">
64: * Java Collections Framework</a>.
65: *
66: */
67: public interface RandomAccess {
68: }
|