Skip to content

Commit 6dfa02e

Browse files
author
Nicolai Parlog
committed
Implemented 'NestedLongProperty' including the builder and tests.
1 parent 51ab23d commit 6dfa02e

File tree

8 files changed

+305
-8
lines changed

8 files changed

+305
-8
lines changed

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import javafx.beans.property.DoubleProperty;
66
import javafx.beans.property.FloatProperty;
77
import javafx.beans.property.IntegerProperty;
8+
import javafx.beans.property.LongProperty;
89
import javafx.beans.property.Property;
910
import javafx.beans.value.ObservableValue;
1011

@@ -97,6 +98,22 @@ public IntegerPropertyNestingBuilder nestIntegerProperty(NestingStep<T, IntegerP
9798
return new IntegerPropertyNestingBuilder(this, nestingStep);
9899
}
99100

101+
/**
102+
* Returns a builder for nestings whose inner observable is a {@link LongProperty}. The created nestings depend on
103+
* this builder's outer observable and nesting steps and adds the specified step as the next one.
104+
*
105+
* @param nestingStep
106+
* the function which performs the nesting step from one observable to the next
107+
* @return a {@link LongPropertyNestingBuilder} which builds a nesting from this builder's settings and the
108+
* specified nesting steps
109+
* @throws NullPointerException
110+
* if the specified function is null
111+
*/
112+
public LongPropertyNestingBuilder nestLongProperty(NestingStep<T, LongProperty> nestingStep) {
113+
Objects.requireNonNull(nestingStep, "The argument 'nestingStep' must not be null.");
114+
return new LongPropertyNestingBuilder(this, nestingStep);
115+
}
116+
100117
/**
101118
* Returns a builder for nestings whose inner observable is a {@link FloatProperty}. The created nestings depend on
102119
* this builder's outer observable and nesting steps and adds the specified step as the next one.
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
package org.codefx.libfx.nesting;
2+
3+
import javafx.beans.property.LongProperty;
4+
5+
import org.codefx.libfx.nesting.property.NestedLongProperty;
6+
import org.codefx.libfx.nesting.property.NestedLongPropertyBuilder;
7+
8+
/**
9+
* A builder for all kinds of nested functionality whose innermost value is held by a {@link LongProperty}.
10+
*/
11+
public class LongPropertyNestingBuilder extends AbstractNestingBuilder<Number, LongProperty> {
12+
13+
// #region CONSTRUCTION
14+
15+
/**
16+
* Creates a new nesting builder which acts as a nested builder.
17+
*
18+
* @param <P>
19+
* the type the previous builder wraps
20+
* @param previousNestedBuilder
21+
* the previous builder
22+
* @param nestingStep
23+
* the function which performs the nesting step from one observable to the next
24+
*/
25+
<P> LongPropertyNestingBuilder(
26+
AbstractNestingBuilder<P, ?> previousNestedBuilder,
27+
NestingStep<P, LongProperty> nestingStep) {
28+
29+
super(previousNestedBuilder, nestingStep);
30+
}
31+
32+
//#end CONSTRUCTION
33+
34+
// #region BUILD
35+
36+
/**
37+
* Creates a nested property from this builder's settings. This method can be called arbitrarily often and each call
38+
* returns a new instance.
39+
*
40+
* @return a new {@link NestedLongProperty} instance with no owning bean and no name
41+
*/
42+
public NestedLongProperty buildProperty() {
43+
Nesting<LongProperty> nesting = buildNesting();
44+
return NestedLongPropertyBuilder.forNesting(nesting).build();
45+
}
46+
47+
/**
48+
* Returns a nested object property builder which can be used to define the new property's attributes before
49+
* building it.
50+
*
51+
* @return a new instance of {@link NestedLongPropertyBuilder}
52+
*/
53+
public NestedLongPropertyBuilder buildPropertyWithBuilder() {
54+
Nesting<LongProperty> nesting = buildNesting();
55+
return NestedLongPropertyBuilder.forNesting(nesting);
56+
}
57+
58+
//#end BUILD
59+
}
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.LongProperty;
7+
import javafx.beans.property.Property;
8+
import javafx.beans.property.ReadOnlyBooleanProperty;
9+
import javafx.beans.property.SimpleBooleanProperty;
10+
import javafx.beans.property.SimpleLongProperty;
11+
12+
import org.codefx.libfx.nesting.Nesting;
13+
14+
/**
15+
* A {@link LongProperty} which also implements {@link NestedProperty}.
16+
*/
17+
public class NestedLongProperty extends SimpleLongProperty 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+
NestedLongProperty(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.LongProperty;
4+
5+
import org.codefx.libfx.nesting.Nesting;
6+
7+
/**
8+
* A builder for a {@link NestedLongProperty} which is bound to the {@link Nesting#innerObservable() innerObservable} of
9+
* a {@link Nesting}.
10+
*/
11+
public class NestedLongPropertyBuilder extends AbstractNestedPropertyBuilder<LongProperty, NestedLongProperty> {
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 NestedLongPropertyBuilder(Nesting<LongProperty> 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 NestedLongPropertyBuilder}
31+
*/
32+
public static NestedLongPropertyBuilder forNesting(Nesting<LongProperty> nesting) {
33+
return new NestedLongPropertyBuilder(nesting);
34+
}
35+
36+
//#end CONSTRUCTION
37+
38+
// #region METHODS
39+
40+
@Override
41+
public NestedLongProperty build() {
42+
return new NestedLongProperty(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.LongProperty;
4+
import javafx.beans.property.SimpleLongProperty;
5+
6+
import org.codefx.libfx.nesting.Nesting;
7+
8+
/**
9+
* Abstract superclass to tests for {@link NestedLongProperty NestedLongProperty} which only leaves the creation of the
10+
* tested properties (by {@link #createNestedPropertyFromNesting(Nesting)}) to the subclasses.
11+
*/
12+
public abstract class AbstractNestedLongPropertyTest extends AbstractNestedPropertyTest<Number, LongProperty> {
13+
14+
/**
15+
* The last value returned by {@link #createNewValue()}.
16+
*/
17+
private long lastValue = 0;
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 LongProperty createNewObservableWithValue(Number value) {
32+
return new SimpleLongProperty(value.longValue());
33+
}
34+
35+
@Override
36+
protected LongProperty createNewObservableWithSomeValue() {
37+
return createNewObservableWithValue(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.LongProperty;
4+
import javafx.beans.property.SimpleLongProperty;
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 NestedLongPropertyBuilder}.
14+
*/
15+
@RunWith(Suite.class)
16+
@SuiteClasses({
17+
NestedLongPropertyBuilderTest.AbstractBuilderContract.class,
18+
NestedLongPropertyBuilderTest.CreatedProperties.class,
19+
})
20+
public class NestedLongPropertyBuilderTest {
21+
22+
/**
23+
* Tests whether the builder fulfills the contract defined by {@link AbstractNestedPropertyBuilder}.
24+
*/
25+
public static class AbstractBuilderContract
26+
extends AbstractNestedPropertyBuilderTest<LongProperty, NestedLongProperty> {
27+
28+
@Override
29+
protected AbstractNestedPropertyBuilder<LongProperty, NestedLongProperty> createBuilder() {
30+
LongProperty innerObservable = new SimpleLongProperty(0);
31+
EditableNesting<LongProperty> nesting = EditableNesting.createWithInnerObservable(innerObservable);
32+
return NestedLongPropertyBuilder.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 AbstractNestedLongPropertyTest {
41+
42+
@Override
43+
protected NestedProperty<Number> createNestedPropertyFromNesting(Nesting<LongProperty> nesting) {
44+
// use the builder to create the property
45+
NestedLongPropertyBuilder builder = NestedLongPropertyBuilder.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.LongProperty;
4+
5+
import org.codefx.libfx.nesting.Nesting;
6+
7+
/**
8+
* Tests the class {@link NestedLongProperty}.
9+
*/
10+
public class NestedLongPropertyTest extends AbstractNestedLongPropertyTest {
11+
12+
@Override
13+
protected NestedProperty<Number> createNestedPropertyFromNesting(Nesting<LongProperty> nesting) {
14+
return new NestedLongProperty(nesting, null, null);
15+
}
16+
17+
}

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

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

0 commit comments

Comments
 (0)