Skip to content

Commit c23345f

Browse files
committed
Add ConcurrentHashMap.KeySetView serializer
1 parent 5e8938f commit c23345f

File tree

2 files changed

+16
-14
lines changed

2 files changed

+16
-14
lines changed

src/com/esotericsoftware/kryo/serializers/DefaultSerializers.java

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
/* Copyright (c) 2008-2025, Nathan Sweet
22
* All rights reserved.
3-
*
3+
*
44
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following
55
* conditions are met:
6-
*
6+
*
77
* - Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
88
* - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following
99
* disclaimer in the documentation and/or other materials provided with the distribution.
1010
* - Neither the name of Esoteric Software nor the names of its contributors may be used to endorse or promote products derived
1111
* from this software without specific prior written permission.
12-
*
12+
*
1313
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
1414
* BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
1515
* SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
@@ -855,18 +855,20 @@ private PriorityQueue createPriorityQueue (Class<? extends Collection> type, int
855855

856856
/** Serializer for {@link ConcurrentHashMap.KeySetView}.
857857
* @author Andreas Bergander */
858-
public static class KeySetViewSerializer extends CollectionSerializer<ConcurrentHashMap.KeySetView> {
859-
protected void writeHeader (Kryo kryo, Output output, ConcurrentHashMap.KeySetView set) {
858+
public static class KeySetViewSerializer extends Serializer<ConcurrentHashMap.KeySetView> {
859+
public void write (Kryo kryo, Output output, ConcurrentHashMap.KeySetView set) {
860860
kryo.writeClassAndObject(output, set.getMap());
861861
kryo.writeClassAndObject(output, set.getMappedValue());
862862
}
863863

864-
protected ConcurrentHashMap.KeySetView create (Kryo kryo, Input input, Class<? extends ConcurrentHashMap.KeySetView> type, int size) {
864+
public ConcurrentHashMap.KeySetView read (Kryo kryo, Input input, Class<? extends ConcurrentHashMap.KeySetView> type) {
865865
return createKeySetView((ConcurrentHashMap)kryo.readClassAndObject(input), kryo.readClassAndObject(input));
866866
}
867867

868-
protected ConcurrentHashMap.KeySetView createCopy (Kryo kryo, ConcurrentHashMap.KeySetView original) {
869-
return createKeySetView(original.getMap(), original.getMappedValue());
868+
public ConcurrentHashMap.KeySetView copy (Kryo kryo, ConcurrentHashMap.KeySetView original) {
869+
870+
ConcurrentHashMap newMap = kryo.copy(original.getMap());
871+
return newMap.keySet(kryo.copy(original.getMappedValue()));
870872
}
871873

872874
private ConcurrentHashMap.KeySetView createKeySetView (ConcurrentHashMap map, Object mappedValue) {

test/com/esotericsoftware/kryo/serializers/DefaultSerializersTest.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
/* Copyright (c) 2008-2025, Nathan Sweet
22
* All rights reserved.
3-
*
3+
*
44
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following
55
* conditions are met:
6-
*
6+
*
77
* - Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
88
* - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following
99
* disclaimer in the documentation and/or other materials provided with the distribution.
1010
* - Neither the name of Esoteric Software nor the names of its contributors may be used to endorse or promote products derived
1111
* from this software without specific prior written permission.
12-
*
12+
*
1313
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
1414
* BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
1515
* SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
@@ -460,7 +460,7 @@ void testConcurrentHashMapKeySetView () {
460460
set.add(12);
461461
kryo.register(ConcurrentHashMap.KeySetView.class, new KeySetViewSerializer());
462462
kryo.register(ConcurrentHashMap.class);
463-
roundTrip(13, set);
463+
roundTrip(9, set);
464464
}
465465

466466
@Test
@@ -474,15 +474,15 @@ void testConcurrentHashMapKeySetViewFromExistingMap () {
474474

475475
kryo.register(ConcurrentHashMap.KeySetView.class, new KeySetViewSerializer());
476476
kryo.register(ConcurrentHashMap.class);
477-
roundTrip(22, set);
477+
roundTrip(15, set);
478478
}
479479

480480
@Test
481481
void testEmptyConcurrentHashMapKeySetView () {
482482
ConcurrentHashMap.KeySetView set = ConcurrentHashMap.newKeySet();
483483
kryo.register(ConcurrentHashMap.KeySetView.class, new KeySetViewSerializer());
484484
kryo.register(ConcurrentHashMap.class);
485-
roundTrip(6, set);
485+
roundTrip(5, set);
486486
}
487487

488488
@Test

0 commit comments

Comments
 (0)