Code cleanup: import static.

This commit is contained in:
akwizgran
2013-01-17 16:56:58 +00:00
parent 77a5fea5c8
commit b8247968b6
18 changed files with 124 additions and 104 deletions

View File

@@ -1,5 +1,7 @@
package net.sf.briar.db;
import static java.sql.Types.BINARY;
import java.io.File;
import java.sql.Connection;
import java.sql.DriverManager;
@@ -7,7 +9,6 @@ import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.Types;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
@@ -119,7 +120,7 @@ public class BasicH2Test extends BriarTestCase {
String sql = "INSERT INTO foo (uniqueId, name) VALUES (?, ?)";
try {
PreparedStatement ps = connection.prepareStatement(sql);
if(id == null) ps.setNull(1, Types.BINARY);
if(id == null) ps.setNull(1, BINARY);
else ps.setBytes(1, id);
ps.setString(2, name);
int rowsAffected = ps.executeUpdate();

View File

@@ -1,6 +1,7 @@
package net.sf.briar.protocol;
import static net.sf.briar.api.protocol.ProtocolConstants.MAX_PACKET_LENGTH;
import static net.sf.briar.api.protocol.Types.ACK;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
@@ -11,7 +12,6 @@ import net.sf.briar.TestUtils;
import net.sf.briar.api.FormatException;
import net.sf.briar.api.protocol.Ack;
import net.sf.briar.api.protocol.PacketFactory;
import net.sf.briar.api.protocol.Types;
import net.sf.briar.api.serial.Reader;
import net.sf.briar.api.serial.ReaderFactory;
import net.sf.briar.api.serial.SerialComponent;
@@ -52,10 +52,10 @@ public class AckReaderTest extends BriarTestCase {
byte[] b = createAck(true);
ByteArrayInputStream in = new ByteArrayInputStream(b);
Reader reader = readerFactory.createReader(in);
reader.addStructReader(Types.ACK, ackReader);
reader.addStructReader(ACK, ackReader);
try {
reader.readStruct(Types.ACK, Ack.class);
reader.readStruct(ACK, Ack.class);
fail();
} catch(FormatException expected) {}
context.assertIsSatisfied();
@@ -75,9 +75,9 @@ public class AckReaderTest extends BriarTestCase {
byte[] b = createAck(false);
ByteArrayInputStream in = new ByteArrayInputStream(b);
Reader reader = readerFactory.createReader(in);
reader.addStructReader(Types.ACK, ackReader);
reader.addStructReader(ACK, ackReader);
assertEquals(ack, reader.readStruct(Types.ACK, Ack.class));
assertEquals(ack, reader.readStruct(ACK, Ack.class));
context.assertIsSatisfied();
}
@@ -89,10 +89,10 @@ public class AckReaderTest extends BriarTestCase {
byte[] b = createEmptyAck();
ByteArrayInputStream in = new ByteArrayInputStream(b);
Reader reader = readerFactory.createReader(in);
reader.addStructReader(Types.ACK, ackReader);
reader.addStructReader(ACK, ackReader);
try {
reader.readStruct(Types.ACK, Ack.class);
reader.readStruct(ACK, Ack.class);
fail();
} catch(FormatException expected) {}
context.assertIsSatisfied();
@@ -101,7 +101,7 @@ public class AckReaderTest extends BriarTestCase {
private byte[] createAck(boolean tooBig) throws Exception {
ByteArrayOutputStream out = new ByteArrayOutputStream();
Writer w = writerFactory.createWriter(out);
w.writeStructId(Types.ACK);
w.writeStructId(ACK);
w.writeListStart();
while(out.size() + serial.getSerialisedUniqueIdLength()
< MAX_PACKET_LENGTH) {
@@ -116,7 +116,7 @@ public class AckReaderTest extends BriarTestCase {
private byte[] createEmptyAck() throws Exception {
ByteArrayOutputStream out = new ByteArrayOutputStream();
Writer w = writerFactory.createWriter(out);
w.writeStructId(Types.ACK);
w.writeStructId(ACK);
w.writeListStart();
w.writeListEnd();
return out.toByteArray();

View File

@@ -1,6 +1,7 @@
package net.sf.briar.protocol;
import static net.sf.briar.api.protocol.ProtocolConstants.MAX_PACKET_LENGTH;
import static net.sf.briar.api.protocol.Types.OFFER;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
@@ -11,7 +12,6 @@ import net.sf.briar.TestUtils;
import net.sf.briar.api.FormatException;
import net.sf.briar.api.protocol.Offer;
import net.sf.briar.api.protocol.PacketFactory;
import net.sf.briar.api.protocol.Types;
import net.sf.briar.api.serial.Reader;
import net.sf.briar.api.serial.ReaderFactory;
import net.sf.briar.api.serial.SerialComponent;
@@ -52,10 +52,10 @@ public class OfferReaderTest extends BriarTestCase {
byte[] b = createOffer(true);
ByteArrayInputStream in = new ByteArrayInputStream(b);
Reader reader = readerFactory.createReader(in);
reader.addStructReader(Types.OFFER, offerReader);
reader.addStructReader(OFFER, offerReader);
try {
reader.readStruct(Types.OFFER, Offer.class);
reader.readStruct(OFFER, Offer.class);
fail();
} catch(FormatException expected) {}
context.assertIsSatisfied();
@@ -75,9 +75,9 @@ public class OfferReaderTest extends BriarTestCase {
byte[] b = createOffer(false);
ByteArrayInputStream in = new ByteArrayInputStream(b);
Reader reader = readerFactory.createReader(in);
reader.addStructReader(Types.OFFER, offerReader);
reader.addStructReader(OFFER, offerReader);
assertEquals(offer, reader.readStruct(Types.OFFER, Offer.class));
assertEquals(offer, reader.readStruct(OFFER, Offer.class));
context.assertIsSatisfied();
}
@@ -89,10 +89,10 @@ public class OfferReaderTest extends BriarTestCase {
byte[] b = createEmptyOffer();
ByteArrayInputStream in = new ByteArrayInputStream(b);
Reader reader = readerFactory.createReader(in);
reader.addStructReader(Types.OFFER, offerReader);
reader.addStructReader(OFFER, offerReader);
try {
reader.readStruct(Types.OFFER, Offer.class);
reader.readStruct(OFFER, Offer.class);
fail();
} catch(FormatException expected) {}
context.assertIsSatisfied();
@@ -101,7 +101,7 @@ public class OfferReaderTest extends BriarTestCase {
private byte[] createOffer(boolean tooBig) throws Exception {
ByteArrayOutputStream out = new ByteArrayOutputStream();
Writer w = writerFactory.createWriter(out);
w.writeStructId(Types.OFFER);
w.writeStructId(OFFER);
w.writeListStart();
while(out.size() + serial.getSerialisedUniqueIdLength()
< MAX_PACKET_LENGTH) {
@@ -116,7 +116,7 @@ public class OfferReaderTest extends BriarTestCase {
private byte[] createEmptyOffer() throws Exception {
ByteArrayOutputStream out = new ByteArrayOutputStream();
Writer w = writerFactory.createWriter(out);
w.writeStructId(Types.OFFER);
w.writeStructId(OFFER);
w.writeListStart();
w.writeListEnd();
return out.toByteArray();

View File

@@ -1,6 +1,7 @@
package net.sf.briar.protocol;
import static net.sf.briar.api.protocol.ProtocolConstants.MAX_PACKET_LENGTH;
import static net.sf.briar.api.protocol.Types.REQUEST;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
@@ -10,7 +11,6 @@ import net.sf.briar.BriarTestCase;
import net.sf.briar.api.FormatException;
import net.sf.briar.api.protocol.PacketFactory;
import net.sf.briar.api.protocol.Request;
import net.sf.briar.api.protocol.Types;
import net.sf.briar.api.serial.Reader;
import net.sf.briar.api.serial.ReaderFactory;
import net.sf.briar.api.serial.Writer;
@@ -53,10 +53,10 @@ public class RequestReaderTest extends BriarTestCase {
byte[] b = createRequest(true);
ByteArrayInputStream in = new ByteArrayInputStream(b);
Reader reader = readerFactory.createReader(in);
reader.addStructReader(Types.REQUEST, requestReader);
reader.addStructReader(REQUEST, requestReader);
try {
reader.readStruct(Types.REQUEST, Request.class);
reader.readStruct(REQUEST, Request.class);
fail();
} catch(FormatException expected) {}
context.assertIsSatisfied();
@@ -76,10 +76,9 @@ public class RequestReaderTest extends BriarTestCase {
byte[] b = createRequest(false);
ByteArrayInputStream in = new ByteArrayInputStream(b);
Reader reader = readerFactory.createReader(in);
reader.addStructReader(Types.REQUEST, requestReader);
reader.addStructReader(REQUEST, requestReader);
assertEquals(request, reader.readStruct(Types.REQUEST,
Request.class));
assertEquals(request, reader.readStruct(REQUEST, Request.class));
context.assertIsSatisfied();
}
@@ -106,8 +105,8 @@ public class RequestReaderTest extends BriarTestCase {
ByteArrayInputStream in = new ByteArrayInputStream(b);
Reader reader = readerFactory.createReader(in);
RequestReader requestReader = new RequestReader(packetFactory);
reader.addStructReader(Types.REQUEST, requestReader);
Request r = reader.readStruct(Types.REQUEST, Request.class);
reader.addStructReader(REQUEST, requestReader);
Request r = reader.readStruct(REQUEST, Request.class);
BitSet decoded = r.getBitmap();
// Check that the decoded BitSet matches the original - we can't
// use equals() because of padding, but the first i bits should
@@ -123,7 +122,7 @@ public class RequestReaderTest extends BriarTestCase {
private byte[] createRequest(boolean tooBig) throws Exception {
ByteArrayOutputStream out = new ByteArrayOutputStream();
Writer w = writerFactory.createWriter(out);
w.writeStructId(Types.REQUEST);
w.writeStructId(REQUEST);
// Allow one byte for the REQUEST tag, one byte for the padding length
// as a uint7, one byte for the BYTES tag, and five bytes for the
// length of the byte array as an int32
@@ -139,7 +138,7 @@ public class RequestReaderTest extends BriarTestCase {
private byte[] createRequest(byte[] bitmap) throws Exception {
ByteArrayOutputStream out = new ByteArrayOutputStream();
Writer w = writerFactory.createWriter(out);
w.writeStructId(Types.REQUEST);
w.writeStructId(REQUEST);
w.writeUint7((byte) 0);
w.writeBytes(bitmap);
return out.toByteArray();