本文整理汇总了Java中com.googlecode.cqengine.IndexedCollection.addAll方法的典型用法代码示例。如果您正苦于以下问题:Java IndexedCollection.addAll方法的具体用法?Java IndexedCollection.addAll怎么用?Java IndexedCollection.addAll使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.googlecode.cqengine.IndexedCollection
的用法示例。
在下文中一共展示了IndexedCollection.addAll方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getDistinctKeysAndCounts
import com.googlecode.cqengine.IndexedCollection; //导入方法依赖的package包/类
@Test
public void getDistinctKeysAndCounts() {
IndexedCollection<EntityHandle<Car>> collection = new ConcurrentIndexedCollection<>();
SortedKeyStatisticsIndex<String, EntityHandle<Car>> MODEL_INDEX = onAttribute(Car.MODEL);
MODEL_INDEX.clear(noQueryOptions());
collection.addIndex(MODEL_INDEX);
collection.addAll(CarFactory.createCollectionOfCars(20));
Set<String> distinctModels = setOf(MODEL_INDEX.getDistinctKeys(noQueryOptions()));
assertEquals(new ArrayList<>(distinctModels),
asList("Accord", "Avensis", "Civic", "Focus", "Fusion", "Hilux", "Insight", "M6", "Prius",
"Taurus"));
for (String model : distinctModels) {
assertEquals(MODEL_INDEX.getCountForKey(model, noQueryOptions()), Integer.valueOf(2));
}
Set<String> distinctModelsDescending = setOf(MODEL_INDEX.getDistinctKeysDescending(noQueryOptions()));
assertEquals(new ArrayList<>(distinctModelsDescending),
asList("Taurus", "Prius", "M6", "Insight", "Hilux", "Fusion", "Focus", "Civic", "Avensis",
"Accord"));
}
示例2: indexExistingData
import com.googlecode.cqengine.IndexedCollection; //导入方法依赖的package包/类
@Test
public void indexExistingData() {
IndexedCollection<EntityHandle<Car>> collection = new ConcurrentIndexedCollection<>();
KeyStatisticsIndex<String, EntityHandle<Car>> MANUFACTURER_INDEX =
(KeyStatisticsIndex<String, EntityHandle<Car>>) onAttribute(Car.MANUFACTURER);
MANUFACTURER_INDEX.clear(noQueryOptions());
collection.addAll(CarFactory.createCollectionOfCars(10));
collection.addIndex(MANUFACTURER_INDEX);
ResultSet<EntityHandle<Car>> cars = collection.retrieve(equal(Car.MANUFACTURER, "Honda"));
assertTrue(cars.isNotEmpty());
assertTrue(streamOf(cars).allMatch(car -> car.get().getManufacturer().contentEquals("Honda")));
cars.close();
MANUFACTURER_INDEX.clear(noQueryOptions());
}
示例3: getStatisticsForDistinctKeys
import com.googlecode.cqengine.IndexedCollection; //导入方法依赖的package包/类
@Test
public void getStatisticsForDistinctKeys() {
IndexedCollection<EntityHandle<Car>> collection = new ConcurrentIndexedCollection<>();
KeyStatisticsIndex<String, EntityHandle<Car>> MANUFACTURER_INDEX = onAttribute(Car.MANUFACTURER);
MANUFACTURER_INDEX.clear(noQueryOptions());
collection.addIndex(MANUFACTURER_INDEX);
collection.addAll(CarFactory.createCollectionOfCars(20));
Set<KeyStatistics<String>> keyStatistics = setOf(
MANUFACTURER_INDEX.getStatisticsForDistinctKeys(noQueryOptions()));
assertEquals(keyStatistics, setOf(
new KeyStatistics<>("Ford", 6),
new KeyStatistics<>("Honda", 6),
new KeyStatistics<>("Toyota", 6),
new KeyStatistics<>("BMW", 2)
));
}
示例4: getStatisticsForDistinctKeysDescending
import com.googlecode.cqengine.IndexedCollection; //导入方法依赖的package包/类
@Test
public void getStatisticsForDistinctKeysDescending() {
IndexedCollection<EntityHandle<Car>> collection = new ConcurrentIndexedCollection<>();
SortedKeyStatisticsIndex<String, EntityHandle<Car>> MANUFACTURER_INDEX = onAttribute(Car.MANUFACTURER);
MANUFACTURER_INDEX.clear(noQueryOptions());
collection.addIndex(MANUFACTURER_INDEX);
collection.addAll(CarFactory.createCollectionOfCars(20));
Set<KeyStatistics<String>> keyStatistics = setOf(
MANUFACTURER_INDEX.getStatisticsForDistinctKeysDescending(noQueryOptions()));
assertEquals(keyStatistics, setOf(
new KeyStatistics<>("Toyota", 6),
new KeyStatistics<>("Honda", 6),
new KeyStatistics<>("Ford", 6),
new KeyStatistics<>("BMW", 2)
));
}
示例5: retrieveLess
import com.googlecode.cqengine.IndexedCollection; //导入方法依赖的package包/类
@Test
public void retrieveLess() {
IndexedCollection<EntityHandle<Car>> collection = new ConcurrentIndexedCollection<>();
SortedKeyStatisticsIndex<String, EntityHandle<Car>> PRICE_INDEX = onAttribute(Car.PRICE);
PRICE_INDEX.clear(noQueryOptions());
collection.addIndex(PRICE_INDEX);
collection.addAll(CarFactory.createCollectionOfCars(10));
try (ResultSet<EntityHandle<Car>> resultSet = collection.retrieve(lessThan(Car.PRICE, 3999.99))) {
assertEquals(resultSet.size(), 1);
assertEquals(resultSet.uniqueResult().get().getModel(), "Accord");
}
try (ResultSet<EntityHandle<Car>> resultSet = collection.retrieve(lessThanOrEqualTo(Car.PRICE, 3999.99))) {
assertEquals(resultSet.size(), 2);
ArrayList<EntityHandle<Car>> values = Lists.newArrayList(resultSet.iterator());
assertTrue(values.stream().anyMatch(h -> h.get().getModel().contentEquals("Fusion")));
assertTrue(values.stream().anyMatch(h -> h.get().getModel().contentEquals("Accord")));
}
}
示例6: retrieveHas
import com.googlecode.cqengine.IndexedCollection; //导入方法依赖的package包/类
@Test
public void retrieveHas() {
IndexedCollection<EntityHandle<Car>> collection = new ConcurrentIndexedCollection<>();
KeyStatisticsIndex<String, EntityHandle<Car>> MANUFACTURER_INDEX =
(KeyStatisticsIndex<String, EntityHandle<Car>>) onAttribute(Car.MANUFACTURER);
MANUFACTURER_INDEX.clear(noQueryOptions());
collection.addIndex(MANUFACTURER_INDEX);
Set<EntityHandle<Car>> coll = CarFactory.createCollectionOfCars(10);
collection.addAll(coll);
ResultSet<EntityHandle<Car>> cars = collection.retrieve(has(Car.MANUFACTURER));
assertTrue(cars.isNotEmpty());
assertEquals(cars.size(), coll.size());
cars.close();
MANUFACTURER_INDEX.clear(noQueryOptions());
}
示例7: retrieveBetween
import com.googlecode.cqengine.IndexedCollection; //导入方法依赖的package包/类
@Test
public void retrieveBetween() {
IndexedCollection<EntityHandle<Car>> collection = new ConcurrentIndexedCollection<>();
SortedKeyStatisticsIndex<String, EntityHandle<Car>> PRICE_INDEX = onAttribute(Car.PRICE);
PRICE_INDEX.clear(noQueryOptions());
collection.addIndex(PRICE_INDEX);
collection.addAll(CarFactory.createCollectionOfCars(10));
try (ResultSet<EntityHandle<Car>> resultSet = collection.retrieve(between(Car.PRICE, 8000.00, 9001.00))) {
assertEquals(resultSet.size(), 2);
ArrayList<EntityHandle<Car>> values = Lists.newArrayList(resultSet.iterator());
assertTrue(values.stream().anyMatch(h -> h.get().getModel().contentEquals("M6")));
assertTrue(values.stream().anyMatch(h -> h.get().getModel().contentEquals("Prius")));
}
}
示例8: indexQuantization_SpanningTwoBucketsMidRange
import com.googlecode.cqengine.IndexedCollection; //导入方法依赖的package包/类
@Test
public void indexQuantization_SpanningTwoBucketsMidRange() {
IndexedCollection<EntityHandle<Car>> collection = new ConcurrentIndexedCollection<>();
Index<EntityHandle<Car>> index = withQuantizerOnAttribute(IntegerQuantizer.withCompressionFactor(10),
Car.CAR_ID);
index.clear(noQueryOptions());
collection.addIndex(index);
collection.addAll(CarFactory.createCollectionOfCars(100));
// Merge cost should be 20 because this query spans 2 buckets (each containing 10 objects)...
ResultSet<EntityHandle<Car>> resultSet = collection.retrieve(between(Car.CAR_ID, 47, 53));
assertEquals(resultSet.getMergeCost(), 20);
resultSet.close();
// 7 objects match the query (between is inclusive)...
resultSet = collection.retrieve(between(Car.CAR_ID, 47, 53));
assertEquals(resultSet.size(), 7);
resultSet.close();
// The matching objects are...
List<Integer> carIdsFound = retrieveCarIds(collection, between(Car.CAR_ID, 47, 53));
assertEquals(carIdsFound, asList(47, 48, 49, 50, 51, 52, 53));
}
示例9: indexQuantization_FirstBucket
import com.googlecode.cqengine.IndexedCollection; //导入方法依赖的package包/类
@Test
public void indexQuantization_FirstBucket() {
IndexedCollection<EntityHandle<Car>> collection = new ConcurrentIndexedCollection<>();
Index<EntityHandle<Car>> index = withQuantizerOnAttribute(IntegerQuantizer.withCompressionFactor(10),
Car.CAR_ID);
index.clear(noQueryOptions());
collection.addIndex(index);
collection.addAll(CarFactory.createCollectionOfCars(100));
// Merge cost should be 10, because objects matching this query are in a single bucket...
ResultSet<EntityHandle<Car>> resultSet = collection.retrieve(between(Car.CAR_ID, 2, 4));
assertEquals(resultSet.getMergeCost(), 10);
resultSet.close();
// 3 objects match the query...
resultSet = collection.retrieve(between(Car.CAR_ID, 2, 4));
assertEquals(resultSet.size(), 3);
resultSet.close();
List<Integer> carIdsFound = retrieveCarIds(collection, between(Car.CAR_ID, 2, 4));
assertEquals(carIdsFound, asList(2, 3, 4));
}
示例10: indexQuantization_LastBucket
import com.googlecode.cqengine.IndexedCollection; //导入方法依赖的package包/类
@Test
public void indexQuantization_LastBucket() {
IndexedCollection<EntityHandle<Car>> collection = new ConcurrentIndexedCollection<>();
Index<EntityHandle<Car>> index = withQuantizerOnAttribute(IntegerQuantizer.withCompressionFactor(10),
Car.CAR_ID);
index.clear(noQueryOptions());
collection.addIndex(index);
collection.addAll(CarFactory.createCollectionOfCars(100));
// Merge cost should be 10, because objects matching this query are in a single bucket...
ResultSet<EntityHandle<Car>> resultSet = collection.retrieve(between(Car.CAR_ID, 96, 98));
assertEquals(resultSet.getMergeCost(), 10);
resultSet.close();
// 3 objects match the query...
resultSet = collection.retrieve(between(Car.CAR_ID, 96, 98));
assertEquals(resultSet.size(), 3);
resultSet.close();
List<Integer> carIdsFound = retrieveCarIds(collection, between(Car.CAR_ID, 96, 98));
assertEquals(carIdsFound, asList(96, 97, 98));
}
示例11: indexQuantization_ComplexQuery
import com.googlecode.cqengine.IndexedCollection; //导入方法依赖的package包/类
@Test
public void indexQuantization_ComplexQuery() {
IndexedCollection<EntityHandle<Car>> collection = new ConcurrentIndexedCollection<>();
Index<EntityHandle<Car>> index = withQuantizerOnAttribute(IntegerQuantizer.withCompressionFactor(10),
Car.CAR_ID);
index.clear(noQueryOptions());
collection.addIndex(index);
collection.addAll(CarFactory.createCollectionOfCars(100));
Query<EntityHandle<Car>> query = and(between(Car.CAR_ID, 96, 98), greaterThan(Car.CAR_ID, 95));
// 3 objects match the query...
ResultSet<EntityHandle<Car>> resultSet = collection.retrieve(query);
assertEquals(resultSet.size(), 3);
resultSet.close();
List<Integer> carIdsFound = retrieveCarIds(collection, query);
assertEquals(carIdsFound, asList(96, 97, 98));
// Merge cost should be 10, because objects matching this query are in a single bucket...
resultSet = collection.retrieve(query);
assertEquals(resultSet.getMergeCost(), 10);
resultSet.close();
}
示例12: byteArrayEquality
import com.googlecode.cqengine.IndexedCollection; //导入方法依赖的package包/类
@Test
public void byteArrayEquality() {
IndexedCollection<EntityHandle<Car>> collection = createIndexedCollection(Car.class);
SimpleAttribute<Car, byte[]> attr = new SimpleAttribute<Car, byte[]>(Car.class,
(Class<EntityHandle<Car>>) ((Class<?>)getClass()),
byte[].class, "bytearray") {
@Override public byte[] getValue(Car object, QueryOptions queryOptions) {
return object.getManufacturer().getBytes();
}
};
HashIndex index = onAttribute(attr);
index.clear(noQueryOptions());
collection.addIndex(index);
collection.addAll(CarFactory.createCollectionOfCars(10));
ResultSet<EntityHandle<Car>> cars = collection.retrieve(equal(attr, "Honda".getBytes()));
assertTrue(cars.isNotEmpty());
assertTrue(streamOf(cars).allMatch(car -> car.get().getManufacturer().contentEquals("Honda")));
cars.close();
index.clear(noQueryOptions());
}
示例13: getStatisticsForDistinctKeys
import com.googlecode.cqengine.IndexedCollection; //导入方法依赖的package包/类
@Test
public void getStatisticsForDistinctKeys() {
IndexedCollection<EntityHandle<Car>> collection = new ConcurrentIndexedCollection<>();
KeyStatisticsIndex<String, EntityHandle<Car>> MANUFACTURER_INDEX =
(KeyStatisticsIndex<String, EntityHandle<Car>>) onAttribute(Car.MANUFACTURER);
MANUFACTURER_INDEX.clear(noQueryOptions());
collection.addIndex(MANUFACTURER_INDEX);
collection.addAll(CarFactory.createCollectionOfCars(20));
Set<KeyStatistics<String>> keyStatistics = setOf(
MANUFACTURER_INDEX.getStatisticsForDistinctKeys(noQueryOptions()));
assertEquals(keyStatistics, setOf(
new KeyStatistics<>("Ford", 6),
new KeyStatistics<>("Honda", 6),
new KeyStatistics<>("Toyota", 6),
new KeyStatistics<>("BMW", 2)
)
);
MANUFACTURER_INDEX.clear(noQueryOptions());
}
示例14: retrieveEqual
import com.googlecode.cqengine.IndexedCollection; //导入方法依赖的package包/类
@Test
public void retrieveEqual() {
IndexedCollection<EntityHandle<Car>> collection = new ConcurrentIndexedCollection<>();
KeyStatisticsIndex<String, EntityHandle<Car>> MANUFACTURER_INDEX =
(KeyStatisticsIndex<String, EntityHandle<Car>>) onAttribute(Car.MANUFACTURER);
MANUFACTURER_INDEX.clear(noQueryOptions());
collection.addIndex(MANUFACTURER_INDEX);
collection.addAll(CarFactory.createCollectionOfCars(10));
ResultSet<EntityHandle<Car>> cars = collection.retrieve(equal(Car.MANUFACTURER, "Honda"));
assertTrue(cars.isNotEmpty());
assertTrue(streamOf(cars).allMatch(car -> car.get().getManufacturer().contentEquals("Honda")));
cars.close();
MANUFACTURER_INDEX.clear(noQueryOptions());
}
示例15: main
import com.googlecode.cqengine.IndexedCollection; //导入方法依赖的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 + ")");
}
}
}