From 218e25878439f8cd4234dd22a5fe8ad00925175a Mon Sep 17 00:00:00 2001 From: "Robert J. Moore" <Robert.J.Moore@allanbank.com> Date: Sun, 4 May 2014 22:30:27 -0400 Subject: [PATCH] Cleanup --- .../com/yahoo/ycsb/db/AsyncMongoDbClient.java | 60 +++++++++---------- 1 file changed, 30 insertions(+), 30 deletions(-) diff --git a/mongodb/src/main/java/com/yahoo/ycsb/db/AsyncMongoDbClient.java b/mongodb/src/main/java/com/yahoo/ycsb/db/AsyncMongoDbClient.java index 1b16220c..645b233e 100644 --- a/mongodb/src/main/java/com/yahoo/ycsb/db/AsyncMongoDbClient.java +++ b/mongodb/src/main/java/com/yahoo/ycsb/db/AsyncMongoDbClient.java @@ -51,17 +51,25 @@ public class AsyncMongoDbClient extends DB { /** The database to use. */ private static String database; + /** Thread local document builder. */ + private static final ThreadLocal<DocumentBuilder> DOCUMENT_BUILDER = new ThreadLocal<DocumentBuilder>() { + @Override + protected DocumentBuilder initialValue() { + return BuilderFactory.start(); + } + }; + + /** The write concern for the requests. */ + private static final AtomicInteger initCount = new AtomicInteger(0); + /** The connection to MongoDB. */ private static MongoClient mongo; - /** The database to MongoDB. */ - private MongoDatabase db; - /** The write concern for the requests. */ private static Durability writeConcern; - /** The write concern for the requests. */ - private static final AtomicInteger initCount = new AtomicInteger(0); + /** The database to MongoDB. */ + private MongoDatabase db; /** * Cleanup any state for this DB. Called once per DB instance; there is one @@ -112,7 +120,7 @@ public class AsyncMongoDbClient extends DB { */ @Override public final void init() throws DBException { - int count = initCount.incrementAndGet(); + final int count = initCount.incrementAndGet(); final Properties props = getProperties(); final String maxConnections = props.getProperty( @@ -221,14 +229,6 @@ public class AsyncMongoDbClient extends DB { } } - /** Thread local document builder. */ - private static final ThreadLocal<DocumentBuilder> DOCUMENT_BUILDER = new ThreadLocal<DocumentBuilder>() { - @Override - protected DocumentBuilder initialValue() { - return BuilderFactory.start(); - } - }; - /** * Read a record from the database. Each field/value pair from the result * will be stored in a HashMap. @@ -316,8 +316,8 @@ public class AsyncMongoDbClient extends DB { fb.setLimit(recordcount); fb.setBatchSize(recordcount); if (fields != null) { - DocumentBuilder fieldsDoc = BuilderFactory.start(); - for (String field : fields) { + final DocumentBuilder fieldsDoc = BuilderFactory.start(); + for (final String field : fields) { fieldsDoc.add(field, 1); } @@ -419,7 +419,7 @@ public class AsyncMongoDbClient extends DB { * @param element * The {@link BinaryElement} to iterate over. */ - public BinaryByteArrayIterator(BinaryElement element) { + public BinaryByteArrayIterator(final BinaryElement element) { this.binaryElement = element; this.offset = 0; } @@ -427,38 +427,38 @@ public class AsyncMongoDbClient extends DB { /** * {@inheritDoc} * <p> - * Overridden to return true if there is more data in the - * {@link BinaryElement}. + * Overridden to return the number of bytes remaining in the iterator. * </p> */ @Override - public boolean hasNext() { - return (offset < binaryElement.length()); + public long bytesLeft() { + return Math.max(0, binaryElement.length() - offset); } /** * {@inheritDoc} * <p> - * Overridden to return the myNext value and advance the iterator. + * Overridden to return true if there is more data in the + * {@link BinaryElement}. * </p> */ @Override - public byte nextByte() { - byte value = binaryElement.get(offset); - offset += 1; - - return value; + public boolean hasNext() { + return (offset < binaryElement.length()); } /** * {@inheritDoc} * <p> - * Overridden to return the number of bytes remaining in the iterator. + * Overridden to return the next value and advance the iterator. * </p> */ @Override - public long bytesLeft() { - return Math.max(0, binaryElement.length() - offset); + public byte nextByte() { + final byte value = binaryElement.get(offset); + offset += 1; + + return value; } } } -- GitLab