Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit fb6132c

Browse filesBrowse files
committed
chsnged state class to record
1 parent 6761a9f commit fb6132c
Copy full SHA for fb6132c

5 files changed

+10-29Lines changed: 10 additions & 29 deletions

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎bloc/src/main/java/com/iluwatar/bloc/Bloc.java‎

Copy file name to clipboardExpand all lines: bloc/src/main/java/com/iluwatar/bloc/Bloc.java
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,13 @@ private void emitState(State newState) {
6868
* Increments the current state value by 1 and notifies listeners of the change.
6969
*/
7070
public void increment() {
71-
emitState(new State(currentState.getValue() + 1));
71+
emitState(new State(currentState.value() + 1));
7272
}
7373

7474
/**
7575
* Decrements the current state value by 1 and notifies listeners of the change.
7676
*/
7777
public void decrement() {
78-
emitState(new State(currentState.getValue() - 1));
78+
emitState(new State(currentState.value() - 1));
7979
}
8080
}
Collapse file

‎bloc/src/main/java/com/iluwatar/bloc/BlocUi.java‎

Copy file name to clipboardExpand all lines: bloc/src/main/java/com/iluwatar/bloc/BlocUi.java
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public void createAndShowUi() {
4141
frame.add(toggleListenerButton, BorderLayout.EAST);
4242

4343
// making a state listener to update the counter label when the state changes
44-
StateListener<State> stateListener = state -> counterLabel.setText("Counter: " + state.getValue());
44+
StateListener<State> stateListener = state -> counterLabel.setText("Counter: " + state.value());
4545

4646
// adding the listener to the Bloc instance
4747
bloc.addListener(stateListener);
Collapse file
+2-21Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,8 @@
11
package com.iluwatar.bloc;
22

3-
import lombok.Getter;
4-
53
/**
64
* The {@code State} class represents a state with an integer value.
75
* This class encapsulates the value and provides methods to retrieve it.
86
*/
9-
@Getter
10-
public class State {
11-
/**
12-
* -- GETTER --
13-
* Returns the value of the state.
14-
*
15-
*/
16-
private final int value;
17-
18-
/**
19-
* Constructs a {@code State} with the specified value.
20-
*
21-
* @param value the value of the state
22-
*/
23-
public State(int value) {
24-
this.value = value;
25-
}
26-
27-
}
7+
public record State(int value) {
8+
}
Collapse file

‎bloc/src/test/java/com/iluwatar/bloc/BlocTest.java‎

Copy file name to clipboardExpand all lines: bloc/src/test/java/com/iluwatar/bloc/BlocTest.java
+4-4Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@ void initialState() {
1919

2020
@Test
2121
void IncrementUpdateState() {
22-
bloc.addListener(state -> stateValue.set(state.getValue()));
22+
bloc.addListener(state -> stateValue.set(state.value()));
2323
bloc.increment();
2424
assertEquals(1, stateValue.get(), "State should increment to 1");
2525
}
2626

2727
@Test
2828
void DecrementUpdateState() {
29-
bloc.addListener(state -> stateValue.set(state.getValue()));
29+
bloc.addListener(state -> stateValue.set(state.value()));
3030
bloc.decrement();
3131
assertEquals(-1, stateValue.get(), "State should decrement to -1");
3232
}
@@ -47,8 +47,8 @@ void removingListener() {
4747
@Test
4848
void multipleListeners() {
4949
AtomicInteger secondValue = new AtomicInteger();
50-
bloc.addListener(state -> stateValue.set(state.getValue()));
51-
bloc.addListener(state -> secondValue.set(state.getValue()));
50+
bloc.addListener(state -> stateValue.set(state.value()));
51+
bloc.addListener(state -> secondValue.set(state.value()));
5252
bloc.increment();
5353
assertEquals(1, stateValue.get(), "First listener should receive state 1.");
5454
assertEquals(1, secondValue.get(), "Second listener should receive state 1.");
Collapse file

‎bloc/src/test/java/com/iluwatar/bloc/BlocUiTest.java‎

Copy file name to clipboardExpand all lines: bloc/src/test/java/com/iluwatar/bloc/BlocUiTest.java
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public void setUp() {
4040
frame.add(decrementButton, BorderLayout.SOUTH);
4141
frame.add(toggleListenerButton, BorderLayout.EAST);
4242

43-
stateListener = state -> counterLabel.setText("Counter: " + state.getValue());
43+
stateListener = state -> counterLabel.setText("Counter: " + state.value());
4444
bloc.addListener(stateListener);
4545

4646
incrementButton.addActionListener(e -> bloc.increment());

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.