Java Code Examples for com.googlecode.cqengine.attribute.SimpleAttribute#getValue()

The following examples show how to use com.googlecode.cqengine.attribute.SimpleAttribute#getValue() . 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: Between.java    From cqengine with Apache License 2.0 6 votes vote down vote up
@Override
protected boolean matchesSimpleAttribute(SimpleAttribute<O, A> attribute, O object, QueryOptions queryOptions) {
    A attributeValue = attribute.getValue(object, queryOptions);
    if (lowerInclusive && upperInclusive) {
        if (lowerValue.compareTo(attributeValue) <= 0 && upperValue.compareTo(attributeValue) >= 0) {
            return true;
        }
    }
    else if (lowerInclusive) {
        if (lowerValue.compareTo(attributeValue) <= 0 && upperValue.compareTo(attributeValue) > 0) {
            return true;
        }
    }
    else if (upperInclusive) {
        if (lowerValue.compareTo(attributeValue) < 0 && upperValue.compareTo(attributeValue) >= 0) {
            return true;
        }
    }
    else {
        if (lowerValue.compareTo(attributeValue) < 0 && upperValue.compareTo(attributeValue) > 0) {
            return true;
        }
    }
    return false;
}
 
Example 2
Source File: LongestPrefix.java    From cqengine with Apache License 2.0 6 votes vote down vote up
@Override
public Iterable<O> getMatchesForSimpleAttribute(SimpleAttribute<O, A> attribute, ObjectSet<O> objectsInCollection, QueryOptions queryOptions) {
    List<O> results = new ArrayList<>();
    int currentCount = -1;
    for (O object : objectsInCollection) {
        CharSequence attributeValue = attribute.getValue(object, queryOptions);
        int count = countPrefixChars(value, attributeValue);
        if (count == 0) {
            continue;
        }
        if (count > currentCount) {
            currentCount = count;
            results.clear();
            results.add(object);
        } else if (count == currentCount) {
            results.add(object);
        }
    }
    return results;
}
 
Example 3
Source File: SQLiteIdentityIndexTest.java    From cqengine with Apache License 2.0 6 votes vote down vote up
@Test
public void testSerialization() {
    SQLiteIdentityIndex<Integer, Car> index = new SQLiteIdentityIndex<Integer, Car>(
            Car.CAR_ID
    );

    SimpleAttribute<Car, byte[]> serializingAttribute = index.new SerializingAttribute(Car.class, byte[].class);
    SimpleAttribute<byte[], Car> deserializingAttribute = index.new DeserializingAttribute(byte[].class, Car.class);

    Car c1 = CarFactory.createCar(1);
    byte[] s1 = serializingAttribute.getValue(c1, noQueryOptions());
    Car c2 = deserializingAttribute.getValue(s1, noQueryOptions());
    byte[] s2 = serializingAttribute.getValue(c2, noQueryOptions());
    Assert.assertEquals(c1, c2);
    Assert.assertArrayEquals(s1, s2);
}
 
Example 4
Source File: LessThan.java    From cqengine with Apache License 2.0 5 votes vote down vote up
@Override
protected boolean matchesSimpleAttribute(SimpleAttribute<O, A> attribute, O object, QueryOptions queryOptions) {
    A attributeValue = attribute.getValue(object, queryOptions);
    if (valueInclusive) {
        return value.compareTo(attributeValue) >= 0;
    }
    else {
        return value.compareTo(attributeValue) > 0;
    }
}
 
Example 5
Source File: GreaterThan.java    From cqengine with Apache License 2.0 5 votes vote down vote up
@Override
protected boolean matchesSimpleAttribute(SimpleAttribute<O, A> attribute, O object, QueryOptions queryOptions) {
    A attributeValue = attribute.getValue(object, queryOptions);
    if (valueInclusive) {
        return value.compareTo(attributeValue) <= 0;
    }
    else {
        return value.compareTo(attributeValue) < 0;
    }
}
 
Example 6
Source File: ExistsIn.java    From cqengine with Apache License 2.0 5 votes vote down vote up
@Override
protected boolean matchesSimpleAttribute(SimpleAttribute<O, A> attribute, O object, QueryOptions queryOptions) {
    A localValue = attribute.getValue(object, queryOptions);
    return foreignRestrictions == null
            ? foreignCollectionContains(foreignCollection, equal(foreignKeyAttribute, localValue))
            : foreignCollectionContains(foreignCollection, and(equal(foreignKeyAttribute, localValue), foreignRestrictions));
}
 
Example 7
Source File: Min.java    From cqengine with Apache License 2.0 5 votes vote down vote up
@Override
public Iterable<O> getMatchesForSimpleAttribute(SimpleAttribute<O, A> attribute, ObjectSet<O> objectsInCollection, QueryOptions queryOptions) {
    A minimumValue = null;
    Set<O> results = new HashSet<>();
    for (O object : objectsInCollection) {
        A attributeValue = attribute.getValue(object, queryOptions);
        minimumValue = evaluate(object, attributeValue, minimumValue, (Set<O>) results);
    }
    return results;
}
 
Example 8
Source File: Max.java    From cqengine with Apache License 2.0 5 votes vote down vote up
@Override
public Iterable<O> getMatchesForSimpleAttribute(SimpleAttribute<O, A> attribute, ObjectSet<O> objectsInCollection, QueryOptions queryOptions) {
    A maximumValue = null;
    Set<O> results = new HashSet<>();
    for (O object : objectsInCollection) {
        A attributeValue = attribute.getValue(object, queryOptions);
        maximumValue = evaluate(object, attributeValue, maximumValue, (Set<O>) results);
    }
    return results;
}
 
Example 9
Source File: StringIsContainedIn.java    From cqengine with Apache License 2.0 4 votes vote down vote up
@Override
protected boolean matchesSimpleAttribute(SimpleAttribute<O, A> attribute, O object, QueryOptions queryOptions) {
    CharSequence attributeValue = attribute.getValue(object, queryOptions);
    // Same as string contains, except we swap the arguments...
    return StringContains.containsFragment(value, attributeValue);
}
 
Example 10
Source File: StringContains.java    From cqengine with Apache License 2.0 4 votes vote down vote up
@Override
protected boolean matchesSimpleAttribute(SimpleAttribute<O, A> attribute, O object, QueryOptions queryOptions) {
    CharSequence attributeValue = attribute.getValue(object, queryOptions);
    return containsFragment(attributeValue, value);
}
 
Example 11
Source File: StringIsPrefixOf.java    From cqengine with Apache License 2.0 4 votes vote down vote up
@Override
protected boolean matchesSimpleAttribute(SimpleAttribute<O, A> attribute, O object, QueryOptions queryOptions) {
    CharSequence attributeValue = attribute.getValue(object, queryOptions);
    //swap the order of values
    return StringStartsWith.matchesValue(value, attributeValue, queryOptions);
}
 
Example 12
Source File: Has.java    From cqengine with Apache License 2.0 4 votes vote down vote up
@Override
protected boolean matchesSimpleAttribute(SimpleAttribute<O, A> attribute, O object, QueryOptions queryOptions) {
    return attribute.getValue(object, queryOptions) != null;
}
 
Example 13
Source File: StringEndsWith.java    From cqengine with Apache License 2.0 4 votes vote down vote up
@Override
protected boolean matchesSimpleAttribute(SimpleAttribute<O, A> attribute, O object, QueryOptions queryOptions) {
    A attributeValue = attribute.getValue(object, queryOptions);
    return matchesValue(attributeValue, queryOptions);
}
 
Example 14
Source File: StringStartsWith.java    From cqengine with Apache License 2.0 4 votes vote down vote up
@Override
protected boolean matchesSimpleAttribute(SimpleAttribute<O, A> attribute, O object, QueryOptions queryOptions) {
    A attributeValue = attribute.getValue(object, queryOptions);
    return matchesValue(attributeValue, value, queryOptions);
}
 
Example 15
Source File: StringMatchesRegex.java    From cqengine with Apache License 2.0 4 votes vote down vote up
@Override
protected boolean matchesSimpleAttribute(SimpleAttribute<O, A> attribute, O object, QueryOptions queryOptions) {
    A attributeValue = attribute.getValue(object, queryOptions);
    return matchesValue(attributeValue, queryOptions);
}