Limited synchronized association access

This commit is contained in:
Andrea Cavalli 2020-11-10 22:39:07 +01:00
parent c755b57e0c
commit dcc5b44520
4 changed files with 14 additions and 6 deletions

View File

@ -104,4 +104,8 @@ public interface Association<T, U> {
static <T, U> Association<T, U> synchronize(Association<T, U> association) {
return new SynchronizedAssociation(association);
}
static <T, U> Association<T, U> synchronize(Association<T, U> association, Object lock) {
return new SynchronizedAssociation(association, lock);
}
}

View File

@ -103,4 +103,8 @@ public interface BiAssociation<T, U> {
static <T, U> BiAssociation<T, U> synchronize(BiAssociation<T, U> association) {
return new SynchronizedBiAssociation(association);
}
static <T, U> BiAssociation<T, U> synchronize(BiAssociation<T, U> association, Object lock) {
return new SynchronizedBiAssociation(association, lock);
}
}

View File

@ -3,17 +3,17 @@ package org.warp.commonutils.type;
import java.util.Optional;
import java.util.Set;
public class SynchronizedAssociation<T, U> implements Association<T, U> {
public final class SynchronizedAssociation<T, U> implements Association<T, U> {
private final Association<T,U> association;
private final Object lock;
public SynchronizedAssociation(Association<T, U> association) {
SynchronizedAssociation(Association<T, U> association) {
this.association = association;
this.lock = new Object();
}
public SynchronizedAssociation(Association<T, U> association, Object lock) {
SynchronizedAssociation(Association<T, U> association, Object lock) {
this.association = association;
this.lock = lock;
}

View File

@ -2,17 +2,17 @@ package org.warp.commonutils.type;
import java.util.Optional;
public class SynchronizedBiAssociation<T, U> implements BiAssociation<T, U> {
public final class SynchronizedBiAssociation<T, U> implements BiAssociation<T, U> {
private final BiAssociation<T,U> association;
private final Object lock;
public SynchronizedBiAssociation(BiAssociation<T, U> association) {
SynchronizedBiAssociation(BiAssociation<T, U> association) {
this.association = association;
this.lock = new Object();
}
public SynchronizedBiAssociation(BiAssociation<T, U> association, Object lock) {
SynchronizedBiAssociation(BiAssociation<T, U> association, Object lock) {
this.association = association;
this.lock = lock;
}