当前位置: 首页>>代码示例>>Java>>正文


Java NavigableIndex类代码示例

本文整理汇总了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);
                }
            }
        }
    }
}
 
开发者ID:codingchili,项目名称:chili-core,代码行数:21,代码来源:IndexedMap.java

示例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 + ")");
        }
    }
}
 
开发者ID:npgall,项目名称:cqengine,代码行数:24,代码来源:IndexOrderingTest.java

示例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
    }
}
 
开发者ID:npgall,项目名称:cqengine,代码行数:18,代码来源:IndexOrderingDemo.java

示例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);
}
 
开发者ID:npgall,项目名称:cqengine,代码行数:21,代码来源:InTest.java

示例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);
}
 
开发者ID:npgall,项目名称:cqengine,代码行数:21,代码来源:InTest.java

示例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);
}
 
开发者ID:npgall,项目名称:cqengine,代码行数:21,代码来源:InTest.java

示例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)))
    );

}
 
开发者ID:eventsourcing,项目名称:es4j,代码行数:36,代码来源:MemoryIndexEngine.java

示例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());
}
 
开发者ID:cr0wbar,项目名称:Bananarama,代码行数:18,代码来源:NavigableIndexProvider.java

示例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));
}
 
开发者ID:jfunktor,项目名称:RxFunktor,代码行数:9,代码来源:ItemDB.java

示例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));
}
 
开发者ID:npgall,项目名称:cqengine,代码行数:9,代码来源:NavigableIndex_PriceBetween.java

示例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)
    );
}
 
开发者ID:npgall,项目名称:cqengine,代码行数:11,代码来源:Quantized_NavigableIndex_CarId.java

示例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;
}
 
开发者ID:npgall,项目名称:cqengine,代码行数:18,代码来源:DynamicIndexer.java

示例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());
}
 
开发者ID:npgall,项目名称:cqengine,代码行数:11,代码来源:CollectionQueryEngineTest.java

示例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);
}
 
开发者ID:npgall,项目名称:cqengine,代码行数:31,代码来源:WrappingPersistenceTest.java

示例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)));
}
 
开发者ID:npgall,项目名称:cqengine,代码行数:9,代码来源:WrappingPersistenceTest.java


注:本文中的com.googlecode.cqengine.index.navigable.NavigableIndex类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。