com.microsoft.azure.cosmosdb.HashIndex Maven / Gradle / Ivy
/*
* The MIT License (MIT)
* Copyright (c) 2018 Microsoft Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.microsoft.azure.cosmosdb;
import org.apache.commons.text.WordUtils;
import com.microsoft.azure.cosmosdb.internal.Constants;
/**
* Represents a hash index in the Azure Cosmos DB database service.
*/
public final class HashIndex extends Index {
/**
* Specifies an instance of HashIndex class with specified DataType.
*
* Here is an example to instantiate HashIndex class passing in the DataType:
*
* {@code
*
* HashIndex hashIndex = new HashIndex(DataType.String);
*
* }
*
*
* @param dataType the data type.
*/
public HashIndex(DataType dataType) {
super(IndexKind.Hash);
this.setDataType(dataType);
}
/**
* Initializes a new instance of the HashIndex class with specified DataType and precision.
*
* Here is an example to instantiate HashIndex class passing in the DataType:
*
* {@code
*
* HashIndex hashIndex = new HashIndex(DataType.String, 3);
*
* }
*
*
* @param dataType the data type.
* @param precision the precision.
*/
public HashIndex(DataType dataType, int precision) {
super(IndexKind.Hash);
this.setDataType(dataType);
this.setPrecision(precision);
}
/**
* Initializes a new instance of the HashIndex class with json string.
*
* @param jsonString the json string that represents the index.
*/
public HashIndex(String jsonString) {
super(jsonString, IndexKind.Hash);
if (this.getDataType() == null) {
throw new IllegalArgumentException("The jsonString doesn't contain a valid 'dataType'.");
}
}
/**
* Gets data type.
*
* @return the data type.
*/
public DataType getDataType() {
DataType result = null;
try {
result = DataType.valueOf(WordUtils.capitalize(super.getString(Constants.Properties.DATA_TYPE)));
} catch (IllegalArgumentException e) {
// Ignore exception and let the caller handle null value.
this.getLogger().warn("Invalid index dataType value {}.", super.getString(Constants.Properties.DATA_TYPE));
}
return result;
}
/**
* Sets data type.
*
* @param dataType the data type.
*/
public void setDataType(DataType dataType) {
super.set(Constants.Properties.DATA_TYPE, dataType.name());
}
/**
* Gets precision.
*
* @return the precision.
*/
public int getPrecision() {
return super.getInt(Constants.Properties.PRECISION);
}
/**
* Sets precision.
*
* @param precision the precision.
*/
public void setPrecision(int precision) {
super.set(Constants.Properties.PRECISION, precision);
}
boolean hasPrecision() {
return super.has(Constants.Properties.PRECISION);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy