Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
927e975
Updating out deprecated blocks in graddle file
Aug 4, 2025
3cb558a
Updating the publication for 8+ version
Symeon94 Aug 4, 2025
833b137
Including the correct version of JavaFX in the build
Symeon94 Aug 4, 2025
f169edb
Mapped list with index
Symeon94 Aug 4, 2025
f5130a1
Removing item added by mistake
Symeon94 Aug 4, 2025
a927fd6
Adding tests for lazy evaluation and removing getSource() to use the …
Symeon94 Aug 4, 2025
d7d7393
Issue with outdated 'runtime' and missing JavaFX dependencies for rea…
Symeon94 Aug 4, 2025
8ca155a
Issue with outdated 'runtime' and missing JavaFX dependencies for rea…
Symeon94 Aug 4, 2025
6d0bc07
Javadoc fails building due to h2 title being used while parent is h3.…
Symeon94 Aug 4, 2025
120acab
Issue with build due to likely bug in the builder library. Upgrading …
Symeon94 Aug 4, 2025
411f081
merge
Symeon94 Aug 4, 2025
cf251ac
merge
Symeon94 Aug 8, 2025
a756475
merge
Symeon94 Aug 8, 2025
c5ccdad
merge
Symeon94 Aug 8, 2025
810958b
Using a secondary constructor instead of inheritance
Symeon94 Aug 8, 2025
95e7798
Removing generated gradle files
Symeon94 Aug 8, 2025
17e668d
Adding some comments to differentiate between the two methods
Symeon94 Aug 8, 2025
3764deb
Cosmetic cleanup
Symeon94 Aug 8, 2025
01a43d4
fixing issue when you are removing multiple items at the same time
Symeon94 Aug 9, 2025
431275d
Added unit tests
Symeon94 Aug 11, 2025
6fbb8a2
Forgot to remove a print
Symeon94 Aug 11, 2025
9255efa
Reversing to the original method to remove elements
Symeon94 Aug 11, 2025
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@ build/
.project
.settings/
.idea/
gradle/
gradlew
gradle.bat
2 changes: 1 addition & 1 deletion reactfx/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ group = 'org.reactfx'

dependencies {
// Test dependencies
testImplementation group: 'junit', name: 'junit', version: '4.12'
testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-api', version: '5.13.4'
testImplementation group: 'org.hamcrest', name: 'hamcrest-library', version: '1.3'
testImplementation group: 'org.junit.contrib', name: 'junit-theories', version: '4.12'
testImplementation group: 'com.pholser', name: 'junit-quickcheck-core', version: '0.4'
Expand Down
19 changes: 19 additions & 0 deletions reactfx/src/main/java/org/reactfx/collection/LiveList.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.util.Collections;
import java.util.List;
import java.util.NoSuchElementException;
import java.util.function.BiFunction;
import java.util.function.BinaryOperator;
import java.util.function.Consumer;
import java.util.function.Function;
Expand All @@ -21,6 +22,7 @@
import org.reactfx.collection.LiveList.QuasiModificationObserver;
import org.reactfx.util.AccumulatorSize;
import org.reactfx.util.Experimental;
import org.reactfx.util.Tuple2;
import org.reactfx.util.WrapperBase;
import org.reactfx.value.Val;

Expand Down Expand Up @@ -179,6 +181,10 @@ default <F> LiveList<F> map(Function<? super E, ? extends F> f) {
return map(this, f);
}

default <F> LiveList<F> map(BiFunction<Integer, ? super E, ? extends F> f) {
return map(this, f);
}

default <F> LiveList<F> mapDynamic(
ObservableValue<? extends Function<? super E, ? extends F>> f) {
return mapDynamic(this, f);
Expand Down Expand Up @@ -291,12 +297,25 @@ static Val<Integer> sizeOf(ObservableList<?> list) {
return Val.create(() -> list.size(), list);
}

/**
* If you wish to use the index of the element in your mapping function, check {@link #map(ObservableList, BiFunction)}.
* @param f a mapping function taking the element from source as input and producing a result
*/
static <E, F> LiveList<F> map(
ObservableList<? extends E> list,
Function<? super E, ? extends F> f) {
return new MappedList<>(list, f);
}

/**
* @param f a mapping function taking the index and the element from source as input and producing a result
*/
static <E, F> LiveList<F> map(
ObservableList<? extends E> list,
BiFunction<Integer, ? super E, ? extends F> f) {
return new MappedList<>(list, f);
}

static <E, F> LiveList<F> mapDynamic(
ObservableList<? extends E> list,
ObservableValue<? extends Function<? super E, ? extends F>> f) {
Expand Down
19 changes: 16 additions & 3 deletions reactfx/src/main/java/org/reactfx/collection/MappedList.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.reactfx.collection;

import java.util.List;
import java.util.function.BiFunction;
import java.util.function.Function;

import javafx.beans.value.ObservableValue;
Expand All @@ -13,18 +14,24 @@
class MappedList<E, F> extends LiveListBase<F>
implements UnmodifiableByDefaultLiveList<F> {
private final ObservableList<? extends E> source;
private final Function<? super E, ? extends F> mapper;
private final BiFunction<Integer, ? super E, ? extends F> mapper;

public MappedList(
ObservableList<? extends E> source,
Function<? super E, ? extends F> mapper) {
this(source, (index, elem) -> mapper.apply(elem));
}

public MappedList(
ObservableList<? extends E> source,
BiFunction<Integer, ? super E, ? extends F> mapper) {
this.source = source;
this.mapper = mapper;
}

@Override
public F get(int index) {
return mapper.apply(source.get(index));
return mapper.apply(index, source.get(index));
}

@Override
Expand All @@ -44,6 +51,12 @@ private void sourceChanged(QuasiListChange<? extends E> change) {
static <E, F> QuasiListChange<F> mappedChangeView(
QuasiListChange<? extends E> change,
Function<? super E, ? extends F> mapper) {
return mappedChangeView(change, (index, elem) -> mapper.apply(elem));
}

static <E, F> QuasiListChange<F> mappedChangeView(
QuasiListChange<? extends E> change,
BiFunction<Integer, ? super E, ? extends F> mapper) {
return new QuasiListChange<F>() {

@Override
Expand All @@ -63,7 +76,7 @@ public int getAddedSize() {

@Override
public List<? extends F> getRemoved() {
return Lists.mappedView(mod.getRemoved(), mapper);
return Lists.mappedView(mod.getRemoved(), (index, elem) -> mapper.apply(mod.getFrom(), elem));
}
});
}
Expand Down
18 changes: 18 additions & 0 deletions reactfx/src/main/java/org/reactfx/util/Lists.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import java.util.List;
import java.util.ListIterator;
import java.util.Objects;
import java.util.function.BiFunction;
import java.util.function.Function;

public final class Lists {
Expand Down Expand Up @@ -188,6 +189,23 @@ public int size() {
};
}

public static <E, F> List<F> mappedView(
List<? extends E> source,
BiFunction<Integer, ? super E, ? extends F> f) {
return new AbstractList<F>() {

@Override
public F get(int index) {
return f.apply(index, source.get(index));
}

@Override
public int size() {
return source.size();
}
};
}

@SafeVarargs
public static <E> List<E> concatView(List<? extends E>... lists) {
return concatView(Arrays.asList(lists));
Expand Down
Loading