io.tarantool.driver.core.conditions.IdIndexImpl Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of cartridge-driver Show documentation
Show all versions of cartridge-driver Show documentation
Tarantool Cartridge driver for Tarantool versions 1.10+ based on Netty framework
package io.tarantool.driver.core.conditions;
import io.tarantool.driver.api.conditions.IdIndex;
import io.tarantool.driver.api.metadata.TarantoolIndexMetadata;
import io.tarantool.driver.api.metadata.TarantoolMetadataOperations;
import io.tarantool.driver.api.metadata.TarantoolSpaceMetadata;
import io.tarantool.driver.exceptions.TarantoolIndexNotFoundException;
import io.tarantool.driver.utils.Assert;
import java.util.Objects;
import java.util.Optional;
/**
* Represents an index defined by its id
*
* @author Alexey Kuzin
*/
public class IdIndexImpl implements IdIndex {
private static final long serialVersionUID = 20200708L;
private final int position;
/**
* Construct index by its id
*
* @param position index position in the order of creation, starting from 0
*/
public IdIndexImpl(int position) {
Assert.state(position >= 0, "Index position should be greater or equal 0");
this.position = position;
}
@Override
public TarantoolIndexMetadata metadata(
TarantoolMetadataOperations metadataOperations,
TarantoolSpaceMetadata spaceMetadata) {
Optional indexMetadata =
metadataOperations.getIndexById(spaceMetadata.getSpaceName(), position);
if (!indexMetadata.isPresent()) {
throw new TarantoolIndexNotFoundException(spaceMetadata.getSpaceName(), position);
}
return indexMetadata.get();
}
@Override
public Integer toIdentifier() {
return position;
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
IdIndexImpl idIndex = (IdIndexImpl) o;
return position == idIndex.position;
}
@Override
public int hashCode() {
return Objects.hash(position);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy