Skip to content

Commit

Permalink
Make use of modern data type factories
Browse files Browse the repository at this point in the history
  • Loading branch information
spannm committed Feb 14, 2024
1 parent 365b9cc commit 3b26380
Show file tree
Hide file tree
Showing 34 changed files with 202 additions and 226 deletions.
1 change: 1 addition & 0 deletions src/main/java/io/github/spannm/jackcess/Cursor.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import io.github.spannm.jackcess.util.IterableBuilder;

import java.io.IOException;
import java.io.UncheckedIOException;
import java.util.Collection;
import java.util.Iterator;
import java.util.Map;
Expand Down
5 changes: 1 addition & 4 deletions src/main/java/io/github/spannm/jackcess/Database.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,7 @@
import io.github.spannm.jackcess.util.LinkResolver;
import io.github.spannm.jackcess.util.TableIterableBuilder;

import java.io.Closeable;
import java.io.File;
import java.io.Flushable;
import java.io.IOException;
import java.io.*;
import java.nio.charset.Charset;
import java.nio.file.Path;
import java.time.ZoneId;
Expand Down
1 change: 1 addition & 0 deletions src/main/java/io/github/spannm/jackcess/Table.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import io.github.spannm.jackcess.util.OleBlob;

import java.io.IOException;
import java.io.UncheckedIOException;
import java.time.LocalDateTime;
import java.util.Iterator;
import java.util.List;
Expand Down
63 changes: 31 additions & 32 deletions src/main/java/io/github/spannm/jackcess/TableBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,38 +54,37 @@ private static final class ReservedWords {
/**
* All of the reserved words in Access that should be escaped when creating table or column names
*/
private static final Set<String> VALUES =
new HashSet<>(Arrays.asList(
"add", "all", "alphanumeric", "alter", "and", "any", "application", "as",
"asc", "assistant", "autoincrement", "avg", "between", "binary", "bit",
"boolean", "by", "byte", "char", "character", "column", "compactdatabase",
"constraint", "container", "count", "counter", "create", "createdatabase",
"createfield", "creategroup", "createindex", "createobject", "createproperty",
"createrelation", "createtabledef", "createuser", "createworkspace",
"currency", "currentuser", "database", "date", "datetime", "delete",
"desc", "description", "disallow", "distinct", "distinctrow", "document",
"double", "drop", "echo", "else", "end", "eqv", "error", "exists", "exit",
"false", "field", "fields", "fillcache", "float", "float4", "float8",
"foreign", "form", "forms", "from", "full", "function", "general",
"getobject", "getoption", "gotopage", "group", "group by", "guid", "having",
"idle", "ieeedouble", "ieeesingle", "if", "ignore", "imp", "in", "index",
"indexes", "inner", "insert", "inserttext", "int", "integer", "integer1",
"integer2", "integer4", "into", "is", "join", "key", "lastmodified", "left",
"level", "like", "logical", "logical1", "long", "longbinary", "longtext",
"macro", "match", "max", "min", "mod", "memo", "module", "money", "move",
"name", "newpassword", "no", "not", "null", "number", "numeric", "object",
"oleobject", "off", "on", "openrecordset", "option", "or", "order", "outer",
"owneraccess", "parameter", "parameters", "partial", "percent", "pivot",
"primary", "procedure", "property", "queries", "query", "quit", "real",
"recalc", "recordset", "references", "refresh", "refreshlink",
"registerdatabase", "relation", "repaint", "repairdatabase", "report",
"reports", "requery", "right", "screen", "section", "select", "set",
"setfocus", "setoption", "short", "single", "smallint", "some", "sql",
"stdev", "stdevp", "string", "sum", "table", "tabledef", "tabledefs",
"tableid", "text", "time", "timestamp", "top", "transform", "true", "type",
"union", "unique", "update", "user", "value", "values", "var", "varp",
"varbinary", "varchar", "where", "with", "workspace", "xor", "year", "yes",
"yesno"));
private static final Set<String> VALUES = Set.of(
"add", "all", "alphanumeric", "alter", "and", "any", "application", "as",
"asc", "assistant", "autoincrement", "avg", "between", "binary", "bit",
"boolean", "by", "byte", "char", "character", "column", "compactdatabase",
"constraint", "container", "count", "counter", "create", "createdatabase",
"createfield", "creategroup", "createindex", "createobject", "createproperty",
"createrelation", "createtabledef", "createuser", "createworkspace",
"currency", "currentuser", "database", "date", "datetime", "delete",
"desc", "description", "disallow", "distinct", "distinctrow", "document",
"double", "drop", "echo", "else", "end", "eqv", "error", "exists", "exit",
"false", "field", "fields", "fillcache", "float", "float4", "float8",
"foreign", "form", "forms", "from", "full", "function", "general",
"getobject", "getoption", "gotopage", "group", "group by", "guid", "having",
"idle", "ieeedouble", "ieeesingle", "if", "ignore", "imp", "in", "index",
"indexes", "inner", "insert", "inserttext", "int", "integer", "integer1",
"integer2", "integer4", "into", "is", "join", "key", "lastmodified", "left",
"level", "like", "logical", "logical1", "long", "longbinary", "longtext",
"macro", "match", "max", "min", "mod", "memo", "module", "money", "move",
"name", "newpassword", "no", "not", "null", "number", "numeric", "object",
"oleobject", "off", "on", "openrecordset", "option", "or", "order", "outer",
"owneraccess", "parameter", "parameters", "partial", "percent", "pivot",
"primary", "procedure", "property", "queries", "query", "quit", "real",
"recalc", "recordset", "references", "refresh", "refreshlink",
"registerdatabase", "relation", "repaint", "repairdatabase", "report",
"reports", "requery", "right", "screen", "section", "select", "set",
"setfocus", "setoption", "short", "single", "smallint", "some", "sql",
"stdev", "stdevp", "string", "sum", "table", "tabledef", "tabledefs",
"tableid", "text", "time", "timestamp", "top", "transform", "true", "type",
"union", "unique", "update", "user", "value", "values", "var", "varp",
"varbinary", "varchar", "where", "with", "workspace", "xor", "year", "yes",
"yesno");
}

/** name of the new table */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -747,7 +747,7 @@ public void setLinkResolver(LinkResolver newLinkResolver) {

@Override
public Map<String, Database> getLinkedDatabases() {
return _linkedDbs == null ? Collections.emptyMap() : Collections.unmodifiableMap(_linkedDbs);
return _linkedDbs == null ? Map.of() : Collections.unmodifiableMap(_linkedDbs);
}

@Override
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/io/github/spannm/jackcess/impl/FKEnforcer.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ private void initColumns() {
}
}
}
_cols = !cols.isEmpty() ? List.copyOf(cols) : Collections.emptyList();
_cols = !cols.isEmpty() ? List.copyOf(cols) : List.of();
}

/**
Expand Down Expand Up @@ -225,7 +225,7 @@ private static void requirePrimaryValues(Joiner joiner, Object[] row)
// this table is a secondary table. however, null values are allowed
if (!areNull(joiner, row) && !joiner.hasRows(row)) {
throw new ConstraintViolationException(
"Adding new row " + Arrays.asList(row) + " violates constraint " + joiner.toFKString());
"Adding new row " + Arrays.toString(row) + " violates constraint " + joiner.toFKString());
}
}

Expand All @@ -235,7 +235,7 @@ private static void requireNoSecondaryValues(Joiner joiner, Object[] row)
// the primary table.
if (joiner.hasRows(row)) {
throw new ConstraintViolationException(
"Removing old row " + Arrays.asList(row) + " violates constraint " + joiner.toFKString());
"Removing old row " + Arrays.toString(row) + " violates constraint " + joiner.toFKString());
}
}

Expand All @@ -248,7 +248,7 @@ private static void updateSecondaryValues(Joiner joiner, Object[] oldFromRow,
Object[] toRow = new Object[joiner.getToTable().getColumnCount()];

for (Iterator<Row> iter = joiner.findRows(oldFromRow)
.withColumnNames(Collections.emptySet())
.withColumnNames(Set.of())
.iterator(); iter.hasNext();) {
iter.next();

Expand All @@ -271,7 +271,7 @@ private static void nullSecondaryValues(Joiner joiner, Object[] oldFromRow)
Object[] toRow = new Object[joiner.getToTable().getColumnCount()];

for (Iterator<Row> iter = joiner.findRows(oldFromRow)
.withColumnNames(Collections.emptySet())
.withColumnNames(Set.of())
.iterator(); iter.hasNext();) {
iter.next();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ private static CharHandler parseCodes(Map<String, Type> prefixMap,
*/
private static CharHandler parseSimpleCodes(String[] codeStrings) {
if (codeStrings.length != 1) {
throw new IllegalStateException("Unexpected code strings " + Arrays.asList(codeStrings));
throw new IllegalStateException("Unexpected code strings " + Arrays.toString(codeStrings));
}
return new SimpleCharHandler(codesToBytes(codeStrings[0], true));
}
Expand All @@ -436,7 +436,7 @@ private static CharHandler parseSimpleCodes(String[] codeStrings) {
*/
private static CharHandler parseInternationalCodes(String[] codeStrings) {
if (codeStrings.length != 2) {
throw new IllegalStateException("Unexpected code strings " + Arrays.asList(codeStrings));
throw new IllegalStateException("Unexpected code strings " + Arrays.toString(codeStrings));
}
return new InternationalCharHandler(codesToBytes(codeStrings[0], true),
codesToBytes(codeStrings[1], true));
Expand All @@ -447,7 +447,7 @@ private static CharHandler parseInternationalCodes(String[] codeStrings) {
*/
private static CharHandler parseUnprintableCodes(String[] codeStrings) {
if (codeStrings.length != 1) {
throw new IllegalStateException("Unexpected code strings " + Arrays.asList(codeStrings));
throw new IllegalStateException("Unexpected code strings " + Arrays.toString(codeStrings));
}
return new UnprintableCharHandler(codesToBytes(codeStrings[0], true));
}
Expand All @@ -457,11 +457,11 @@ private static CharHandler parseUnprintableCodes(String[] codeStrings) {
*/
private static CharHandler parseUnprintableExtCodes(String[] codeStrings) {
if (codeStrings.length != 1) {
throw new IllegalStateException("Unexpected code strings " + Arrays.asList(codeStrings));
throw new IllegalStateException("Unexpected code strings " + Arrays.toString(codeStrings));
}
byte[] bytes = codesToBytes(codeStrings[0], true);
if (bytes.length != 1) {
throw new IllegalStateException("Unexpected code strings " + Arrays.asList(codeStrings));
throw new IllegalStateException("Unexpected code strings " + Arrays.toString(codeStrings));
}
return new UnprintableExtCharHandler(bytes[0]);
}
Expand All @@ -471,7 +471,7 @@ private static CharHandler parseUnprintableExtCodes(String[] codeStrings) {
*/
private static CharHandler parseInternationalExtCodes(String[] codeStrings) {
if (codeStrings.length != 3) {
throw new IllegalStateException("Unexpected code strings " + Arrays.asList(codeStrings));
throw new IllegalStateException("Unexpected code strings " + Arrays.toString(codeStrings));
}

byte crazyFlag = "1".equals(codeStrings[2]) ? CRAZY_CODE_1 : CRAZY_CODE_2;
Expand All @@ -483,7 +483,7 @@ private static CharHandler parseInternationalExtCodes(String[] codeStrings) {
*/
private static CharHandler parseSignificantCodes(String[] codeStrings) {
if (codeStrings.length != 1) {
throw new IllegalStateException("Unexpected code strings " + Arrays.asList(codeStrings));
throw new IllegalStateException("Unexpected code strings " + Arrays.toString(codeStrings));
}
return new SignificantCharHandler(codesToBytes(codeStrings[0], true));
}
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/io/github/spannm/jackcess/impl/IndexData.java
Original file line number Diff line number Diff line change
Expand Up @@ -565,7 +565,7 @@ private PendingChange prepareAddRow(Object[] row, RowIdImpl rowId, AddRowPending
return change;
}
if (nullCount > 0 && (isBackingPrimaryKey() || isRequired())) {
throw new ConstraintViolationException(withErrorContext("Null value found in row " + Arrays.asList(row) + " for primary key or required index"));
throw new ConstraintViolationException(withErrorContext("Null value found in row " + Arrays.toString(row) + " for primary key or required index"));
}

// make sure we've parsed the entries
Expand Down Expand Up @@ -594,7 +594,7 @@ private PendingChange prepareAddEntry(Entry newEntry, boolean isNullEntry, Objec
// defined by Access.
boolean isDupeEntry = nextPos != null && newEntry.equalsEntryBytes(nextPos.getEntry()) || prevPos != null && newEntry.equalsEntryBytes(prevPos.getEntry());
if (isUnique() && !isNullEntry && isDupeEntry) {
throw new ConstraintViolationException(withErrorContext("New row " + Arrays.asList(row) + " violates uniqueness constraint for index"));
throw new ConstraintViolationException(withErrorContext("New row " + Arrays.toString(row) + " violates uniqueness constraint for index"));
}

change.setAddRow(newEntry, dataPage, idx, isDupeEntry);
Expand Down Expand Up @@ -671,7 +671,7 @@ private Entry deleteRowImpl(Object[] row, RowIdImpl rowId) throws IOException {
if (removedEntry != null) {
++_modCount;
} else {
LOG.warn(withErrorContext("Failed removing index entry " + oldEntry + " for row: " + Arrays.asList(row)));
LOG.warn(withErrorContext("Failed removing index entry " + oldEntry + " for row: " + Arrays.toString(row)));
}
return removedEntry;
}
Expand Down Expand Up @@ -2511,7 +2511,7 @@ public void setEntryPrefix(byte[] entryPrefix) {

@Override
public List<Entry> getEntries() {
return Collections.emptyList();
return List.of();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

import static io.github.spannm.jackcess.impl.IndexData.*;

import io.github.spannm.jackcess.impl.IndexData.DataPage;
import io.github.spannm.jackcess.impl.IndexData.Entry;
import org.apache.commons.lang3.builder.ToStringBuilder;

import java.io.IOException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ public TableImpl createTable(TableBuilder table) throws IOException {
_columns = table.getColumns();
_indexes = table.getIndexes();
if (_indexes == null) {
_indexes = Collections.emptyList();
_indexes = List.of();
}

validate();
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/io/github/spannm/jackcess/impl/TableImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -1037,7 +1037,7 @@ protected static void writeTableDefinition(TableCreator creator)
buffer.flip();

// write table buffer to database
writeTableDefinitionBuffer(buffer, creator.getTdefPageNumber(), creator, Collections.emptyList());
writeTableDefinitionBuffer(buffer, creator.getTdefPageNumber(), creator, List.of());
}

private static void writeTableDefinitionBuffer(
Expand Down Expand Up @@ -2619,7 +2619,7 @@ private ByteBuffer newDataPage() throws IOException {
// exposed for unit tests
protected ByteBuffer createRow(Object[] rowArray, ByteBuffer buffer)
throws IOException {
return createRow(rowArray, buffer, 0, Collections.emptyMap());
return createRow(rowArray, buffer, 0, Map.of());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@
import java.io.*;
import java.nio.ByteBuffer;
import java.time.LocalDateTime;
import java.util.Arrays;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;
import java.util.zip.Deflater;
import java.util.zip.DeflaterOutputStream;
Expand All @@ -41,12 +39,11 @@
*
* @author James Ahlborn
*/
public class AttachmentColumnInfoImpl extends ComplexColumnInfoImpl<Attachment>
implements AttachmentColumnInfo {
public class AttachmentColumnInfoImpl extends ComplexColumnInfoImpl<Attachment> implements AttachmentColumnInfo {

/** some file formats which may not be worth re-compressing */
private static final Set<String> COMPRESSED_FORMATS = new HashSet<>(
Arrays.asList("jpg", "zip", "gz", "bz2", "z", "7z", "cab", "rar",
"mp3", "mpg"));
private static final Set<String> COMPRESSED_FORMATS = Set.of(
"jpg", "zip", "gz", "bz2", "z", "7z", "cab", "rar", "mp3", "mpg");

private static final String FILE_NAME_COL_NAME = "FileName";
private static final String FILE_TYPE_COL_NAME = "FileType";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ public List<Row> getRawValues(int complexValueFk,
Iterator<Row> entryIter =
getComplexValFkIter(complexValueFk, columnNames);
if (!entryIter.hasNext()) {
return Collections.emptyList();
return List.of();
}

List<Row> values = new ArrayList<>();
Expand All @@ -157,7 +157,7 @@ public List<V> getValues(ComplexValueForeignKey complexValueFk)
throws IOException {
List<Row> rawValues = getRawValues(complexValueFk.get());
if (rawValues.isEmpty()) {
return Collections.emptyList();
return List.of();
}

return toValues(complexValueFk, rawValues);
Expand Down Expand Up @@ -237,7 +237,7 @@ public void deleteValues(Collection<? extends V> values) throws IOException {

@Override
public void deleteAllValues(int complexValueFk) throws IOException {
Iterator<Row> entryIter = getComplexValFkIter(complexValueFk, Collections.emptySet());
Iterator<Row> entryIter = getComplexValFkIter(complexValueFk, Set.of());
while (entryIter.hasNext()) {
entryIter.next();
entryIter.remove();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,7 @@ enum TokenType {
}

private static final byte[] CHAR_FLAGS = new byte[128];
private static final Set<String> TWO_CHAR_COMP_OPS = new HashSet<>(
Arrays.asList("<=", ">=", "<>"));
private static final Set<String> TWO_CHAR_COMP_OPS = Set.of("<=", ">=", "<>");

static {
setCharFlag(IS_OP_FLAG, '+', '-', '*', '/', '\\', '^', '&');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ public class Expressionator {
setWordType(WordType.DELIM, ".", "!", ",", "(", ")");
}

private static final Collection<String> TRUE_STRS = Arrays.asList("true", "yes", "on");
private static final Collection<String> FALSE_STRS = Arrays.asList("false", "no", "off");
private static final Collection<String> TRUE_STRS = List.of("true", "yes", "on");
private static final Collection<String> FALSE_STRS = List.of("false", "no", "off");

// Useful links:
// - syntax:
Expand Down Expand Up @@ -416,8 +416,8 @@ public String toString() {
new OpType[] {LogOp.IMP},
new OpType[] {SpecOp.IN, SpecOp.NOT_IN, SpecOp.BETWEEN, SpecOp.NOT_BETWEEN});

private static final Set<Character> REGEX_SPEC_CHARS = new HashSet<>(
Arrays.asList('\\', '.', '%', '=', '+', '$', '^', '|', '(', ')', '{', '}', '&', '[', ']', '*', '?'));
private static final Set<Character> REGEX_SPEC_CHARS = Set.of(
'\\', '.', '%', '=', '+', '$', '^', '|', '(', ')', '{', '}', '&', '[', ']', '*', '?');
// this is a regular expression which will never match any string
private static final Pattern UNMATCHABLE_REGEX = Pattern.compile("(?!)");

Expand Down Expand Up @@ -729,7 +729,7 @@ private static List<Expr> findParenExprs(
Token t = buf.peekNext();
if (isDelim(t, CLOSE_PAREN)) {
buf.next();
return Collections.emptyList();
return List.of();
}
}

Expand Down
Loading

0 comments on commit 3b26380

Please sign in to comment.