-
Notifications
You must be signed in to change notification settings - Fork 587
/
ImmutableListMultimapImpl.java
188 lines (160 loc) · 6.31 KB
/
ImmutableListMultimapImpl.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
/*
* Copyright (c) 2022 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.list;
import java.io.Externalizable;
import java.io.Serializable;
import org.eclipse.collections.api.RichIterable;
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.block.procedure.Procedure2;
import org.eclipse.collections.api.factory.Lists;
import org.eclipse.collections.api.factory.Maps;
import org.eclipse.collections.api.list.ImmutableList;
import org.eclipse.collections.api.list.MutableList;
import org.eclipse.collections.api.map.ImmutableMap;
import org.eclipse.collections.api.map.MutableMap;
import org.eclipse.collections.api.multimap.bag.ImmutableBagMultimap;
import org.eclipse.collections.api.multimap.bag.MutableBagMultimap;
import org.eclipse.collections.api.multimap.list.ImmutableListMultimap;
import org.eclipse.collections.api.multimap.list.MutableListMultimap;
import org.eclipse.collections.api.tuple.Pair;
import org.eclipse.collections.impl.multimap.AbstractImmutableMultimap;
import org.eclipse.collections.impl.multimap.AbstractMutableMultimap;
import org.eclipse.collections.impl.multimap.ImmutableMultimapSerializationProxy;
import org.eclipse.collections.impl.multimap.bag.HashBagMultimap;
import org.eclipse.collections.impl.utility.Iterate;
/**
* The default ImmutableListMultimap implementation.
*
* @since 1.0
*/
public final class ImmutableListMultimapImpl<K, V>
extends AbstractImmutableMultimap<K, V, ImmutableList<V>>
implements ImmutableListMultimap<K, V>, Serializable
{
private static final long serialVersionUID = 1L;
public ImmutableListMultimapImpl(MutableMap<K, ImmutableList<V>> map)
{
super(map);
}
public ImmutableListMultimapImpl(ImmutableMap<K, ImmutableList<V>> map)
{
super(map);
}
@Override
protected ImmutableList<V> createCollection()
{
return Lists.immutable.empty();
}
@Override
public void forEachKeyImmutableList(Procedure2<? super K, ? super ImmutableList<V>> procedure)
{
this.getMap().forEachKeyValue(procedure);
}
@Override
public ImmutableListMultimap<K, V> newEmpty()
{
return new ImmutableListMultimapImpl<>(Maps.immutable.of());
}
@Override
public MutableListMultimap<K, V> toMutable()
{
return new FastListMultimap<>(this);
}
@Override
public ImmutableListMultimap<K, V> toImmutable()
{
return this;
}
private Object writeReplace()
{
return new ImmutableListMultimapSerializationProxy<>(this.map);
}
public static class ImmutableListMultimapSerializationProxy<K, V>
extends ImmutableMultimapSerializationProxy<K, V, ImmutableList<V>> implements Externalizable
{
private static final long serialVersionUID = 1L;
public ImmutableListMultimapSerializationProxy()
{
// For Externalizable use only
}
public ImmutableListMultimapSerializationProxy(ImmutableMap<K, ImmutableList<V>> map)
{
super(map);
}
@Override
protected AbstractMutableMultimap<K, V, MutableList<V>> createEmptyMutableMultimap()
{
return new FastListMultimap<>();
}
}
@Override
public ImmutableListMultimap<K, V> newWith(K key, V value)
{
return (ImmutableListMultimap<K, V>) super.newWith(key, value);
}
@Override
public ImmutableListMultimap<K, V> newWithout(Object key, Object value)
{
return (ImmutableListMultimap<K, V>) super.newWithout(key, value);
}
@Override
public ImmutableListMultimap<K, V> newWithAll(K key, Iterable<? extends V> values)
{
return (ImmutableListMultimap<K, V>) super.newWithAll(key, values);
}
@Override
public ImmutableListMultimap<K, V> newWithoutAll(Object key)
{
return (ImmutableListMultimap<K, V>) super.newWithoutAll(key);
}
@Override
public ImmutableBagMultimap<V, K> flip()
{
return Iterate.flip(this).toImmutable();
}
@Override
public ImmutableListMultimap<K, V> selectKeysValues(Predicate2<? super K, ? super V> predicate)
{
return this.selectKeysValues(predicate, FastListMultimap.newMultimap()).toImmutable();
}
@Override
public ImmutableListMultimap<K, V> rejectKeysValues(Predicate2<? super K, ? super V> predicate)
{
return this.rejectKeysValues(predicate, FastListMultimap.newMultimap()).toImmutable();
}
@Override
public ImmutableListMultimap<K, V> selectKeysMultiValues(Predicate2<? super K, ? super RichIterable<V>> predicate)
{
return this.selectKeysMultiValues(predicate, FastListMultimap.newMultimap()).toImmutable();
}
@Override
public ImmutableListMultimap<K, V> rejectKeysMultiValues(Predicate2<? super K, ? super RichIterable<V>> predicate)
{
return this.rejectKeysMultiValues(predicate, FastListMultimap.newMultimap()).toImmutable();
}
@Override
public <K2, V2> ImmutableBagMultimap<K2, V2> collectKeysValues(Function2<? super K, ? super V, Pair<K2, V2>> function)
{
return this.collectKeysValues(function, HashBagMultimap.newMultimap()).toImmutable();
}
@Override
public <K2, V2> ImmutableBagMultimap<K2, V2> collectKeyMultiValues(Function<? super K, ? extends K2> keyFunction, Function<? super V, ? extends V2> valueFunction)
{
MutableBagMultimap<K2, V2> mutableMultimap = this.collectKeyMultiValues(keyFunction, valueFunction, HashBagMultimap.newMultimap());
return mutableMultimap.toImmutable();
}
@Override
public <V2> ImmutableListMultimap<K, V2> collectValues(Function<? super V, ? extends V2> function)
{
return this.collectValues(function, FastListMultimap.<K, V2>newMultimap()).toImmutable();
}
}