Skip to content

Commit

Permalink
Merge branch 'jdk8'
Browse files Browse the repository at this point in the history
  • Loading branch information
bjorndarri committed Jan 27, 2024
2 parents 0d273b8 + 78f4251 commit 5ba2eaf
Show file tree
Hide file tree
Showing 66 changed files with 460 additions and 461 deletions.
2 changes: 2 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ Codion Change Log
==================

## 0.17.26-SNAPSHOT
### is.codion.common.core
- EventObserver now accepts data listeners for value type superclasses.
### is.codion.common.rmi
- Clients.resolveTrustStore() now uses the default 'changeit' truststore password when combining truststores instead of throwing an exception in case no truststore password is provided.
### is.codion.swing.common.ui
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,12 @@ public boolean removeListener(Runnable listener) {
}

@Override
public boolean addDataListener(Consumer<T> listener) {
public boolean addDataListener(Consumer<? super T> listener) {
return observer().addDataListener(listener);
}

@Override
public boolean removeDataListener(Consumer<T> listener) {
public boolean removeDataListener(Consumer<? super T> listener) {
return observer().removeDataListener(listener);
}

Expand All @@ -79,12 +79,12 @@ public boolean removeWeakListener(Runnable listener) {
}

@Override
public boolean addWeakDataListener(Consumer<T> listener) {
public boolean addWeakDataListener(Consumer<? super T> listener) {
return observer().addWeakDataListener(listener);
}

@Override
public boolean removeWeakDataListener(Consumer<T> listener) {
public boolean removeWeakDataListener(Consumer<? super T> listener) {
return observer().removeWeakDataListener(listener);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,20 +35,20 @@ final class DefaultEventObserver<T> implements EventObserver<T> {
private final Object lock = new Object();

private Set<Runnable> listeners;
private Set<Consumer<T>> dataListeners;
private Set<Consumer<? super T>> dataListeners;
private List<WeakReference<Runnable>> weakListeners;
private List<WeakReference<Consumer<T>>> weakDataListeners;
private List<WeakReference<Consumer<? super T>>> weakDataListeners;

@Override
public boolean addDataListener(Consumer<T> listener) {
public boolean addDataListener(Consumer<? super T> listener) {
requireNonNull(listener, LISTENER);
synchronized (lock) {
return initDataListeners().add(listener);
}
}

@Override
public boolean removeDataListener(Consumer<T> listener) {
public boolean removeDataListener(Consumer<? super T> listener) {
requireNonNull(listener, LISTENER);
synchronized (lock) {
return initDataListeners().remove(listener);
Expand Down Expand Up @@ -94,11 +94,11 @@ public boolean removeWeakListener(Runnable listener) {
}

@Override
public boolean addWeakDataListener(Consumer<T> listener) {
public boolean addWeakDataListener(Consumer<? super T> listener) {
requireNonNull(listener, LISTENER);
synchronized (lock) {
List<WeakReference<Consumer<T>>> references = initWeakDataListeners();
for (WeakReference<Consumer<T>> reference : references) {
List<WeakReference<Consumer<? super T>>> references = initWeakDataListeners();
for (WeakReference<Consumer<? super T>> reference : references) {
if (reference.get() == listener) {
return false;
}
Expand All @@ -108,7 +108,7 @@ public boolean addWeakDataListener(Consumer<T> listener) {
}

@Override
public boolean removeWeakDataListener(Consumer<T> listener) {
public boolean removeWeakDataListener(Consumer<? super T> listener) {
requireNonNull(listener, LISTENER);
synchronized (lock) {
return initWeakDataListeners().removeIf(reference -> reference.get() == null || reference.get() == listener);
Expand All @@ -119,7 +119,7 @@ void notifyListeners(T data) {
for (Runnable listener : listeners()) {
listener.run();
}
for (Consumer<T> dataListener : dataListeners()) {
for (Consumer<? super T> dataListener : dataListeners()) {
dataListener.accept(data);
}
for (WeakReference<Runnable> reference : weakListeners()) {
Expand All @@ -128,8 +128,8 @@ void notifyListeners(T data) {
weakListener.run();
}
}
for (WeakReference<Consumer<T>> reference : weakDataListeners()) {
Consumer<T> weakDataListener = reference.get();
for (WeakReference<Consumer<? super T>> reference : weakDataListeners()) {
Consumer<? super T> weakDataListener = reference.get();
if (weakDataListener != null) {
weakDataListener.accept(data);
}
Expand All @@ -146,7 +146,7 @@ private List<Runnable> listeners() {
return emptyList();
}

private List<Consumer<T>> dataListeners() {
private List<Consumer<? super T>> dataListeners() {
synchronized (lock) {
if (dataListeners != null && !dataListeners.isEmpty()) {
return new ArrayList<>(dataListeners);
Expand All @@ -168,7 +168,7 @@ private List<WeakReference<Runnable>> weakListeners() {
return emptyList();
}

private List<WeakReference<Consumer<T>>> weakDataListeners() {
private List<WeakReference<Consumer<? super T>>> weakDataListeners() {
synchronized (lock) {
if (weakDataListeners != null && !weakDataListeners.isEmpty()) {
weakDataListeners.removeIf(reference -> reference.get() == null);
Expand All @@ -188,7 +188,7 @@ private Set<Runnable> initListeners() {
return listeners;
}

private Set<Consumer<T>> initDataListeners() {
private Set<Consumer<? super T>> initDataListeners() {
if (dataListeners == null) {
dataListeners = new LinkedHashSet<>(1);
}
Expand All @@ -204,7 +204,7 @@ private List<WeakReference<Runnable>> initWeakListeners() {
return weakListeners;
}

private List<WeakReference<Consumer<T>>> initWeakDataListeners() {
private List<WeakReference<Consumer<? super T>>> initWeakDataListeners() {
if (weakDataListeners == null) {
weakDataListeners = new ArrayList<>(1);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,14 @@ public interface EventObserver<T> {
* @return true if this observer did not already contain the specified listener
* @throws NullPointerException in case listener is null
*/
boolean addDataListener(Consumer<T> listener);
boolean addDataListener(Consumer<? super T> listener);

/**
* Removes {@code listener} from this {@link EventObserver}
* @param listener the listener to remove
* @return true if this observer contained the specified listener
*/
boolean removeDataListener(Consumer<T> listener);
boolean removeDataListener(Consumer<? super T> listener);

/**
* Uses a {@link java.lang.ref.WeakReference}, adding {@code listener} does not prevent it from being garbage collected.
Expand All @@ -79,12 +79,12 @@ public interface EventObserver<T> {
* @param listener the listener
* @return true if this observer did not already contain the specified listener
*/
boolean addWeakDataListener(Consumer<T> listener);
boolean addWeakDataListener(Consumer<? super T> listener);

/**
* Removes {@code listener} from this {@link EventObserver}.
* @param listener the listener to remove
* @return true if this observer contained the specified listener
*/
boolean removeWeakDataListener(Consumer<T> listener);
boolean removeWeakDataListener(Consumer<? super T> listener);
}
Original file line number Diff line number Diff line change
Expand Up @@ -147,12 +147,12 @@ public boolean removeListener(Runnable listener) {
}

@Override
public boolean addDataListener(Consumer<Boolean> listener) {
public boolean addDataListener(Consumer<? super Boolean> listener) {
return observer().addDataListener(listener);
}

@Override
public boolean removeDataListener(Consumer<Boolean> listener) {
public boolean removeDataListener(Consumer<? super Boolean> listener) {
if (observer != null) {
return observer.removeDataListener(listener);
}
Expand All @@ -175,12 +175,12 @@ public boolean removeWeakListener(Runnable listener) {
}

@Override
public boolean addWeakDataListener(Consumer<Boolean> listener) {
public boolean addWeakDataListener(Consumer<? super Boolean> listener) {
return observer().addWeakDataListener(listener);
}

@Override
public boolean removeWeakDataListener(Consumer<Boolean> listener) {
public boolean removeWeakDataListener(Consumer<? super Boolean> listener) {
if (observer != null) {
return observer.removeWeakDataListener(listener);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,12 +129,12 @@ public boolean removeListener(Runnable listener) {
}

@Override
public boolean addDataListener(Consumer<Boolean> listener) {
public boolean addDataListener(Consumer<? super Boolean> listener) {
return observer.addDataListener(listener);
}

@Override
public boolean removeDataListener(Consumer<Boolean> listener) {
public boolean removeDataListener(Consumer<? super Boolean> listener) {
return observer.removeDataListener(listener);
}

Expand All @@ -149,12 +149,12 @@ public boolean removeWeakListener(Runnable listener) {
}

@Override
public boolean addWeakDataListener(Consumer<Boolean> listener) {
public boolean addWeakDataListener(Consumer<? super Boolean> listener) {
return observer.addWeakDataListener(listener);
}

@Override
public boolean removeWeakDataListener(Consumer<Boolean> listener) {
public boolean removeWeakDataListener(Consumer<? super Boolean> listener) {
return observer.removeWeakDataListener(listener);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,12 @@ public boolean removeListener(Runnable listener) {
}

@Override
public boolean addDataListener(Consumer<Boolean> listener) {
public boolean addDataListener(Consumer<? super Boolean> listener) {
return eventObserver().addDataListener(listener);
}

@Override
public boolean removeDataListener(Consumer<Boolean> listener) {
public boolean removeDataListener(Consumer<? super Boolean> listener) {
return eventObserver().removeDataListener(listener);
}

Expand All @@ -111,12 +111,12 @@ public boolean removeWeakListener(Runnable listener) {
}

@Override
public boolean addWeakDataListener(Consumer<Boolean> listener) {
public boolean addWeakDataListener(Consumer<? super Boolean> listener) {
return eventObserver().addWeakDataListener(listener);
}

@Override
public boolean removeWeakDataListener(Consumer<Boolean> listener) {
public boolean removeWeakDataListener(Consumer<? super Boolean> listener) {
return eventObserver().removeWeakDataListener(listener);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,12 +127,12 @@ public final boolean removeListener(Runnable listener) {
}

@Override
public final boolean addDataListener(Consumer<T> listener) {
public final boolean addDataListener(Consumer<? super T> listener) {
return changeEvent().addDataListener(listener);
}

@Override
public final boolean removeDataListener(Consumer<T> listener) {
public final boolean removeDataListener(Consumer<? super T> listener) {
if (changeEvent != null) {
return changeEvent.removeDataListener(listener);
}
Expand All @@ -155,12 +155,12 @@ public final boolean removeWeakListener(Runnable listener) {
}

@Override
public final boolean addWeakDataListener(Consumer<T> listener) {
public final boolean addWeakDataListener(Consumer<? super T> listener) {
return changeEvent().addWeakDataListener(listener);
}

@Override
public final boolean removeWeakDataListener(Consumer<T> listener) {
public final boolean removeWeakDataListener(Consumer<? super T> listener) {
if (changeEvent != null) {
return changeEvent.removeWeakDataListener(listener);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,12 @@ public boolean removeListener(Runnable listener) {
}

@Override
public boolean addDataListener(Consumer<T> listener) {
public boolean addDataListener(Consumer<? super T> listener) {
return value.addDataListener(listener);
}

@Override
public boolean removeDataListener(Consumer<T> listener) {
public boolean removeDataListener(Consumer<? super T> listener) {
return value.removeDataListener(listener);
}

Expand All @@ -71,12 +71,12 @@ public boolean removeWeakListener(Runnable listener) {
}

@Override
public boolean addWeakDataListener(Consumer<T> listener) {
public boolean addWeakDataListener(Consumer<? super T> listener) {
return value.addWeakDataListener(listener);
}

@Override
public boolean removeWeakDataListener(Consumer<T> listener) {
public boolean removeWeakDataListener(Consumer<? super T> listener) {
return value.removeWeakDataListener(listener);
}
}
14 changes: 7 additions & 7 deletions common/db/src/test/sql/create_h2_db.sql
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
create schema scott;
create schema employees;

CREATE TABLE scott.dept (
CREATE TABLE employees.department (
deptno INT NOT NULL,
dname VARCHAR(14) NOT NULL,
loc VARCHAR(13),
constraint dept_pk primary key (deptno)
);

CREATE TABLE scott.emp (
CREATE TABLE employees.employee (
empno INT NOT NULL,
ename VARCHAR(10) NOT NULL,
job VARCHAR(9),
Expand All @@ -17,17 +17,17 @@ CREATE TABLE scott.emp (
comm DECIMAL(7, 2),
deptno INT NOT NULL,
constraint emp_pk primary key (empno),
constraint emp_dept_fk foreign key (deptno) references scott.dept(deptno),
constraint emp_mgr_fk foreign key (mgr) references scott.emp(empno)
constraint emp_dept_fk foreign key (deptno) references employees.department(deptno),
constraint emp_mgr_fk foreign key (mgr) references employees.employee(empno)
);

INSERT INTO scott.dept(deptno, dname, loc)
INSERT INTO employees.department(deptno, dname, loc)
VALUES (10, 'ACCOUNTING', 'NEW YORK'),
(20, 'RESEARCH', 'DALLAS'),
(30, 'SALES', 'CHICAGO'),
(40, 'OPERATIONS', 'BOSTON');

INSERT INTO scott.emp(empno, ename, job, mgr, hiredate, sal, comm, deptno)
INSERT INTO employees.employee(empno, ename, job, mgr, hiredate, sal, comm, deptno)
VALUES (8, 'KING', 'PRESIDENT', NULL, '1981-11-17', 5000, NULL, 10),
(3, 'JONES', 'MANAGER', 8, '1981-04-02', 2975, NULL, 20),
(5, 'BLAKE', 'MANAGER', 3, '1981-05-01', 2850, NULL, 10),
Expand Down
Loading

0 comments on commit 5ba2eaf

Please sign in to comment.