Skip to content

Commit 418872c

Browse files
committed
MP-11740 Fix intendations
1 parent df3c1de commit 418872c

7 files changed

Lines changed: 63 additions & 0 deletions

File tree

src/main/java/com/trivago/fastutilconcurrentwrapper/ConcurrentLongShortTreeMapBuilder.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,39 @@
11
package com.trivago.fastutilconcurrentwrapper;
2+
23
import com.trivago.fastutilconcurrentwrapper.map.ConcurrentBusyWaitingLongShortTreeMap;
34
import com.trivago.fastutilconcurrentwrapper.map.ConcurrentLongShortTreeMap;
5+
46
public final class ConcurrentLongShortTreeMapBuilder {
57
private MapMode mapMode = MapMode.BLOCKING;
68
private int buckets = 8;
79
private short defaultValue = LongShortMap.DEFAULT_VALUE;
10+
811
private ConcurrentLongShortTreeMapBuilder() {
912
}
13+
1014
public static ConcurrentLongShortTreeMapBuilder newBuilder() {
1115
return new ConcurrentLongShortTreeMapBuilder();
1216
}
17+
1318
public ConcurrentLongShortTreeMapBuilder withBuckets(int buckets) {
1419
this.buckets = buckets;
1520
return this;
1621
}
22+
1723
public ConcurrentLongShortTreeMapBuilder withMode(MapMode mapMode) {
1824
this.mapMode = mapMode;
1925
return this;
2026
}
27+
2128
public ConcurrentLongShortTreeMapBuilder withDefaultValue(short defaultValue) {
2229
this.defaultValue = defaultValue;
2330
return this;
2431
}
32+
2533
public LongShortTreeMap build() {
2634
return mapMode.createMap(this);
2735
}
36+
2837
public enum MapMode {
2938
BUSY_WAITING {
3039
@Override
@@ -42,6 +51,7 @@ LongShortTreeMap createMap(ConcurrentLongShortTreeMapBuilder builder) {
4251
builder.defaultValue);
4352
}
4453
};
54+
4555
abstract LongShortTreeMap createMap(ConcurrentLongShortTreeMapBuilder builder);
4656
}
4757
}

src/main/java/com/trivago/fastutilconcurrentwrapper/map/ConcurrentLongShortTreeMap.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
package com.trivago.fastutilconcurrentwrapper.map;
2+
23
import com.trivago.fastutilconcurrentwrapper.LongShortTreeMap;
34
import com.trivago.fastutilconcurrentwrapper.wrapper.PrimitiveFastutilLongShortTreeWrapper;
45
import it.unimi.dsi.fastutil.longs.Long2ShortFunction;
56
import it.unimi.dsi.fastutil.longs.Long2ShortMap;
7+
68
import java.util.concurrent.locks.Lock;
79
import java.util.function.BiFunction;
10+
811
public class ConcurrentLongShortTreeMap extends PrimitiveConcurrentMap implements LongShortTreeMap {
912
private final LongShortTreeMap[] maps;
1013
private final short defaultValue;
14+
1115
public ConcurrentLongShortTreeMap(int numBuckets, short defaultValue) {
1216
super(numBuckets);
1317
this.maps = new LongShortTreeMap[numBuckets];
@@ -16,14 +20,17 @@ public ConcurrentLongShortTreeMap(int numBuckets, short defaultValue) {
1620
maps[i] = new PrimitiveFastutilLongShortTreeWrapper(defaultValue);
1721
}
1822
}
23+
1924
@Override
2025
public int size() {
2126
return super.size(maps);
2227
}
28+
2329
@Override
2430
public boolean isEmpty() {
2531
return super.isEmpty(maps);
2632
}
33+
2734
@Override
2835
public boolean containsKey(long key) {
2936
int bucket = getBucket(key);
@@ -35,6 +42,7 @@ public boolean containsKey(long key) {
3542
readLock.unlock();
3643
}
3744
}
45+
3846
@Override
3947
public Long2ShortMap.Entry floorEntry(long key) {
4048
int bucket = getBucket(key);
@@ -46,6 +54,7 @@ public Long2ShortMap.Entry floorEntry(long key) {
4654
readLock.unlock();
4755
}
4856
}
57+
4958
@Override
5059
public short get(long l) {
5160
int bucket = getBucket(l);
@@ -59,6 +68,7 @@ public short get(long l) {
5968
}
6069
return result;
6170
}
71+
6272
@Override
6373
public short put(long key, short value) {
6474
int bucket = getBucket(key);
@@ -72,10 +82,12 @@ public short put(long key, short value) {
7282
}
7383
return result;
7484
}
85+
7586
@Override
7687
public short getDefaultValue() {
7788
return defaultValue;
7889
}
90+
7991
@Override
8092
public short remove(long key) {
8193
int bucket = getBucket(key);
@@ -87,6 +99,7 @@ public short remove(long key) {
8799
writeLock.unlock();
88100
}
89101
}
102+
90103
@Override
91104
public boolean remove(long key, short value) {
92105
int bucket = getBucket(key);
@@ -98,6 +111,7 @@ public boolean remove(long key, short value) {
98111
writeLock.unlock();
99112
}
100113
}
114+
101115
@Override
102116
public short computeIfAbsent(long key, Long2ShortFunction mappingFunction) {
103117
int bucket = getBucket(key);
@@ -109,6 +123,7 @@ public short computeIfAbsent(long key, Long2ShortFunction mappingFunction) {
109123
writeLock.unlock();
110124
}
111125
}
126+
112127
@Override
113128
public short computeIfPresent(long key, BiFunction<Long, Short, Short> mappingFunction) {
114129
int bucket = getBucket(key);

src/test/java/com/trivago/fastutilconcurrentwrapper/ConcurrentLongShortTreeMapBuilderTest.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
package com.trivago.fastutilconcurrentwrapper;
2+
23
import com.trivago.fastutilconcurrentwrapper.map.ConcurrentBusyWaitingLongShortTreeMap;
34
import com.trivago.fastutilconcurrentwrapper.map.ConcurrentLongShortTreeMap;
45
import org.junit.jupiter.api.Test;
6+
57
import static org.junit.jupiter.api.Assertions.assertEquals;
68
import static org.junit.jupiter.api.Assertions.assertTrue;
9+
710
public class ConcurrentLongShortTreeMapBuilderTest {
811
private final short DEFAULT_VALUE = -1;
12+
913
@Test
1014
public void buildsBusyWaitingMap() {
1115
ConcurrentLongShortTreeMapBuilder b = ConcurrentLongShortTreeMapBuilder.newBuilder()
@@ -19,6 +23,7 @@ public void buildsBusyWaitingMap() {
1923
assertEquals(10, v);
2024
assertEquals(map.get(2L), map.getDefaultValue());
2125
}
26+
2227
@Test
2328
public void buildsBlockingMap() {
2429
ConcurrentLongShortTreeMapBuilder b = ConcurrentLongShortTreeMapBuilder.newBuilder()

src/test/java/com/trivago/fastutilconcurrentwrapper/longshort/AbstractLongShortTreeMapTest.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,44 @@
11
package com.trivago.fastutilconcurrentwrapper.longshort;
2+
23
import com.trivago.fastutilconcurrentwrapper.AbstractMapTest;
34
import com.trivago.fastutilconcurrentwrapper.LongShortTreeMap;
45
import it.unimi.dsi.fastutil.longs.Long2ShortMap;
56
import org.junit.jupiter.api.BeforeEach;
67
import org.junit.jupiter.api.Test;
8+
79
import static org.junit.jupiter.api.Assertions.assertEquals;
810
import static org.junit.jupiter.api.Assertions.assertFalse;
911
import static org.junit.jupiter.api.Assertions.assertNotNull;
1012
import static org.junit.jupiter.api.Assertions.assertNull;
1113
import static org.junit.jupiter.api.Assertions.assertTrue;
14+
1215
abstract class AbstractLongShortTreeMapTest extends AbstractMapTest {
1316
private static final short FASTUTIL_DEFAULT_VALUE = 0;
1417
protected short defaultValue;
1518
private LongShortTreeMap map;
19+
1620
abstract LongShortTreeMap createMap();
21+
1722
@BeforeEach
1823
void initializeMap() {
1924
defaultValue = nextShort();
2025
map = createMap();
2126
}
27+
2228
@Test
2329
protected void containsKeyReturnsFalseIfMapIsEmpty() {
2430
final long key = nextLong();
2531
assertFalse(map.containsKey(key));
2632
}
33+
2734
@Test
2835
protected void containsKeyReturnsTrueIfKeyExists() {
2936
long key = nextLong();
3037
short value = nextShort();
3138
map.put(key, value);
3239
assertTrue(map.containsKey(key));
3340
}
41+
3442
@Test
3543
protected void containsKeyReturnsFalseIfKeyWasRemoved() {
3644
long key = nextLong();
@@ -39,10 +47,12 @@ protected void containsKeyReturnsFalseIfKeyWasRemoved() {
3947
map.remove(key);
4048
assertFalse(map.containsKey(key));
4149
}
50+
4251
@Test
4352
protected void mapIsEmptyWhenNothingWasInserted() {
4453
assertTrue(map.isEmpty());
4554
}
55+
4656
@Test
4757
protected void mapIsEmptyWhenAllKeysAreDeleted() {
4858
int entryCount = (Math.abs(nextInt()) % 100) + 1;
@@ -55,6 +65,7 @@ protected void mapIsEmptyWhenAllKeysAreDeleted() {
5565
}
5666
assertTrue(map.isEmpty());
5767
}
68+
5869
@Test
5970
protected void sizeIsCorrect() {
6071
int entries = (Math.abs(nextInt()) % 50) + 1;
@@ -64,57 +75,66 @@ protected void sizeIsCorrect() {
6475
}
6576
assertEquals(entries, map.size());
6677
}
78+
6779
@Test
6880
protected void gettingExistingValueReturnsCorrectValue() {
6981
long key = nextLong();
7082
short value = nextShort();
7183
map.put(key, value);
7284
assertEquals(value, map.get(key));
7385
}
86+
7487
@Test
7588
protected void gettingNonExistingValueReturnsCorrectValue() {
7689
long key = nextLong();
7790
assertEquals(defaultValue, map.get(key));
7891
}
92+
7993
@Test
8094
protected void removingNonExistingKeyReturnsDefaultValue() {
8195
long key = nextLong();
8296
assertEquals(defaultValue, map.remove(key));
8397
}
98+
8499
@Test
85100
protected void removingExistingKeyReturnsPreviousValue() {
86101
long key = nextLong();
87102
short value = nextShort();
88103
map.put(key, value);
89104
assertEquals(value, map.remove(key));
90105
}
106+
91107
@Test
92108
protected void removingWithValueWhenKeyDoesNotExistReturnsFalse() {
93109
long key = nextLong();
94110
short value = nextShort();
95111
assertFalse(map.remove(key, value));
96112
}
113+
97114
@Test
98115
protected void removingWithValueWhenValueIsDifferentReturnsFalse() {
99116
long key = nextLong();
100117
short value = nextShort();
101118
map.put(key, value);
102119
assertFalse(map.remove(key, (short) (value - 1)));
103120
}
121+
104122
@Test
105123
protected void removingWithValueWhenValueIsSameReturnsTrue() {
106124
long key = nextLong();
107125
short value = nextShort();
108126
map.put(key, value);
109127
assertTrue(map.remove(key, value));
110128
}
129+
111130
@Test
112131
protected void puttingValueIfAbsentReturnsSameValue() {
113132
long key = nextLong();
114133
short value = nextShort();
115134
map.computeIfAbsent(key, l -> value);
116135
assertEquals(value, map.get(key));
117136
}
137+
118138
@Test
119139
protected void checkingValueIfNotAbsentReturnsSameValue() {
120140
long key = nextLong();
@@ -124,6 +144,7 @@ protected void checkingValueIfNotAbsentReturnsSameValue() {
124144
assertEquals(value, map.get(key));
125145
assertEquals(value, returned);
126146
}
147+
127148
@Test
128149
protected void replacingValueIfPresentReturnsNewValue() {
129150
long key = nextLong();
@@ -132,17 +153,20 @@ protected void replacingValueIfPresentReturnsNewValue() {
132153
map.computeIfPresent(key, (aLongKey, aShortValue) -> (short) (2 * aShortValue));
133154
assertEquals((short) (2 * value), map.get(key));
134155
}
156+
135157
@Test
136158
protected void checkingValueIfNotPresentReturnsDefaultValue() {
137159
long key = nextLong();
138160
map.computeIfPresent(key, (aLongKey, aShortValue) -> (short) (2 * aShortValue));
139161
assertEquals(map.getDefaultValue(), map.get(key));
140162
}
163+
141164
// --- floorEntry tests ---
142165
@Test
143166
protected void floorEntryEmptyMapReturnsNull() {
144167
assertNull(map.floorEntry(100L));
145168
}
169+
146170
@Test
147171
protected void floorEntryExactMatchReturnsExactEntry() {
148172
map.put(10L, (short) 1);
@@ -153,6 +177,7 @@ protected void floorEntryExactMatchReturnsExactEntry() {
153177
assertEquals(20L, result.getLongKey());
154178
assertEquals((short) 2, result.getShortValue());
155179
}
180+
156181
@Test
157182
protected void floorEntryKeyBetweenEntriesReturnsPredecessor() {
158183
map.put(10L, (short) 1);
@@ -163,12 +188,14 @@ protected void floorEntryKeyBetweenEntriesReturnsPredecessor() {
163188
assertEquals(20L, result.getLongKey());
164189
assertEquals((short) 2, result.getShortValue());
165190
}
191+
166192
@Test
167193
protected void floorEntryKeyBelowMinimumReturnsNull() {
168194
map.put(10L, (short) 1);
169195
map.put(20L, (short) 2);
170196
assertNull(map.floorEntry(5L));
171197
}
198+
172199
@Test
173200
protected void floorEntryKeyAboveMaximumReturnsLastEntry() {
174201
map.put(10L, (short) 1);

src/test/java/com/trivago/fastutilconcurrentwrapper/longshort/ConcurrentBusyWaitingLongShortTreeMapTest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package com.trivago.fastutilconcurrentwrapper.longshort;
2+
23
import com.trivago.fastutilconcurrentwrapper.LongShortTreeMap;
34
import com.trivago.fastutilconcurrentwrapper.map.ConcurrentBusyWaitingLongShortTreeMap;
5+
46
public class ConcurrentBusyWaitingLongShortTreeMapTest extends AbstractLongShortTreeMapTest {
57
@Override
68
LongShortTreeMap createMap() {

src/test/java/com/trivago/fastutilconcurrentwrapper/longshort/ConcurrentPrimitiveLongShortTreeMapTest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package com.trivago.fastutilconcurrentwrapper.longshort;
2+
23
import com.trivago.fastutilconcurrentwrapper.LongShortTreeMap;
34
import com.trivago.fastutilconcurrentwrapper.map.ConcurrentLongShortTreeMap;
5+
46
public class ConcurrentPrimitiveLongShortTreeMapTest extends AbstractLongShortTreeMapTest {
57
@Override
68
LongShortTreeMap createMap() {

src/test/java/com/trivago/fastutilconcurrentwrapper/longshort/PrimitiveFastutilLongShortTreeWrapperTest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package com.trivago.fastutilconcurrentwrapper.longshort;
2+
23
import com.trivago.fastutilconcurrentwrapper.LongShortTreeMap;
34
import com.trivago.fastutilconcurrentwrapper.wrapper.PrimitiveFastutilLongShortTreeWrapper;
5+
46
public class PrimitiveFastutilLongShortTreeWrapperTest extends AbstractLongShortTreeMapTest {
57
@Override
68
LongShortTreeMap createMap() {

0 commit comments

Comments
 (0)