本文整理汇总了Java中com.googlecode.cqengine.attribute.Attribute类的典型用法代码示例。如果您正苦于以下问题:Java Attribute类的具体用法?Java Attribute怎么用?Java Attribute使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Attribute类属于com.googlecode.cqengine.attribute包,在下文中一共展示了Attribute类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: matchesNonSimpleAttribute
import com.googlecode.cqengine.attribute.Attribute; //导入依赖的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);
}
}
示例2: ensureTargetIsFound
import com.googlecode.cqengine.attribute.Attribute; //导入依赖的package包/类
private void ensureTargetIsFound(Attribute<EntityHandle<O>, A> attribute, QueryOptions queryOptions) {
if (target == null) {
Iterable<EntityHandle<O>> collection = queryOptions.get(Iterable.class);
if (collection == null) {
throw new RuntimeException(
toString() + " has to be supported by the target index or queryOptions should" +
" include IndexedCollection key");
}
Iterator<EntityHandle<O>> iterator = collection.iterator();
A targetValue = null;
while (iterator.hasNext()) {
EntityHandle<O> next = iterator.next();
Iterable<A> values = attribute.getValues(next, queryOptions);
for (A value : values) {
if (target == null || isBetterValue(value, targetValue)) {
target = next;
targetValue = value;
}
}
}
}
}
示例3: All
import com.googlecode.cqengine.attribute.Attribute; //导入依赖的package包/类
public All(Class<O> attributeType) {
super(new Attribute<EntityHandle<O>, O>() {
@Override
public Class<EntityHandle<O>> getObjectType() {
return null;
}
@Override
public Class<O> getAttributeType() {
return attributeType;
}
@Override
public String getAttributeName() {
return "true";
}
@Override
public Iterable<O> getValues(EntityHandle<O> object, QueryOptions queryOptions) {
return Collections.singletonList(object.get());
}
});
this.attributeType = attributeType;
}
示例4: None
import com.googlecode.cqengine.attribute.Attribute; //导入依赖的package包/类
public None(Class<O> attributeType) {
super(new Attribute<EntityHandle<O>, O>() {
@Override
public Class<EntityHandle<O>> getObjectType() {
return null;
}
@Override
public Class<O> getAttributeType() {
return attributeType;
}
@Override
public String getAttributeName() {
return "true";
}
@Override
public Iterable<O> getValues(EntityHandle<O> object, QueryOptions queryOptions) {
return Collections.singletonList(object.get());
}
});
this.attributeType = attributeType;
}
示例5: testInMany
import com.googlecode.cqengine.attribute.Attribute; //导入依赖的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);
}
示例6: main
import com.googlecode.cqengine.attribute.Attribute; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public static void main(String[] args) throws Exception {
// Generate an attribute from bytecode to read the Car.model field...
Map<String, ? extends Attribute<Car, ?>> attributes = AttributeBytecodeGenerator.createAttributes(Car.class);
Attribute<Car, String> MODEL = (Attribute<Car, String>) attributes.get("model");
// Create a collection of 10 Car objects (Ford Focus, Honda Civic etc.)...
IndexedCollection<Car> cars = new ConcurrentIndexedCollection<Car>();
cars.addAll(CarFactory.createCollectionOfCars(10));
// Retrieve the cars whose Car.model field is "Civic" (i.e. the Honda Civic)...
ResultSet<Car> results = cars.retrieve(equal(MODEL, "Civic"));
for (Car car : results) {
System.out.println(car);
}
// ..prints:
// Car{carId=3, manufacturer='Honda', model='Civic', color=WHITE, doors=5, price=4000.0, features=[grade b]}
}
示例7: testInNone
import com.googlecode.cqengine.attribute.Attribute; //导入依赖的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);
}
示例8: IsLatestEntity
import com.googlecode.cqengine.attribute.Attribute; //导入依赖的package包/类
/**
* @deprecated
* @param collection collection to query against
* @param queryFunction query returning function
* @param timestampAttribute timestamp attribute.
*/
@Deprecated
public IsLatestEntity(IndexedCollection<O> collection,
Function<O, Query<O>> queryFunction,
Attribute<O, HybridTimestamp> timestampAttribute) {
super(timestampAttribute);
this.collection = collection;
this.queryFunction = queryFunction;
this.timestampAttribute = timestampAttribute;
}
示例9: matchesNonSimpleAttribute
import com.googlecode.cqengine.attribute.Attribute; //导入依赖的package包/类
@Override
protected boolean matchesNonSimpleAttribute(Attribute<EntityHandle<O>, Boolean> attribute, EntityHandle<O> object,
QueryOptions queryOptions) {
if (!scope.matches(object, queryOptions)) {
return false;
}
Iterable<EntityHandle<O>> iterable = queryOptions.get(Iterable.class);
Map<Object, Object> options = new HashMap<>(queryOptions.getOptions());
options.put(Iterable.class, new FilteringIterable<>(scope, iterable, queryOptions));
return query.matches(object, new QueryOptions(options));
}
示例10: getIndexMatrix
import com.googlecode.cqengine.attribute.Attribute; //导入依赖的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)))
);
}
示例11: matchesNonSimpleAttribute
import com.googlecode.cqengine.attribute.Attribute; //导入依赖的package包/类
@Override
protected boolean matchesNonSimpleAttribute(Attribute<O, Object> attribute, O object,
QueryOptions queryOptions) {
for (Object attributeValue : attribute.getValues(object, queryOptions)) {
if (attributeValue.equals(getValue())) {
return true;
}
}
return false;
}
示例12: compatibleAttribute
import com.googlecode.cqengine.attribute.Attribute; //导入依赖的package包/类
public static <O extends Entity, A> Attribute<EntityHandle<O>, ?> compatibleAttribute(Attribute<EntityHandle<O>, A>
attribute) {
if (attribute.getAttributeType() == byte[].class) {
return new ByteArrayWrappingAttribute<>((Attribute<EntityHandle<O>, byte[]>) attribute);
} else {
return attribute;
}
}
示例13: getIndex
import com.googlecode.cqengine.attribute.Attribute; //导入依赖的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());
}
示例14: getIndex
import com.googlecode.cqengine.attribute.Attribute; //导入依赖的package包/类
/**
*
* @param attr the attribute against which the
* index will be built
* @return an instance of {@link DiskIndex}
*/
@SuppressWarnings("unchecked")
@Override
public Index<O> getIndex(Attribute<O, ?> attr) {
if(attr instanceof SimpleAttribute)
return (Index<O>) DiskIndex.onAttribute((SimpleAttribute)attr);
throw new IllegalArgumentException(attr.toString() + " must be an instance of SimpleAttribute in order to be persisted on disk");
}
示例15: getIndex
import com.googlecode.cqengine.attribute.Attribute; //导入依赖的package包/类
/**
*
* @param attribute
* @param attr the attribute against which the
* index will be built
* @return an instance of {@link RadixTreeIndex}
*/
@SuppressWarnings("unchecked")
@Override
public Index<O> getIndex(Attribute<O,?> attribute) {
if(CharSequence.class.isAssignableFrom(attribute.getAttributeType()))
return RadixTreeIndex.onAttribute((Attribute < O, ? extends CharSequence>)attribute);
throw new IllegalArgumentException(RadixTreeIndex.class.getName()
+ " cannot be applied on "
+ attribute.getAttributeName()
+ " because it does not extend "
+ CharSequence.class.getName());
}