-
Notifications
You must be signed in to change notification settings - Fork 587
/
immutableObjectPrimitiveMapFactoryImpl.stg
99 lines (83 loc) · 3.09 KB
/
immutableObjectPrimitiveMapFactoryImpl.stg
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
import "copyright.stg"
targetPath() ::= "org/eclipse/collections/impl/map/immutable/primitive"
fileName(primitive) ::= "ImmutableObject<primitive.name>MapFactoryImpl"
class(primitive) ::= <<
<body(primitive.type, primitive.name)>
>>
body(type, name) ::= <<
<copyright()>
package org.eclipse.collections.impl.map.immutable.primitive;
import org.eclipse.collections.api.block.function.Function;
import org.eclipse.collections.api.block.function.primitive.<name>Function;
import org.eclipse.collections.api.factory.map.primitive.ImmutableObject<name>MapFactory;
import org.eclipse.collections.api.map.primitive.ImmutableObject<name>Map;
import org.eclipse.collections.api.map.primitive.MutableObject<name>Map;
import org.eclipse.collections.api.map.primitive.Object<name>Map;
import org.eclipse.collections.impl.factory.primitive.Object<name>Maps;
/**
* ImmutableObject<name>MapFactoryImpl is a factory implementation which creates instances of type {@link ImmutableObject<name>Map}.
* This file was automatically generated from template file immutableObjectPrimitiveMapFactoryImpl.stg.
*
* @since 4.0.
*/
public class ImmutableObject<name>MapFactoryImpl implements ImmutableObject<name>MapFactory
{
public static final ImmutableObject<name>MapFactory INSTANCE = new ImmutableObject<name>MapFactoryImpl();
@Override
public \<K> ImmutableObject<name>Map\<K> empty()
{
return (ImmutableObject<name>Map\<K>) ImmutableObject<name>EmptyMap.INSTANCE;
}
@Override
public \<K> ImmutableObject<name>Map\<K> of()
{
return this.empty();
}
@Override
public \<K> ImmutableObject<name>Map\<K> with()
{
return this.empty();
}
@Override
public \<K> ImmutableObject<name>Map\<K> of(K key, <type> value)
{
return this.with(key, value);
}
@Override
public \<K> ImmutableObject<name>Map\<K> with(K key, <type> value)
{
return new ImmutableObject<name>SingletonMap\<>(key, value);
}
@Override
public \<K> ImmutableObject<name>Map\<K> ofAll(Object<name>Map\<? extends K> map)
{
return this.withAll(map);
}
@Override
public \<K> ImmutableObject<name>Map\<K> withAll(Object<name>Map\<? extends K> map)
{
if (map instanceof ImmutableObject<name>Map)
{
return (ImmutableObject<name>Map\<K>) map;
}
if (map.isEmpty())
{
return this.with();
}
if (map.size() == 1)
{
//TODO use keysView() when available.
final Object[] array = new Object[1];
map.forEachKey((K each) -> array[0] = each);
return new ImmutableObject<name>SingletonMap\<>((K) array[0], map.get(array[0]));
}
return new ImmutableObject<name>HashMap\<>(map);
}
@Override
public \<T, K> ImmutableObject<name>Map\<K> from(Iterable\<T> iterable, Function\<? super T, ? extends K> keyFunction, <name>Function\<? super T> valueFunction)
{
MutableObject<name>Map\<K> map = Object<name>Maps.mutable.from(iterable, keyFunction, valueFunction);
return map.toImmutable();
}
}
>>