Skip to content

Commit 78d26e6

Browse files
author
Nicolai Parlog
committed
Minor, non-functional changes.
1 parent d63d14f commit 78d26e6

File tree

9 files changed

+80
-35
lines changed

9 files changed

+80
-35
lines changed

demo/org/codefx/libfx/nesting/NestingDemo.java

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import javafx.beans.property.SimpleDoubleProperty;
66
import javafx.beans.property.SimpleObjectProperty;
77

8-
import org.codefx.libfx.nesting.Nestings;
98
import org.codefx.libfx.nesting.property.NestedProperty;
109

1110
/**
@@ -28,7 +27,7 @@ public class NestingDemo {
2827
* Creates a new demo.
2928
*/
3029
private NestingDemo() {
31-
this.currentEmployee = new SimpleObjectProperty<>(new Employee(54_000));
30+
this.currentEmployee = new SimpleObjectProperty<>(new Employee(54000));
3231
}
3332

3433
/**
@@ -55,8 +54,35 @@ private void demoNestedProperties() {
5554
.nest(employee -> employee.salaryProperty())
5655
.buildProperty();
5756

57+
System.out
58+
.println("Check that the object hierarchy's value is initially the same as the nested property's value.");
59+
outputSalaryValues(currentEmployee, currentEmployeesSalary);
60+
61+
System.out
62+
.println("Check that when the object hierarchy's value is changed, the nested property's value changes as well.");
63+
currentEmployee.getValue().salaryProperty().setValue(58000);
64+
outputSalaryValues(currentEmployee, currentEmployeesSalary);
65+
66+
System.out
67+
.println("Check that when the nested property's value is changed, the object hierarchy's value changes as well.");
68+
currentEmployeesSalary.setValue(62000);
69+
outputSalaryValues(currentEmployee, currentEmployeesSalary);
70+
}
71+
72+
/**
73+
* Outputs the salary of both specified properties.
74+
*
75+
* @param currentEmployee
76+
* the property holding the current employee; the printed value is accessed by moving through the object
77+
* hierarchy
78+
* @param currentEmployeesSalary
79+
* the nested property holding the current employee's salary; the printed value is accessed by simply
80+
* getting it
81+
*/
82+
private static void outputSalaryValues(Property<Employee> currentEmployee, Property<Number> currentEmployeesSalary) {
5883
System.out.println("Salary - object hierarchy: " + currentEmployee.getValue().salaryProperty().getValue());
5984
System.out.println("Salary - nested property: " + currentEmployeesSalary.getValue());
85+
System.out.println();
6086
}
6187

6288
//#end DEMOS

src/org/codefx/libfx/nesting/Nestings.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@
1010
* outer -> nested -> inner (which is also nested) <br>
1111
* level 0 -> level 1 -> ...
1212
* <p>
13-
* TODO: nomenclature: "observable" = "observable value" TODO: fix names of all generics to some common schema like
14-
* O(outer) and N(ested)
13+
* TODO: nomenclature: "observable" = "observable value"
14+
* <p>
15+
* TODO: fix names of all generics to some common schema like O(outer) and N(ested)
1516
* <p>
1617
* TODO examples; differences between builder types
1718
* <p>

test/org/codefx/libfx/nesting/AbstractDeepNestingTest.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import javafx.beans.Observable;
77
import javafx.beans.value.ObservableValue;
88

9-
import org.codefx.libfx.nesting.Nesting;
109
import org.junit.Test;
1110

1211
/**
@@ -115,14 +114,14 @@ public void testWhenSettingOuterValueToNull() {
115114
protected enum Level {
116115

117116
/**
118-
* A level below the outer level.
117+
* The outer level.
119118
*/
120-
NESTED,
119+
OUTER,
121120

122121
/**
123-
* The outer level.
122+
* A level below the outer level.
124123
*/
125-
OUTER,
124+
NESTED,
126125
}
127126

128127
/**

test/org/codefx/libfx/nesting/AbstractDeepNestingTestForDefaultNesting.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import org.codefx.libfx.nesting.testhelper.OuterValue;
1111

1212
/**
13-
* Superclass for tests for deep nestings which are based on the nesting hierarchy in the package
13+
* Abstract superclass to tests for deep nestings which are based on the nesting hierarchy in the package
1414
* {@link org.codefx.libfx.nesting.testhelper testhelper}.
1515
* <p>
1616
* It leaves {@link #createNewNestingFromOuterObservable(Observable)} and {@link #getInnerObservable(Observable)}

test/org/codefx/libfx/nesting/AbstractNestingTest.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import javafx.beans.Observable;
66
import javafx.beans.value.ObservableValue;
77

8-
import org.codefx.libfx.nesting.Nesting;
98
import org.junit.Before;
109
import org.junit.Test;
1110

test/org/codefx/libfx/nesting/AbstractShallowNestingTest.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
package org.codefx.libfx.nesting;
22

3-
import org.codefx.libfx.nesting.Nesting;
4-
import org.codefx.libfx.nesting.ShallowNesting;
5-
63
import javafx.beans.Observable;
74

85
/**
9-
* Abstract superclass tests of {@link ShallowNesting ShallowNestings}. Implements all abstract methods from
6+
* Abstract superclass to tests of {@link ShallowNesting ShallowNestings}. Implements all abstract methods from
107
* {@link AbstractNestingTest} except the creation of the nesting.
118
*
129
* @param <O>

test/org/codefx/libfx/nesting/ShallowNestingTest.java

Lines changed: 36 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,9 @@
55
import javafx.beans.Observable;
66
import javafx.beans.property.Property;
77
import javafx.beans.property.SimpleObjectProperty;
8+
import javafx.beans.value.ChangeListener;
89
import javafx.beans.value.ObservableValue;
910

10-
import org.codefx.libfx.nesting.Nesting;
11-
import org.codefx.libfx.nesting.ShallowNesting;
1211
import org.codefx.libfx.nesting.testhelper.SomeValue;
1312
import org.junit.runner.RunWith;
1413
import org.junit.runners.Suite;
@@ -19,9 +18,9 @@
1918
*/
2019
@RunWith(Suite.class)
2120
@SuiteClasses({
22-
ShallowNestingTest.OnObservable.class,
23-
ShallowNestingTest.OnObservableValue.class,
24-
ShallowNestingTest.OnProperty.class,
21+
ShallowNestingTest.OnObservable.class,
22+
ShallowNestingTest.OnObservableValue.class,
23+
ShallowNestingTest.OnProperty.class,
2524
})
2625
public class ShallowNestingTest {
2726

@@ -57,15 +56,43 @@ public void removeListener(InvalidationListener arg0) {
5756
* Tests a {@link ShallowNesting} based on an {@link ObservableValue}.
5857
*/
5958
public static class OnObservableValue
60-
extends AbstractShallowNestingTest<ObservableValue<SomeValue>> {
59+
extends AbstractShallowNestingTest<ObservableValue<SomeValue>> {
6160

6261
@Override
6362
protected ObservableValue<SomeValue> createNewNestingHierarchy() {
63+
final SomeValue someValue = new SomeValue();
64+
6465
/*
65-
* TODO check whether it would be better to return an implementation of 'ObservableValue' which does not
66-
* also implement other interfaces.
66+
* To return an implementation of the 'ObservableValue' interface which does not also implement other
67+
* interfaces, create an anonymous class. It is assumed that listeners are neither added nor removed.
6768
*/
68-
return new SimpleObjectProperty<SomeValue>(new SomeValue());
69+
return new ObservableValue<SomeValue>() {
70+
71+
@Override
72+
public void addListener(InvalidationListener listener) {
73+
fail();
74+
}
75+
76+
@Override
77+
public void removeListener(InvalidationListener listener) {
78+
fail();
79+
}
80+
81+
@Override
82+
public void addListener(ChangeListener<? super SomeValue> listener) {
83+
fail();
84+
}
85+
86+
@Override
87+
public void removeListener(ChangeListener<? super SomeValue> listener) {
88+
fail();
89+
}
90+
91+
@Override
92+
public SomeValue getValue() {
93+
return someValue;
94+
}
95+
};
6996
}
7097
}
7198

test/org/codefx/libfx/nesting/property/NestedIntegerPropertyBuilderTest.java

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,6 @@
44
import javafx.beans.property.SimpleIntegerProperty;
55

66
import org.codefx.libfx.nesting.Nesting;
7-
import org.codefx.libfx.nesting.property.AbstractNestedPropertyBuilder;
8-
import org.codefx.libfx.nesting.property.NestedIntegerProperty;
9-
import org.codefx.libfx.nesting.property.NestedIntegerPropertyBuilder;
10-
import org.codefx.libfx.nesting.property.NestedProperty;
117
import org.codefx.libfx.nesting.testhelper.NestingAccess.EditableNesting;
128
import org.junit.runner.RunWith;
139
import org.junit.runners.Suite;
@@ -18,16 +14,16 @@
1814
*/
1915
@RunWith(Suite.class)
2016
@SuiteClasses({
21-
NestedIntegerPropertyBuilderTest.AbstractBuilderContract.class,
22-
NestedIntegerPropertyBuilderTest.CreatedProperties.class,
17+
NestedIntegerPropertyBuilderTest.AbstractBuilderContract.class,
18+
NestedIntegerPropertyBuilderTest.CreatedProperties.class,
2319
})
2420
public class NestedIntegerPropertyBuilderTest {
2521

2622
/**
2723
* Tests whether the builder fulfills the contract defined by {@link AbstractNestedPropertyBuilder}.
2824
*/
2925
public static class AbstractBuilderContract
30-
extends AbstractNestedPropertyBuilderTest<IntegerProperty, NestedIntegerProperty> {
26+
extends AbstractNestedPropertyBuilderTest<IntegerProperty, NestedIntegerProperty> {
3127

3228
@Override
3329
protected AbstractNestedPropertyBuilder<IntegerProperty, NestedIntegerProperty> createBuilder() {

test/org/codefx/libfx/nesting/testhelper/NestingAccess.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
import org.codefx.libfx.nesting.Nesting;
1414

1515
/**
16-
* Provides simple usability functions to access an outer observables nesting hierarchy in a more readable way. To that
17-
* end many arguments and return types can be null (see method comments).
16+
* Provides simple usability functions to access an outer observable's nesting hierarchy in a more readable way. To that
17+
* end, many arguments and return types can be null (see method comments).
1818
*/
1919
public class NestingAccess {
2020

@@ -25,8 +25,8 @@ public class NestingAccess {
2525
* the type of observable the nesting contains
2626
* @param nesting
2727
* the nesting whose observable will be returned
28-
* @return {@link Nesting#innerObservable()}.{@link ReadOnlyProperty#getValue() getValue()}.{@link Optional#get()};
29-
* can be null
28+
* @return {@link Nesting#innerObservable()}.{@link ReadOnlyProperty#getValue() getValue()}.{@link Optional#get()
29+
* get()}; can be null
3030
*/
3131
public static <O extends Observable> O getNestingObservable(Nesting<O> nesting) {
3232
Objects.requireNonNull(nesting, "The argument 'nesting' must not be null.");

0 commit comments

Comments
 (0)