com.bol.ipresource.etree.SynchronizedIntervalMap Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of ip-resource Show documentation
Show all versions of ip-resource Show documentation
High performance, low memory IP library (originally developed for RIPE NCC Whois server)
package com.bol.ipresource.etree;
import com.bol.ipresource.ip.Interval;
import java.util.List;
public final class SynchronizedIntervalMap, V> implements IntervalMap {
private final Object mutex;
private final IntervalMap wrapped;
public static , V> IntervalMap synchronizedMap(IntervalMap toWrap) {
return new SynchronizedIntervalMap<>(toWrap);
}
public static , V> IntervalMap synchronizedMap(IntervalMap toWrap, final Object mutex) {
return new SynchronizedIntervalMap<>(toWrap, mutex);
}
private SynchronizedIntervalMap(final IntervalMap wrapped) {
this.wrapped = wrapped;
this.mutex = this;
}
private SynchronizedIntervalMap(final IntervalMap wrapped, final Object mutex) {
this.wrapped = wrapped;
this.mutex = mutex;
}
@Override
public void put(K key, V value) {
synchronized (mutex) {
wrapped.put(key, value);
}
}
@Override
public void remove(K key) {
synchronized (mutex) {
wrapped.remove(key);
}
}
@Override
public void remove(K key, V value) {
synchronized (mutex) {
wrapped.remove(key, value);
}
}
@Override
public List findFirstLessSpecific(K key) {
synchronized (mutex) {
return wrapped.findFirstLessSpecific(key);
}
}
@Override
public List findAllLessSpecific(K key) {
synchronized (mutex) {
return wrapped.findAllLessSpecific(key);
}
}
@Override
public List findExactAndAllLessSpecific(K key) {
synchronized (mutex) {
return wrapped.findExactAndAllLessSpecific(key);
}
}
@Override
public List findExact(K key) {
synchronized (mutex) {
return wrapped.findExact(key);
}
}
@Override
public List findExactOrFirstLessSpecific(K key) {
synchronized (mutex) {
return wrapped.findExactOrFirstLessSpecific(key);
}
}
@Override
public List findFirstMoreSpecific(K key) {
synchronized (mutex) {
return wrapped.findFirstMoreSpecific(key);
}
}
@Override
public List findAllMoreSpecific(K key) {
synchronized (mutex) {
return wrapped.findAllMoreSpecific(key);
}
}
@Override
public List findExactAndAllMoreSpecific(K key) {
synchronized (mutex) {
return wrapped.findExactAndAllMoreSpecific(key);
}
}
@Override
public void clear() {
synchronized (mutex) {
wrapped.clear();
}
}
}