Java Code Examples for com.googlecode.cqengine.query.Query#getClass()
The following examples show how to use
com.googlecode.cqengine.query.Query#getClass() .
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: LogicalQuery.java From cqengine with Apache License 2.0 | 6 votes |
/** * Creates a new {@link LogicalQuery} initialized to logically connect the supplied set of child queries. * * @param childQueries The child queries which this {@code LogicalQuery} is to logically connect */ public LogicalQuery(Collection<Query<O>> childQueries) { Objects.requireNonNull(childQueries, "The child queries supplied to a logical query cannot be null"); for (Query<O> query : childQueries) { if (query instanceof LogicalQuery) { logicalQueries.add((LogicalQuery<O>) query); } else if (query instanceof SimpleQuery) { simpleQueries.add((SimpleQuery<O, ?>) query); } else if (query instanceof ComparativeQuery) { comparativeQueries.add((ComparativeQuery<O, ?>) query); } else { throw new IllegalStateException("Unexpected type of query: " + (query == null ? null : query + ", " + query.getClass())); } } this.hasLogicalQueries = !logicalQueries.isEmpty(); this.hasSimpleQueries = !simpleQueries.isEmpty(); this.hasComparativeQueries = !comparativeQueries.isEmpty(); this.size = childQueries.size(); this.childQueries = childQueries; }
Example 2
Source File: HashIndex.java From cqengine with Apache License 2.0 | 6 votes |
/** * {@inheritDoc} */ @Override public ResultSet<O> retrieve(final Query<O> query, final QueryOptions queryOptions) { Class<?> queryClass = query.getClass(); if (queryClass.equals(Equal.class)) { @SuppressWarnings("unchecked") Equal<O, A> equal = (Equal<O, A>) query; return retrieveEqual(equal, queryOptions); } else if (queryClass.equals(In.class)) { @SuppressWarnings("unchecked") In<O, A> in = (In<O, A>) query; return retrieveIn(in, queryOptions); } else if (queryClass.equals(Has.class)) { return deduplicateIfNecessary(indexMap.values(), query, getAttribute(), queryOptions, INDEX_RETRIEVAL_COST); } else { throw new IllegalArgumentException("Unsupported query: " + query); } }
Example 3
Source File: UniqueIndex.java From cqengine with Apache License 2.0 | 6 votes |
@Override public ResultSet<O> retrieve(final Query<O> query, final QueryOptions queryOptions) { Class<?> queryClass = query.getClass(); if (queryClass.equals(Equal.class)) { final ConcurrentMap<A, O> indexMap = this.indexMap; @SuppressWarnings("unchecked") Equal<O, A> equal = (Equal<O, A>) query; return retrieveEqual(equal, queryOptions, indexMap); } else if(queryClass.equals(In.class)){ @SuppressWarnings("unchecked") In<O, A> in = (In<O, A>) query; return retrieveIn(in, queryOptions, indexMap); } throw new IllegalArgumentException("Unsupported query: " + query); }
Example 4
Source File: NavigableIndex.java From cqengine with Apache License 2.0 | 4 votes |
/** * {@inheritDoc} */ @Override public ResultSet<O> retrieve(final Query<O> query, final QueryOptions queryOptions) { Class<?> queryClass = query.getClass(); final boolean indexIsQuantized = isQuantized(); // Process Equal queries in the same was as HashIndex... if (queryClass.equals(Equal.class)) { @SuppressWarnings("unchecked") Equal<O, A> equal = (Equal<O, A>) query; return retrieveEqual(equal, queryOptions); }else if (queryClass.equals(In.class)){ @SuppressWarnings("unchecked") In<O, A> in = (In<O, A>) query; return retrieveIn(in, queryOptions); } else if (queryClass.equals(Has.class)) { return deduplicateIfNecessary(indexMap.values(), query, getAttribute(), queryOptions, INDEX_RETRIEVAL_COST); } // Process LessThan, GreaterThan and Between queries as follows... final IndexRangeLookupFunction<O> lookupFunction; if (queryClass.equals(LessThan.class)) { @SuppressWarnings("unchecked") final LessThan<O, A> lessThan = (LessThan<O, A>) query; lookupFunction = new IndexRangeLookupFunction<O>(query, false, true) { @Override public Iterable<StoredResultSet<O>> perform() { return indexMap.headMap( getQuantizedValue(lessThan.getValue()), lessThan.isValueInclusive() || indexIsQuantized ).values(); } }; } else if (queryClass.equals(GreaterThan.class)) { @SuppressWarnings("unchecked") final GreaterThan<O, A> greaterThan = (GreaterThan<O, A>) query; lookupFunction = new IndexRangeLookupFunction<O>(query, true, false) { @Override public Iterable<StoredResultSet<O>> perform() { return indexMap.tailMap( getQuantizedValue(greaterThan.getValue()), greaterThan.isValueInclusive() || indexIsQuantized ).values(); } }; } else if (queryClass.equals(Between.class)) { @SuppressWarnings("unchecked") final Between<O, A> between = (Between<O, A>) query; lookupFunction = new IndexRangeLookupFunction<O>(query, true, true) { @Override public Iterable<StoredResultSet<O>> perform() { return indexMap.subMap( getQuantizedValue(between.getLowerValue()), between.isLowerInclusive() || indexIsQuantized, getQuantizedValue(between.getUpperValue()), between.isUpperInclusive() || indexIsQuantized ).values(); } }; } else { throw new IllegalStateException("Unsupported query: " + query); } // Fetch results using the supplied function. // This should return a Collection which is actually just a view onto the index // which presents a collection of sets containing values selected by the function... @SuppressWarnings({"unchecked"}) Iterable<ResultSet<O>> results = (Iterable<ResultSet<O>>) lookupFunction.perform(); // Add filtering for quantization (implemented by subclass supporting a Quantizer, a no-op in this class)... results = addFilteringForQuantization(results, lookupFunction, queryOptions); return deduplicateIfNecessary(results, query, getAttribute(), queryOptions, INDEX_RETRIEVAL_COST); }
Example 5
Source File: UniqueIndex.java From cqengine with Apache License 2.0 | 4 votes |
@Override public boolean supportsQuery(Query<O> query, QueryOptions queryOptions) { Class<?> queryClass = query.getClass(); return queryClass.equals(Equal.class) || queryClass.equals(In.class); }