Spec-Zone .ru
спецификации, руководства, описания, API
001/*
002 * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
003 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004 *
005 * This code is free software; you can redistribute it and/or modify it
006 * under the terms of the GNU General Public License version 2 only, as
007 * published by the Free Software Foundation.  Oracle designates this
008 * particular file as subject to the "Classpath" exception as provided
009 * by Oracle in the LICENSE file that accompanied this code.
010 *
011 * This code is distributed in the hope that it will be useful, but WITHOUT
012 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
014 * version 2 for more details (a copy is included in the LICENSE file that
015 * accompanied this code).
016 *
017 * You should have received a copy of the GNU General Public License version
018 * 2 along with this work; if not, write to the Free Software Foundation,
019 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020 *
021 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
022 * or visit www.oracle.com if you need additional information or have any
023 * questions.
024 */
025package javafx.collections;
026
027/**
028 * An int[] array that allows listeners to track changes when they occur. To achieve
029 * that internal array is encapsulated and there is no direct access available
030 * from outside. Bulk operations are supported but they always do copy of the 
031 * data range.
032 * 
033 * @see ArrayChangeListener
034 */
035public interface ObservableIntegerArray extends ObservableArray<ObservableIntegerArray> {
036
037    /**
038     * Copies specified portion of array into {@code dest} array. Throws
039     * the same exceptions as {@link System#arraycopy(java.lang.Object,
040     * int, java.lang.Object, int, int) }
041     * @param srcIndex starting position in the observable array
042     * @param dest destination array
043     * @param destIndex starting position in destination array
044     * @param length length of portion to copy
045     */
046    public void copyTo(int srcIndex, int[] dest, int destIndex, int length);
047    public void copyTo(int srcIndex, ObservableIntegerArray dest, int destIndex, int length);
048
049    /**
050     * Gets a single value of array. This is generally as fast as direct access
051     * to an array and eliminates necessity to make a copy of array.
052     * @param index index of element to get
053     * @return value at the given index
054     * @throws ArrayIndexOutOfBoundsException if {@code index} is outside
055     * array bounds
056     */
057    public int get(int index);
058
059    /**
060     * Appends given {@code elements} to the end of array. Capacity is increased
061     * if necessary to match the new size of the data.
062     * @param elements
063     */
064    public void addAll(int... elements);
065    public void addAll(ObservableIntegerArray src);
066    public void addAll(int[] src, int srcIndex, int length);
067    public void addAll(ObservableIntegerArray src, int srcIndex, int length);
068
069    /**
070     * Sets observable array to a copy of given array. Capacity is increased
071     * if necessary to match the new size of the data
072     * @param elements source array to copy.
073     * @throws NullPointerException if {@code array} is null
074     */
075    public void setAll(int... elements);
076    public void setAll(int[] src, int srcIndex, int length);
077    public void setAll(ObservableIntegerArray src);
078    public void setAll(ObservableIntegerArray src, int srcIndex, int length);
079
080    /**
081     * Sets portion of observable array to a copy of given array. Throws 
082     * the same exceptions as {@link System#arraycopy(java.lang.Object, 
083     * int, java.lang.Object, int, int) }
084     * @param destIndex the starting destination index in this observable array
085     * @param src source array to copy
086     * @param srcIndex starting position in source array
087     * @param length length of portion to copy
088     */
089    public void set(int destIndex, int[] src, int srcIndex, int length);
090    public void set(int destIndex, ObservableIntegerArray src, int srcIndex, int length);
091
092    /**
093     * Sets a single value in the array. Avoid using this method if many values
094     * are updated, use {@linkplain #setAll(int, int[], int, int)} update method
095     * instead with as minimum number of invocations as possible.
096     * @param index index of the value to setAll
097     * @param value new value for the given index
098     * @throws ArrayIndexOutOfBoundsException if {@code index} is outside
099     * array bounds
100     */
101    public void set(int index, int value);
102
103    /**
104     * Returns an array containing copy of the observable array. 
105     * If the observable array fits in the specified array, it is copied therein. 
106     * Otherwise, a new array is allocated with the size of the observable array.
107     *
108     * @param dest the array into which the observable array to be copied,
109     *          if it is big enough; otherwise, a new int array is allocated. 
110     *          Ignored, if null.
111     * @return an int array containing the copy of the observable array
112     */
113    public int[] toArray(int[] dest);
114
115    /**
116     * Returns an array containing copy of specified portion of the observable array. 
117     * If specified portion of the observable array fits in the specified array, 
118     * it is copied therein. Otherwise, a new array of given length is allocated.
119     *
120     * @param srcIndex starting position in the observable array
121     * @param dest the array into which specified portion of the observable array 
122     *          to be copied, if it is big enough; 
123     *          otherwise, a new int array is allocated. 
124     *          Ignored, if null.
125     * @param length length of portion to copy
126     * @return an int array containing the copy of specified portion the observable array
127     */
128    public int[] toArray(int srcIndex, int[] dest, int length);
129    
130}