usr/src/java/vpanels/app/usermgr/com/oracle/solaris/vp/panels/usermgr/client/swing/QuickVector.java
changeset 847 a8e124b894b8
equal deleted inserted replaced
846:0a2af4721353 847:a8e124b894b8
       
     1 /*
       
     2  * CDDL HEADER START
       
     3  *
       
     4  * The contents of this file are subject to the terms of the
       
     5  * Common Development and Distribution License (the "License").
       
     6  * You may not use this file except in compliance with the License.
       
     7  *
       
     8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
       
     9  * or http://www.opensolaris.org/os/licensing.
       
    10  * See the License for the specific language governing permissions
       
    11  * and limitations under the License.
       
    12  *
       
    13  * When distributing Covered Code, include this CDDL HEADER in each
       
    14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
       
    15  * If applicable, add the following below this CDDL HEADER, with the
       
    16  * fields enclosed by brackets "[]" replaced with your own identifying
       
    17  * information: Portions Copyright [yyyy] [name of copyright owner]
       
    18  *
       
    19  * CDDL HEADER END
       
    20  */
       
    21 
       
    22 /*
       
    23  * Copyright (c) 1998, 2012, Oracle and/or its affiliates. All rights reserved.
       
    24  */
       
    25 
       
    26 
       
    27 package com.oracle.solaris.vp.panels.usermgr.client.swing;
       
    28 
       
    29 import java.util.Vector;
       
    30 
       
    31 /**
       
    32  * SMC code adapted for Visual Panels
       
    33  *
       
    34  * The <code>QuickVector</code> class extends the Vector class,
       
    35  * providing additional methods which allow faster
       
    36  * access to elements of the array.
       
    37  *
       
    38  */
       
    39 public
       
    40 class QuickVector extends Vector {
       
    41 
       
    42     /**
       
    43      * Constructs an empty vector with the specified initial capacity and
       
    44      * capacity increment.
       
    45      *
       
    46      * @param   initialCapacity	    the initial capacity of the vector.
       
    47      * @param   capacityIncrement   the amount by which the capacity is
       
    48      *				    increased when the vector overflows.
       
    49      */
       
    50     public QuickVector(int initialCapacity, int capacityIncrement) {
       
    51         super(initialCapacity, capacityIncrement);
       
    52     }
       
    53 
       
    54     /**
       
    55      * Constructs an empty vector with the specified initial capacity.
       
    56      *
       
    57      * @param   initialCapacity   the initial capacity of the vector.
       
    58      */
       
    59     public QuickVector(int initialCapacity) {
       
    60         super(initialCapacity);
       
    61     }
       
    62 
       
    63     /**
       
    64      * Constructs an empty vector.
       
    65      *
       
    66      */
       
    67     public QuickVector() {
       
    68         super();
       
    69     }
       
    70 
       
    71     /**
       
    72      * Returns the component at the specified index.
       
    73      *
       
    74      * @param	index   an index into this vector.
       
    75      * @return	the component at the specified index.
       
    76      * @exception  ArrayIndexOutOfBoundsException  if an invalid index was
       
    77      * given.
       
    78      */
       
    79     public final Object quickElementAt(int index) {
       
    80         if (index >= elementCount) {
       
    81             throw new ArrayIndexOutOfBoundsException(
       
    82 		index + " >= " + elementCount);
       
    83         }
       
    84         return elementData[index];
       
    85     }
       
    86 
       
    87     /**
       
    88      * Sets the component at the specified <code>index</code> of this
       
    89      * vector to be the specified object. The previous component at that
       
    90      * position is discarded.
       
    91      * <p>
       
    92      * The index must be a value greater than or equal to <code>0</code>
       
    93      * and less than the current size of the vector.
       
    94      *
       
    95      * @param	obj	what the component is to be set to.
       
    96      * @param	index	the specified index.
       
    97      * @exception  ArrayIndexOutOfBoundsException  if the index was invalid.
       
    98      */
       
    99     public final void quickSetElementAt(Object obj, int index) {
       
   100         if (index >= elementCount) {
       
   101             throw new ArrayIndexOutOfBoundsException(
       
   102 		index + " >= " + elementCount);
       
   103         }
       
   104         elementData[index] = obj;
       
   105     }
       
   106 
       
   107     public final void quickSwapElementsAt(int element1, int element2) {
       
   108         Object obj = null;
       
   109 
       
   110         if (element1 >= elementCount) {
       
   111             throw new ArrayIndexOutOfBoundsException(
       
   112 		element1 + " >= " + elementCount);
       
   113         }
       
   114         if (element2 >= elementCount) {
       
   115             throw new ArrayIndexOutOfBoundsException(
       
   116 		element2 + " >= " + elementCount);
       
   117         }
       
   118         obj =  elementData[element1];
       
   119         elementData[element1] = elementData[element2];
       
   120         elementData[element2] = obj;
       
   121     }
       
   122 
       
   123 }