
io.permazen.core.Index3View Maven / Gradle / Ivy
/*
* Copyright (C) 2015 Archie L. Cobbs. All rights reserved.
*/
package io.permazen.core;
import io.permazen.core.type.Tuple2FieldType;
import io.permazen.core.type.Tuple3FieldType;
import io.permazen.kv.KeyFilter;
import io.permazen.tuple.Tuple2;
import io.permazen.tuple.Tuple3;
import io.permazen.util.UnsignedIntEncoder;
/**
* A view of an index on three values.
*/
class Index3View extends AbstractIndexView {
/**
* Normal constructor.
*
* @param storageId field storage ID
* @param value1Type first value type
* @param value2Type second value type
* @param value3Type third value type
* @param targetType index target type
* @throws IllegalArgumentException if any parameter is null is null or empty
*/
Index3View(int storageId, FieldType value1Type,
FieldType value2Type, FieldType value3Type, FieldType targetType) {
this(UnsignedIntEncoder.encode(storageId), false, value1Type, value2Type, value3Type, targetType);
}
/**
* Constructor for views formed from larger composite indexes.
*
* @param prefix key prefix
* @param prefixMode true if {@code targetType} is not the final field in the index
* @param value1Type first value type
* @param value2Type second value type
* @param value3Type third value type
* @param targetType index target type
* @throws IllegalArgumentException if any parameter is null is null or empty
*/
Index3View(byte[] prefix, boolean prefixMode,
FieldType value1Type, FieldType value2Type, FieldType value3Type, FieldType targetType) {
super(prefix, prefixMode, value1Type, value2Type, value3Type, targetType);
}
// Internal copy constructor
private Index3View(Index3View original) {
super(original);
}
@SuppressWarnings("unchecked")
public FieldType getValue1Type() {
return (FieldType)this.fieldTypes[0];
}
@SuppressWarnings("unchecked")
public FieldType getValue2Type() {
return (FieldType)this.fieldTypes[1];
}
@SuppressWarnings("unchecked")
public FieldType getValue3Type() {
return (FieldType)this.fieldTypes[2];
}
@SuppressWarnings("unchecked")
public FieldType getTargetType() {
return (FieldType)this.fieldTypes[3];
}
@Override
@SuppressWarnings("unchecked")
public Index3View filter(int index, KeyFilter keyFilter) {
return (Index3View)super.filter(index, keyFilter);
}
@Override
protected Index3View copy() {
return new Index3View<>(this);
}
// Tuple views
public IndexView, T> asTuple3IndexView() {
// Create new IndexView
IndexView, T> indexView = new IndexView<>(this.prefix, this.prefixMode,
new Tuple3FieldType<>(this.getValue1Type(), this.getValue2Type(), this.getValue3Type()), this.getTargetType());
// Get filters
final KeyFilter value1Filter = this.getFilter(0);
final KeyFilter value2Filter = this.getFilter(1);
final KeyFilter value3Filter = this.getFilter(2);
final KeyFilter targetFilter = this.getFilter(3);
// Apply filtering to tuple field
if (value1Filter != null || value2Filter != null || value3Filter != null) {
FieldTypesFilter tupleFilter = new FieldTypesFilter(null,
this.getValue1Type(), this.getValue2Type(), this.getValue3Type());
if (value1Filter != null)
tupleFilter = tupleFilter.filter(0, value1Filter);
if (value2Filter != null)
tupleFilter = tupleFilter.filter(1, value2Filter);
if (value3Filter != null)
tupleFilter = tupleFilter.filter(2, value3Filter);
indexView = indexView.filter(0, tupleFilter);
}
// Apply filtering to target field
if (targetFilter != null)
indexView = indexView.filter(1, targetFilter);
// Done
return indexView;
}
public Index2View, V3, T> asTuple2Index2View() {
// Create new IndexView
Index2View, V3, T> indexView = new Index2View<>(this.prefix, this.prefixMode,
new Tuple2FieldType<>(this.getValue1Type(), this.getValue2Type()), this.getValue3Type(), this.getTargetType());
// Get filters
final KeyFilter value1Filter = this.getFilter(0);
final KeyFilter value2Filter = this.getFilter(1);
final KeyFilter value3Filter = this.getFilter(2);
final KeyFilter targetFilter = this.getFilter(3);
// Apply filtering to tuple field
if (value1Filter != null || value2Filter != null) {
FieldTypesFilter tupleFilter = new FieldTypesFilter(null, this.getValue1Type(), this.getValue2Type());
if (value1Filter != null)
tupleFilter = tupleFilter.filter(0, value1Filter);
if (value2Filter != null)
tupleFilter = tupleFilter.filter(1, value2Filter);
indexView = indexView.filter(0, tupleFilter);
}
// Apply filtering to value field #3
if (value3Filter != null)
indexView = indexView.filter(1, value3Filter);
// Apply filtering to target field
if (targetFilter != null)
indexView = indexView.filter(2, targetFilter);
// Done
return indexView;
}
// Prefix view
public Index2View asIndex2View() {
// Create IndexView
Index2View indexView = new Index2View<>(this.prefix,
true, this.getValue1Type(), this.getValue2Type(), this.getValue3Type());
// Get filters
final KeyFilter value1Filter = this.getFilter(0);
final KeyFilter value2Filter = this.getFilter(1);
final KeyFilter value3Filter = this.getFilter(2);
// Apply filters
if (value1Filter != null)
indexView = indexView.filter(0, value1Filter);
if (value2Filter != null)
indexView = indexView.filter(1, value2Filter);
if (value3Filter != null)
indexView = indexView.filter(2, value3Filter);
// Done
return indexView;
}
// Suffix view
public Index2View asIndex2View(byte[] keyPrefix) {
// Create IndexView
Index2View indexView = new Index2View<>(keyPrefix,
this.prefixMode, this.getValue2Type(), this.getValue3Type(), this.getTargetType());
// Get filters
final KeyFilter value2Filter = this.getFilter(1);
final KeyFilter value3Filter = this.getFilter(2);
final KeyFilter targetFilter = this.getFilter(3);
// Apply filters
if (value2Filter != null)
indexView = indexView.filter(0, value2Filter);
if (value3Filter != null)
indexView = indexView.filter(1, value3Filter);
if (targetFilter != null)
indexView = indexView.filter(2, targetFilter);
// Done
return indexView;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy