Code cleanup, fixup warnings

This commit is contained in:
nathan 2014-09-04 18:28:10 +02:00
parent 66cb0d4029
commit f56631f3fb
7 changed files with 92 additions and 93 deletions

View File

@ -114,7 +114,7 @@ public class EndPointWithSerialization extends EndPoint {
throw new RuntimeException("Cannot create a remote object space after the remote endpoint has already connected!");
}
this.remoteObjectSpace = new RmiBridge(this.logger, this.name);
this.remoteObjectSpace = new RmiBridge(this.logger);
}
}

View File

@ -78,8 +78,6 @@ public class RmiBridge {
// the name of who created this object space.
private final org.slf4j.Logger logger;
private final String name;
private final Listener<Connection, InvokeMethod> invokeListener= new Listener<Connection, InvokeMethod>() {
@Override
public void received(final Connection connection, final InvokeMethod invokeMethod) {
@ -140,9 +138,8 @@ public class RmiBridge {
* <p>
* For safety, this should ONLY be called by {@link EndPoint#getRmiBridge() }
*/
public RmiBridge(Logger logger, String name) {
public RmiBridge(Logger logger) {
this.logger = logger;
this.name = "RMI - " + name + " (remote)";
instances.addIfAbsent(this);
}

View File

@ -14,7 +14,6 @@ import dorkbox.network.util.SerializationManager;
import dorkbox.network.util.exceptions.InitializationException;
import dorkbox.network.util.exceptions.SecurityException;
@SuppressWarnings({"rawtypes"})
public class ChunkedDataTest extends BaseTest {
private volatile boolean success = false;

View File

@ -13,6 +13,7 @@ import com.esotericsoftware.kryo.io.Input;
import com.esotericsoftware.kryo.io.Output;
/** @author Nathan Sweet <misc@n4te.com> */
@SuppressWarnings("resource")
public class InputOutputTest extends KryoTestCase {
public void testOutputStream () throws IOException {
ByteArrayOutputStream buffer = new ByteArrayOutputStream();

View File

@ -9,7 +9,7 @@ import java.util.Random;
import java.util.TreeMap;
import java.util.concurrent.ConcurrentHashMap;
import junit.framework.Assert;
import org.junit.Assert;
import com.esotericsoftware.kryo.Kryo;
import com.esotericsoftware.kryo.io.Input;
@ -18,117 +18,117 @@ import com.esotericsoftware.kryo.serializers.MapSerializer;
/** @author Nathan Sweet <misc@n4te.com> */
public class MapSerializerTest extends KryoTestCase {
{
supportsCopy = true;
}
{
supportsCopy = true;
}
@SuppressWarnings({"rawtypes","unchecked"})
@SuppressWarnings({"rawtypes","unchecked"})
public void testMaps () {
kryo.register(HashMap.class);
kryo.register(LinkedHashMap.class);
HashMap map = new HashMap();
map.put("123", "456");
map.put("789", "abc");
roundTrip(18, 21, map);
roundTrip(2, 5, new LinkedHashMap());
roundTrip(18, 21, new LinkedHashMap(map));
kryo.register(HashMap.class);
kryo.register(LinkedHashMap.class);
HashMap map = new HashMap();
map.put("123", "456");
map.put("789", "abc");
roundTrip(18, 21, map);
roundTrip(2, 5, new LinkedHashMap());
roundTrip(18, 21, new LinkedHashMap(map));
MapSerializer serializer = new MapSerializer();
kryo.register(HashMap.class, serializer);
kryo.register(LinkedHashMap.class, serializer);
serializer.setKeyClass(String.class, kryo.getSerializer(String.class));
serializer.setKeysCanBeNull(false);
serializer.setValueClass(String.class, kryo.getSerializer(String.class));
roundTrip(14, 17, map);
serializer.setValuesCanBeNull(false);
roundTrip(14, 17, map);
}
MapSerializer serializer = new MapSerializer();
kryo.register(HashMap.class, serializer);
kryo.register(LinkedHashMap.class, serializer);
serializer.setKeyClass(String.class, kryo.getSerializer(String.class));
serializer.setKeysCanBeNull(false);
serializer.setValueClass(String.class, kryo.getSerializer(String.class));
roundTrip(14, 17, map);
serializer.setValuesCanBeNull(false);
roundTrip(14, 17, map);
}
public void testEmptyHashMap () {
execute(new HashMap<Object, Object>(), 0);
}
public void testEmptyHashMap () {
execute(new HashMap<Object, Object>(), 0);
}
public void testNotEmptyHashMap () {
execute(new HashMap<Object, Object>(), 1000);
}
public void testNotEmptyHashMap () {
execute(new HashMap<Object, Object>(), 1000);
}
public void testEmptyConcurrentHashMap () {
execute(new ConcurrentHashMap<Object, Object>(), 0);
}
public void testEmptyConcurrentHashMap () {
execute(new ConcurrentHashMap<Object, Object>(), 0);
}
public void testNotEmptyConcurrentHashMap () {
execute(new ConcurrentHashMap<Object, Object>(), 1000);
}
public void testNotEmptyConcurrentHashMap () {
execute(new ConcurrentHashMap<Object, Object>(), 1000);
}
public void testGenerics () {
kryo.register(HasGenerics.class);
kryo.register(Integer[].class);
kryo.register(HashMap.class);
public void testGenerics () {
kryo.register(HasGenerics.class);
kryo.register(Integer[].class);
kryo.register(HashMap.class);
HasGenerics test = new HasGenerics();
test.map.put("moo", new Integer[] {1, 2});
HasGenerics test = new HasGenerics();
test.map.put("moo", new Integer[] {1, 2});
output = new Output(4096);
kryo.writeClassAndObject(output, test);
output.flush();
output = new Output(4096);
kryo.writeClassAndObject(output, test);
output.flush();
input = new Input(output.toBytes());
HasGenerics test2 = (HasGenerics)kryo.readClassAndObject(input);
assertEquals(test.map.get("moo"), test2.map.get("moo"));
}
input = new Input(output.toBytes());
HasGenerics test2 = (HasGenerics)kryo.readClassAndObject(input);
assertEquals(test.map.get("moo"), test2.map.get("moo"));
}
private void execute (Map<Object, Object> map, int inserts) {
Random random = new Random();
for (int i = 0; i < inserts; i++) {
private void execute (Map<Object, Object> map, int inserts) {
Random random = new Random();
for (int i = 0; i < inserts; i++) {
map.put(random.nextLong(), random.nextBoolean());
}
Kryo kryo = new Kryo();
kryo.register(HashMap.class, new MapSerializer());
kryo.register(ConcurrentHashMap.class, new MapSerializer());
Kryo kryo = new Kryo();
kryo.register(HashMap.class, new MapSerializer());
kryo.register(ConcurrentHashMap.class, new MapSerializer());
Output output = new Output(2048, -1);
kryo.writeClassAndObject(output, map);
output.close();
Output output = new Output(2048, -1);
kryo.writeClassAndObject(output, map);
output.close();
Input input = new Input(output.toBytes());
Object deserialized = kryo.readClassAndObject(input);
input.close();
Input input = new Input(output.toBytes());
Object deserialized = kryo.readClassAndObject(input);
input.close();
Assert.assertEquals(map, deserialized);
}
Assert.assertEquals(map, deserialized);
}
@SuppressWarnings({"unchecked","rawtypes"})
@SuppressWarnings({"unchecked","rawtypes"})
public void testTreeMap () {
kryo.register(TreeMap.class);
TreeMap map = new TreeMap();
map.put("123", "456");
map.put("789", "abc");
roundTrip(19, 22, map);
kryo.register(TreeMap.class);
TreeMap map = new TreeMap();
map.put("123", "456");
map.put("789", "abc");
roundTrip(19, 22, map);
kryo.register(KeyThatIsntComparable.class);
kryo.register(KeyComparator.class);
map = new TreeMap(new KeyComparator());
KeyThatIsntComparable key = new KeyThatIsntComparable();
key.value = "123";
map.put(key, "456");
roundTrip(11, 14, map);
}
kryo.register(KeyThatIsntComparable.class);
kryo.register(KeyComparator.class);
map = new TreeMap(new KeyComparator());
KeyThatIsntComparable key = new KeyThatIsntComparable();
key.value = "123";
map.put(key, "456");
roundTrip(11, 14, map);
}
@SuppressWarnings({"unchecked","rawtypes"})
static public class HasGenerics {
@SuppressWarnings({"unchecked","rawtypes"})
static public class HasGenerics {
public HashMap<String, Integer[]> map = new HashMap();
public HashMap<String, ?> map2 = new HashMap();
}
}
static public class KeyComparator implements Comparator<KeyThatIsntComparable> {
@Override
static public class KeyComparator implements Comparator<KeyThatIsntComparable> {
@Override
public int compare (KeyThatIsntComparable o1, KeyThatIsntComparable o2) {
return o1.value.compareTo(o2.value);
}
}
return o1.value.compareTo(o2.value);
}
}
static public class KeyThatIsntComparable {
public String value;
}
static public class KeyThatIsntComparable {
public String value;
}
}

View File

@ -12,6 +12,7 @@ import com.esotericsoftware.kryo.io.UnsafeInput;
import com.esotericsoftware.kryo.io.UnsafeOutput;
/** @author Nathan Sweet <misc@n4te.com> */
@SuppressWarnings("resource")
public class UnsafeInputOutputTest extends KryoTestCase {
public void testOutputStream () throws IOException {
ByteArrayOutputStream buffer = new ByteArrayOutputStream();

View File

@ -14,6 +14,7 @@ import com.esotericsoftware.kryo.io.UnsafeMemoryOutput;
import com.esotericsoftware.kryo.util.UnsafeUtil;
/** @author Roman Levenstein <romixlev@gmail.com> */
@SuppressWarnings("resource")
public class UnsafeMemoryInputOutputTest extends KryoTestCase {
public void testByteBufferOutputWithPreallocatedMemory () {