当前位置: 首页>>代码示例>>Java>>正文


Java Predicates类代码示例

本文整理汇总了Java中com.hazelcast.query.Predicates的典型用法代码示例。如果您正苦于以下问题:Java Predicates类的具体用法?Java Predicates怎么用?Java Predicates使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


Predicates类属于com.hazelcast.query包,在下文中一共展示了Predicates类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: findByFilters

import com.hazelcast.query.Predicates; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public Collection<LogBean> findByFilters(JsonNode jsonNode) {
	Iterator<String> fieldNames = jsonNode.fieldNames();
	Predicate<String, LogBean> predicate = null;
	while(fieldNames.hasNext()) {
		String field = fieldNames.next();
		String value = jsonNode.get(field).asText();

		Predicate<String, LogBean> tmp = Predicates.equal(field, value);
		if(predicate == null) {
			predicate = tmp;
		} else {
			predicate = Predicates.and(predicate, tmp);
		}
	}
	return logRepository.findByPredicate(predicate);
}
 
开发者ID:Mockenize,项目名称:mockenize-server,代码行数:18,代码来源:LoggingService.java

示例2: getLastPartKeyForUri

import com.hazelcast.query.Predicates; //导入依赖的package包/类
public DocumentKey getLastPartKeyForUri(String uri) {
	IMap<DocumentKey, Document> xdd = nodeEngine.getHazelcastInstance().getMap(CN_XDM_DOCUMENT);
	Predicate<DocumentKey, Document> pp = new PartitionPredicate(uri.hashCode(), Predicates.equal("uri", uri));
	Set<DocumentKey> keys = xdd.keySet(pp);
	DocumentKey last = null;
	for (DocumentKey key: keys) {
		if (last == null) {
			last = key;
		} else {
			if (key.getVersion() > last.getVersion()) {
				last = key;
			}
		}
	}
	// alternatively, can run it on partition via QueryPartitionOperation:
	//QueryPartitionOperation op = new QueryPartitionOperation(query);
	//op.setMapService(svc);
	//int partId = nodeEngine.getPartitionService().getPartitionId(uri.hashCode());
	//op.setPartitionId(partId);
	//op.beforeRun();
	//op.run();
	//QueryResult rs = (QueryResult) op.getResponse();
	logger.trace("getLastPartKeyForUri; uri: {}; returning: {}", uri, last);
	return last;
}
 
开发者ID:dsukhoroslov,项目名称:bagri,代码行数:26,代码来源:DataDistributionService.java

示例3: when_readRemoteMap_withNativePredicateAndProjection

import com.hazelcast.query.Predicates; //导入依赖的package包/类
@Test
public void when_readRemoteMap_withNativePredicateAndProjection()
        throws Exception {
    populateMap(hz.getMap(SOURCE_NAME));

    DAG dag = new DAG();
    Vertex source = dag.newVertex("source",
            readRemoteMapP(SOURCE_NAME, clientConfig,
                    Predicates.greaterThan("this", "0"),
                    Projections.singleAttribute("value")
            )
    ).localParallelism(4);
    Vertex sink = dag.newVertex(SINK_NAME, writeListP(SINK_NAME)).localParallelism(1);
    dag.edge(between(source, sink));

    executeAndWait(dag);
    IStreamList<Object> list = jet.getList(SINK_NAME);
    assertEquals(ITEM_COUNT - 1, list.size());
    assertFalse(list.contains(0));
    assertTrue(list.contains(1));
}
 
开发者ID:hazelcast,项目名称:hazelcast-jet,代码行数:22,代码来源:HazelcastRemoteConnectorTest.java

示例4: when_readMap_withNativePredicateAndProjection

import com.hazelcast.query.Predicates; //导入依赖的package包/类
@Test
public void when_readMap_withNativePredicateAndProjection() {
    IStreamMap<Integer, Integer> sourceMap = jetInstance.getMap(sourceName);
    range(0, ENTRY_COUNT).forEach(i -> sourceMap.put(i, i));

    DAG dag = new DAG();
    Vertex source = dag.newVertex("source",
            readMapP(sourceName,
                    Predicates.greaterThan("this", "0"),
                    Projections.singleAttribute("value")
            )
    );
    Vertex sink = dag.newVertex("sink", writeListP(sinkName));
    dag.edge(between(source, sink));

    jetInstance.newJob(dag).join();

    IStreamList<Object> list = jetInstance.getList(sinkName);
    assertEquals(ENTRY_COUNT - 1, list.size());
    for (int i = 0; i < ENTRY_COUNT; i++) {
        assertEquals(i != 0, list.contains(i));
    }
}
 
开发者ID:hazelcast,项目名称:hazelcast-jet,代码行数:24,代码来源:HazelcastConnectorTest.java

示例5: getQuery

import com.hazelcast.query.Predicates; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public static Predicate<DocumentKey, Document> getQuery(SchemaRepository repo, String pattern) {
	String[] parts = pattern.split(",");
	Predicate<DocumentKey, Document> result = null;
	for (String part: parts) {
		//logger.trace("getDocumentUris; translating query part: {}", part);
		Predicate<DocumentKey, Document> query = toPredicate(repo, part.trim());
		if (query != null) {
			if (result == null) {
				result = query;
			} else {
				result = Predicates.and(result, query);
			}
		} else {
		//	logger.info("getDocumentUris; cannot translate query part '{}' to Predicate, skipping", part);
		}
	}
	return result;
}
 
开发者ID:dsukhoroslov,项目名称:bagri,代码行数:20,代码来源:DocumentPredicateBuilder.java

示例6: getLastDocumentForUri

import com.hazelcast.query.Predicates; //导入依赖的package包/类
public Document getLastDocumentForUri(String uri) {
	MapService svc = nodeEngine.getService(MapService.SERVICE_NAME);
	MapServiceContext mapCtx = svc.getMapServiceContext();
	Query query = new Query(CN_XDM_DOCUMENT, Predicates.equal("uri", uri), IterationType.VALUE, null, null);
	try {
		Document last = null;
		QueryResult rs = (QueryResult) mapCtx.getMapQueryRunner(CN_XDM_DOCUMENT).runIndexOrPartitionScanQueryOnOwnedPartitions(query);
		for (QueryResultRow row: rs.getRows()) {
			Document doc = nodeEngine.toObject(row.getValue());
			if (last == null) {
				last = doc;
			} else {
				if (doc.getVersion() > last.getVersion()) {
					last = doc;
				}
			}
		}
		logger.trace("getLastDocumentForUri; uri: {}; returning: {}", uri, last);
		return last;
	} catch (ExecutionException | InterruptedException ex) {
		logger.error("getLastDocumentForUri.error: ", ex);
	}
	return null;
}
 
开发者ID:dsukhoroslov,项目名称:bagri,代码行数:25,代码来源:DataDistributionService.java

示例7: getElementKeys

import com.hazelcast.query.Predicates; //导入依赖的package包/类
public Collection<DataKey> getElementKeys(long docId) {
	MapService svc = nodeEngine.getService(MapService.SERVICE_NAME);
	MapServiceContext mapCtx = svc.getMapServiceContext();
	Query query = new Query(CN_XDM_ELEMENT, Predicates.equal("__key#documentKey", docId), IterationType.KEY, null, null);
	Collection<DataKey> result = null;
	try {
		QueryResult rs = (QueryResult) mapCtx.getMapQueryRunner(CN_XDM_ELEMENT).runIndexOrPartitionScanQueryOnOwnedPartitions(query);
		result = new ArrayList<>(rs.size());
		for (QueryResultRow row: rs.getRows()) {
			result.add((DataKey) nodeEngine.toObject(row.getKey()));
		}
		return result;
	} catch (ExecutionException | InterruptedException ex) {
		logger.error("getElementKeys.error", ex);
	}
	return result;
}
 
开发者ID:dsukhoroslov,项目名称:bagri,代码行数:18,代码来源:DataDistributionService.java

示例8: getElements

import com.hazelcast.query.Predicates; //导入依赖的package包/类
public Map<DataKey, Elements> getElements(long docId) {
	MapService svc = nodeEngine.getService(MapService.SERVICE_NAME);
	MapServiceContext mapCtx = svc.getMapServiceContext();
	Query query = new Query(CN_XDM_ELEMENT, Predicates.equal("__key#documentKey", docId), IterationType.ENTRY, null, null);
	Map<DataKey, Elements> result = null;
	try {
		QueryResult rs = (QueryResult) mapCtx.getMapQueryRunner(CN_XDM_ELEMENT).runIndexOrPartitionScanQueryOnOwnedPartitions(query);
		result = new HashMap<>(rs.size());
		for (QueryResultRow row: rs.getRows()) {
			result.put((DataKey) nodeEngine.toObject(row.getKey()), (Elements) nodeEngine.toObject(row.getValue()));
		}
		return result;
	} catch (ExecutionException | InterruptedException ex) {
		logger.error("getElementKeys.error", ex);
	}
	return result;
}
 
开发者ID:dsukhoroslov,项目名称:bagri,代码行数:18,代码来源:DataDistributionService.java

示例9: fromInequalityVariant

import com.hazelcast.query.Predicates; //导入依赖的package包/类
private Predicate<?, ?> fromInequalityVariant(Type type, boolean ignoreCase, String property,
		Iterator<Comparable<?>> iterator) {

	if (ignoreCase && type != Type.SIMPLE_PROPERTY) {
		throw new InvalidDataAccessApiUsageException(String.format("Ignore case not supported for '%s'", type));
	}

	switch (type) {

		case GREATER_THAN:
			return Predicates.greaterThan(property, iterator.next());
		case GREATER_THAN_EQUAL:
			return Predicates.greaterEqual(property, iterator.next());
		case LESS_THAN:
			return Predicates.lessThan(property, iterator.next());
		case LESS_THAN_EQUAL:
			return Predicates.lessEqual(property, iterator.next());

		default:
			throw new InvalidDataAccessApiUsageException(String.format("Logic error for '%s' in query", type));
	}
}
 
开发者ID:hazelcast,项目名称:spring-data-hazelcast,代码行数:23,代码来源:HazelcastQueryCreator.java

示例10: fromEqualityVariant

import com.hazelcast.query.Predicates; //导入依赖的package包/类
private Predicate<?, ?> fromEqualityVariant(Type type, boolean ignoreCase, String property,
		Iterator<Comparable<?>> iterator) {

	switch (type) {

		case SIMPLE_PROPERTY:
			if (ignoreCase) {
				return Predicates.ilike(property, iterator.next().toString());
			} else {
				return Predicates.equal(property, iterator.next());
			}

		default:
			throw new InvalidDataAccessApiUsageException(String.format("Logic error for '%s' in query", type));
	}
}
 
开发者ID:hazelcast,项目名称:spring-data-hazelcast,代码行数:17,代码来源:HazelcastQueryCreator.java

示例11: notJavaDuke

import com.hazelcast.query.Predicates; //导入依赖的package包/类
@Test
public void notJavaDuke() {
	String FIRST_NAME_IS_JOHN = "John";
	String LAST_NAME_IS_WAYNE = "Wayne";
	String NINETEEN_SIXTY_NINE = "1969";

	Predicate<?, ?> predicate = Predicates.and(Predicates.equal("firstname", FIRST_NAME_IS_JOHN),
			Predicates.equal("lastname", LAST_NAME_IS_WAYNE));

	// Force operation to server's content, not remote
	Set<String> localKeySet = super.server_personMap.localKeySet(predicate);

	assertThat("Entry exists", localKeySet.size(), equalTo(1));
	String key = localKeySet.iterator().next();

	assertThat("Correct key", key, equalTo(NINETEEN_SIXTY_NINE));

	Person person = super.server_personMap.get(key);
	assertThat("Not invalidated", person, notNullValue());
	assertThat("@Id matches key", person.getId(), equalTo(key));
	assertThat("First name", person.getFirstname(), equalTo(FIRST_NAME_IS_JOHN));
	assertThat("Last name", person.getLastname(), equalTo(LAST_NAME_IS_WAYNE));
}
 
开发者ID:hazelcast,项目名称:spring-data-hazelcast,代码行数:24,代码来源:ClientServerIT.java

示例12: usingPredicates

import com.hazelcast.query.Predicates; //导入依赖的package包/类
@Test
public void usingPredicates() {
    bookRepository.save(Arrays.asList(Book.create("978-1785285332", "Getting Started With Hazelcast", 3848),
            Book.create("978-1782169970", "Infinispan Data Grid Platform Definitive Guide", 4947),
            Book.create("978-1783988181", "Mastering Redis", 6172)));

    Predicate<String, Book> predicate =
            Predicates.and(Predicates.equal("isbn", "978-1785285332"), Predicates.greaterEqual("price", 3000));

    KeyValueQuery<Predicate<String, Book>> query = new KeyValueQuery<>(predicate);

    Iterable<Book> books = keyValueOperations.find(query, Book.class);

    assertThat(StreamSupport.stream(books.spliterator(), false).map(Book::getTitle).collect(Collectors.toList()))
            .hasSize(1)
            .containsExactly("Getting Started With Hazelcast");
}
 
开发者ID:kazuhira-r,项目名称:hazelcast-examples,代码行数:18,代码来源:SpringDataHazelcastTest.java

示例13: query

import com.hazelcast.query.Predicates; //导入依赖的package包/类
@TimeStep(prob = -1)
public void query(ThreadState state, Probe probe, @StartNanos long startNanos) {
    int key = state.getRandomKey();
    Predicate predicate = Predicates.equal("payloadField[any]", key);
    Collection<Object> result = null;
    try {
        result = map.values(predicate);
    } finally {
        probe.done(startNanos);
    }

    if (throttlingLogger.requestLogSlot()) {
        throttlingLogger.logInSlot(Level.INFO,
                format("Query 'payloadField[any]= %d' returned %d results.", key, result.size()));
    }

    for (Object resultSillySequence : result) {
        state.assertValidSequence(resultSillySequence);
    }
}
 
开发者ID:hazelcast,项目名称:hazelcast-simulator,代码行数:21,代码来源:MultiValueMapTest.java

示例14: pagePredicate

import com.hazelcast.query.Predicates; //导入依赖的package包/类
@TimeStep(prob = 0.2)
public void pagePredicate(ThreadState state) {
    double maxSalary = state.randomDouble() * Employee.MAX_SALARY;
    Predicate predicate = Predicates.lessThan("salary", maxSalary);
    SalaryComparator salaryComparator = new SalaryComparator();
    PagingPredicate pagingPredicate = new PagingPredicate(predicate, salaryComparator, pageSize);

    Collection<Employee> employees;
    List<Employee> employeeList;
    do {
        employees = map.values(pagingPredicate);
        employeeList = fillListWithQueryResultSet(employees);
        Employee nextEmployee;
        Employee currentEmployee;
        for (int i = 0; i < employeeList.size() - 1; i++) {
            currentEmployee = employeeList.get(i);
            nextEmployee = employeeList.get(i + 1);
            // check the order & max salary
            assertTrue(format(baseAssertMessage, currentEmployee.getSalary(), predicate),
                    currentEmployee.getSalary() <= nextEmployee.getSalary() && nextEmployee.getSalary() < maxSalary);
        }
        pagingPredicate.nextPage();
    } while (!employees.isEmpty());

    state.operationCounter.pagePredicateCount++;
}
 
开发者ID:hazelcast,项目名称:hazelcast-simulator,代码行数:27,代码来源:MapPredicateTest.java

示例15: clean

import com.hazelcast.query.Predicates; //导入依赖的package包/类
@Override
public void clean()
{
    final long oldest = System.currentTimeMillis() - kfkaCfg.getTtl(TimeUnit.MILLISECONDS);
    final Predicate<?, ?> p = Predicates.lessThan("timestamp", oldest); 
    this.messages.executeOnEntries(cleanProcessor, p);
}
 
开发者ID:ethlo,项目名称:kfka,代码行数:8,代码来源:KfkaManagerImpl.java


注:本文中的com.hazelcast.query.Predicates类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。