Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ReactiveBuilder for RxJava #5

Merged
merged 8 commits into from
Nov 21, 2018
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@

<modules>
<module>propertly.core</module>
<module>propertly.reactive</module>
<module>propertly.serialization</module>
</modules>

Expand Down Expand Up @@ -114,7 +115,6 @@
<version>3.0.1</version>
<configuration>
<failOnError>false</failOnError>
<additionalparam>-Xdoclint:none</additionalparam>
</configuration>
</plugin>

Expand Down
63 changes: 63 additions & 0 deletions propertly.reactive/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>de.adito.propertly</groupId>
<artifactId>propertly.parent</artifactId>
<version>0.4.3-SNAPSHOT</version>
</parent>

<artifactId>propertly.reactive</artifactId>

<dependencies>
<dependency>
<groupId>de.adito.propertly</groupId>
<artifactId>propertly.core</artifactId>
<version>${project.version}</version>
</dependency>

<!-- RxJava 2 -->
<dependency>
<groupId>io.reactivex.rxjava2</groupId>
<artifactId>rxjava</artifactId>
<version>2.2.3</version>
</dependency>

<!-- Utility for RxJava 2 -->
<dependency>
<groupId>de.adito.util</groupId>
<artifactId>reactive</artifactId>
<version>1.0.2</version>
</dependency>

<!-- Mockito -->
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>2.23.0</version>
<scope>test</scope>
</dependency>

</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<configuration>
<instructions>
<Export-Package>
de.adito.propertly.reactive.api
</Export-Package>
</instructions>
</configuration>
</plugin>
</plugins>
</build>


</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package de.adito.propertly.reactive.api;

/**
* Exception for onError-Processing inside Propertly Observables
*
* @author w.glanzer, 01.11.2018
*/
@SuppressWarnings("unused")
public class PropertlyReactiveException extends Exception
wglanzer marked this conversation as resolved.
Show resolved Hide resolved
{

public PropertlyReactiveException()
{
}

public PropertlyReactiveException(String message)
{
super(message);
}

public PropertlyReactiveException(String message, Throwable cause)
{
super(message, cause);
}

public PropertlyReactiveException(Throwable cause)
{
super(cause);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package de.adito.propertly.reactive.api.builder;

import io.reactivex.Observable;
import org.jetbrains.annotations.NotNull;

import java.util.Optional;

/**
* Common Interface for all Propertly-Observables constructed by PropertlyObservableBuilder
*
* @see PropertlyObservableBuilder
* @author w.glanzer, 09.11.2018
*/
public interface IBuilderObservable<V>
wglanzer marked this conversation as resolved.
Show resolved Hide resolved
{

/**
* Constructs the underlying observable.
* The Value is an Optional of the "real" value, because RxJava
* does not allow to return NULL inside one Observable.
* The returned Observable is not distincted automatically.
*
* @return the observable, not <tt>null</tt>
*/
@NotNull
Observable<Optional<V>> toObservable();

/**
* Constructs the underlying observable.
* The Value is the outboxed value of {@link IBuilderObservable##toObservable()},
* previously filtered by {@link Optional#isPresent()}.
* Use this with care - you will not be notified with NULL-Value-Changes (e.g. propertyValueChange with newValue=NULL).
* The returned Observable is not distincted automatically.
*
* @return the observable, not <tt>null</tt>
*/
@NotNull
Observable<V> toObservableUnsafe();

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
package de.adito.propertly.reactive.api.builder;

import de.adito.propertly.core.spi.*;
import io.reactivex.Observable;
import org.jetbrains.annotations.NotNull;

import java.util.*;

/**
* A PropertyListObservable is a wrapper around an Observable with
* a list of properties in it.
*
* @param <S> PropertyPitProvider all properties belong to
* @param <T> Value-Type of all properties
* @author w.glanzer, 09.11.2018
*/
public interface IBuilderPropertyListObservable<S extends IPropertyPitProvider, T> extends IBuilderObservable<List<IProperty<S, T>>>
{

/**
* Constructs an Observable that contains the values of all
* properties in this PropertyListObservable. <br>
* The resulting Observable is not distincted automatically.<br>
* All properties are observed, so the Observable will get notified if any of the
* containing properties changes.
* <b>It does not contain any NULL-Values</b>. If you have the need to, use {@link IBuilderPropertyListObservable#emitValues(boolean)}
*
* @return the Observable, not <tt>null</tt>
* @see IBuilderPropertyListObservable#emitDistinctedValues()
*/
@NotNull
default Observable<Optional<List<T>>> emitValues()
{
return emitValues(false);
}

/**
* Constructs an Observable that contains the values of all
* properties in this PropertyListObservable. <br>
* The resulting Observable is not distincted automatically. <br>
* All properties are observed, so the Observable will get notified if any of the
* containing properties changes.
*
* @param pIncludeNullValues <tt>true</tt>, if the inner list should contain NULL-Values, if a property has <tt>null</tt> as a value
* @return the Observable, not <tt>null</tt>
* @see IBuilderPropertyListObservable#emitDistinctedValues(boolean)
*/
@NotNull
Observable<Optional<List<T>>> emitValues(boolean pIncludeNullValues);
wglanzer marked this conversation as resolved.
Show resolved Hide resolved

/**
* Constructs an Observable that contains the values of all
* properties in this PropertyListObservable. <br>
* The resulting Observable <b>will be distincted automatically</b><br>
* All properties are observed, so the Observable will get notified if any of the
* containing properties changes. <br>
* <b>It does not contain any NULL-Values</b>. If you have the need to, use {@link IBuilderPropertyListObservable#emitDistinctedValues(boolean)}
*
* @return the Observable, not <tt>null</tt>
*/
@NotNull
default Observable<Optional<List<T>>> emitDistinctedValues()
{
return emitValues()
.distinctUntilChanged();
}

/**
* Constructs an Observable that contains the values of all
* properties in this PropertyListObservable. <br>
* The resulting Observable <b>will be distincted automatically</b><br>
* All properties are observed, so the Observable will get notified if any of the
* containing properties changes.
*
* @param pIncludeNullValues <tt>true</tt>, if the inner list should contain NULL-Values, if a property has <tt>null</tt> as a value
* @return the Observable, not <tt>null</tt>
*/
@NotNull
default Observable<Optional<List<T>>> emitDistinctedValues(boolean pIncludeNullValues)
{
return emitValues(pIncludeNullValues)
.distinctUntilChanged();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package de.adito.propertly.reactive.api.builder;

import de.adito.propertly.core.spi.*;
import io.reactivex.Observable;
import org.jetbrains.annotations.NotNull;

import java.util.Optional;

/**
* A BuilderPropertyObservable is a wrapper around an Observable that
* contains a single Property as value. <br>
* It will trigger, if propertyNameChanged/propertyValueChanged is fired
*
* @param <S> PropertyPitProvider this property belongs to
* @param <T> Value-Type of the property
* @author w.glanzer, 09.11.2018
*/
public interface IBuilderPropertyObservable<S extends IPropertyPitProvider, T> extends IBuilderObservable<IProperty<S, T>>
{

/**
* Constructs an Observable that contains an Optional representing
* the value of the underlying property. <br>
* The Optional will be empty, if the property has NULL as value. <br>
* This Observable is not distincted automatically.
*
* @return the Observable, not <tt>null</tt>
*/
@NotNull
Observable<Optional<T>> emitValue();

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
package de.adito.propertly.reactive.api.builder;

import de.adito.propertly.core.spi.*;
import io.reactivex.Observable;
import org.jetbrains.annotations.NotNull;

import java.util.*;

/**
* a BuilderPropertyPitObservable is a Observable that
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm missing a description of the life cycle of an Observable. When will it fail or complete.

* contains a PropertyPitProvider as value and will trigger,
* if propertyAdded/propertyOrderChanged/propertyRemoved is fired
*
* @param <P> Parent of the containing PropertyPitProvider
* @param <S> Self-Type of the containing PropertyPitProvider
* @param <T> Value-Type the containing PropertyPitProvider can contain
* @author w.glanzer, 09.11.2018
*/
public interface IBuilderPropertyPitObservable<P extends IPropertyPitProvider, S extends IPropertyPitProvider<P, S, T>, T>
extends IBuilderObservable<S>
{

/**
* Emits a single Property, identified by the given PropertyDescription. <br>
* If the property is not found in this pit, the resulting BuilderPropertyObservable will be empty. <br>
* The PropertyObservable will trigger, if the property will be added/changed/removed
*
* @param pDescription Description to identify the property to observe on
* @param <T2> Value-Type of the property and it's description
* @return the IBuilderPropertyObservable, not <tt>null</tt>
*/
@NotNull <T2> IBuilderPropertyObservable<S, T2> emitProperty(@NotNull IPropertyDescription<? super S, T2> pDescription);

/**
* Emits a child PropertyPitProvider, identified by the given PropertyDescription. <br>
* If the property is not found in this pit, the resulting BuilderPropertyPitObservable will be empty <br>
* The PropertyPitObservable will trigger, if the property that contains the searched pit will be added/changed/removed or
* the pit itself does something like propertyAdded/propertyOrderChanged/propertyRemoved.
*
* @param pDescription Description to identify the property (with an PropertyPitProvider as value-type) to observe on
* @param <S2> Value-Type of the property -> It has to be a subtype of PropertyPitProvider!
* @return IBuilderPropertyPitObservable, not <tt>null</tt>
*/
@NotNull <P2 extends IPropertyPitProvider, S2 extends IPropertyPitProvider<P2, S2, T2>, T2>
IBuilderPropertyPitObservable<P2, S2, T2> emitPropertyPit(@NotNull IPropertyDescription<? super S, S2> pDescription);

/**
* Emits all properties this PropertyPitProvider has.
*
* @return IBuilderPropertyListObservable, not <tt>null</tt>
*/
@NotNull
IBuilderPropertyListObservable<S, T> emitProperties();

/**
* Emits all values of all properties this PropertyPit has.
* It calls {@link IBuilderPropertyPitObservable#emitProperties()} first, to retrieve a list of all properties,
* and then emits their values with {@link IBuilderPropertyListObservable#emitValues()}
* The resulting Observable is not distincted automatically.
* <b>It does not contain any NULL-Values</b>. If you have the need to, use {@link IBuilderPropertyPitObservable#emitPropertyValues(boolean)}
*
* @return the Observable containing all values as list, not <tt>null</tt>
*/
@NotNull
default Observable<Optional<List<T>>> emitPropertyValues()
{
return emitProperties().emitValues();
}

/**
* Emits all values of all properties this PropertyPit has.
* It calls {@link IBuilderPropertyPitObservable#emitProperties()} first, to retrieve a list of all properties,
* and then emits their values with {@link IBuilderPropertyListObservable#emitValues()}
* The resulting Observable is not distincted automatically.
*
* @param pIncludeNullValues <tt>true</tt>, if the inner list should contain NULL-Values, if a property has <tt>null</tt> as a value
* @return the Observable containing all values as list, not <tt>null</tt>
*/
@NotNull
default Observable<Optional<List<T>>> emitPropertyValues(boolean pIncludeNullValues)
{
return emitProperties().emitValues(pIncludeNullValues);
}

}
Loading