本文整理汇总了Java中com.googlecode.cqengine.IndexedCollection.add方法的典型用法代码示例。如果您正苦于以下问题:Java IndexedCollection.add方法的具体用法?Java IndexedCollection.add怎么用?Java IndexedCollection.add使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.googlecode.cqengine.IndexedCollection
的用法示例。
在下文中一共展示了IndexedCollection.add方法的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: 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());
}
示例3: 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());
}
示例4: testDeduplication_Materialize
import com.googlecode.cqengine.IndexedCollection; //导入方法依赖的package包/类
@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()));
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());
}
示例5: testDeduplication_Logical
import com.googlecode.cqengine.IndexedCollection; //导入方法依赖的package包/类
@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()));
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());
}
示例6: main
import com.googlecode.cqengine.IndexedCollection; //导入方法依赖的package包/类
/**
* Demonstrates how to concurrently replace a Car in a collection, using multi-version concurrency control.
* <p/>
* Prints:
* <pre>
* The only car in the collection, before the replacement: Car{carId=1, name='Ford Focus', version=1}
* Collection contains 2 cars, but we filtered the duplicate: Car{carId=1, name='New Ford Focus', version=2}
* Collection contains 1 car again: Car{carId=1, name='New Ford Focus', version=2}
* </pre>
*
* @param args Not used
*/
public static void main(String[] args) {
IndexedCollection<Car> cars = new ConcurrentIndexedCollection<Car>();
// Add a car with carId 1...
cars.add(new Car(1, "Ford Focus"));
// Test the retrieval...
Car carFound = retrieveOnlyOneVersion(cars, 1);
System.out.println("The only car in the collection, before the replacement: " + carFound);
// Update the name of the Car with carId 1, by replacing it using MVCC...
Car oldVersion = cars.retrieve(equal(Car.CAR_ID, 1)).uniqueResult(); // Retrieve the existing version
Car newVersion = new Car(1, "New Ford Focus"); // Create a new car, same carId, different version
cars.add(newVersion); // Collection now contains two versions of the same car
// Test the retrieval (collection contains both versions, should retrieve only one of them)...
carFound = retrieveOnlyOneVersion(cars, 1);
System.out.println("Collection contains " + cars.size() + " cars, but we filtered the duplicate: " + carFound);
cars.remove(oldVersion); // Remove the old version, collection now only contains new version
// Test the retrieval...
carFound = retrieveOnlyOneVersion(cars, 1);
System.out.println("Collection contains " + cars.size() + " car again: " + carFound);
}
示例7: main
import com.googlecode.cqengine.IndexedCollection; //导入方法依赖的package包/类
public static void main(String[] args) {
IndexedCollection<User> users = new ConcurrentIndexedCollection<User>();
users.add(new User(1, "Joe"));
users.add(new User(2, "Jane"));
users.add(new User(3, "Jesse"));
IndexedCollection<Role> roles = new ConcurrentIndexedCollection<Role>();
roles.add(new Role(1, "CEO"));
roles.add(new Role(2, "Manager"));
roles.add(new Role(3, "Employee"));
IndexedCollection<UserRole> userRoles = new ConcurrentIndexedCollection<UserRole>();
userRoles.add(new UserRole(1, 3)); // Joe is an Employee
userRoles.add(new UserRole(2, 2)); // Jane is a Manager
userRoles.add(new UserRole(3, 2)); // Jesse is a Manager
// Retrieve Users who are managers...
Query<User> usersWhoAreManagers =
existsIn(userRoles, User.USER_ID, UserRole.USER_ID,
existsIn(roles, UserRole.ROLE_ID, Role.ROLE_ID, equal(Role.ROLE_NAME, "Manager")));
for (User u : users.retrieve(usersWhoAreManagers)) {
System.out.println(u.userName);
}
// ..prints: Jane, Jesse
}
示例8: testReflectiveAttribute
import com.googlecode.cqengine.IndexedCollection; //导入方法依赖的package包/类
@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);
}
示例9: testDateMath
import com.googlecode.cqengine.IndexedCollection; //导入方法依赖的package包/类
@Test
public void testDateMath() {
// Create a collection of Order objects, with shipDates 2015-08-01, 2015-08-02 and 2015-08-03...
IndexedCollection<Order> collection = new ConcurrentIndexedCollection<Order>();
collection.add(createOrder("2015-08-01"));
collection.add(createOrder("2015-08-02"));
collection.add(createOrder("2015-08-03"));
// Create a parser for CQN queries on Order objects...
CQNParser<Order> parser = CQNParser.forPojoWithAttributes(Order.class, createAttributes(Order.class));
// Register a DateMathParser which can parse date math expressions
// relative to the given date value for "now" ("2015-08-04").
// The custom value for "now" can be omitted to have it always calculate relative to the current time...
parser.registerValueParser(Date.class, new DateMathParser(createDate("2015-08-04")));
// Retrieve orders whose ship date is between 3 days ago and 2 days ago...
ResultSet<Order> results = parser.retrieve(collection, "between(\"shipDate\", \"-3DAYS\", \"-2DAYS\")");
// Assert that the following two orders are returned...
Assert.assertTrue(results.contains(createOrder("2015-08-01")));
Assert.assertTrue(results.contains(createOrder("2015-08-02")));
Assert.assertEquals(2, results.size());
}
示例10: testInMany
import com.googlecode.cqengine.IndexedCollection; //导入方法依赖的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);
}
示例11: testInOne
import com.googlecode.cqengine.IndexedCollection; //导入方法依赖的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);
}
示例12: testInNone
import com.googlecode.cqengine.IndexedCollection; //导入方法依赖的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);
}
示例13: testExists
import com.googlecode.cqengine.IndexedCollection; //导入方法依赖的package包/类
@Test
public void testExists() {
// 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; }
};
// Add some indexes...
cars.addIndex(StandingQueryIndex.onQuery(has(NAME)));
cars.addIndex(StandingQueryIndex.onQuery(not(has(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, null, "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(has(NAME)).size(), 2);
Assert.assertEquals(cars.retrieve(not(has(NAME))).size(), 1);
}
示例14: testUniqueIndex
import com.googlecode.cqengine.IndexedCollection; //导入方法依赖的package包/类
@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);
}
示例15: onEvent
import com.googlecode.cqengine.IndexedCollection; //导入方法依赖的package包/类
private void onEvent(Event event,
Map<Class<? extends Event>, IndexedCollection<EntityHandle<Event>>> txCollections,
Map<EntitySubscriber, Set<UUID>> subscriptions,
Collection<EntitySubscriber> subscribers
) {
IndexedCollection<EntityHandle<Event>> coll = txCollections
.computeIfAbsent(event.getClass(), klass -> new ConcurrentIndexedCollection<>());
coll.add(new ResolvedEntityHandle<>(event));
subscribers.stream()
.filter(s -> s.matches(repository, event))
.forEach(s -> subscriptions.get(s).add(event.uuid()));
}