From f107667d079d3ff07abb29c38ebf225965ed819c Mon Sep 17 00:00:00 2001 From: Romuald Rousseau Date: Mon, 9 Dec 2024 23:01:15 +0800 Subject: [PATCH] fix: Fix the data loss --- .../archery/commons/behavior/Scenario.java | 71 ------------------- .../archery/commons/redux/Action.java | 33 --------- .../archery/commons/redux/Reducer.java | 6 -- .../archery/commons/redux/Store.java | 36 ---------- .../archery/commons/redux/Subscriber.java | 6 -- .../archery/commons/python/Test_Python.java | 13 +++- .../archery/commons/redux/Test_Redux.java | 56 --------------- .../archery/header/PivotKeyHeader.java | 7 +- 8 files changed, 17 insertions(+), 211 deletions(-) delete mode 100644 archery-commons/src/main/java/com/github/romualdrousseau/archery/commons/behavior/Scenario.java delete mode 100644 archery-commons/src/main/java/com/github/romualdrousseau/archery/commons/redux/Action.java delete mode 100644 archery-commons/src/main/java/com/github/romualdrousseau/archery/commons/redux/Reducer.java delete mode 100644 archery-commons/src/main/java/com/github/romualdrousseau/archery/commons/redux/Store.java delete mode 100644 archery-commons/src/main/java/com/github/romualdrousseau/archery/commons/redux/Subscriber.java delete mode 100644 archery-commons/src/test/java/com/github/romualdrousseau/archery/commons/redux/Test_Redux.java diff --git a/archery-commons/src/main/java/com/github/romualdrousseau/archery/commons/behavior/Scenario.java b/archery-commons/src/main/java/com/github/romualdrousseau/archery/commons/behavior/Scenario.java deleted file mode 100644 index ad57b6e3..00000000 --- a/archery-commons/src/main/java/com/github/romualdrousseau/archery/commons/behavior/Scenario.java +++ /dev/null @@ -1,71 +0,0 @@ -package com.github.romualdrousseau.archery.commons.behavior; - -import java.util.HashMap; -import java.util.Map; -import java.util.Optional; - -public class Scenario { - - @FunctionalInterface - public interface GivenClause { - void given(final Scenario scenario) throws Exception; - } - - @FunctionalInterface - public interface WhenClause { - T when(final Scenario scenario) throws Exception; - } - - @FunctionalInterface - public interface ThenClause { - void then(final Scenario scenario, final T actual) throws Exception; - } - - public static Scenario givenNoParameters() throws Exception { - return new Scenario(new HashMap<>(), null); - } - - public static Scenario givenParameters(final Map parameters) throws Exception { - return new Scenario(new HashMap<>(parameters), null); - } - - public static Scenario givenScenario(final Scenario parent) throws Exception { - return new Scenario(parent.context, null); - } - - private final Map context; - private final R value; - - private Scenario(final Map context, final R value) { - this.context = context; - this.value = value; - } - - public Map getContext() { - return this.context; - } - - @SuppressWarnings("unchecked") - public Optional get(final String key) { - return Optional.ofNullable((T) this.context.get(key)); - } - - public T put(final String key, final T value) { - this.context.put(key, value); - return value; - } - - public Scenario given(final GivenClause step) throws Exception { - step.given(this); - return this; - } - - public Scenario when(final WhenClause step) throws Exception { - return new Scenario(this.context, step.when(this)); - } - - public Scenario then(final ThenClause step) throws Exception { - step.then(this, this.value); - return this; - } -} diff --git a/archery-commons/src/main/java/com/github/romualdrousseau/archery/commons/redux/Action.java b/archery-commons/src/main/java/com/github/romualdrousseau/archery/commons/redux/Action.java deleted file mode 100644 index f160414e..00000000 --- a/archery-commons/src/main/java/com/github/romualdrousseau/archery/commons/redux/Action.java +++ /dev/null @@ -1,33 +0,0 @@ -package com.github.romualdrousseau.archery.commons.redux; - -import java.util.function.Supplier; - -public class Action implements Supplier { - - private final String type; - - public Action(final String type) { - this.type = type; - } - - public String getType() { - return this.type; - } - - public int hashCode() { - return this.type.hashCode(); - } - - public boolean equals(final Object obj) { - if (!(obj instanceof Action)) { - return false; - } - final var otherAction = (Action) obj; - return this.type.equals(otherAction.type); - } - - @Override - public Action get() { - return this; - } -} diff --git a/archery-commons/src/main/java/com/github/romualdrousseau/archery/commons/redux/Reducer.java b/archery-commons/src/main/java/com/github/romualdrousseau/archery/commons/redux/Reducer.java deleted file mode 100644 index 72585084..00000000 --- a/archery-commons/src/main/java/com/github/romualdrousseau/archery/commons/redux/Reducer.java +++ /dev/null @@ -1,6 +0,0 @@ -package com.github.romualdrousseau.archery.commons.redux; - -import java.util.function.BiFunction; - -@FunctionalInterface -public interface Reducer extends BiFunction {} diff --git a/archery-commons/src/main/java/com/github/romualdrousseau/archery/commons/redux/Store.java b/archery-commons/src/main/java/com/github/romualdrousseau/archery/commons/redux/Store.java deleted file mode 100644 index 372833bd..00000000 --- a/archery-commons/src/main/java/com/github/romualdrousseau/archery/commons/redux/Store.java +++ /dev/null @@ -1,36 +0,0 @@ -package com.github.romualdrousseau.archery.commons.redux; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -public class Store { - - private final Map>> subscribers = new HashMap<>(); - private final List> reducers = new ArrayList<>(); - private S state; - - public Store(final S state) { - this.state = state; - } - - public S getState() { - return this.state; - } - - public void addSubscriber(final A action, final Subscriber subscriber) { - this.subscribers.computeIfAbsent(action, x -> new ArrayList<>()).add(subscriber); - } - - public void addReducer(final Reducer reducer) { - this.reducers.add(reducer); - } - - public void dispatch(final A action) { - @SuppressWarnings("unchecked") final var result = (A) action.get(); - this.state = reducers.stream().reduce(this.state, (x, y) -> y.apply(x, result), (x, y) -> y); - this.subscribers.getOrDefault(result, Collections.emptyList()).forEach(x -> x.accept(this, result)); - } -} diff --git a/archery-commons/src/main/java/com/github/romualdrousseau/archery/commons/redux/Subscriber.java b/archery-commons/src/main/java/com/github/romualdrousseau/archery/commons/redux/Subscriber.java deleted file mode 100644 index f6cf9477..00000000 --- a/archery-commons/src/main/java/com/github/romualdrousseau/archery/commons/redux/Subscriber.java +++ /dev/null @@ -1,6 +0,0 @@ -package com.github.romualdrousseau.archery.commons.redux; - -import java.util.function.BiConsumer; - -@FunctionalInterface -public interface Subscriber extends BiConsumer, A> {} diff --git a/archery-commons/src/test/java/com/github/romualdrousseau/archery/commons/python/Test_Python.java b/archery-commons/src/test/java/com/github/romualdrousseau/archery/commons/python/Test_Python.java index c85ecaea..a82f8c2d 100644 --- a/archery-commons/src/test/java/com/github/romualdrousseau/archery/commons/python/Test_Python.java +++ b/archery-commons/src/test/java/com/github/romualdrousseau/archery/commons/python/Test_Python.java @@ -6,6 +6,7 @@ import java.time.LocalDate; import java.time.ZoneId; import java.util.Date; +import java.util.Locale; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Tag; @@ -15,8 +16,18 @@ public class Test_Python { @Test @Tag("unit") public void testPythonSimpleDateformat() throws ParseException { - final PythonSimpleDateFormat formatter = new PythonSimpleDateFormat("%a,%d/%m/%y"); + final var formatter = new PythonSimpleDateFormat("%a,%d/%m/%y"); assertEquals("Sun,24/09/23", formatter.format(Date.from(LocalDate.of(2023, 9, 24).atStartOfDay(ZoneId.systemDefault()).toInstant()))); assertEquals("Sun,05/12/99", formatter.format(formatter.parse("Sun,05/12/99"))); } + + @Test + @Tag("unit") + public void testPythonSimpleDateformatWithLocale() throws ParseException { + final var formatterGB = new PythonSimpleDateFormat("%b, %Y", Locale.forLanguageTag("en-GB")); + assertEquals("Sept, 2023", formatterGB.format(formatterGB.parse("Sept, 2023"))); + + final var formatterUS = new PythonSimpleDateFormat("%b, %Y", Locale.forLanguageTag("en-US")); + assertEquals("Sep, 2023", formatterUS.format(formatterUS.parse("Sep, 2023"))); + } } diff --git a/archery-commons/src/test/java/com/github/romualdrousseau/archery/commons/redux/Test_Redux.java b/archery-commons/src/test/java/com/github/romualdrousseau/archery/commons/redux/Test_Redux.java deleted file mode 100644 index b9674fb2..00000000 --- a/archery-commons/src/test/java/com/github/romualdrousseau/archery/commons/redux/Test_Redux.java +++ /dev/null @@ -1,56 +0,0 @@ -package com.github.romualdrousseau.archery.commons.redux; - -import static org.junit.Assert.assertEquals; - -import java.util.HashMap; - -import org.junit.jupiter.api.Tag; -import org.junit.jupiter.api.Test; - -public class Test_Redux { - - @Test - @Tag("unit") - public void testStoreNoReducerNoSbuscriber() { - final var state = new HashMap(); - final var store = new Store, Action>(state); - final var testAction = new Action("test"); - store.dispatch(testAction); - } - - @Test - - public void testStoreNoReducerWithSubscriber() { - final var state = new HashMap(); - final var store = new Store, Action>(state); - final var testAction = new Action("test"); - store.addSubscriber(testAction, (s, a) -> assertEquals("test", a.getType())); - store.dispatch(testAction); - } - - @Test - @Tag("unit") - public void testStoreWithReducerAndSubscribers() { - final var state = new HashMap(); - state.put("counter", 0); - - final var store = new Store, Action>(state); - store.addReducer((s, a) -> { - if (a.getType().equals("inc")) { - s.computeIfPresent("counter", (x, y) -> y + 1); - } - if (a.getType().equals("dec")) { - s.computeIfPresent("counter", (x, y) -> y - 1); - } - return s; - }); - - final var incAction = new Action("inc"); - final var decAction = new Action("dec"); - - store.addSubscriber(incAction, (s, a) -> assertEquals(Integer.valueOf(1), s.getState().get("counter"))); - store.addSubscriber(decAction, (s, a) -> assertEquals(Integer.valueOf(0), s.getState().get("counter"))); - store.dispatch(incAction); - store.dispatch(decAction); - } -} diff --git a/archery/src/main/java/com/github/romualdrousseau/archery/header/PivotKeyHeader.java b/archery/src/main/java/com/github/romualdrousseau/archery/header/PivotKeyHeader.java index a5bcf723..900595a4 100644 --- a/archery/src/main/java/com/github/romualdrousseau/archery/header/PivotKeyHeader.java +++ b/archery/src/main/java/com/github/romualdrousseau/archery/header/PivotKeyHeader.java @@ -54,9 +54,12 @@ public Set getEntryTypeValues() { } public void setEntryTypeValues(final Set entryTypeValues) { + final var newEntries = entryTypeValues.stream() + .flatMap(x -> this.entries.stream() + .map(y -> new PivotEntry(y.getCell(), this.pivotEntityName).setTypeValue(x))) + .toList(); this.entries.clear(); - this.entries.addAll(entryTypeValues.stream() - .map(x -> new PivotEntry(this.getCell(), this.pivotEntityName).setTypeValue(x)).toList()); + this.entries.addAll(newEntries); } public Set getEntryPivotValues() {