use of java.util.function.Predicate in project n4js by eclipse.
the class ScriptApiTracker method _computeMissingApiGetterSetter.
/**
* Internal algorithm.
*/
private List<AccessorTuple> _computeMissingApiGetterSetter(TN4Classifier declaration, List<AccessorTuple> concreteAccessorTuples, Predicate<ProjectComparisonEntry> filterPredicate, boolean recursive) {
Optional<ProjectComparisonAdapter> optAdapt = firstProjectComparisonAdapter(declaration.eResource());
if (optAdapt.isPresent()) {
ProjectComparisonAdapter projectComparisonAdapter = optAdapt.get();
ProjectComparisonEntry compareEntry = projectComparisonAdapter.getEntryFor(EcoreUtil2.getContainerOfType(declaration, TModule.class));
ProjectComparisonEntry typeCompare = compareEntry.getChildForElementImpl(declaration);
if (typeCompare == null) {
return Collections.emptyList();
}
Predicate<ProjectComparisonEntry> filter = (pce -> (pce.getElementAPI() instanceof TGetter) || (pce.getElementAPI() instanceof TSetter));
filter = filter.and(pce -> pce.getElementImpl()[0] == null).and(filterPredicate);
ArrayList<ProjectComparisonEntry> collectedPCEofGetterOrSetter = new ArrayList<>();
Function<TN4Classifier, Consumer<? super ProjectComparisonEntry>> actionProvider = pivot -> pce -> {
// Get or Set ??
collectedPCEofGetterOrSetter.add(pce);
};
// recursive Extension will generate a stream of compareEntries.
if (recursive)
interfaceApiSupertypeWalker(filter, actionProvider, projectComparisonAdapter, (TN4Classifier) typeCompare.getElementAPI(), TN4Classifier.class);
// ----
/*-
Cases of the Implementation: A getter or setter can
- be given as AST (x)
- be missing (m)
- were not required by API (/)
So we have 3*3=9 cases:
get set
(x) (x) --> all fine, pair will be transpiled
(x) (m) --> code for getter will be transpiled, need to inject virtual setter code into existing tuple.
(x) (/) --> all fine, getter will be transpiled
(m) (x) --> code for setter will be transpiled, need to inject virtual getter code into existing tuple.
(m) (m) --> need to create virtual accessor tuple (similar to missing field) with setter & getter
(m) (/) --> need to create virtual accessor tuple with getter only
(/) (x) --> all fine
(/) (m) --> need to create virtual accessor tuple with setter only
(/) (/) --> all fine nothing to be done.
*/
List<ProjectComparisonEntry> getSetList;
if (recursive)
getSetList = collectedPCEofGetterOrSetter;
else
getSetList = typeCompare.allChildren().filter(pce -> (pce.getElementAPI() instanceof TGetter) || (pce.getElementAPI() instanceof TSetter)).filter(filterPredicate).collect(Collectors.toList());
HashMap<Pair<String, Boolean>, GetSetGroup> hmName2getset = new HashMap<>();
for (ProjectComparisonEntry pce : getSetList) {
TMember apiAsMember = ((TMember) pce.getElementAPI());
String name = apiAsMember.getName();
boolean staticCase = apiAsMember.isStatic();
Pair<String, Boolean> key = Pair.of(name, staticCase);
GetSetGroup group = hmName2getset.get(key);
if (group == null) {
group = new GetSetGroup(name, staticCase);
hmName2getset.put(key, group);
}
if (pce.getElementAPI() instanceof TGetter) {
// case getter:
TGetter apiGetter = (TGetter) pce.getElementAPI();
if (pce.getElementImpl(0) != null) {
// case (x) for getter-
group.getterIsInAST = true;
} else {
// case (m) for getter-
group.getterIsInAST = false;
group.getter = new VirtualApiTGetter(name, apiGetter);
}
} else if (pce.getElementAPI() instanceof TSetter) {
// case setter:
TSetter apiSetter = (TSetter) pce.getElementAPI();
if (pce.getElementImpl(0) != null) {
// case (x) for setter -
group.setterIsInAST = true;
} else {
// case (m) for setter:
group.setterIsInAST = false;
group.setter = new VirtualApiTSetter(name, apiSetter);
}
}
}
// go over the list of known AccessorTupels and enhance them by adding virtual things.
for (AccessorTuple conAccTupel : concreteAccessorTuples) {
GetSetGroup getset = hmName2getset.remove(Pair.of(conAccTupel.getName(), conAccTupel.isStatic()));
if (getset != null) {
// some missings found:
if (getset.hasGetter() && !getset.getterIsInAST && // could be mixed in by interface-default-impl different
conAccTupel.getGetter() == null) // to the intended API-path c.f. GHOLD-212
{
conAccTupel.setGetter(getset.getter);
}
if (getset.hasSetter() && !getset.setterIsInAST && // could be mixed in by interface-default-impl different
conAccTupel.getSetter() == null) // to the intended API-path c.f. GHOLD-212
{
conAccTupel.setSetter(getset.setter);
}
}
}
// remaining entries in hmName2getset need to translated into VirtualApiAccessors.
List<AccessorTuple> ret = new ArrayList<>();
for (GetSetGroup getset : hmName2getset.values()) {
VirtualApiAccessorTuple vAccessTupel = new VirtualApiAccessorTuple(getset.name, getset.staticCases);
if (getset.getter != null)
vAccessTupel.setGetter(getset.getter);
if (getset.setter != null)
vAccessTupel.setSetter(getset.setter);
ret.add(vAccessTupel);
}
return ret;
}
return emptyList();
}
use of java.util.function.Predicate in project herd by FINRAOS.
the class TagServiceImpl method indexValidateTagsList.
/**
* A helper method that will validate a list of tags
*
* @param tagEntityList the list of tags that will be validated
*
* @return true all of the tags are valid in the index
*/
private boolean indexValidateTagsList(final List<TagEntity> tagEntityList) {
final String indexName = SearchIndexTypeEntity.SearchIndexTypes.TAG.name().toLowerCase();
final String documentType = configurationHelper.getProperty(ConfigurationValue.ELASTICSEARCH_BDEF_DOCUMENT_TYPE, String.class);
Predicate<TagEntity> validInIndexPredicate = tagEntity -> {
// Fetch Join with .size()
tagEntity.getChildrenTagEntities().size();
// Convert the tag entity to a JSON string
final String jsonString = tagHelper.safeObjectMapperWriteValueAsString(tagEntity);
return this.indexFunctionsDao.isValidDocumentIndex(indexName, documentType, tagEntity.getId().toString(), jsonString);
// searchFunctions.getIsValidFunction().test(indexName, documentType, tagEntity.getId().toString(), jsonString);
};
boolean isValid = true;
for (TagEntity tagEntity : tagEntityList) {
if (!validInIndexPredicate.test(tagEntity)) {
isValid = false;
}
}
return isValid;
}
use of java.util.function.Predicate in project com.revolsys.open by revolsys.
the class Graph method getNodes.
public List<Node<T>> getNodes(final Predicate<Node<T>> filter, final Geometry geometry, final double maxDistance) {
final BoundingBox boundingBox = geometry.getBoundingBox().expand(maxDistance);
final Predicate<Node<T>> distanceFilter = (node) -> {
return filter.test(node) && node.distance(geometry) <= maxDistance;
};
return getNodes(boundingBox, distanceFilter, null);
}
use of java.util.function.Predicate in project com.revolsys.open by revolsys.
the class Graph method getEdges.
public List<Edge<T>> getEdges(final Point point, final double maxDistance) {
if (point == null) {
return Collections.emptyList();
} else {
BoundingBox boundingBox = point.getBoundingBox();
boundingBox = boundingBox.expand(maxDistance);
final double x = point.getX();
final double y = point.getY();
final Predicate<Edge<T>> filter = (edge) -> {
final LineString line = edge.getLineString();
final double distance = line.distance(x, y);
if (distance <= maxDistance) {
return true;
} else {
return false;
}
};
return BoundingBox.newArraySorted(this::forEachEdge, boundingBox, filter);
}
}
use of java.util.function.Predicate in project strimzi by strimzi.
the class StatefulSetOperator method restartPod.
private Future<Void> restartPod(String namespace, String name, Predicate<String> isReady, String podName) {
Future<Void> result = Future.future();
log.info("Roll {}/{}: Rolling pod {}", namespace, name, podName);
Future<Void> deleted = Future.future();
Future<CompositeFuture> deleteFinished = Future.future();
Watcher<Pod> watcher = new RollingUpdateWatcher(deleted);
Watch watch = podOperations.watch(namespace, podName, watcher);
// Delete the pod
log.debug("Roll {}/{}: Waiting for pod {} to be deleted", namespace, name, podName);
Future podReconcileFuture = podOperations.reconcile(namespace, podName, null);
CompositeFuture.join(podReconcileFuture, deleted).setHandler(deleteResult -> {
watch.close();
if (deleteResult.succeeded()) {
log.debug("Roll {}/{}: Pod {} was deleted", namespace, name, podName);
}
deleteFinished.handle(deleteResult);
});
deleteFinished.compose(ix -> {
log.debug("Roll {}/{}: Waiting for new pod {} to get ready", namespace, name, podName);
Future<Void> readyFuture = Future.future();
vertx.setPeriodic(1_000, timerId -> {
p(isReady, podName).setHandler(x -> {
if (x.succeeded()) {
if (x.result()) {
vertx.cancelTimer(timerId);
readyFuture.complete();
}
// else not ready
} else {
vertx.cancelTimer(timerId);
readyFuture.fail(x.cause());
}
});
});
return readyFuture;
}).setHandler(result);
return result;
}
Aggregations