com.jparams.store.index.SynchronizedIndex Maven / Gradle / Ivy
package com.jparams.store.index;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
public class SynchronizedIndex implements Index
{
private final Index index;
private final Object mutex;
public SynchronizedIndex(final Index index, final Object mutex)
{
this.index = index;
this.mutex = mutex;
}
@Override
public T getFirst(final Object key)
{
final T result;
synchronized (mutex)
{
result = index.getFirst(key);
}
return result;
}
@Override
public Optional findFirst(final Object key)
{
final Optional result;
synchronized (mutex)
{
result = index.findFirst(key);
}
return result;
}
@Override
public List get(final Object key)
{
final List results;
synchronized (mutex)
{
results = index.get(key);
}
return results;
}
@Override
public String getName()
{
return index.getName();
}
public Index getIndex()
{
return index;
}
@Override
public boolean equals(final Object other)
{
if (this == other)
{
return true;
}
if (other == null || getClass() != other.getClass())
{
return false;
}
final SynchronizedIndex> that = (SynchronizedIndex>) other;
return Objects.equals(index, that.index)
&& Objects.equals(mutex, that.mutex);
}
@Override
public int hashCode()
{
return Objects.hash(index, mutex);
}
@Override
public String toString()
{
return String.valueOf(index);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy