]> source.dussan.org Git - jackcess.git/commitdiff
cleanup some compiler warnings, thanks Markus Spann
authorJames Ahlborn <jtahlborn@yahoo.com>
Thu, 8 Feb 2024 03:00:28 +0000 (03:00 +0000)
committerJames Ahlborn <jtahlborn@yahoo.com>
Thu, 8 Feb 2024 03:00:28 +0000 (03:00 +0000)
git-svn-id: https://svn.code.sf.net/p/jackcess/code/jackcess/trunk@1407 f203690c-595d-4dc9-a70b-905162fa7fd2

13 files changed:
src/main/java/com/healthmarketscience/jackcess/impl/IndexData.java
src/main/java/com/healthmarketscience/jackcess/impl/IndexPageCache.java
src/main/java/com/healthmarketscience/jackcess/impl/TableImpl.java
src/main/java/com/healthmarketscience/jackcess/impl/expr/Expressionator.java
src/main/java/com/healthmarketscience/jackcess/util/MemFileChannel.java
src/test/java/com/healthmarketscience/jackcess/DatabaseTest.java
src/test/java/com/healthmarketscience/jackcess/PropertiesTest.java
src/test/java/com/healthmarketscience/jackcess/TestUtil.java
src/test/java/com/healthmarketscience/jackcess/impl/BigIntTest.java
src/test/java/com/healthmarketscience/jackcess/impl/CodecHandlerTest.java
src/test/java/com/healthmarketscience/jackcess/impl/LongValueTest.java
src/test/java/com/healthmarketscience/jackcess/util/ColumnFormatterTest.java
src/test/java/com/healthmarketscience/jackcess/util/RowFilterTest.java

index c08e70b8c6ef98f5035cad4bdca6f4f34fb3581d..7eb094a7334ad3d7c8a6190963869aa737780c29 100644 (file)
@@ -532,6 +532,7 @@ public class IndexData {
    * @param creator description of the indexes to write
    * @param buffer Buffer to write to
    */
+  @SuppressWarnings("resource")
   protected static void writeDefinition(
       TableMutator creator, ByteBuffer buffer,
       TableMutator.IndexDataState idxDataState, ByteBuffer rootPageBuffer)
@@ -2659,36 +2660,32 @@ public class IndexData {
       _between = between;
     }
 
-    public DataPage getDataPage() {
+    DataPage getDataPage() {
       return _dataPage;
     }
 
-    public int getIndex() {
+    int getIndex() {
       return _idx;
     }
 
-    public int getNextIndex() {
+    int getNextIndex() {
       // note, _idx does not need to be advanced if it was pointing at a
       // between position
       return(_between ? _idx : (_idx + 1));
     }
 
-    public int getPrevIndex() {
+    int getPrevIndex() {
       // note, we ignore the between flag here because the index will be
       // pointing at the correct next index in either the between or
       // non-between case
       return(_idx - 1);
     }
 
-    public Entry getEntry() {
+    Entry getEntry() {
       return _entry;
     }
 
-    public boolean isBetween() {
-      return _between;
-    }
-
-    public boolean equalsEntry(Entry entry) {
+    boolean equalsEntry(Entry entry) {
       return _entry.equals(entry);
     }
 
index b64b93daabb963ac08cbb043b7ef0cfa531fe011..0d6c997e7d48446da761693f0cb705c782ef1e9b 100644 (file)
@@ -23,7 +23,6 @@ import java.util.AbstractList;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.HashMap;
-import java.util.HashSet;
 import java.util.Iterator;
 import java.util.LinkedHashMap;
 import java.util.LinkedList;
@@ -31,7 +30,6 @@ import java.util.List;
 import java.util.Map;
 import java.util.Queue;
 import java.util.RandomAccess;
-import java.util.Set;
 
 import static com.healthmarketscience.jackcess.impl.IndexData.*;
 import com.healthmarketscience.jackcess.impl.IndexData.DataPage;
index c01c1a520eb5149f63b63d4e19ca546928b7efd7..2be9f4583d5b3011dd5a6db4acae0c78f21b18f5 100644 (file)
@@ -53,7 +53,6 @@ import com.healthmarketscience.jackcess.Table;
 import com.healthmarketscience.jackcess.expr.Identifier;
 import com.healthmarketscience.jackcess.util.ErrorHandler;
 import com.healthmarketscience.jackcess.util.ExportUtil;
-import org.apache.commons.lang3.builder.ToStringBuilder;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
index 1c6d5f3f326b2de8255fec242050224cbc3eb602..e15e7beebdee32cad460250662d2644970922023 100644 (file)
@@ -73,7 +73,6 @@ public class Expressionator
   }
 
   private static final String FUNC_START_DELIM = "(";
-  private static final String FUNC_END_DELIM = ")";
   private static final String OPEN_PAREN = "(";
   private static final String CLOSE_PAREN = ")";
   private static final String FUNC_PARAM_SEP = ",";
index ba9a037d866d7ee57976ae6a35c1bfb1fab2d496..156f88225ce5d172b68dd5a45821a5aeb678bbca 100644 (file)
@@ -116,13 +116,14 @@ public class MemFileChannel extends FileChannel
   public static MemFileChannel newChannel(File file, String mode)
     throws IOException
   {
+    RandomAccessFile raf = null;
     FileChannel in = null;
     try {
-      return newChannel(in = new RandomAccessFile(
-                            file, RO_CHANNEL_MODE).getChannel(),
-                        mode);
+      raf = new RandomAccessFile(file, RO_CHANNEL_MODE);
+      return newChannel(in = raf.getChannel(), mode);
     } finally {
       ByteUtil.closeQuietly(in);
+      ByteUtil.closeQuietly(raf);
     }
   }
 
index 2ea9e29c1434a7a08d21f97388a2cd954b0e23e7..8452dc9aa228e44188e5083c751570e10d54fb9c 100644 (file)
@@ -199,7 +199,6 @@ public class DatabaseTest extends TestCase
       Map<String,Object> row2 = createTestRowMap("Tim2");
       Map<String,Object> row3 = createTestRowMap("Tim3");
       Table table = db.getTable("Test");
-      @SuppressWarnings("unchecked")
       List<Map<String,Object>> rows = Arrays.asList(row1, row2, row3);
       table.addRowsFromMaps(rows);
       assertRowCount(3, table);
index f5cb304e4ce5cfd5c847ffcc90f119495373b0b1..92f7b517edaa326f53b84d3658cc2f65c139d3a5 100644 (file)
@@ -25,7 +25,6 @@ import java.util.Map;
 import java.util.UUID;
 
 import static com.healthmarketscience.jackcess.Database.*;
-import com.healthmarketscience.jackcess.InvalidValueException;
 import com.healthmarketscience.jackcess.impl.DatabaseImpl;
 import static com.healthmarketscience.jackcess.impl.JetFormatTest.*;
 import com.healthmarketscience.jackcess.impl.PropertyMapImpl;
index 97139b871f51e1327c6e9257e7c16dd3c142a79e..fae1fa0733a8c66ee766d7923fafab832c4f1e91 100644 (file)
@@ -16,14 +16,7 @@ limitations under the License.
 
 package com.healthmarketscience.jackcess;
 
-import java.io.DataInputStream;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.io.PrintWriter;
+import java.io.*;
 import java.lang.reflect.Field;
 import java.nio.ByteBuffer;
 import java.nio.channels.FileChannel;
@@ -31,24 +24,13 @@ import java.nio.charset.Charset;
 import java.time.Instant;
 import java.time.LocalDateTime;
 import java.time.ZoneId;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Calendar;
-import java.util.Date;
-import java.util.List;
-import java.util.Map;
-import java.util.TimeZone;
-
-import static com.healthmarketscience.jackcess.Database.*;
+import java.util.*;
+import java.util.stream.StreamSupport;
+
+import com.healthmarketscience.jackcess.Database.FileFormat;
 import com.healthmarketscience.jackcess.complex.ComplexValueForeignKey;
-import com.healthmarketscience.jackcess.impl.ByteUtil;
-import com.healthmarketscience.jackcess.impl.DatabaseImpl;
-import com.healthmarketscience.jackcess.impl.IndexData;
-import com.healthmarketscience.jackcess.impl.IndexImpl;
-import com.healthmarketscience.jackcess.impl.JetFormatTest;
+import com.healthmarketscience.jackcess.impl.*;
 import com.healthmarketscience.jackcess.impl.JetFormatTest.TestDB;
-import com.healthmarketscience.jackcess.impl.RowIdImpl;
-import com.healthmarketscience.jackcess.impl.RowImpl;
 import com.healthmarketscience.jackcess.util.MemFileChannel;
 import org.junit.Assert;
 
@@ -264,11 +246,8 @@ public class TestUtil
   }
 
   public static int countRows(Table table) throws Exception {
-    int rtn = 0;
-    for(Map<String, Object> row : CursorBuilder.createCursor(table)) {
-      rtn++;
-    }
-    return rtn;
+    Cursor cursor = CursorBuilder.createCursor(table);
+    return (int) StreamSupport.stream(cursor.spliterator(), false).count();
   }
 
   public static void assertTable(
index 98689d677605c568b86655c94778c36718936cf4..6ef97aee524e3c5eb846e9219cb5e4863e050592 100644 (file)
@@ -18,7 +18,6 @@ package com.healthmarketscience.jackcess.impl;
 
 import java.util.ArrayList;
 import java.util.Collections;
-import java.util.Comparator;
 import java.util.List;
 import java.util.Map;
 
index 51e9f3c14d4502d971565583db7e40cbb90ed41a..7c5f59f80a3244ff77d87e46c9a3ef9f99f14aa2 100644 (file)
@@ -167,25 +167,26 @@ public class CodecHandlerTest extends TestCase
     throws Exception
   {
     long dbLen = dbFile.length();
-    FileChannel fileChannel = new RandomAccessFile(dbFile, "rw").getChannel();
-    ByteBuffer bb = ByteBuffer.allocate(pageSize)
-      .order(PageChannel.DEFAULT_BYTE_ORDER);
-    for(long offset = pageSize; offset < dbLen; offset += pageSize) {
-
-      bb.clear();
-      fileChannel.read(bb, offset);
+    try (RandomAccessFile randomAccessFile = new RandomAccessFile(dbFile, "rw");
+         FileChannel fileChannel = randomAccessFile.getChannel()) {
+      ByteBuffer bb = ByteBuffer.allocate(pageSize)
+        .order(PageChannel.DEFAULT_BYTE_ORDER);
+      for(long offset = pageSize; offset < dbLen; offset += pageSize) {
+
+        bb.clear();
+        fileChannel.read(bb, offset);
+
+        int pageNumber = (int)(offset / pageSize);
+        if(simple) {
+          simpleEncode(bb.array(), bb.array(), pageNumber, 0, pageSize);
+        } else {
+          fullEncode(bb.array(), bb.array(), pageNumber);
+        }
 
-      int pageNumber = (int)(offset / pageSize);
-      if(simple) {
-        simpleEncode(bb.array(), bb.array(), pageNumber, 0, pageSize);
-      } else {
-        fullEncode(bb.array(), bb.array(), pageNumber);
+        bb.rewind();
+        fileChannel.write(bb, offset);
       }
-
-      bb.rewind();
-      fileChannel.write(bb, offset);
     }
-    fileChannel.close();
   }
 
   private static void simpleEncode(byte[] inBuffer, byte[] outBuffer,
index 96418e69f640ae4ea4d34d80b0a035393f162710..2a21bbce761637e0cac97dbc8cffaf4b90f09c8e 100644 (file)
@@ -214,7 +214,7 @@ public class LongValueTest extends TestCase
   public void testUnicodeCompression() throws Exception
   {
     File dbFile = new File("src/test/data/V2003/testUnicodeCompV2003.mdb");
-    Database db = open(Database.FileFormat.V2003, new File("src/test/data/V2003/testUnicodeCompV2003.mdb"), true);
+    Database db = open(Database.FileFormat.V2003, dbFile, true);
 
     StringBuilder sb = new StringBuilder(127);
     for(int i = 1; i <= 0xFF; ++i) {
index d9aecb7891255de0c25c5b8e9f17c5aefbe334d4..edf4a7908950e411e8879c3703232531ffb15bb6 100644 (file)
@@ -19,15 +19,12 @@ package com.healthmarketscience.jackcess.util;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
-import java.util.Map;
 
 import com.healthmarketscience.jackcess.Column;
 import com.healthmarketscience.jackcess.ColumnBuilder;
-import com.healthmarketscience.jackcess.CursorBuilder;
 import com.healthmarketscience.jackcess.DataType;
 import com.healthmarketscience.jackcess.Database;
 import com.healthmarketscience.jackcess.Database.FileFormat;
-import com.healthmarketscience.jackcess.IndexCursor;
 import com.healthmarketscience.jackcess.PropertyMap;
 import com.healthmarketscience.jackcess.Row;
 import com.healthmarketscience.jackcess.Table;
index 4a247d92a04e486c7077509b1344f318f91a6e06..1117521c160565b99e6ebb5849d6939a7cbc0d81 100644 (file)
@@ -41,7 +41,6 @@ public class RowFilterTest extends TestCase
     super(name);
   }
 
-  @SuppressWarnings("unchecked")
   public void testFilter() throws Exception 
   {
     Row row0 = createExpectedRow(ID_COL, 0, COL1, "foo", COL2, 13, COL3, "bar");