Skip to content

Commit

Permalink
Fix bug with missing nullables
Browse files Browse the repository at this point in the history
  • Loading branch information
Emil Forslund committed Feb 1, 2016
1 parent 1eaeeea commit 0b65cef
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 19 deletions.
Expand Up @@ -57,6 +57,7 @@
import javafx.beans.property.SimpleObjectProperty;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;
import javafx.beans.value.ChangeListener;
import static javafx.collections.FXCollections.observableMap;
import static javafx.collections.FXCollections.unmodifiableObservableMap;
import javafx.collections.ListChangeListener;
Expand Down Expand Up @@ -300,12 +301,17 @@ protected final AbstractDocumentProperty createChild(Speedment speedment, String
* @return the same property but with listener attached
*/
private <T> Property<T> prepare(String key, Property<T> property, T value) {
property.addListener((ob, o, n) -> {
final ChangeListener<T> change = (ob, o, n) -> {
config.put(key, n);
invalidate();
});
};

property.setValue(value);
property.addListener(change);

if (value != null) {
change.changed(property, null, value);
}

return property;
}
Expand Down
Expand Up @@ -97,22 +97,15 @@ public static void merge(
// property.
if (!wasChild) {

if (setProperty(String.class, proposedValue, casted -> existing.stringPropertyOf(key, () -> casted))
|| setProperty(Boolean.class, proposedValue, casted -> existing.booleanPropertyOf(key, () -> casted))
|| setProperty(boolean.class, proposedValue, casted -> existing.booleanPropertyOf(key, () -> casted))
|| setProperty(Integer.class, proposedValue, casted -> existing.integerPropertyOf(key, () -> casted))
|| setProperty(int.class, proposedValue, casted -> existing.integerPropertyOf(key, () -> casted))
|| setProperty(Long.class, proposedValue, casted -> existing.longPropertyOf(key, () -> casted))
|| setProperty(long.class, proposedValue, casted -> existing.longPropertyOf(key, () -> casted))
|| setProperty(Float.class, proposedValue, casted -> existing.doublePropertyOf(key, () -> casted))
|| setProperty(float.class, proposedValue, casted -> existing.doublePropertyOf(key, () -> casted))
|| setProperty(Double.class, proposedValue, casted -> existing.doublePropertyOf(key, () -> casted))
|| setProperty(double.class, proposedValue, casted -> existing.doublePropertyOf(key, () -> casted))
|| setProperty(Byte.class, proposedValue, casted -> existing.doublePropertyOf(key, () -> casted))
|| setProperty(byte.class, proposedValue, casted -> existing.doublePropertyOf(key, () -> casted))
|| setProperty(Short.class, proposedValue, casted -> existing.doublePropertyOf(key, () -> casted))
|| setProperty(short.class, proposedValue, casted -> existing.doublePropertyOf(key, () -> casted))
|| setProperty(Object.class, proposedValue, casted -> existing.objectPropertyOf(key, (Class<Object>) casted.getClass(), () -> casted))) {}
if (setPropertyIf(String.class, proposedValue, casted -> existing.stringPropertyOf(key, () -> casted))
|| setPropertyIf(Boolean.class, proposedValue, casted -> existing.booleanPropertyOf(key, () -> casted))
|| setPropertyIf(Integer.class, proposedValue, casted -> existing.integerPropertyOf(key, () -> casted))
|| setPropertyIf(Long.class, proposedValue, casted -> existing.longPropertyOf(key, () -> casted))
|| setPropertyIf(Float.class, proposedValue, casted -> existing.doublePropertyOf(key, () -> casted))
|| setPropertyIf(Double.class, proposedValue, casted -> existing.doublePropertyOf(key, () -> casted))
|| setPropertyIf(Byte.class, proposedValue, casted -> existing.doublePropertyOf(key, () -> casted))
|| setPropertyIf(Short.class, proposedValue, casted -> existing.doublePropertyOf(key, () -> casted))
|| setPropertyIf(Object.class, proposedValue, casted -> existing.objectPropertyOf(key, (Class<Object>) casted.getClass(), () -> casted))) {}
else {
throw new SpeedmentException(
"Property was not of any known type."
Expand Down Expand Up @@ -233,7 +226,7 @@ private static boolean isSame(Document first, Document second) {
* @param propertyGetter getter for the property
* @return {@code true} if a value was set, else {@code false}
*/
private static <T, P extends Property<? super T>> boolean setProperty(
private static <T, P extends Property<? super T>> boolean setPropertyIf(
Class<T> type,
Object value,
Function<T, P> propertyGetter) {
Expand Down

0 comments on commit 0b65cef

Please sign in to comment.