Skip to content

Commit

Permalink
Make classes serializable (#4148)
Browse files Browse the repository at this point in the history
* Make classes serializable

* Sponarqube fixes

* Fixes

* Fixes

* Fixes

* Fixes

* Fixes

* Refactoring and optimization

* Small fix

* SplitPackagesTest ignores flow-test-generic

* Make sonarqube happy

* Use sl4j

* Add a copyright

* Optimize, fix sonarqube issues

* Make the test friendly for the depended projects

* After review fix, small improvements

* Small improvements

* Javadoc
  • Loading branch information
Ilia Motornyi authored and Denis committed May 24, 2018
1 parent 3c0716f commit bad717d
Show file tree
Hide file tree
Showing 49 changed files with 613 additions and 53 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
*/
package com.vaadin.flow.data.binder;

import java.io.Serializable;

/**
* A generic interface for field components and other user interface objects
* that have a user-editable value that should be validated.
Expand All @@ -24,7 +26,7 @@
* @param <V>
* the value type
*/
public interface HasValidator<V> {
public interface HasValidator<V> extends Serializable {

/**
* Returns a validator that checks the state of the Value. This should be
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public interface ArrayUpdater extends Serializable {
* Array updater strategy.
*
*/
public interface Update {
public interface Update extends Serializable {
/**
* Clears {@code length} elements in array from the {@code start}
* position.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public class DataCommunicator<T> implements Serializable {
private SerializableConsumer<ExecutionContext> flushRequest;
private SerializableConsumer<ExecutionContext> flushUpdatedDataRequest;

private static class SizeVerifier<T> implements Consumer<T> {
private static class SizeVerifier<T> implements Consumer<T>, Serializable {

private int size;

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

package com.vaadin.flow.data.value;

import java.io.Serializable;

import com.vaadin.flow.component.AbstractSinglePropertyField;
import com.vaadin.flow.component.HasValue;

Expand All @@ -30,7 +32,7 @@
*
* @author Vaadin Ltd.
*/
public interface HasValueChangeMode {
public interface HasValueChangeMode extends Serializable {

/**
* Gets current value change mode of the component.
Expand Down
7 changes: 7 additions & 0 deletions flow-server/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>com.vaadin</groupId>
<artifactId>flow-test-generic</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>


<!-- API DEPENDENCIES -->

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package com.vaadin.flow.component;

import java.io.Serializable;
import java.util.List;
import java.util.Locale;
import java.util.Optional;
Expand Down Expand Up @@ -52,7 +53,7 @@ public abstract class Component
* Encapsulates data required for mapping a new component instance to an
* existing element.
*/
static class MapToExistingElement {
static class MapToExistingElement implements Serializable {
Element element = null;
private boolean mapElementToComponent = false;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
*/
package com.vaadin.flow.component;

import java.io.Serializable;

import com.vaadin.flow.dom.Element;

/**
Expand All @@ -23,7 +25,7 @@
* @author Vaadin Ltd
*/
@FunctionalInterface
public interface HasElement {
public interface HasElement extends Serializable {
/**
* Gets the element associated with this instance.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,14 @@

package com.vaadin.flow.component;

import java.io.Serializable;

/**
* A component that supports input validation.
*
* @author Vaadin Ltd.
*/
public interface HasValidation {
public interface HasValidation extends Serializable {

/**
* Sets an error message to the component.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@
* the value type
* @author Vaadin Ltd.
*/
public interface HasValue<E extends ValueChangeEvent<V>, V> {
public interface HasValue<E extends ValueChangeEvent<V>, V> extends Serializable {

/**
* An event fired when the value of a {@code HasValue} changes.
*
* @param <V>
* the value type
*/
interface ValueChangeEvent<V> {
interface ValueChangeEvent<V> extends Serializable {
HasValue<?, V> getHasValue();

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
*/
package com.vaadin.flow.component;

import java.io.Serializable;

import com.vaadin.flow.dom.Element;

/**
Expand All @@ -34,7 +36,7 @@
* the type used when getting the property value, this is typically
* either <code>S</code> or <code>Optional&lt;S&gt;</code>
*/
public interface PropertyDescriptor<S, G> {
public interface PropertyDescriptor<S, G> extends Serializable {

/**
* Sets the property value for the given component.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package com.vaadin.flow.component.internal;

import java.io.Serializable;
import java.lang.reflect.Constructor;
import java.util.LinkedHashMap;
import java.util.Optional;
Expand All @@ -28,7 +29,7 @@
*
* @author Vaadin Ltd
*/
public class EventDataCache {
public class EventDataCache implements Serializable {

private ConcurrentHashMap<Class<? extends ComponentEvent<?>>, LinkedHashMap<String, Class<?>>> dataExpressions = new ConcurrentHashMap<>();
private ConcurrentHashMap<Class<? extends ComponentEvent<?>>, Constructor<?>> eventConstructors = new ConcurrentHashMap<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import java.io.IOException;
import java.io.InputStream;
import java.io.Serializable;
import java.net.URI;
import java.net.URISyntaxException;
import java.nio.charset.StandardCharsets;
Expand Down Expand Up @@ -45,7 +46,7 @@
* @author Vaadin Ltd
*
*/
public class HtmlDependencyParser {
public class HtmlDependencyParser implements Serializable {

private final String root;

Expand Down
3 changes: 2 additions & 1 deletion flow-server/src/main/java/com/vaadin/flow/dom/ClassList.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,15 @@
*/
package com.vaadin.flow.dom;

import java.io.Serializable;
import java.util.Set;

/**
* Representation of the class names for an {@link Element}.
*
* @author Vaadin Ltd
*/
public interface ClassList extends Set<String> {
public interface ClassList extends Set<String>, Serializable {

/**
* Sets or removes the given class name, based on the {@code set} parameter.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@
*/
package com.vaadin.flow.dom;

import java.io.Serializable;

/**
* Listener for element attach events. It is invoked when the element is
* attached to the UI.
*/
@FunctionalInterface
public interface ElementAttachListener {
public interface ElementAttachListener extends Serializable {
/**
* Invoked when an element is attached to the UI.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@
*/
package com.vaadin.flow.dom;

import java.io.Serializable;

/**
* Listener for element detach events. It is invoked when the element is
* detached from the UI.
*/
@FunctionalInterface
public interface ElementDetachListener {
public interface ElementDetachListener extends Serializable {
/**
* Invoked when an element is detached from the UI.
*
Expand Down
3 changes: 2 additions & 1 deletion flow-server/src/main/java/com/vaadin/flow/dom/ThemeList.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,15 @@
*/
package com.vaadin.flow.dom;

import java.io.Serializable;
import java.util.Set;

/**
* Representation of the theme names for an {@link Element}.
*
* @author Vaadin Ltd
*/
public interface ThemeList extends Set<String> {
public interface ThemeList extends Set<String>, Serializable {

/**
* Sets or removes the given theme name, based on the {@code set} parameter.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package com.vaadin.flow.dom.impl;

import java.io.Serializable;
import java.util.AbstractSet;
import java.util.ArrayList;
import java.util.Collection;
Expand All @@ -29,7 +30,7 @@
* @author Vaadin Ltd
*/
public class ImmutableClassList extends AbstractSet<String>
implements ClassList {
implements ClassList, Serializable {

private static final String CANT_MODIFY_MESSAGE = ImmutableEmptyStyle.CANT_MODIFY_MESSAGE;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package com.vaadin.flow.dom.impl;

import java.io.Serializable;
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
Expand All @@ -34,7 +35,7 @@
*
* @author Vaadin Ltd.
*/
public class ThemeListImpl implements ThemeList {
public class ThemeListImpl implements ThemeList, Serializable {
public static final String THEME_ATTRIBUTE_NAME = "theme";
private static final String THEME_NAMES_DELIMITER = " ";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package com.vaadin.flow.function;

import java.io.Serializable;
import java.util.Objects;
import java.util.function.Predicate;

/**
Expand All @@ -28,5 +29,21 @@
*
*/
public interface SerializablePredicate<T> extends Predicate<T>, Serializable {
// Only method inherited from Predicate

@Override
default SerializablePredicate<T> and(Predicate<? super T> other) {
Objects.requireNonNull(other);
return t -> test(t) && other.test(t);
}

@Override
default SerializablePredicate<T> negate() {
return t -> !test(t);
}

@Override
default SerializablePredicate<T> or(Predicate<? super T> other) {
Objects.requireNonNull(other);
return t -> test(t) || other.test(t);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,14 @@
*/
package com.vaadin.flow.i18n;

import java.io.Serializable;
import java.util.List;
import java.util.Locale;

/**
* I18N provider interface for internationalization usage.
*/
public interface I18NProvider {
public interface I18NProvider extends Serializable {

/**
* Get the locales that we have translations for. The first locale should be
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,16 @@
*/
package com.vaadin.flow.i18n;

import java.io.Serializable;

/**
* Any {@code com.vaadin.ui.Component} implementing this interface will be
* informed when the UI locale is changed and on attach.
*
* @author Vaadin Ltd
*/
@FunctionalInterface
public interface LocaleChangeObserver {
public interface LocaleChangeObserver extends Serializable {

/**
* Method called when the UI locale is changed.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Function;

import com.vaadin.flow.function.SerializableFunction;

/**
* A thread-safe cache for the result of doing some reflection lookup based on a
* class. Cached values never expire since it's assumed that the there is a
Expand All @@ -39,7 +41,7 @@ public class ReflectionCache<C, T> {

private final ConcurrentHashMap<Class<? extends C>, T> values = new ConcurrentHashMap<>();

private final Function<Class<? extends C>, T> valueProvider;
private final SerializableFunction<Class<? extends C>, T> valueProvider;

/**
* Creates a new reflection cache with the given value provider. The value
Expand All @@ -52,7 +54,7 @@ public class ReflectionCache<C, T> {
* a function that computes the cached value for a class, not
* <code>null</code>
*/
public ReflectionCache(Function<Class<C>, T> valueProvider) {
public ReflectionCache(SerializableFunction<Class<C>, T> valueProvider) {
if (valueProvider == null) {
throw new IllegalArgumentException("value provider cannot be null");
}
Expand All @@ -62,8 +64,8 @@ public ReflectionCache(Function<Class<C>, T> valueProvider) {
}

@SuppressWarnings({ "unchecked", "rawtypes" })
private static <C, T> Function<Class<? extends C>, T> wrapValueProvider(
Function<Class<C>, T> valueProvider) {
private static <C, T> SerializableFunction<Class<? extends C>, T> wrapValueProvider(
SerializableFunction<Class<C>, T> valueProvider) {
return type -> {
Map<Class<?>, CurrentInstance> instances = CurrentInstance
.getInstances();
Expand Down
Loading

0 comments on commit bad717d

Please sign in to comment.