Skip to content

Commit 71aa2f9

Browse files
author
Nicolai Parlog
committed
Implemented 'NestedFloatProperty' including the builder and tests.
1 parent eafdfa4 commit 71aa2f9

8 files changed

+304
-6
lines changed

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import java.util.Objects;
44

55
import javafx.beans.property.DoubleProperty;
6+
import javafx.beans.property.FloatProperty;
67
import javafx.beans.property.IntegerProperty;
78
import javafx.beans.property.Property;
89
import javafx.beans.value.ObservableValue;
@@ -96,6 +97,22 @@ public IntegerPropertyNestingBuilder nestIntegerProperty(NestingStep<T, IntegerP
9697
return new IntegerPropertyNestingBuilder(this, nestingStep);
9798
}
9899

100+
/**
101+
* Returns a builder for nestings whose inner observable is a {@link FloatProperty}. The created nestings depend on
102+
* this builder's outer observable and nesting steps and adds the specified step as the next one.
103+
*
104+
* @param nestingStep
105+
* the function which performs the nesting step from one observable to the next
106+
* @return an {@link FloatPropertyNestingBuilder} which builds a nesting from this builder's settings and the
107+
* specified nesting steps
108+
* @throws NullPointerException
109+
* if the specified function is null
110+
*/
111+
public FloatPropertyNestingBuilder nestFloatProperty(NestingStep<T, FloatProperty> nestingStep) {
112+
Objects.requireNonNull(nestingStep, "The argument 'nestingStep' must not be null.");
113+
return new FloatPropertyNestingBuilder(this, nestingStep);
114+
}
115+
99116
/**
100117
* Returns a builder for nestings whose inner observable is a {@link DoubleProperty}. The created nestings depend on
101118
* this builder's outer observable and nesting steps and adds the specified step as the next one.
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
package org.codefx.libfx.nesting;
2+
3+
import javafx.beans.property.FloatProperty;
4+
5+
import org.codefx.libfx.nesting.property.NestedFloatProperty;
6+
import org.codefx.libfx.nesting.property.NestedFloatPropertyBuilder;
7+
import org.codefx.libfx.nesting.property.NestedObjectPropertyBuilder;
8+
9+
/**
10+
* A builder for all kinds of nested functionality whose innermost value is held by a {@link FloatProperty}.
11+
*/
12+
public class FloatPropertyNestingBuilder extends AbstractNestingBuilder<Number, FloatProperty> {
13+
14+
// #region CONSTRUCTION
15+
16+
/**
17+
* Creates a new nesting builder which acts as a nested builder.
18+
*
19+
* @param <P>
20+
* the type the previous builder wraps
21+
* @param previousNestedBuilder
22+
* the previous builder
23+
* @param nestingStep
24+
* the function which performs the nesting step from one observable to the next
25+
*/
26+
<P> FloatPropertyNestingBuilder(
27+
AbstractNestingBuilder<P, ?> previousNestedBuilder,
28+
NestingStep<P, FloatProperty> nestingStep) {
29+
30+
super(previousNestedBuilder, nestingStep);
31+
}
32+
33+
//#end CONSTRUCTION
34+
35+
// #region BUILD
36+
37+
/**
38+
* Creates a nested property from this builder's settings. This method can be called arbitrarily often and each call
39+
* returns a new instance.
40+
*
41+
* @return a new {@link NestedFloatProperty} instance with no owning bean and no name
42+
*/
43+
public NestedFloatProperty buildProperty() {
44+
Nesting<FloatProperty> nesting = buildNesting();
45+
return NestedFloatPropertyBuilder.forNesting(nesting).build();
46+
}
47+
48+
/**
49+
* Returns a nested object property builder which can be used to define the new property's attributes before
50+
* building it.
51+
*
52+
* @return a new instance of {@link NestedObjectPropertyBuilder}
53+
*/
54+
public NestedFloatPropertyBuilder buildPropertyWithBuilder() {
55+
Nesting<FloatProperty> nesting = buildNesting();
56+
return NestedFloatPropertyBuilder.forNesting(nesting);
57+
}
58+
59+
//#end BUILD
60+
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
package org.codefx.libfx.nesting.property;
2+
3+
import java.util.Objects;
4+
5+
import javafx.beans.property.BooleanProperty;
6+
import javafx.beans.property.FloatProperty;
7+
import javafx.beans.property.Property;
8+
import javafx.beans.property.ReadOnlyBooleanProperty;
9+
import javafx.beans.property.SimpleBooleanProperty;
10+
import javafx.beans.property.SimpleFloatProperty;
11+
12+
import org.codefx.libfx.nesting.Nesting;
13+
14+
/**
15+
* A {@link FloatProperty} which also implements {@link NestedProperty}.
16+
*/
17+
public class NestedFloatProperty extends SimpleFloatProperty implements NestedProperty<Number> {
18+
19+
// #region PROPERTIES
20+
21+
/**
22+
* The property indicating whether the nesting's inner observable is currently null.
23+
*/
24+
private final BooleanProperty innerObservableNull;
25+
26+
//#end PROPERTIES
27+
28+
// #region CONSTUCTION
29+
30+
/**
31+
* Creates a new property. Except {@code nesting} all arguments can be null.
32+
*
33+
* @param nesting
34+
* the nesting this property is based on
35+
* @param bean
36+
* the bean which owns this property; can be null
37+
* @param name
38+
* this property's name; can be null
39+
*/
40+
NestedFloatProperty(Nesting<? extends Property<Number>> nesting, Object bean, String name) {
41+
super(bean, name);
42+
Objects.requireNonNull(nesting, "The argument 'nesting' must not be null.");
43+
this.innerObservableNull = new SimpleBooleanProperty(this, "innerObservableNull");
44+
45+
PropertyToNestingBinding.bind(this, isNull -> innerObservableNull.set(isNull), nesting);
46+
}
47+
48+
//#end CONSTUCTION
49+
50+
// #region IMPLEMENTATION OF 'NestedProperty'
51+
52+
@Override
53+
public ReadOnlyBooleanProperty innerObservableNull() {
54+
return innerObservableNull;
55+
}
56+
57+
@Override
58+
public boolean isInnerObservableNull() {
59+
return innerObservableNull.get();
60+
}
61+
62+
//#end IMPLEMENTATION OF 'NestedProperty'
63+
64+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package org.codefx.libfx.nesting.property;
2+
3+
import javafx.beans.property.FloatProperty;
4+
5+
import org.codefx.libfx.nesting.Nesting;
6+
7+
/**
8+
* A builder for a {@link NestedFloatProperty} which is bound to the {@link Nesting#innerObservable() innerObservable}
9+
* of a {@link Nesting}.
10+
*/
11+
public class NestedFloatPropertyBuilder extends AbstractNestedPropertyBuilder<FloatProperty, NestedFloatProperty> {
12+
13+
// #region CONSTRUCTION
14+
15+
/**
16+
* Creates a new builder which uses the specified nesting.
17+
*
18+
* @param nesting
19+
* the nesting which will be used for all nested properties
20+
*/
21+
private NestedFloatPropertyBuilder(Nesting<FloatProperty> nesting) {
22+
super(nesting);
23+
}
24+
25+
/**
26+
* Creates a new builder which uses the specified nesting.
27+
*
28+
* @param nesting
29+
* the nesting which will be used for all nested properties
30+
* @return a new instance of {@link NestedObjectPropertyBuilder}
31+
*/
32+
public static NestedFloatPropertyBuilder forNesting(Nesting<FloatProperty> nesting) {
33+
return new NestedFloatPropertyBuilder(nesting);
34+
}
35+
36+
//#end CONSTRUCTION
37+
38+
// #region METHODS
39+
40+
@Override
41+
public NestedFloatProperty build() {
42+
return new NestedFloatProperty(getNesting(), getBean(), getName());
43+
}
44+
45+
//#end METHODS
46+
47+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package org.codefx.libfx.nesting.property;
2+
3+
import javafx.beans.property.FloatProperty;
4+
import javafx.beans.property.SimpleFloatProperty;
5+
6+
import org.codefx.libfx.nesting.Nesting;
7+
8+
/**
9+
* Abstract superclass to tests for {@link NestedFloatProperty NestedFloatProperty} which only leaves the creation of
10+
* the tested properties (by {@link #createNestedPropertyFromNesting(Nesting)}) to the subclasses.
11+
*/
12+
public abstract class AbstractNestedFloatPropertyTest extends AbstractNestedPropertyTest<Number, FloatProperty> {
13+
14+
/**
15+
* The next value returned by {@link #createNewValue()}.
16+
*/
17+
private float lastValue = 1.5f;
18+
19+
@Override
20+
protected boolean allowsNullValues() {
21+
return false;
22+
}
23+
24+
@Override
25+
protected Number createNewValue() {
26+
lastValue += 1;
27+
return lastValue;
28+
}
29+
30+
@Override
31+
protected FloatProperty createNewObservableWithValue(Number value) {
32+
return new SimpleFloatProperty(value.floatValue());
33+
}
34+
35+
@Override
36+
protected FloatProperty createNewObservableWithSomeValue() {
37+
return createNewObservableWithValue(0.0);
38+
}
39+
40+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
package org.codefx.libfx.nesting.property;
2+
3+
import javafx.beans.property.FloatProperty;
4+
import javafx.beans.property.SimpleFloatProperty;
5+
6+
import org.codefx.libfx.nesting.Nesting;
7+
import org.codefx.libfx.nesting.testhelper.NestingAccess.EditableNesting;
8+
import org.junit.runner.RunWith;
9+
import org.junit.runners.Suite;
10+
import org.junit.runners.Suite.SuiteClasses;
11+
12+
/**
13+
* Tests the class {@link NestedFloatPropertyBuilder}.
14+
*/
15+
@RunWith(Suite.class)
16+
@SuiteClasses({
17+
NestedFloatPropertyBuilderTest.AbstractBuilderContract.class,
18+
NestedFloatPropertyBuilderTest.CreatedProperties.class,
19+
})
20+
public class NestedFloatPropertyBuilderTest {
21+
22+
/**
23+
* Tests whether the builder fulfills the contract defined by {@link AbstractNestedPropertyBuilder}.
24+
*/
25+
public static class AbstractBuilderContract
26+
extends AbstractNestedPropertyBuilderTest<FloatProperty, NestedFloatProperty> {
27+
28+
@Override
29+
protected AbstractNestedPropertyBuilder<FloatProperty, NestedFloatProperty> createBuilder() {
30+
FloatProperty innerObservable = new SimpleFloatProperty(0);
31+
EditableNesting<FloatProperty> nesting = EditableNesting.createWithInnerObservable(innerObservable);
32+
return NestedFloatPropertyBuilder.forNesting(nesting);
33+
}
34+
35+
}
36+
37+
/**
38+
* Uses the builder to create properties which are then tested.
39+
*/
40+
public static class CreatedProperties extends AbstractNestedFloatPropertyTest {
41+
42+
@Override
43+
protected NestedProperty<Number> createNestedPropertyFromNesting(Nesting<FloatProperty> nesting) {
44+
// use the builder to create the property
45+
NestedFloatPropertyBuilder builder = NestedFloatPropertyBuilder.forNesting(nesting);
46+
return builder.build();
47+
}
48+
49+
}
50+
51+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package org.codefx.libfx.nesting.property;
2+
3+
import javafx.beans.property.FloatProperty;
4+
5+
import org.codefx.libfx.nesting.Nesting;
6+
7+
/**
8+
* Tests the class {@link NestedFloatProperty}.
9+
*/
10+
public class NestedFloatPropertyTest extends AbstractNestedFloatPropertyTest {
11+
12+
@Override
13+
protected NestedProperty<Number> createNestedPropertyFromNesting(Nesting<FloatProperty> nesting) {
14+
return new NestedFloatProperty(nesting, null, null);
15+
}
16+
17+
}

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

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,14 @@
99
*/
1010
@RunWith(Suite.class)
1111
@SuiteClasses({
12-
NestedDoublePropertyTest.class,
13-
NestedDoublePropertyBuilderTest.class,
14-
NestedIntegerPropertyTest.class,
15-
NestedIntegerPropertyBuilderTest.class,
16-
NestedObjectPropertyTest.class,
17-
NestedObjectPropertyBuilderTest.class,
12+
NestedFloatPropertyTest.class,
13+
NestedFloatPropertyBuilderTest.class,
14+
NestedDoublePropertyTest.class,
15+
NestedDoublePropertyBuilderTest.class,
16+
NestedIntegerPropertyTest.class,
17+
NestedIntegerPropertyBuilderTest.class,
18+
NestedObjectPropertyTest.class,
19+
NestedObjectPropertyBuilderTest.class,
1820
})
1921
public class _AllNestedPropertyTests {
2022
// no body needed

0 commit comments

Comments
 (0)