/** * Do the same search as in {@link this#findNearest(SType)} but return {@link SInstance#getValue} instead of the SInstance * @param targetType * @param <V> * @return */ @SuppressWarnings("unchecked") public <V> Optional<V> findNearestValue(SType<?> targetType) { return (Optional<V>) findNearest(targetType).map(SInstance::getValueWithDefault); }
private static SInstance getInstance(SInstance instance, SType target) { return (SInstance) instance.findNearest(target).orElse(null); }
private static SInstance getInstance(SInstance instancia, SType target) { return (SInstance) instancia.findNearest(target).orElse(null); }
public static <T extends SInstance> Predicate<SInstance> atLeastOneFilled(int quantity, SType<T>... types) { return i -> { int count = 0; for (SType<T> sType : types) { if (!i.findNearest(sType).filter(SInstance::isEmptyOfData).isPresent()) { count++; } } return count < quantity; }; }
public <V> Optional<V> findNearestValue(SType<?> targetType, Class<V> valueClass) { return findNearest(targetType).map(it -> valueClass.cast(it.getValueWithDefault(valueClass))); }
@Override List<Integer> getIds(SInstance root) { final SIList<SIComposite> formulas = root.findNearest(formulasHomeopaticas).orElse(null); final List<Integer> ids = new ArrayList<>(); if (formulas != null) { ids.addAll(formulas.stream() .flatMap(f -> f.getChildren().stream()) .map(i -> i.findNearest(idDescricaoDinamizada)) .filter(Optional::isPresent) .map(Optional::get) .map(SIInteger::getValue) .collect(Collectors.toList())); } return ids; } }).converter((ValueToSICompositeConverter<FormaFarmaceuticaBasica>) (ins, desc) -> {
/** * Returns the nearest instance for the given type or throws an Exception if it is not found. * This method works exactly as the {@link this#findNearest(SType)} * * @param targetType * @param <A> * @return */ @Nonnull public <A extends SInstance> A findNearestOrException(@Nonnull SType<A> targetType) { return findNearest(targetType).orElseThrow(() -> new SingularFormException(String.format("O tipo %s não foi encontrado", targetType.getName()))); }
private <ST extends SType<?>> SInstance resolveTypeFinderInstance(IFunction<T, ST> typeFinder) { SInstance instance = getRootSInstanceForGivenSTypeClass(); ST subtype = typeFinder.apply((T) instance.getType()); return instance.findNearest((SType<SInstance>) subtype).orElse(null); }
private static void validate(Component component, AjaxRequestTarget target, SInstance fieldInstance) { if (!isSkipValidationOnRequest()) { final InstanceValidationContext validationContext; // Validação do valor do componente validationContext = new InstanceValidationContext(); validationContext.validateSingle(fieldInstance); // limpa erros de instancias dependentes, e limpa o valor caso de este não seja válido para o provider for (SType<?> dependentType : fieldInstance.getType().getDependentTypes()) { fieldInstance .findNearest(dependentType) .ifPresent(it -> { it.getDocument().clearValidationErrors(it.getId()); //Executa validações que dependem do valor preenchido if (!it.isEmptyOfData()) { validationContext.validateSingle(it); } }); } WicketBuildContext .findNearest(component) .flatMap(ctx -> Optional.of(ctx.getRootContext())) .flatMap(ctx -> Optional.of(Stream.builder().add(ctx.getRootContainer()).add(ctx.getExternalContainer()).build())) .ifPresent(containers -> containers.forEach(container -> { updateValidationFeedbackOnDescendants(target, (MarkupContainer) container); })); } }
.dependsOn(descricaoDinamizada) .visible(i -> { final SIList<SIComposite> list = i.findNearest(formulasHomeopaticas).orElse(null); final boolean hasIdDescricaoDinamizadaPresent = list.stream() .map(SIComposite::getChildren) .flatMap(Collection::stream) .map(ins -> ins.findNearest(descricaoDinamizada)) .filter(ins -> ins.isPresent() && Value.notNull(ins.get(), idDescricaoDinamizada)) .findFirst().isPresent();
.dependsOn(acao) .visible(itensInstance -> { SIString acaoInstance = itensInstance.findNearest(acao).get(); return acaoInstance.getValue() != null; });
.dependsOn(acao) .visible(itensInstance -> { SIString acaoInstance = itensInstance.findNearest(acao).get(); return acaoInstance.getValue() != null; });