Skip to content

Commit ce135e5

Browse files
committed
Apply final keyword where appropriate
1 parent dd18470 commit ce135e5

File tree

6 files changed

+46
-47
lines changed

6 files changed

+46
-47
lines changed

src/main/java/org/lmdbjava/Cursor.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public class Cursor {
3737
private final Pointer ptr;
3838
private final Txn tx;
3939

40-
Cursor(Pointer ptr, Txn tx) {
40+
Cursor(final Pointer ptr, final Txn tx) {
4141
this.ptr = ptr;
4242
this.tx = tx;
4343
}
@@ -65,7 +65,7 @@ public void close() {
6565
* @throws LmdbNativeException if a native C error occurred
6666
*/
6767
public long count() throws LmdbNativeException {
68-
NativeLongByReference longByReference = new NativeLongByReference();
68+
final NativeLongByReference longByReference = new NativeLongByReference();
6969
checkRc(lib.mdb_cursor_count(ptr, longByReference));
7070
return longByReference.longValue();
7171
}
@@ -95,7 +95,7 @@ public void delete() throws LmdbNativeException {
9595
* @param op A cursor operation.
9696
* @throws LmdbNativeException if a native C error occurred
9797
*/
98-
public void get(ByteBuffer key, ByteBuffer val, CursorOp op)
98+
public void get(final ByteBuffer key, final ByteBuffer val, final CursorOp op)
9999
throws LmdbNativeException {
100100
requireNonNull(key);
101101
requireNonNull(val);
@@ -129,7 +129,8 @@ public void get(ByteBuffer key, ByteBuffer val, CursorOp op)
129129
* @param op Options for this operation.
130130
* @throws LmdbNativeException if a native C error occurred
131131
*/
132-
public void put(ByteBuffer key, ByteBuffer val, PutFlags... op)
132+
public void put(final ByteBuffer key, final ByteBuffer val,
133+
final PutFlags... op)
133134
throws LmdbNativeException {
134135
requireNonNull(key);
135136
requireNonNull(val);
@@ -158,7 +159,7 @@ public void put(ByteBuffer key, ByteBuffer val, PutFlags... op)
158159
* @param tx transaction handle
159160
* @throws LmdbNativeException if a native C error occurred
160161
*/
161-
public void renew(Txn tx) throws LmdbNativeException {
162+
public void renew(final Txn tx) throws LmdbNativeException {
162163
if (!tx.isReadOnly()) {
163164
throw new IllegalArgumentException("cannot renew write transactions");
164165
}

src/main/java/org/lmdbjava/Dbi.java

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
package org.lmdbjava;
32

43
import java.nio.ByteBuffer;
@@ -39,7 +38,7 @@ public final class Dbi {
3938
* @throws CommittedException if already committed
4039
* @throws LmdbNativeException if a native C error occurred
4140
*/
42-
public Dbi(Txn tx, String name, DbiFlags... flags)
41+
public Dbi(final Txn tx, final String name, final DbiFlags... flags)
4342
throws CommittedException, LmdbNativeException {
4443
requireNonNull(tx);
4544
if (tx.isCommitted()) {
@@ -60,7 +59,7 @@ public Dbi(Txn tx, String name, DbiFlags... flags)
6059
* @throws LmdbNativeException if a native C error occurred
6160
* @see #delete(Txn, ByteBuffer, ByteBuffer)
6261
*/
63-
public void delete(ByteBuffer key) throws
62+
public void delete(final ByteBuffer key) throws
6463
CommittedException, LmdbNativeException, NotOpenException {
6564
try (Txn tx = new Txn(env)) {
6665
delete(tx, key);
@@ -75,7 +74,7 @@ public void delete(ByteBuffer key) throws
7574
* @throws LmdbNativeException if a native C error occurred
7675
* @see #delete(Txn, ByteBuffer, ByteBuffer)
7776
*/
78-
public void delete(Txn tx, ByteBuffer key) throws
77+
public void delete(final Txn tx, final ByteBuffer key) throws
7978
CommittedException, LmdbNativeException {
8079
delete(tx, key, null);
8180
}
@@ -85,20 +84,21 @@ public void delete(Txn tx, ByteBuffer key) throws
8584
* Removes key/data pairs from the database.
8685
* </p>
8786
* If the database does not support sorted duplicate data items
88-
* ({@link org.lmdbjava.DbiFlags#MDB_DUPSORT}) the value parameter is
89-
* ignored. If the database supports sorted duplicates and the data parameter
90-
* is NULL, all of the duplicate data items for the key will be deleted.
91-
* Otherwise, if the data parameter is non-NULL only the matching data item
92-
* will be deleted. This function will return false if the specified key/data
93-
* pair is not in the database.
87+
* ({@link org.lmdbjava.DbiFlags#MDB_DUPSORT}) the value parameter is ignored.
88+
* If the database supports sorted duplicates and the data parameter is NULL,
89+
* all of the duplicate data items for the key will be deleted. Otherwise, if
90+
* the data parameter is non-NULL only the matching data item will be deleted.
91+
* This function will return false if the specified key/data pair is not in
92+
* the database.
9493
*
9594
* @param tx Transaction handle
9695
* @param key The key to delete from the database
9796
* @param val The value to delete from the database
9897
* @throws CommittedException if already committed
9998
* @throws LmdbNativeException if a native C error occurred
10099
*/
101-
public void delete(Txn tx, ByteBuffer key, ByteBuffer val) throws
100+
public void delete(final Txn tx, final ByteBuffer key, final ByteBuffer val)
101+
throws
102102
CommittedException, LmdbNativeException {
103103

104104
final MDB_val k = createVal(key);
@@ -116,7 +116,7 @@ public void delete(Txn tx, ByteBuffer key, ByteBuffer val) throws
116116
* @throws LmdbNativeException if a native C error occurred
117117
* @see #get(Txn, ByteBuffer)
118118
*/
119-
public ByteBuffer get(ByteBuffer key) throws
119+
public ByteBuffer get(final ByteBuffer key) throws
120120
CommittedException, LmdbNativeException, NotOpenException {
121121
try (Txn tx = new Txn(env, MDB_RDONLY)) {
122122
return get(tx, key);
@@ -131,8 +131,8 @@ public ByteBuffer get(ByteBuffer key) throws
131131
* This function retrieves key/data pairs from the database. The address and
132132
* length of the data associated with the specified \b key are returned in the
133133
* structure to which \b data refers. If the database supports duplicate keys
134-
* ({@link org.lmdbjava.DbiFlags#MDB_DUPSORT}) then the first data item
135-
* for the key will be returned. Retrieval of other items requires the use of
134+
* ({@link org.lmdbjava.DbiFlags#MDB_DUPSORT}) then the first data item for
135+
* the key will be returned. Retrieval of other items requires the use of
136136
* #mdb_cursor_get().
137137
*
138138
* @param tx transaction handle
@@ -142,7 +142,7 @@ public ByteBuffer get(ByteBuffer key) throws
142142
* @throws CommittedException if already committed
143143
* @throws LmdbNativeException if a native C error occurred
144144
*/
145-
public ByteBuffer get(Txn tx, ByteBuffer key) throws
145+
public ByteBuffer get(final Txn tx, final ByteBuffer key) throws
146146
CommittedException, LmdbNativeException {
147147
assert key.isDirect();
148148

@@ -152,7 +152,7 @@ public ByteBuffer get(Txn tx, ByteBuffer key) throws
152152
checkRc(lib.mdb_get(tx.ptr, dbi, k, v));
153153

154154
// inefficient as we create a BB
155-
ByteBuffer bb = allocateDirect(1).order(LITTLE_ENDIAN);
155+
final ByteBuffer bb = allocateDirect(1).order(LITTLE_ENDIAN);
156156
wrap(bb, v);
157157
return bb;
158158
}
@@ -187,7 +187,7 @@ public String getName() {
187187
* @param tx transaction handle
188188
* @return cursor handle
189189
*/
190-
public Cursor openCursor(Txn tx) throws LmdbNativeException {
190+
public Cursor openCursor(final Txn tx) throws LmdbNativeException {
191191
PointerByReference ptr = new PointerByReference();
192192
checkRc(lib.mdb_cursor_open(tx.ptr, dbi, ptr));
193193
return new Cursor(ptr.getValue(), tx);
@@ -201,7 +201,7 @@ public Cursor openCursor(Txn tx) throws LmdbNativeException {
201201
* @throws LmdbNativeException if a native C error occurred
202202
* @see #put(Txn, ByteBuffer, ByteBuffer, DatabaseFlags...)
203203
*/
204-
public void put(ByteBuffer key, ByteBuffer val) throws
204+
public void put(final ByteBuffer key, final ByteBuffer val) throws
205205
CommittedException, LmdbNativeException, NotOpenException {
206206
try (Txn tx = new Txn(env)) {
207207
put(tx, key, val);
@@ -226,9 +226,9 @@ public void put(ByteBuffer key, ByteBuffer val) throws
226226
* @throws CommittedException if already committed
227227
* @throws LmdbNativeException if a native C error occurred
228228
*/
229-
public void put(Txn tx, ByteBuffer key, ByteBuffer val, DbiFlags... flags)
230-
throws
231-
CommittedException, LmdbNativeException {
229+
public void put(final Txn tx, final ByteBuffer key, final ByteBuffer val,
230+
final DbiFlags... flags)
231+
throws CommittedException, LmdbNativeException {
232232

233233
final MDB_val k = createVal(key);
234234
final MDB_val v = createVal(val);

src/main/java/org/lmdbjava/Env.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,9 @@ public void close() {
7171
* @throws AlreadyClosedException if already closed
7272
* @throws LmdbNativeException if a native C error occurred
7373
*/
74-
public void setMapSize(int mapSize) throws AlreadyOpenException,
75-
AlreadyClosedException,
76-
LmdbNativeException {
74+
public void setMapSize(final int mapSize) throws AlreadyOpenException,
75+
AlreadyClosedException,
76+
LmdbNativeException {
7777
if (open) {
7878
throw new AlreadyOpenException();
7979
}
@@ -91,9 +91,9 @@ public void setMapSize(int mapSize) throws AlreadyOpenException,
9191
* @throws AlreadyClosedException if already closed
9292
* @throws LmdbNativeException if a native C error occurred
9393
*/
94-
public void setMaxDbs(int dbs) throws AlreadyOpenException,
95-
AlreadyClosedException,
96-
LmdbNativeException {
94+
public void setMaxDbs(final int dbs) throws AlreadyOpenException,
95+
AlreadyClosedException,
96+
LmdbNativeException {
9797
if (open) {
9898
throw new AlreadyOpenException();
9999
}
@@ -111,9 +111,9 @@ public void setMaxDbs(int dbs) throws AlreadyOpenException,
111111
* @throws AlreadyClosedException if already closed
112112
* @throws LmdbNativeException if a native C error occurred
113113
*/
114-
public void setMaxReaders(int readers) throws AlreadyOpenException,
115-
AlreadyClosedException,
116-
LmdbNativeException {
114+
public void setMaxReaders(final int readers) throws AlreadyOpenException,
115+
AlreadyClosedException,
116+
LmdbNativeException {
117117
if (open) {
118118
throw new AlreadyOpenException();
119119
}

src/main/java/org/lmdbjava/MaskedFlag.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*/
1616
package org.lmdbjava;
1717

18-
import static java.util.Objects.nonNull;
18+
import static java.util.Objects.requireNonNull;
1919

2020
/**
2121
* Indicates an enum that can provide integers for each of its values,
@@ -58,7 +58,7 @@ static int mask(final MaskedFlag... flags) {
5858
* @return
5959
*/
6060
static boolean isSet(final int flags, final MaskedFlag test) {
61-
nonNull(test);
61+
requireNonNull(test);
6262
return (flags & test.getMask()) == test.getMask();
6363
}
6464
}

src/main/java/org/lmdbjava/ResultCodeMapper.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,15 @@
4545
/**
4646
* Maps a LMDB C result code to the equivalent Java exception.
4747
*/
48-
public final class ResultCodeMapper {
48+
final class ResultCodeMapper {
49+
50+
private static final ConstantSet CONSTANTS;
51+
private static final String POSIX_ERR_NO = "Errno";
4952

5053
/**
5154
* Successful result
5255
*/
53-
public static final int MDB_SUCCESS = 0;
54-
55-
private static final ConstantSet CONSTANTS;
56-
private static final String POSIX_ERR_NO = "Errno";
56+
static final int MDB_SUCCESS = 0;
5757

5858
static {
5959
CONSTANTS = getConstantSet(POSIX_ERR_NO);
@@ -65,7 +65,7 @@ public final class ResultCodeMapper {
6565
* @param rc the LMDB result code
6666
* @throws org.lmdbjava.LmdbNativeException
6767
*/
68-
public static void checkRc(final int rc) throws LmdbNativeException {
68+
static void checkRc(final int rc) throws LmdbNativeException {
6969
if (rc == MDB_SUCCESS) {
7070
return;
7171
}

src/main/java/org/lmdbjava/Txn.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -188,8 +188,7 @@ public boolean isReset() {
188188
* @throws NotResetException if reset not called
189189
* @throws LmdbNativeException if a native C error occurred
190190
*/
191-
public void renew() throws NotResetException,
192-
LmdbNativeException {
191+
public void renew() throws NotResetException, LmdbNativeException {
193192
if (!reset) {
194193
throw new NotResetException();
195194
}
@@ -204,8 +203,7 @@ public void renew() throws NotResetException,
204203
* @throws ReadOnlyRequiredException if a read-write transaction
205204
* @throws ResetException if reset already performed
206205
*/
207-
public void reset() throws ReadOnlyRequiredException,
208-
ResetException {
206+
public void reset() throws ReadOnlyRequiredException, ResetException {
209207
if (!isReadOnly()) {
210208
throw new ReadOnlyRequiredException();
211209
}

0 commit comments

Comments
 (0)