You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by da...@apache.org on 2017/10/26 17:27:21 UTC
svn commit: r1813435 - in /felix/trunk/converter/converter/src:
main/java/org/apache/felix/converter/impl/ main/java/org/osgi/util/converter/
test/java/org/apache/felix/converter/impl/
Author: davidb
Date: Thu Oct 26 17:27:21 2017
New Revision: 1813435
URL: http://svn.apache.org/viewvc?rev=1813435&view=rev
Log:
Felix Converter: add comments and make some internal classes package private.
Modified:
felix/trunk/converter/converter/src/main/java/org/apache/felix/converter/impl/AbstractSpecifying.java
felix/trunk/converter/converter/src/main/java/org/apache/felix/converter/impl/AdapterImpl.java
felix/trunk/converter/converter/src/main/java/org/apache/felix/converter/impl/ConverterBuilderImpl.java
felix/trunk/converter/converter/src/main/java/org/apache/felix/converter/impl/ConverterImpl.java
felix/trunk/converter/converter/src/main/java/org/apache/felix/converter/impl/ConvertingImpl.java
felix/trunk/converter/converter/src/main/java/org/apache/felix/converter/impl/FunctioningImpl.java
felix/trunk/converter/converter/src/main/java/org/apache/felix/converter/impl/InternalConverter.java
felix/trunk/converter/converter/src/main/java/org/apache/felix/converter/impl/InternalConverting.java
felix/trunk/converter/converter/src/main/java/org/osgi/util/converter/Converters.java
felix/trunk/converter/converter/src/test/java/org/apache/felix/converter/impl/ConverterTest.java
Modified: felix/trunk/converter/converter/src/main/java/org/apache/felix/converter/impl/AbstractSpecifying.java
URL: http://svn.apache.org/viewvc/felix/trunk/converter/converter/src/main/java/org/apache/felix/converter/impl/AbstractSpecifying.java?rev=1813435&r1=1813434&r2=1813435&view=diff
==============================================================================
--- felix/trunk/converter/converter/src/main/java/org/apache/felix/converter/impl/AbstractSpecifying.java (original)
+++ felix/trunk/converter/converter/src/main/java/org/apache/felix/converter/impl/AbstractSpecifying.java Thu Oct 26 17:27:21 2017
@@ -18,7 +18,7 @@ package org.apache.felix.converter.impl;
import org.osgi.util.converter.Specifying;
-public abstract class AbstractSpecifying<T extends Specifying<T>> implements Specifying<T> {
+abstract class AbstractSpecifying<T extends Specifying<T>> implements Specifying<T> {
protected volatile Object defaultValue;
protected volatile boolean hasDefault = false;
protected volatile boolean forceCopy = false;
Modified: felix/trunk/converter/converter/src/main/java/org/apache/felix/converter/impl/AdapterImpl.java
URL: http://svn.apache.org/viewvc/felix/trunk/converter/converter/src/main/java/org/apache/felix/converter/impl/AdapterImpl.java?rev=1813435&r1=1813434&r2=1813435&view=diff
==============================================================================
--- felix/trunk/converter/converter/src/main/java/org/apache/felix/converter/impl/AdapterImpl.java (original)
+++ felix/trunk/converter/converter/src/main/java/org/apache/felix/converter/impl/AdapterImpl.java Thu Oct 26 17:27:21 2017
@@ -30,7 +30,7 @@ import org.osgi.util.converter.Convertin
import org.osgi.util.converter.Functioning;
import org.osgi.util.converter.TypeReference;
-public class AdapterImpl implements InternalConverter {
+class AdapterImpl implements InternalConverter {
private final InternalConverter delegate;
private final Map<Type, List<ConverterFunction>> typeRules;
private final List<ConverterFunction> allRules;
Modified: felix/trunk/converter/converter/src/main/java/org/apache/felix/converter/impl/ConverterBuilderImpl.java
URL: http://svn.apache.org/viewvc/felix/trunk/converter/converter/src/main/java/org/apache/felix/converter/impl/ConverterBuilderImpl.java?rev=1813435&r1=1813434&r2=1813435&view=diff
==============================================================================
--- felix/trunk/converter/converter/src/main/java/org/apache/felix/converter/impl/ConverterBuilderImpl.java (original)
+++ felix/trunk/converter/converter/src/main/java/org/apache/felix/converter/impl/ConverterBuilderImpl.java Thu Oct 26 17:27:21 2017
@@ -28,7 +28,7 @@ import org.osgi.util.converter.Converter
import org.osgi.util.converter.ConverterFunction;
import org.osgi.util.converter.TargetRule;
-public class ConverterBuilderImpl implements ConverterBuilder {
+class ConverterBuilderImpl implements ConverterBuilder {
private final InternalConverter adapter;
private final Map<Type, List<ConverterFunction>> rules = new HashMap<>();
private final List<ConverterFunction> catchAllRules = new ArrayList<>();
Modified: felix/trunk/converter/converter/src/main/java/org/apache/felix/converter/impl/ConverterImpl.java
URL: http://svn.apache.org/viewvc/felix/trunk/converter/converter/src/main/java/org/apache/felix/converter/impl/ConverterImpl.java?rev=1813435&r1=1813434&r2=1813435&view=diff
==============================================================================
--- felix/trunk/converter/converter/src/main/java/org/apache/felix/converter/impl/ConverterImpl.java (original)
+++ felix/trunk/converter/converter/src/main/java/org/apache/felix/converter/impl/ConverterImpl.java Thu Oct 26 17:27:21 2017
@@ -32,6 +32,13 @@ import org.osgi.util.converter.Rule;
import org.osgi.util.converter.TypeRule;
import org.osgi.util.function.Function;
+/**
+ * Top-level implementation of the Converter. This class contains a number of rules
+ * that cover 'special cases'. <p>
+ *
+ * Note that this class avoids lambda's and hard dependencies on Java-8 (or later) types
+ * to also work under Java 7.
+ */
public class ConverterImpl implements InternalConverter {
private static final SimpleDateFormat ISO8601_DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssXXX");
static {
Modified: felix/trunk/converter/converter/src/main/java/org/apache/felix/converter/impl/ConvertingImpl.java
URL: http://svn.apache.org/viewvc/felix/trunk/converter/converter/src/main/java/org/apache/felix/converter/impl/ConvertingImpl.java?rev=1813435&r1=1813434&r2=1813435&view=diff
==============================================================================
--- felix/trunk/converter/converter/src/main/java/org/apache/felix/converter/impl/ConvertingImpl.java (original)
+++ felix/trunk/converter/converter/src/main/java/org/apache/felix/converter/impl/ConvertingImpl.java Thu Oct 26 17:27:21 2017
@@ -47,7 +47,7 @@ import org.osgi.util.converter.Converter
import org.osgi.util.converter.Converting;
import org.osgi.util.converter.TypeReference;
-public class ConvertingImpl extends AbstractSpecifying<Converting> implements Converting, InternalConverting {
+class ConvertingImpl extends AbstractSpecifying<Converting> implements Converting, InternalConverting {
private static final Map<Class<?>, Class<?>> INTERFACE_IMPLS;
static {
Map<Class<?>, Class<?>> m = new HashMap<>();
Modified: felix/trunk/converter/converter/src/main/java/org/apache/felix/converter/impl/FunctioningImpl.java
URL: http://svn.apache.org/viewvc/felix/trunk/converter/converter/src/main/java/org/apache/felix/converter/impl/FunctioningImpl.java?rev=1813435&r1=1813434&r2=1813435&view=diff
==============================================================================
--- felix/trunk/converter/converter/src/main/java/org/apache/felix/converter/impl/FunctioningImpl.java (original)
+++ felix/trunk/converter/converter/src/main/java/org/apache/felix/converter/impl/FunctioningImpl.java Thu Oct 26 17:27:21 2017
@@ -22,10 +22,10 @@ import org.osgi.util.converter.Functioni
import org.osgi.util.converter.TypeReference;
import org.osgi.util.function.Function;
-public class FunctioningImpl extends AbstractSpecifying<Functioning> implements Functioning {
+class FunctioningImpl extends AbstractSpecifying<Functioning> implements Functioning {
private InternalConverter converter;
- public FunctioningImpl(InternalConverter converterImpl) {
+ FunctioningImpl(InternalConverter converterImpl) {
converter = converterImpl;
}
Modified: felix/trunk/converter/converter/src/main/java/org/apache/felix/converter/impl/InternalConverter.java
URL: http://svn.apache.org/viewvc/felix/trunk/converter/converter/src/main/java/org/apache/felix/converter/impl/InternalConverter.java?rev=1813435&r1=1813434&r2=1813435&view=diff
==============================================================================
--- felix/trunk/converter/converter/src/main/java/org/apache/felix/converter/impl/InternalConverter.java (original)
+++ felix/trunk/converter/converter/src/main/java/org/apache/felix/converter/impl/InternalConverter.java Thu Oct 26 17:27:21 2017
@@ -18,6 +18,19 @@ package org.apache.felix.converter.impl;
import org.osgi.util.converter.Converter;
-public interface InternalConverter extends Converter {
+/**
+ * This interface specifies a {@link #convert(Object)} method that
+ * returns an {@link InternalConverting} rather than a normal Converting
+ * instance.
+ */
+interface InternalConverter extends Converter {
+ /**
+ * Start a conversion for the given object. This method overrides the
+ * {@link Converter#convert(Object)} method with a co-variant return type.
+ *
+ * @param obj The object that should be converted.
+ * @return An {@link InternalConverting} object to complete the conversion.
+ */
+ @Override
InternalConverting convert(Object obj);
}
Modified: felix/trunk/converter/converter/src/main/java/org/apache/felix/converter/impl/InternalConverting.java
URL: http://svn.apache.org/viewvc/felix/trunk/converter/converter/src/main/java/org/apache/felix/converter/impl/InternalConverting.java?rev=1813435&r1=1813434&r2=1813435&view=diff
==============================================================================
--- felix/trunk/converter/converter/src/main/java/org/apache/felix/converter/impl/InternalConverting.java (original)
+++ felix/trunk/converter/converter/src/main/java/org/apache/felix/converter/impl/InternalConverting.java Thu Oct 26 17:27:21 2017
@@ -19,6 +19,16 @@ package org.apache.felix.converter.impl;
import org.osgi.util.converter.Converter;
import org.osgi.util.converter.Converting;
-public interface InternalConverting extends Converting {
+/**
+ * This interface is the same as the {@link Converting} interface with the addition
+ * that the current converter (which may include custom rules) can be set on it.
+ * This allows the converter to be re-entrant and use itself for sub-conversions if
+ * applicable.
+ */
+interface InternalConverting extends Converting {
+ /**
+ * Set the current converter.
+ * @param c The current converter.
+ */
void setConverter(Converter c);
}
Modified: felix/trunk/converter/converter/src/main/java/org/osgi/util/converter/Converters.java
URL: http://svn.apache.org/viewvc/felix/trunk/converter/converter/src/main/java/org/osgi/util/converter/Converters.java?rev=1813435&r1=1813434&r2=1813435&view=diff
==============================================================================
--- felix/trunk/converter/converter/src/main/java/org/osgi/util/converter/Converters.java (original)
+++ felix/trunk/converter/converter/src/main/java/org/osgi/util/converter/Converters.java Thu Oct 26 17:27:21 2017
@@ -16,9 +16,7 @@
*/
package org.osgi.util.converter;
-import org.apache.felix.converter.impl.ConverterBuilderImpl;
import org.apache.felix.converter.impl.ConverterImpl;
-import org.apache.felix.converter.impl.InternalConverter;
/**
* Factory class to obtain the standard converter or a new converter builder.
@@ -27,11 +25,11 @@ import org.apache.felix.converter.impl.I
* @ThreadSafe
*/
public class Converters {
- private static final InternalConverter CONVERTER;
+ private static final Converter CONVERTER;
static {
ConverterImpl impl = new ConverterImpl();
- ConverterBuilderImpl cb = impl.newConverterBuilder();
+ ConverterBuilder cb = impl.newConverterBuilder();
impl.addStandardRules(cb);
CONVERTER = cb.build();
}
Modified: felix/trunk/converter/converter/src/test/java/org/apache/felix/converter/impl/ConverterTest.java
URL: http://svn.apache.org/viewvc/felix/trunk/converter/converter/src/test/java/org/apache/felix/converter/impl/ConverterTest.java?rev=1813435&r1=1813434&r2=1813435&view=diff
==============================================================================
--- felix/trunk/converter/converter/src/test/java/org/apache/felix/converter/impl/ConverterTest.java (original)
+++ felix/trunk/converter/converter/src/test/java/org/apache/felix/converter/impl/ConverterTest.java Thu Oct 26 17:27:21 2017
@@ -1041,6 +1041,7 @@ public class ConverterTest {
assertEquals("{}", cs);
}
+ @SuppressWarnings({ "rawtypes", "unchecked" })
@Test
public void testTargetAsDTO() {
MyDTOWithMethods expected = new MyDTOWithMethods();