use of java.util.Objects in project grakn by graknlabs.
the class InferenceRule method propagateConstraints.
/**
* @param parentAtom atom containing constraints (parent)
* @param unifier unifier unifying parent with the rule
* @return rule with propagated constraints from parent
*/
public InferenceRule propagateConstraints(Atom parentAtom, Unifier unifier) {
if (!parentAtom.isRelation() && !parentAtom.isResource())
return this;
Atom headAtom = head.getAtom();
Set<Atomic> bodyAtoms = new HashSet<>(body.getAtoms());
// transfer value predicates
parentAtom.getPredicates(ValuePredicate.class).flatMap(vp -> vp.unify(unifier).stream()).forEach(bodyAtoms::add);
// if head is a resource merge vps into head
if (headAtom.isResource() && ((ResourceAtom) headAtom).getMultiPredicate().isEmpty()) {
ResourceAtom resourceHead = (ResourceAtom) headAtom;
Set<ValuePredicate> innerVps = parentAtom.getInnerPredicates(ValuePredicate.class).flatMap(vp -> vp.unify(unifier).stream()).peek(bodyAtoms::add).collect(toSet());
headAtom = ResourceAtom.create(headAtom.getPattern(), headAtom.getPredicateVariable(), resourceHead.getRelationVariable(), resourceHead.getTypeId(), innerVps, headAtom.getParentQuery());
}
Set<TypeAtom> unifiedTypes = parentAtom.getTypeConstraints().flatMap(type -> type.unify(unifier).stream()).collect(toSet());
// set rule body types to sub types of combined query+rule types
Set<TypeAtom> ruleTypes = body.getAtoms(TypeAtom.class).filter(t -> !t.isRelation()).collect(toSet());
Set<TypeAtom> allTypes = Sets.union(unifiedTypes, ruleTypes);
allTypes.stream().filter(ta -> {
SchemaConcept schemaConcept = ta.getSchemaConcept();
SchemaConcept subType = allTypes.stream().map(Atom::getSchemaConcept).filter(Objects::nonNull).filter(t -> ReasonerUtils.supers(t).contains(schemaConcept)).findFirst().orElse(null);
return schemaConcept == null || subType == null;
}).forEach(t -> bodyAtoms.add(t.copy(body)));
return new InferenceRule(ReasonerQueries.atomic(headAtom), ReasonerQueries.create(bodyAtoms, tx), ruleId, tx);
}
use of java.util.Objects in project carbon-apimgt by wso2.
the class ApiFileDAOImpl method getAPIs.
/**
* @see ApiDAO#getAPIs(Set, String)
*/
@Override
public List<API> getAPIs(Set<String> roles, String user) throws APIMgtDAOException {
File[] files = new File(storagePath).listFiles();
List<API> apiList = new ArrayList<>();
final FilenameFilter filenameFilter = (dir, name) -> (name.endsWith(APIMgtConstants.APIFileUtilConstants.JSON_EXTENSION) && name.contains(APIMgtConstants.APIFileUtilConstants.API_DEFINITION_FILE_PREFIX) && !dir.isHidden());
if (files != null) {
for (File file : files) {
apiList.add((API) fetchObject(file, FileApi.class, filenameFilter));
}
}
apiList.removeIf(Objects::isNull);
return apiList;
}
use of java.util.Objects in project TinyKeePass by sorz.
the class AuthActivity method onDatabaseOpened.
@Override
protected void onDatabaseOpened() {
StructureParser.Result result = parseStructure();
KeePassFile keePass = KeePassStorage.get(this);
SearchIndex index = new SearchIndex(keePass);
StringBuilder queryBuilder = new StringBuilder();
result.title.forEach(title -> queryBuilder.append(title).append(' '));
Stream<Entry> entryStream = index.search(queryBuilder.toString()).map(keePass::getEntryByUUID);
FillResponse.Builder responseBuilder = new FillResponse.Builder();
// add matched entities
entryStream.map(entry -> AutofillUtils.buildDataset(this, entry, result)).filter(Objects::nonNull).limit(MAX_NUM_CANDIDATE_ENTRIES).forEach(responseBuilder::addDataset);
// add "show all" item
RemoteViews presentation = AutofillUtils.getRemoteViews(this, getString(R.string.autofill_item_show_all), R.drawable.ic_more_horiz_gray_24dp);
presentation.setTextColor(R.id.textView, getColor(R.color.hint));
Dataset.Builder datasetBuilder = new Dataset.Builder(presentation).setAuthentication(EntrySelectActivity.getAuthIntentSenderForResponse(this));
result.allAutofillIds().forEach(id -> datasetBuilder.setValue(id, null));
responseBuilder.addDataset(datasetBuilder.build());
setFillResponse(responseBuilder.build());
finish();
}
use of java.util.Objects in project camel by apache.
the class EtcdServiceDiscovery method getServices.
protected List<ServiceDefinition> getServices(Predicate<EtcdServiceDefinition> filter) {
List<ServiceDefinition> servers = Collections.emptyList();
if (isRunAllowed()) {
try {
final EtcdConfiguration conf = getConfiguration();
final EtcdKeyGetRequest request = getClient().get(conf.getServicePath()).recursive();
if (conf.hasTimeout()) {
request.timeout(conf.getTimeout(), TimeUnit.SECONDS);
}
final EtcdKeysResponse response = request.send().get();
if (Objects.nonNull(response.node) && !response.node.nodes.isEmpty()) {
servers = response.node.nodes.stream().map(node -> node.value).filter(ObjectHelper::isNotEmpty).map(this::nodeFromString).filter(Objects::nonNull).filter(filter).sorted(EtcdServiceDefinition.COMPARATOR).collect(Collectors.toList());
}
} catch (Exception e) {
throw new RuntimeCamelException(e);
}
}
return servers;
}
use of java.util.Objects in project opennms by OpenNMS.
the class GraphMLMetaTopologyFactory method updated.
@Override
public void updated(String pid, @SuppressWarnings("rawtypes") Dictionary properties) throws ConfigurationException {
LOG.debug("updated(String, Dictionary) invoked");
String location = (String) properties.get(TOPOLOGY_LOCATION);
if (!m_serviceRegistration.containsKey(pid)) {
LOG.debug("Service with pid '{}' is new. Register {}", pid, GraphMLMetaTopologyProvider.class.getSimpleName());
final Dictionary<String, Object> metaData = new Hashtable<>();
metaData.put(Constants.SERVICE_PID, pid);
if (properties.get(LABEL) != null) {
metaData.put(LABEL, properties.get(LABEL));
}
// Expose the MetaTopologyProvider
try {
final GraphMLMetaTopologyProvider metaTopologyProvider = new GraphMLMetaTopologyProvider(m_serviceAccessor);
metaTopologyProvider.setTopologyLocation(location);
metaTopologyProvider.reload();
registerService(pid, MetaTopologyProvider.class, metaTopologyProvider, metaData);
// Create and register additional services
final Set<String> iconKeys = metaTopologyProvider.getGraphProviders().stream().map(GraphProvider::getNamespace).flatMap(eachNamespace -> metaTopologyProvider.getRawTopologyProvider(eachNamespace).getVertices().stream()).map(Vertex::getIconKey).filter(Objects::nonNull).collect(Collectors.toSet());
registerService(pid, IconRepository.class, new GraphMLIconRepository(iconKeys));
// Create an OSGi aware script engine manager
final ScriptEngineManager scriptEngineManager = new OSGiScriptEngineManager(m_bundleContext);
metaTopologyProvider.getGraphProviders().forEach(it -> {
// Find Topology Provider
final GraphMLTopologyProvider rawTopologyProvider = metaTopologyProvider.getRawTopologyProvider(it.getNamespace());
// EdgeStatusProvider
registerService(pid, EdgeStatusProvider.class, new GraphMLEdgeStatusProvider(rawTopologyProvider, scriptEngineManager, m_serviceAccessor));
// SearchProvider
registerService(pid, SearchProvider.class, new GraphMLSearchProvider(rawTopologyProvider));
// Vertex Status Provider
// Only add status provider if explicitly set in GraphML document
this.buildStatusProvider(metaTopologyProvider, scriptEngineManager, rawTopologyProvider).ifPresent(statusProvider -> registerService(pid, StatusProvider.class, statusProvider));
});
} catch (InvalidGraphException | IOException e) {
LOG.error("An error occurred while loading GraphMLTopology from file {}. Ignoring...", location, e);
}
} else {
LOG.warn("Service with pid '{}' updated. Updating is not supported. Ignoring...");
}
}
Aggregations