Language

The Free and Open Productivity Suite
Released: Apache OpenOffice 4.1.15

API

SDK

Tips ‘n’ Tricks

Miscellaneous

InterfaceContainer (Java UNO Runtime Reference)
UDK 3.2.7 Java API Reference

com.sun.star.lib.uno.helper
Class InterfaceContainer

java.lang.Object
  extended by com.sun.star.lib.uno.helper.InterfaceContainer
All Implemented Interfaces:
Cloneable

public class InterfaceContainer
extends Object
implements Cloneable

This class is a container for interfaces. It is intended to be used as storage for UNO interface of a specific type. The client has to ensure that the container contains only elements of the same type. If one needs to store different types, then one uses OMultiTypeInterfaceContainer. When the client calls disposeAndClear, the contained objects are queried for com.sun.star.lang.XEventListener and disposing is called. Afterwards the list cannot be used anymore. This list does not allow null values. All methods are thread-safe. The same holds true for iterators, issued by this class. Several iterators can exist at the same time and can also be modified (java.util.ListIterator.add, java.util.ListIterator.remove etc.). To make this work, the InterfaceContainer provides the iterators with copys of the list's data. The add and remove calls on the iterator modify the data in the iterator's list as well as in InterfaceContainer. Modification on InterfaceContainer, however, are not synchronized with existing iterators. For example

 InterfaceContainer cont= new InterfaceContainer();
 ListIterator it= cont.listIterator();

 cont.add( someInterface);
 // one cannot obtain someInterface through iterator it,
 // instead get a new iterator
 it= cont.listIterator();
 // it now keeps a fresh copy of cont and hence contains someInterface

 // Adding an interface on the iterator will cause the interface also to be added
 // to InterfaceContainer
 it.add( someOtherInterface);
 // someOtherInterface is now in it and cont
 ListIterator it2= cont.listIterator();
 //someOtherInterface can also be obtained by all newly created iterators, e.g. it2.
 
The add and remove methods of an iterator work on a particular location within a list, dependent on what the value of the iterator's cursor is. After the call the value at the appropriate position has been modified. Since the iterator received a copy of InterfaceContainer's data, InterfaceContainer may have been modified (by List methods or through other iterators). Therefore both data sets may not contain the same elements anymore. Consequently, a List method that modifies data, does not modify InterfaceContainer's data at a certain index (according to the iterators cursor). Instead, new elements are added at the end of list. When Iterator.remove is called, then the first occurrence of that element in InterfaceContainer is removed. ListIterator.set is not supported. A lot of methods resemble those of the to java.util.List interface, allthough this class does not implement it. However, the list iterators returned, for example by the listIterator method implement the java.util.ListIterator interface. Implementing the List interface would mean to support all none - optional methods as prescribed by the interface declaration. Among those is the subList method which returns a range of values of the list's data wrapped in a List implementation. Changes to the sub list have to cause changes in the main list. This is a problem, since this class is to be used in a multi-threaded environment. The sub list could work on a copy as the iterators do, but all the functions which work on an given index could not be properly supported. Unfortunatly, the List interface documentation states that all optional methods implemented by the list have to be implemented in the sub list. That would mean to do without all those critical methods, allthough they might work well in the "main list" (as opposed to sub list).


Constructor Summary
InterfaceContainer()
          Creates a new instance of InterfaceContainer
InterfaceContainer(int initialCapacity)
          Constructs an empty list with the specified initial capacity.
 
Method Summary
 void add(int index, Object element)
          Inserts the specified element at the specified position in this list.
 boolean add(Object o)
          Appends the specified element to the end of this list.
 boolean addAll(Collection c)
          Appends all of the elements in the specified Collection to the end of this list, in the order that they are returned by the specified Collection's Iterator.
 boolean addAll(int index, Collection c)
          Inserts all of the elements in the specified Collection into this list, starting at the specified position.
 void clear()
          Removes all of the elements from this list.
 Object clone()
          Returns a shallow copy of this ArrayList instance.
 boolean contains(Object elem)
          Returns true if this list contains the specified element.
 boolean containsAll(Collection collection)
           
 void disposeAndClear(EventObject evt)
           
 void ensureCapacity(int minCapacity)
          Increases the capacity of this ArrayList instance, if necessary, to ensure that it can hold at least the number of elements specified by the minimum capacity argument.
 Object get(int index)
          Returns the element at the specified position in this list.
 int indexOf(Object elem)
          Searches for the first occurence of the given argument, testing for equality using the equals method.
 boolean isEmpty()
          Tests if this list has no elements.
 Iterator iterator()
           
 int lastIndexOf(Object elem)
          Returns the index of the last occurrence of the specified object in this list.
 ListIterator listIterator()
           
 ListIterator listIterator(int index)
          The iterator keeps a copy of the list.
 Object remove(int index)
          Removes the element at the specified position in this list.
 boolean remove(Object obj)
          Parameter obj may
 boolean removeAll(Collection collection)
           
 boolean retainAll(Collection collection)
           
 Object set(int index, Object element)
          Not supported.
 int size()
          Returns the number of elements in this list.
 Object[] toArray()
          Returns an array containing all of the elements in this list in the correct order.
 Object[] toArray(Object[] a)
          Returns an array containing all of the elements in this list in the correct order.
 void trimToSize()
          Trims the capacity of this ArrayList instance to be the list's current size.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

InterfaceContainer

public InterfaceContainer()
Creates a new instance of InterfaceContainer


InterfaceContainer

public InterfaceContainer(int initialCapacity)
Constructs an empty list with the specified initial capacity.

Parameters:
initialCapacity - the initial capacity of the list.
Throws:
IllegalArgumentException - if the specified initial capacity is negative
Method Detail

trimToSize

public void trimToSize()
Trims the capacity of this ArrayList instance to be the list's current size. An application can use this operation to minimize the storage of an ArrayList instance.


ensureCapacity

public void ensureCapacity(int minCapacity)
Increases the capacity of this ArrayList instance, if necessary, to ensure that it can hold at least the number of elements specified by the minimum capacity argument.

Parameters:
minCapacity - the desired minimum capacity.

add

public boolean add(Object o)
Appends the specified element to the end of this list.

Parameters:
o - element to be appended to this list.
Returns:
true (as per the general contract of Collection.add).

add

public void add(int index,
                Object element)
Inserts the specified element at the specified position in this list. Shifts the element currently at that position (if any) and any subsequent elements to the right (adds one to their indices).

Parameters:
index - index at which the specified element is to be inserted.
element - element to be inserted.
Throws:
IndexOutOfBoundsException - if index is out of range (index < 0 || index > size()).

addAll

public boolean addAll(Collection c)
Appends all of the elements in the specified Collection to the end of this list, in the order that they are returned by the specified Collection's Iterator. The behavior of this operation is undefined if the specified Collection is modified while the operation is in progress. (This implies that the behavior of this call is undefined if the specified Collection is this list, and this list is nonempty.)

Parameters:
c - the elements to be inserted into this list.
Throws:
IndexOutOfBoundsException - if index out of range (index < 0 || index > size()).

addAll

public boolean addAll(int index,
                      Collection c)
Inserts all of the elements in the specified Collection into this list, starting at the specified position. Shifts the element currently at that position (if any) and any subsequent elements to the right (increases their indices). The new elements will appear in the list in the order that they are returned by the specified Collection's iterator.

Parameters:
index - index at which to insert first element from the specified collection.
c - elements to be inserted into this list.
Throws:
IndexOutOfBoundsException - if index out of range (index < 0 || index > size()).

clear

public void clear()
Removes all of the elements from this list. The list will be empty after this call returns.


contains

public boolean contains(Object elem)
Returns true if this list contains the specified element.

Parameters:
elem - element whose presence in this List is to be tested.

containsAll

public boolean containsAll(Collection collection)

get

public Object get(int index)
Returns the element at the specified position in this list.

Parameters:
index - index of element to return.
Returns:
the element at the specified position in this list.
Throws:
IndexOutOfBoundsException - if index is out of range (index < 0 || index >= size()).

indexOf

public int indexOf(Object elem)
Searches for the first occurence of the given argument, testing for equality using the equals method.

Parameters:
elem - an object.
Returns:
the index of the first occurrence of the argument in this list; returns -1 if the object is not found.
See Also:
Object.equals(Object)

isEmpty

public boolean isEmpty()
Tests if this list has no elements.

Returns:
true if this list has no elements; false otherwise.

iterator

public Iterator iterator()

lastIndexOf

public int lastIndexOf(Object elem)
Returns the index of the last occurrence of the specified object in this list.

Parameters:
elem - the desired element.
Returns:
the index of the last occurrence of the specified object in this list; returns -1 if the object is not found.

clone

public Object clone()
Returns a shallow copy of this ArrayList instance. The contained references are copied but the objects not.

Overrides:
clone in class Object
Returns:
a clone of this List instance.

listIterator

public ListIterator listIterator()

listIterator

public ListIterator listIterator(int index)
The iterator keeps a copy of the list. Changes to InterfaceContainer do not affect the data of the iterator. Conversly, changes to the iterator are effect InterfaceContainer.


remove

public Object remove(int index)
Removes the element at the specified position in this list. Shifts any subsequent elements to the left (subtracts one from their indices).

Parameters:
index - the index of the element to removed.
Returns:
the element that was removed from the list.
Throws:
IndexOutOfBoundsException - if index out of range (index < 0 || index >= size()).

remove

public boolean remove(Object obj)
Parameter obj may


removeAll

public boolean removeAll(Collection collection)

retainAll

public boolean retainAll(Collection collection)

set

public Object set(int index,
                  Object element)
Not supported.

Parameters:
index - index of element to replace.
element - element to be stored at the specified position.
Returns:
the element previously at the specified position.
Throws:
IndexOutOfBoundsException - if index out of range (index < 0 || index >= size()).

size

public int size()
Returns the number of elements in this list.

Returns:
the number of elements in this list.

toArray

public Object[] toArray()
Returns an array containing all of the elements in this list in the correct order.

Returns:
an array containing all of the elements in this list in the correct order.

toArray

public Object[] toArray(Object[] a)
Returns an array containing all of the elements in this list in the correct order. The runtime type of the returned array is that of the specified array. If the list fits in the specified array, it is returned therein. Otherwise, a new array is allocated with the runtime type of the specified array and the size of this list.

If the list fits in the specified array with room to spare (i.e., the array has more elements than the list), the element in the array immediately following the end of the collection is set to null. This is useful in determining the length of the list only if the caller knows that the list does not contain any null elements.

Parameters:
a - the array into which the elements of the list are to be stored, if it is big enough; otherwise, a new array of the same runtime type is allocated for this purpose.
Returns:
an array containing the elements of the list.
Throws:
ArrayStoreException - if the runtime type of a is not a supertype of the runtime type of every element in this list.

disposeAndClear

public void disposeAndClear(EventObject evt)

UDK 3.2.7 Java API Reference

Apache Software Foundation

Copyright & License | Privacy | Contact Us | Donate | Thanks

Apache, OpenOffice, OpenOffice.org and the seagull logo are registered trademarks of The Apache Software Foundation. The Apache feather logo is a trademark of The Apache Software Foundation. Other names appearing on the site may be trademarks of their respective owners.