Hi,

being in need of some generic map interface in UNO, I suggest
introducing the attached css.container.XMap interface in module udkapi.

The interface is roughly designed after the Map class from the Java
Collections Framework.

Any comments on the suggested design are welcome ...

Since the interface is a little bit bigger than the canonical
"has/insert/remove" triple, I also thought about introducing a
css.container.Map default implementation, which as constructor arguments
takes a key and a value type, and defaults certain behavior. This would
include the definition of key equality, the fact that no NULL keys are
allowed (while NULL values are), and perhaps more. Would that make sense?

Ciao
Frank

-- 
- Frank Schönheit, Software Engineer         [email protected] -
- Sun Microsystems                      http://www.sun.com/staroffice -
- OpenOffice.org Base                       http://dba.openoffice.org -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
/*************************************************************************
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* 
* Copyright 2008 by Sun Microsystems, Inc.
*
* OpenOffice.org - a multi-platform office productivity suite
*
* $RCSfile: code,v $
*
* $Revision: 1.3 $
*
* This file is part of OpenOffice.org.
*
* OpenOffice.org is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License version 3
* only, as published by the Free Software Foundation.
*
* OpenOffice.org is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU Lesser General Public License version 3 for more details
* (a copy is included in the LICENSE file that accompanied this code).
*
* You should have received a copy of the GNU Lesser General Public License
* version 3 along with OpenOffice.org.  If not, see
* <http://www.openoffice.org/license.html>
* for a copy of the LGPLv3 License.
************************************************************************/

#ifndef __com_sun_star_container_XMap_idl__
#define __com_sun_star_container_XMap_idl__

#include <com/sun/star/container/XEnumerationAccess.idl>
#include <com/sun/star/beans/IllegalTypeException.idl>
#include <com/sun/star/lang/NullPointerException.idl>
#include <com/sun/star/lang/NoSupportException.idl>
#include <com/sun/star/lang/IllegalArgumentException.idl>
#include <com/sun/star/container/NoSuchElementException.idl>
#include <com/sun/star/container/XSet.idl>

//=============================================================================

module com { module sun { module star { module container { 

//=============================================================================

/** describes a map between keys and values.

    <p>Keys in the map are unique, and each key maps to exactly one value.</p>
*/
interface XMap
{
    /** provides access to an enumeration for all the elements in the map

        <p>The elements returned by the enumeration are instances of <type scope="com::sun::star::beans">Pair</type>,
        holding the key-value-pairs which are currently part of the map.</p>

        <p>The enumeration behavior is undefined when the map is modified while the enumeration is running.</p>
    */
    interface XEnumerationAccess;

    /** denotes the type of the keys in the map.

        <p>Implementations are free to accept any supertype of <code>KeyType</code> as keys.</p>
    */
    [attribute, readonly]   type    KeyType;

    /** denotes the type of the values in the map.

        <p>Implementations are free to accept any supertype of the <code>ValueType</code> as values.</p>
    */
    [attribute, readonly]   type    ValueType;

    /** denotes the number of elements in the map.
    */
    [attribute, readonly]   long    Size;

    /** indicates whether the map is currently empty.
    */
    [attribute, readonly]   boolean IsEmpty;

    /** provides access to the set of the keys of all mappings in the map

        <p>The map and the key set are linked, in that changes to any of the two are reflected in the other,
        too. However, inserting new elements into the key set is not supported.</p>

        <p>If you modify the key set while an enumeration of key set elements or map elements is running,
        the behavior of the enumeration is undefined.</p>
    */
    [attribute, readonly]   XSet    KeySet;

    /** provides access to an enumeration of the values of all mappings in the map

        <p>The map and the value collection are linked, in that changes in the map are reflected in the value
        collection, too.</p>

        <p>If you modify the map while an enumeration of values is running,
        the behavior of the enumeration is undefined.</p>
    */
    [attribute, readonly]   XEnumerationAccess
                                    Values;

    /** clears the map, removing all key-value pairs from it.

        @throws ::com::sun::star::beans::NoSupportException
            if the map is not mutable.
    */
	void clear()
        raises( ::com::sun::star::lang::NoSupportException );

    /** determines whether a mapping for he given key exists in the map

        @param _key
            is the key whose presence in the map is to be tested.
        @return
            <TRUE/> if and only if the map contains a mapping for the given key.

        @throws ::com::sun::star::beans::IllegalTypeException
            if the given key is not of a type which is accepted by the map
        @throws ::com::sun::star::beans::NullPointerException
            if the given key is <NULL/>, but the map does not accept <NULL/> keys.
    */
    boolean containsKey( [in] any _key )
        raises( ::com::sun::star::beans::IllegalTypeException,
                ::com::sun::star::lang::NullPointerException );

    /** determines whether the map contains a mapping to a given value.

        @param _value
            is the value whose presence in the map is to be tested.
        @return
            <TRUE/> if and only one or more keys map to the given value.

        @throws ::com::sun::star::beans::IllegalTypeException
            if the given value is not of a type which is accepted by the map
        @throws ::com::sun::star::beans::NullPointerException
            if the given value is <NULL/>, but the map does not accept <NULL/> values.
    */
    boolean containsValue( [in] any _value )
        raises( ::com::sun::star::beans::IllegalTypeException,
                ::com::sun::star::lang::NullPointerException );

    /** gets the value to which a given key maps.

        @param _key
            they key whose associated value is to be returned.
        @return
            the value which is associated with the given key.

        @throws ::com::sun::star::beans::IllegalTypeException
            if the given key is not of a type which is accepted by the map
        @throws ::com::sun::star::beans::NullPointerException
            if the given key is <NULL/>, but the map does not accept <NULL/> keys.
        @throws ::com::sun::star::container::NoSuchElementException
            if there is no value associated with the given key
    */
    any     get( [in] any _key )
        raises( ::com::sun::star::beans::IllegalTypeException,
                ::com::sun::star::lang::NullPointerException,
                ::com::sun::star::container::NoSuchElementException );

    /** associates a given key with a given value

        <p>If the map already contains a mapping for the given key, then the old value is replaced by the
        given new value.</p>

        @param _key
            is the key which the given value should be associated with
        @param _value
            is the value which should be associated with the given key
        @return
            the value which was previously associated with the given key, or <NULL/>
            if there was no such previous association.

        @throws ::com::sun::star::beans::IllegalTypeException
            if the given key is not of a type which is accepted by the map
        @throws ::com::sun::star::beans::NullPointerException
            if the given key is <NULL/>, but the map does not accept <NULL/> keys, or
            if the given value is <NULL/>, but the map does not accept <NULL/> values
        @throws ::com::sun::star::beans::NoSupportException
            if the map does not support putting new mappings into it
        @throws ::com::sun::star::lang::IllegalArgumentException
            if the given mapping cannot be stored in the map, since it does not fulfill
            additional requirements.
    */
    any     put( [in] any _key, [in] any _value )
        raises( ::com::sun::star::lang::NoSupportException,
                ::com::sun::star::beans::IllegalTypeException,
                ::com::sun::star::lang::NullPointerException,
                ::com::sun::star::lang::IllegalArgumentException );

    /** removes a key-value mapping, given by key, from the map.

        @param _key
            is the key whose mapping should be removed from the map
        @return
            the value which was associated with the given key before the removal

        @throws ::com::sun::star::beans::IllegalTypeException
            if the given key is not of a type which is accepted by the map
        @throws ::com::sun::star::beans::NullPointerException
            if the given key is <NULL/>, but the map does not accept <NULL/> keys.
        @throws ::com::sun::star::beans::NoSupportException
            if the map does not support putting new mappings into it
        @throws ::com::sun::star::container::NoSuchElementException
            if there is no value associated with the given key
    */
    any     remove( [in] any _key )
        raises( ::com::sun::star::lang::NoSupportException,
                ::com::sun::star::beans::IllegalTypeException,
                ::com::sun::star::lang::NullPointerException,
                ::com::sun::star::container::NoSuchElementException );
};

//=============================================================================

}; }; }; }; 

//=============================================================================

#endif

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to