You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jdo-commits@db.apache.org by mb...@apache.org on 2022/08/13 19:35:46 UTC
[db-jdo] 07/07: JDO-817 removing compiler warnings: „anonymous can be replaced by lambda“ in api submodule
This is an automated email from the ASF dual-hosted git repository.
mbo pushed a commit to branch tck-compiler-warnings
in repository https://gitbox.apache.org/repos/asf/db-jdo.git
commit 6084535ecbb99ccff46d30591827b09f21dc978c
Author: Michael Bouschen <Mi...@akquinet.de>
AuthorDate: Sat Aug 13 21:21:42 2022 +0200
JDO-817 removing compiler warnings: „anonymous can be replaced by lambda“ in api submodule
---
api/src/main/java/javax/jdo/JDOHelper.java | 114 ++++-----------------
.../java/javax/jdo/identity/ObjectIdentity.java | 9 +-
api/src/main/java/javax/jdo/spi/I18NHelper.java | 16 +--
api/src/main/java/javax/jdo/spi/JDOImplHelper.java | 51 ++++-----
api/src/test/java/javax/jdo/EnhancerTest.java | 22 ++--
.../javax/jdo/identity/ObjectIdentityTest.java | 9 +-
api/src/test/java/javax/jdo/schema/XMLTest.java | 6 +-
api/src/test/java/javax/jdo/util/XMLTestUtil.java | 12 +--
8 files changed, 56 insertions(+), 183 deletions(-)
diff --git a/api/src/main/java/javax/jdo/JDOHelper.java b/api/src/main/java/javax/jdo/JDOHelper.java
index 3473be46..fb479b84 100644
--- a/api/src/main/java/javax/jdo/JDOHelper.java
+++ b/api/src/main/java/javax/jdo/JDOHelper.java
@@ -176,13 +176,7 @@ public class JDOHelper implements Constants {
* implementations.
*/
private static JDOImplHelper implHelper =
- doPrivileged(
- new PrivilegedAction<JDOImplHelper> () {
- public JDOImplHelper run () {
- return JDOImplHelper.getInstance();
- }
- }
- );
+ doPrivileged((PrivilegedAction<JDOImplHelper>) JDOImplHelper::getInstance);
/** The singleton instance of JDOHelper.
* @since 2.1
@@ -209,101 +203,61 @@ public class JDOHelper implements Constants {
* implementations of getPersistenceManager.
*/
static StateInterrogationObjectReturn getPersistenceManager =
- new StateInterrogationObjectReturn() {
- public Object get(Object pc, StateInterrogation si) {
- return si.getPersistenceManager(pc);
- }
- };
+ (pc, si) -> si.getPersistenceManager(pc);
/** The stateless instance used for handling non-binary-compatible
* implementations of getObjectId.
*/
static StateInterrogationObjectReturn getObjectId =
- new StateInterrogationObjectReturn() {
- public Object get(Object pc, StateInterrogation si) {
- return si.getObjectId(pc);
- }
- };
+ (pc, si) -> si.getObjectId(pc);
/** The stateless instance used for handling non-binary-compatible
* implementations of getTransactionalObjectId.
*/
static StateInterrogationObjectReturn getTransactionalObjectId =
- new StateInterrogationObjectReturn() {
- public Object get(Object pc, StateInterrogation si) {
- return si.getTransactionalObjectId(pc);
- }
- };
+ (pc, si) -> si.getTransactionalObjectId(pc);
/** The stateless instance used for handling non-binary-compatible
* implementations of getVersion.
*/
static StateInterrogationObjectReturn getVersion =
- new StateInterrogationObjectReturn() {
- public Object get(Object pc, StateInterrogation si) {
- return si.getVersion(pc);
- }
- };
+ (pc, si) -> si.getVersion(pc);
/** The stateless instance used for handling non-binary-compatible
* implementations of isPersistent.
*/
static StateInterrogationBooleanReturn isPersistent =
- new StateInterrogationBooleanReturn() {
- public Boolean is(Object pc, StateInterrogation si) {
- return si.isPersistent(pc);
- }
- };
+ (pc, si) -> si.isPersistent(pc);
/** The stateless instance used for handling non-binary-compatible
* implementations of isTransactional.
*/
static StateInterrogationBooleanReturn isTransactional =
- new StateInterrogationBooleanReturn() {
- public Boolean is(Object pc, StateInterrogation si) {
- return si.isTransactional(pc);
- }
- };
+ (pc, si) -> si.isTransactional(pc);
/** The stateless instance used for handling non-binary-compatible
* implementations of isDirty.
*/
static StateInterrogationBooleanReturn isDirty =
- new StateInterrogationBooleanReturn() {
- public Boolean is(Object pc, StateInterrogation si) {
- return si.isDirty(pc);
- }
- };
+ (pc, si) -> si.isDirty(pc);
/** The stateless instance used for handling non-binary-compatible
* implementations of isNew.
*/
static StateInterrogationBooleanReturn isNew =
- new StateInterrogationBooleanReturn() {
- public Boolean is(Object pc, StateInterrogation si) {
- return si.isNew(pc);
- }
- };
+ (pc, si) -> si.isNew(pc);
/** The stateless instance used for handling non-binary-compatible
* implementations of isDeleted.
*/
static StateInterrogationBooleanReturn isDeleted =
- new StateInterrogationBooleanReturn() {
- public Boolean is(Object pc, StateInterrogation si) {
- return si.isDeleted(pc);
- }
- };
+ (pc, si) -> si.isDeleted(pc);
/** The stateless instance used for handling non-binary-compatible
* implementations of isDetached.
*/
static StateInterrogationBooleanReturn isDetached =
- new StateInterrogationBooleanReturn() {
- public Boolean is(Object pc, StateInterrogation si) {
- return si.isDetached(pc);
- }
- };
+ (pc, si) -> si.isDetached(pc);
/** Return the associated <code>PersistenceManager</code> if there is one.
* Transactional and persistent instances return the associated
@@ -1902,11 +1856,7 @@ public class JDOHelper implements Constants {
*/
private static ClassLoader getContextClassLoader() {
return doPrivileged(
- new PrivilegedAction<ClassLoader> () {
- public ClassLoader run () {
- return Thread.currentThread().getContextClassLoader();
- }
- }
+ (PrivilegedAction<ClassLoader>) () -> Thread.currentThread().getContextClassLoader()
);
}
@@ -1915,13 +1865,7 @@ public class JDOHelper implements Constants {
*/
private static InputStream getResourceAsStream(
final ClassLoader resourceLoader, final String name) {
- return doPrivileged(
- new PrivilegedAction<InputStream>() {
- public InputStream run() {
- return resourceLoader.getResourceAsStream(name);
- }
- }
- );
+ return doPrivileged((PrivilegedAction<InputStream>) () -> resourceLoader.getResourceAsStream(name));
}
@@ -1940,11 +1884,7 @@ public class JDOHelper implements Constants {
throws NoSuchMethodException {
try {
return doPrivileged(
- new PrivilegedExceptionAction<Method>() {
- public Method run() throws NoSuchMethodException {
- return implClass.getMethod(methodName, parameterTypes);
- }
- }
+ (PrivilegedExceptionAction<Method>) () -> implClass.getMethod(methodName, parameterTypes)
);
} catch (PrivilegedActionException ex) {
throw (NoSuchMethodException)ex.getException();
@@ -1959,13 +1899,7 @@ public class JDOHelper implements Constants {
throws IllegalAccessException, InvocationTargetException {
try {
return doPrivileged(
- new PrivilegedExceptionAction<Object>() {
- public Object run()
- throws IllegalAccessException,
- InvocationTargetException {
- return method.invoke (instance, parameters);
- }
- }
+ (PrivilegedExceptionAction<Object>) () -> method.invoke (instance, parameters)
);
} catch (PrivilegedActionException ex) {
Exception cause = ex.getException();
@@ -1990,11 +1924,7 @@ public class JDOHelper implements Constants {
throws IOException {
try {
return doPrivileged(
- new PrivilegedExceptionAction<Enumeration<URL>>() {
- public Enumeration<URL> run() throws IOException {
- return resourceLoader.getResources(resourceName);
- }
- }
+ (PrivilegedExceptionAction<Enumeration<URL>>) () -> resourceLoader.getResources(resourceName)
);
} catch (PrivilegedActionException ex) {
throw (IOException)ex.getException();
@@ -2016,11 +1946,7 @@ public class JDOHelper implements Constants {
throws ClassNotFoundException {
try {
return doPrivileged(
- new PrivilegedExceptionAction<Class<?>>() {
- public Class<?> run() throws ClassNotFoundException {
- return Class.forName(name, init, loader);
- }
- }
+ (PrivilegedExceptionAction<Class<?>>) () -> Class.forName(name, init, loader)
);
} catch (PrivilegedActionException ex) {
throw (ClassNotFoundException)ex.getException();
@@ -2037,11 +1963,7 @@ public class JDOHelper implements Constants {
throws IOException {
try {
return doPrivileged(
- new PrivilegedExceptionAction<InputStream>() {
- public InputStream run() throws IOException {
- return url.openStream();
- }
- }
+ (PrivilegedExceptionAction<InputStream>) () -> url.openStream()
);
} catch (PrivilegedActionException ex) {
throw (IOException)ex.getException();
diff --git a/api/src/main/java/javax/jdo/identity/ObjectIdentity.java b/api/src/main/java/javax/jdo/identity/ObjectIdentity.java
index 6106d891..a3285842 100644
--- a/api/src/main/java/javax/jdo/identity/ObjectIdentity.java
+++ b/api/src/main/java/javax/jdo/identity/ObjectIdentity.java
@@ -47,14 +47,7 @@ public class ObjectIdentity extends SingleFieldIdentity<ObjectIdentity> {
/** The JDOImplHelper instance used for parsing the String to an Object.
*/
- private static JDOImplHelper helper =
- doPrivileged(
- new PrivilegedAction<JDOImplHelper> () {
- public JDOImplHelper run () {
- return JDOImplHelper.getInstance();
- }
- }
- );
+ private static JDOImplHelper helper = doPrivileged(JDOImplHelper::getInstance);
@SuppressWarnings("unchecked")
private static <T> T doPrivileged(PrivilegedAction<T> privilegedAction) {
diff --git a/api/src/main/java/javax/jdo/spi/I18NHelper.java b/api/src/main/java/javax/jdo/spi/I18NHelper.java
index 161bf844..304e082b 100644
--- a/api/src/main/java/javax/jdo/spi/I18NHelper.java
+++ b/api/src/main/java/javax/jdo/spi/I18NHelper.java
@@ -106,13 +106,7 @@ public class I18NHelper {
* @return the helper instance bound to the bundle
*/
public static I18NHelper getInstance (final Class<?> cls) {
- ClassLoader classLoader = doPrivileged (
- new PrivilegedAction<ClassLoader> () {
- public ClassLoader run () {
- return cls.getClassLoader();
- }
- }
- );
+ ClassLoader classLoader = doPrivileged (cls::getClassLoader);
String bundle = getPackageName (cls.getName()) + bundleSuffix;
return getInstance (bundle, classLoader);
}
@@ -388,13 +382,7 @@ public class I18NHelper {
* block because of security.
*/
private static ClassLoader getSystemClassLoaderPrivileged() {
- return doPrivileged (
- new PrivilegedAction<ClassLoader> () {
- public ClassLoader run () {
- return ClassLoader.getSystemClassLoader();
- }
- }
- );
+ return doPrivileged (ClassLoader::getSystemClassLoader);
}
@SuppressWarnings("unchecked")
diff --git a/api/src/main/java/javax/jdo/spi/JDOImplHelper.java b/api/src/main/java/javax/jdo/spi/JDOImplHelper.java
index b036c9bf..b1cd91e7 100644
--- a/api/src/main/java/javax/jdo/spi/JDOImplHelper.java
+++ b/api/src/main/java/javax/jdo/spi/JDOImplHelper.java
@@ -736,30 +736,27 @@ public class JDOImplHelper extends java.lang.Object {
static {
if (isClassLoadable("java.util.Currency")) {
jdoImplHelper.registerStringConstructor(
- Currency.class, new StringConstructor() {
- public Object construct(String s) {
- try {
- return Currency.getInstance(s);
- } catch (IllegalArgumentException ex) {
- throw new javax.jdo.JDOUserException(msg.msg(
- "EXC_CurrencyStringConstructorIllegalArgument", //NOI18N
- s), ex);
- } catch (Exception ex) {
- throw new JDOUserException(msg.msg(
- "EXC_CurrencyStringConstructorException"), //NOI18N
- ex);
- }
- }
- });
+ Currency.class,
+ s -> {
+ try {
+ return Currency.getInstance(s);
+ } catch (IllegalArgumentException ex) {
+ throw new JDOUserException(msg.msg(
+ "EXC_CurrencyStringConstructorIllegalArgument", //NOI18N
+ s), ex);
+ } catch (Exception ex) {
+ throw new JDOUserException(msg.msg(
+ "EXC_CurrencyStringConstructorException"), //NOI18N
+ ex);
+ }
+ });
}
- jdoImplHelper.registerStringConstructor(Locale.class, new StringConstructor() {
- public Object construct(String s) {
- try {
- return getLocale(s);
- } catch (Exception ex) {
- throw new JDOUserException(msg.msg(
- "EXC_LocaleStringConstructorException"), ex); //NOI18N
- }
+ jdoImplHelper.registerStringConstructor(Locale.class, s -> {
+ try {
+ return getLocale(s);
+ } catch (Exception ex) {
+ throw new JDOUserException(msg.msg(
+ "EXC_LocaleStringConstructorException"), ex); //NOI18N
}
});
jdoImplHelper.registerStringConstructor(Date.class, new StringConstructor() {
@@ -874,13 +871,7 @@ public class JDOImplHelper extends java.lang.Object {
static DateFormat getDateTimeInstance() {
DateFormat result = null;
try {
- result = doPrivileged (
- new PrivilegedAction<DateFormat> () {
- public DateFormat run () {
- return DateFormat.getDateTimeInstance();
- }
- }
- );
+ result = doPrivileged (() -> DateFormat.getDateTimeInstance());
} catch (Exception ex) {
result = DateFormat.getInstance();
}
diff --git a/api/src/test/java/javax/jdo/EnhancerTest.java b/api/src/test/java/javax/jdo/EnhancerTest.java
index 38782e95..4e8046c1 100644
--- a/api/src/test/java/javax/jdo/EnhancerTest.java
+++ b/api/src/test/java/javax/jdo/EnhancerTest.java
@@ -324,19 +324,17 @@ public class EnhancerTest extends AbstractTest {
private Thread createReaderThread(final InputStream input, final CharBuffer output) {
final Reader reader = new InputStreamReader(input);
Thread thread = new Thread(
- new Runnable() {
- public void run() {
- int count = 0;
- int outputBytesRead = 0;
- try {
- while (-1 != (outputBytesRead = reader.read(output))) {
- count += outputBytesRead;
- }
- } catch (IOException e) {
- e.printStackTrace();
- } finally {
- output.flip();
+ () -> {
+ int count = 0;
+ int outputBytesRead = 0;
+ try {
+ while (-1 != (outputBytesRead = reader.read(output))) {
+ count += outputBytesRead;
}
+ } catch (IOException e) {
+ e.printStackTrace();
+ } finally {
+ output.flip();
}
});
thread.start();
diff --git a/api/src/test/java/javax/jdo/identity/ObjectIdentityTest.java b/api/src/test/java/javax/jdo/identity/ObjectIdentityTest.java
index 63d311f4..34af5cf7 100644
--- a/api/src/test/java/javax/jdo/identity/ObjectIdentityTest.java
+++ b/api/src/test/java/javax/jdo/identity/ObjectIdentityTest.java
@@ -52,14 +52,7 @@ public class ObjectIdentityTest extends SingleFieldIdentityTest {
/** The JDOImplHelper instance used for Date formatting.
*/
- private static JDOImplHelper helper =
- doPrivileged(
- new PrivilegedAction<JDOImplHelper> () {
- public JDOImplHelper run () {
- return JDOImplHelper.getInstance();
- }
- }
- );
+ private static JDOImplHelper helper = doPrivileged(JDOImplHelper::getInstance);
@SuppressWarnings("unchecked")
private static <T> T doPrivileged(PrivilegedAction<T> privilegedAction) {
diff --git a/api/src/test/java/javax/jdo/schema/XMLTest.java b/api/src/test/java/javax/jdo/schema/XMLTest.java
index ceb03e47..c1286952 100644
--- a/api/src/test/java/javax/jdo/schema/XMLTest.java
+++ b/api/src/test/java/javax/jdo/schema/XMLTest.java
@@ -70,11 +70,7 @@ public class XMLTest extends AbstractTest {
/** Returns array of files of matching file names. */
protected static File[] getFiles(final String prefix, final String suffix) {
- FilenameFilter filter = new FilenameFilter () {
- public boolean accept(File file, String name) {
- return (name.startsWith(prefix) && name.endsWith(suffix));
- }
- };
+ FilenameFilter filter = (file, name) -> (name.startsWith(prefix) && name.endsWith(suffix));
File dir = new File(FILE_PREFIX);
return dir.listFiles(filter);
}
diff --git a/api/src/test/java/javax/jdo/util/XMLTestUtil.java b/api/src/test/java/javax/jdo/util/XMLTestUtil.java
index 07f5ce25..520c8926 100644
--- a/api/src/test/java/javax/jdo/util/XMLTestUtil.java
+++ b/api/src/test/java/javax/jdo/util/XMLTestUtil.java
@@ -456,21 +456,13 @@ public class XMLTestUtil {
/** Returns array of files of matching file names. */
private File[] getFiles(File dir, final String suffix) {
- FilenameFilter filter = new FilenameFilter() {
- public boolean accept(File file, String name) {
- return name.endsWith(suffix);
- }
- };
+ FilenameFilter filter = (file, name) -> name.endsWith(suffix);
return dir.listFiles(filter);
}
/** */
private File[] getDirectories(File dir) {
- FileFilter filter = new FileFilter() {
- public boolean accept(File pathname) {
- return pathname.isDirectory();
- }
- };
+ FileFilter filter = File::isDirectory;
return dir.listFiles(filter);
}