1dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond/*
2dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * Licensed to the Apache Software Foundation (ASF) under one or more
3dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * contributor license agreements.  See the NOTICE file distributed with
4dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * this work for additional information regarding copyright ownership.
5dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * The ASF licenses this file to You under the Apache License, Version 2.0
6dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * (the "License"); you may not use this file except in compliance with
7dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * the License.  You may obtain a copy of the License at
8dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond *
9dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond *      http://www.apache.org/licenses/LICENSE-2.0
10dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond *
11dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * Unless required by applicable law or agreed to in writing, software
12dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * distributed under the License is distributed on an "AS IS" BASIS,
13dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * See the License for the specific language governing permissions and
15dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * limitations under the License.
16dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond */
17dee0849a9704d532af0b550146cbafbaa6ee1d19Raymondpackage org.apache.commons.math.util;
18dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond
19dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond
20dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond/**
21dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * Provides a standard interface for double arrays.  Allows different
22dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * array implementations to support various storage mechanisms
23dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * such as automatic expansion, contraction, and array "rolling".
24dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond *
25dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * @version $Revision: 811685 $ $Date: 2009-09-05 19:36:48 +0200 (sam. 05 sept. 2009) $
26dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond */
27dee0849a9704d532af0b550146cbafbaa6ee1d19Raymondpublic interface DoubleArray {
28dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond
29dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    /**
30dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * Returns the number of elements currently in the array.  Please note
31dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * that this may be different from the length of the internal storage array.
32dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     *
33dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * @return number of elements
34dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     */
35dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    int getNumElements();
36dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond
37dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    /**
38dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * Returns the element at the specified index.  Note that if an
39dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * out of bounds index is supplied a ArrayIndexOutOfBoundsException
40dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * will be thrown.
41dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     *
42dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * @param index index to fetch a value from
43dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * @return value stored at the specified index
44dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * @throws ArrayIndexOutOfBoundsException if <code>index</code> is less than
45dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     *         zero or is greater than <code>getNumElements() - 1</code>.
46dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     */
47dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    double getElement(int index);
48dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond
49dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    /**
50dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * Sets the element at the specified index.  If the specified index is greater than
51dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * <code>getNumElements() - 1</code>, the <code>numElements</code> property
52dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * is increased to <code>index +1</code> and additional storage is allocated
53dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * (if necessary) for the new element and all  (uninitialized) elements
54dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * between the new element and the previous end of the array).
55dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     *
56dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * @param index index to store a value in
57dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * @param value value to store at the specified index
58dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * @throws ArrayIndexOutOfBoundsException if <code>index</code> is less than
59dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     *         zero.
60dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     */
61dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    void setElement(int index, double value);
62dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond
63dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    /**
64dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * Adds an element to the end of this expandable array
65dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     *
66dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * @param value to be added to end of array
67dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     */
68dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    void addElement(double value);
69dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond
70dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    /**
71dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * <p>
72dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * Adds an element to the end of the array and removes the first
73dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * element in the array.  Returns the discarded first element.
74dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * The effect is similar to a push operation in a FIFO queue.
75dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * </p>
76dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * <p>
77dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * Example: If the array contains the elements 1, 2, 3, 4 (in that order)
78dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * and addElementRolling(5) is invoked, the result is an array containing
79dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * the entries 2, 3, 4, 5 and the value returned is 1.
80dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * </p>
81dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     *
82dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * @param value the value to be added to the array
83dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * @return the value which has been discarded or "pushed" out of the array
84dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     *         by this rolling insert
85dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     */
86dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    double addElementRolling(double value);
87dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond
88dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    /**
89dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * Returns a double[] array containing the elements of this
90dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * <code>DoubleArray</code>.  If the underlying implementation is
91dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * array-based, this method should always return a copy, rather than a
92dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * reference to the underlying array so that changes made to the returned
93dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     *  array have no effect on the <code>DoubleArray.</code>
94dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     *
95dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * @return all elements added to the array
96dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     */
97dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    double[] getElements();
98dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond
99dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    /**
100dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     * Clear the double array
101dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond     */
102dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond    void clear();
103dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond
104dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond}
105