本文整理汇总了Java中com.googlecode.cqengine.index.navigable.NavigableIndex类的典型用法代码示例。如果您正苦于以下问题:Java NavigableIndex类的具体用法?Java NavigableIndex怎么用?Java NavigableIndex使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
NavigableIndex类属于com.googlecode.cqengine.index.navigable包,在下文中一共展示了NavigableIndex类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createIndex
import com.googlecode.cqengine.index.navigable.NavigableIndex; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public void createIndex(String fieldName, boolean multiValued) {
if (!holder.indexed.contains(fieldName)) {
synchronized (maps) {
if (!holder.indexed.contains(fieldName)) {
try {
Attribute<Value, String> attribute = getAttribute(fieldName, multiValued);
holder.attributes.put(fieldName, attribute);
holder.db.addIndex(NavigableIndex.onAttribute(attribute));
holder.db.addIndex(RadixTreeIndex.onAttribute(attribute));
} catch (Throwable e) {
context.logger(getClass()).onError(e);
} finally {
holder.indexed.add(fieldName);
}
}
}
}
}
示例2: main
import com.googlecode.cqengine.index.navigable.NavigableIndex; //导入依赖的package包/类
public static void main(String[] args) {
final int NUM_ITERATIONS = 1000;
final int[] numObjects = {10000, 10000, 100000};
final double[] selectivityThreshold = {0.0, 0.5, 1.0};
IndexedCollection<Car> cars = new ConcurrentIndexedCollection<Car>();
cars.addAll(CarFactory.createCollectionOfCars(1000000));
cars.addIndex(NavigableIndex.onAttribute(Car.CAR_ID));
cars.addIndex(NavigableIndex.onAttribute(Car.COLOR));
for (int n : numObjects) {
for (double s : selectivityThreshold) {
long start = System.currentTimeMillis();
long count = 0;
for (int i = 0; i < NUM_ITERATIONS; i++) {
count = countRetrievedResults(cars, n, s);
}
long timeTaken = System.currentTimeMillis() - start;
System.out.println("Number: " + n + ", selectivity threshold: " + s + ", time taken per iteration: " + (timeTaken / (double)NUM_ITERATIONS) + " (count=" + count + ")");
}
}
}
示例3: main
import com.googlecode.cqengine.index.navigable.NavigableIndex; //导入依赖的package包/类
public static void main(String[] args) {
IndexedCollection<Car> cars = new ConcurrentIndexedCollection<Car>();
cars.addIndex(NavigableIndex.onAttribute(Car.FEATURES));
cars.addIndex(NavigableIndex.onAttribute(forObjectsMissing(Car.FEATURES)));
cars.addAll(CarFactory.createCollectionOfCars(100));
ResultSet<Car> results = cars.retrieve(
between(Car.CAR_ID, 40, 50),
queryOptions(
orderBy(ascending(missingLast(Car.FEATURES))),
applyThresholds(threshold(INDEX_ORDERING_SELECTIVITY, 1.0))
)
);
for (Car car : results) {
System.out.println(car); // prints cars 40 -> 50, using the index on Car.FEATURES to accelerate ordering
}
}
示例4: testInMany
import com.googlecode.cqengine.index.navigable.NavigableIndex; //导入依赖的package包/类
@Test
public void testInMany() {
// Create an indexed collection (note: could alternatively use CQEngine.copyFrom() existing collection)...
IndexedCollection<Car> cars = new ConcurrentIndexedCollection<Car>();
Attribute<Car, String> NAME = new SimpleNullableAttribute<Car, String>("name") {
public String getValue(Car car, QueryOptions queryOptions) {
return car.name;
}
};
cars.addIndex(NavigableIndex.onAttribute(NAME));
// Add some objects to the collection...
cars.add(new Car(1, "ford", null, null));
cars.add(new Car(2, "honda", null, null));
cars.add(new Car(3, "toyota", null, null));
Assert.assertEquals(cars.retrieve(in(NAME, "ford", "honda")).size(), 2);
Assert.assertEquals(cars.retrieve(in(NAME, Arrays.asList("ford", "honda"))).size(), 2);
}
示例5: testInOne
import com.googlecode.cqengine.index.navigable.NavigableIndex; //导入依赖的package包/类
@Test
public void testInOne() {
// Create an indexed collection (note: could alternatively use CQEngine.copyFrom() existing collection)...
IndexedCollection<Car> cars = new ConcurrentIndexedCollection<Car>();
Attribute<Car, String> NAME = new SimpleNullableAttribute<Car, String>("name") {
public String getValue(Car car, QueryOptions queryOptions) {
return car.name;
}
};
cars.addIndex(NavigableIndex.onAttribute(NAME));
// Add some objects to the collection...
cars.add(new Car(1, "ford", null, null));
cars.add(new Car(2, "honda", null, null));
cars.add(new Car(3, "toyota", null, null));
Assert.assertEquals(cars.retrieve(in(NAME, "ford")).size(), 1);
Assert.assertEquals(cars.retrieve(in(NAME, Collections.singletonList("ford"))).size(), 1);
}
示例6: testInNone
import com.googlecode.cqengine.index.navigable.NavigableIndex; //导入依赖的package包/类
@Test
public void testInNone() {
// Create an indexed collection (note: could alternatively use CQEngine.copyFrom() existing collection)...
IndexedCollection<Car> cars = new ConcurrentIndexedCollection<Car>();
Attribute<Car, String> NAME = new SimpleNullableAttribute<Car, String>("name") {
public String getValue(Car car, QueryOptions queryOptions) {
return car.name;
}
};
cars.addIndex(NavigableIndex.onAttribute(NAME));
// Add some objects to the collection...
cars.add(new Car(1, "ford", null, null));
cars.add(new Car(2, "honda", null, null));
cars.add(new Car(3, "toyota", null, null));
Assert.assertEquals(cars.retrieve(in(NAME)).size(), 0);
Assert.assertEquals(cars.retrieve(in(NAME, new ArrayList<String>())).size(), 0);
}
示例7: getIndexMatrix
import com.googlecode.cqengine.index.navigable.NavigableIndex; //导入依赖的package包/类
@Override
protected List<IndexCapabilities> getIndexMatrix() {
return Arrays.asList(
new IndexCapabilities<Attribute>("Hash",
new IndexFeature[]{IndexFeature.EQ, IndexFeature.IN, IndexFeature.QZ},
attr -> HashIndex.onAttribute(compatibleAttribute(attr))),
new IndexCapabilities<Attribute>("Unique",
new IndexFeature[]{IndexFeature.UNIQUE, IndexFeature.EQ, IndexFeature.IN},
attr -> UniqueIndex.onAttribute(compatibleAttribute(attr))),
new IndexCapabilities<Attribute[]>("Compound",
new IndexFeature[]{IndexFeature.COMPOUND, IndexFeature.EQ, IndexFeature.IN, IndexFeature.QZ},
attrs -> {
Attribute[] attributes = (Attribute[]) Arrays.stream(attrs)
.map(attr -> compatibleAttribute(attr))
.toArray();
return CompoundIndex.onAttributes(attributes);
}),
new IndexCapabilities<Attribute>("Navigable",
new IndexFeature[]{IndexFeature.EQ, IndexFeature.IN, IndexFeature.QZ, IndexFeature.LT, IndexFeature.GT, IndexFeature.BT},
attr -> NavigableIndex.onAttribute(compatibleAttribute(attr))),
new IndexCapabilities<Attribute>("RadixTree",
new IndexFeature[]{IndexFeature.EQ, IndexFeature.IN, IndexFeature.SW},
attr -> RadixTreeIndex.onAttribute(compatibleAttribute(attr))),
new IndexCapabilities<Attribute>("ReversedRadixTree",
new IndexFeature[]{IndexFeature.EQ, IndexFeature.IN, IndexFeature.EW},
attr -> ReversedRadixTreeIndex.onAttribute(compatibleAttribute(attr))),
new IndexCapabilities<Attribute>("InvertedRadixTree",
new IndexFeature[]{IndexFeature.EQ, IndexFeature.IN, IndexFeature.CI},
attr -> InvertedRadixTreeIndex.onAttribute(compatibleAttribute(attr))),
new IndexCapabilities<Attribute>("SuffixTree",
new IndexFeature[]{IndexFeature.EQ, IndexFeature.IN, IndexFeature.EW, IndexFeature.SC},
attr -> SuffixTreeIndex.onAttribute(compatibleAttribute(attr)))
);
}
示例8: getIndex
import com.googlecode.cqengine.index.navigable.NavigableIndex; //导入依赖的package包/类
/**
*
* @param attr the attribute against which the
* index will be built
* @return an instance of {@link NavigableIndex}
*/
@Override @SuppressWarnings({"unchecked","rawtypes"})
public Index<O> getIndex(Attribute<O,?> attribute) {
if(Comparable.class.isAssignableFrom(attribute.getAttributeType()))
return NavigableIndex.onAttribute((Attribute < O, ? extends Comparable>)attribute);
throw new IllegalArgumentException(NavigableIndex.class.getName()
+ " cannot be applied on "
+ attribute.getAttributeName()
+ " because it does not extend "
+ Comparable.class.getName());
}
示例9: indexCollection
import com.googlecode.cqengine.index.navigable.NavigableIndex; //导入依赖的package包/类
private void indexCollection(List<Item> list) {
items.addAll(list);
items.addIndex(HashIndex.onAttribute(Item.ITEM_ID));
items.addIndex(HashIndex.onAttribute(Item.ITEM_NAME));
items.addIndex(SuffixTreeIndex.onAttribute(Item.ITEM_NAME));
items.addIndex(SuffixTreeIndex.onAttribute(Item.ITEM_DESCRIPTION));
items.addIndex(NavigableIndex.onAttribute(Item.ITEM_QUANTITY));
}
示例10: init
import com.googlecode.cqengine.index.navigable.NavigableIndex; //导入依赖的package包/类
@Override
public void init(Collection<Car> collection) {
this.collection = collection;
IndexedCollection<Car> indexedCollection1 = new ConcurrentIndexedCollection<Car>();
indexedCollection1.addAll(collection);
this.indexedCollection = indexedCollection1;
this.indexedCollection.addIndex(NavigableIndex.onAttribute(Car.PRICE));
}
示例11: init
import com.googlecode.cqengine.index.navigable.NavigableIndex; //导入依赖的package包/类
@Override
public void init(Collection<Car> collection) {
this.collection = collection;
IndexedCollection<Car> indexedCollection1 = new ConcurrentIndexedCollection<Car>();
indexedCollection1.addAll(collection);
this.indexedCollection = indexedCollection1;
this.indexedCollection.addIndex(
NavigableIndex.withQuantizerOnAttribute(IntegerQuantizer.withCompressionFactor(5), Car.CAR_ID)
);
}
示例12: newAutoIndexedCollection
import com.googlecode.cqengine.index.navigable.NavigableIndex; //导入依赖的package包/类
/**
* Creates an IndexedCollection and adds NavigableIndexes for the given attributes.
*
* @param attributes Attributes for which indexes should be added
* @param <O> Type of objects stored in the collection
* @return An IndexedCollection configured with indexes on the given attributes.
*/
public static <O> IndexedCollection<O> newAutoIndexedCollection(Iterable<Attribute<O, Comparable>> attributes) {
IndexedCollection<O> autoIndexedCollection = new ConcurrentIndexedCollection<O>();
for (Attribute<O, ? extends Comparable> attribute : attributes) {
// Add a NavigableIndex...
@SuppressWarnings("unchecked")
NavigableIndex<? extends Comparable, O> index = NavigableIndex.onAttribute(attribute);
autoIndexedCollection.addIndex(index);
}
return autoIndexedCollection;
}
示例13: testAddNonDuplicateIndex
import com.googlecode.cqengine.index.navigable.NavigableIndex; //导入依赖的package包/类
@Test
public void testAddNonDuplicateIndex() throws Exception {
CollectionQueryEngine<Car> queryEngine = new CollectionQueryEngine<Car>();
QueryOptions queryOptions = new QueryOptions();
queryOptions.put(Persistence.class, OnHeapPersistence.withoutPrimaryKey());
queryEngine.init(emptyObjectStore(), queryOptions);
queryEngine.addIndex(HashIndex.onAttribute(Car.MANUFACTURER), noQueryOptions());
queryEngine.addIndex(NavigableIndex.onAttribute(Car.MANUFACTURER), noQueryOptions());
}
示例14: testWrappingPersistence
import com.googlecode.cqengine.index.navigable.NavigableIndex; //导入依赖的package包/类
@Test
public void testWrappingPersistence() {
Collection<Car> backingCollection = new LinkedHashSet<Car>();
backingCollection.addAll(CarFactory.createCollectionOfCars(3)); // CarIds 0, 1, 2
IndexedCollection<Car> indexedCollection = new ConcurrentIndexedCollection<Car>(
WrappingPersistence.aroundCollection(backingCollection)
);
indexedCollection.addIndex(NavigableIndex.onAttribute(Car.CAR_ID));
ResultSet<Car> results = indexedCollection.retrieve(greaterThan(Car.CAR_ID, 0));
// Assert that the index will be used...
assertNotEquals(Integer.MAX_VALUE, results.getRetrievalCost());
// Assert correct results are returned...
Set<Integer> expectedCarIds, actualCarIds;
expectedCarIds = asSet(1, 2);
actualCarIds = extractCarIds(results, new HashSet<Integer>());
assertEquals(expectedCarIds, actualCarIds);
// Add that a new object added to the IndexedCollection...
indexedCollection.add(CarFactory.createCar(3));
// Assert the new object was added to the backing collection...
expectedCarIds = asSet(0, 1, 2, 3);
actualCarIds = extractCarIds(backingCollection, new HashSet<Integer>());
assertEquals(expectedCarIds, actualCarIds);
}
示例15: testSupportsIndex
import com.googlecode.cqengine.index.navigable.NavigableIndex; //导入依赖的package包/类
@Test
public void testSupportsIndex() throws Exception {
WrappingPersistence<Car, Integer> wrappingPersistence =
WrappingPersistence.aroundCollectionOnPrimaryKey(new HashSet<Car>(), Car.CAR_ID);
assertTrue(wrappingPersistence.supportsIndex(NavigableIndex.onAttribute(Car.MANUFACTURER)));
assertFalse(wrappingPersistence.supportsIndex(DiskIndex.onAttribute(Car.MANUFACTURER)));
}