package textbender.g.util; // Copyright 2006, Michael Allan. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Textbender Software"), to deal in the Textbender Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicence, and/or sell copies of the Textbender Software, and to permit persons to whom the Textbender Software is furnished to do so, subject to the following conditions: The preceding copyright notice and this permission notice shall be included in all copies or substantial portions of the Textbender Software. THE TEXTBENDER SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE TEXTBENDER SOFTWARE OR THE USE OR OTHER DEALINGS IN THE TEXTBENDER SOFTWARE. import textbender.g.lang.*; /** A map that permits duplicate keys (multiple values per key). */ public interface MultiMap { // - M u l t i - M a p ---------------------------------------------------------------- /** Returns the values for the specified key. * If there are multiple values, they are returned in put-order. * * @return either an array Object[] (multiple values); * a non-array Object (single value); or null (no value). */ public Object get( Object key ); /** Adds a value for the specified key. */ public void put( K key, V value ); // ==================================================================================== /** Multi-map utilities. */ public @ThreadSafe static final class U { private U() {} /** Returns an unmodifiable view of a multi-map. * * @see java.util.Collections#unmodifiableMap */ public static MultiMap unmodifiableMultiMap( MultiMap multiMap ) { return new UnmodifiableMultiMap( multiMap ); } } // ==================================================================================== /** A multi-map that wraps an underlying multi-map to make it unmodifiable. */ @ThreadRestricted("per underlying multi-map") public static final class UnmodifiableMultiMap extends MultiMapW { // Cf. java.util.Collections.UnmodifiableMap UnmodifiableMultiMap( MultiMap multiMap ) { super( multiMap ); } // - M u l t i - M a p ---------------------------------------------------------------- /** @throws UnsupportedOperationException */ public void put( K key, V value ) { throw new UnsupportedOperationException(); } } }