diff options
author | James Ahlborn <jtahlborn@yahoo.com> | 2007-11-03 04:21:10 +0000 |
---|---|---|
committer | James Ahlborn <jtahlborn@yahoo.com> | 2007-11-03 04:21:10 +0000 |
commit | 26f63555d13618ddd4fb1923efe1683f7c5a41a6 (patch) | |
tree | 245c470430c65b9e860365da1aae5b1c5b1b8c1e | |
parent | 04e0924490a27d7985de7d4487e80d2adfb8996e (diff) | |
download | jackcess-26f63555d13618ddd4fb1923efe1683f7c5a41a6.tar.gz jackcess-26f63555d13618ddd4fb1923efe1683f7c5a41a6.zip |
fix some pmd/findbugs issues
git-svn-id: https://svn.code.sf.net/p/jackcess/code/jackcess/trunk@172 f203690c-595d-4dc9-a70b-905162fa7fd2
6 files changed, 44 insertions, 60 deletions
diff --git a/src/java/com/healthmarketscience/jackcess/Column.java b/src/java/com/healthmarketscience/jackcess/Column.java index 899ba2d..cef17cc 100644 --- a/src/java/com/healthmarketscience/jackcess/Column.java +++ b/src/java/com/healthmarketscience/jackcess/Column.java @@ -36,7 +36,6 @@ import java.nio.CharBuffer; import java.sql.SQLException; import java.util.Calendar; import java.util.Date; -import java.util.Iterator; import java.util.List; import java.util.TimeZone; import java.util.regex.Matcher; @@ -120,6 +119,9 @@ public class Column implements Comparable<Column> { * Only used by unit tests */ Column(boolean testing) { + if(!testing) { + throw new IllegalArgumentException(); + } _format = JetFormat.VERSION_4; _pageChannel = new PageChannel(testing); } @@ -337,15 +339,15 @@ public class Column implements Comparable<Column> { if (_type == DataType.BOOLEAN) { throw new IOException("Tried to read a boolean from data instead of null mask."); } else if (_type == DataType.BYTE) { - return new Byte(buffer.get()); + return Byte.valueOf(buffer.get()); } else if (_type == DataType.INT) { - return new Short(buffer.getShort()); + return Short.valueOf(buffer.getShort()); } else if (_type == DataType.LONG) { - return new Integer(buffer.getInt()); + return Integer.valueOf(buffer.getInt()); } else if (_type == DataType.DOUBLE) { - return new Double(buffer.getDouble()); + return Double.valueOf(buffer.getDouble()); } else if (_type == DataType.FLOAT) { - return new Float(buffer.getFloat()); + return Float.valueOf(buffer.getFloat()); } else if (_type == DataType.SHORT_DATE_TIME) { return readDateValue(buffer); } else if (_type == DataType.BINARY) { diff --git a/src/java/com/healthmarketscience/jackcess/Database.java b/src/java/com/healthmarketscience/jackcess/Database.java index 450d51a..58dc6fe 100644 --- a/src/java/com/healthmarketscience/jackcess/Database.java +++ b/src/java/com/healthmarketscience/jackcess/Database.java @@ -427,7 +427,7 @@ public class Database _format); //Add this table to our internal list. - addTable(name, new Integer(tdefPageNumber)); + addTable(name, Integer.valueOf(tdefPageNumber)); //Add this table to system tables addToSystemCatalog(name, tdefPageNumber); @@ -446,7 +446,7 @@ public class Database for (iter = _systemCatalog.getColumns().iterator(); iter.hasNext(); idx++) { Column col = (Column) iter.next(); if (COL_ID.equals(col.getName())) { - catalogRow[idx] = new Integer(pageNumber); + catalogRow[idx] = Integer.valueOf(pageNumber); } else if (COL_NAME.equals(col.getName())) { catalogRow[idx] = name; } else if (COL_TYPE.equals(col.getName())) { @@ -458,7 +458,7 @@ public class Database } else if (COL_PARENT_ID.equals(col.getName())) { catalogRow[idx] = _tableParentId; } else if (COL_FLAGS.equals(col.getName())) { - catalogRow[idx] = new Integer(0); + catalogRow[idx] = Integer.valueOf(0); } else if (COL_OWNER.equals(col.getName())) { byte[] owner = new byte[2]; catalogRow[idx] = owner; @@ -484,7 +484,7 @@ public class Database } else if (col.getName().equals(COL_F_INHERITABLE)) { aceRow[idx] = Boolean.FALSE; } else if (col.getName().equals(COL_OBJECT_ID)) { - aceRow[idx] = new Integer(pageNumber); + aceRow[idx] = Integer.valueOf(pageNumber); } else if (col.getName().equals(COL_SID)) { aceRow[idx] = SID; } diff --git a/src/java/com/healthmarketscience/jackcess/Index.java b/src/java/com/healthmarketscience/jackcess/Index.java index 9512a4e..0cd6689 100644 --- a/src/java/com/healthmarketscience/jackcess/Index.java +++ b/src/java/com/healthmarketscience/jackcess/Index.java @@ -57,10 +57,6 @@ public class Index implements Comparable<Index> { private static final short COLUMN_UNUSED = -1; - private static final int NEW_ENTRY_COLUMN_INDEX = -1; - - private static final byte REVERSE_ORDER_FLAG = (byte)0x01; - private static final byte INDEX_NODE_PAGE_TYPE = (byte)0x03; private static final byte INDEX_LEAF_PAGE_TYPE = (byte)0x04; @@ -222,6 +218,10 @@ public class Index implements Comparable<Index> { _rowCount = rowCount; } + public int getRowCount() { + return _rowCount; + } + /** * Note, there may still be some issues around the name of an index, this * information may not be correct. I've done a variety of testing comparing @@ -349,7 +349,7 @@ public class Index implements Comparable<Index> { { for (int i = 0; i < MAX_COLUMNS; i++) { short columnNumber = tableBuffer.getShort(); - Byte flags = new Byte(tableBuffer.get()); + Byte flags = Byte.valueOf(tableBuffer.get()); if (columnNumber != COLUMN_UNUSED) { _columns.put(availableColumns.get(columnNumber), flags); } @@ -472,9 +472,9 @@ public class Index implements Comparable<Index> { int length = i * 8 + j - lastStart; indexPage.position(entryPos + lastStart); if(isLeaf) { - entries.add(new Entry(indexPage, length, valuePrefix)); + entries.add(new Entry(indexPage, valuePrefix)); } else { - nodeEntries.add(new NodeEntry(indexPage, length, valuePrefix)); + nodeEntries.add(new NodeEntry(indexPage, valuePrefix)); } // read any shared "compressed" bytes @@ -553,10 +553,11 @@ public class Index implements Comparable<Index> { (col.getType() == DataType.MEMO)); } - private static boolean isFloatingPointColumn(Column col) { - return((col.getType() == DataType.FLOAT) || - (col.getType() == DataType.DOUBLE)); - } + // FIXME +// private static boolean isFloatingPointColumn(Column col) { +// return((col.getType() == DataType.FLOAT) || +// (col.getType() == DataType.DOUBLE)); +// } /** * Converts an index value for a fixed column into the index bytes @@ -576,10 +577,10 @@ public class Index implements Comparable<Index> { // Column column = entryCol._column; // // if (value instanceof Integer) { -// // value = new Integer((int) (((Integer) value).longValue() - +// // value = Integer.valueOf((int) (((Integer) value).longValue() - // // ((long) Integer.MAX_VALUE + 1L))); // // } else if (value instanceof Short) { -// // value = new Short((short) (((Short) value).longValue() - +// // value = Short.valueOf((short) (((Short) value).longValue() - // // ((long) Integer.MAX_VALUE + 1L))); // // } @@ -694,7 +695,7 @@ public class Index implements Comparable<Index> { /** * Read an existing entry in from a buffer */ - public Entry(ByteBuffer buffer, int length, byte[] valuePrefix) + public Entry(ByteBuffer buffer, byte[] valuePrefix) throws IOException { for(Map.Entry<Column, Byte> entry : _columns.entrySet()) { @@ -886,8 +887,6 @@ public class Index implements Comparable<Index> { // FIXME, reverse is 0x80, reverse null is 0xFF if (flag != (byte) 0) { byte[] data = new byte[_column.getType().getFixedSize()]; - int numPrefixBytes = ((valuePrefix == null) ? 0 : - (valuePrefix.length - 1)); int dataOffset = 0; if((valuePrefix != null) && (valuePrefix.length > 1)) { System.arraycopy(valuePrefix, 1, data, 0, @@ -899,10 +898,10 @@ public class Index implements Comparable<Index> { //ints and shorts are stored in index as value + 2147483648 if (_value instanceof Integer) { - _value = new Integer((int) (((Integer) _value).longValue() + + _value = Integer.valueOf((int) (((Integer) _value).longValue() + (long) Integer.MAX_VALUE + 1L)); } else if (_value instanceof Short) { - _value = new Short((short) (((Short) _value).longValue() + + _value = Short.valueOf((short) (((Short) _value).longValue() + (long) Integer.MAX_VALUE + 1L)); } } @@ -923,10 +922,10 @@ public class Index implements Comparable<Index> { buffer.put((byte) 0x7F); Comparable value = _value; if (value instanceof Integer) { - value = new Integer((int) (((Integer) value).longValue() - + value = Integer.valueOf((int) (((Integer) value).longValue() - ((long) Integer.MAX_VALUE + 1L))); } else if (value instanceof Short) { - value = new Short((short) (((Short) value).longValue() - + value = Short.valueOf((short) (((Short) value).longValue() - ((long) Integer.MAX_VALUE + 1L))); } buffer.put(_column.write(value, 0, ByteOrder.BIG_ENDIAN)); @@ -1114,10 +1113,10 @@ public class Index implements Comparable<Index> { /** * Read an existing node entry in from a buffer */ - public NodeEntry(ByteBuffer buffer, int length, byte[] valuePrefix) + public NodeEntry(ByteBuffer buffer, byte[] valuePrefix) throws IOException { - super(buffer, length, valuePrefix); + super(buffer, valuePrefix); _subPageNumber = ByteUtil.getInt(buffer, ByteOrder.BIG_ENDIAN); } diff --git a/src/java/com/healthmarketscience/jackcess/PageChannel.java b/src/java/com/healthmarketscience/jackcess/PageChannel.java index dcd31a6..0c823c8 100644 --- a/src/java/com/healthmarketscience/jackcess/PageChannel.java +++ b/src/java/com/healthmarketscience/jackcess/PageChannel.java @@ -85,6 +85,9 @@ public class PageChannel implements Channel, Flushable { * Only used by unit tests */ PageChannel(boolean testing) { + if(!testing) { + throw new IllegalArgumentException(); + } _channel = null; _format = JetFormat.VERSION_4; _autoSync = false; diff --git a/src/java/com/healthmarketscience/jackcess/Table.java b/src/java/com/healthmarketscience/jackcess/Table.java index 968ad95..bb392b0 100644 --- a/src/java/com/healthmarketscience/jackcess/Table.java +++ b/src/java/com/healthmarketscience/jackcess/Table.java @@ -29,7 +29,6 @@ package com.healthmarketscience.jackcess; import java.io.IOException; import java.nio.ByteBuffer; -import java.nio.ByteOrder; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; @@ -120,6 +119,9 @@ public class Table * Only used by unit tests */ Table(boolean testing) throws IOException { + if(!testing) { + throw new IllegalArgumentException(); + } _pageChannel = new PageChannel(testing); } @@ -325,7 +327,6 @@ public class Table Map<String, Object> rtn = new LinkedHashMap<String, Object>( columns.size()); for(Column column : columns) { - Object value = null; if((columnNames == null) || (columnNames.contains(column.getName()))) { // Add the value to the row data rtn.put(column.getName(), getRowColumn(rowBuffer, nullMask, column)); @@ -345,7 +346,7 @@ public class Table { boolean isNull = nullMask.isNull(column.getColumnNumber()); if(column.getType() == DataType.BOOLEAN) { - return new Boolean(!isNull); //Boolean values are stored in the null mask + return Boolean.valueOf(!isNull); //Boolean values are stored in the null mask } else if(isNull) { // well, that's easy! return null; @@ -571,7 +572,6 @@ public class Table for(Column col : columns) { // we add the number of bytes for the column name and 2 bytes for the // length of the column name - ByteBuffer cName = format.CHARSET.encode(col.getName()); int nameByteLen = (col.getName().length() * JetFormat.TEXT_FIELD_UNIT_SIZE); totalTableDefSize += nameByteLen + 2; @@ -938,24 +938,6 @@ public class Table // reset to end of index info tableBuffer.position(idxEndOffset); } - - /** - * Sets up the _varColumns list, assuming the _columns has already been set - * up. - */ - private void setupVariableColumns() - { - // pull out the variable length columns into a separate list - for(Column col : _columns) { - if(col.isVariableLength()) { - _varColumns.add(col); - } - } - - // lastly sort these columns based on their index into the variable length - // offset table, because we will write the columns in this order - Collections.sort(_varColumns, VAR_LEN_COLUMN_COMPARATOR); - } /** * Writes the given page data to the given page number, clears any other diff --git a/src/java/com/healthmarketscience/jackcess/UsageMap.java b/src/java/com/healthmarketscience/jackcess/UsageMap.java index bf19fb4..ec3bc36 100644 --- a/src/java/com/healthmarketscience/jackcess/UsageMap.java +++ b/src/java/com/healthmarketscience/jackcess/UsageMap.java @@ -473,17 +473,15 @@ public class UsageMap if(_assumeOutOfRangeBitsOn) { // we are using an inline map and assuming that anything not - // within the current range is "on" + // within the current range is "on". so, if we attempt to set a + // bit which is before the current page, ignore it, we are not + // going back for it. if((firstPage == PageChannel.INVALID_PAGE_NUMBER) || (pageNumber > lastPage)) { // move to new start page, filling in as we move moveToNewStartPageForRemove(firstPage, lastPage, pageNumber); - } else { - - // umm, we are removing an already passed bit. whatever, we are - // not going back for it } } else { @@ -661,7 +659,7 @@ public class UsageMap mapPageBuffer.put((byte) 0x01); //Unknown mapPageBuffer.putShort((short) 0); //Unknown for(int i = 0; i < mapPageBuffer.limit(); ++i) { - byte b = mapPageBuffer.get(i); + mapPageBuffer.get(i); } int mapPageNum = _mapPageHolder.getPageNumber(); getTableBuffer().putInt(calculateMapPagePointerOffset(pageIndex), |