org.eclipse.collections.impl.multimap.bag.TreeBagMultimap Maven / Gradle / Ivy
/*
* Copyright (c) 2016 Goldman Sachs and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* and Eclipse Distribution License v. 1.0 which accompany this distribution.
* The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
* and the Eclipse Distribution License is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*/
package org.eclipse.collections.impl.multimap.bag;
import java.io.Externalizable;
import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectOutput;
import java.util.Comparator;
import org.eclipse.collections.api.bag.sorted.ImmutableSortedBag;
import org.eclipse.collections.api.bag.sorted.MutableSortedBag;
import org.eclipse.collections.api.block.function.Function;
import org.eclipse.collections.api.block.function.Function2;
import org.eclipse.collections.api.block.predicate.Predicate2;
import org.eclipse.collections.api.map.MutableMap;
import org.eclipse.collections.api.multimap.Multimap;
import org.eclipse.collections.api.multimap.bag.MutableBagMultimap;
import org.eclipse.collections.api.multimap.sortedbag.ImmutableSortedBagMultimap;
import org.eclipse.collections.api.multimap.sortedbag.MutableSortedBagMultimap;
import org.eclipse.collections.api.multimap.sortedbag.SortedBagMultimap;
import org.eclipse.collections.api.tuple.Pair;
import org.eclipse.collections.impl.bag.sorted.mutable.TreeBag;
import org.eclipse.collections.impl.map.mutable.UnifiedMap;
import org.eclipse.collections.impl.multimap.AbstractMutableMultimap;
import org.eclipse.collections.impl.multimap.bag.sorted.immutable.ImmutableSortedBagMultimapImpl;
import org.eclipse.collections.impl.multimap.bag.sorted.mutable.SynchronizedSortedBagMultimap;
import org.eclipse.collections.impl.multimap.list.FastListMultimap;
import org.eclipse.collections.impl.utility.Iterate;
/**
* @deprecated in 5.0. Use {@link org.eclipse.collections.impl.multimap.bag.sorted.mutable.TreeBagMultimap} instead.
*/
@Deprecated
public final class TreeBagMultimap
extends AbstractMutableMultimap>
implements MutableSortedBagMultimap, Externalizable
{
private static final long serialVersionUID = 1L;
private Comparator super V> comparator;
public TreeBagMultimap()
{
this.comparator = null;
}
public TreeBagMultimap(Comparator super V> comparator)
{
this.comparator = comparator;
}
public TreeBagMultimap(Multimap extends K, ? extends V> multimap)
{
super(Math.max(multimap.keysView().size() * 2, 16));
this.comparator = multimap instanceof SortedBagMultimap, ?> ? ((SortedBagMultimap) multimap).comparator() : null;
this.putAll(multimap);
}
public TreeBagMultimap(Pair... pairs)
{
super(pairs);
this.comparator = null;
}
public static TreeBagMultimap newMultimap()
{
return new TreeBagMultimap<>();
}
public static TreeBagMultimap newMultimap(Multimap extends K, ? extends V> multimap)
{
return new TreeBagMultimap<>(multimap);
}
public static TreeBagMultimap newMultimap(Comparator super V> comparator)
{
return new TreeBagMultimap<>(comparator);
}
public static TreeBagMultimap newMultimap(Pair... pairs)
{
return new TreeBagMultimap<>(pairs);
}
@Override
protected MutableMap> createMap()
{
return UnifiedMap.newMap();
}
@Override
protected MutableMap> createMapWithKeyCount(int keyCount)
{
return UnifiedMap.newMap(keyCount);
}
@Override
protected MutableSortedBag createCollection()
{
return TreeBag.newBag(this.comparator);
}
@Override
public TreeBagMultimap newEmpty()
{
return new TreeBagMultimap<>(this.comparator);
}
@Override
public Comparator super V> comparator()
{
return this.comparator;
}
@Override
public MutableSortedBagMultimap toMutable()
{
return new TreeBagMultimap<>(this);
}
@Override
public ImmutableSortedBagMultimap toImmutable()
{
MutableMap> map = UnifiedMap.newMap();
this.map.forEachKeyValue((key, bag) -> map.put(key, bag.toImmutable()));
return new ImmutableSortedBagMultimapImpl<>(map, this.comparator());
}
@Override
public void writeExternal(ObjectOutput out) throws IOException
{
out.writeObject(this.comparator());
super.writeExternal(out);
}
@Override
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
{
this.comparator = (Comparator super V>) in.readObject();
super.readExternal(in);
}
@Override
public MutableBagMultimap flip()
{
return Iterate.flip(this);
}
@Override
public TreeBagMultimap selectKeysValues(Predicate2 super K, ? super V> predicate)
{
return this.selectKeysValues(predicate, this.newEmpty());
}
@Override
public TreeBagMultimap rejectKeysValues(Predicate2 super K, ? super V> predicate)
{
return this.rejectKeysValues(predicate, this.newEmpty());
}
@Override
public TreeBagMultimap selectKeysMultiValues(Predicate2 super K, ? super Iterable> predicate)
{
return this.selectKeysMultiValues(predicate, this.newEmpty());
}
@Override
public TreeBagMultimap rejectKeysMultiValues(Predicate2 super K, ? super Iterable> predicate)
{
return this.rejectKeysMultiValues(predicate, this.newEmpty());
}
@Override
public HashBagMultimap collectKeysValues(Function2 super K, ? super V, Pair> function)
{
return this.collectKeysValues(function, HashBagMultimap.newMultimap());
}
@Override
public FastListMultimap collectValues(Function super V, ? extends V2> function)
{
return this.collectValues(function, FastListMultimap.newMultimap());
}
@Override
public MutableSortedBagMultimap asSynchronized()
{
return SynchronizedSortedBagMultimap.of(this);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy