aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJames Ahlborn <jtahlborn@yahoo.com>2020-04-27 00:44:02 +0000
committerJames Ahlborn <jtahlborn@yahoo.com>2020-04-27 00:44:02 +0000
commit400f6cf9622f416cfd922e52245a86f438fd9a3f (patch)
tree41d3ebc9727b64b7f0cf7aee9c67da4cdaf209d7
parent11bf84249c9eea4fedacd12b9339fc197521d266 (diff)
downloadjackcess-400f6cf9622f416cfd922e52245a86f438fd9a3f.tar.gz
jackcess-400f6cf9622f416cfd922e52245a86f438fd9a3f.zip
tag functional interfaces; use lambda syntax
git-svn-id: https://svn.code.sf.net/p/jackcess/code/jackcess/trunk@1322 f203690c-595d-4dc9-a70b-905162fa7fd2
-rw-r--r--src/main/java/com/healthmarketscience/jackcess/util/ColumnMatcher.java3
-rw-r--r--src/main/java/com/healthmarketscience/jackcess/util/ColumnValidator.java1
-rw-r--r--src/main/java/com/healthmarketscience/jackcess/util/ColumnValidatorFactory.java3
-rw-r--r--src/main/java/com/healthmarketscience/jackcess/util/ErrorHandler.java7
-rw-r--r--src/main/java/com/healthmarketscience/jackcess/util/LinkResolver.java1
-rw-r--r--src/test/java/com/healthmarketscience/jackcess/util/ColumnValidatorTest.java40
6 files changed, 27 insertions, 28 deletions
diff --git a/src/main/java/com/healthmarketscience/jackcess/util/ColumnMatcher.java b/src/main/java/com/healthmarketscience/jackcess/util/ColumnMatcher.java
index 3a1d3ae..6291020 100644
--- a/src/main/java/com/healthmarketscience/jackcess/util/ColumnMatcher.java
+++ b/src/main/java/com/healthmarketscience/jackcess/util/ColumnMatcher.java
@@ -25,7 +25,8 @@ import com.healthmarketscience.jackcess.Table;
* @author James Ahlborn
* @usage _intermediate_class_
*/
-public interface ColumnMatcher
+@FunctionalInterface
+public interface ColumnMatcher
{
/**
diff --git a/src/main/java/com/healthmarketscience/jackcess/util/ColumnValidator.java b/src/main/java/com/healthmarketscience/jackcess/util/ColumnValidator.java
index ffe2e71..719870a 100644
--- a/src/main/java/com/healthmarketscience/jackcess/util/ColumnValidator.java
+++ b/src/main/java/com/healthmarketscience/jackcess/util/ColumnValidator.java
@@ -27,6 +27,7 @@ import com.healthmarketscience.jackcess.Column;
*
* @author James Ahlborn
*/
+@FunctionalInterface
public interface ColumnValidator
{
/**
diff --git a/src/main/java/com/healthmarketscience/jackcess/util/ColumnValidatorFactory.java b/src/main/java/com/healthmarketscience/jackcess/util/ColumnValidatorFactory.java
index c1a4034..14bf3d4 100644
--- a/src/main/java/com/healthmarketscience/jackcess/util/ColumnValidatorFactory.java
+++ b/src/main/java/com/healthmarketscience/jackcess/util/ColumnValidatorFactory.java
@@ -25,7 +25,8 @@ import com.healthmarketscience.jackcess.Column;
*
* @author James Ahlborn
*/
-public interface ColumnValidatorFactory
+@FunctionalInterface
+public interface ColumnValidatorFactory
{
/**
* Returns a ColumnValidator instance for the given column, or {@code null}
diff --git a/src/main/java/com/healthmarketscience/jackcess/util/ErrorHandler.java b/src/main/java/com/healthmarketscience/jackcess/util/ErrorHandler.java
index fe9197b..48ddcb7 100644
--- a/src/main/java/com/healthmarketscience/jackcess/util/ErrorHandler.java
+++ b/src/main/java/com/healthmarketscience/jackcess/util/ErrorHandler.java
@@ -27,11 +27,12 @@ import com.healthmarketscience.jackcess.Table;
* or Cursor level to customize error handling as desired. The default
* instance used is {@link #DEFAULT}, which just rethrows any exceptions
* encountered.
- *
+ *
* @author James Ahlborn
* @usage _intermediate_class_
*/
-public interface ErrorHandler
+@FunctionalInterface
+public interface ErrorHandler
{
/**
* default error handler used if none provided (just rethrows exception)
@@ -75,7 +76,7 @@ public interface ErrorHandler
/**
* Provides location information for an error.
*/
- public interface Location
+ public interface Location
{
/**
* @return the table in which the error occurred
diff --git a/src/main/java/com/healthmarketscience/jackcess/util/LinkResolver.java b/src/main/java/com/healthmarketscience/jackcess/util/LinkResolver.java
index c1beee3..8e6fd82 100644
--- a/src/main/java/com/healthmarketscience/jackcess/util/LinkResolver.java
+++ b/src/main/java/com/healthmarketscience/jackcess/util/LinkResolver.java
@@ -29,6 +29,7 @@ import com.healthmarketscience.jackcess.impl.DatabaseImpl;
* @author James Ahlborn
* @usage _intermediate_class_
*/
+@FunctionalInterface
public interface LinkResolver
{
/**
diff --git a/src/test/java/com/healthmarketscience/jackcess/util/ColumnValidatorTest.java b/src/test/java/com/healthmarketscience/jackcess/util/ColumnValidatorTest.java
index e3634d0..e8d8eeb 100644
--- a/src/test/java/com/healthmarketscience/jackcess/util/ColumnValidatorTest.java
+++ b/src/test/java/com/healthmarketscience/jackcess/util/ColumnValidatorTest.java
@@ -37,7 +37,7 @@ import static com.healthmarketscience.jackcess.impl.JetFormatTest.*;
*
* @author James Ahlborn
*/
-public class ColumnValidatorTest extends TestCase
+public class ColumnValidatorTest extends TestCase
{
public ColumnValidatorTest(String name) {
@@ -71,19 +71,16 @@ public class ColumnValidatorTest extends TestCase
// force table to be reloaded
clearTableCache(db);
-
- final ColumnValidator cv = new ColumnValidator() {
- public Object validate(Column col, Object v1) {
+
+ final ColumnValidator cv = (col, v1) -> {
Number num = (Number)v1;
if((num == null) || (num.intValue() < 0)) {
throw new IllegalArgumentException("not gonna happen");
}
return v1;
- }
- };
-
- ColumnValidatorFactory fact = new ColumnValidatorFactory() {
- public ColumnValidator createValidator(Column col) {
+ };
+
+ ColumnValidatorFactory fact = col -> {
Table t = col.getTable();
assertFalse(t.isSystem());
if(!"Test".equals(t.getName())) {
@@ -95,13 +92,12 @@ public class ColumnValidatorTest extends TestCase
}
return null;
- }
- };
+ };
db.setColumnValidatorFactory(fact);
table = db.getTable("Test");
-
+
for(Column col : table.getColumns()) {
ColumnValidator cur = col.getColumnValidator();
assertNotNull(cur);
@@ -111,7 +107,7 @@ public class ColumnValidatorTest extends TestCase
assertSame(SimpleColumnValidator.INSTANCE, cur);
}
}
-
+
Column idCol = table.getColumn("id");
Column dataCol = table.getColumn("data");
Column numCol = table.getColumn("num");
@@ -123,7 +119,7 @@ public class ColumnValidatorTest extends TestCase
// success
}
assertSame(SimpleColumnValidator.INSTANCE, idCol.getColumnValidator());
-
+
try {
table.addRow(Column.AUTO_NUMBER, "row4", -3);
fail("IllegalArgumentException should have been thrown");
@@ -139,12 +135,12 @@ public class ColumnValidatorTest extends TestCase
createExpectedRow("id", 2, "data", "row2", "num", 0),
createExpectedRow("id", 3, "data", "row3", "num", 1),
createExpectedRow("id", 4, "data", "row4", "num", 4));
-
+
assertTable(expectedRows, table);
IndexCursor pkCursor = CursorBuilder.createPrimaryKeyCursor(table);
assertNotNull(pkCursor.findRowByEntry(1));
-
+
pkCursor.setCurrentRowValue(dataCol, "row1_mod");
assertEquals(createExpectedRow("id", 1, "data", "row1_mod", "num", -1),
@@ -174,15 +170,13 @@ public class ColumnValidatorTest extends TestCase
assertEquals(createExpectedRow("id", 3, "data", "row3", "num", 1),
CursorBuilder.findRowByPrimaryKey(table, 3));
- final ColumnValidator cv2 = new ColumnValidator() {
- public Object validate(Column col, Object v1) {
+ final ColumnValidator cv2 = (col, v1) -> {
Number num = (Number)v1;
if((num == null) || (num.intValue() < 0)) {
return 0;
}
return v1;
- }
- };
+ };
numCol.setColumnValidator(cv2);
@@ -195,7 +189,7 @@ public class ColumnValidatorTest extends TestCase
createExpectedRow("id", 3, "data", "row3", "num", 1),
createExpectedRow("id", 4, "data", "row4", "num", 4),
createExpectedRow("id", 5, "data", "row5", "num", 0));
-
+
assertTable(expectedRows, table);
assertNotNull(pkCursor.findRowByEntry(3));
@@ -203,8 +197,8 @@ public class ColumnValidatorTest extends TestCase
assertEquals(createExpectedRow("id", 3, "data", "row3", "num", 0),
pkCursor.getCurrentRow());
-
+
db.close();
}
- }
+ }
}