use of javax.cache.Cache.Entry in project ignite by apache.
the class GAGrid method selectGeneByChromsomeCriteria.
/**
* method assumes ChromosomeCriteria is set.
*
* @param k Gene index in Chromosome
* @return Primary key of respective Gene
*/
private long selectGeneByChromsomeCriteria(int k) {
List<Gene> genes = new ArrayList();
StringBuffer sbSqlClause = new StringBuffer("_val like '");
sbSqlClause.append("%");
sbSqlClause.append(config.getChromosomeCriteria().getCriteria().get(k));
sbSqlClause.append("%'");
IgniteCache<Long, Gene> cache = ignite.cache(GAGridConstants.GENE_CACHE);
SqlQuery sql = new SqlQuery(Gene.class, sbSqlClause.toString());
try (QueryCursor<Entry<Long, Gene>> cursor = cache.query(sql)) {
for (Entry<Long, Gene> e : cursor) genes.add(e.getValue());
}
int idx = selectRandomIndex(genes.size());
Gene gene = genes.get(idx);
return gene.id();
}
use of javax.cache.Cache.Entry in project ignite by apache.
the class GAGridUtils method getGenesInOrderForChromosome.
/**
* Retrieve genes in order
*
* @param ignite Ignite
* @param chromosome Chromosome
* @return List of Genes
*/
public static List<Gene> getGenesInOrderForChromosome(Ignite ignite, Chromosome chromosome) {
List<Gene> genes = new ArrayList();
IgniteCache<Long, Gene> cache = ignite.cache(GAGridConstants.GENE_CACHE);
long[] primaryKeys = chromosome.getGenes();
for (int k = 0; k < primaryKeys.length; k++) {
StringBuffer sbSqlClause = new StringBuffer();
sbSqlClause.append("_key IN ");
sbSqlClause.append("(");
sbSqlClause.append(primaryKeys[k]);
sbSqlClause.append(")");
SqlQuery sql = new SqlQuery(Gene.class, sbSqlClause.toString());
try (QueryCursor<Entry<Long, Gene>> cursor = cache.query(sql)) {
for (Entry<Long, Gene> e : cursor) genes.add(e.getValue());
}
}
return genes;
}
Aggregations