com.googlecode.cqengine.index.hash.HashIndex Java Examples
The following examples show how to use
com.googlecode.cqengine.index.hash.HashIndex.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ReflectiveAttributeTest.java From cqengine with Apache License 2.0 | 6 votes |
@Test public void testReflectiveAttribute() { // Create an indexed collection (note: could alternatively use CQEngine.copyFrom() existing collection)... IndexedCollection<Car> cars = new ConcurrentIndexedCollection<Car>(); // Define an attribute which will use reflection... Attribute<Car, String> NAME = ReflectiveAttribute.forField(Car.class, String.class, "name"); cars.addIndex(HashIndex.onAttribute(NAME)); // Add some objects to the collection... cars.add(new Car(1, "ford focus", "great condition, low mileage", Arrays.asList("spare tyre", "sunroof"))); cars.add(new Car(2, "ford taurus", "dirty and unreliable, flat tyre", Arrays.asList("spare tyre", "radio"))); cars.add(new Car(3, "honda civic", "has a flat tyre and high mileage", Arrays.asList("radio"))); Assert.assertEquals(cars.retrieve(equal(NAME, "honda civic")).size(), 1); }
Example #2
Source File: DeduplicationTest.java From cqengine with Apache License 2.0 | 6 votes |
@Test public void testDeduplication_Materialize() { IndexedCollection<Car> cars = new ConcurrentIndexedCollection<Car>(); cars.add(new Car(1, "Ford", "Focus", BLUE, 5, 1000.0, Collections.<String>emptyList(), Collections.emptyList())); cars.addIndex(HashIndex.onAttribute(Car.COLOR)); cars.addIndex(HashIndex.onAttribute(Car.MANUFACTURER)); Query<Car> query = or( equal(COLOR, BLUE), equal(MANUFACTURER, "Ford") ); ResultSet<Car> results; results = cars.retrieve(query); assertEquals(2, results.size()); DeduplicationOption deduplicate = deduplicate(DeduplicationStrategy.MATERIALIZE); results = cars.retrieve(query, queryOptions(deduplicate)); assertEquals(1, results.size()); }
Example #3
Source File: DeduplicationTest.java From cqengine with Apache License 2.0 | 6 votes |
@Test public void testDeduplication_Logical() { IndexedCollection<Car> cars = new ConcurrentIndexedCollection<Car>(); cars.add(new Car(1, "Ford", "Focus", BLUE, 5, 1000.0, Collections.<String>emptyList(), Collections.emptyList())); cars.addIndex(HashIndex.onAttribute(Car.COLOR)); cars.addIndex(HashIndex.onAttribute(Car.MANUFACTURER)); Query<Car> query = or( equal(COLOR, BLUE), equal(MANUFACTURER, "Ford") ); ResultSet<Car> results; results = cars.retrieve(query); assertEquals(2, results.size()); DeduplicationOption deduplicate = deduplicate(DeduplicationStrategy.LOGICAL_ELIMINATION); results = cars.retrieve(query, queryOptions(deduplicate)); assertEquals(1, results.size()); }
Example #4
Source File: AttributeMetadataTest.java From cqengine with Apache License 2.0 | 6 votes |
@Test public void testGetKeysAndValues() { IndexedCollection<Car> cars = new ConcurrentIndexedCollection<>(); Car car1 = new Car(1, "Ford", "Taurus", Car.Color.GREEN, 4, 1000.0, emptyList(), Collections.emptyList()); Car car2 = new Car(2, "Honda", "Civic", Car.Color.BLUE, 4, 2000.0, emptyList(), Collections.emptyList()); Car car3 = new Car(3, "Honda", "Accord", Car.Color.RED, 4, 3000.0, emptyList(), Collections.emptyList()); cars.addAll(asList(car1, car2, car3)); // Add an unsorted index on Car.MANUFACTURER (a HashIndex)... cars.addIndex(HashIndex.onAttribute(Car.MANUFACTURER)); MetadataEngine<Car> metadataEngine = cars.getMetadataEngine(); // Access metadata for Car.MODEL attribute. // Because we call getAttributeMetadata() (and not getSortedAttributeMetadata()), // values will be returned in no particular order... AttributeMetadata<String, Car> attributeMetadata = metadataEngine.getAttributeMetadata(Car.MANUFACTURER); // Call AttributeMetadata.getDistinctKeys() to retrieve distinct keys in no particular order. // We retrieve into a Set (not a List), to assert the expected values were returned, without asserting any order... assertEquals( asSet(keyValue("Ford", car1), keyValue("Honda", car2), keyValue("Honda", car3)), attributeMetadata.getKeysAndValues().collect(toSet()) ); }
Example #5
Source File: UniqueIndexTest.java From cqengine with Apache License 2.0 | 6 votes |
@Test public void testUniqueIndex() { IndexedCollection<Car> cars = new ConcurrentIndexedCollection<Car>(); // Add some indexes... cars.addIndex(UniqueIndex.onAttribute(Car.CAR_ID)); cars.addIndex(HashIndex.onAttribute(Car.CAR_ID)); // Add some objects to the collection... cars.add(new Car(1, "ford focus", "great condition, low mileage", Arrays.asList("spare tyre", "sunroof"))); cars.add(new Car(2, "ford taurus", "dirty and unreliable, flat tyre", Arrays.asList("spare tyre", "radio"))); cars.add(new Car(3, "honda civic", "has a flat tyre and high mileage", Arrays.asList("radio"))); Query<Car> query = equal(Car.CAR_ID, 2); ResultSet<Car> rs = cars.retrieve(query); Assert.assertEquals("should prefer unique index over hash index", UniqueIndex.INDEX_RETRIEVAL_COST, rs.getRetrievalCost()); Assert.assertEquals("should retrieve car 2", 2, rs.uniqueResult().carId); }
Example #6
Source File: AttributeMetadataTest.java From cqengine with Apache License 2.0 | 6 votes |
@Test public void testGetDistinctKeys() { IndexedCollection<Car> cars = createIndexedCollectionOfCars(20); // the 20 cars will contain 10 distinct models // Add an unsorted index on Car.MODEL (a HashIndex)... cars.addIndex(HashIndex.onAttribute(Car.MODEL)); MetadataEngine<Car> metadataEngine = cars.getMetadataEngine(); // Access metadata for Car.MODEL attribute. // Because we call getAttributeMetadata() (and not getSortedAttributeMetadata()), // values will be returned in no particular order... AttributeMetadata<String, Car> attributeMetadata = metadataEngine.getAttributeMetadata(Car.MODEL); // Call AttributeMetadata.getDistinctKeys() to retrieve distinct keys in no particular order. // We retrieve into a Set (not a List), to assert the expected values were returned, without asserting any order... assertEquals( asSet("Accord", "Avensis", "Civic", "Focus", "Fusion", "Hilux", "Insight", "M6", "Prius", "Taurus"), attributeMetadata.getDistinctKeys().collect(toSet()) ); }
Example #7
Source File: AttributeMetadataTest.java From cqengine with Apache License 2.0 | 6 votes |
@Test public void testGetFrequencyDistribution() { IndexedCollection<Car> cars = createIndexedCollectionOfCars(20); // Add an unsorted index on Car.MANUFACTURER (a HashIndex)... cars.addIndex(HashIndex.onAttribute(Car.MANUFACTURER)); MetadataEngine<Car> metadataEngine = cars.getMetadataEngine(); // Access metadata for Car.MANUFACTURER attribute. // Because we call getAttributeMetadata() (and not getSortedAttributeMetadata()), // values will be returned in no particular order... AttributeMetadata<String, Car> sortedAttributeMetadata = metadataEngine.getAttributeMetadata(Car.MANUFACTURER); // Call AttributeMetadata.getFrequencyDistribution() to retrieve distinct keys and counts in no particular order. // We retrieve into a Set (not a List), to assert the expected values were returned, without asserting any order... assertEquals( asSet(frequency("Ford", 6), frequency("BMW", 2), frequency("Toyota", 6), frequency("Honda", 6)), sortedAttributeMetadata.getFrequencyDistribution().collect(toSet()) ); }
Example #8
Source File: MetadataEngineTest.java From cqengine with Apache License 2.0 | 6 votes |
@Test public void testAttemptToAccessMetadataWithIndexOnDifferentAttribute() { IndexedCollection<Car> cars = createIndexedCollectionOfCars(5); // Add an index on a different attribute... cars.addIndex(HashIndex.onAttribute(Car.MODEL)); // Create a mock (different) attribute we will query... @SuppressWarnings("unchecked") Attribute<Car, Integer> ATTRIBUTE = Mockito.mock(SimpleAttribute.class); Mockito.when(ATTRIBUTE.toString()).thenReturn("ATTRIBUTE"); IllegalStateException expected = null; try { cars.getMetadataEngine().getAttributeMetadata(ATTRIBUTE); } catch (IllegalStateException e) { expected = e; } assertNotNull(expected); assertEquals("A KeyStatisticsAttributeIndex has not been added to the collection, and must be added first, to enable metadata to be examined for attribute: ATTRIBUTE", expected.getMessage()); }
Example #9
Source File: AttributeMetadataTest.java From cqengine with Apache License 2.0 | 5 votes |
@Test public void testGetCountOfDistinctKeys() { IndexedCollection<Car> cars = createIndexedCollectionOfCars(20); // the 20 cars will contain 4 distinct manufacturers // Add an unsorted index on Car.MANUFACTURER (a HashIndex)... cars.addIndex(HashIndex.onAttribute(Car.MANUFACTURER)); MetadataEngine<Car> metadataEngine = cars.getMetadataEngine(); // Count the distinct manufacturers... AttributeMetadata<String, Car> attributeMetadata = metadataEngine.getAttributeMetadata(Car.MANUFACTURER); assertEquals(Integer.valueOf(4), attributeMetadata.getCountOfDistinctKeys()); }
Example #10
Source File: CollectionQueryEngineTest.java From cqengine with Apache License 2.0 | 5 votes |
@Test public void testAddNonDuplicateIndex() { CollectionQueryEngine<Car> queryEngine = new CollectionQueryEngine<Car>(); queryEngine.init(emptyObjectStore(), queryOptionsWithOnHeapPersistence()); queryEngine.addIndex(HashIndex.onAttribute(Car.MANUFACTURER), noQueryOptions()); queryEngine.addIndex(NavigableIndex.onAttribute(Car.MANUFACTURER), noQueryOptions()); }
Example #11
Source File: CollectionQueryEngineTest.java From cqengine with Apache License 2.0 | 5 votes |
@Test public void testRemoveIndex() { CollectionQueryEngine<Car> queryEngine = new CollectionQueryEngine<Car>(); queryEngine.init(emptyObjectStore(), queryOptionsWithOnHeapPersistence()); HashIndex<String, Car> index1 = HashIndex.onAttribute(Car.MANUFACTURER); queryEngine.addIndex(index1, noQueryOptions()); UniqueIndex<Integer, Car> index2 = UniqueIndex.onAttribute(Car.CAR_ID); queryEngine.addIndex(index2, noQueryOptions()); StandingQueryIndex<Car> index3 = StandingQueryIndex.onQuery(equal(Car.MODEL, "Focus")); queryEngine.addIndex(index3, noQueryOptions()); CompoundIndex<Car> index4 = CompoundIndex.onAttributes(Car.MANUFACTURER, Car.MODEL); queryEngine.addIndex(index4, noQueryOptions()); HashIndex<Boolean, Car> index5 = HashIndex.onAttribute(forStandingQuery(equal(Car.MANUFACTURER, "Ford"))); queryEngine.addIndex(index5, noQueryOptions()); Assert.assertEquals(5, countElements(queryEngine.getIndexes())); queryEngine.removeIndex(index1, noQueryOptions()); Assert.assertEquals(4, countElements(queryEngine.getIndexes())); queryEngine.removeIndex(index2, noQueryOptions()); Assert.assertEquals(3, countElements(queryEngine.getIndexes())); queryEngine.removeIndex(index3, noQueryOptions()); Assert.assertEquals(2, countElements(queryEngine.getIndexes())); queryEngine.removeIndex(index4, noQueryOptions()); Assert.assertEquals(1, countElements(queryEngine.getIndexes())); queryEngine.removeIndex(index5, noQueryOptions()); Assert.assertEquals(0, countElements(queryEngine.getIndexes())); }
Example #12
Source File: CollectionQueryEngineTest.java From cqengine with Apache License 2.0 | 5 votes |
static HashIndex<Integer, Car> createImmutableIndex() { HashIndex.DefaultIndexMapFactory<Integer, Car> defaultIndexMapFactory = new HashIndex.DefaultIndexMapFactory<Integer, Car>(); HashIndex.DefaultValueSetFactory<Car> defaultValueSetFactory = new HashIndex.DefaultValueSetFactory<Car>(); return new HashIndex<Integer, Car>(defaultIndexMapFactory, defaultValueSetFactory, Car.CAR_ID ) { @Override public boolean isMutable() { return false; } }; }
Example #13
Source File: Introduction.java From cqengine with Apache License 2.0 | 5 votes |
public static void main(String[] args) { // Create an indexed collection (note: could alternatively use CQEngine.copyFrom() existing collection)... IndexedCollection<Car> cars = new ConcurrentIndexedCollection<Car>(); // Add some indexes... cars.addIndex(NavigableIndex.onAttribute(Car.CAR_ID)); cars.addIndex(ReversedRadixTreeIndex.onAttribute(Car.NAME)); cars.addIndex(SuffixTreeIndex.onAttribute(Car.DESCRIPTION)); cars.addIndex(HashIndex.onAttribute(Car.FEATURES)); // Add some objects to the collection... cars.add(new Car(1, "ford focus", "great condition, low mileage", Arrays.asList("spare tyre", "sunroof"))); cars.add(new Car(2, "ford taurus", "dirty and unreliable, flat tyre", Arrays.asList("spare tyre", "radio"))); cars.add(new Car(3, "honda civic", "has a flat tyre and high mileage", Arrays.asList("radio"))); // -------------------------- Run some queries -------------------------- System.out.println("Cars whose name ends with 'vic' or whose id is less than 2:"); Query<Car> query1 = or(endsWith(Car.NAME, "vic"), lessThan(Car.CAR_ID, 2)); cars.retrieve(query1).forEach(System.out::println); System.out.println("\nCars whose flat tyre can be replaced:"); Query<Car> query2 = and(contains(Car.DESCRIPTION, "flat tyre"), equal(Car.FEATURES, "spare tyre")); cars.retrieve(query2).forEach(System.out::println); System.out.println("\nCars which have a sunroof or a radio but are not dirty:"); Query<Car> query3 = and(in(Car.FEATURES, "sunroof", "radio"), not(contains(Car.DESCRIPTION, "dirty"))); cars.retrieve(query3).forEach(System.out::println); }
Example #14
Source File: AttributeMetadataTest.java From cqengine with Apache License 2.0 | 5 votes |
@Test public void testGetCountForKey() { IndexedCollection<Car> cars = createIndexedCollectionOfCars(20); // Add an unsorted index on Car.MANUFACTURER (a HashIndex)... cars.addIndex(HashIndex.onAttribute(Car.MANUFACTURER)); MetadataEngine<Car> metadataEngine = cars.getMetadataEngine(); // Count the number of cars manufactured by BMW... AttributeMetadata<String, Car> attributeMetadata = metadataEngine.getAttributeMetadata(Car.MANUFACTURER); assertEquals(Integer.valueOf(2), attributeMetadata.getCountForKey("BMW")); }
Example #15
Source File: ConcurrentIndexedCollectionTest.java From cqengine with Apache License 2.0 | 5 votes |
public void testGetIndexes() { IndexedCollection<Car> indexedCollection = new ConcurrentIndexedCollection<Car>(); indexedCollection.addIndex(HashIndex.onAttribute(Car.CAR_ID), noQueryOptions()); List<Index<Car>> indexes = new ArrayList<Index<Car>>(); for (Index<Car> index : indexedCollection.getIndexes()) { indexes.add(index); } Assert.assertEquals(1, indexes.size()); Assert.assertEquals(HashIndex.class, indexes.get(0).getClass()); }
Example #16
Source File: ConcurrentIndexedCollectionTest.java From cqengine with Apache License 2.0 | 5 votes |
public void testRemoveIndex() { IndexedCollection<Car> indexedCollection = new ConcurrentIndexedCollection<Car>(); HashIndex<Integer, Car> index = HashIndex.onAttribute(Car.CAR_ID); indexedCollection.addIndex(index); Assert.assertEquals(1, IteratorUtil.countElements(indexedCollection.getIndexes())); indexedCollection.removeIndex(index); Assert.assertEquals(0, IteratorUtil.countElements(indexedCollection.getIndexes())); }
Example #17
Source File: TilingImplementation.java From BIMserver with GNU Affero General Public License v3.0 | 5 votes |
public TilingImplementation(Octree octree) { this.octree = octree; objects.addIndex(HashIndex.onAttribute(CROID)); objects.addIndex(HashIndex.onAttribute(ECLASS)); objects.addIndex(HashIndex.onAttribute(TILE_ID)); objects.addIndex(HashIndex.onAttribute(TILE_LEVEL)); objects.addIndex(HashIndex.onAttribute(DENSITY)); objects.addIndex(HashIndex.onAttribute(ORDER)); for (Node node : octree.values()) { for (GeometryObject geometryObject : node.getValues()) { objects.add(geometryObject); } } }
Example #18
Source File: CollectionQueryEngineTest.java From cqengine with Apache License 2.0 | 5 votes |
@Test(expected = IllegalStateException.class) public void testAddDuplicateIndex() { CollectionQueryEngine<Car> queryEngine = new CollectionQueryEngine<Car>(); queryEngine.init(emptyObjectStore(), queryOptionsWithOnHeapPersistence()); queryEngine.addIndex(HashIndex.onAttribute(Car.MANUFACTURER), noQueryOptions()); queryEngine.addIndex(HashIndex.onAttribute(Car.MANUFACTURER), noQueryOptions()); }
Example #19
Source File: AbstractCQEngineSyncTarget.java From domino-jna with Apache License 2.0 | 5 votes |
public AbstractCQEngineSyncTarget() { m_lastSyncEndDates = new HashMap<String, NotesTimeDate>(); m_indexCollection = createCollection(); //make sure we have an index for the UNID m_indexCollection.addIndex((Index<T>) HashIndex.onAttribute(OBJ_UNID)); addIndices(m_indexCollection); }
Example #20
Source File: HashIndex_ManufacturerFord.java From cqengine with Apache License 2.0 | 5 votes |
@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(HashIndex.onAttribute(Car.MANUFACTURER)); }
Example #21
Source File: HashIndex_CarId.java From cqengine with Apache License 2.0 | 5 votes |
@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( HashIndex.onAttribute(Car.CAR_ID) ); }
Example #22
Source File: NonOptimalIndexes_ManufacturerToyotaColorBlueDoorsThree.java From cqengine with Apache License 2.0 | 5 votes |
@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(HashIndex.onAttribute(Car.DOORS)); }
Example #23
Source File: Quantized_HashIndex_CarId.java From cqengine with Apache License 2.0 | 5 votes |
@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( HashIndex.withQuantizerOnAttribute(IntegerQuantizer.withCompressionFactor(5), Car.CAR_ID) ); }
Example #24
Source File: HashIndex_ModelFocus.java From cqengine with Apache License 2.0 | 5 votes |
@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(HashIndex.onAttribute(Car.MODEL)); }
Example #25
Source File: HashIndex_Manufacturer.java From cqengine with Apache License 2.0 | 4 votes |
@Override public void buildIndex() { indexedCollection.addIndex(HashIndex.onAttribute(Car.MANUFACTURER)); }
Example #26
Source File: HashIndex_Model.java From cqengine with Apache License 2.0 | 4 votes |
@Override public void buildIndex() { indexedCollection.addIndex(HashIndex.onAttribute(Car.MODEL)); }
Example #27
Source File: HashIndex_CarId.java From cqengine with Apache License 2.0 | 4 votes |
@Override public void buildIndex() { indexedCollection.addIndex(HashIndex.onAttribute(Car.CAR_ID)); }
Example #28
Source File: Quantized_HashIndex_CarId.java From cqengine with Apache License 2.0 | 4 votes |
@Override public void buildIndex() { indexedCollection.addIndex(HashIndex.withQuantizerOnAttribute(IntegerQuantizer.withCompressionFactor(10), Car.CAR_ID)); }
Example #29
Source File: GeneralFunctionalTest.java From cqengine with Apache License 2.0 | 4 votes |
@Test public void testGeneralFunctionality() { IndexedCollection<Car> cars = new ConcurrentIndexedCollection<Car>(); cars.addIndex(HashIndex.onAttribute(Car.MODEL)); cars.addIndex(HashIndex.onAttribute(Car.COLOR)); cars.addIndex(NavigableIndex.onAttribute(Car.DOORS)); cars.addIndex(RadixTreeIndex.onAttribute(Car.MODEL)); cars.addIndex(ReversedRadixTreeIndex.onAttribute(Car.MODEL)); cars.addIndex(InvertedRadixTreeIndex.onAttribute(Car.MODEL)); cars.addIndex(SuffixTreeIndex.onAttribute(Car.MODEL)); cars.add(new Car(1, "Ford", "Focus", Car.Color.BLUE, 5, 9000.50, Collections.<String>emptyList(), Collections.emptyList())); cars.add(new Car(2, "Ford", "Fiesta", Car.Color.BLUE, 2, 5000.00, Collections.<String>emptyList(), Collections.emptyList())); cars.add(new Car(3, "Ford", "F-150", Car.Color.RED, 2, 9500.00, Collections.<String>emptyList(), Collections.emptyList())); cars.add(new Car(4, "Honda", "Civic", Car.Color.RED, 5, 5000.00, Collections.<String>emptyList(), Collections.emptyList())); cars.add(new Car(5, "Toyota", "Prius", Car.Color.BLACK, 3, 9700.00, Collections.<String>emptyList(), Collections.emptyList())); // Ford cars... assertThat(carIdsIn(cars.retrieve(equal(Car.MANUFACTURER, "Ford"))), is(setOf(1, 2, 3))); // 3-door cars... assertThat(carIdsIn(cars.retrieve(equal(Car.DOORS, 3))), is(setOf(5))); // 2 or 3-door cars... assertThat(carIdsIn(cars.retrieve(between(Car.DOORS, 2, 3))), is(setOf(2, 3, 5))); // 2 or 5-door cars... assertThat(carIdsIn(cars.retrieve(in(Car.DOORS, 2, 5))), is(setOf(1, 2, 3, 4))); // Blue Ford cars... assertThat(carIdsIn(cars.retrieve(and(equal(Car.COLOR, Car.Color.BLUE), equal(Car.MANUFACTURER, "Ford")))), is(setOf(1, 2))); // NOT 3-door cars... assertThat(carIdsIn(cars.retrieve(not(equal(Car.DOORS, 3)))), is(setOf(1, 2, 3, 4))); // Cars which have 5 doors and which are not red... assertThat(carIdsIn(cars.retrieve(and(equal(Car.DOORS, 5), not(equal(Car.COLOR, Car.Color.RED))))), is(setOf(1))); // Cars whose model starts with 'F'... assertThat(carIdsIn(cars.retrieve(startsWith(Car.MODEL, "F"))), is(setOf(1, 2, 3))); // Cars whose model ends with 's'... assertThat(carIdsIn(cars.retrieve(endsWith(Car.MODEL, "s"))), is(setOf(1, 5))); // Cars whose model contains 'i'... assertThat(carIdsIn(cars.retrieve(contains(Car.MODEL, "i"))), is(setOf(2, 4, 5))); // Cars whose model is contained in 'Banana, Focus, Civic, Foobar'... assertThat(carIdsIn(cars.retrieve(isContainedIn(Car.MODEL, "Banana, Focus, Civic, Foobar"))), is(setOf(1, 4))); // NOT 3-door cars, sorted by doors ascending... assertThat( carIdsIn(cars.retrieve(not(equal(Car.DOORS, 3)), queryOptions(orderBy(ascending(Car.DOORS))))).toString(), is(equalTo(setOf(2, 3, 1, 4).toString())) ); // NOT 3-door cars, sorted by doors ascending then price descending... assertThat( carIdsIn( cars.retrieve( not(equal(Car.DOORS, 3)), queryOptions( orderBy(ascending(Car.DOORS), descending(Car.PRICE)) ) ) ).toString(), is(equalTo(setOf(3, 2, 1, 4).toString())) ); }
Example #30
Source File: RegularMapTest.java From cqengine with Apache License 2.0 | 4 votes |
@Test public void testMapFunctionality() { IndexedCollection<Map> cars = new ConcurrentIndexedCollection<Map>(); cars.addIndex(HashIndex.onAttribute(COLOR)); cars.addIndex(NavigableIndex.onAttribute(DOORS)); cars.addIndex(RadixTreeIndex.onAttribute(MODEL)); cars.addIndex(ReversedRadixTreeIndex.onAttribute(MODEL)); cars.addIndex(InvertedRadixTreeIndex.onAttribute(MODEL)); cars.addIndex(SuffixTreeIndex.onAttribute(MODEL)); cars.add(buildNewCar(1, "Ford", "Focus", Car.Color.BLUE, 5, 9000.50, Collections.<String>emptyList())); cars.add(buildNewCar(2, "Ford", "Fiesta", Car.Color.BLUE, 2, 5000.00, Collections.<String>emptyList())); cars.add(buildNewCar(3, "Ford", "F-150", Car.Color.RED, 2, 9500.00, Collections.<String>emptyList())); cars.add(buildNewCar(4, "Honda", "Civic", Car.Color.RED, 5, 5000.00, Collections.<String>emptyList())); cars.add(buildNewCar(5, "Toyota", "Prius", Car.Color.BLACK, 3, 9700.00, Collections.<String>emptyList())); // Ford cars... assertThat(carIdsIn(cars.retrieve(equal(MANUFACTURER, "Ford"))), is(setOf(1, 2, 3))); // 3-door cars... assertThat(carIdsIn(cars.retrieve(equal(DOORS, 3))), is(setOf(5))); // 2 or 3-door cars... assertThat(carIdsIn(cars.retrieve(between(DOORS, 2, 3))), is(setOf(2, 3, 5))); // 2 or 5-door cars... assertThat(carIdsIn(cars.retrieve(in(DOORS, 2, 5))), is(setOf(1, 2, 3, 4))); // Blue Ford cars... assertThat(carIdsIn(cars.retrieve(and(equal(COLOR, Car.Color.BLUE), equal(MANUFACTURER, "Ford")))), is(setOf(1, 2))); // NOT 3-door cars... assertThat(carIdsIn(cars.retrieve(not(equal(DOORS, 3)))), is(setOf(1, 2, 3, 4))); // Cars which have 5 doors and which are not red... assertThat(carIdsIn(cars.retrieve(and(equal(DOORS, 5), not(equal(COLOR, Car.Color.RED))))), is(setOf(1))); // Cars whose model starts with 'F'... assertThat(carIdsIn(cars.retrieve(startsWith(MODEL, "F"))), is(setOf(1, 2, 3))); // Cars whose model ends with 's'... assertThat(carIdsIn(cars.retrieve(endsWith(MODEL, "s"))), is(setOf(1, 5))); // Cars whose model contains 'i'... assertThat(carIdsIn(cars.retrieve(contains(MODEL, "i"))), is(setOf(2, 4, 5))); // Cars whose model is contained in 'Banana, Focus, Civic, Foobar'... assertThat(carIdsIn(cars.retrieve(isContainedIn(MODEL, "Banana, Focus, Civic, Foobar"))), is(setOf(1, 4))); // NOT 3-door cars, sorted by doors ascending... assertThat( carIdsIn(cars.retrieve(not(equal(DOORS, 3)), queryOptions(orderBy(ascending(DOORS), ascending(MODEL))))).toString(), is(equalTo(setOf(3, 2, 4, 1).toString())) ); // NOT 3-door cars, sorted by doors ascending then price descending... assertThat( carIdsIn( cars.retrieve( not(equal(DOORS, 3)), queryOptions( orderBy(ascending(DOORS), descending(PRICE)) ) ) ), is(equalTo(setOf(3, 2, 1, 4))) ); }