本文整理汇总了Java中com.googlecode.cqengine.IndexedCollection类的典型用法代码示例。如果您正苦于以下问题:Java IndexedCollection类的具体用法?Java IndexedCollection怎么用?Java IndexedCollection使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
IndexedCollection类属于com.googlecode.cqengine包,在下文中一共展示了IndexedCollection类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: retrieve
import com.googlecode.cqengine.IndexedCollection; //导入依赖的package包/类
@Test
public void retrieve() {
IndexedCollection<EntityHandle<Car>> cars = new ConcurrentIndexedCollection<>();
// Add some indexes...
UniqueIndex index = onAttribute(Car.FEATURES);
cars.addIndex(index);
index.clear(noQueryOptions());
// Add some objects to the collection...
cars.add(new ResolvedEntityHandle<>(new Car(1, "ford focus", "foo", Arrays.asList("spare tyre", "sunroof"))));
cars.add(new ResolvedEntityHandle<>(new Car(2, "ford taurus", "bar", Arrays.asList("radio", "cd player"))));
ResultSet<EntityHandle<Car>> radio = cars.retrieve(equal(Car.FEATURES, "radio"));
assertEquals(radio.size(), 1);
radio.close();
ResultSet<EntityHandle<Car>> unknown = cars.retrieve(equal(Car.FEATURES, "unknown"));
assertEquals(unknown.size(), 0);
unknown.close();
index.clear(noQueryOptions());
}
示例2: IndexedMap
import com.googlecode.cqengine.IndexedCollection; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public IndexedMap(Function<SimpleAttribute<Value, String>, IndexedCollection<Value>> supplier,
StorageContext<Value> context) {
this.context = context;
FIELD_ID = attribute(context.valueClass(), String.class, Storable.idField, Storable::getId);
// share collections that share the same identifier.
synchronized (maps) {
if (maps.containsKey(context.identifier())) {
holder = maps.get(context.identifier());
} else {
holder = new IndexedMapHolder<>(supplier.apply(FIELD_ID));
maps.put(context.identifier(), holder);
}
db = holder.db;
}
}
示例3: configureIndices
import com.googlecode.cqengine.IndexedCollection; //导入依赖的package包/类
@SneakyThrows
private boolean configureIndices(Class<? extends Entity> klass) {
try {
if (!indicesConfiguredFor.contains(klass.getName())) {
for (IndexLoader loader : indexLoaders) {
Iterable<Index> indices = loader.load(indexEngine, klass);
for (Index i : indices) {
IndexedCollection<? extends EntityHandle<? extends Entity>> collection =
indexEngine.getIndexedCollection(klass);
boolean hasIndex = StreamSupport.stream(collection.getIndexes().spliterator(), false)
.anyMatch(index -> index.equals(i));
if (!hasIndex) {
collection.addIndex(i);
}
}
}
indicesConfiguredFor.add(klass.getName());
}
} catch (IndexEngine.IndexNotSupported e) {
notifyFailed(e);
return true;
}
return false;
}
示例4: publish
import com.googlecode.cqengine.IndexedCollection; //导入依赖的package包/类
@Override
public <T, S, C extends Command<S, T>> CompletableFuture<T> publish(C command, Collection<EntitySubscriber>
subscribers) {
Map<EntitySubscriber, Set<UUID>> subscriptions = new HashMap<>();
subscribers.forEach(s -> subscriptions.put(s, new HashSet<>()));
Map<Class<? extends Event>, IndexedCollection<EntityHandle<Event>>> txCollections = new HashMap<>();
CompletableFuture<T> future = new CompletableFuture<>();
HybridTimestamp txTimestamp;
synchronized (timestamp) {
timestamp(command, timestamp);
txTimestamp = timestamp.clone();
}
final HybridTimestamp commandTimestamp = txTimestamp.clone();
threadPool.execute(
new CommandHandler<>(commandTimestamp, command, txCollections, subscriptions, subscribers,
future,
txTimestamp));
return future;
}
示例5: timestamping
import com.googlecode.cqengine.IndexedCollection; //导入依赖的package包/类
@Test
@SneakyThrows
public void timestamping() {
IndexedCollection<EntityHandle<TestEvent>> coll = indexEngine.getIndexedCollection(TestEvent.class);
coll.clear();
IndexedCollection<EntityHandle<RepositoryTestCommand>> coll1 = indexEngine
.getIndexedCollection(RepositoryTestCommand.class);
coll1.clear();
repository.publish(RepositoryTestCommand.builder().build()).get();
TestEvent test = coll.retrieve(equal(TestEvent.ATTR, "test")).uniqueResult().get();
assertNotNull(test.timestamp());
RepositoryTestCommand test1 = coll1.retrieve(equal(RepositoryTestCommand.ATTR, "test")).uniqueResult().get();
assertNotNull(test1.timestamp());
assertTrue(test.timestamp().compareTo(test1.timestamp()) > 0);
}
示例6: commandTimestamping
import com.googlecode.cqengine.IndexedCollection; //导入依赖的package包/类
@Test
@SneakyThrows
public void commandTimestamping() {
HybridTimestamp timestamp = new HybridTimestamp(timeProvider);
timestamp.update();
RepositoryTestCommand command1 = RepositoryTestCommand.builder().value("forced")
.timestamp(timestamp)
.build();
RepositoryTestCommand command2 = RepositoryTestCommand.builder().build();
IndexedCollection<EntityHandle<RepositoryTestCommand>> coll1 = indexEngine
.getIndexedCollection(RepositoryTestCommand.class);
coll1.clear();
repository.publish(command2).get();
repository.publish(command1).get();
RepositoryTestCommand test1 = coll1.retrieve(equal(RepositoryTestCommand.ATTR, "forced")).uniqueResult().get();
RepositoryTestCommand test2 = coll1.retrieve(equal(RepositoryTestCommand.ATTR, "test")).uniqueResult().get();
assertTrue(test1.timestamp().compareTo(test2.timestamp()) < 0);
assertTrue(repository.getTimestamp().compareTo(test1.timestamp()) > 0);
assertTrue(repository.getTimestamp().compareTo(test2.timestamp()) > 0);
}
示例7: eventTimestamping
import com.googlecode.cqengine.IndexedCollection; //导入依赖的package包/类
@Test
@SneakyThrows
public void eventTimestamping() {
IndexedCollection<EntityHandle<TestEvent>> coll = indexEngine
.getIndexedCollection(TestEvent.class);
coll.clear();
HybridTimestamp timestamp = new HybridTimestamp(timeProvider);
timestamp.update();
TimestampingEventCommand command = TimestampingEventCommand.builder().eventTimestamp(timestamp).build();
repository.publish(command).get();
TestEvent test = coll.retrieve(equal(TestEvent.ATTR, "test")).uniqueResult().get();
assertTrue(test.timestamp().compareTo(command.timestamp()) < 0);
assertTrue(repository.getTimestamp().compareTo(test.timestamp()) > 0);
TestEvent followup = coll.retrieve(equal(TestEvent.ATTR, "followup")).uniqueResult().get();
assertTrue(test.timestamp().compareTo(followup.timestamp()) < 0);
assertTrue(repository.getTimestamp().compareTo(followup.timestamp()) > 0);
}
示例8: indexing
import com.googlecode.cqengine.IndexedCollection; //导入依赖的package包/类
@Test
@SneakyThrows
public void indexing() {
IndexedCollection<EntityHandle<TestEvent>> coll = indexEngine.getIndexedCollection(TestEvent.class);
coll.clear();
IndexedCollection<EntityHandle<RepositoryTestCommand>> coll1 = indexEngine
.getIndexedCollection(RepositoryTestCommand.class);
coll1.clear();
repository.publish(RepositoryTestCommand.builder().build()).get();
assertTrue(coll.retrieve(equal(TestEvent.ATTR, "test")).isNotEmpty());
assertTrue(coll.retrieve(equal(TestEvent.ATTR_DEP, "test")).isNotEmpty());
assertTrue(coll.retrieve(contains(TestEvent.ATTR, "es")).isNotEmpty());
assertEquals(coll.retrieve(equal(TestEvent.ATTR, "test")).uniqueResult().get().string(), "test");
assertEquals(coll.retrieve(equal(TestEvent.ATTRS, "test")).uniqueResult().get().string(), "test");
assertEquals(coll.retrieve(equal(TestEventExtraIndices.ATTRL, Arrays.asList("test"))).uniqueResult().get().string(),
"test");
assertTrue(coll.retrieve(equal(TestEventExtraIndices.ATTRL, Arrays.asList("test1"))).isEmpty());
assertTrue(coll1.retrieve(equal(RepositoryTestCommand.ATTR, "test")).isNotEmpty());
assertTrue(coll1.retrieve(contains(RepositoryTestCommand.ATTR, "es")).isNotEmpty());
}
示例9: streamExceptionIndexing
import com.googlecode.cqengine.IndexedCollection; //导入依赖的package包/类
@Test
@SneakyThrows
public void streamExceptionIndexing() {
IndexedCollection<EntityHandle<TestEvent>> coll = indexEngine.getIndexedCollection(TestEvent.class);
coll.clear();
UUID eventUUID = UUID.randomUUID();
StreamExceptionCommand command = StreamExceptionCommand.builder().eventUUID(eventUUID).build();
CompletableFuture<Void> future = repository.publish(command);
while (!future.isDone()) { Thread.sleep(10); } // to avoid throwing an exception
assertTrue(future.isCompletedExceptionally());
// result() was not called
assertFalse(command.isResultCalled());
try (ResultSet<EntityHandle<CommandTerminatedExceptionally>> resultSet = repository
.query(CommandTerminatedExceptionally.class,
and(all(CommandTerminatedExceptionally.class),
existsIn(
indexEngine.getIndexedCollection(EventCausalityEstablished.class),
CommandTerminatedExceptionally.ID, EventCausalityEstablished.EVENT)))) {
assertEquals(resultSet.size(), 1);
}
assertTrue(journal.get(command.uuid()).isPresent());
assertFalse(journal.get(eventUUID).isPresent());
assertTrue(repository.query(TestEvent.class, equal(TestEvent.ATTR, "test")).isEmpty());
}
示例10: matchesSimpleAttribute
import com.googlecode.cqengine.IndexedCollection; //导入依赖的package包/类
@Override
protected boolean matchesSimpleAttribute(SimpleAttribute<O, HybridTimestamp> attribute, O object, QueryOptions
queryOptions) {
Query<O> actualQuery = query == null ? queryFunction.apply(object) : query;
Optional<Boolean> terminatedQuery = terminatedQuery(object, actualQuery, queryOptions);
if (terminatedQuery.isPresent()) {
return terminatedQuery.get();
}
HybridTimestamp value = attribute.getValue(object, queryOptions);
IndexedCollection<O> collection = (IndexedCollection<O>) getCollection(queryOptions);
try (ResultSet<O> resultSet = collection.retrieve(and(
actualQuery,
greaterThan(timestampAttribute, value)))) {
return matches(resultSet, actualQuery, object, queryOptions);
}
}
示例11: matchesNonSimpleAttribute
import com.googlecode.cqengine.IndexedCollection; //导入依赖的package包/类
@Override
protected boolean matchesNonSimpleAttribute(Attribute<O, HybridTimestamp> attribute, O object, QueryOptions
queryOptions) {
Query<O> actualQuery = query == null ? queryFunction.apply(object) : query;
Optional<Boolean> terminatedQuery = terminatedQuery(object, actualQuery, queryOptions);
if (terminatedQuery.isPresent()) {
return terminatedQuery.get();
}
Iterable<HybridTimestamp> values = attribute.getValues(object, queryOptions);
List<Query<O>> conditions = StreamSupport.stream(values.spliterator(), false)
.map(v -> greaterThan(timestampAttribute, v))
.collect(Collectors.toList());
Query<O> timestampQuery = conditions.size() == 1 ? conditions.get(0) : new Or<>(conditions);
IndexedCollection<O> collection = (IndexedCollection<O>) getCollection(queryOptions);
try (ResultSet<O> resultSet = collection.retrieve(and(
actualQuery,
timestampQuery))) {
return matches(resultSet, actualQuery, object, queryOptions);
}
}
示例12: getIndexedCollection
import com.googlecode.cqengine.IndexedCollection; //导入依赖的package包/类
@Override @SuppressWarnings("unchecked")
public <T extends Entity> IndexedCollection<EntityHandle<T>> getIndexedCollection(Class<T> klass) {
IndexedCollection existingCollection = indexedCollections.get(klass.getName());
if (existingCollection == null) {
JournalPersistence<T> tJournalPersistence = null;
if (Event.class.isAssignableFrom(klass))
tJournalPersistence = (JournalPersistence<T>) new EventJournalPersistence<>(journal,
(Class<Event>) klass);
if (Command.class.isAssignableFrom(klass))
tJournalPersistence = (JournalPersistence<T>) new CommandJournalPersistence<>(journal,
(Class<Command>) klass);
if (tJournalPersistence == null) {
throw new IllegalArgumentException();
}
IndexedCollection<EntityHandle<T>> indexedCollection = createIndexedCollection(tJournalPersistence);
indexedCollections.put(klass.getName(), indexedCollection);
return indexedCollection;
} else {
return existingCollection;
}
}
示例13: indexingExistingData
import com.googlecode.cqengine.IndexedCollection; //导入依赖的package包/类
@Test
public void indexingExistingData() {
IndexedCollection<EntityHandle<Car>> cars = new ConcurrentIndexedCollection<>();
UniqueIndex index = onAttribute(Car.FEATURES);
index.clear(noQueryOptions());
// Add some objects to the collection...
cars.add(new ResolvedEntityHandle<>(new Car(1, "ford focus", "foo", Arrays.asList("spare tyre", "sunroof"))));
cars.add(new ResolvedEntityHandle<>(new Car(2, "ford taurus", "bar", Arrays.asList("radio", "cd player"))));
// Add some indexes...
cars.addIndex(index);
ResultSet<EntityHandle<Car>> radio = cars.retrieve(equal(Car.FEATURES, "radio"));
assertEquals(radio.size(), 1);
radio.close();
ResultSet<EntityHandle<Car>> unknown = cars.retrieve(equal(Car.FEATURES, "unknown"));
assertEquals(unknown.size(), 0);
unknown.close();
index.clear(noQueryOptions());
}
示例14: reindexData
import com.googlecode.cqengine.IndexedCollection; //导入依赖的package包/类
@Test
public void reindexData() {
IndexedCollection<EntityHandle<Car>> cars = new ConcurrentIndexedCollection<>();
UniqueIndex index = onAttribute(Car.FEATURES);
index.clear(noQueryOptions());
// Add some objects to the collection...
cars.add(new ResolvedEntityHandle<>(new Car(1, "ford focus", "foo", Arrays.asList("spare tyre", "sunroof"))));
cars.add(new ResolvedEntityHandle<>(new Car(2, "ford taurus", "bar", Arrays.asList("radio", "cd player"))));
cars.addIndex(index);
IndexedCollection<EntityHandle<Car>> cars1 = new ConcurrentIndexedCollection<>();
UniqueIndex index1 = onAttribute(Car.FEATURES);
cars1.addAll(cars);
cars1.addIndex(index1);
ResultSet<EntityHandle<Car>> radio = cars.retrieve(equal(Car.FEATURES, "radio"));
assertEquals(radio.size(), 1);
radio.close();
index.clear(noQueryOptions());
index1.clear(noQueryOptions());
}
示例15: 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"));
}