Unmodifiable Vector Adapter : Vector « Collections « Java Tutorial






/*
 * $Id: UnmodifiableVectorAdapter.java,v 1.1.1.1 2005/04/07 18:36:25 pocho Exp $
 */

import java.util.Collection;
import java.util.List;
import java.util.Vector;

/**
 * Adapter that adapts any {@link java.util.List} to {@link java.util.Vector} class.
 * 
 * @version $Name:  $ - $Revision: 1.1.1.1 $ - $Date: 2005/04/07 18:36:25 $
 */
public class UnmodifiableVectorAdapter extends Vector {
  
  private List adaptedList;
  
  public UnmodifiableVectorAdapter(List list) {
    setAdaptedList(list);
  }
  
  public void setAdaptedList(List list) {
    this.adaptedList = list;
  }
  
  public boolean contains(Object elem) {
    return adaptedList.contains(elem);
  }
  
  public boolean containsAll(Collection c) {
    return adaptedList.containsAll(c);
  }
  
  public Object elementAt(int index) {
    return adaptedList.get(index);
  }
  
  public Object get(int index) {
    return adaptedList.get(index);
  }
  
  public int indexOf(Object elem) {
    return adaptedList.indexOf(elem);
  }
  
  public int indexOf(Object elem, int index) {
    return subList(index, size()).indexOf(elem);
  }

  public boolean isEmpty() {
    return adaptedList.isEmpty();    
  }
  
  public Object lastElement() {
    return adaptedList.get(size() - 1);
  }
  
  public int lastIndexOf(Object elem) {
    return adaptedList.lastIndexOf(elem);
  }
  
  public int lastIndexOf(Object elem, int index) {
    return subList(0, index).indexOf(elem);
  }
  
  public int size() {
    return adaptedList.size();
  }
  
  public List subList(int fromIndex, int toIndex) {
    return adaptedList.subList(fromIndex, toIndex);
  }

  public Object[] toArray() {
    return adaptedList.toArray();
  }
  
  public Object[] toArray(Object[] a) {
    return adaptedList.toArray(a);
  }

  public String toString() {
    return adaptedList.toString();
  }
  
  public void add(int index, Object element) { 
    throw new UnsupportedOperationException();
  }
  
  
  public boolean add(Object o) {
    throw new UnsupportedOperationException();
  }
  
  public boolean addAll(Collection c) {
    throw new UnsupportedOperationException();
  }
  
  public boolean addAll(int index, Collection c) {
    throw new UnsupportedOperationException(); 
  }
  
  public void addElement(Object obj) {
    throw new UnsupportedOperationException();
  }
  
  public void clear() { 
    throw new UnsupportedOperationException();
  }
  
  public Object clone() {
    throw new UnsupportedOperationException();
  }

  public void insertElementAt(Object obj, int index) {
    throw new UnsupportedOperationException();
  }

  public Object remove(int index) {
    throw new UnsupportedOperationException();
  }
  
  public boolean remove(Object o) {
    throw new UnsupportedOperationException();
  }
  
  public boolean removeAll(Collection c) {
    throw new UnsupportedOperationException();
  }
  
  public void removeAllElements() {
    throw new UnsupportedOperationException();
  }
  
  public boolean removeElement(Object obj) {
    throw new UnsupportedOperationException();
  }

  public void removeElementAt(int index) {
    throw new UnsupportedOperationException();
  }

  public boolean retainAll(Collection c) {
    throw new UnsupportedOperationException();
  }
  
  public Object set(int index, Object element) {
    throw new UnsupportedOperationException();
  }
  
  public void setElementAt(Object obj, int index) {
    throw new UnsupportedOperationException();
  }
  
  
  public void setSize(int newSize) {
    throw new UnsupportedOperationException();
  }
}








9.47.Vector
9.47.1.Java vectors: dynamically sized arrays with synchronized access.
9.47.2.The asList() method of the Arrays class will create an object
9.47.3.Adding Elements: Adding at the End
9.47.4.Adding in the Middle
9.47.5.Adding Another Collection
9.47.6.Printing Vectors: a comma-delimited list, in index order and surrounded by square brackets ([])
9.47.7.Removing All Elements: clear out all of a vector's elements: clear() and removeAllElements()
9.47.8.When removing all the elements from a vector, the capacity does not change.
9.47.9.Removing Single Elements
9.47.10.Passing the object to remove to either of the remove() or removeElement() methods
9.47.11.Removing Another Collection: public boolean removeAll(Collection c)
9.47.12.Retaining Another Collection: public boolean retainAll(Collection c)
9.47.13.Replacing Elements
9.47.14.Replace an element at specified index of Java Vector
9.47.15.Search an element of Java Vector
9.47.16.Search an element of Vector from specific index
9.47.17.Replace All Elements Of Vector with Collections.fill
9.47.18.Sizing Vectors
9.47.19.Setting vector's size to trim elements
9.47.20.Storage Capacity
9.47.21.ensureCapacity(): make sure a vector is large enough before adding elements: public void ensureCapacity(int minCapacity)
9.47.22.Vector Immutability
9.47.23.Getting elements by Index without generics
9.47.24.Getting elements by Index with Generics
9.47.25.Getting by Position
9.47.26.Enumerating through the Elements
9.47.27.Using Iterator to loop through Vector elements
9.47.28.Using list Iterator to loop through the vector
9.47.29.Multidimensional Vectors (Vectors of Vectors)
9.47.30.The contains() method: reports if a specific element is within the vector
9.47.31.Checking for Position: where it is in the vector
9.47.32.Checking for Position from End
9.47.33.Finding all the positions for a single element
9.47.34.Checking for Collection Containment: containsAll()
9.47.35.Copying and Cloning Vectors
9.47.36.Converting the vector to an array: public Object[] toArray()
9.47.37.Converting the vector to an array: public Object[] toArray(Object[] a)
9.47.38.Converting the vector to an array: public void copyInto(Object[] anArray)
9.47.39.subList(): taking a subset of the vector's elements and referencing them from another List
9.47.40.The Vector's subList() method does not make a clone of the element references
9.47.41.The equals() method is used to check for element equality
9.47.42.Checking Vectors for Equality: Containing equivalent elements in identical order
9.47.43.Count distinct elements in a Vector
9.47.44.The Vector class overrides the hashCode() method: public int hashCode()
9.47.45.Serializing Vector
9.47.46.Replace all occurrences of specified element of Java Vector
9.47.47.Reverse order of all elements of Java Vector
9.47.48.Shuffle elements of Vector
9.47.49.Swap elements of Vector
9.47.50.Sort Vector in descending order using comparator
9.47.51.Enumerate through a Vector using Java Enumeration
9.47.52.Append all elements of other Collection to Vector
9.47.53.Perform Binary Search on Java Vector
9.47.54.Get Enumeration over Java Vector
9.47.55.Find maximum element of Java Vector
9.47.56.Find Minimum element of Java Vector
9.47.57.Create Java ArrayList From Enumeration which is from Vector
9.47.58.Copy Elements of Vector to ArrayList with Collection.copy
9.47.59.Copy Elements of One Vector to Another Vector with Collection.copy
9.47.60.Unmodifiable Vector Adapter