-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added support for non-unique Multi-Indices
A single value can be assigned to a set of index keys. Each index key alone can be used to access the object
- Loading branch information
Showing
9 changed files
with
591 additions
and
213 deletions.
There are no files selected for viewing
63 changes: 63 additions & 0 deletions
63
src/main/java/org/jacis/index/AbstractJacisMultiIndex.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package org.jacis.index; | ||
|
||
import org.jacis.JacisApi; | ||
|
||
import java.util.Set; | ||
import java.util.function.Function; | ||
|
||
/** | ||
* Abstract base class for Jacis Indices where one value object can have multiple index keys. | ||
* | ||
* @param <IK> Index key type for this unique index | ||
* @param <K> Key type of the store entry | ||
* @param <TV> Type of the objects in the transaction view. This is the type visible from the outside. | ||
* @author Jan Wiemer | ||
*/ | ||
@JacisApi | ||
public abstract class AbstractJacisMultiIndex<IK, K, TV> { | ||
|
||
/** Name of the index used to register it at the store. The index names have to be unique for one store. */ | ||
protected final String indexName; | ||
/** Reference to the index registry storing all indices registered for a store. */ | ||
protected final JacisIndexRegistry<K, TV> indexRegistry; | ||
/** Function defining how to compute the set of index keys from the value stored in the store. */ | ||
protected final Function<TV, Set<IK>> indexKeyFunction; | ||
|
||
AbstractJacisMultiIndex(String indexName, Function<TV, Set<IK>> indexKeyFunction, JacisIndexRegistry<K, TV> indexRegistry) { | ||
this.indexName = indexName; | ||
this.indexKeyFunction = indexKeyFunction; | ||
this.indexRegistry = indexRegistry; | ||
} | ||
|
||
/** @return the name of the index (the name used to register the index during creation). */ | ||
public String getIndexName() { | ||
return indexName; | ||
} | ||
|
||
/** @return The function to compute the set of the index keys from the stored value. */ | ||
Function<TV, Set<IK>> getIndexKeyFunction() { | ||
return indexKeyFunction; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return getClass().getSimpleName() + "(" + indexName + ")"; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return indexName.hashCode(); | ||
} | ||
|
||
@SuppressWarnings("unchecked") | ||
@Override | ||
public boolean equals(Object that) { | ||
if (that == null) { | ||
return false; | ||
} | ||
if (!this.getClass().equals(that.getClass())) { | ||
return false; | ||
} | ||
return this.indexName.equals(((AbstractJacisMultiIndex<IK, K, TV>) that).indexName); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.