/*
* Copyright 2014 Goldman Sachs.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.gs.collections.impl.multimap.list;
import com.gs.collections.api.block.function.Function;
import com.gs.collections.api.block.function.Function2;
import com.gs.collections.api.block.procedure.Procedure2;
import com.gs.collections.api.list.ImmutableList;
import com.gs.collections.api.list.MutableList;
import com.gs.collections.api.map.MutableMap;
import com.gs.collections.api.multimap.list.ImmutableListMultimap;
import com.gs.collections.api.multimap.list.MutableListMultimap;
import com.gs.collections.api.tuple.Pair;
import com.gs.collections.impl.map.mutable.UnifiedMap;
import com.gs.collections.impl.multimap.AbstractMutableMultimap;
import com.gs.collections.impl.multimap.bag.HashBagMultimap;
public abstract class AbstractMutableListMultimap<K, V> extends AbstractMutableMultimap<K, V, MutableList<V>> implements MutableListMultimap<K, V>
{
protected AbstractMutableListMultimap()
{
}
protected AbstractMutableListMultimap(Pair<K, V>... pairs)
{
super(pairs);
}
protected AbstractMutableListMultimap(Iterable<Pair<K, V>> inputIterable)
{
super(inputIterable);
}
protected AbstractMutableListMultimap(int size)
{
super(size);
}
public MutableListMultimap<K, V> toMutable()
{
return new FastListMultimap<K, V>(this);
}
public ImmutableListMultimap<K, V> toImmutable()
{
final MutableMap<K, ImmutableList<V>> map = UnifiedMap.newMap();
this.map.forEachKeyValue(new Procedure2<K, MutableList<V>>()
{
public void value(K key, MutableList<V> list)
{
map.put(key, list.toImmutable());
}
});
return new ImmutableListMultimapImpl<K, V>(map);
}
public <K2, V2> HashBagMultimap<K2, V2> collectKeysValues(Function2<? super K, ? super V, Pair<K2, V2>> function)
{
return this.collectKeysValues(function, HashBagMultimap.<K2, V2>newMultimap());
}
public <V2> FastListMultimap<K, V2> collectValues(Function<? super V, ? extends V2> function)
{
return this.collectValues(function, FastListMultimap.<K, V2>newMultimap());
}
}